// Added flash insertion function //

function insertFlashMovie (src){
	document.write (src)
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image( 100, 25 );
		rslt.src = arg;
		return rslt;
	}
}


var tabColors = new Array();
tabColors[0] = '#092f5e';
tabColors[1] = '#bb0c1f';
tabColors[2] = '#209172';
tabColors[3] = '#cf5d0a';
tabColors[4] = '#a52983';
var tabTitles = new Array();
tabTitles[0] = "Search Properties For Sale";
tabTitles[1] = "Search Properties To Rent";
tabTitles[2] = "Search New Homes";
tabTitles[3] = "Search Commercial Properties";
tabTitles[4] = "Search Overseas Properties";

function initialiseSearchTabs(tabId)
{
  tabs = $(tabId).getElementsByTagName("LI");
  	if( GetCookie( tabId + "-current" ) )
  	{
  		currentTab = GetCookie( tabId + "-current" );
	}
	else
	{
		if ( GetCookie( "remember-" + tabId + "-current" ) )
		{
			currentTab = GetCookie( "remember-" + tabId + "-current" );
		}
		else
		{
			currentTab = 0;
		}
	}

	for(x=0; x < tabs.length; x++)
	{
		if(currentTab == x)
		{
			tabs[x].className = 'current';

			$("quick-search-title").style.backgroundColor = tabColors[x];
			$("quick-search-title").innerHTML = tabTitles[x];
			ChangeSearchTab( x );
		}
		tabs[x].getElementsByTagName("A")[0].onclick = function(){
			if(this.parentNode.className == 'current')
			{
				return true;
			}
		    tabs = $(tabId).getElementsByTagName("LI");
		    for(x=0; x < tabs.length; x++)
		    {
			    if(tabs[x] == this.parentNode){

					  if ( x == 5 )
						{
							tabs[x].className = 'currentGreen';
						}
						else
						{
							tabs[x].className = 'current';
						}
		    		$("quick-search-title").style.backgroundColor = tabColors[x];
		    		$("quick-search-title").innerHTML = tabTitles[x];
				    ChangeSearchTab( x );
						if ( x != 5)
						{
							SetCookie( tabId + "-current", x, 1000, "/" );
						}
			    }
			    else
			    {
						if ( x == 5 )
						{
							tabs[x].className = 'green';
						}
						else
						{
							tabs[x].className = '';
						}
			    }
		    }
		    //$("searchTextBox").focus();
			return searchTabsReturnValue;
		};
	}
}

var saleType;

function ChangeSearchTab( tabID )
{
	$("searchType").style.display = 'none';

	switch(tabID)
	{
	case 0:
		saleType= 'Sale';
		$("region-search").style.display = 'block';
		//if( regionCode != 'IE' )
		//{
		//	$("region-epc").style.display = 'none';
		//}
		$("searchRooms").style.display = 'block';
		advanceSearchLink = "/homesearch.php";
		$("searchClass").value = "s";
		break;
	case 1:
		saleType= 'Rental';
		$("region-search").style.display = 'block';
		//if( regionCode != 'IE' )
		//{
		//	$("region-epc").style.display = 'none';
		//}
		$("searchRooms").style.display = 'block';
		advanceSearchLink = "/rentalsearch.php";
		$("searchClass").value = "r";
		break;
	case 2:
		saleType= 'NewHomes';
		$("region-search").style.display = 'block';
		//if( regionCode != 'IE' )
		//{
		//	$("region-epc").style.display = 'none';
		//}

		$("searchRooms").style.display = 'block';

		advanceSearchLink = "/newhomes.php";
		$("searchClass").value = "s";
		break;
	case 3:
		saleType= 'Commercial';
		$("searchType").style.display = 'block';
		$("region-search").style.display = 'block';
		//if( regionCode != 'IE' )
		//{
		//	$("region-epc").style.display = 'none';
		//}
		$("searchRooms").style.display = 'none';
		advanceSearchLink = "/commercial.php";
		$("searchClass").value = "cb";
		break;
	case 4:
		saleType= 'Overseas';
		$("region-search").style.display = 'block';
		//if( regionCode != 'IE' )
		//{
		//	$("region-epc").style.display = 'none';
		//}
		$("searchRooms").style.display = 'block';
		advanceSearchLink = "/overseas.php";
		$("searchClass").value = "s";
		break;
	case 5:
		$("region-search").style.display = 'none';
		//if( regionCode != 'IE' )
		//{
		//	$("region-epc").style.display = 'block';
		//}
		break;

	}

	advanceSearchLinks = document.getElementsByName("SearchAdvancedLink");
	for ( y = 0; y < advanceSearchLinks.length; y++ )
	{
		advanceSearchLinks[y].href = advanceSearchLink;
	}
	UpdateMaxPrice( saleType );
	SetRoomValues( saleType );
}

