// JavaScript Document

function echeck(str) {
		if(str.value != ""){
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str.value)){
				//return (true)
			}else{
				alert("The Email Address you have Entered is Not Properly Formatted")
				document.getElementById(str.id).value = "";
				document.getElementById(str.id).focus();
				//return (false)
			}
		}
	}

	function checkAlpha(str){
		 var charpos = str.value.search("[^A-Za-z]"); 
		 if(str.value.length > 0 &&  charpos >= 0){ 
				alert("The SCAC Information you have Entered Can not be a Number")
				document.getElementById(str.id).value = "";
				document.getElementById(str.id).focus();
			}
						
	}
	function checkZip(str){
		var valuePass = false;
		//check if USA or Mexico
		if(/^([0-9])+([0-9])+([0-9])+([0-9])+([0-9])$/.test(str.value) && str.value.length == 5 ){ 
			valuePass = true;
			}
		//check if Canada
		else if(/^([a-zA-Z])+([0-9])+([a-zA-Z])+( |-)+([0-9])+([a-zA-Z])+([0-9])$/.test(str.value) && str.value.length == 7  ){ 
			valuePass = true;
			} 
		if(!valuePass && str.value.length != 0){
			alert("Please Enter A Valid Zip Code!\n USA or Mexico xxxxx, Canada xxx-xxx(xxx xxx)")
			document.getElementById(str.id).value = "";
			document.getElementById(str.id).focus();
		}
	}
	function checkNum(str){
		 var charpos = str.value.search("[^0-9]"); 
		 if(str.value.length > 0 &&  charpos >= 0){ 
				alert("Please Enter Only Numbers into This Field!")
				document.getElementById(str.id).value = "";
				document.getElementById(str.id).focus();
			}
						
	}
	function checkPhone(str){
		var inputErrors = 0;
		if(str.value.length != 0){
				if (str.value.length != 12){inputErrors++;}
				if (str.value.substring(0,3).search("[^0-9]") >= 0){inputErrors++;}
				if (str.value.charAt(3) != "-" && str.value.charAt(3) != " "){inputErrors++;}
				if (str.value.substring(4,7).search("[^0-9]") >= 0){inputErrors++;}
				if (str.value.charAt(7) != "-" && str.value.charAt(7) != " "){inputErrors++;}
				if (str.value.substring(8,12).search("[^0-9]") >= 0){inputErrors++;}
		}	
		if(inputErrors != 0){
			alert("The Phone Number You Have Entered is in Invalid! (xxx-xxx-xxxx) \n"+str.name)
			document.getElementById(str.id).value = "";
			document.getElementById(str.id).focus();
		}	
	}