// JavaScript Document

// JavaScript Document

//auto tab for maxlengths

var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
	var keyCode = (isNN) ? e.which : e.keyCode; 
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}
	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele)
				found = true;
			else
			index++;
		return found;
	}
	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)index = i;
			else i++;
		return index;
	}
	return true;
}

// email validation
function emailCheck (emailStr) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	
var user=matchArray[1];
var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Ths username contains invalid characters.");
			return false;
		   }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Ths domain name contains invalid characters.");
			return false;
		   }
	}
	if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid.");
		return false;
	}
var IPArray=domain.match(ipDomainPat);

	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
				return false;
		  	}
		}
	return true;
	}
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;

	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("The domain name does not seem to be valid.");
			return false;
		   }
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
	if (len<2) {
		alert("This address is missing a hostname!");
		return false;
	}
	return true;
}







function submit_samples_check (){
	// variables that will be used to validate integers
	var phone1x = document.form.phone1.value;
	var phone2x = document.form.phone2.value;
	var phone3x = document.form.phone3.value;
	
	var cellphone1x = document.form.cellphone1.value;
	var cellphone2x = document.form.cellphone2.value;
	var cellphone3x = document.form.cellphone3.value;
	
	var fax1x = document.form.fax1.value;
	var fax2x = document.form.fax2.value;
	var fax3x = document.form.fax3.value;
	
	var sample_quantity1x = document.form.sample_quantity1.value;
	var sample_quantity2x = document.form.sample_quantity2.value;

	// this variable contains elements to test if the input is an integer
	var anum = /(^\d+$)|(^\d+\.\d+$)/;

 	if (document.form.fullname.value == ""){
   		alert ("Please enter your full name");
    	document.form.fullname.focus();
		return (false);
	}
	else if(document.form.company.value == ""){ 
     	alert ("Please enter your company name");
     	document.form.company.focus();
	 	return(false);
	}	
	else if(document.form.phone1.value.length < 3 || !anum.test(phone1x)){
    	alert ("Please fill in the area code of your work phone number");
     	document.form.phone1.focus();
		document.form.phone1.select();
	 	return(false);
	}
	else if(document.form.phone2.value.length < 3 || !anum.test(phone2x)){
    	alert ("Please fill in your work phone number");
     	document.form.phone2.focus();
		document.form.phone2.select();
	 	return(false);
	}
	else if(document.form.phone3.value.length < 4 || !anum.test(phone3x)){
    	alert ("Please fill in the last 4 numbers of your work phone number");
     	document.form.phone3.focus();
		document.form.phone3.select();
	 	return(false);
	}
	else if(document.form.email.value == ""){  
    	alert ("Please fill in your email address");
     	document.form.email.focus();
	 	return(false);
	}
	else if(document.form.sample_type1.value == ""){
    	alert ("Please select the type of sample");
     	document.form.sample_type1.focus();
	 	return(false);
	}
	else if(!anum.test(sample_quantity1x)){
    	alert ("Please enter the quantity of samples");
     	document.form.sample_quantity1.focus();
		document.form.sample_quantity1.select();
	 	return(false);
	}
	else if(document.form.sample_due1.value == ""){
    	alert ("Please enter the date / time results are due for Sample 1");
     	document.form.sample_due1.focus();
	 	return(false);
	}
	else if(document.form.samples_arriving.value == ""){
    	alert ("Please enter the date for when the samples will arrive");
     	document.form.samples_arriving.focus();
	 	return(false);
	}
	else if(document.form.samples_shipped_via.value == ""){
    	alert ("Please select how the samples are to be delivered");
     	document.form.samples_shipped_via.focus();
	 	return(false);
	}	
	return (emailCheck(document.form.email.value));
}



function asbestos_request_check (){
	// variables that will be used to validate integers
	var phone1x = document.form.phone1.value;
	var phone2x = document.form.phone2.value;
	var phone3x = document.form.phone3.value;	

	// this variable contains elements to test if the input is an integer
	var anum = /(^\d+$)|(^\d+\.\d+$)/;

 	if (document.form.fullname.value == ""){
   		alert ("Please enter your full name");
    	document.form.fullname.focus();
		return (false);
	}
	else if(document.form.company.value == ""){ 
     	alert ("Please enter your company name");
     	document.form.company.focus();
	 	return(false);
	}	
	else if(document.form.phone1.value.length < 3 || !anum.test(phone1x)){
    	alert ("Please fill in the area code of your work phone number");
     	document.form.phone1.focus();
		document.form.phone1.select();
	 	return(false);
	}
	else if(document.form.phone2.value.length < 3 || !anum.test(phone2x)){
    	alert ("Please fill in your work phone number");
     	document.form.phone2.focus();
		document.form.phone2.select();
	 	return(false);
	}
	else if(document.form.phone3.value.length < 4 || !anum.test(phone3x)){
    	alert ("Please fill in the last 4 numbers of your work phone number");
     	document.form.phone3.focus();
		document.form.phone3.select();
	 	return(false);
	}
	else if(document.form.email.value == ""){  
    	alert ("Please fill in your email address");
     	document.form.email.focus();
	 	return(false);
	}	
	return (emailCheck(document.form.email.value));
}


