// JavaScript Document
var junk = ( navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('Mac') != -1 );
var gecko = ( navigator.userAgent.indexOf('Gecko') != -1 );
var isIE =  ( navigator.userAgent.indexOf('MSIE') != -1 );
var Safari = ( navigator.userAgent.indexOf('KHTML') != -1);
var sign_in_open = false;
var adDataSettings = new Object ();
var advert_code = new Object();
var eventHolder = new Object;
eventHolder['run'] = null;
var startRange;
var rangeCount;
var local_locations_list = null;
var location_loading = null;
var attempts = 0;

function checkReferrer (ref) {
  var isScraper = 0;
  var isHomes = 0;
  scraperSites = new Array('oodle.co.uk','oodle.com','vast.com', 'wheresmyproperty.com','pickupaproperty.com', 'local.thesun.co.uk', 'nestoria.co.uk');

  for (x=0;x<scraperSites.length;x++) {
    if (ref.indexOf(scraperSites[x]) != -1) {
      isScraper ++;
    }
  }
  if (location.pathname.indexOf('/renting/') != -1) {
    isHomes = 1;
  }


  if (isScraper && isHomes) {
    location.replace("http://" + location.hostname + "/help/referrer-help.shtml");
  }
}

checkReferrer(document.referrer);

/* Event Cache Code copyright 2005 Mark Wubben

Provides a way for automagically removing events from nodes and thus preventing memory leakage.
See <http://novemberborn.net/javascript/event-cache> for more information.

This software is licensed under the CC-GNU LGPL <http://creativecommons.org/licenses/LGPL/2.1/>
*/

if(Array.prototype.push == null){
    Array.prototype.push = function(){
	for(var i = 0; i < arguments.length; i++){
	    this[this.length] = arguments[i];
	};
	return this.length;
    };
};

var EventCache = function(){
    var listEvents = [];

    return {
	listEvents : listEvents,

	    add : function(node, sEventName, fHandler, bCapture){
	    listEvents.push(arguments);
	},

	    flush : function(){
		var i, item;
		for(i = listEvents.length - 1; i >= 0; i = i - 1){
		    item = listEvents[i];
		    if(item[0].removeEventListener){
                item[0].removeEventListener(item[1], item[2], item[3]);
		    };
		    /* From this point on we need the event names to be prefixed with 'on" */
		    if(item[1].substring(0, 2) != "on"){
                item[1] = "on" + item[1];
		    };
		    if(item[0].detachEvent){
                item[0].detachEvent(item[1], item[2]);
		    };
		    item[0][item[1]] = null;
		};
		eventHolder.run = null;
	    }
    };
}();


/* Data Loader Code */

var data_control = new Object;
data_control.queue = new Array;
data_control.check = null;
data_control.loaded = false;
data_control.load_count = 0;
data_control.max_load = 2000;
data_control.check_interval = 5;
data_control.current_load = null;
data_control.loading = false;

var load_fun = null;

function load_external_data( url, target, fun, dom )
{
    if ( ! document.getElementById('dataHolder')) return;

    if ( ! dom ) { dom  = false }
    var dummy = new Object;
    dummy.url = url;
    dummy.target = target;
    dummy.fun = fun;
    dummy.dom = dom;

    data_control.queue[data_control.queue.length] =  dummy ;

    if ( ! data_control.loading ) load_from_queue();

}


function load_from_queue()
{
    if ( data_control.queue.length ==  0 )
	{
	    window.frames['dataFrame'].window.location.replace('about:blank');
	    return;
	}
    data_control.loading = true;
    data_control.loaded = true;
    data_control.load_count = 0;
    data_control.current_load = data_control.queue[data_control.queue.length - 1];
    data_control.queue.length--;

    window.frames['dataFrame'].window.location.replace(data_control.current_load.url);

    data_control.check = setTimeout( 'load_check()', 1 );
}

function load_check() {
    if (data_control.check) {clearTimeout(data_control.check)}
    data_control.load_count++;

    if (data_control.loaded) {
	    if (data_control.current_load.dom) {
		    if (window.frames['dataFrame'].document) {
			    window[data_control.current_load.target] = window.frames['dataFrame'].document.getElementById('DOMFrag').innerHTML;
				alert(window[data_control.current_load.target]);
			} else {
			    alert('nothing loaded');
			    window[data_control.current_load.target] = null;
			}
		} else {
		    window[data_control.current_load.target] = window.frames['dataFrame'].data;
			alert(window[data_control.current_load.target] );
		}

	    load_fun = data_control.current_load.fun;
	    setTimeout( 'load_fun()',1 );

	    //data_control.current_load.fun();
	    data_control.loading = false;

	    load_from_queue();
	} else if (data_control.load_count > data_control.max_load) {
	    window[data_control.current_load.target] = null;
	    data_control.current_load.fun();

	    data_control.loading = false;
	    if (data_control.queue.length > 0) {
		    load_from_queue();
		} else {
		    window.frames['dataFrame'].window.location.replace('about:blank');
		}
		alert('not loaded');
	} else {
	    data_control.check = setTimeout( 'load_check()', data_control.check_interval );
	}
}

