function showMe (it, box) {
var vis = (box.checked) ? "none" : "block";
document.getElementById(it).style.display = vis;
}


function formValidator(){     
      
	// Make quick references to the fields
	var firstname = document.getElementById('firstname');
	var lastname = document.getElementById('lastname');
	var phone = document.getElementById('phone');
	var email = document.getElementById('email');
	var address1 = document.getElementById('address1');
	var address2 = document.getElementById('address2');
	var postcode = document.getElementById('postcode');
	var city = document.getElementById('city');
	var country = document.getElementById('country');
	var model = document.getElementById('model_nbr');
    var serial = document.getElementById('serial_nbr');
    var order = document.getElementById('order_nbr');
    var problem = document.getElementById('message');
    var rcenter = document.getElementById('repair_center');
	var firstname_ship = document.getElementById('firstname_ship');
	var lastname_ship = document.getElementById('lastname_ship');
	var phone_ship = document.getElementById('phone_ship');
	var email_ship = document.getElementById('email_ship');
	var address1_ship = document.getElementById('address1_ship');
	var address2_ship = document.getElementById('address2_ship');
	var postcode_ship = document.getElementById('postcode_ship');
	var city_ship = document.getElementById('city_ship');
	var country_ship = document.getElementById('country_ship');


	// Check each input in the order that it appears in the form!
	if(notEmpty(firstname, "Please enter your first name")){
	if(notEmpty(lastname, "Please enter your last name")){
	if(notEmpty(phone, "Please enter your phone number")){
	if(emailValidator(email, "Please enter a valid email address")){
	if(notEmpty(address1,  "Please enter address1")){
	if(notEmpty(address2, "Please enter address2")){
    if(notEmpty(postcode, "Please enter your post code")){
    if(notEmpty(city, "Please enter your city")){
    if(notEmpty(country, "Please enter your country")){
    if(notEmpty(model, "Please enter the model number")){
    if(notEmpty(serial, "Please enter your serial number")){
    if(notEmpty(order, "Please enter your order number")){
    if(notEmpty(problem, "Please describe the problem")){
    if(madeSelection(rcenter, "Please select a repair center")){
	
	if(notEmpty2(firstname_ship, "Please enter the \"Ship To\" first name")){
	if(notEmpty2(lastname_ship, "Please enter the \"Ship To\" last name")){
    if(notEmpty2(phone_ship, "Please enter the \"Ship To\" phone number")){
	if(emailValidator2(email_ship, "Please enter a valid \"Ship To\" email address")){
    if(notEmpty2(address1_ship, "Please enter the \"Ship To\" address1")){
    if(notEmpty2(address2_ship, "Please enter the \"Ship To\" address2")){
    if(notEmpty2(postcode_ship, "Please enter the \"Ship To\" post code")){
    if(notEmpty2(city_ship, "Please enter the \"Ship To\" city")){
    if(notEmpty2(country_ship, "Please enter the \"Ship To\" country")){

 
		return true;

	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	}
	

	   return false;

}


function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}


function notEmpty2(elem, helperMsg){
	if(elem.value.length == 0 && !document.form1.ship_same.checked){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}


function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "select"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function emailValidator2(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(!elem.value.match(emailExp) && !document.form1.ship_same.checked){
	    alert(helperMsg);
		elem.focus();
		return false;
	}else{
		
		return true;
	}
}