
function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}
function number(value,length){
	
	chk1="1234567890";
	for(i=0;i<length;i++)
	{
		ch1=value.charAt(i);
		rtn1=chk1.indexOf(ch1);
		if(rtn1==-1)
			return false;
	}
	return true;
}


		function validcheck()
		{		
			if(Trim(document.contactus.vName.value)=="")
			{
				alert("Please Enter Name");
				document.contactus.vName.focus();
				return false;
			}
			if(Trim(document.contactus.vPhone.value)=="")
			{
				alert("Please Enter Phone Number");
				document.contactus.vPhone.focus();
				return false;
			}
			
			if(!number(document.contactus.vPhone.value,document.contactus.vPhone.value.length))
			{
				alert("Please Enter Valid Phone Number");
				document.contactus.vPhone.focus();
				return false;
			}
			/*
			if(document.contactus.vCountry.value.length < 1)
			{
				alert("Please select country");
				document.contactus.vCountry.focus();
				return false;
			}
			*/
			
			
			if(document.contactus.vEmail.value.length < 1)
			{
				alert("Please Enter Email");
				document.contactus.vEmail.focus();
				return false;
			}
			if(!isValidEmail(document.contactus.vEmail.value))
			{
				document.contactus.vEmail.focus();
				return false;	
				
			}
			
			
			if(Trim(document.contactus.vSubject.value)=="")
			{
				alert("Please Enter subject");
				document.contactus.vSubject.focus();
				return false;
			}
			if(Trim(document.contactus.vMessage.value)=="")
			{
				alert("Please Enter Message");
				document.contactus.vMessage.focus();
				return false;
			}
			/*
			if(document.contactus._vCapt_CONTACT.value=="")
			{
				alert("Please enter the verification code");
				document.contactus._vCapt_CONTACT.focus();
				return false;	
			}
			if(document.contactus._vCapt_CONTACT.value.length<5)
			{
				alert("Please enter the excatly 5 letter verification code i.e. shown in image.");
				document.contactus._vCapt_CONTACT.focus();
				return false;
			}
			*/
			
								
			//CheckValidationText();
				
			//	return false;
			
		}
		
		function CheckValidationText()
		{ 
			var vText;
			if(document.getElementById('_vCapt_CONTACT'))
				vText = document.getElementById('_vCapt_CONTACT').value;
			else
				vText = "";
				
			var url = "checkcaptcha.html?paraValid="+vText;
			//var url = "validate.php?vText="+vText;
			
			if (window.XMLHttpRequest)
			{
				http=new XMLHttpRequest()
				http.open("GET",url,true)
				http.onreadystatechange=function (){
					if (http.readyState == 4) 
					{	
						isWorking = false;
						if (http.responseText.indexOf('invalid') == -1) 
						{
							var xmlDocument = http.responseXML;
							var existId = xmlDocument.getElementsByTagName('msg').item(0).firstChild.data;
							if(existId == "0"){
								alert("Verification Code is not Valid ! Please Try Again");
								document.contactus._vCapt_CONTACT.focus();
								return false;
							}
							else
							{
								document.contactus.submit();
							}	
								
						}
					}
				}
				http.send(null)
			}
			// code for IE
			else if (window.ActiveXObject)
			{
				http=new ActiveXObject("Microsoft.XMLHTTP")
				if (http)
				{
					http.open("GET",url,true)
					http.onreadystatechange=function (){
						if (http.readyState == 4) 
						{	
							isWorking = false;
							if (http.responseText.indexOf('invalid') == -1) 
							{
								var xmlDocument = http.responseXML; 
								var existId  = xmlDocument.getElementsByTagName('msg').item(0).firstChild.data;
								if(existId == "0")
								{
									alert("Verification Code is not Valid ! Please Try Again");
									return false;
								}
								else
								{
									document.contactus.submit();
								}	
								
							}
							
						}
					}	
					http.send()
				}
			}
		}	

