// JavaScript Document

function LogOut()
{
	if(confirm('Are You Sure You Want to Log Out?'))
	{
		window.location="index.php";
		}
	  //else {
		//  return false;
		  //}
	}
	function ValidateLogin()
	 {
		 //return true;
		 if(document.form1.username.value < 1)
		  {
			  //alert('Please Provide Username');
			  document.getElementById('myusername').innerHTML = '*Please Provide Username';
			  document.form1.username.focus();
			  document.getElementById('mypass').innerHTML = '';
			  return false;
			  }
		     if(document.form1.password.value <1)
			  {
				  document.getElementById('myusername').innerHTML = '';
				 // alert('Please Provide Password');
				   document.getElementById('mypass').innerHTML = '*Please Provide Password';
				   document.form1.password.focus();
				   return false;
				  }
		 else {
			 document.form1.hdAction.value=1;
			 document.form1.submit();
			 return true;
			 }
		 }
		 
		
			 
			 
			 function ValidatePropForm(){
				
				if(document.form1.title.value<1){
					 
					 document.getElementById('mytitle').innerHTML = 'Missing'
					 document.form1.title.focus();
					 return false;
					 }
					 
					/* if(document.form1.size.value<1){	
					 document.getElementById('mytitle').innerHTML = ''	
					 document.getElementById('mysize').innerHTML = 'Missing'
					 document.form1.size.focus();						 	 
					 return false;
					}
					
*/					if(document.form1.price.value<1){	
					 document.getElementById('mytitle').innerHTML = ''	
					 document.getElementById('myprice').innerHTML = 'Missing'
					 document.form1.price.focus();						 	 
					 return false;
					}										
					
					if(document.form1.status.value<1){	
					 document.getElementById('myprice').innerHTML = ''	
					 document.getElementById('mystatus').innerHTML = 'Missing'
					 document.form1.status.focus();						 	 
					 return false;
					}										
				
				 else{
					 //documment.form1.submit();
					 return true;
					 }
				 
				 }
				 
				 function AddProperty(){
 					var status = ValidatePropForm();
 					if(status){
 					document.form1.hdAction.value = 1;
 					
 					//document.getElementById('layer1').InnerHTML = 'Property Added Successfully';
					document.form1.submit();
 					
					}
	}
	
	            function UpdateProperty(){
 					
					var status = ValidatePropForm();
					if(status){
 					document.form1.hdAction.value = 3;
 					document.form1.action = 'updateproperty.php';
 					//document.getElementById('layer1').InnerHTML = 'Property Added Successfully';
					document.form1.submit();
 					
					}
	}
	
	
 function handleOnChange(dd1)
{
  var idx = dd1.selectedIndex;
  var val = dd1[idx].text;
  var par = document.forms["form1"];
  var parelmts = par.elements;
  var prezsel = parelmts["sublocation"];
  var country = val;
 
  if (country != "Select Location")
  {
 	Http.get({
		url: "./location/" +  country + ".txt",
		callback: fillPrez,
		cache: Http.Cache.Get
	}, [prezsel]);
  }
}

function fillPrez(xmlreply, prezelmt)
{
  if (xmlreply.status == Http.Status.OK)
  {
    var prezresponse = xmlreply.responseText;
     
	var prezar = prezresponse.split("|");
    prezelmt.length = 1;
    prezelmt.length = prezar.length;
    for (o=1; o < prezar.length; o++)
    {
      prezelmt[o].text = prezar[o];
    }
  }
  else
  {
    //alert("Cannot handle the AJAX call.");
  }
}

//main page functions