/* End Data Loader */

function verifyPFP() {
	var themessage = "Please enter:\n";

	if ((document.form1.email.value.indexOf('@') < 1) || (document.form1.email.value.length < (document.form1.email.value.indexOf('@') + 5))) {
		themessage = themessage + " - Your email address\n";
	}
	//alert if fields are empty and cancel form submit

	if (themessage == "Please enter:\n") {
		return true;
	} else {
		alert(themessage);
		return false;
	}
}

function showHiddenOptions() {
	if (document.body.clientWidth > 895) {
        document.getElementById('advanced1024').style.display = "none";
        document.getElementById('hiddenOptions1024').style.display = "block";
	} else {
	document.getElementById('advanced800').style.display = "none";
	document.getElementById('hiddenOptions800').style.display = "block";
	}
}

function checkHidden() {
  if(document && document.stepOne) {
	if(document.stepOne.garage.checked || document.stepOne.garden.checked ||
	   document.stepOne.whenpropadded.value != "" ||
	   document.stepOne.keywords.value != "")
	   {
	       //showHiddenOptions();
	   }
  }
}

function showLargePic1() {
	document.getElementById('largePic1').style.display = "block";
	document.getElementById('largePic2').style.display = "none";
	document.getElementById('largePic3').style.display = "none";
	document.getElementById('largePic4').style.display = "none";
	document.getElementById('largePic5').style.display = "none";
	document.getElementById('largePic6').style.display = "none";
	document.getElementById('largePic7').style.display = "none";
	document.getElementById('largePic8').style.display = "none";
}

function showLargePic2() {
	document.getElementById('largePic1').style.display = "none";
	document.getElementById('largePic2').style.display = "block";
	document.getElementById('largePic3').style.display = "none";
	document.getElementById('largePic4').style.display = "none";
	document.getElementById('largePic5').style.display = "none";
	document.getElementById('largePic6').style.display = "none";
	document.getElementById('largePic7').style.display = "none";
	document.getElementById('largePic8').style.display = "none";
}

function showLargePic3() {
	document.getElementById('largePic1').style.display = "none";
	document.getElementById('largePic2').style.display = "none";
	document.getElementById('largePic3').style.display = "block";
	document.getElementById('largePic4').style.display = "none";
	document.getElementById('largePic5').style.display = "none";
	document.getElementById('largePic6').style.display = "none";
	document.getElementById('largePic7').style.display = "none";
	document.getElementById('largePic8').style.display = "none";
}

function showLargePic4() {
	document.getElementById('largePic1').style.display = "none";
	document.getElementById('largePic2').style.display = "none";
	document.getElementById('largePic3').style.display = "none";
	document.getElementById('largePic4').style.display = "block";
	document.getElementById('largePic5').style.display = "none";
	document.getElementById('largePic6').style.display = "none";
	document.getElementById('largePic7').style.display = "none";
	document.getElementById('largePic8').style.display = "none";
}

function showLargePic5() {
	document.getElementById('largePic1').style.display = "none";
	document.getElementById('largePic2').style.display = "none";
	document.getElementById('largePic3').style.display = "none";
	document.getElementById('largePic4').style.display = "none";
	document.getElementById('largePic5').style.display = "block";
	document.getElementById('largePic6').style.display = "none";
	document.getElementById('largePic7').style.display = "none";
	document.getElementById('largePic8').style.display = "none";
}

function showLargePic6() {
	document.getElementById('largePic1').style.display = "none";
	document.getElementById('largePic2').style.display = "none";
	document.getElementById('largePic3').style.display = "none";
	document.getElementById('largePic4').style.display = "none";
	document.getElementById('largePic5').style.display = "none";
	document.getElementById('largePic6').style.display = "block";
	document.getElementById('largePic7').style.display = "none";
	document.getElementById('largePic8').style.display = "none";
}

function showLargePic7() {
	document.getElementById('largePic1').style.display = "none";
	document.getElementById('largePic2').style.display = "none";
	document.getElementById('largePic3').style.display = "none";
	document.getElementById('largePic4').style.display = "none";
	document.getElementById('largePic5').style.display = "none";
	document.getElementById('largePic6').style.display = "none";
	document.getElementById('largePic7').style.display = "block";
	document.getElementById('largePic8').style.display = "none";
}

function showLargePic8() {
	document.getElementById('largePic1').style.display = "none";
	document.getElementById('largePic2').style.display = "none";
	document.getElementById('largePic3').style.display = "none";
	document.getElementById('largePic4').style.display = "none";
	document.getElementById('largePic5').style.display = "none";
	document.getElementById('largePic6').style.display = "none";
	document.getElementById('largePic7').style.display = "none";
	document.getElementById('largePic8').style.display = "block";
}

