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.Inquiry.vName.value)=="")
	{
		alert("Please Enter Name");
		document.Inquiry.vName.focus();
		return false;
	}
	if(Trim(document.Inquiry.vEmail.value)=="")
	{
		alert("Please Enter Email");
		document.Inquiry.vEmail.focus();
		return false;
	}
	if (!isValidEmail(document.Inquiry.vEmail.value))
	{	
					document.Inquiry.vEmail.focus();
					return false;	
	}
	if(document.Inquiry.vCountry.selectedIndex ==0)
	{
		alert("Please Select Country Name From List");
		document.Inquiry.vCountry.focus();
		return false;
	}
	if(Trim(document.Inquiry.vPhone.value)=="")
	{
		alert("Please Enter Phone");
		document.Inquiry.vPhone.focus();
		return false;
	}
	if(!number(document.Inquiry.vPhone.value,document.Inquiry.vPhone.value.length))
	{
		alert("Please Enter Valid Phone Number");
		document.Inquiry.vPhone.focus();
		return false;
	}
/*		
	if(document.Inquiry._vCapt_INQ.value=="")
	{
		alert("Please enter the verification code");
		document.Inquiry._vCapt_INQ.focus();
		return false;	
	}
	if(document.Inquiry._vCapt_INQ.value.length<5)
	{
		alert("Please enter the excatly 5 letter verification code i.e. shown in image.");
		document.Inquiry._vCapt_INQ.focus();
		return false;
	}
	
	CheckValidationText();
	return false;
	*/
}	


function CheckValidationText()
{ 
	var vText;
	if(document.getElementById('capt'))
		vText = document.getElementById('capt').value;
	else
		vText = "";
	
	var url = "checkcaptcha.html?paraValid="+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");
						return false;
					}
					else
					{
						document.Inquiry.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");
							document.Inquiry._vCapt_INQ.focus();
							return false;
						}
						else
						{
							document.Inquiry.submit();
						}	
						
					}
					
				}
			}	
    		http.send()
    	}
  	}
}