/******************************************************************************************



Function Name : f_isEmpty



Input : String 



Output : true or false



Description : This function returns true if string is not empty o.w. returns false.



******************************************************************************************/



function f_isEmpty(msStr)



{   







    var   msTemp=msStr;



    for(mnI=0;mnI<msTemp.length;mnI++)



    {



     // find out ascii value of each character   



     temp=msTemp.charCodeAt(mnI);



    if ( temp != 10 &&  temp != 13 &&  temp != "@" &&  temp != 32)



                    {



                        return false;



                    }



    }



    msStr.value="";



    return true;



}







/******************************************************************************************



Function Name : f_isNumber



Input : String 



Output : true or false



Description : This function returns true if string is numeric o.w. returns false.



******************************************************************************************/



function f_isNumber(str)



{



	nstr = '0123456789';



    err = 0;



    for (f=0;f<str.length;f++){



      if (nstr.indexOf(str.charAt(f)) == -1) err++;



    }



    if (err!=0) return false;



    else return true;



}







/******************************************************************************************



Function Name : f_isFloatNumber



Input : String 



Output : true or false



Description : This function returns true if string is numeric o.w. returns false.



******************************************************************************************/



function f_isFloatNumber(sStr)



{



var msStr = "0123456789.";



var d1 = sStr.indexOf(".");



var d2 = sStr.lastIndexOf(".");







if ((d1 >= 0 && d2 >= 0) && d1 != d2)



{



return false;



}



for (i=0;i<sStr.length;i++)



{



if ( msStr.indexOf(sStr.charAt(i)) == -1 )



{



return false; // Not Numeric....



}



}



return true; // string is Numeric....



}







/******************************************************************************************



Function Name : f_isValidPhone



Input : String i.e. an email address



Output : true or false



Description : This function returns true if email id is valid o.w. returns false.



******************************************************************************************/



function IsValidphone(Phone)



{



 var list="0123456789- + _.()";



  var str = Phone



  if(str.indexOf(' ')==0) return false;



  for(var i=0; i<str.length; i++){



	if(list.indexOf(str.charAt(i))<0){      



      return false;



	}



   }



	return true;



 }







function IsValidName(Name)



{



  var list="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ";



  var str = Name



  if(str.indexOf(' ')==0) return true;



  for(var i=0; i<str.length; i++){



	if(list.indexOf(str.charAt(i))<0){     



      return true;



	}



   }



	return false;



 }



 



/******************************************************************************************



Function Name : Check_email



Input : String i.e. an email address



Output : true or false



Description : This function returns true if email id is valid o.w. returns false.



******************************************************************************************/



function Check_email(emailStr) 



{



	var emailPat=/^(.+)@(.+)$/



	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"



	var validChars="\[^\\s" + specialChars + "\]"



	var quotedUser="(\"[^\"]*\")"



	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/



	var atom=validChars + '+'



	var word="(" + atom + "|" + quotedUser + ")"



	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")



	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")



	var matchArray=emailStr.match(emailPat)



	



	if (matchArray==null) 



	{  



		//alert("Email address seems incorrect (check @ and .'s)")



		return false



	}



	var user=matchArray[1]



	var domain=matchArray[2]



	if (user.match(userPat)==null) 



	{



	    //alert("The username doesn't seem to be valid email.")



	    return false



	}



	var IPArray=domain.match(ipDomainPat)



	if (IPArray!=null) 



	{  



		  for (var i=1;i<=4;i++) 



		  {



		    if (IPArray[i]>255) 



			{



		       // alert("Destination IP address is invalid!")



				return false



		    }



	    }



	    return true



	}



	var domainArray=domain.match(domainPat)



	if (domainArray==null) 



	{



		//alert("The domain name doesn't seem to be valid.")



	    return false



	}



	var atomPat=new RegExp(atom,"g")



	var domArr=domain.match(atomPat)



	var len=domArr.length



	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 



	{   



	   //alert("The address must end in a three-letter domain, or two letter country.")



	   return false



	}



	if (len<2) 



	{



	   var errStr="This address is missing a hostname!"



	  // alert(errStr)



	   return false



	}



	return true;



}



/******************************************************************************************/















function checkName()



{



	var lstrpath=document.contactus;



	var rstr=true;



	var name=document.getElementById("name");



	name.className="nomessage";



 if(f_isEmpty(lstrpath.yourname.value)){



	name.innerHTML="Please Enter First Name <br/>";



	name.className="message";



	rstr=false;



 }



 else if(IsValidName(lstrpath.yourname.value)){



	name.innerHTML="Please Enter Valid First Name";



	name.className="messageInvalid";



	rstr=false;



 }



 return rstr;



}



