// JavaScript quote form validation script

	function Validation(){

		var fname =  document.web_contact_form.First_Name.value;
		var lname =  document.web_contact_form.Last_Name.value;
		var company =  document.web_contact_form.Company.value;
		var address =  document.web_contact_form.Address.value;
		var city =  document.web_contact_form.City.value;
		var state =  document.web_contact_form.State.value;
		var zip =  document.web_contact_form.Zip.value;
		var phone =  document.web_contact_form.Phone.value;
		var email =  document.web_contact_form.Email_Address.value;

		var OriginCity =  document.web_contact_form.Origin_City.value;
		var DestinationCity =  document.web_contact_form.Destination_City.value;
		var commodity =  document.web_contact_form.Commodity.value;
		var weight =  document.web_contact_form.Weight.value;
		var valueofgoods =  document.web_contact_form.Value_of_Goods.value;		
		var equipmenttype =  document.web_contact_form.Equipment_Type.value;
		var equipmentsize =  document.web_contact_form.Equipment_Size.value;
		var noofpallets =  document.web_contact_form.No_of_Pallets_and_Footage_Req.value;
		var freightclass =  document.web_contact_form.Freight_Class.value;
		var trailertype =  document.web_contact_form.Trailer_Type.value;
		var size =  document.web_contact_form.Size.value;


		if(!checkAlphaChar(fname)) {
			alert("Enter valid first name");
			document.web_contact_form.First_Name.focus();
			return false;
		}
		if(!checkAlphaChar(lname)) {
			alert("Enter valid last name");
			document.web_contact_form.Last_Name.focus();
			return false;
		}
		if(checkBlanks(company) || !checkBlanks(company)) {
			if(!checkSpecialChars(company) || !checkurl(company)) {
				alert("Enter valid company name");
				document.web_contact_form.Company.focus();
				return false;	
			}
		}
		if(checkBlanks(address)) {
			if(!checkSpecialChars(address) || !checkurl(address)) {
				alert("Enter valid address");
				document.web_contact_form.Address.focus();
				return false;	
			}
		}
		if(checkBlanks(city)) {
			if(!checkSpecialChars(city) || !checkurl(city)) {
				alert("Enter valid city");
				document.web_contact_form.City.focus();
				return false;	
			}
		}
		if(checkBlanks(state)) {
			if(!checkSpecialChars(state) || !checkurl(state)) {
				alert("Enter valid state");
				document.web_contact_form.State.focus();
				return false;	
			}
		}
		if(checkBlanks(zip)) {
			if(!checkSpecialChars(zip) || !checkurl(zip)) {
				alert("Enter valid zip");
				document.web_contact_form.Zip.focus();
				return false;	
			}
		}

		if(!checkBlanks(phone) || (phone.length<10)) {
			alert("Enter valid phone");

			document.web_contact_form.Phone.focus();
			return false;	
		}
		if(!checkemail(email) || !checkBlanks(email)) {
			alert("Enter valid email");
			document.web_contact_form.Email_Address.focus();
			return false;
		}

		/**/
		if(checkBlanks(OriginCity)) {
			if(!checkSpecialChars(OriginCity) || !checkurl(OriginCity)) {
				alert("Enter valid origin city");
				document.web_contact_form.Origin_City.focus();
				return false;	
			}
		}
		if(checkBlanks(DestinationCity)) {
			if(!checkSpecialChars(DestinationCity) || !checkurl(DestinationCity)) {
				alert("Enter valid destination city");
				document.web_contact_form.Destination_City.focus();
				return false;	
			}
		}
		if(checkBlanks(commodity)) {
			if(!checkSpecialChars(commodity) || !checkurl(commodity)) {
				alert("Enter valid commodity");
				document.web_contact_form.Commodity.focus();
				return false;	
			}
		}

		if(checkBlanks(commodity)) {
			if(!checkSpecialChars(commodity) || !checkurl(commodity)) {
				alert("Enter valid commodity");
				document.web_contact_form.Commodity.focus();
				return false;	
			}
		}
		if(checkBlanks(weight)) {
			if( !checkurl(weight)) {
				alert("Enter valid weight");
				document.web_contact_form.Weight.focus();
				return false;	
			}
		}
		if(checkBlanks(valueofgoods)) {
			if( !checkurl(valueofgoods)) {
				alert("Enter valid value of goods");
				document.web_contact_form.Value_of_Goods.focus();
				return false;	
			}
		}
		if(checkBlanks(equipmenttype)) {
			if( !checkurl(equipmenttype)) {
				alert("Enter valid Equipment Type");
				document.web_contact_form.Equipment_Type.focus();
				return false;	
			}
		}
		if(checkBlanks(equipmentsize)) {
			if( !checkurl(equipmentsize)) {
				alert("Enter valid equipment size");
				document.web_contact_form.Equipment_Size.focus();
				return false;	
			}
		}
		if(checkBlanks(equipmentsize)) {
			if( !checkurl(equipmentsize)) {
				alert("Enter valid equipment size");
				document.web_contact_form.Equipment_Size.focus();
				return false;	
			}
		}
		if(checkBlanks(noofpallets)) {
			if( !checkurl(noofpallets)) {
				alert("Enter valid no of pallets");
				document.web_contact_form.No_of_Pallets_and_Footage_Req.focus();
				return false;	
			}
		}
		if(checkBlanks(freightclass)) {
			if( !checkurl(freightclass)) {
				alert("Enter valid freight class");
				document.web_contact_form.Freight_Class.focus();
				return false;	
			}
		}
		if(checkBlanks(trailertype)) {
			if( !checkurl(trailertype)) {
				alert("Enter valid trailer type");
				document.web_contact_form.Trailer_Type.focus();
				return false;	
			}
		}
		if(checkBlanks(size)) {
			if( !checkurl(size)) {
				alert("Enter valid size");
				document.web_contact_form.Size.focus();
				return false;	
			}
		}

		//alert('End of the function');
	}

