




function validatelicense(theForm) {
	
	
var reason = "";

reason += validateEmpty(theForm.name);
  reason += validateEmpty(theForm.lname);
  reason += validatePhone(theForm.phone);  
  reason += validateEmail(theForm.email);
   
   
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;
}

function alphaSpace(val) {
	var num = /^[A-Za-z\s]*$/;
	return (num.test(val)) ? false : true;
}

function phoneValid(val) {
	var num = /^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$/;
	return (num.test(val)) ? false : true;
}

function emailValid(val) {
	var num = /^([0-9a-zA-Z]([-\.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
	return (num.test(val)) ? false : true;	
}

function validateemp() {
	var theForm = document.employment;
	if(theForm.name.value == "") {
		alert("Please enter the name");
		document.getElementById('name').focus();
		return false;
	}
	if(alphaSpace(theForm.name.value)) {
		alert("Please enter the alphabets and space only");
		document.getElementById('name').focus();
		return false;
	}
	if(theForm.city.value == "") {
		alert("Please enter the city");
		document.getElementById('city').focus();
		return false;
	}
	if(alphaSpace(theForm.city.value)) {
		alert("Please enter the alphabets and space only");
		document.getElementById('city').focus();
		return false;
	}
	if(theForm.phone.value == "") {
		alert("Please enter the phone");
		document.getElementById('phone').focus();
		return false;
	}
	if(theForm.email.value == "") {
		alert("Please enter the email address");
		document.getElementById('email').focus();
		return false;
	}
	if(emailValid(theForm.email.value)) {
		alert("Please enter the valid email address");
		document.getElementById('email').focus();
		return false;
	}
	return changeform(2);
}

function changeform(x)
{
	if (x==1)
	{
		document.getElementById("form1").style.display="block";
		document.getElementById("form2").style.display="none";
		document.getElementById("form3").style.display="none";
		document.getElementById("form4").style.display="none";
	}
	if (x==2)
	{
		document.getElementById("form1").style.display="none";
		document.getElementById("form2").style.display="block";
		document.getElementById("form3").style.display="none";
		document.getElementById("form4").style.display="none";
	}
	if (x==3)
	{
		document.getElementById("form1").style.display="none";
		document.getElementById("form2").style.display="none";
		document.getElementById("form3").style.display="block";
		document.getElementById("form4").style.display="none";
	}
	if (x==4)
	{
		document.getElementById("form1").style.display="none";
		document.getElementById("form2").style.display="none";
		document.getElementById("form3").style.display="none";
		document.getElementById("form4").style.display="block";
	}
	return true;
}

function authorise() {
	var theForm = document.employment;
	if(theForm.authorize.value == "") {
		alert("Please select the authorize");
		document.getElementById('authorize').focus();
		return false;
	}
	return true;	
}

function validemp2() {
	var theForm = document.employment;
	if(theForm.position.value == "") {
		alert("Please select the position");
		document.getElementById('position').focus();
		return false;
	}
	if(theForm.start_month.value == "") {
		alert("Please select the month");
		document.getElementById('start_month').focus();
		return false;
	}
	if(theForm.start_year.value == "") {
		alert("Please select the starting year");
		document.getElementById('start_year').focus();
		return false;
	}
	return changeform(3);
}



function validatecustomersurvey(theForm) {
var reason = "";

  reason += validateEmpty(theForm.name);
  reason += validateEmpty(theForm.city);
  reason += validatePhone(theForm.phone);  
  reason += validateEmail(theForm.email);
   
   
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;

}


function validatesplpromotions(theForm) {
var reason = "";
  	

  reason += validateEmail(theForm.email);
  reason += validateEmpty(theForm.dob);
   
   
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;

}

function validateFormOnSubmit(theForm) {
var reason = "";
  

  reason += validateEmail(theForm.email);
  reason += validateEmpty(theForm.telephone);
   
   
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }

  return true;

}
function validateEmpty(fld) {
    var error = "";
    if (fld.value.length == 0) {
        fld.style.background = 'Yellow'; 
        error = "The required field has not been filled in.\n"
    } else {
        fld.style.background = 'White';
    }
    return error;  
}
function validateUsername(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "You didn't enter a username.\n";
    } else if ((fld.value.length < 5) || (fld.value.length > 15)) {
        fld.style.background = 'Yellow'; 
        error = "The username is the wrong length.\n";
    } else if (illegalChars.test(fld.value)) {
        fld.style.background = 'Yellow'; 
        error = "The username contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePassword(fld) {
    var error = "";
    var illegalChars = /[\W_]/; // allow only letters and numbers 
 
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter a password.\n";
    } else if ((fld.value.length < 7) || (fld.value.length > 15)) {
        error = "The password is the wrong length. \n";
        fld.style.background = 'Yellow';
    } else if (illegalChars.test(fld.value)) {
        error = "The password contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!((fld.value.search(/(a-z)+/)) && (fld.value.search(/(0-9)+/)))) {
        error = "The password must contain at least one numeral.\n";
        fld.style.background = 'Yellow';
    } else {
        fld.style.background = 'White';
    }
   return error;
}  
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}
function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "You didn't enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}
function validatePhone(fld) {
    var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

   if (fld.value == "") {
        error = "You didn't enter a phone number.\n";
        fld.style.background = 'Yellow';
    } else if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    } else if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
        fld.style.background = 'Yellow';
    }
    return error;
}