function change_inputs(obj) {

  if( obj.value == "tolet" ) {
    document.getElementById("tolet1").style.display = "block";	
    document.getElementById("tolet2").style.display = "block";
    document.getElementById("forsale1").style.display = "none";	
    document.getElementById("forsale2").style.display = "none";
  }

  if( obj.value == "forsale" ) {
    document.getElementById("tolet1").style.display = "none";	
    document.getElementById("tolet2").style.display = "none";
    document.getElementById("forsale1").style.display = "block";	
    document.getElementById("forsale2").style.display = "block";
  }

}

function change_pricing(type) { 

  if( type == "letting" ) {	
    document.getElementById("rent").style.display = "block";	
    document.getElementById("rentinp").style.display = "block";
  } 

  if( type == "sales" ) {	
    document.getElementById("rent").style.display = "none";	
    document.getElementById("rentinp").style.display = "none";
  }  

}

function pricetype(type) { 

  if( type == "letting" ) {	
    document.getElementById("saleprice").style.display = "none";	
    document.getElementById("lettingprice").style.display = "block";
  } 

  if( type == "sales" ) {	
    document.getElementById("saleprice").style.display = "block";	
    document.getElementById("lettingprice").style.display = "none";
  }  

}
function arealetter( search ) {

  if( search == 'borough' ) { 
    document.getElementById('areai').style.display="none";
    document.getElementById('boroughi').style.display="block";
    document.getElementById('pci').style.display="none";
  }
  if( search == 'postcode' ) {
    document.getElementById('areai').style.display="none"; 
    document.getElementById('boroughi').style.display="none";
    document.getElementById('pci').style.display="block";
  }
  if( search == 'area' ) {
    document.getElementById('areai').style.display="block";
    document.getElementById('boroughi').style.display="none";
    document.getElementById('pci').style.display="none"; 
  }

}

function openclose(obj,mode) {  

  if( mode == "close" ) {
    document.getElementById(obj+'open').style.display = "block";
    document.getElementById(obj+'close').style.display = "none";
  }

  if( mode == "open" ) {
    document.getElementById(obj+'open').style.display = "none";
    document.getElementById(obj+'close').style.display = "block";
  }

}

function change_box(hobj,bobj,mode) {

if( mode == "open" ) {
  xmlHttp=GetXmlHttpObject() 
  var url="./ajax.php"
  url=url+"?hobj="+hobj+"&bobj="+bobj+"&dw=openbox"
  url=url+"&sid="+Math.random()

  xmlHttp.onreadystatechange=function() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
      document.getElementById(bobj).innerHTML=  xmlHttp.responseText 
      document.getElementById(hobj+"open").style.display = "none"
      document.getElementById(hobj+"close").style.display = "block"
    } 
  }

  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

if( mode == "close" ) {
  xmlHttp=GetXmlHttpObject() 
  var url="./ajax.php"
  url=url+"?hobj="+hobj+"&bobj="+bobj+"&dw=closebox"
  url=url+"&sid="+Math.random()

  xmlHttp.onreadystatechange=function() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
      document.getElementById(bobj).innerHTML=  xmlHttp.responseText
      document.getElementById(hobj+"open").style.display = "block"
      document.getElementById(hobj+"close").style.display = "none" 
    } 
  }

  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

}


function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}

function register_check()
{

var theForm = document.forms.registerform; 

chkboxterms = theForm.userterms.checked; 
if (chkboxterms != true){
alert('You must read and accept our terms and conditions and privacy policy.');
return false;
                        }

textLength = theForm.username.value.length; textLength2 = theForm.username;
if (textLength  < 1){
var msg = "Please ensure Username is entered.";
alert(msg); mycheck = "false"; textLength2.focus(); return false;
                    }

textLength = theForm.useremail.value.length; textLength2 = theForm.useremail;
if (textLength  < 1){
var msg = "Please ensure Email Address is entered.";
alert(msg); mycheck = "false"; textLength2.focus(); return false;
                   }

textLength = theForm.userpassword.value.length; textLength2 = theForm.userpassword;
if (textLength  < 1){
var msg = "Please ensure Password is entered.";
alert(msg); mycheck = "false"; textLength2.focus(); return false;
                   }

textLength2 = theForm.userpassword;
if (theForm.userpassword.value != theForm.reenteruserpassword.value){
var msg = "Please ensure Both Passwords entered match.";
alert(msg); mycheck = "false"; textLength2.focus(); return false;
                   }

}

function get_search(type) {

  xmlHttp=GetXmlHttpObject() 
  var url="./ajax.php"
  url=url+"?type="+type+"&dw=searchhome"
  url=url+"&sid="+Math.random()

  xmlHttp.onreadystatechange=function() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
      document.getElementById("searchhome").innerHTML =  xmlHttp.responseText

      if( type == "searchborough" ){ 
        document.getElementById("searchborough").checked=true 
        document.getElementById("searchpc").checked=false 
        document.getElementById("searcharea").checked=false 
      }

      if( type == "searchpc" ){  
        document.getElementById("searchborough").checked=false 
        document.getElementById("searchpc").checked=true 
        document.getElementById("searcharea").checked=false 
      }

      if( type == "searcharea" ){  
        document.getElementById("searchborough").checked=false 
        document.getElementById("searchpc").checked=false 
        document.getElementById("searcharea").checked=true 
      }

    } 
  }

  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)

}

function get_areas(let) {

  xmlHttp=GetXmlHttpObject() 
  var url="./ajax.php"
  url=url+"?letter="+let+"&dw=searchletter"
  url=url+"&sid="+Math.random()

  xmlHttp.onreadystatechange=function() {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
      document.getElementById("arealist").innerHTML =  xmlHttp.responseText
    }
  }

  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)

}

function change_listtype() {

  var type = document.getElementById("listtype").value;

  if( type == "tolet" ) {
     document.getElementById("forsalei").style.display = "none";
     document.getElementById("toleti").style.display = "block";
  }

  if( type == "forsale" ) {
     document.getElementById("forsalei").style.display = "block";
     document.getElementById("toleti").style.display = "none";
  }

}

function open_window_centred(win_url, win_name, win_w, win_h, styles)
{
  var win_left = (screen.width - win_w) / 2;
  var win_top = (screen.height - win_h) / 2;
  
  var win_style = (styles == undefined)? '' : styles + ', ';
  
  win_style += 'width=' + win_w;
  win_style += ',height=' + win_h;
  win_style += ',left=' + win_left;
  win_style += ',top=' + win_top;

  var newwin = window.open(win_url, win_name, win_style);
  newwin.focus();
  return;
}