function SetRoomValues( saleType )
{
    optionElements = document.getElementById( "rooms" ).options;

	switch ( saleType )
	{
		case "Rental":
			for ( j = 0; j < optionElements.length; j++  )
			{
				if ( optionElements[j].value == 1 )
				{
					optionElements[j].text = "1";
				}
				if ( optionElements[j].value == 2 )
				{
					optionElements[j].text = "2";
				}
				if ( optionElements[j].value == 3 )
				{
					optionElements[j].text = "3";
				}
				if ( optionElements[j].value == 4 )
				{
					optionElements[j].text = "4";
				}
				if ( optionElements[j].value == 5 )
				{
					optionElements[j].text = "5+";
					optionElements[j].value = 99;
				}
				if ( optionElements[j].value == 6 )
				{
					optionElements[j].value = -1;
					optionElements[j].text = "Shared";
				}
			}
			break;
		default:
			for ( j = 0; j < optionElements.length; j++  )
			{
				if ( optionElements[j].value == 1 )
				{
					optionElements[j].text = "1+";
				}
				if ( optionElements[j].value == 2 )
				{
					optionElements[j].text = "2+";
				}
				if ( optionElements[j].value == 3 )
				{
					optionElements[j].text = "3+";
				}
				if ( optionElements[j].value == 4 )
				{
					optionElements[j].text = "4+";
				}
				if ( optionElements[j].value == 99 )
				{
					optionElements[j].value = "5";
				}
				if ( optionElements[j].value == -1 )
				{
					optionElements[j].value = 6;
					optionElements[j].text = "6+";
				}
			}
			break;
	}
}

function UpdateMaxPrice( type )
{

	switch (type)
	{
		case "NewHomes":
		case "Commercial":
		case "Overseas":
			type = "Sale"
			break;
	}
	var currency = (regionCode == "GB") ? "GBP" : "EUR";
	type = ( !type )? "Sale" : type;

	var maxPriceValue = document.getElementById( 'MaxPrice' ).value;
	var url = '/ajax/priceMatrix.php';
	var pars = 'c=' + currency + '&t='+type+'&s=Max&e=MaxPrice&st=0&cv=' + maxPriceValue;

	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onSuccess: function(response)
			{
				$("searchPrice").innerHTML = "<h5>Max Price</h5>"+response.responseText;
			}
		});
}

function ChangeOpacity( object, opacity )
{
    object.style.opacity = opacity;
    object.style.MozOpacity = opacity;
    object.style.KhtmlOpacity = opacity;
    object.style.filter = "alpha(opacity=" + ( opacity * 100 ) + ")";
}

var dialogBackground;

function GetScrollOffsetY()
{
	var y;

	if (self.pageYOffset) // all except Explorer
	{
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		y = document.body.scrollTop;
	}

	return y;
}

function CreateDialogBackground()
{
	dialogBackground = document.createElement( "div" );
	dialogBackground.style.position = 'absolute';
	dialogBackground.style.left = '0';
	dialogBackground.style.top = '0';
	dialogBackground.style.width = '100%';

	var pageHeight;

	pageHeight = document.documentElement.scrollHeight;

	dialogBackground.style.height = pageHeight + "px";
	dialogBackground.style.backgroundColor = '#000000';
	dialogBackground.style.zIndex = 100;
	ChangeOpacity( dialogBackground, 0.3 );
	dialogBackground.id = 'blackDiv';

	document.body.appendChild( dialogBackground );
}

function DestroyDialogBackground()
{
	dialogBackground.style.display = 'none';
}




function showMoreFilters(x,e)
{
    hideMoreFilters(e);
	if (!e) var e = window.event;
	e.cancelBubble=true;
	//window.event.cancelBubble = true;
	list = document.getElementById("more-"+x);
	numberOfItems= list.getElementsByTagName("DD").length;
	if(numberOfItems > 16){
		list.style.overflowY = 'auto';
        list.style.overflowX = 'hidden';
        list.style.paddingRight = '20px';
		list.style.height = '267px';
	}
	list.style.display="block";
}