function popper(e) {
    var targ = get_event_target( e );

    if (targ.nodeName == 'IMG') {targ = targ.parentNode}

    if (! targ.href ) {return true}

    var width=300;
    var height=300;
    var scroll='yes';
    if (targ.rel) {
	    var size = targ.rel.match(/^(pop.+) (.+$)/);
	    if (size) {
		    var tmp = size[2].split(/x/);
		    width = tmp[0];
		    height = tmp[1];
		    if ( size[1] == 'popad' ) { scroll = 'no' }
		}
	}

    var left = 800 - width;
    var top = 600 - height;
    window.open(targ.href,'help','width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top+',scrollbars='+scroll);
    return false;
}

function get_event_target(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;

    return targ;
}

function stop_prop(e) {
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}

function hide_sign_in_form() {
    if (sign_in_open == true) {
	    hide_target( document.getElementById( 'signInPopUp' ) );
	    apply_to_child_class( document, 'signHide', show_target  );
	    sign_in_open = false;
		var targ1 = document.getElementById('locationSelector4column');
		if (targ1) { show_target(targ1); }
		var targ2 = document.getElementById('propType');
		if (targ2) { show_target(targ2); }
		var targ3 = document.getElementById('ptmb');
		if (targ3) { show_target(targ3); }
	}
}

function read_query_type(name, query, delim) {
    var desp = new RegExp( delim );
    var list = query.split(desp);
    var res = '';
    var test = new RegExp('^\\s*'+name+'\\s*$');

    for (var x = 0; x< list.length;  x++) {
	    var sp = list[x].split("=");
	    if (sp[0].match(test)) {
		    res = unescape(sp[1]);
		    break;
		}
	}
    return res;
}

function hide_target(t) { t.style.visibility = 'hidden' }
function focus_target(t) { t.focus() }
function show_target(t) { t.style.visibility = 'visible' }
function show_target_nospace( t ) { t.style.display = 'block' }
function hide_target_nospace( t ) { t.style.display = 'none' }

function apply_to_child_class( target, cl, fun ) {
    if (target == null) {return}

    var reg = new RegExp(cl);

    if (target.className && target.className.match(reg)) {fun(target)}

    for ( var i = 0; i<target.childNodes.length; i++ ) {
	    apply_to_child_class( target.childNodes[i], cl, fun );
	}
}

function submit() {
   document.mainform.submit();
}

function init_range() {
   range_init = false;

   if (range_init) {return true}
   range_init = true;

   writeRange( startRange, rangeCount );
}

var maxResults   = 10; // per page

function writeRange(start, maxCount) {
  var target = document.getElementById('rangeBlock');
  if ( ! target || ! rangeCount || ! start || (rangeCount < maxResults) || maxCount > 40000) {
        var target1 = document.getElementById('pageSelect');
		target1.style.display = 'inline';
        return false;
  }

  var select = document.createElement('select');
  select.name='base';

  var target1 = document.getElementById('pageSelect');
  hide_target_nospace(target1);

  clean(target);
  var detailspage = document.getElementById('baseval');
  if (detailspage) {
    addEvent(select,'change', details_range_redirect);
  } else {
    addEvent(select,'change', search_range_redirect);
  }
  target.appendChild(select);

  var counter = 1;

  for (1; counter <= maxCount; counter = counter + maxResults) {
    var exit = (counter + maxResults) - 1;
    if (exit >= maxCount) {exit = maxCount}

    var opt = new Option(counter + ' to ' + exit, counter);
    if (counter == exit) opt = new Option(counter, counter);

    select.options[select.options.length] = opt;
    if (counter == start) {
        select.options[select.options.length -1].selected = true;
    }
  }
}

function addEvent(oTarget, sType, fpDest) {
  sType = 'on'+sType;
  var oOldEvent = oTarget[sType];
  if (typeof oOldEvent != "function") {
    oTarget[sType] = fpDest;
  } else {
    oTarget[sType] = function(e) {
      oOldEvent(e);
      fpDest(e);
    }
  }
}

var junk = ( navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('Mac') != -1 );

function clean(target) {
   if (junk) {
      target.innerHTML = '';
   } else {
      while (target.childNodes.length > 0) {
         target.removeChild(target.firstChild)
      }
   }
}

function addLoader(func) {
    if (eventHolder['run'] && eventHolder['run'] != null) {
	    var oldRun = eventHolder['run'];
	    eventHolder['run'] = function(e) {oldRun(e); func(e)}
	} else {
	    eventHolder['run'] = function(e) { func(e) }
	}
}

function setup_bedrooms_range_option() {
    target = document.getElementById('bedrooms');
    if (target != null && target.nodeName == 'SELECT') {
        addEvent( target, 'change', bedroomCheck );
        if (target.options[target.options.length-1].value != '5 or more') {
            var tmp = target.options[target.options.length-1];
            target.options[target.options.length-1] = new Option ( 'Enter range...','Enter range...', 0,0);
            target.options[target.options.length] = tmp;
        } else {
            target.options[target.options.length] = new Option ( 'Enter range...','Enter range...', 0,0);
        }
    }
}

function bedroomCheck(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) // defeat Safari bug
        targ = targ.parentNode;

    if ( targ.options[targ.selectedIndex].value == 'Enter range...' ) {
       s1homes_search_getUserBedroomsRange(targ);
    }
}

