// JavaScript Document
function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);		
	else 
		countfield.value = maxlimit - field.value.length;
}
function checkAlphabetic(textboxvalue){
	var x = textboxvalue;
	x = x.replace(/^\s+|\s+$/g,""); // strip all leading and trailing spaces
	x = x.replace(/\s{2,}/g," "); // replace multiple spaces with one space
	var ch=1;
	if (/[^a-z\s\-\']/gi.test(x)) { // only letters space hyphen apostophe allowed - Smith-Jones O'Flanaghan
		ch=0;
	}
	return ch;
} 
function checkphone(textboxvalue){
	var x = textboxvalue;
	x = x.replace(/^\s+|\s+$/g,""); // strip all leading and trailing spaces
	x = x.replace(/\s{2,}/g," "); // replace multiple spaces with one space
	var ch=1;
	if (/[^0-9\s\-\(\)\+\']/gi.test(x)) { // only letters space hyphen apostophe allowed - Smith-Jones O'Flanaghan
		ch=0;
	}
	return ch;
} 
function checkquickquotefrm(){
	var doc=document.quickfrm;
	if(!doc.enq_name.value.length || doc.enq_name.value=='Name'){
		alert("Please enter your Name!");
		doc.enq_name.value='';
		doc.enq_name.focus();
		return false;
	}
	if(doc.enq_name.value.length>0){
		var check= checkAlphabetic(doc.enq_name.value);
		//alert(check);
		if(check==0){
			alert("You can use Letters, Space, Hyphen, Apostrophe Only!");
			doc.enq_name.value='';
			doc.enq_name.focus();
			return false;		
		}
	}
	if(!doc.enq_email.value.length || doc.enq_email.value=='Email'){
		alert("Please enter your Email!");
		doc.enq_email.value='';
		doc.enq_email.focus();
		return false;
	}
	if(doc.enq_email.value.length>0){
		var emailPatterns = [
		/.+@.+\..+$/i,
		/^\w.+@\w.+\.[a-z]+$/i,
		/^\w[-_a-z~.]+@\w[-_a-z~.]+\.[a-z]{2}[a-z]*$/i,
		/^\w[\w\d]+(\.[\w\d]+)*@\w[\w\d]+(\.[\w\d]+)*\.[a-z]{2,7}$/i
		];
		if (!emailPatterns[0].test(doc.enq_email.value)){
			alert("Please enter your Email correctly!");
			doc.enq_email.value='';
			doc.enq_email.focus();
			return false;
		}
	}
	if(!doc.enq_phone.value.length  || doc.enq_phone.value=='Phone'){
		alert("Please enter your Phone/Mobile!");
		doc.enq_phone.value='';
		doc.enq_phone.focus();
		return false;
	}
	if(doc.enq_phone.value.length>0){
		var check= checkphone(doc.enq_phone.value);
		//alert(check);
		if(check==0){
			alert("Please enter your Phone/Mobile in numeric format!");
			doc.enq_phone.value='';
			doc.enq_phone.focus();
			return false;		
		}
	}
	if(!doc.enq_description.value.length  || doc.enq_description.value=='Comment'){
		alert("Please enter your Comments/Requirements!");
		doc.enq_description.value='';
		doc.enq_description.focus();
		return false;
	}
}
function checkcontactfrm(){
	var doc=document.contactfrm;
	if(!doc.enq_name.value.length){
		alert("Please enter your Name!");
		doc.enq_name.focus();
		return false;
	}
	if(doc.enq_name.value.length>0){
		var check= checkAlphabetic(doc.enq_name.value);
		//alert(check);
		if(check==0){
			alert("You can use Letters, Space, Hyphen, Apostrophe Only!");
			doc.enq_name.focus();
			return false;		
		}
	}
	if(!doc.enq_email.value.length){
		alert("Please enter your Email!");
		doc.enq_email.focus();
		return false;
	}
	if(doc.enq_email.value.length>0){
		var emailPatterns = [
		/.+@.+\..+$/i,
		/^\w.+@\w.+\.[a-z]+$/i,
		/^\w[-_a-z~.]+@\w[-_a-z~.]+\.[a-z]{2}[a-z]*$/i,
		/^\w[\w\d]+(\.[\w\d]+)*@\w[\w\d]+(\.[\w\d]+)*\.[a-z]{2,7}$/i
		];
		if (!emailPatterns[0].test(doc.enq_email.value)){
			alert("Please enter your Email correctly!");
			doc.enq_email.focus();
			return false;
		}
	}
	if(!doc.countrycode.value.length){
		alert("Please enter Country code!");
		doc.countrycode.focus();
		return false;
	}
	if(isNaN(doc.countrycode.value)){
		alert("Please enter Country code in numeric format!");
		doc.countrycode.focus();
		return false;
	}
	if(!doc.areacode.value.length){
		alert("Please enter Area code!");
		doc.areacode.focus();
		return false;
	}
	if(isNaN(doc.areacode.value)){
		alert("Please enter Area code in numeric format!");
		doc.areacode.focus();
		return false;
	}
	if(!doc.enq_phone.value.length){
		alert("Please enter your Phone/Mobile!");
		doc.enq_phone.focus();
		return false;
	}
	if(isNaN(doc.enq_phone.value)){
		alert("Please enter your Phone/Mobile in numeric format!");
		doc.enq_phone.focus();
		return false;
	}
	if(!doc.enq_industry.value.length || doc.enq_industry.value==0){
		alert("Please select Industry!");
		doc.enq_industry.focus();
		return false;
	}
	if(doc.enq_country.value==""){
		alert("Please select Country!");
		doc.enq_country.focus();
		return false;
	}
	if(doc.enq_state.value==0 || !doc.enq_state.value.length){
		alert("Please select State!");
		doc.enq_state.focus();
		return false;
	}
	if(doc.enq_state.value.length>0){
		var check= checkAlphabetic(doc.enq_state.value);
		//alert(check);
		if(check==0){
			alert("You can use Letters, Space, Hyphen, Apostrophe Only!");
			doc.enq_state.focus();
			return false;		
		}
	}
	if(doc.enq_city.value.length>0){
		var check= checkAlphabetic(doc.enq_city.value);
		//alert(check);
		if(check==0){
			alert("You can use Letters, Space, Hyphen, Apostrophe Only!");
			doc.enq_city.focus();
			return false;		
		}
	}
	if(!doc.enq_description.value.length){
		alert("Please enter your Message!");
		doc.enq_description.focus();
		return false;
	}
	/*if(!doc.code.value.length){
		alert("Please enter Security code!");
		doc.code.focus();
		return false;
	}*/
}