function initialiseTabs(tabId, initialTab)
{
	tabs = $(tabId).getElementsByTagName("LI");

    if( initialTab != "" )
    {
        document.getElementById(tabId+initialTab).style.display = 'block';
    }
	for(x=0; x < tabs.length; x++)
	{
		tabs[x].getElementsByTagName("A")[0].onclick = function(){
					tabs = $(tabId).getElementsByTagName("LI");
					for(x=0; x < tabs.length; x++)
					{
						if(tabs[x] == this.parentNode){
							tabs[x].className = 'current';
							document.getElementById(tabId+(x+1)).style.display = 'block';
						}
						else
						{
							tabs[x].className = '';
							document.getElementById(tabId+(x+1)).style.display = 'none';
						}
					}

				return false;
		};
	}
}

var memberTabsObjTimer;

function MemberOptionTabs( tabGroupId )
{
    this.tabGroupId = tabGroupId;
    this.Initialise = Initialise;
    this.Show = Show;
    this.Hide = Hide;
    this.currentTab = -1;
    this.currentTabIndex = -1;
    this.overTab = false;
    this.timer;
    this.LoadData = LoadData;
    this.GetTabIndex = GetTabIndex;

    function Initialise()
    {
        this.tabs = $(this.tabGroupId).getElementsByTagName("LI");

        for(x=0; x < this.tabs.length; x++)
        {
            tabA = this.tabs[x].getElementsByTagName("A")[0];
            tabDiv = $(this.tabGroupId+(x+1));
            tabA.onmouseover = function()
            {
                clearTimeout(this.timer);
                memberTabsObj.overTab = true;
                if( memberTabsObj.currentTabIndex == -1 || memberTabsObj.currentTabIndex != memberTabsObj.GetTabIndex())
                {
                    memberTabsObj.currentTab = this;
                    memberTabsObjTimer = setTimeout("memberTabsObj.Show()",500);
                }
            };
            tabDiv.onmouseover = function()
            {
                //alert(memberTabsObjTimer);
                clearTimeout(memberTabsObjTimer);
                memberTabsObj.overTab = true;
            };
            tabA.onmouseout = function()
            {
                clearTimeout(memberTabsObjTimer);
                memberTabsObjTimer = setTimeout("memberTabsObj.Hide()",500);
                memberTabsObj.overTab = false;
            };
            tabDiv.onmouseout = function()
            {
                clearTimeout(memberTabsObjTimer);
                memberTabsObj.overTab = false;
                memberTabsObjTimer = setTimeout("memberTabsObj.Hide()",500);
            };
        }
    }

    function Show()
    {
        this.tabs = $(this.tabGroupId).getElementsByTagName("LI");
        for(x=0; x < this.tabs.length; x++)
        {
            if(this.tabs[x] == memberTabsObj.currentTab.parentNode){
                this.tabs[x].className = 'current';
                $(this.tabGroupId+(x+1)).style.display = 'block';
            }
            else
            {
                this.tabs[x].className = '';
                $(this.tabGroupId+(x+1)).style.display = 'none';
            }
        }
        this.currentTabIndex = x+1;
        this.LoadData();
    }

    function Hide()
    {
        if (this.overTab == false)
        {
            for(x=0; x < this.tabs.length; x++)
            {
            	this.tabs[x].className = '';
            	document.getElementById(this.tabGroupId+(x+1)).style.display = 'none';
            }
            this.currentTab = -1;
            this.currentTabIndex = -1
        }
    }

    function LoadData()
    {
        x = this.GetTabIndex();
        var alertUrl = "/ajax/load-member-data.php";
        var pars = "x=" + x;

        var updater = new Ajax.Updater(
            this.tabGroupId + "Content" + x,
            alertUrl,
            {
                method: 'get',
                parameters: pars
            });
    }

    function GetTabIndex()
    {
        if(this.currentTab != -1){
            currentLi = this.currentTab.parentNode;
            this.tabs = $(this.tabGroupId).getElementsByTagName("LI");
            x = 0;
            while(currentLi != this.tabs[x])
            {
                x++;
            }
            x++;
        }
        else x= -1;
        return x;
    }
}

function testAlert(tab){

	alert(tab.getElementsByTagName("SPAN")[0].innerHTML);
}

