function trimSpace(x)
{
	var emptySpace = / /g;
	var trimAfter = x.replace(emptySpace,"");
	return(trimAfter);
}


function checkAlpha(x)
{
	pcode=x.toUpperCase();
		var CharArr="ABCDEFGHIJKLMNOPQRSTUVWXYZ ";

		var IsNumber=true;
	var Char1;
	for (i = 0; i < pcode.length ; i++) 
    {
    	Char1 = pcode.charAt(i);
    	//alert(Char1);
    	if (CharArr.indexOf(Char1) == -1)
    	{
    		IsNumber = false;
    	}
    }

 if (IsNumber == false)
    {
    	return IsNumber;
    }
}
function ValidateEmail(str) {

	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID");
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID");
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail ID");
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail ID");
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail ID");
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail ID");
	    return false;
	 }

	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail ID");
	    return false;
	 }

	 return true;
}

function validate()
{
	var s,checkat,checdot
	//s=trimSpace(document.form1.email_f.value);
	//checkat=s.indexOf('@')
	//checkdot=s.indexOf('.')
	
	if(trimSpace(document.form1.nature.value).length==0)
	{
		alert("Please select Nature of Employment");
		document.form1.nature.focus();
		return false;
	}
	else if(trimSpace(document.form1.title.value).length==0)
	{
		alert("Please select title");
		document.form1.title.focus();
		return false;
	}
		else if(trimSpace(document.form1.fname_f.value).length==0)
	{
		alert("Please enter your First Name");
		document.form1.fname_f.focus();
		return false;
	}
		else if(checkAlpha(document.form1.fname_f.value)==false)
	{
		alert("Name should be in letters only");
		document.form1.fname_f.focus();
	}


	else if ((ValidateEmail(document.form1.email_f.value)==false))
	{
		document.form1.email_f.focus();
		return false;
	}
	
		else if(trimSpace(document.form1.post_code_f.value).length==0)
	{
		alert("Please enter your Postal Code");
		document.form1.post_code_f.focus();
		return false;
	}
		else if((trimSpace(document.form1.post_code_f.value).length < 5))
	{
		alert("Please enter valid Postal Code");
		document.form1.post_code_f.focus();
		return false;
	}

		else if(trimSpace(document.form1.hm_phone_f.value).length==0)
	{
		alert("Please enter your Residence Phone Number");
		document.form1.hm_phone_f.focus();
		return false;
	}
		else if((trimSpace(document.form1.hm_phone_f.value).length < 6 || isNaN(document.form1.hm_phone_f.value)))
	{
		alert("Phone number must be in Numeric Value");
		document.form1.hm_phone_f.focus();
		return false;
	}
	
	else
	{
	document.form1.submit();
	return true;
	}
	
}

//VALIDATION FOR QUICK HOME PAGE FORM
function quickform()
{
	var s,checkat,checdot
	//s=trimSpace(document.quickform.email_f.value);
	//checkat=s.indexOf('@')
	//checkdot=s.indexOf('.')
	
	if(trimSpace(document.quickform.name.value).length==0)
	{
		alert("Please enter your Name");
		document.quickform.name.focus();
		return false;
	}
		else if(checkAlpha(document.quickform.name.value)==false)
	{
		alert("Name should be in letters only");
		document.quickform.name.focus();
	}
	else if(trimSpace(document.quickform.company.value).length==0)
	{
		alert("Please enter your Company Name");
		document.quickform.company.focus();
		return false;
	}
		else if(checkAlpha(document.quickform.company.value)==false)
	{
		alert("Company Name should be in letters only");
		document.quickform.company.focus();
	}
	else if ((ValidateEmail(document.quickform.email.value)==false))
	{
		document.quickform.email.focus();
		return false;
	}
	else
	{
	document.quickform.submit();
	return true;
	}
	
}

//VALIDATION FOR NEWSLETTER REGISTRATION
function newletter()
{
	var s,checkat,checdot
	//s=trimSpace(document.form1.email_f.value);
	//checkat=s.indexOf('@')
	//checkdot=s.indexOf('.')
	
	if(trimSpace(document.form1.name.value).length==0)
	{
		alert("Please enter your Name");
		document.form1.name.focus();
		return false;
	}
		else if(checkAlpha(document.form1.name.value)==false)
	{
		alert("Name should be in letters only");
		document.form1.name.focus();
	}
	else if(trimSpace(document.form1.company.value).length==0)
	{
		alert("Please enter your Company Name");
		document.form1.company.focus();
		return false;
	}
		else if(checkAlpha(document.form1.company.value)==false)
	{
		alert("Company Name should be in letters only");
		document.form1.company.focus();
	}
	else if ((ValidateEmail(document.form1.email.value)==false))
	{
		document.form1.email.focus();
		return false;
	}
	else
	{
	document.form1.submit();
	return true;
	}
	
}

