function changecurrency(thedrop){
  thedrop.form.submit();
}
function checkcompose(dowhat){
  document.getElementById('todo').value = dowhat;
  return true;
}
function contactcheck(){
  fieldlist=new Array();
  fielderrorlist=new Array();
  fieldlist = ["name","message"];
fielderrorlist = ["Your Name","Your Message"];
  
  for (i=0; i < fieldlist.length; i++){
    formitem=fieldlist[i];
    if (document.forms.theform[formitem].value.length<3){
      alert("Please ensure " + fielderrorlist[i] + " is entered!");
      document.forms.theform[formitem].focus();
      return false;
      break;
    }
  }
}
function setsearchspeciality(thedrop){
  var theval = thedrop.options[thedrop.selectedIndex].value;
  if(theval != '')
    window.location = 'ecom_product_list.html?searchspeciality='+theval;
}
function setsearchsubject(thedrop){
  var tmp = document.getElementById('searchspeciality');
  var theval = thedrop.options[thedrop.selectedIndex].value;
  if(theval!='')
    window.location = 'ecom_product_list.html?searchspeciality='+tmp.options[tmp.selectedIndex].value+'&searchsubject='+thedrop.options[thedrop.selectedIndex].value;
}
function setsearchopt(fieldname,thedrop){
  var theurl = document.getElementById('the_link').value;
  if(fieldname == 'searchspeciality'){
    theurl = getfields(theurl,fieldname,thedrop.options[thedrop.selectedIndex].value);
    theurl = getfields(theurl,'searchsubject','');
  } else if(fieldname == 'searchsubject'){
    theurl = getfields(theurl,fieldname,thedrop.options[thedrop.selectedIndex].value);
  }
  window.location = theurl;
}
function getfields(thestring,fieldname,thevalue){
  var theval = thevalue;
  var tmp = document.getElementById('theold_'+fieldname).value;
  var tmp2 = '&'+fieldname+'='+tmp; var tmp3;
  if(theval!=''){
    tmp3 = '&'+fieldname+'='+theval;
  }
  thestring = thestring.replace(tmp2,'');
  return thestring+((theval!='')?tmp3:'');  
}
function setImg(theimg){
  document.getElementById('course_mainimg').innerHTML = '<img src="page/files/'+theImgs[theimg]+'" '+bigsize[theimg]+' alt="">';
}
function hideimg(){
  document.getElementById('course_mainimg').innerHTML = 'Scroll over image for larger view';
}
function chkcheckout1(){
  fieldlist=new Array();
  fielderrorlist=new Array();
  fieldlist = ["clientfname","clientsname","clientaddress1","clienttown","clientpostcode","clienttelephone","clientbfname","clientbsname","clientbaddress1","clientbtown","clientbpostcode","clientbtelephone","clientemail"];
fielderrorlist = ["First Name","Surname","Address","Town","Postcode","Telephone","Billing First Name","Billing Surname","Billing Address","Billing Town","Billing Postcode","Billing Telephone","Email"];
  
  for (i=0; i < fieldlist.length; i++){
    formitem=fieldlist[i];
    if (document.forms.theform[formitem].value.length<3){
      alert("Please ensure " + fielderrorlist[i] + " is entered!");
      document.forms.theform[formitem].focus();
      return false;
      break;
    }
    if(formitem == 'clientemail' && document.forms.theform['signmeup'].value=='yes'){
      if(document.forms.theform['clientpassword'].value.length < 3){
        alert('Please ensure Password is entered!');
        document.forms.theform['clientpassword'].focus();
        return false;
        break;
      }
    }
  }
}
function copyaddress(){
  var theForm = document.forms.theform;
  theForm.clientbtitle.value = theForm.clienttitle.value;
  theForm.clientbfname.value = theForm.clientfname.value;
  theForm.clientbsname.value = theForm.clientsname.value;
  theForm.clientbaddress1.value = theForm.clientaddress1.value;
  theForm.clientbaddress2.value = theForm.clientaddress2.value;
  theForm.clientbtown.value = theForm.clienttown.value;
  theForm.clientbcounty.value = theForm.clientcounty.value;
  theForm.clientbpostcode.value = theForm.clientpostcode.value;
  theForm.clientbtelephone.value = theForm.clienttelephone.value;
}
function addtobasket(productid){
  window.location = 'page_data.php?dw=ecom_addtobasket&productid='+productid;
}
var _w = null;
function createNew(thispic) {
  mypic = thispic;
  _w = window.open();
  _w.document.open();
  _w.document.write('<html><head><title>Full Image Preview</title></head><body><a href="javascript:window.close();">Close Window</a><br>');
  _w.document.write('<img src = "');
  _w.document.write (mypic);
  _w.document.write ('">');
  
  _w.document.write('</body></html>');
  _w.document.close();
}
function psimember(){
  if (document.getElementById("registerpsimember").value == "Yes"){
    document.getElementById("exvat").value = "£"+coursepriceexvat+" (PSI Member)";
    document.getElementById("plusvat").value = "£"+coursepricevat;
  } else {
    document.getElementById("exvat").value = "£"+coursepriceexvat2+" (Non-Member)";
    document.getElementById("plusvat").value = "£"+coursepricevat2;
  }
}
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;
}

function quickjump() {

  var sid = document.getElementById("topicjump").value;
  window.location = "/page_data.php?dw=quickjump&sid="+sid;

}

function delete_subgroup() {

  c = confirm("Are you sure you want to delete the Subgroup?");

  if( c == true ) {
    document.getElementById("dowhat").value = "delete";
    return true;
  }
  else { return false; }

}
function open_editor_window(thefield){
  open_window_centred('page/minieditor.php?&thefield='+thefield+'&type=id','window',700,500,'location=no, menubar=no, status=no, resizable=yes, toolbar=no, scrollbars=yes');
}