function env_lead_request_check (){
	// variables that will be used to validate integers
	var phone1x = document.form.phone1.value;
	var phone2x = document.form.phone2.value;
	var phone3x = document.form.phone3.value;	

	// this variable contains elements to test if the input is an integer
	var anum = /(^\d+$)|(^\d+\.\d+$)/;

 	if (document.form.fullname.value == ""){
   		alert ("Please enter your full name");
    	document.form.fullname.focus();
		return (false);
	}
	else if(document.form.company.value == ""){ 
     	alert ("Please enter your company name");
     	document.form.company.focus();
	 	return(false);
	}	
	else if(document.form.phone1.value.length < 3 || !anum.test(phone1x)){
    	alert ("Please fill in the area code of your work phone number");
     	document.form.phone1.focus();
		document.form.phone1.select();
	 	return(false);
	}
	else if(document.form.phone2.value.length < 3 || !anum.test(phone2x)){
    	alert ("Please fill in your work phone number");
     	document.form.phone2.focus();
		document.form.phone2.select();
	 	return(false);
	}
	else if(document.form.phone3.value.length < 4 || !anum.test(phone3x)){
    	alert ("Please fill in the last 4 numbers of your work phone number");
     	document.form.phone3.focus();
		document.form.phone3.select();
	 	return(false);
	}
	else if(document.form.email.value == ""){  
    	alert ("Please fill in your email address");
     	document.form.email.focus();
	 	return(false);
	}	
	return (emailCheck(document.form.email.value));
}


function industrial_hyg_request_check (){
	// variables that will be used to validate integers
	var phone1x = document.form.phone1.value;
	var phone2x = document.form.phone2.value;
	var phone3x = document.form.phone3.value;	

	// this variable contains elements to test if the input is an integer
	var anum = /(^\d+$)|(^\d+\.\d+$)/;

 	if (document.form.fullname.value == ""){
   		alert ("Please enter your full name");
    	document.form.fullname.focus();
		return (false);
	}
	else if(document.form.company.value == ""){ 
     	alert ("Please enter your company name");
     	document.form.company.focus();
	 	return(false);
	}	
	else if(document.form.phone1.value.length < 3 || !anum.test(phone1x)){
    	alert ("Please fill in the area code of your work phone number");
     	document.form.phone1.focus();
		document.form.phone1.select();
	 	return(false);
	}
	else if(document.form.phone2.value.length < 3 || !anum.test(phone2x)){
    	alert ("Please fill in your work phone number");
     	document.form.phone2.focus();
		document.form.phone2.select();
	 	return(false);
	}
	else if(document.form.phone3.value.length < 4 || !anum.test(phone3x)){
    	alert ("Please fill in the last 4 numbers of your work phone number");
     	document.form.phone3.focus();
		document.form.phone3.select();
	 	return(false);
	}
	else if(document.form.email.value == ""){  
    	alert ("Please fill in your email address");
     	document.form.email.focus();
	 	return(false);
	}	
	return (emailCheck(document.form.email.value));
}



function mcl_loq_request_check (){
	// variables that will be used to validate integers
	var phone1x = document.form.phone1.value;
	var phone2x = document.form.phone2.value;
	var phone3x = document.form.phone3.value;	

	// this variable contains elements to test if the input is an integer
	var anum = /(^\d+$)|(^\d+\.\d+$)/;

 	if (document.form.fullname.value == ""){
   		alert ("Please enter your full name");
    	document.form.fullname.focus();
		return (false);
	}
	else if(document.form.company.value == ""){ 
     	alert ("Please enter your company name");
     	document.form.company.focus();
	 	return(false);
	}	
	else if(document.form.phone1.value.length < 3 || !anum.test(phone1x)){
    	alert ("Please fill in the area code of your work phone number");
     	document.form.phone1.focus();
		document.form.phone1.select();
	 	return(false);
	}
	else if(document.form.phone2.value.length < 3 || !anum.test(phone2x)){
    	alert ("Please fill in your work phone number");
     	document.form.phone2.focus();
		document.form.phone2.select();
	 	return(false);
	}
	else if(document.form.phone3.value.length < 4 || !anum.test(phone3x)){
    	alert ("Please fill in the last 4 numbers of your work phone number");
     	document.form.phone3.focus();
		document.form.phone3.select();
	 	return(false);
	}
	else if(document.form.email.value == ""){  
    	alert ("Please fill in your email address");
     	document.form.email.focus();
	 	return(false);
	}	
	return (emailCheck(document.form.email.value));
}



function QA_QC_request_check (){
	// variables that will be used to validate integers
	var phone1x = document.form.phone1.value;
	var phone2x = document.form.phone2.value;
	var phone3x = document.form.phone3.value;	

	// this variable contains elements to test if the input is an integer
	var anum = /(^\d+$)|(^\d+\.\d+$)/;

 	if (document.form.fullname.value == ""){
   		alert ("Please enter your full name");
    	document.form.fullname.focus();
		return (false);
	}
	else if(document.form.company.value == ""){ 
     	alert ("Please enter your company name");
     	document.form.company.focus();
	 	return(false);
	}	
	else if(document.form.phone1.value.length < 3 || !anum.test(phone1x)){
    	alert ("Please fill in the area code of your work phone number");
     	document.form.phone1.focus();
		document.form.phone1.select();
	 	return(false);
	}
	else if(document.form.phone2.value.length < 3 || !anum.test(phone2x)){
    	alert ("Please fill in your work phone number");
     	document.form.phone2.focus();
		document.form.phone2.select();
	 	return(false);
	}
	else if(document.form.phone3.value.length < 4 || !anum.test(phone3x)){
    	alert ("Please fill in the last 4 numbers of your work phone number");
     	document.form.phone3.focus();
		document.form.phone3.select();
	 	return(false);
	}
	else if(document.form.email.value == ""){  
    	alert ("Please fill in your email address");
     	document.form.email.focus();
	 	return(false);
	}	
	return (emailCheck(document.form.email.value));
}




