var xmlHttp
function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
var urlname;
//alert(urlname);

var fname;
var email;
var Comments;
//var security_code;
var sec_code;
<!--var error = 1;-->

function get_mail_home(fname,email,Comments,sec_code)
{
	//fname=document.form1.fname.value;
	//email=document.form1.email.value;
	//phone=document.form1.phone.value;	
	//country=document.form1.country.value;
	//comments=document.form1.Comments.value;
			
	//alert("FRST NAME : " + fname);
	//alert("EMAL ID : " + email);
	//alert("PHONE : " + phone);
	//alert("COUNTRY : " + country);
	//alert("COMMENTS : " + comments);
	
	
	
	if (fname=='')
  	{
  	  //alert("You must enter your first name123.");
  	  //document.form1.fname.style.backgroundColor='red';
	  document.form1.fname.style.border='2px solid #FF0000';
	  document.form1.fname.focus();
  	  return false;
  	}
	if (fname=='Name')
	{
		document.form1.fname.style.border='2px solid #FF0000';
		//document.form1.fname.value='Please enter Name';
		document.form1.fname.focus();
      	return false
	}
  	else
  	{
	  document.form1.fname.style.border='1px solid #fff';
	  //alert('A');
	}	

	if (email=='Email')
	{
    	//alert("You must enter your email.");
    	//document.form1.email.style.backgroundColor='red';
		document.form1.email.style.border='2px solid #FF0000';
		document.form1.email.focus();
    	return false;
  	}
  	else
	{
		document.form1.email.style.border='1px solid #fff';
	}
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
  			var address = document.form1.email.value;
  		 	if(reg.test(address) == false) 
   			{	
				//alert('Invalid Email Address');
    			document.form1.email.style.border='2px solid #FF0000';
				document.form1.email.value='Invalid email Id';
				document.form1.email.focus();
      			return false;
			}
			else
			{	
				document.form1.email.style.border='1px solid #fff';
			}
  	if (Comments=='')
	{
   		//alert("You must enter the comments.");
    	//document.form1.Comments.style.backgroundColor='red';
		document.form1.Comments.style.border='2px solid #FF0000';
		document.form1.Comments.focus();
    	return false;
  	}
  	else
	{
		document.form1.Comments.style.border='1px solid #fff';
	}
	if(document.form1.code.value == "Enter Security Code" || document.form1.code.value == "")
	{
			document.form1.code.style.border='2px solid #FF0000';
			document.form1.code.value='Enter Security Code';
			document.form1.code.focus();
			return false;
	}
	else
	{
	    
		var url = 'captcheck.php?code=';
		///var params = '?code=';
		
		
        var captchaOK = 2;  // 2 - not yet checked, 1 - correct, 0 - failed
		function handleHttpResponse() 
		{
			if (xmlHttp1.readyState == 4) 
			{
				captchaOK = xmlHttp1.responseText;
				if(captchaOK != 1) 
				{
					alert('The entered code was not correct. Please try again');
					document.form1.code.style.border='2px solid #FF0000';
					document.form1.code.value='';
					document.form1.code.focus();
					return false;
				}
	
				xmlHttp=GetXmlHttpObject()
				if (xmlHttp==null)
 				{
 					alert ("Browser does not support HTTP Request")
 					return
 				}
//		alert('A');
		//alert("FRST NAME : " + fname);
	//alert("EMAL ID : " + email);
	//alert("comments : " + Comments);
	//alert("Security code : " + security_code);
	
		var url="mail_index.php";
		var query_string = "name="+fname+"&email="+email+"&Comments="+Comments+"&security_code="+sec_code
		//alert('url');
		//url=url+"?r="+str1
		//alert("URL :" + url);
	//alert (url)
//url=url+"&sid="+Math.random()
		xmlHttp.onreadystatechange=uvalues
		xmlHttp.open("POST",url,true)
		
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		//alert(query_string)
		xmlHttp.send(query_string)
		//alert ("a");
		document.form1.fname.value='';
		document.form1.email.value='';
		document.form1.Comments.value='';
			}
		
		}
	
        function checkcode(thecode) 
		{
			  xmlHttp1=new XMLHttpRequest();
			  xmlHttp1.open("POST", url + escape(thecode), true);
			 
			  xmlHttp1.onreadystatechange = handleHttpResponse;
			 xmlHttp1.send(null)
			  
			 
			 
        }
		 checkcode(document.form1.code.value);
		 //return false;

	}






		//	if (phone.length < 10)
//			  {
//      			//alert("Please enter valid number");
//				document.form1.phone.style.border='2px solid #FF0000';
//				document.form1.phone.value='Please enter a valid number';
//				document.form1.phone.focus();
//      			return false
//	  		}
//			else
//			{
//				document.form1.phone.style.border='1px solid #fff';
//				//document.form1.phone.focus();
//			}
  /*	if (security_code=='Security Code')
	{
   		//alert("You must enter the country.");
    	//document.form1.country.style.backgroundColor='red';
		document.form1.security_code.style.border='2px solid #FF0000';
		document.form1.security_code.focus();
    	return false;
  	}
	if (security_code!=sec_code)
	{
   		//alert("You must enter the sec_code.");
    	//document.form1.country.style.backgroundColor='red';
		document.form1.security_code.style.border='2px solid #FF0000';
		//alert("You must enter the valid string.");
		document.form1.security_code.value='Please enter a valid string';
		document.form1.security_code.focus();
		generate();
    	return false;
  	}
  	else
	{
		document.form1.security_code.style.border='1px solid #fff';
	}*/

	//alert("You must enter your comments.");
  //	if (Comments=='')
//	{
//   		//alert("You must enter the comments.");
//    	//document.form1.Comments.style.backgroundColor='red';
//		document.form1.Comments.style.border='2px solid #FF0000';
//		document.form1.Comments.focus();
//    	return false;
//  	}
//  	else
//	{
//		document.form1.Comments.style.border='1px solid #fff';
//	}
  	//return true;
	//else
	//{
	
		//document.form1.security_code.value='';
		//document.form1.sec_code.value='';
		//alert ("b");
		//window.open('thankyou.html','_self');
}

/*function generate() 
{
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 3;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	document.form1.sec_code.value = randomstring;
	document.form1.sec_code1.value = randomstring;
alert(randomstring);
}*/

//function show()
//{
//	alert("H"); 
//
//	//alert(str1);
//	//urlname = str1;
//
//	//new Function(url_name()); 
//
//	
////alert(sel_name)
////document.form1.txtname.value = form1.sel_name.options[form1.sel_name.options.selectedIndex].value
//}
//function url_name()
//{
//	document.getElementById('fname').value = urlname;
//}
function uvalues() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 	document.getElementById("f_name").innerHTML=xmlHttp.responseText 
	//alert("fsdfsd" );
	//window.open('thankyou.html?home','_self');
 } 
}
