// 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;

function checkReferrer(ref) {

  var mySW = document.getElementById("scraper_warning");
  var mySWi = document.getElementById("sw_inner");
  var isScraper = 0;
  var isHomes = 0;
  var myScraperS = new Array();
  var myScraperF = new Array();

  myScraperS[0] = "oodle.co.uk";
  myScraperF[0] = "Oodle";

  myScraperS[1] = "oodle.com";
  myScraperF[1] = "Oodle";

  myScraperS[2] = "vast.com";
  myScraperF[2] = "Vast";

  myScraperS[3] = "local.thesun.co.uk";
  myScraperF[3] = "The Sun Local";

  myScraperS[4] = "wheresmyproperty.com";
  myScraperF[4] = "Where's My Property";

  myScraperS[5] = "pickupaproperty.com";
  myScraperF[5] = "PickUpAProperty";

  myScraperS[6] = "renovatealerts.com";
  myScraperF[6] = "Renovate Alerts";

  myScraperS[6] = "gg.idev.s1now.com";
  myScraperF[6] = "Test Site";

  for (x=0; x<myScraperS.length; x++) {
    if (ref.indexOf(myScraperS[x]) != -1) {
	  friendlyName = myScraperF[x];
	  isScraper ++;
    }
  }
  if (location.pathname.indexOf('/buying/') != -1) isHomes = 1;

  if (isScraper && isHomes) showScraperWarning(friendlyName);
}

function showScraperWarning(friendlyName) {
  var mySW = document.getElementById("scraper_warning");
  var mySWi = document.getElementById("sw_inner");

  mySW.style.display = "block";
  mySWi.style.display = "block";

  document.getElementById("sSiteName").innerHTML = friendlyName + ", ";

  var docHeight = (document.height !== undefined) ? document.height + 50 : document.body.offsetHeight + 50;
  var docWidth = (document.width !== undefined) ? document.width : document.body.offsetWidth;
  //mySW.style.width = "100%";
  mySW.style.height = docHeight + 'px';
  mySWi.style.left = "20px";
  mySWi.style.top = "160px";
}

function closeSW() {
  var mySW = document.getElementById("scraper_warning");
  var mySWi = document.getElementById("sw_inner");

  mySW.style.display = "none";
  mySWi.style.display = "none";

  document.getElementById("skyscraper_target").style.display = "block";
  document.getElementById("button_target").style.display = "block";
  document.getElementById("banner_target").style.display = "block";

}


// End Referrer Checking


function checkLocation()
{
  if(document.mainform.noagents.value == 1)
  {
    alert("Sorry we have no agents listed for this location.");
	return false;
  }

  if(!document.mainform.locationid.value.match(/[A-Za-z0-9]/))
  {
    alert("Please select a location first");
	return false;
  }

  if(document.mainform.locationid.value == 7)
  {
    document.location.href = '/selling/glasgow-select.shtml';
	return true;
  }
  else if (document.mainform.locationid.value == 5)
  {
    document.location.href = '/selling/edinburgh-select.shtml';
	return true;
  }
  else
  {
    document.location.href = '/selling/contact_agents.cgi?location=' + document.mainform.locationid.value;
    return true;
  }
}

function showHiddenOptions()
{

	if (document.body.clientWidth > 895)
	{
		var targ = document.getElementById('advanced1024');
		if(targ)
		{
			targ.style.display = "none";
		}
		var targ2 = document.getElementById('hiddenOptions1024');
		if(targ2)
		{
			targ2.style.display = "block";
		}

	}
	else
	{
	   var targ = document.getElementById('advanced800');
	   if(targ)
	   {
	       targ.style.display = "none";
	   }
	   var targ2 = document.getElementById('hiddenOptions800');
	   if(targ2)
	   {
	       targ2.style.display = "block";
       }
	}
}

function checkHidden()
{
  if(document.stepOne)
  {


	if(	document.stepOne.garage && document.stepOne.garden && document.stepOne.centralheating &&document.stepOne.whenpropadded)
	{
	if(document.stepOne.garage.checked || document.stepOne.garden.checked ||
	   document.stepOne.centralheating.checked || document.stepOne.whenpropadded.value)
	  {
	  	showHiddenOptions();
	  }
	}

	if(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 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 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 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 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 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');

	if(target1){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 = myLabel;
                }
                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 run_onloading_funcs()
{
 //show advance option if values in them
 checkHidden();

 //show the sorted by drop down as we know js is enabled
 show_sorted_by();
 //write the range 1-5 etc. drop down
 if(startRange && rangeCount)
 {
  writeRange(startRange, rangeCount);
 }

 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)
 {
  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();

}

function run_onload_funcs()
{
 //create and hide the mini signin dropdown form
 create_sign_in_form();
 //add the range option to the bedrooms dropdown
 setup_bedrooms_range_option()
 //add an on change event to the location dropdown
 var targ = document.getElementById('locationSelector');
 if(targ)
 {
  addEvent( targ, 'change', getChildLocationAreasFaster);
  //show the very local option if location dropdown selected
 }

 var targ = document.getElementById('locationSelector4column');
 if(targ)
 {
  addEvent( targ, 'change', getChildLocationAreasFasterFour);
  //show the very local option if location dropdown selected
 }


 var targ = document.getElementById('locationSelectorAlter');
 if(targ)
 {
  addEvent( targ, 'change', getChildLocationAreasAlter);
  //show the very local option if location dropdown selected
 }

 var targ = document.getElementById('refine');
 if(targ)
     {
	 populate_search_form_with_cookie();
     }

 var targ = document.getElementById('signInForm');
 if(targ)
     {
	 if(targ.email)  { targ.email.focus(); }
     }
 showHideExplorer();

}

 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))
  {
  // Change the past date from strign to jsut puting a date as cookie expire is set to older date
  //results in the expiration/deletion
   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";

  }

}


 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;
}

