function booktime(timeid,timetime,y,m,d){
  document.getElementById('booknow').innerHTML = document.getElementById('date').innerHTML+'<br><b>'+timetime+'</b>';
  document.getElementById('y').value = y;
  document.getElementById('m').value = m;
  document.getElementById('d').value = d;
  document.getElementById('timeid').value = timeid;
  document.getElementById('booknowdiv').style.display = '';
}
function ChangeDiv(thedate,div){
  var tmp = document.getElementById(div);
  if(typeof thedate == "number"){
    tmp.innerHTML = thedate + (
      (thedate % 10 == 1 && thedate % 100 != 11)? 'st':
      (thedate % 10 == 2 && thedate % 100 != 12)? 'nd':
      (thedate % 10 == 3 && thedate % 100 != 13)? 'rd' : 'th');
  } else {
    tmp.innerHTML = thedate;
  }
}
function doaddtime(){
  boxes['timetime'] = document.getElementById('timetime');
  if(boxes['timetime'].value!=''){
  divs['timelist'] = document.getElementById('timelist');
  divs['timelist'].innerHTML = 'Reloading...';

  var http = RequestObject();
  http.open('POST','ajax.php');
  http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  http.send('dw=addtime&time='+boxes['timetime'].value+myRand());
  boxes['timetime'].value = '';
  http.onreadystatechange = function (){
  if(http.readyState == 4)
    send_request('timeslist','GET','ajax.php?dw=gettimeslist');
  }
  }
  return false;
}
function process_response(opt, response){
  if(opt == 'timeslist')
    divs['timelist'].innerHTML = response;
}

var boxes = new Array(); 
var divs = new Array();
function RequestObject(){
	var req;
	try {
	req = new XMLHttpRequest(); /* e.g. Firefox */
	} catch(e) {
	  try {
		req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
	  } catch (e) {
		try {
		req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
		} catch (E) {
		  req = false;
		} 
	  } 
	}
	return req;
}
function send_request(opt, method, action){
	var http = RequestObject();
	action += myRand();
	if(method == 'POST'){
		http.open(method,'ajax.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		to_send = action;
	} else {
		http.open(method,action);
		to_send = null;
	}
	http.send(to_send);
	http.onreadystatechange = function () {
		if(http.readyState == 4){
			var response = http.responseText;
			process_response(opt,response);
		}
	}
}
function myRand(){
 return '&myrand='+parseInt(Math.random()*99999999);
}
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";
  }

}