function s1homes_search_getUserBedroomsRange (popup) {
    var lowRange = prompt('Enter the minimum number of bedrooms:','1');
    if (lowRange == null) {
        popup.selectedIndex = 0;
        return true;
    } else {
        lowRange = parseInt(lowRange);
        if (isNaN(lowRange)) {
            lowRange = 1;
            if (! confirm("Please enter numbers only.\n\nYour minimum bedrooms\n    has been set to 1.")) {
                popup.selectedIndex = 0;
                return true;
            }
        }
        if (lowRange < 0) lowRange = 0;
        var highRange = prompt('Enter the maximum number of bedrooms:',lowRange);
        if (highRange == null) {
            if (lowRange <= 5) {
                popup.selectedIndex = lowRange + 2;
                return true;
            }
            else {
                popup.selectedIndex = 0;
                return true;
            }
        } else {
            if (isNaN(highRange)) {
                highRange = 5;
                if (! confirm("Please enter numbers only.\n\nYour maximum bedrooms\n    has been set to 5.")) {
                    popup.selectedIndex = 0;
                    return true;
                }
            }
            if (highRange < lowRange) {
                alert("You have entered a maximum lower than your minimum!\nSelect 'Enter Range...' to try again.");
                popup.selectedIndex = 0;
                return true;
            } else {
                var myLabel  = '';
                var myValue  = '';
                if (highRange == lowRange) {
                    myLabel = lowRange + ' (only)';
                    myValue = lowRange + '-' + lowRange;
                }
                else {
                    myLabel = lowRange + '-' + highRange;
                    myValue = myLabel;
                }
                var myValsAr = new Array ();
                var myLabsAr = new Array ();
                for (var i=0; i<popup.options.length && (i==0 || popup.options[i-1].value != 'Enter range...') ; ++i) {
                    myValsAr[i] = popup.options[i].value;
                    myLabsAr[i] = popup.options[i].value;
                }
                myValsAr[myValsAr.length] = myValue;
                myLabsAr[myLabsAr.length] = myLabel;
				repopulateMultipleSelect(popup,myValsAr,myLabsAr);
            }
        }
    }
    return true;
}

function repopulateMultipleSelect(s,av,al) {
    s.options.length = 0;
    for (var i=0; i<av.length; ++i) {
        var selectedI = i == av.length-1 ? 1 : 0;
        s.options[s.options.length] = new Option (al[i],av[i],0,selectedI);
  }
  return true;
}

function showSignOut() {
   var targ = document.getElementById('signout');
   if(targ) {
     targ.style.display = "inline";
   }
}