/*Delete blanks from the words
  onblur="trim_text(this.value,'fieldname','formname');"*/
function trim_text(str) {
	str = str.replace(/^\s+|\s+$/g, '');
	return str;
}

/*This function is checking the value is
- a url
- a special character
- or a blank
*/
function checkAlphaChar(strval) {
	var retVal = true;
	var strval = strval;
	myRegExp = new RegExp("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$", "i"); 
	if(myRegExp.test(strval)) {
		retVal = false;
	} else {
		myRegExp = new RegExp("^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$", "i"); 
		if(myRegExp.test(strval)) {
			retVal = false;
		}
	}
	/*Here checking the field contains only alpha characters*/
   if (!strval) return false;
   var iChars = "*|,\":<>[]{}.`\;()@&$#%1234567890";

   for (var i = 0; i < strval.length; i++) {
	  if (iChars.indexOf(strval.charAt(i)) != -1)
		 return false;
   }
	/*Checking the value is blank*/
	var len = strval.length ;
	var foundBlank = 1;
	while(foundBlank == 1 && len > 0) 
	{
		var indx = strval.indexOf(" ");
		if(indx == -1) 
			foundBlank = 0 ;
		else
			strval = strval.substring(0,indx) + strval.substring(indx+1,len);
		len = strval.length;
	}
	retVal = len;
	return retVal;
}


function checkSpecialChars(string) {

   if (!string) return false;
   var iChars = "*|\":<>[]{}`\;()@&$#%";

   for (var i = 0; i < string.length; i++) {
	  if (iChars.indexOf(string.charAt(i)) != -1)
		 return false;
   }
   return true;
} 

function checkBlanks(entry)
{
	var len = entry.length ;
	var foundBlank = 1;
	while(foundBlank == 1 && len > 0) 
	{
		var indx = entry.indexOf(" ");
		if(indx == -1) 
			foundBlank = 0 ;
		else
			entry = entry.substring(0,indx) + entry.substring(indx+1,len);
		len = entry.length;
	}
	return entry;
}

function checkurl(urlval) {
	var urlval = urlval;
	myRegExp = new RegExp("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$", "i"); 
	if(myRegExp.test(urlval)) {
		return false;
	} else {
		myRegExp = new RegExp("^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$", "i"); 
		if(myRegExp.test(urlval)) {
			return false;
		}
	}
	return true;
}

/*Function allowed only to enter numbers
onkeypress="return numbersonly(event, false);"
*/

function numbersonly(e, decimal) {
	var key;
	var keychar;
  
	 if (window.event) {
		key = window.event.keyCode;
	  }
	  else if (e) {
		 key = e.which;
	  }
	  else {
		 return true;
	  }
	  
	  keychar = String.fromCharCode(key);
  
	  if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
		 return true;
	  }
	  else if ((("0123456789").indexOf(keychar) > -1)) {
		 return true;
	  }
	  else if (decimal && (keychar == ".")) { 
		return true;
	  }
	  else
		 return false;
}


function checkemail(email){
	var re = /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i;
	if(trim_text(email) !="") {
		if (!re.test(email))
		{
			return false;
		}
	}	
	return true;
}