var preLoad = [];
function initialisePage(){
		try
		{
			$( "searchTextBox" ).setAttribute('autocomplete','off');
		}
		catch ( e ) {  }


		if ( document.images )
		{
			for(x=0;x<preLoad.length;x++)
			{
				var preImage = newImage( preLoad[x] );
			}
		}
        setTimeout("LoadAdverts()", 100);
	}


    var advertsToLoad = Array();

    function LoadAdverts()
    {
        for (x = 0; x < advertsToLoad.length; x++ )
        {
            document.getElementById(advertsToLoad[x][0]).innerHTML = advertsToLoad[x][1];
        }
    }

	function UpdatePreviewStatus()
	{
		if ( ( inTextbox || inPreview ) && ( !previewEmpty ) )
		{
			document.getElementById('searchCriteriaPreview').style.display='block';
			document.getElementById('QSearchCntr').style.border='1px solid #837A4F';
			document.getElementById('QSearchCntr').style.backgroundColor='#FFF7D1';
		}
		else
		{
			document.getElementById('searchCriteriaPreview').style.display='none';
			document.getElementById('QSearchCntr').style.border='1px solid #FFFFFF';
			document.getElementById('QSearchCntr').style.backgroundColor='#FFFFFF';
		}
	}

	function n(o){
		if(o&&o.className)
		{
			o.className=o.className+"N";
		}
	}

	function nbc(c){
		o = document.getElementsByClassName(c)
		for(x = 0; x < o.length; x++){
			n(o[x]);
		}
	}


	function e(n){return document.getElementById(n);}

	document.getElementsByClassName = function(className) {
  var children = document.getElementsByTagName('*') || document.all;
  var elements = new Array();
  for (var i = 0; i < children.length; i++) {
    var child = children[i];
    var classNames = child.className.split(' ');
    for (var j = 0; j < classNames.length; j++) {
      if (classNames[j] == className) {
        elements.push(child);
        break;
      }
    }
  }
  return elements;
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function getAdSize(containerID)
{
	var adSize = new Array();
	childNode = document.getElementById(containerID).childNodes
	for(x=0; x<childNode.length;x++)
	{
		try
		{
			if (childNode[x].nodeValue && childNode[x].nodeValue.indexOf("GiantBanner") > 0)
			{
				adSize["width"] = 750;
				adSize["height"] = 90;
				return adSize;
			}
			//alert(childNode[x].tagName);
			if((childNode[x].tagName == "OBJECT" || childNode[x].tagName == "IMG" || childNode[x].tagName == "IFRAME") && childNode[x].width)
			{
				adSize["width"] = childNode[x].width;
				adSize["height"] = ( childNode[x].height > 90 ) ? 70 : childNode[x].height;
				//alert(adSize["height"] + " :: " + adSize["width"]);
				return adSize;
			}
			if(childNode[x].tagName == "A")
			{
				childNode2 = childNode[x].childNodes
				for(j=0; j<childNode2.length;j++)
				{
					if(childNode2[j].tagName == "IMG" && childNode2[j].width ){
						adSize["width"] = childNode2[j].width;
						adSize["height"] = ( childNode2[j].height > 90 ) ? 70 : childNode2[j].height;
						return adSize;
					}
				}
			}
		}
		catch(e)
		{
			//assume small
			adSize["width"] = 468;
			adSize["height"] = 60;
		}
	}
	if (!adSize["width"]){
			adSize["width"] = 468;
			adSize["height"] = 60;
	}
	return adSize;
}

function showMenu(menuID)
{
	menu = e(menuID);
	childNode = menu.childNodes;
	var menuHeight = 0;
	for(x = 0;x < childNode.length; x++){
		if(childNode[x].tagName == 'DIV') menuHeight += 19;
	}
	menu.style.height = menuHeight + 'px';
}

function hideMenu(menuID)
{

	menu = e(menuID);
	menu.style.height = 17 + 'px';
}

function locationHref(loc)
{
	if(!window.event || window.event.srcElement && window.event.srcElement.tagName == "A")
	{
		return
	}
	else location.href = loc;
}


function changeImages() {
	if (document.images) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document.getElementById(changeImages.arguments[i]).src = changeImages.arguments[i+1];
		}
	}
}

var searchTimer;
var hideTimer;

function HideSearchPopups()
{
	var resultDiv = document.getElementById( 'searchLocationResults' );
	var hintDiv = document.getElementById( 'searchLocationHint' );
	hintDiv.style.display = 'none';
	resultDiv.style.display = 'none';

	ShowSelects();

	dontSampleTextBox = false;
}

function LeaveSearch()
{
	hideTimer = setTimeout( "HideSearchPopups()", "200" );

	var searchText = document.getElementById( 'searchTextBox' ).value;

	var searchUl = document.getElementById( 'searchUl' );

	if ( searchUl.getElementsByTagName( 'li' ).length > 1 )
	{
		return;
	}

	document.getElementById( 'searchWatermark' ).style.display = ( searchText == "" ) ? 'block' : 'none';
}