function popper(e) {
    var targ = get_event_target(e);

    if (targ.nodeName == 'IMG') {targ = targ.parentNode}

    if (! targ.href) {return true}

    var width=300;
    var height=300;
    var scroll='yes';
    if (targ.rel) {
	    var size = targ.rel.match(/^(pop.+) (.+$)/);
	    if (size) {
		    var tmp = size[2].split(/x/);
		    width = tmp[0];
		    height = tmp[1];
		    if ( size[1] == 'popad' ) { scroll = 'no' }
		}
	}
    var left = 800 - width;
    var top = 600 - height;
    window.open(targ.href,'help','width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top+',scrollbars='+scroll);
    return false;
}

function set_pop(t) {addEvent( t, 'click', popper )}

function set_poppers() {
    apply_to_child_class(document, 'popper', set_pop);
}

function create_sign_in_form() {
    var target = document.getElementById( 'signInHolder' );
    if (! target) {return}

    if (junk || Safari) {return}

    var popup = document.createElement('DIV');
    target.appendChild( popup );
    popup.id = 'signInPopUp';

    var form = document.createElement('FORM');
    popup.appendChild(form);

    form.action = '/myaccount/sign_in.cgi';
    form.method = 'post';

    form.appendChild(document.createElement('DIV') ).appendChild( document.createTextNode('email address'));

    var inp1 = document.createElement('INPUT');
    inp1.name = 'email';
    inp1.type = 'text';
    inp1.className = 'focus';
    form.appendChild(document.createElement('DIV')).appendChild(inp1);

    form.appendChild( document.createElement('DIV') ).appendChild( document.createTextNode('password') );
    var inp2 = document.createElement('INPUT');
    inp2.name = 'password';
    inp2.type = 'password';
    form.appendChild( document.createElement('DIV')).appendChild(inp2);

    var inp3 = document.createElement('INPUT');
    inp3.name = 'return_to';
    inp3.type = 'hidden';

	var inpt9 = document.createElement('INPUT');
    inpt9.name = 'goingto';
    inpt9.type = 'hidden';
	inpt9.value = 'profile';
    form.appendChild( inpt9 );

    var test = document.getElementById('signInClick').search;
    test = test.slice(1,test.length);

    var rto = read_query_type('return_to', test, ';');
    inp3.value = rto;
    form.appendChild(inp3);

    var di = document.createElement('DIV');
    form.appendChild( di );
    var inp4 = document.createElement('INPUT');

    inp4.name = 'rememberme';
    inp4.type = 'checkbox';
    inp4.value = 'yes';
    inp4.className = 'left';
    di.appendChild(inp4);

    di.appendChild(document.createTextNode('remember me on this PC'));
    di.appendChild(document.createElement( 'BR'));
    var st = document.createElement('SPAN');
    di.appendChild(st);
    st.className = 'note';
    st.appendChild(document.createTextNode("not for shared PC's - "));

    var link = document.createElement('A');
    st.appendChild( link );
    link.href = '/myaccount/tellmemore.shtml';
    link.appendChild( document.createTextNode("why?"));
    addEvent(link, 'click', popper);

    var di = document.createElement('DIV');
    form.appendChild( di );
    var inp4 = document.createElement('INPUT');

    inp4.name = 'submit';
    inp4.type = 'submit';
    inp4.value = 'sign in';
    inp4.className = 'left';
    di.appendChild( inp4 );

    var st = document.createElement('SPAN');
    di.appendChild(st);
    st.className = 'right note';
    var link = document.createElement('A');
    st.appendChild(link);
    link.href = '/myaccount/forgotten-password.shtml';
    link.appendChild(document.createTextNode("forgotten password"));

    addEvent(popup, 'click', stop_prop);
    addEvent(document.getElementById('signInClick'), 'click', show_sign_in_form);
    addEvent(document, 'click', hide_sign_in_form );
}

function show_sign_in_form(e) {
    if (sign_in_open == false) {
	    stop_prop(e);
	    apply_to_child_class(document, 'signHide', hide_target);
	    show_target(document.getElementById('signInPopUp'));
	    apply_to_child_class(document.getElementById('signInPopUp'), 'focus', focus_target);
		var targ1 = document.getElementById('locationSelector4column');
		if (targ1) {hide_target(targ1);}
		var targ2 = document.getElementById('propType');
		if (targ2) {hide_target(targ2);}
		var targ3 = document.getElementById('ptmb');
		if (targ3) {hide_target(targ3);}
	    sign_in_open = true;
	}

    return false;
}

function load_very_local_areas() {
    //add an on change event to the location dropdown
    var targ = document.getElementById('locationSelector');
    if(targ) {
        addEvent(targ, 'change', getChildLocationAreasFaster);
    }

    var targ = document.getElementById('locationSelectorAlter');
    if(targ) {
        addEvent( targ, 'change', getChildLocationAreas);
        //show the very local option if location dropdown selected
        if(targ.selectedIndex && targ.selectedIndex != "") {
            getChildLocationAreasAlter();
        }
        var targ = document.getElementById('locationSelector4Column');
        if(targ) {
            addEvent(targ, 'change', getChildLocationAreasFasterFour);
        }
    }
}

function run_while_loading() {
   //create and hide the mini signin dropdown form
   create_sign_in_form();
   //show advance option if values in them
   checkHidden();
   setup_bedrooms_range_option()
   load_very_local_areas();
}

function run_onload_funcs() {
    //show the sorted by drop down as we know js is enabled
    show_sorted_by();
    //add the range option to the bedrooms dropdown

    var targ = document.getElementById('mobilelink');
    if (targ && document.body && document.body.clientWidth>=895) {
        targ.style.display = "inline";
    }

    if (read_cookie('mys1_eid')) {getCookieData(); showSignOut();}
    if (Get_Cookie('advanced')) {showHiddenOptions();}

    var targ = document.getElementById('locationSelector');

    if (targ && targ.selectedIndex && targ.selectedIndex != "") {
        getChildLocationAreasFaster();
    }

    if (targ) {
        addEvent( targ, 'change', getChildLocationAreasFaster);
    }

    var targ = document.getElementById('locationSelector4Column');

    if (targ) {
        addEvent( targ, 'change', getChildLocationAreasFasterFour);
    }

    var targ = document.getElementById('refine');

    if (targ) {
	    populate_search_form_with_cookie();
    }

    showHideExplorer();

    //write the range 1-5 etc. drop down
    if(startRange && rangeCount) {
        writeRange(startRange, rangeCount);
    }

    // gray out type
    if(document.getElementById('stepOne')) {
        grayout(document.getElementById('stepOne'));
    }
}

function read_cookie(name) {
    return read_query_type(name, document.cookie, ';');
}

function getCookieData() {
    if (window.ActiveXObject) // if it's ie
    {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // xmlhttp is global
       xmlhttp.onreadystatechange = function() {
          if(xmlhttp.readyState == 4) writecookiecontent(xmlhttp.responseText);
       };
    } else {
       if (window.XMLHttpRequest) // if it's firefox etc.
       {
         xmlhttp        = new XMLHttpRequest() // xmlhttp is global
         xmlhttp.onload = function () { writecookiecontent(xmlhttp.responseText) };
       }
       else return;
    }

	if (read_cookie('mys1_eid')) {
        if (document.mainform && document.mainform.cookietype) {
            var type = document.mainform.cookietype.value;
            if (type) {
                var id = read_cookie('mys1_eid');
                var url = "http://" + document.location.hostname + "/get_cookie_data.cgi?type=" + type + "&membersid=" + id;
                xmlhttp.open("GET", url , true);
                xmlhttp.send(null);
            }
        }
	}
}

function writecookiecontent(content) {
    var targ = document.getElementById('cookieText');
	if(targ && !content.match(/.error./)) {
        document.getElementById('cookieText').innerHTML = content;
    }
}

function Get_Cookie(name) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length))) {
        return null;
	}
	if (start == -1) return null;
	var end = document.cookie.indexOf(";", len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len , end));
}

