//Global XMLHTTP Request object
var XmlHttp;

var prp_id;

var prpid;

var trns_type;

var errMSG;

var RES;

var tmp;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}

//Gets called when country combo box selection changes
function sendMail(prp_id,trns_type,process) 
{

if ((document.getElementById(prp_id+'sendemail').style.cursor=="default") || (document.getElementById(prp_id+'sendsms').style.cursor=="default") || (document.getElementById(prp_id+'mailsms').style.cursor=="default") ) 
{
alert("Already Sent The Information!!!");
return;
}

prpid=prp_id;

	tmp=prp_id+"txtName";
	var name=document.getElementById(tmp);

	tmp=prp_id+"country";
	var countryList=document.getElementById(tmp);
    var country =countryList.options[countryList.selectedIndex].value;

	tmp=prp_id+"lcftxtemail";
	var mailId=document.getElementById(tmp);
        
	tmp=prp_id+"lcftxtmobile";
        var mobileNo=document.getElementById(tmp); 

	tmp=prp_id+"lcftacomment";
        var comments=document.getElementById(tmp);


if (process==""){ 
process="3";
}

//validation

RES="true"

errMSG="";
errMSG="Please select / Provide the following details"+'\n'+'\n';
	if ((name.value=="Your Name*") || (name.value=="") ) 
	{
		errMSG=errMSG  +"* Contact Name Should Not Be Empty \n";
		RES="false";
	}
	
    // alert(process);
  
if(process=="1")
{
if((mailId.value=="Email*")|| (mailId.value==""))
{
errMSG=errMSG  + "* Email Should Not Be Empty";
RES="false";
}
}

  if(process=="2")
     {
      if ((mobileNo.value=="Mobile Number")|| (mobileNo.value=="")) 
          {
              errMSG=errMSG + "* Mobile Number Should Not Be Empty";
              RES="false";
          }
     }
if(process=="3")
{

if  ((mailId.value=="Email*") || (mailId.value=="") || (mobileNo.value=="Mobile Number") || (mobileNo.value==""))
	{ 
		errMSG=errMSG + "* Both Email And Mobile Number Should Not Be Empty";
		RES="false";
	}
}

    if   (mailId.value!="Email*") {
            var vemail;
            vemail=emailvalidation(mailId);
            
            if (!vemail) {
             
        		errMSG=errMSG + "* Enter Valid Email Id";
		        RES="false";
             }
    }

// * Email Validation    

function emailvalidation(field1)
{
var mvalid="yes";
var emailchar ="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@_.-"

if (field1.value.length > 0)
{
	for(var emc=0;emc<field1.value.length;emc++)
	{
	   if(emailchar.indexOf(field1.value.charAt(emc))==-1)
	   {
			mvalid="no"
		}
	}
	if (field1.value.indexOf("@") == -1 || field1.value.indexOf(".")==-1)
	{
		mvalid = "no"
	}
	if (mvalid=="no")
	{
	   return false;
   }
   else
   {
   		return true;
   }   
}
}
// * Email Validation End
	if (RES=="true")
	{
	}
	else
	{
	alert(errMSG);
	return;
	}
	
	document.getElementById(prpid+'sendemail').style.cursor="default";
	document.getElementById(prpid+'sendsms').style.cursor="default";
	document.getElementById(prpid+'mailsms').style.cursor="default";
	document.getElementById(prp_id+'sendemail').src="images/sendemail2.gif";
	document.getElementById(prp_id+'sendsms').src="images/sendsms2.gif";
	document.getElementById(prp_id+'mailsms').src="images/mailsms2.gif";
	
		// Lading the loader image here
    document.getElementById(prpid+'imgloader').innerHTML="<table cellSpacing=0 cellPadding=0 border=0 ><tr><td><img src=images/loader1.gif width =32 height=32></td></tr></table>";
	
	// URL to get states for a given country
	var requestUrl = AjaxServerPageName + "?process="+process+"&trns_type="+trns_type+"&prp_id=" + prp_id + "&name=" + name.value + "&mailid=" +mailId.value+"&mobileno="+mobileNo.value+"&comments="+comments.value+"&cnt="+country;

	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse;

		//Initializes the request object with GET(METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		
		//Sends the request to server
		XmlHttp.send(null);

 //document.getElementById(prp_id+"lcftacomment").value=requestUrl ;
	}
	// document.getElementById(prp_id+'imgloader').innerHTML="";
}
//Called when response comes back from server
function HandleResponse()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{	
		var xmlDoc=XmlHttp.responseXML.documentElement;
		
		var result=xmlDoc.getElementsByTagName("status")[0].childNodes[0].nodeValue

		if (result==0) {

		//If process success

         document.getElementById(prpid+'imgloader').innerHTML="";
                 
		alert("Thanks For Chosen Gold Earth Properties. Our People Will Communicate Soon!!!");
		}
		else
		{	
		//If process fail
		    document.getElementById(prpid+'imgloader').innerHTML="";
	document.getElementById(prpid+'sendemail').style.cursor="hand";
	document.getElementById(prpid+'sendsms').style.cursor="hand";
	document.getElementById(prpid+'mailsms').style.cursor="hand";
	document.getElementById(prpid+'sendemail').src="images/sendemail1.gif";
	document.getElementById(prpid+'sendsms').src="images/sendsms1.gif";
	document.getElementById(prpid+'mailsms').src="images/mailsms1.gif";
		   	alert(xmlDoc.getElementsByTagName("remarks")[0].childNodes[0].nodeValue);
       	}
		}
		else
		{
		document.getElementById(prpid+'imgloader').innerHTML="";
		// If activate the send Button
	document.getElementById(prpid+'sendemail').style.cursor="hand";
	document.getElementById(prpid+'sendsms').style.cursor="hand";
	document.getElementById(prpid+'mailsms').style.cursor="hand";
	document.getElementById(prpid+'sendemail').src="images/sendemail1.gif";
	document.getElementById(prpid+'sendsms').src="images/sendsms1.gif";
	document.getElementById(prpid+'mailsms').src="images/mailsms1.gif";
		alert("There was a problem retrieving data from the server." );
		}
	}
}