function EnterSearch()
{
	var resultsWindow = document.getElementById('searchLocationResults');

	UpdateSearchHintText();

	LocationLookup();

	document.getElementById( 'searchWatermark' ).style.display = 'none';
}

function StartSearchTimer()
{
	searchTimer = setTimeout( 'LocationLookup();', 200 );
}

function SearchBoxKeyPress( ev )
{
	if ( !ev )
	{
		ev = window.event;
	}

	if ( ( navigator.appVersion.indexOf( "MSIE" ) == -1 ) && ( ( ev.keyCode == 38 ) || ( ev.keyCode == 40 ) ) )
	{
		return false;
	}

    if( ( ev.keyCode == 13 ) )
    {
        return false;
    }

	CheckSearchBoxSize();
	StartSearchTimer();

	return true;
}

var removeLi;

function SearchKeyDown( ev )
{
	if ( !ev )
	{
		ev = window.event;
	}

   	if ( ev.keyCode == 8 )
	{
		var textBox = document.getElementById( 'searchTextBox' );
		var selStart = -1;
		var selLength = 0;

    	if ( typeof textBox.selectionStart != "undefined" )
		{
			selStart = textBox.selectionStart;
			selLength = textBox.selectionEnd - selStart;
		}
		else
		{
			if (document.selection)
			{
				selLength = document.selection.createRange().text.length;
				selStart = Math.abs(document.selection.createRange().moveStart("character", -1000000));
			}
		}

		if ( ( selStart == 0 ) && ( selLength == 0 ) )
		{
			var ul = document.getElementById( 'searchUl' );
			var lis = ul.getElementsByTagName( 'li' );

			if ( lis.length > 1 )
			{
				removeLi = lis[ lis.length - 2 ];
			}
		}
	}
}

function CheckForDownArrow( ev )
{
	if ( !ev )
	{
		ev = window.event;
	}

	var resultList = document.getElementById( 'resultList' );

	// 38 is up
	// 40 is down
	if ( ev.keyCode == 38 )
	{
		selectedRow--;


		if ( selectedRow < 2 )
		{
			selectedRow = 0;
		}
	}

	if ( ev.keyCode == 40 )
	{
		selectedRow++;

		if ( selectedRow > ( resultList.getElementsByTagName( 'li' ).length - 1 ) )
		{
			selectedRow = resultList.getElementsByTagName( 'li' ).length - 1;
		}
		else if ( selectedRow == 1 )
		{
			selectedRow = 2;
		}
	}

	if ( ev.keyCode == 13 )
	{
		var resultDiv = document.getElementById( 'searchLocationResults' );

		if ( ( resultDiv.style.display == 'block' ) && ( selectedRow > -1 ) )
		{
			var lis = resultList.getElementsByTagName( 'li' );
			var li = lis[ selectedRow ];

			var areaId = li.getAttribute('areaId');
			var locationName = li.getAttribute('locationName');
			var areaName = li.getAttribute('areaName');
			var isArea = li.getAttribute( 'isArea' );

			if ( areaId != "" )
			{
				AddSearchLocation( areaId, locationName, areaName, isArea );
				EnterSearch();
			}
			else
			{
				HideSearchPopups();

                if ( QuickSearchSubmit() )
				{
					// Submit the form
					document.forms["searchForm"].submit();
				}
			}
		}
		else
		{
			if ( QuickSearchSubmit() )
			{
				// Submit the form
				document.forms["searchForm"].submit();
			}
		}
	}

	if ( ev.keyCode == 8 )
	{
		if ( removeLi )
		{
			var ul = document.getElementById( 'searchUl' );
			ul.removeChild( removeLi );

			UpdateSearchHintText();

			removeLi = null;

			DecideToShowRadius();
		}

    	LocationLookup();
	}

	SelectResultRow();

	return false;
}

var selectedRow = -1;

function SelectResultRow()
{
	var resultList = document.getElementById( 'resultList' );

	if ( !resultList )
	{
		return;
	}

	var lis = resultList.getElementsByTagName( 'li' );

	for( var i = 0; i < lis.length; i++ )
	{
		var li = lis[ i ];

		li.className = ( i == selectedRow ) ? "searchLocationSelectedResult" : "searchLocationResult";
	}
}

var dontSampleTextBox = false;
var searchText = "";

