// JavaScript Document
var form = "";
var submitted = 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("postcode", 5, "Your postcode 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.submit.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", 8, "Please enter your detailed delivery address");
	
	check_input("postcode", 5, "Your postcode is incorrect.");
	check_input("telephone", 5, "Your telephone is incorrect.");
 how =false;

  if (error == true) {
    alert(error_message);
		form.submit.disabled = false;
    return false;
  } else {
    submitted = true;
		form.submit.disabled = false;
		/*if(form.country.value=='United Kingdom'){
			$.ajax({
			   type: "POST",
			   async: false,
			   url: "checkout_certification.php",
			   data: "street=" + form.street.value + "&postal=" + form.postal.value + "&city=" + form.city.value + "&company=" + form.company.value,
			   success: function(msg){
				   
				   infos = msg.split('|');
				   alert(infos[0]);
				if(infos[0]==1){
					suggest_add = $('#suggest_add');
					suggest_add.css('display','block');
					suggest_add.html('<ul><li><b>Please choose from the following options for your registered address<b></li><li>Verify address as filled above again</li><li>Use address as filled above (Invalid address may lead to fail delivery)</li><li><table><tr><td>Matched Address</td><td>&nbsp;</td></tr><tr><td>Address Line 1:	</td><td>'+ infos[1] +'</td></tr><tr><td>Address Line 2:</td><td>'+ infos[2] +'</td></tr><tr><td>Town/City:</td><td>'+ infos[3] +'</td></tr><tr><td>County:</td><td>'+ infos[5] +'</td></tr><tr><td>Postcode/ZIP:</td><td>'+ infos[4] +'</td></tr></table></li></ul>');
					how = false;
				}else{
					how = true;
				}
			   }
			});
		}*/
    return true;
  }
}



//-->

