function EmptyTextBox(data,fieldName)
{
	if(trim(data.value)=="")
	{
		document.getElementById('errorMsg').innerHTML="Please enter "+fieldName;
		data.value="";
		data.focus();
		return false;
	}
	
	return true;

}

// Removes leading whitespaces
function LTrim( value ) 
{
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) 
{
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) 
{
	
	return LTrim(RTrim(value));
	
}
function PhoneValidation(phone)
{
       var a=phone.value;
       if(a=="")
       {
               alert("please Enter the Contact Number");
               phone.focus();
               return false;
       }
       if(isNaN(a))
       {
                       alert("Enter the valid Mobile Number(Like : 9566137117)");
                       phone.focus();
                       return false;
       }
       if(a.length!=10)
       {
                               alert("Your Mobile Number must be 1 to 10 Integers");
                               phone.focus();
                               return false;
       } return true;
}

function ValidateEmail(email,emailvalid)
{
	var emailID=email;
	
	if ((emailID.value==null)||(emailID.value==""))
	{
		
		document.getElementById(emailvalid).innerHTML="Please Enter your Email ID";
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value)==false)
	{
		emailID.value="";
		emailID.focus();
		return false;
	}
	return true;
} 
//function used in validating email
function echeck(str) 
{

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){;
		   document.getElementById('errorMsg').innerHTML="Invalid E-mail ID";
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   document.getElementById('errorMsg').innerHTML="Invalid E-mail ID";
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    document.getElementById('errorMsg').innerHTML="Invalid E-mail ID";
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    document.getElementById('errorMsg').innerHTML="Invalid E-mail ID";
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    document.getElementById('errorMsg').innerHTML="Invalid E-mail ID";
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    document.getElementById('errorMsg').innerHTML="Invalid E-mail ID";
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    document.getElementById('errorMsg').innerHTML="Invalid E-mail ID";
		    return false;
		 }

 		 return true;					
}
function validate_queryform()
{
	var checkValidation =1;
	if(ValidateEmail(document.getElementById('email'),'errorMsg')==false)
		{
			checkValidation=0;
		}
	if(checkValidation==0)
		{
			return false;
		}
	
	return true;
}
function validateContactUs()
{
	//alert('heloo');
	
	if(EmptyTextBox(document.getElementById('fname'),'First Name') == false)
		{
			return false;
		}
	if(ValidateEmail(document.getElementById('email'),'errorMsg')==false)
		{
			return false;
		}
	if(EmptyTextBox(document.getElementById('message'),'Question/Query') == false)
		{
			return false;
		}
	return true;
	
}