function LocationLookup()
{
	if ( !dontSampleTextBox )
	{
		searchText = document.getElementById( 'searchTextBox' ).value;
	}

	if ( searchText == "" || searchText.replace(' ','').length < 3 )
	{
		var resultDiv = document.getElementById( 'searchLocationResults' );

		UpdateSearchHintText();
		ShowSelects();
		resultDiv.style.display = 'none';
		return;
	}

	if ( !dontSampleTextBox )
	{
		selectedRow = -1;
	}

	var resultsWindow = document.getElementById('searchLocationResults');

	var searchType = "l";

	if ( saleType == 'Overseas' )
	{
		searchType = "o";
	}

	if ( saleType == 'NewHomes' )
	{
		searchType = "n";
	}

	var ajaxUrl = '/ajax/location-lookup.php';
	var pars = 's=' + escape( searchText ) + '&t=' + searchType;

	var ajax = new Ajax.Request(
		ajaxUrl,
		{
			method: 'get',
			parameters: pars,
			onSuccess: function( response )
			{
				var hintDiv = document.getElementById( 'searchLocationHint' );
				var resultDiv = document.getElementById( 'searchLocationResults' );

				if ( response.responseText == "" )
				{
					UpdateSearchHintText();
					resultDiv.style.display = 'none';
					ShowSelects();
				}
				else
				{
					hintDiv.style.display = 'none';
					resultDiv.style.display = 'block';
					HideSelects();
	                resultDiv.innerHTML = response.responseText;

	                resultDiv.style.height = ( ( document.getElementById( 'resultList' ).getElementsByTagName( 'li' ).length * 27 ) + 74 ) + "px";

//	                SelectResultRow();
				}

				UpdateSearchHintText();
			}
		});

		DecideToShowRadius();
}

function ShowSelects()
{
	var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

	if ( !isIE6 )
	{
		return;
	}

	var selects = document.getElementsByTagName( "select" );

	for( var x = 0; x < selects.length; x++ )
	{
		selects[x].style.visibility = 'visible';
	}
}

function HideSelects()
{
	var isIE6 = navigator.userAgent.toLowerCase().indexOf('msie 6') != -1;

	if ( !isIE6 )
	{
		return;
	}

	var selects = document.getElementsByTagName( "select" );

	for( var x = 0; x < selects.length; x++ )
	{
		selects[x].style.visibility = 'hidden';
	}
}

function DecideToShowRadius()
{
    return;
	var ul = document.getElementById( 'searchUl' );
	var lis = ul.getElementsByTagName( "li" );

	if ( lis.length > 1 )
	{
		document.getElementById( 'searchRadius' ).style.display = 'block';
	}
	else
	{
		if ( document.getElementById( 'searchRadius' ).style.display == 'block' )
		{
			document.getElementById( 'searchRadius' ).style.display = 'none';
			document.getElementById( 'Radius' ).value = '';
		}
	}
}

var maxSearchWidth = 365;
var suppressSearchHint = false;

function UpdateSearchHintText()
{
	var ul = document.getElementById( 'searchUl' );
	var text = "";

	if ( ul.getElementsByTagName('li').length > 1 )
	{
		text = "Continue typing to search for additional locations, or add other search terms";
	}

	if ( suppressSearchHint )
	{
		text = "";
	}

	var hintDiv = document.getElementById( 'searchLocationHint' );
	hintDiv.innerHTML = text;
	hintDiv.style.display = ( text == "" ) ? 'none' : 'block';
}

function CheckSearchBoxSize()
{
	var searchBox = document.getElementById( 'searchTextBox' );
	var length = searchBox.value.length;

	var size = length * 7 + 10;

	if ( size > maxSearchWidth )
	{
		size = maxSearchWidth;
	}

	if ( size < 100 )
	{
		size = 100;
	}

	searchBox.style.width = size + 'px';
}

function RemoveSearchLocation( areaId )
{
	var ul = document.getElementById( 'searchUl' );
	var li = document.getElementById( 'lli-' + areaId );

	ul.removeChild( li );

	UpdateSearchHintText();

	clearTimeout( hideTimer );

	DecideToShowRadius();
}

var dontFocus = false;
var addLocationData;

function MetaAddSearchLocation( e )
{
	if ( !e )
	{
		var e = window.event;
	}

	AddSearchLocation( addLocationData.locationId, addLocationData.location, addLocationData.area, addLocationData.isArea, e );
}

var clearOnLeave = false;