function toggleLayer( whichLayer )
{ 
 var elem, vis;  if( document.getElementById ) // this is the way the standards work    
 elem = document.getElementById( whichLayer ); 
  else if( document.all ) // this is the way old msie versions work     
   elem = document.all[whichLayer];  else if( document.layers ) // this is the way nn4 works  
     elem = document.layers[whichLayer];  vis = elem.style;   //if the style.display value is blank we try to figure it out here
	   if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)    
	 vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
	 }

	   function UpdatePrperty(id){
	   
	   window.open ("updateproperty.php?id="+id,"LDP","status=0,scrollbars=0,left=150,top=120,width=850,height=650");
	   }
	   

     function getRefNo(value){
	 
	 document.getElementById('hdCat').value = value;
	 
	 if(value=='sale'){ 
	 var num = randomnumber=Math.floor(Math.random()*1001);
	 document.getElementById('refno').value = "PS"+ num;
	 document.getElementById('cheques').innerHTML = 'Service Charges';
	 }
	 if(value=='rent'){
	 var num = randomnumber=Math.floor(Math.random()*1001);
	 document.getElementById('refno').value = "PR"+ num;
	 document.getElementById('cheques').innerHTML = 'Number of Cheques';  
	   }
	  return value;
	 }
	
	function getEmployeeName(){
		var name = document.getElementById('contactemail').options[document.getElementById('contactemail').selectedIndex].value;
		
		var First = name.charAt(0);
		var Second = name.charAt(2);
		var complete = First + Second;
		var CapitalComplete = complete.toUpperCase();
		var refroot = document.getElementById('refno').value;
		if((CapitalComplete=='RA') || (CapitalComplete=='FA')){
			CapitalComplete = 'LD';	
			}
		//alert(CapitalComplete);
		var fullrefno = CapitalComplete+refroot;
		document.getElementById('refno').value = fullrefno;
		
		}
	
	 function deleteprop(id){
	 if(confirm('Are You Sure to Delete?')){
	 document.form1.hdIdent.value = id;
	 document.form1.hdAction.value = 2;
	 document.form1.submit();
	 }
	}
	
	function deletelocation(id){
	 if(confirm('Are You Sure to Delete This Location?\nNote: Associated Sub Location will also be Deleted.')){
	 document.form1.hdIdent.value = id;
	 document.form1.hdAction.value = 2;
	 document.form1.submit();
	 }
	}
	
	function deletesublocation(id){
	 if(confirm('Are You Sure to Delete This Sub Location?')){
	 document.form1.hdIdent.value = id;
	 document.form1.hdAction.value = 2;
	 document.form1.submit();
	 }
	}
	
	function CalClsFee(){
	 
	 var cat = document.getElementById('hdCat').value;
	 
	//alert(cat);
	var price = Number(document.getElementById('price').value);
	
	if(cat=='sale'){
	var clrfee =  Number(price*3/100);
    var finalprice = Number(price+clrfee);
	document.getElementById('closingfee').innerHTML = finalprice;
	document.getElementById('totalclosingfee').value = finalprice;
	 }
	if(cat=='rent'){
	  if(price>=50000){
	  var HighPrice = Number(price*0.1);
	  var HighPricefn = Number(price+HighPrice);
	  document.getElementById('closingfee').innerHTML = HighPricefn;
	  document.getElementById('totalclosingfee').value = HighPricefn;
	   }
	    if(price<50000){
		var LowPrice = Number(price*0.05);
	    var LowPricefn = Number(price+LowPrice+2500);
	    document.getElementById('closingfee').innerHTML = LowPricefn;
	    document.getElementById('totalclosingfee').value = LowPricefn;
		}
	  }
	}

    function QuickSearch(){
		document.form1.action = 'search.php';
		document.form1.submit();
	}
	
	function AdvanceSearch(){
		document.form1.action = 'advsearchresult.php';
		document.form1.submit();
	}



  function ViewDetails(id){
	  
	  
	  document.form1.hdViewDetails.value = id;
	  document.form1.action = 'property_detail.php';
	  document.form1.submit();
	  
	  }

function backtohome(){
	if(confirm('Are You Sure to Cancel?')){
	  window.location = 'main.php';
	}
}


function UpdateMainPhoto(id,photoid){
	   
	   window.open ("updatephoto.php?id="+id+"&photoid="+photoid,"LDP","status=0,scrollbars=0,left=150,top=120,width=300,height=200");
	   }
	   
	   
	   function GenerateRSS(){
	   
	   window.open ("LDP_Feed.php?xml_feed=1","LDP","status=0,scrollbars=0,left=150,top=120,width=300,height=200");
	   }
	   
	   
	   function FindGepoPoint(){
	   window.open ("geopoint.php","LDP","status=0,scrollbars=1,left=150,top=120,width=850,height=750");
	   }
	   
	   
	   function DisableBedRooms(obj){
		   
		   if((obj=='office') || (obj=='warehouse')){
			   
			   document.getElementById('bedrooms').className = 'formfont2';
			   
			   }
		   else {
			   
			   document.getElementById('bedrooms').className = 'formfont';
			   
			   }
		   
		   }