// JavaScript Document
function showbasicscreen(){
	
	//Property_id, Property_Code, Property_Name, Property_Type, State, City, Property_Address, Bedrooms, Bathrooms, Ageofconstruction, Facing, Floor_Number, Typeofownership, Area_sqft, Price, Annual_Tax_dues, Property_details, Description, Property_Photo, OwnerName, Address, workphone, Homephone, Mobile, Fax, Email
	//	registeraction
	var ownername = document.getElementById("ownername").value
	var ownaddr = document.getElementById("ownaddr").value
	var ownphone =document.getElementById("ownphone").value
	var ownhphone =document.getElementById("ownhphone").value
	var ownmobile = document.getElementById("ownmobile").value
	var ownfax = document.getElementById("ownfax").value
	var ownemail = document.getElementById("ownemail").value
	if(ownername == null || ownername == ""){
		alert("Please enter Property Owner Name");
		document.getElementById("ownername").focus()
	}
	
		else if(ownaddr == null || ownaddr == "")
	 {
		 alert("Please enter Property Owner Address");
		 document.getElementById("ownaddr").focus()
	 }
	 else if(isNaN(ownphone))
				  {
					  alert("Please Enter the valid Phone number");
					 document.getElementById("ownphone").value="";
				  }
	else if(isNaN(ownhphone))
				  {
					  alert("Please Enter the valid Phone number");
					  document.getElementById("ownhphone").value="";
				  }
	
	else if(ownmobile == null || ownmobile == "")
	 {
		 alert("Please enter Mobile Number");
		 document.getElementById("ownmobile").focus()
	 }
	 else if(ownmobile != "" && checkInternationalPhone(ownmobile)==false){
		 
		alert("Please Enter a Valid Phone Number");
		
	
		document.getElementById("ownmobile").focus()
		//return false
	
	 }
	  else if(isNaN(ownfax))
				  {
					  alert("Please Enter the valid Fax number");
					 document.getElementById("ownfax").value="";
				  }
	else if ((ownemail==null)||(ownemail=="")){
		alert("Please Enter your Email ID")
		document.getElementById("ownemail").focus()
		//return false
	}
	else if (ownemail != "" && echeck(ownemail)==false){
		//emailID.value=""
		document.getElementById("ownemail").focus()
		//return false
	}
	
	
	else {
		
		xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null)
				{
					alert ("Browser does not support HTTP Request")
					return
				}
				//delId = 0;
				
				
				var url="registeraction.php?action=owndtls&ownername="+ownername+"&ownaddr="+ownaddr+"&ownphone="+ownphone+"&ownhphone="+ownhphone+"&ownfax="+ownfax+"&ownemail="+ownemail+"&ownmobile="+ownmobile+"";
				xmlHttp.onreadystatechange=registeractionstateChanged
				xmlHttp.open("GET",url,true)
				xmlHttp.send(null)
	}
}
var ppid;
function registeractionstateChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
				 { 
				 	document.getElementById("ownerdtls").style.display = "none";
					document.getElementById("basicdtls").style.display = "block";
					var strflds = xmlHttp.responseXML.getElementsByTagName('row');
					ppid = getNodeValue(strflds[0],'ppid');
					document.getElementById("ppid").value = ppid
					
				 }
}

function getNodeValue(obj,tag)
                {
                    return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;
                }