function AddSearchLocation( locationId, location, area, isArea, e )
{
	// Create a new li and add it to the list
	var newLi = document.createElement( 'li' );
	var inputName = ( ( isArea == "true" ) || ( isArea == true ) ) ? "Area" : "Location";

	newLi.id = 'lli-' + locationId;
    newLi.className = 'selected-item';
	newLi.innerHTML = '<span style="font-weight: bold;" title="' + location + ', ' + area + '">' + location + "</span><a href='javascript: RemoveSearchLocation(\"" + locationId + "\");'>x</a><input type='hidden' name='" + inputName + "[]' value='" + locationId + "' />";
	var ul = document.getElementById( 'searchUl' );
	ul.insertBefore( newLi, document.getElementById( 'searchLi' ) );

	document.getElementById( 'searchTextBox' ).value = '';

	if ( !e || !e.ctrlKey )
	{
		document.getElementById( 'searchLocationResults' ).style.display = 'none';

	    if ( !dontFocus )
	    {
		    document.getElementById( 'searchTextBox' ).focus();
	    }
	}
	else
	{
		dontSampleTextBox = true;
	}

	DecideToShowRadius();

	clearTimeout( hideTimer );
}

function QuickSearchSubmit()
{
	var form = document.getElementById( 'searchForm' );
	var resultList = document.getElementById( 'searchUl' );

	if( saleType == "NewHomes" )
	{
		// See if we have any areas and build a redirect string instead of posting the form.
        var lis = resultList.getElementsByTagName( 'li' );

        var areaVal = "";
        var searchPhrase = "";

        var bedrooms = document.getElementById( "rooms" ).value;
        var maxPrice = document.getElementById( "MaxPrice" ).value;

		for( var i = 0; i < lis.length; i++ )
		{
			// Get the input if we have one
			var inputs = lis[ i ].getElementsByTagName( 'input' );

	        for( var x = 0; x < inputs.length; x++ )
			{
				var input = inputs[ x ];

				if ( input.name == 'Area[]' )
				{
					areaVal = input.value;
				}

                if ( input.name == 'ph' )
				{
					searchPhrase = input.value;
				}
			}
		}

		location.href = '/newhomesSearch.php?q=' + searchPhrase + '&a=' + areaVal + '&Bedrooms=' + bedrooms + '&MaxPrice=' + maxPrice;
		return false;
	}

    if( saleType == "Overseas" )
	{
		form.action = '/overseas-results.php';
	}

	return true;
}

// Toggle layer visibility for map page
function ToggleLayer( whichLayer )
{
  var elem, vis, newvis;

  elem = document.getElementById( whichLayer );

  vis = elem.style;

  vis.display = ( vis.display == 'block' ) ? 'none' : 'block';
  elem.parentNode.className = (vis.display == 'block') ? "primary-filter-li minus" : "primary-filter-li plus";
  return false;
}

// Toggle layer visibility for normal pages
function ToggleLayerNormal( whichLayer )
{
  var elem, vis, newvis;

  elem = document.getElementById( whichLayer );

  vis = elem.style;

  vis.display = ( vis.display == 'block' ) ? 'none' : 'block';

  return false;
}

//
// Cookie Handling functions
//

function SetCookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this function gets the cookie, if it exists
function GetCookie( name ) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length,c.length));
        }
        return null;
}

