// JavaScript Document
function checkemail(em)   //Email validation 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(em))
	return true
	else
	return false
}
function chkAppraisal() 
{
	//alert("enter");
	var missinginfo;
	missinginfo = "";
	
	if(Trim(document.getElementById("name").value)=="")
	{
		missinginfo += "\n     - Name ";
		document.getElementById("name").focus;
	}
	if(Trim(document.getElementById("address").value)=="")
	{
		missinginfo += "\n     - Address ";
		document.getElementById("address").focus;
	}
	if(Trim(document.getElementById("region").value)=="")
	{
		missinginfo += "\n     - State ";
		document.getElementById("region").focus;
	}
	if(Trim(document.getElementById("city").value)=="")
	{
		missinginfo += "\n     - City ";
		document.getElementById("city").focus;
	}
	if(Trim(document.getElementById("suburb1").value)=="")
	{
		missinginfo += "\n     - Suburb ";
		document.getElementById("suburb1").focus;
	}
	if(Trim(document.getElementById("country").value)=="")
	{
		missinginfo += "\n     - Country ";
		document.getElementById("country").focus;
	}
	if(Trim(document.getElementById("descript").value)=="")
	{
		missinginfo += "\n     - Message";
		document.getElementById("descript").focus;
	}
	if(document.getElementById("contact_email").value == "") 
	{
		missinginfo += "\n     - Email Id";
		document.getElementById("contact_email").focus();
	}
	if(document.getElementById("contact_email").value!="")
	{
		var emailcheck = checkemail(document.getElementById("contact_email").value);
		if(emailcheck==false)
			missinginfo += "\n -Enter a Valid Email ID!";
			document.getElementById("contact_email").focus();
	}	
	if(Trim(document.getElementById("phone").value)=="")
	{
		missinginfo += "\n     - Phone ";
		document.getElementById("phone").focus;
	}
	
	if (missinginfo != "") 
	{
		missinginfo ="_____________________________\n" + "You failed to correctly fill in your:\n" + missinginfo + "\n_____________________________" + "\nPlease re-enter and submit again!";
		alert(missinginfo);
		return false;
	}
	else 
	{
		//alert("sucess");
		postAppraisal('action/send_contactus.php');
	}
}

function postAppraisal(datasourse)
{ 		
	
	var XMLHttpreqobj2500 = false;
	if(window.XMLHttpRequest)
 	{
		XMLHttpreqobj2500 = new XMLHttpRequest();
		if(XMLHttpreqobj2500.overrideMimeType)
		{
			XMLHttpreqobj2500.overrideMimeType("text/xml");
		}
    }
    else if (window.ActiveXObject)
    {
        XMLHttpreqobj2500 = new ActiveXObject("Microsoft.XMLHTTP");
    }
				
							
		var appraisalContent='name='+document.getElementById("name").value
		    +'&address='		 	+document.getElementById("address").value
			+'&region='				+document.getElementById("region").value
			+'&city='				+document.getElementById("city").value
			+'&suburb='				+document.getElementById("suburb1").value					
			+'&country='		 	+document.getElementById("country").value
			+'&descript='			+document.getElementById("descript").value
			+'&email='				+document.getElementById("contact_email").value
			+'&phone='		 		+document.getElementById("phone").value
			+'&mobile='			 	+document.getElementById("mobile").value
			+'&fax='			 	+document.getElementById("fax").value;
			  			
		 if (XMLHttpreqobj2500)
            {
               
                XMLHttpreqobj2500.open("POST",datasourse);
				XMLHttpreqobj2500.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                XMLHttpreqobj2500.onreadystatechange = function()
                {
					
				   if (XMLHttpreqobj2500.readyState == 4 && XMLHttpreqobj2500.status == 200)
                    {
					
						//alert(XMLHttpreqobj2500.responseText);
						
							document.getElementById("sucMsg").innerHTML="<span class=\"sucessmsg\">Sending Your Details</span>";
						//var anchorname="josy";
						//window.location.href='contactus1.php#'+anchorname;
						location.href="#adTop";
						
					}				    			
					else
					{						
						document.getElementById("sucMsg").innerHTML ='<div><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="90" height="40"><param name="movie" value="images/loading2.swf" /><param name="quality" value="high" />      <embed src="images/loading2.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="90" height="40"></embed></object></div>';
						//location.href="#to";
						
					}
                }
                XMLHttpreqobj2500.send(appraisalContent);//send datas
				
            }
			
}

function Trim(TRIM_VALUE)
{
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function

function listCountries()//FOR QUICK SEARCH
{ 		
	var XMLHttpreqobj1004 = false;
	if(window.XMLHttpRequest)
	{
		 XMLHttpreqobj1004 = new XMLHttpRequest();
		 if(XMLHttpreqobj1004.overrideMimeType)
		 {
				XMLHttpreqobj1004.overrideMimeType("text/xml");
		 }
	}
	else if (window.ActiveXObject)
	{
		XMLHttpreqobj1004 = new ActiveXObject("Microsoft.XMLHTTP");
	}
		if (XMLHttpreqobj1004)
		{
			XMLHttpreqobj1004.open("POST","action/list_countries.php");
			XMLHttpreqobj1004.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			XMLHttpreqobj1004.onreadystatechange = function()
			{
				if(XMLHttpreqobj1004.readyState == 4 && XMLHttpreqobj1004.status == 200)
				{
						document.getElementById("selCountry").innerHTML=XMLHttpreqobj1004.responseText;
						
				}					
			}
			XMLHttpreqobj1004.send(null);//send datas
	  }
}	

function goanchor(anchorname) { 
  window.location.href = window.location.href + 
       "#" + anchorname; 
}