function newletter1()
{
	var s,checkat,checdot
	//s=trimSpace(document.form1.email_f.value);
	//checkat=s.indexOf('@')
	//checkdot=s.indexOf('.')
	
	if(trimSpace(document.form2.name1.value).length==0)
	{
		alert("Please enter your Name");
		document.form2.name1.focus();
		return false;
	}
		else if(checkAlpha(document.form2.name1.value)==false)
	{
		alert("Name should be in letters only");
		document.form2.name1.focus();
	}
	else if(trimSpace(document.form2.company1.value).length==0)
	{
		alert("Please enter your Company Name");
		document.form2.company1.focus();
		return false;
	}
		else if(checkAlpha(document.form2.company1.value)==false)
	{
		alert("Company Name should be in letters only");
		document.form2.company1.focus();
	}
	else if ((ValidateEmail(document.form2.email1.value)==false))
	{
		document.form2.email1.focus();
		return false;
	}
	else
	{
	document.form2.submit();
	return true;
	}
	
}
/////////////
function quotevalid()
{
	if(trimSpace(document.quoteform.comments.value).length==0)
	{
		alert("Please write how do you hear about us.");
		document.quoteform.comments.focus();
		return false;
	}
	if(trimSpace(document.quoteform.company_name.value).length==0)
	{
		alert("Please write your company name.");
		document.quoteform.company_name.focus();
		return false;
	}
	if(checkAlpha(document.quoteform.company_name.value)==false)
	{
		alert("Company Name should be in letters only");
		document.quoteform.company_name.focus();
	}
	if(trimSpace(document.quoteform.contact.value).length==0)
	{
		alert("Please write your contact details.");
		document.quoteform.contact.focus();
		return false;
	}
	if(trimSpace(document.quoteform.email.value).length==0)
	{
		alert("Please write your email id.");
		document.quoteform.email.focus();
		return false;
	}
	if ((ValidateEmail(document.quoteform.email.value)==false))
	{
		document.quoteform.email.focus();
		return false;
	}
	if(trimSpace(document.quoteform.phone.value).length==0)
	{
		alert("Please write your phone number.");
		document.quoteform.phone.focus();
		return false;
	}
	if(isNaN(document.quoteform.phone.value))
	{
		alert("Phone number should be numeric.");
		document.quoteform.phone.focus();
		return false;
	}
	if(trimSpace(document.quoteform.city.value).length==0)
	{
		alert("Please write city.");
		document.quoteform.city.focus();
		return false;
	}
	if(checkAlpha(document.quoteform.city.value)==false)
	{
		alert("City Name should be in letters only");
		document.quoteform.city.focus();
	}
	if(trimSpace(document.quoteform.state.value).length==0)
	{
		alert("Please write state name.");
		document.quoteform.state.focus();
		return false;
	}
	if(checkAlpha(document.quoteform.state.value)==false)
	{
		alert("State Name should be in letters only");
		document.quoteform.state.focus();
	}
	
	return true;
}

///
function contactvalid()
{
	if(trimSpace(document.contact.department.value).length==0)
	{
		alert("Please select department.");
		document.contact.department.focus();
		return false;
	}
	if(trimSpace(document.contact.company_name.value).length==0)
	{
		alert("Please write your company name.");
		document.contact.company_name.focus();
		return false;
	}
	if(checkAlpha(document.contact.company_name.value)==false)
	{
		alert("Company Name should be in letters only");
		document.contact.company_name.focus();
	}
	if(trimSpace(document.contact.contact.value).length==0)
	{
		alert("Please write your contact details.");
		document.contact.contact.focus();
		return false;
	}
	
	if(trimSpace(document.contact.phone.value).length==0)
	{
		alert("Please write your phone number.");
		document.contact.phone.focus();
		return false;
	}
	if(isNaN(document.contact.phone.value))
	{
		alert("Phone number shold be numeric.");
		document.contact.phone.focus();
		return false;
	}
	if(trimSpace(document.contact.email.value).length==0)
	{
		alert("Please write your email id.");
		document.contact.email.focus();
		return false;
	}
	if ((ValidateEmail(document.contact.email.value)==false))
	{
		document.contact.email.focus();
		return false;
	}
	if(trimSpace(document.contact.comments.value).length==0)
	{
		alert("Please write comments.");
		document.contact.comments.focus();
		return false;
	}
	
	
	return true;
}


//////////

function validpopup()
{
	var s,checkat,checdot
	s=trimSpace(document.acceptfrm.emailid.value);
	checkat=s.indexOf('@')
	checkdot=s.indexOf('.')
	
	if(trimSpace(document.acceptfrm.name.value).length==0)
	{
		alert("Please enter your Name");
		document.acceptfrm.name.focus();
		return false;
	}
			else if(checkAlpha(document.acceptfrm.name.value)==false)
	{
		alert("Name should be in letters only");
		document.acceptfrm.name.focus();
	}

	else if ((ValidateEmail(document.acceptfrm.emailid.value)==false))
	{
		document.acceptfrm.emailid.focus();
		return false;
	}
	else
	{
	document.acceptfrm.submit();
	return true;
	}
	
}