
// Copyright House Price Spy Limited.

var addressData = new Array;
var addressLookup = new Array;

function clearText() {
if (document.searchForm.search.value == 'postcode OR street, city'){
document.searchForm.search.value = "";
}
}

function StartUp() {

try
{
CustomStartUp()
}
catch(err)
{

}

}

function LookUpPostcode(postcode, returnCode, refID) {

addressData.length = 0;
addressLookup.length = 0;

url = "/cgi-bin/lookup-postcode.pl?query_id=" + refID + "&postcode=" + encodeURIComponent(postcode);

LoadXML();

    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {

if (self.xmlHttpReq.responseText != 'ERR'){

temp = self.xmlHttpReq.responseText.split('\n');

for (var x= 0; x < temp.length; x++) {

pair = temp[x].split('|');

idKey = parseInt(pair[1]);

if (pair[0] == 'D'){
addressData[idKey] = pair[2];
} else if (pair[0] == 'A'){
addressLookup[idKey] = pair[2];
}

}

}

eval(returnCode + "();");

        }
    }

self.xmlHttpReq.open("GET", url, true) 
self.xmlHttpReq.send(null);

}

function UpdateSatNav(fieldName) {

eval("fieldState = document.satNavForm."+fieldName+".checked;");

if (fieldState == true){
url = "/cgi-bin/sat-nav.pl?location_id="+fieldName+"&status=add";
} else {
url = "/cgi-bin/sat-nav.pl?location_id="+fieldName+"&status=remove";
}

LoadXML();

    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            
temp = self.xmlHttpReq.responseText.split('\n');

if (temp[0] == "ERR"){
alert('Sorry we were unable to update your Sat Nav.');
} else if (temp[0] == 'OK'){
document.getElementById('satNavStatus').innerHTML = '<a href="/cgi-bin/sat-nav.pl" style="text-decoration:underline;font-size:12px;">Sat Nav</a> ('+temp[1]+')';
}


        }
    }

self.xmlHttpReq.open("GET", url, true) 
self.xmlHttpReq.send(null);

}

function LoadXML() {
  var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
}


function RefinePage(fieldName, fieldValue) {

if (fieldName == "letter"){
document.refineForm.letter.value = fieldValue;
document.refineForm.page.value = 1;
document.refineForm.submit();
}

if (fieldName == "page"){
document.refineForm.page.value = fieldValue;
document.refineForm.submit();
}

}

function SortPage(fieldName, fieldPos) {
document.refineForm.sortField.value = fieldName;
document.refineForm.sortPos.value = fieldPos;
document.refineForm.page.value = 1;
document.refineForm.submit();
}

function BookmarkSite() {

title = "House Price Spy";
url = location.href;

var done = 0;

if (window.sidebar) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(title, url,"");
done = 1;
} else if( window.external ) { // IE Favorite
window.external.AddFavorite( url, title);
done = 1;
}else if(window.opera && window.print) { // Opera Hotlist	
return true;
done = 1;
}

if (! done){
alert("Sorry. Netscape and Mac Safari users must bookmark the pages manually by hitting <Ctrl-D>");
}

}

function VisitWebsite(url){
window.open(url);
}
