// JavaScript Document
var form;
var submitted = false;
var click_edit=false;
var error = false;
var error_message = "";


function check_input(field_name, field_size, message) {
  if (form.elements[field_name]) {
    var field_value = form.elements[field_name].value;
    if (field_value == '' || field_value.length < field_size) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}


function check_password(field_name_1, field_name_2, field_size, message_1, message_2) {
  if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) {
    var password = form.elements[field_name_1].value;
    var confirmation = form.elements[field_name_2].value;

    if (password == '' || password.length < field_size) {
      error_message = error_message + "* " + message_1 + "\n";
      error = true;
    } else if (password != confirmation) {
      error_message = error_message + "* " + message_2 + "\n";
      error = true;
    }
  }
}


function check_form(form_name) {
  if (submitted == true) {
    alert("This form has already been submitted. Please press Ok and wait for this process to be completed.");
    return false;
  }

  error = false;
  form = form_name;
  error_message = "Errors have occured during the process of your form.\n\nPlease make the following corrections:\n\n";

  check_input("email", 6, "Your Email Address must contain a minimum of 6 characters.");

  check_input("name", 2, "Your Name must contain a minimum of 1 characters or a maximum of 30 characters.");

  check_input("city", 2, "Please enter your city/town");
	check_input("address", 10, "Please enter your detailed delivery address");
	
	check_input("postal", 4, "Your postcode is incorrect.");
check_input("telephone", 5, "Your telephone is incorrect.");
  check_password("password", "confirmation", 5, "Your Password must contain a minimum of 5 characters.", "The Password Confirmation must match your Password.");

  if (error == true) {
    alert(error_message);
    return false;
  } else {
    submitted = true;
    return true;
  }
}

function check_logon_form(form_name) {
  if (submitted == true) {
    alert("This form has already been submitted. Please press Ok and wait for this process to be completed.");
    return false;
  }
  error = false;
  form = form_name;
  form.checkout.disabled = true;
  error_message = "Errors have occured during the process of your form.\n\nPlease make the following corrections:\n\n";
  check_input("email", 6, "Email address must contain a minimum of 6 characters.");
  check_input("name", 2, "Your Name must contain a minimum of 1 characters or a maximum of 30 characters.");
  check_input("city", 2, "please enter your city/town");
  check_input("street", 10, "Please enter your detailed delivery address");
  check_input("postal", 4, "Your postcode is incorrect.");
  check_input("telephone", 5, "Your telephone is incorrect.");
	var radios=form.payment;
	var flag=false;
	if(radios[0].type=='radio'){
	for(var i=0;i<radios.length;i++){
		if(radios[i].checked==true){
			flag=true;
			break;
		}
	}
	}else{
		if(radios.value!=""){
			flag=true;
		}
	}
	
	if(flag==false){
	  error_message = error_message + "* " + "Please select the preferred payment method to use on this order." + "\n";
	  error=true;
	}
  if (error == true) {
    alert(error_message);
		form.checkout.disabled = false;
		return false;

  } else {
    	submitted = true;
		form.checkout.disabled = false;
    	return true;
  }
}
function editInfo(form){
  if (click_edit == true) {
    return false;
  }
	var e=form.elements;
	for(var i=0;i<e.length;i++){
		if(e[i].className=='confirmbox'){
			e[i].className='editinfo';
			e[i].readOnly=false;
		}
	}
	form.country.className='confirmbox';
	var payment=document.getElementById("payment");
	var parent_p=payment.parentNode;
	parent_p.removeChild(payment);
	
	var state=document.getElementById("state");
	var parent_state=state.parentNode;
	parent_state.removeChild(state);
	
	var shipping=document.getElementById("shipping");
	var parent_s=shipping.parentNode;
	parent_s.removeChild(shipping);
	
	var payment_method=document.getElementById("payment_method");
	payment_method.style.display='block';
	
	var shipping_method=document.getElementById("shipping_method");
	shipping_method.style.display='block';
	
	var state_select=document.getElementById("state_select");
	state_select.style.display='block';	
	click_edit=true;
}
//-->