// 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() + 6000000);
   var curCookie = "thispropcount=" + value + "; expires=" + ExpireDate.toGMTString() + "; path=/";
   document.cookie = curCookie;
 }

 function showSignOut()
 {
   var targ = document.getElementById('signout');
   if(targ)
   {
     targ.style.display = "inline";
   }

   targ = document.getElementById('signedInOnlyLinks');
   if(targ)
   {
     targ.style.display = "inline";
   }

   targ = document.getElementById('igoogle');
   if(targ)
   {
     targ.style.display = "inline";
   }
 }

 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 url = '';

	   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 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.location)
	{
	 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";
//	   alert(url);
	   xmlhttp.open("GET", url , true);
       xmlhttp.send(null);
       document.getElementById('locationHeader').style.display = 'block';

	}
	else
	{
		writecontent('');
		document.getElementById('locationHeader').style.display = 'none';
	}
}
function getChildLocationAreas ()
{

    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;
	}

	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
	{
	   var targ = document.getElementById('locationHeader');
	   if(targ)
	    {
	       targ.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)
	{
		if(document.stepOne.verylocals)
		{
	    var locationid = document.stepOne.location.options[document.stepOne.location.selectedIndex].value;
      var verylocals = document.stepOne.verylocals.value;
    }
	}
	if(document.getElementById('locationHeader'))
	{
	 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)
{

     if(document.getElementById('locationDetail')){
     document.getElementById('locationDetail').innerHTML = content;
    }
}

function read_cookie( name )
{

    return read_query_type( name, document.cookie, ';' );

}


function redirect_sortedby()
{
 var searchparams = document.mainform.searchparams.value;
 var script;
 if(document.getElementById('mapPage'))
   {
      script = "/buying/search/forsale_search_results_onmap.cgi?";
   }
   else
   {
       script = "/buying/search/forsale_search_results.cgi?";
   }
 if(searchparams != "")
 {
  if (document.mainform.sortedby)
  {
	var url = script + searchparams + "&sortedby=" + document.mainform.sortedby.options[document.mainform.sortedby.selectedIndex].value;
  }
  else
  {
	var url = script + searchparams + "&sortedby=" + document.sortedbyform.sortedby.options[document.sortedbyform.sortedby.selectedIndex].value;
  }
 document.location.href=url;
 }
}

function redirect_sortedby_newhomes()
{
	//searchparamsnosort
 var searchparams = document.mainform.searchparams.value;

 var url = "/newhomes/newhomes_search_results.cgi?" + searchparams + "&sortedby=" + document.mainform.sortedby.options[document.mainform.sortedby.selectedIndex].value;
 document.location.href=url;
}

function details_range_redirect()
{
  var searchparams = document.mainform.searchparams.value;
  var script;
  if(document.getElementById('mapPage'))
   {
      script = "/buying/search/forsale_search_results_onmap.cgi?";
   }
   else
   {
       script = "/buying/search/forsale_search_results.cgi?";
   }
  var url = script + searchparams + "&base=" + this.options[this.selectedIndex].value;
  if(document.mainform.fromnewhomes)
  {
   var fromnewhomes = document.mainform.fromnewhomes.value;
   url = "/newhomes/newhomes_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 script;
 if(document.getElementById('mapPage'))
   {
      script = "/buying/search/forsale_search_results_onmap.cgi?";
   }
   else
   {
       script = "/buying/search/forsale_search_results.cgi?";
   }
 var url = script + searchparams + "&base=" + this.options[this.selectedIndex].value;
 if(document.mainform.fromnewhomes)
 {
  var fromnewhomes = document.mainform.fromnewhomes.value;
  url = "/newhomes/newhomes_search_results.cgi?" + searchparams + "&base=" + this.options[this.selectedIndex].value;
 }

 document.location.href=url;
}

function sortedby_redirect()
{
 var searchparams = document.mainform.searchparamsnosort.value;
 if(searchparams != "")
 {
   var script;
   if(document.getElementById('mapPage'))
   {
      script = "/buying/search/forsale_search_results_onmap.cgi?"
   }
   else
   {
       script = "/buying/search/forsale_search_results.cgi?";
   }
      document.location.href=url;
	  var url = script + searchparams + "&sortedby=" + document.mainform.sortedby.options[document.mainform.sortedby.options.selectedIndex].value;
 }
}

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' )
		  if(id != 'undefined')
		  {
	        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 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 verifyPremier()
{
	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";
	}

	if (document.form1.password.value=="")
	{
		themessage = themessage + " - Your password\n";
	}
	//alert if fields are empty and cancel form submit

	if (themessage == "Please enter:\n")
	{
		return true;
	}
	else
	{
		alert(themessage);
		return false;
	}
}

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 verifyChangePassword()
{
	if ((document.form2.password.value=="") || (document.form2.password2.value=="") || (document.form2.password3.value==""))
	{
	     alert('Please complete all three password fields');
		return false;
	}
	else if (document.form2.password2.value != document.form2.password3.value)
	{
	    alert('Your new passwords do not match');
	    return false;
	}
	else
	{
		return true;
	}
}

function fastAds()
{
	var ad_types = new Array ( 'skyscraper', 'mpu', 'banner', 'nhslot1', 'nhslot2', 'nhslot3', 'nhslot4', 'nhslot5', 'nhslot6', 'nhslot7', 'nh_mpu' );
	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 changeNumberPerPage(number)
{
 var searchparams = document.mainform.searchparamsnosort.value;
 if(searchparams != "")
 {
 var url = "/buying/search/forsale_search_results.cgi?" + searchparams + "&numberPerPage=" + number;
 document.location.href=url;
 }
}


function create_remember_search_cookie(f)
{
    var fields = new Array('minprice', 'maxprice', 'type', 'bedrooms', 'location', 'keywords', 'whenpropadded');

	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');
	  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', 'newhomes', 'soldstcm' );
	  for (var i=0; i < checkedfields.length; i++)
	  {
        if(getCookie('search-' + checkedfields[i]))
				{
		  	 document.stepOne[checkedfields[i]].checked = true;
				}else
			{
				document.stepOne[checkedfields[i]].checked = false;
			}

      }

	  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;
}

// --- TRK


function checkCookie()
{
    if (getTCookie()) return true;
    setTCookie(30);
	if (getTCookie())
	{
		return true;
	}
    else
	{
		return false;
	}
}

function setTCookie(expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays)
        document.cookie="t=1" +
        ((expiredays==null) ? "" : "; expires="+exdate.toGMTString());
}

function getTCookie()
{
    if (document.cookie.match(/t=/))
	{
		return true;
	}
    else
	{
		return false;
	}
}

function trackParams()
{
   var domain = document.location.host;
   var url = document.location.pathname;
   var query_string = encodeURIComponent(document.location.search);
   var mys1id = null;
   var mycookie = document.cookie;
   var pos = mycookie.indexOf("mys1_eid=");
   if(pos != -1)
   {
      var start = pos + 9;
      var end = mycookie.indexOf(";", start);
      if(end == -1) end = mycookie.length;
      mys1id = unescape(mycookie.substring(start,end));
   }
   var params = "dom=" + domain + "&qs=" + query_string + "&url=" + url;
   if(mys1id)
   {
      params += "&mys1_eid=" + mys1id;
   }
   else
   {
	  var rv = Math.round(1000000*Math.random());
      params += "&rv=" + rv;
   }
   return params;
}

function writeTracker()
{
    var ccheck = checkCookie();
    if (!ccheck) return;
	    var params = trackParams();
	    var i=new Image(1,1);
	    i.src = "http://c.s1now.com/t.gif?"+params;
	    i.onload = function() { return ;}
}

// table row highlighting code
// requires the following line on the page to call the feature: window.onload=function(){tableruler();}
// also requires the table to have a class of 'ruler' attached to it

function tableruler()
{
 if (document.getElementById && document.createTextNode)
  {
   var tables=document.getElementsByTagName('table');
   for (var i=0;i<tables.length;i++)
   {
    if(tables[i].className=='ruler')
    {
     var trs=tables[i].getElementsByTagName('tr');
     for(var j=0;j<trs.length;j++)
     {
      if(trs[j].parentNode.nodeName=='TBODY' && trs[j].parentNode.nodeName!='TFOOT')
       {
       trs[j].onmouseover=function(){this.className='ruled'; return false}
       trs[j].onmouseout=function(){this.className=''; return false}
     }
    }
   }
  }
 }
}

// end table row highlighting code











addLoader( run_onload_funcs );
addEvent( window, 'load', run_onloading_funcs );
addEvent( window, 'resize', showHideExplorer );

addEvent( window, 'load', writeTracker );