function createCookie() {
    var ExpireDate = new Date ();
    var tmp = new Date();
    ExpireDate.setTime(ExpireDate.getTime() + 10000);
    var curCookie = "advanced=true" + "; expires=" + ExpireDate.toGMTString() + "; path=/";
    document.cookie = curCookie;
}

function delCookie(NameOfCookie) {
    // The function simply checks to see if the cookie is set.
    // If so, the expiration date is set to Jan. 1st 1970.
    if (Get_Cookie(NameOfCookie)) {
        var cookie_date = new Date();  // current date & time
        cookie_date.setTime (cookie_date.getTime() - 1);
        document.cookie = NameOfCookie += "=; expires=" + cookie_date.toGMTString() + "; path=/";
        /*
        WARNING: Do not assume the Cookie has actually been deleted during that session, both Opera and IE have
        in some of their browser versions maintained the cookie until you restart your browser even if you have
        deleted it in the script. If script functionality depends on the delete action having happened, make sure
        you do another Get_Cookie test on the deleted cookie to make sure it's actually deleted.
        */
        document.cookie = NameOfCookie += "=; expires=Thu, 01-Jan-1970 00:00:01 GMT";
    }
}

// we need to send across the prop_id, this count of this prop and the showing X of this prop
function createThisPropCountCookie(value) {
    var ExpireDate = new Date ();
    var tmp = new Date();
    ExpireDate.setTime(ExpireDate.getTime() + 600000);
    var curCookie = "thispropcount=" + value + "; expires=" + ExpireDate.toGMTString() + "; path=/";
    document.cookie = curCookie;
}

function show_sorted_by() {
  var target1 = document.getElementById('sortedbyselect');
  if (target1) {
    show_target_nospace(target1);
  }
}

function getChildLocationAreasFaster() {
    if (window.ActiveXObject) // if it's ie
    {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // xmlhttp is global
       xmlhttp.onreadystatechange = function() {
          if(xmlhttp.readyState == 4) writecontent(xmlhttp.responseText);
       };
    } else {
       if (window.XMLHttpRequest) // if it's firefox etc.
       {
         xmlhttp        = new XMLHttpRequest() // xmlhttp is global
         xmlhttp.onload = function () { writecontent(xmlhttp.responseText) };
       }
       else return; //
    }

   if (document.stepOne) {
        var locationid = document.stepOne.location.options[document.stepOne.location.selectedIndex].value;
	} else if (document.mainform) {
        var locationid = document.mainform.area_id.options[document.mainform.area_id.selectedIndex].value;
	}

	if (locationid != "") {
        var index = locationid.indexOf(',');
	   if (index > 0) {
	     locationid = locationid.substring(0, index);
	   }
	   var url = "http://" + document.location.hostname + "/ssi/very-local-locations/" + locationid + ".html";
       xmlhttp.open("GET", url , true);
       xmlhttp.send(null);
       document.getElementById('locationHeader').style.display = 'block';
	}
}

function get_loaded_data() {
    if(window.frames['dataFrame'].document && window.frames['dataFrame'].document.getElementById('childareas')) {
        window['local-locations-list'] = window.frames['dataFrame'].document.getElementById('childareas').innerHTML;
        if(document.getElementById('locationDetail')) {
            document.getElementById('locationDetail').innerHTML = window['local-locations-list'];
            document.getElementById('locationHeader').style.display = 'block';
        } else {
            alert('no location details');
        }
    }
}

function getChildLocationAreas() {
     // lets set a loading box meantime
    document.getElementById('locationHeader').style.display = 'block';
    document.getElementById('locationDetail').innerHTML = "<br><p>Loading...</p>";

    if ( window.ActiveXObject ) // if it's ie
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // xmlhttp is global
        xmlhttp.onreadystatechange = function () {
            if(xmlhttp.readyState == 4) writecontent(xmlhttp.responseText);
        };
    } else {
       if (window.XMLHttpRequest) // if it's firefox etc.
       {
            xmlhttp        = new XMLHttpRequest() // xmlhttp is global
            xmlhttp.onload = function () { writecontent(xmlhttp.responseText) };
       } else return;
    }

	var locationid = document.stepOne.location.options[document.stepOne.location.selectedIndex].value;
	var targ = document.getElementById('locationHeader').style.display = 'block';
	if(locationid != "") {
	   var url = "http://" + document.location.hostname + "/get_child_locations.cgi?locationid=" + locationid;
       xmlhttp.open("GET", url , true);
       xmlhttp.send(null);
	} else {
	   document.getElementById('locationHeader').style.display = 'none'
	}
}