function deleteCookie( name, path, domain ) {
	if ( GetCookie( name ) )
		document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function CreateBookmarkLink() {

	if (document.all)
	{
		window.external.AddFavorite(location.href, document.title);
	}
	else if (window.sidebar)
	{
		window.sidebar.addPanel(document.title, location.href, "")
	}

}


function PreferIE()
{
    SetCookie( "preferIE", "1", 360, "/", ".propertynews.com", false );

}

function PreferCurrentSite()
{
    SetCookie( "pncDontIePrompt", "1", 360, "/", ".propertynews.com", false );
    SetCookie( "pncDontIePrompt", "1", 360, "/", ".propertynews.ie", false );
    SetCookie( "pncDontIePrompt", "1", 360, "/", ".gcdtech.com", false );
}

function KeepNewSite( al )
{
	SetCookie( "pncBetaPrefer", "1", 360, "/", ".propertynews.com", false );

	if( al == true )
	{
		alert( "The beta site is now stored as your homepage preference. You can change this at any time by clicking 'Leave the beta' at the top of the site." );
	}
}

// ADD TO FAVOURITES javascript call
function AddToFavourites( property, type, member, development )
{
    if ( type == 'add' )
    {
    	document.getElementById( "addToFavourites-"+property ).innerHTML = "<span class='quiet'>Saving...</span>";
	}
	else if ( type == 'remove' )
	{
		document.getElementById( "addToFavourites-"+property ).innerHTML = "<span class='quiet'>Removing...</span>";
	}
    if ( member == '' )
    {
          window.location="/member/login.php";
    }
    else
    {
        var ajaxUrl = "/ajax/add-to-favourites.php";
        var pars = "p=" + property + "&t=" + type + "&m=" + member + "&d=" + development;

        var ajax = new Ajax.Request(
            ajaxUrl,
            {
                method: 'get',
                parameters: pars,
                onSuccess:function( response )
                {

                    if( type == "add" )
                    {
                        document.getElementById( "addToFavourites-"+property ).className = "propAdded";
                        document.getElementById( "addToFavourites-"+property ).innerHTML = response.responseText;

                        if ( favourites )
                        {
                        	favourites[ favourites.length ] = property;

                        	map.clearOverlays();
      						setTimeout('PlacePins()',1);
						}
                    }
                    else
                    {
                        document.getElementById( "addToFavourites-"+property ).className = "propAdd";
                        document.getElementById( "addToFavourites-"+property ).innerHTML = response.responseText;
                        if ( favourites )
                        {
                        	for ( x = 0; x < favourites.length; x++ )
                        	{
                        		if ( favourites[ x ] == property )
                        		{
                        			favourites.splice( x, 1 );
                        			break;
								}
							}

							map.clearOverlays();
						    setTimeout('PlacePins()',1);
                    	}
                	}
				}
        });
	}
}


function inArray( srcArray,value )
{
	var i;
	for ( i = 0; i < srcArray.length; i++ )
	{
		if ( srcArray[ i ] === value )
		{
			return true;
		}
	}
	return false;
};

function AttemptToSelectFirstControl ( dialog )
{

}

/////////////////////////////////
// PgDialog Javascript


function DestroyDialog( dialogName )
{
	DestroyDialogBackground();
	document.getElementById( 'dialog-' + dialogName ).style.display = 'none';

    var dialogContent = document.getElementById( 'dialog-content-' + dialogName );
	var processingContent = document.getElementById( 'dialog-processing-' + dialogName );

	if ( dialogContent )
	{
		dialogContent.style.display = 'block';
	}

	if ( processingContent )
	{
		processingContent.style.display = 'none';
	}
}

function DialogError( dialogName,error )
{
	var processingContent = document.getElementById( 'dialog-processing-' + dialogName );

	if ( processingContent )
	{
		processingContent.innerHTML = '<p style="text-align: center">An error occured during this operation.';

		if ( error )
		{
			processingContent.innerHTML += '<blockquote>' + error + '</blockquote>';
		}

		processingContent.innerHTML += '</p><p style="text-align: center"><a href="javascript: DestroyDialog( \'' + dialogName + '\');">Cancel</a></p></center>';
	}
}

function DialogSuccess( dialogName, message )
{
	var processingContent = document.getElementById( 'dialog-processing-' + dialogName );

	if ( processingContent )
	{
		processingContent.innerHTML = '<p style="text-align: center"><blockquote>' + message;
		processingContent.innerHTML += '</blockquote></p><p style="text-align: center"><a href="javascript: DestroyDialog( \'' + dialogName + '\');">Close</a></p></center>';
	}
}

function SubmitDialog( dialogName )
{
	var dialogContent = document.getElementById( 'dialog-content-' + dialogName );
	var processingContent = document.getElementById( 'dialog-processing-' + dialogName );

	if ( dialogContent )
	{
		var result = true;
		var evalString = 'result = ProcessDialog' + dialogName + '();';

		eval( evalString );

		if ( result == false )
		{
			return;
		}

		if ( !processingContent )
		{
			div = document.createElement( "div" );
			div.id = 'dialog-processing-' + dialogName;

			dialogContent.parentNode.insertBefore( div, dialogContent.nextSibling);
			processingContent = div;
		}

		processingContent.innerHTML = "<center><img src='/images/processing.gif' /><p style='text-align: center'><a href=\"javascript: DestroyDialog( '" + dialogName + "');\">Cancel</a></p></center>";

		dialogContent.style.display = 'none';
		processingContent.style.display = 'block';
	}
}

function ShowDialog( dialogName )
{
	CreateDialogBackground();
	var top = GetScrollOffsetY();
	document.getElementById( 'dialog-' + dialogName ).style.marginTop = top + 'px';
	document.getElementById( 'dialog-' + dialogName ).style.display = 'block';

	AttemptToSelectFirstControl( document.getElementById( 'dialog-' + dialogName ) );
}

// End PgDialog Javascript
/////////////////////////////////