function showthirdscreen(){
	var iwanto = document.getElementById("iwanto").value
	var ptype = document.getElementById("ptype").value
	var ttype = ""//document.getElementById("ttype").value
	var state = document.getElementById("state").value
	var city = document.getElementById("city").value
	var location = document.getElementById("location").value
	var txtPropertyAddress = document.getElementById("txtPropertyAddress").value
	var bedrooms = document.getElementById("bedrooms").value
	var bathRooms = document.getElementById("bathRooms").value
	var alphaExp = /^[a-zA-Z]+$/;
	if(iwanto ==null || iwanto=="")
	{
		alert("Please Select the drop down");
		 document.getElementById("iwanto").focus()
	}
	else if(ptype ==null || ptype=="")
	{
		alert("Please Select the Property Type");
		 document.getElementById("ptype").focus()
	}
	
	else if(state ==null || state == "")
	{
		alert("Please Enter State");
			 document.getElementById("state").focus()
	}
	
	
	else if(!state.match(alphaExp))
	{
	alert("Please Enter the Character");
	document.getElementById("state").value="";
	document.getElementById("state").focus();
	}
		
	else if(city ==null || city == "")
	{
		alert("Please Enter City");
			 document.getElementById("city").focus()
	}
	else if(!city.match(alphaExp))
	{
	alert("Please Enter the Character");
	document.getElementById("city").value="";
	document.getElementById("city").focus();
	}
	else if(location ==null || location == "")
	{
		alert("Please Select the Location");
			 document.getElementById("location").focus()
	}
	else if(txtPropertyAddress ==null || txtPropertyAddress == "")
	{
		alert("Please Enter Property Address");
			 document.getElementById("txtPropertyAddress").focus()
	}
	
	else{
			xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null)
				{
					alert ("Browser does not support HTTP Request")
					return
				}
				//delId = 0;
				var url="registeraction.php?action=bscdtls&iwanto="+iwanto+"&ptype="+ptype+"&ttype="+ttype+"&state="+state+"&city="+city+"&location="+location+"&txtPropertyAddress="+txtPropertyAddress+"&bedrooms="+bedrooms+"&bathRooms="+bathRooms+"&ppid="+ppid;
				xmlHttp.onreadystatechange=showthirdscreenstateChanged
				xmlHttp.open("GET",url,true)
				xmlHttp.send(null)
	}
	
}
function showthirdscreenstateChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
				 { 
				 	//document.getElementById("ownerdtls").style.display = "none";
					
					//var strflds = xmlHttp.responseXML.getElementsByTagName('row');
					//ppid = getNodeValue(strflds[i],'ppid');
					document.getElementById("basicdtls").style.display = "none";
					document.getElementById("aredtls").style.display = "block";
					
				 }
}
function showfourthscreen(){
	
	var ddlAgeofCon = document.getElementById("ddlAgeofCon").value
	var ddlFacing = document.getElementById("ddlFacing").value
	var ddlPropertyOnFloor = document.getElementById("PropertyOnFloor").value
	var ddlOwnership= document.getElementById("ddlOwnership").value
	
	var plo= document.getElementById("parea").value//+""+document.getElementById("plotarea").value
	var sqr=document.getElementById("sqft1").value
	var plotarea=plo+sqr;
	var buildarea ="";// document.getElementById("barea").value+""+document.getElementById("buildarea").value
	var rate = document.getElementById("tax").value//+""+document.getElementById("rate").value
	var price = document.getElementById("price").value
	
	if(ddlAgeofCon==null || ddlAgeofCon==""){
		alert("Please Select Age of Construction");
		 document.getElementById("ddlAgeofCon").focus() 
	}else if(ddlOwnership==null || ddlOwnership==""){
		alert("Please Select Type of Ownership");
		document.getElementById("ddlOwnership").focus()
	}else if(plo ==null || plo == ""){
		alert("Please Enter the Area  ");
		document.getElementById("parea").focus()
	}
	else if(isNaN(plo))
				  {
					  alert("Please Enter the valid area");
					  document.getElementById("parea").value="";
					  document.getElementById("parea").focus()
				  }
	else if(sqr==null || sqr==""){
		alert("Please Select  Area Available (Sqm/Sqft)  ");
		document.getElementById("sqft1").focus()
	} else if(price ==null || price == ""){
		alert("Please Enter the Price  ");
		document.getElementById("price").focus()
	}
	else if(isNaN(price))
				  {
					  alert("Please Enter the valid price");
					  document.getElementById("price").value="";
					   document.getElementById("price").focus()
				  }
	else {
		xmlHttp=GetXmlHttpObject()
			if (xmlHttp==null)
				{
					alert ("Browser does not support HTTP Request")
					return
				}
				//delId = 0;
				var url="registeraction.php?action=aapdtls&ddlAgeofCon="+ddlAgeofCon+"&ddlFacing="+ddlFacing+"&ddlPropertyOnFloor="+ddlPropertyOnFloor+"&ddlOwnership="+ddlOwnership+"&plotarea="+plotarea+"&buildarea="+buildarea+"&rate="+rate+"&price="+price+"&ppid="+ppid;
				xmlHttp.onreadystatechange=showfourthscreenstateChanged
				xmlHttp.open("GET",url,true)
				xmlHttp.send(null)
	}
	
}
function showfourthscreenstateChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
				 { 
				 	//document.getElementById("ownerdtls").style.display = "none";
					
					//var strflds = xmlHttp.responseXML.getElementsByTagName('row');
					//ppid = getNodeValue(strflds[i],'ppid');
					//document.getElementById("basicdtls").style.display = "none";
					document.getElementById("aredtls").style.display = "none";
					document.getElementById("perss").style.display = "block";
					
				 }
}
var xmlHttp;
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
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;
			}
			
function uploadimage(){
	document.upimg.submit();	
}