function getChildLocationAreasFasterFour() {
    if ( window.ActiveXObject ) // if it's ie
	{
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // xmlhttp is global
	    xmlhttp.onreadystatechange = function() {
		    if(xmlhttp.readyState == 4) writecontent(xmlhttp.responseText);
		};
	} else {
	    if (window.XMLHttpRequest) // if it's firefox etc.
		{
		    xmlhttp        = new XMLHttpRequest() // xmlhttp is global
			xmlhttp.onload = function () { writecontent(xmlhttp.responseText) };
		}
	    else return; //
	}

    if (document.stepOne) {
        var locationid = document.stepOne.location.options[document.stepOne.location.selectedIndex].value;
	} else if (document.mainform) {
        var locationid = document.mainform.area_id.options[document.mainform.area_id.selectedIndex].value;
	}

    if(locationid != "") {
        var url = '';
	    url = "http://" + document.location.hostname  + "/ssi/very-local-locations-4column/" + locationid + ".html";
	    xmlhttp.open("GET", url , true);
	    xmlhttp.send(null);
	    document.getElementById('locationHeader').style.display = 'block';
	} else {
		writecontent('');
		document.getElementById('locationHeader').style.display = 'none';
	}
}

function getChildLocationAreasAlter() {
    if ( window.ActiveXObject ) // if it's ie
    {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // xmlhttp is global
       xmlhttp.onreadystatechange = function () {
          if(xmlhttp.readyState == 4) writecontent(xmlhttp.responseText);
       };
    } else {
       if (window.XMLHttpRequest) // if it's firefox etc.
       {
            xmlhttp        = new XMLHttpRequest() // xmlhttp is global
            xmlhttp.onload = function () { writecontent(xmlhttp.responseText) };
       }
       else return;
    }

	if(document.stepOne) {
        var locationid = document.stepOne.location.options[document.stepOne.location.selectedIndex].value;
        var verylocals = document.stepOne.verylocals.value;
	}

	var targ = document.getElementById('locationHeader').style.display = 'block';
	if(locationid != "") {
        var url = "http://" + document.location.hostname + "/get_child_locations.cgi?locationid=" + locationid + "&" + verylocals;
        xmlhttp.open("GET", url , true);
        xmlhttp.send(null);
	} else {
        var targ = document.getElementById('locationHeader');
        if(targ) {
            targ.style.display = 'none';
		}
	}
}

function writecontent(content) {
    document.getElementById('locationDetail').innerHTML = content;
}

function redirect_sortedby() {
    if (document.mainform.searchparamsnosort) {
        var searchparams = document.mainform.searchparamsnosort.value;
        if (document.mainform.sortedby) {
            var url = "/renting/search/forrent_search_results.cgi?" + searchparams + "&sortedby=" + document.mainform.sortedby.options[document.mainform.sortedby.selectedIndex].value;
        } else {
            var url = "/renting/search/forrent_search_results.cgi?" + searchparams + "&sortedby=" + document.sortedbyform.sortedby.options[document.sortedbyform.sortedby.selectedIndex].value;
        }
        document.location.href=url;
    }
}

function details_range_redirect() {
    var searchparams = document.mainform.searchparams.value;
    var url = "/renting/search/forrent_search_results.cgi?" + searchparams + "&base=" + this.options[this.selectedIndex].value;
    document.location.href=url;
}

function search_range_redirect() {
    var searchparams = document.mainform.searchparams.value;
    var url = "/renting/search/forrent_search_results.cgi?" + searchparams + "&base=" + this.options[this.selectedIndex].value;
    document.location.href=url;
}

function sortedby_redirect() {
    if (document.mainform.searchparamsnosort) {
        var searchparams = document.mainform.searchparamsnosort.value;
        var url = "/renting/search/forrent_search_results.cgi?" + searchparams + "&sortedby=" + document.mainform.sortedby.options[document.mainform.sortedby.options.selectedIndex].value;
        document.location.href=url;
    }
}

function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if (node == null)
        node = document;
	if (tag == null)
        tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function selectAll(searchClass) {
    var checkboxes = getElementsByClass(searchClass);
    for (i=0; i < checkboxes.length; i++) {
        checkboxes[i].checked = true;
    }
}

function unselectAll(searchClass) {
    var checkboxes = getElementsByClass(searchClass);
    for (i=0; i < checkboxes.length; i++) {
        checkboxes[i].checked = false;
    }
}