function checkLastName()



{



	var lstrpath=document.contactus;



	var rstr=true;



	var name=document.getElementById("name");



	var lastname=document.getElementById("lastname");



	var email=document.getElementById("email");



	var comments=document.getElementById("comments");



	lastname.className="nomessage";



 if(f_isEmpty(lstrpath.yourlastname.value)){



	lastname.innerHTML="Please Enter Your Last Name<br/>";



	lastname.className="message";



	rstr=false;



 }



 else if(IsValidName(lstrpath.yourlastname.value)){



	lastname.innerHTML="Please Enter Valid Last Name";



	lastname.className="messageInvalid";



	rstr=false;



 }



 return rstr;



}



function checkeMail()



{



	var lstrpath=document.contactus;



	var rstr=true;



	var name=document.getElementById("name");



	var lastname=document.getElementById("lastname");



	var email=document.getElementById("email");



	var comments=document.getElementById("comments");



	email.className="nomessage";



 if(f_isEmpty(lstrpath.youremail.value)){



	email.innerHTML="Please Enter Your Email <br/>";



	email.className="message";



	rstr=false;



 }



 else if(!Check_email(lstrpath.youremail.value)){



	email.innerHTML="Please Enter Valid Email";



	email.className="messageInvalid";



	rstr=false;



 }



 return rstr;



}



function checkComments()



{



	var lstrpath=document.contactus;



	var rstr=true;



	var name=document.getElementById("name");



	var lastname=document.getElementById("lastname");



	var email=document.getElementById("email");



	var comments=document.getElementById("comments");



	comments.className="nomessage";



 if(f_isEmpty(lstrpath.yourcomments.value)){



	comments.innerHTML="Please Enter Your Comments <br/>";



	comments.className="message";



	rstr=false;



 }



/* else if(IsValidName(lstrpath.yourcomments.value)){



	comments.innerHTML="Please Enter Valid Comments";



	comments.className="messageInvalid";



	rstr=false;



 }*/



 return rstr;



}

function checkPhone()



{



	var lstrpath=document.contactus;



	var rstr=true;



	var phone=document.getElementById("phone");



	phone.className="nomessage";



 if(f_isEmpty(lstrpath.yourphone.value)){



	phone.innerHTML="Please Enter Your Phone Number <br/>";



	phone.className="message";



	rstr=false;



 }



 else if(!IsValidphone(lstrpath.yourphone.value)){



	phone.innerHTML="Please Enter  Phone Number";



	phone.className="messageInvalid";



	rstr=false;



 }



 return rstr;



}

function checkCity()



{



	var lstrpath=document.contactus;



	var rstr=true;



	var city=document.getElementById("city");



	city.className="nomessage";



 if(f_isEmpty(lstrpath.yourcity.value)){



	city.innerHTML="Please Enter Your City,State <br/>";



	city.className="message";



	rstr=false;



 }



  return rstr;



}

function checkCountry()



{



	var lstrpath=document.contactus;



	var rstr=true;



	var country=document.getElementById("country");



	country.className="nomessage";



 if(f_isEmpty(lstrpath.yourcountry.value)){



	country.innerHTML="Please Enter Your Country <br/>";



	country.className="message";



	rstr=false;



 }



  return rstr;



}

function checkCaptcha()



{



	var lstrpath=document.contactus;



	var rstr=true;



	var CAPTCHA=document.getElementById("CAPTCHA");



	CAPTCHA.className="nomessage";



 if(f_isEmpty(lstrpath.strCAPTCHA.value)){



	CAPTCHA.innerHTML="Please Enter Verification Code Below. <br/>";



	CAPTCHA.className="message";



	rstr=false;



 }



  return rstr;



}



function validate()



{



	



	var rstr=true;



	var loading = document.getElementById("loading");



	if(rstr) rstr=checkName(); else checkName();



	if(rstr) rstr=checkLastName(); else checkLastName();



	if(rstr) rstr=checkeMail(); else checkeMail();



	if(rstr) rstr=checkComments(); else checkComments();



	if(rstr) rstr=checkComments(); else checkPhone();



	if(rstr) rstr=checkComments(); else checkCity();



	if(rstr) rstr=checkComments(); else checkCountry();



	if(rstr) rstr=checkCaptcha(); else checkCaptcha();





	if(rstr)



	{



		loading.className="loading";



	}







 return rstr;







}











///////////////////////







   function thankyou()



   {



	   	document.getElementById('loading').innerHTML="<br/><br/>Thank You for showing interest!!!<br/> Our editor will get back to you vey soon.<br/><br/><br/><br/>"



   }