function showHideExplorer() {
    if (document.getElementById('skyscraper1024') != null) {
        if (navigator.userAgent.toLowerCase().indexOf('safari') != -1 ) { document.getElementById('skyscraper1024').style.display = "none"; return;}

	    if(document.body) {
			var iWidth = document.body.clientWidth;
			var skyLeft1 = ( (iWidth - 960) / 2 ) + 10;
			var skyLeft2 = (skyLeft1 + 960);
		}

        if(iWidth > 1220) {
		    document.getElementById('skyscraper1024').style.display = "";
		    document.getElementById('skyscraper1024').style.left = ((skyLeft2) + 'px');
        } else {
            document.getElementById('skyscraper1024').style.display = "none";
        }

        if (document.getElementById('skyscraper_target') && document.getElementById('skyscraper_loader')) {
            document.getElementById('skyscraper_target').appendChild( document.getElementById('skyscraper_loader'));
        }
    }
}

function fastAds() {
	var ad_types = new Array ('banner','mpu','skyscraper', 'button');
	for ( var i = 0; i < ad_types.length; i++ ) {
		if (document.getElementById(ad_types[i]+'_target') && document.getElementById(ad_types[i]+'_loader')) {
            document.getElementById(ad_types[i]+'_target').appendChild( document.getElementById(ad_types[i]+'_loader') );
		}
	}
}

function create_remember_search_cookie(f) {
    var fields = new Array('minprice', 'maxprice', 'type', 'bedrooms', 'location', 'keywords', 'availability', 'furnished');

    for (var i=0; i< fields.length; i++) {
		delCookie("search-" + fields[i]);
		delCookie("search-map-" + fields[i]);
		if (f[fields[i]] && f[fields[i]].selectedIndex) {
            setCookie("search-" + fields[i], f[fields[i]].selectedIndex);
		    setCookie("search-map-" + fields[i], f[fields[i]].options[f[fields[i]].selectedIndex].value);
		} else {
            setCookie("search-" + fields[i], f[fields[i]].value);
            setCookie("search-map-" + fields[i], f[fields[i]].value);
		}
	}

	fields = new Array('garage', 'garden', 'centralheating', 'newhomes', 'soldstcm');

    for (var i=0; i< fields.length; i++) {
		delCookie("search-" + fields[i]);
		if (f[fields[i]] && f[fields[i]].checked) {
		    setCookie("search-" + fields[i], f[fields[i]].value);
		}
	}

	var veryLocal = f['veryLocal'];
	var veryLocalString = '';
	
    if (veryLocal) {
		for (var i=0; i< veryLocal.length; i++) {
			if (veryLocal[i].checked) {
                veryLocalString += 'veryLocal=' + veryLocal[i].value + '&';
			}
		}
        setCookie("search-veryLocal", veryLocalString);
	} else {
        delCookie("search-veryLocal");
	}
    return true;
}

function populate_search_form_with_cookie() {
    if(document.stepOne) {
	    var fields = new Array('minprice', 'maxprice', 'keywords');

	    for (var i=0; i < fields.length; i++) {
		    if (getCookie('search-' + fields[i]) && document.stepOne) {
			    if(document.stepOne[fields[i]]) {
				    document.stepOne[fields[i]].value = getCookie('search-' + fields[i]);
				}
			}
		}

	    var fields = new Array('type', 'bedrooms', 'location', 'whenpropadded', 'availability', 'furnished');
	    for (var i=0; i < fields.length; i++) {
		    if (getCookie('search-' + fields[i]) && document.stepOne) {
			    if(document.stepOne[fields[i]]) {
				    document.stepOne[fields[i]].selectedIndex = getCookie('search-' + fields[i]);
				}
			}
		}

	    var checkedfields = new Array('garage', 'garden', 'centralheating');
	    for (var i=0; i < checkedfields.length; i++) {
		    if(getCookie('search-' + checkedfields[i])) {
			    document.stepOne[checkedfields[i]].checked = true;
			}
		}

	    if (getCookie('search-keywords') && document.stepOne) {
		    var kys = getCookie('search-keywords');
		    if (!kys || kys == 'undefined') { kys = ''; }
		    document.stepOne.keywords.value = kys;
		}

	    if (getCookie('search-keywords') && document.stepOne) {
		    var kys = getCookie('search-keywords');
		    if (!kys || kys == 'undefined') {kys = '';}
		    document.stepOne.keywords.value = kys;
		}

	    if (document.stepOne['location'].selectedIndex && document.stepOne) {
		    var veryLocal = getCookie('search-veryLocal')
		    if(veryLocal && veryLocal != '') { document.stepOne.verylocals.value = veryLocal;}
		    getChildLocationAreasAlter();
		}
	}
}

function setCookie(sName, sValue) {
    document.cookie = sName + "=" + escape(sValue) + "; path=/;";
}

function getCookie(sName) {
    var aCookie = document.cookie.split("; ");
    for (var i=0; i < aCookie.length; i++) {
	    var aCrumb = aCookie[i].split("=");
	    if (sName == aCrumb[0]) return unescape(aCrumb[1]);
	}
    return 0;
}

function grayout(f) {
   if (f['type'].value.match(/room|bedsit/i)) {
         f["bedrooms"].disabled =true;
    } else {
        f["bedrooms"].disabled =false;
   }
}

addLoader(run_while_loading);
addLoader(showHideExplorer);
addEvent(window, 'load', run_onload_funcs);
addEvent(window, 'resize', showHideExplorer);
