var objVisibleLayer;
var aPrices = new Array(8);
aPrices[0] = 50;
aPrices[1] = 100;
aPrices[2] = 250;
aPrices[3] = 500;
aPrices[4] = 750;
aPrices[5] = 1000;
aPrices[6] = 1500;
aPrices[7] = 2000;

var aPricesText = new Array(8);
aPricesText[0] = '50,000';
aPricesText[1] = '100,000';
aPricesText[2] = '250,000';
aPricesText[3] = '500,000';
aPricesText[4] = '750,000';
aPricesText[5] = '1,000,000';
aPricesText[6] = '1,500,000';
aPricesText[7] = '2,000,000';

var selPrices = new Array(8);
selPrices[0] = false;
selPrices[1] = false;
selPrices[2] = false;
selPrices[3] = false;
selPrices[4] = false;
selPrices[5] = false;
selPrices[6] = false;
selPrices[7] = false;

var selMinPrice = -1;
var selMaxPrice = -1;

var rssItemCount = 0;
var rssItemCounter = 0;
var rssItems;

var priceMin = 0;
var priceMax = 99999999;

function selectPrice(p)
{
	var pSummary = '';
	
	selPrices[p] = !selPrices[p];
	
	selMinPrice = -1;
	selMaxPrice = -1;
	
	for(i = 0; i < selPrices.length; i++)
	{
		if(selPrices[i])
		{
			if(selMinPrice == -1)
			{
				selMinPrice = i;
			}
			selMaxPrice = i;
		}
	}
	
	if(selMinPrice > -1)
	{
		for(i = selMinPrice; i <= selMaxPrice; i++)
		{
			selPrices[i] = true;
		}
		
		if(selMinPrice != selMaxPrice)
		{
			pSummary = "Between £" + aPricesText[selMinPrice] + ' and £' + aPricesText[selMaxPrice];
		}
		else
		{
			pSummary = "Up to £" + aPricesText[selMinPrice];
		}
		
		if(selMaxPrice == 7)
		{
			pSummary += "+";
		}
		
		document.getElementById('minPrice').value = aPrices[selMinPrice];
		document.getElementById('maxPrice').value = aPrices[selMaxPrice];
	}
	else
	{
		document.getElementById('minPrice').value = 0;
		document.getElementById('maxPrice').value = 99999999;
	}
	
	for(i = 0; i < selPrices.length; i++)
	{
		if(selPrices[i])
		{
			document.getElementById('price_'+aPrices[i]).src = 'images/price'+aPrices[i]+'-on.gif';
		}
		else
		{
			document.getElementById('price_'+aPrices[i]).src = 'images/price'+aPrices[i]+'-off.gif';
		}
	}
	
	
	document.getElementById('priceSummary').innerHTML = pSummary;
}

function RefreshForm(formName) 
{
	var f = document.getElementById(formName);
	f.postback.value = 1;

	f.submit();
}

function RefreshQForm(formName, formType) 
{
	var f = document.getElementById(formName);
	document.getElementById("postback" + formType).value = 1;

	f.submit();
}

function registerAuctionAlerts()
{
	var f = document.getElementById('frmEnquiry');
	var msg = '';
	
	if(f.txtName.value == '')
	{
		msg += '\r\n- Your name';
	}
	
	if(f.txtEmail.value == '')
	{
		msg += '\r\n- Your email';
	}
	else if(!isEmail(f.txtEmail.value))
	{
		msg += '\r\n- A valid email address';
	}
	
	if(f.captchatext && f.captchatext.value == '')
	{
		msg += '\r\n- The text shown in the image at the bottom of the form';
	}
	
	if(msg == '')
	{
		f.submit();
	}
	else
	{
		alert('Please complete the following:' + msg);
	}
}

function registerPropertyAlerts()
{
	var f = document.getElementById('frmEnquiry');
	var msg = '';
	
	if(f.txtName.value == '')
	{
		msg += '\r\n- Your name';
	}
	
	if(f.txtEmail.value == '')
	{
		msg += '\r\n- Your email';
	}
	else if(!isEmail(f.txtEmail.value))
	{
		msg += '\r\n- A valid email address';
	}
	
	if(f.captchatext && f.captchatext.value == '')
	{
		msg += '\r\n- The text shown in the image at the bottom of the form';
	}
	
	if(msg == '')
	{
		f.submit();
	}
	else
	{
		alert('Please complete the following:' + msg);
	}
}

function submitQuickEnquiry(frmName, fieldID)
{
	var f = document.getElementById(frmName);
	var msg = '';
	
	if(document.getElementById('txtQuickName' + fieldID).value == '')
	{
		msg += '\r\n- Your name';
	}
	
	if(document.getElementById('txtQuickEmail' + fieldID).value == '')
	{
		msg += '\r\n- Your email';
	}
	else if(!isEmail(document.getElementById('txtQuickEmail' + fieldID).value))
	{
		msg += '\r\n- A valid email address';
	}
	
	if(document.getElementById('txtQuickTel' + fieldID).value == '')
	{
		msg += '\r\n- Your telephone number';
	}
	
	if(document.getElementById('captchatext' + fieldID).value == '')
	{
		msg += '\r\n- The text shown in the image at the bottom of the form';
	}
	
	if(msg == '')
	{
		f.submit();
	}
	else
	{
		alert('Please complete the following:' + msg);
	}
}

function requestValuation()
{
	var f = document.getElementById('frmEnquiry');
	var msg = '';
	
	if(f.txtName.value == '')
	{
		msg += '\r\n- Your name';
	}
	
	if(f.txtEmail.value == '')
	{
		msg += '\r\n- Your email';
	}
	else if(!isEmail(f.txtEmail.value))
	{
		msg += '\r\n- A valid email address';
	}
	
	if(f.txtWorkTel.value == '' && f.txtHomeTel.value == '' && f.txtMobileTel.value == '')
	{
		msg += '\r\n- A telephone number';
	}
	
	if(f.txtYourProperty.value == '')
	{
		msg += '\r\n- Your property';
	}
	
	if(f.txtPostCode.value == '')
	{
		msg += '\r\n- Your postcode';
	}
	
	if(f.lstArea.selectedIndex == 0)
	{
		msg += '\r\n- Your area';
	}
	
	if(f.lstPropertyType.selectedIndex == 0)
	{
		msg += '\r\n- Your property type';
	}
	
	if(f.lstPrice.selectedIndex == 0)
	{
		msg += '\r\n- Your property value';
	}
	
	if(f.lstUrgency.selectedIndex == 0)
	{
		msg += '\r\n- Urgency';
	}
	
	/* if(getRadioButtonValue(f.rdoSource) == '')
	{
		msg += '\r\n- How did you find us?';
	} */
	
	/* if(f.captchatext && f.captchatext.value == '')
	{
		msg += '\r\n- The text shown in the image at the bottom of the form';
	} */
	
	
	if(msg == '')
	{
		f.submit();
	}
	else
	{
		alert('Please complete the following:' + msg);
	}
}

function submitPropertyEnquiry()
{
	var f = document.getElementById('frmEnquiry');
	var msg = '';
	
	if(f.txtName.value == '')
	{
		msg += '\r\n- Your name';
	}
	
	if(f.txtEmail.value == '')
	{
		msg += '\r\n- Your email';
	}
	else if(!isEmail(f.txtEmail.value))
	{
		msg += '\r\n- A valid email address';
	}
	
//	if(f.txtMessage.value == '' || f.txtMessage.value == 'Enter your enquiry here.')
//	{
//		msg += '\r\n- Your enquiry';
//	}
	
	if( f.txtMobileTel.value == '' )
	{
		msg += '\r\n- Telephone number';
	}

	if(f.captchatext && f.captchatext.value == '')
	{
		msg += '\r\n- The text shown in the image at the bottom of the form';
	}
	
	if(msg == '')
	{
		f.submit();
	}
	else
	{
		alert('Please complete the following:' + msg);
	}
}

function showHideViewingOptions()
{
	if(document.getElementById('chkViewing').checked)
	{
		document.getElementById('viewingOptions').style.visibility = 'visible';
		document.getElementById('viewingOptions').style.display = '';
	}
	else
	{
		document.getElementById('viewingOptions').style.visibility = 'hidden';
		document.getElementById('viewingOptions').style.display = 'none';
	}
}

function showHideCallOptions()
{
	if(document.getElementById('chkCall').checked)
	{
		document.getElementById('callOptions').style.visibility = 'visible';
		document.getElementById('callOptions').style.display = '';
	}
	else
	{
		document.getElementById('callOptions').style.visibility = 'hidden';
		document.getElementById('callOptions').style.display = 'none';
	}
}

function submitSendtoFriend()
{
	var f = document.getElementById('frmEnquiry');
	var msg = '';
	
	if(f.txtName.value == '')
	{
		msg += '\r\n- Your name';
	}
	
	if(f.txtEmail.value == '')
	{
		msg += '\r\n- Your email';
	}
	else if(!isEmail(f.txtEmail.value))
	{
		msg += '\r\n- A valid email address';
	}
	
	if(f.txtName.value == '')
	{
		msg += '\r\n- Your friend\'s name';
	}
	
	if(f.txtEmail.value == '')
	{
		msg += '\r\n- Your friend\'s email';
	}
	else if(!isEmail(f.txtEmail.value))
	{
		msg += '\r\n- A valid email address for your friend';
	}
	
	if(f.txtMessage.value == '' || f.txtMessage.value == 'Enter your enquiry here.')
	{
		msg += '\r\n- Your message';
	}
	
	if(f.captchatext && f.captchatext.value == '')
	{
		msg += '\r\n- The text shown in the image at the bottom of the form';
	}
	
	if(msg == '')
	{
		f.submit();
	}
	else
	{
		alert('Please complete the following:' + msg);
	}
}

function submitKeepMeInformed()
{
	var f = document.getElementById('frmEnquiry');
	var msg = '';
	
	if(f.txtName.value == '')
	{
		msg += '\r\n- Your name';
	}
	
	if(f.txtEmail.value == '')
	{
		msg += '\r\n- Your email';
	}
	else if(!isEmail(f.txtEmail.value))
	{
		msg += '\r\n- A valid email address';
	}
	
	if(f.captchatext && f.captchatext.value == '')
	{
		msg += '\r\n- The text shown in the image at the bottom of the form';
	}
	
	if(msg == '')
	{
		f.submit();
	}
	else
	{
		alert('Please complete the following:' + msg);
	}
}

function clearMessageField()
{
	if(document.getElementById('txtMessage').value == 'Enter your enquiry here.')
	{
		document.getElementById('txtMessage').value = '';
	}
}

function submitPropertyViewing()
{
	var f = document.getElementById('frmEnquiry');
	var msg = '';
	
	if(f.txtName.value == '')
	{
		msg += '\r\n- Your name';
	}
	
	if(f.txtEmail.value == '')
	{
		msg += '\r\n- Your email';
	}
	else if(!isEmail(f.txtEmail.value))
	{
		msg += '\r\n- A valid email address';
	}
	
	if(f.lstViewingDay.selectedIndex == 0)
	{
		msg += '\r\n- Viewing day';
	}
	if(f.lstViewingDate.selectedIndex == 0)
	{
		msg += '\r\n- Viewing date';
	}
	if(f.lstViewingTime.selectedIndex == 0)
	{
		msg += '\r\n- Viewing time';
	}
	
	if(getRadioButtonValue(f.rdoContactMethod) == '')
	{
		msg += '\r\n- Contact method';
	}
	else if(getRadioButtonValue(f.rdoContactMethod) == 'Home Tel' && f.txtHomeTel.value == '')
	{
		msg += '\r\n- Home Telephone'
	}
	else if(getRadioButtonValue(f.rdoContactMethod) == 'Work Tel' && f.txtWorkTel.value == '')
	{
		msg += '\r\n- Work Telephone'
	}
	else if(getRadioButtonValue(f.rdoContactMethod) == 'Mobile Tel' && f.txtMobileTel.value == '')
	{
		msg += '\r\n- Mobile Telephone'
	}
	
	if(f.captchatext && f.captchatext.value == '')
	{
		msg += '\r\n- The text shown in the image at the bottom of the form';
	}
	
	if(msg == '')
	{
		f.submit();
	}
	else
	{
		alert('Please complete the following:' + msg);
	}
}

function submitDetailedSearch()
{
	var msg = '';
	var f = document.getElementById('frmSearch');
	
	if(msg == '')
	{
		f.submit();
	}
	else
	{
		alert('Please complete the following:' + msg);
	}
}

function submitArchiveDetailedSearch()
{
	var msg = '';
	var f = document.getElementById('frmSearch');
	
	if(msg == '')
	{
		f.action = 'default.cfm/searchtype.archive';
		f.submit();
	}
	else
	{
		alert('Please complete the following:' + msg);
	}
}

function togglePropertyType()
{
	if(document.getElementById('optPropertyTypeSELECT').checked)
	{
		document.getElementById('formAreaPropertyType').style.visibility = 'visible';
		document.getElementById('formAreaPropertyType').style.display = '';
	}
	else
	{
		document.getElementById('formAreaPropertyType').style.visibility = 'hidden';
		document.getElementById('formAreaPropertyType').style.display = 'none';
	}
}

function toggleYear()
{
	if(document.getElementById('optYearSELECT').checked)
	{
		document.getElementById('formAreaYear').style.visibility = 'visible';
		document.getElementById('formAreaYear').style.display = '';
	}
	else
	{
		document.getElementById('formAreaYear').style.visibility = 'hidden';
		document.getElementById('formAreaYear').style.display = 'none';
	}
}

function togglePrice()
{
	if(document.getElementById('optPriceSELECT').checked)
	{
		document.getElementById('formAreaPrice').style.visibility = 'visible';
		document.getElementById('formAreaPrice').style.display = '';
	}
	else
	{
		document.getElementById('formAreaPrice').style.visibility = 'hidden';
		document.getElementById('formAreaPrice').style.display = 'none';
	}
}

function swapImage(image, caption)
{
	var ext = '';
	ext = image.substring(image.length-3);
	
	if(ext == 'peg' || ext == 'jpg')
	{
		document.getElementById('mainPropImage').src = 'images/property/main/' + image;		
	}
	else
	{
		document.getElementById('mainPropImage').src = 'images/property/' + image;
	}
	
	document.getElementById('mainPropImage').alt = caption;
}

function addToFavourites()
{
	window.external.AddFavorite(self.location.href, window.title); 
}

function ContactRD()
{
	var f = document.getElementById('frmContact');
	var msg = "";
	
	if(f.txtName.value == "")
	{
		msg += "\r\n- Your name";
	}
	if(!isEmail(f.txtEmail.value))
	{
		msg += "\r\n- A valid email address";
	}
	if(f.lstSubject.selectedIndex < 1)
	{
		msg += "\r\n- Subject";
	}
	
	if(msg == "")
	{
		f.submit();
	}
	else
	{
		alert('Please complete the following:'+msg);
	}
}

function ShowTerms()
{
	ShowPopUpWindow('terms','showterms.cfm',500,500,'no', 'yes', 'yes');
}

function ShowPopUp(url, w, h)
{
	var t=0, l = 0, winstring = "";

	if(infowindow){
		if(!infowindow.closed) infowindow.close()
	}

	l = ((screen.width / 2) - (w / 2))
	t = ((screen.height / 2) - (h / 2))

	winstring = "width=" + w + ", height=" + h + ",left=" + l + ",top=" + t +  ",status=" + 'no' + ",resizable=" + 'yes' + ",scrollbars=" + 'yes';

	infowindow = window.open(url,'extnew' ,winstring);
}

function BigPicLink(picID, w, h, newWin){
	if( newWin )
		ShowPopUpWindow("BigPic","bigpic.cfm?pic_id="+picID,w,h,"no","no","yes");
	else
		document.location.href = 'popup_pic.cfm?pic_id=' + picID;
}

function quickSearch()
{
	if(document.getElementById('lstSection').value != '')
	{
		document.location.href = 'default.cfm/' + document.getElementById('lstSection').value;
	}
}

function showContactDetails(divID)
{
	document.getElementById(divID).style.visibility = 'visible';
	document.getElementById(divID).style.display = '';
	
	document.getElementById(divID + 'link').style.visibility = 'hidden';
	document.getElementById(divID + 'link').style.display = 'none';
}

function showLayer(layerID){
	if( objVisibleLayer ){
		if( objVisibleLayer.id == layerID ) return 0;
	}

	objVisibleLayer = document.getElementById(layerID);

	if( objVisibleLayer )
		objVisibleLayer.style.display = '';

}

function hideLayer(){

	if( objVisibleLayer ){
		objVisibleLayer.style.display = 'none';
		objVisibleLayer = null;
	}

}

function swapSideImage(imgName, imgPath){
	var imgRef = document.getElementById(imgName);

	if( imgRef ){

		imgRef.src = imgPath;

	}

}

function ShowPopUpWindow(Name, File, w, h, Status, Resize, Scroll){
	var t=0, l = 0, winstring = "";

	if(infowindow){
		if(!infowindow.closed) infowindow.close()
	}

	l = ((screen.width / 2) - (w / 2))
	t = ((screen.height / 2) - (h / 2))

	winstring = "width=" + w + ", height=" + h + ",left=" + l + ",top=" + t +  ",status=" + Status + ",resizable=" + Resize + ",scrollbars=" + Scroll;

	infowindow = window.open(basehref + File,Name,winstring);
}

function showElement(eName)
{
	var e = document.getElementById(eName);
	e.style.visibility = 'visible';
	e.style.display = '';
}

function hideElement(eName)
{
	var e = document.getElementById(eName);
	e.style.visibility = 'hidden';
	e.style.display = 'none';
}

function getRadioButtonValue(radioButtonArray) {
	var value = '';
	
	if (!radioButtonArray.length) {
		// Only one radio button, so form.radiobuttonname returns a radiobutton element, not an array
		if (radioButtonArray.checked) {
			value = radioButtonArray.value;
		}
	}
	else {
		for (var i=0; i<radioButtonArray.length; i++) {
			if (radioButtonArray[i].checked) {
				value = radioButtonArray[i].value;
				break;
			}
		}
	}
	
	return value;
}

function GetElementPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function SetValue(id, newValue) {
	identity=document.getElementById(id);
	identity.value=newValue;
}

function SetInnerHtml(id, newValue) {
	identity=document.getElementById(id);
	identity.innerHTML=newValue;
}

function SetStyle(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}

function isEmail(email) {
	var invalidCharString = " ,<>!\"?%^&*()+=*/\\\';:#~[]{}";
	var i = 0;
	
	for (i = 0; i < invalidCharString.length; i++) {
		if (-1 < email.indexOf(invalidCharString.charAt(i))) {
			return false;
		}
	}
	
	var firstAt = email.indexOf('@');
	var lastAt = email.lastIndexOf('@');
	var lastDot = email.lastIndexOf('.');
	if (!((0 < firstAt) && (1 < lastDot) && (firstAt == lastAt) && ((firstAt + 1) < lastDot) && (lastDot < (email.length - 2)))) 
	{
		return false;
	}
	else {
		return true;
	}
}

function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strDay=dtStr.substring(0,pos1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		
		return false;
	}
return true;
}
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.-";
	var IsNumber=true;
	var Char;


	for (i = 0; i < sText.length && IsNumber == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsNumber = false;
		}
	}
	return IsNumber;
   
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function SetVisibility(id, visible) {
	var identity=document.getElementById(id);
	if (visible) {
		identity.className = "visibleElement";
	}
	else {
		identity.className = "hiddenElement";
	}
}

function getInputArrayValue(inputArray) {
	var value = '';
	
	if (!inputArray.length) {
		// Only one radio button, so form.radiobuttonname returns a radiobutton element, not an array
		if (inputArray.checked) {
			value = inputArray.value;
		}
	}
	else {
		for (var i=0; i<inputArray.length; i++) {
			if (inputArray[i].checked) {
				value = inputArray[i].value;
				break;
			}
		}
	}
	
	return value;
}

function InsertTextAtCursor(inputElement,textToInsert) {
	inputElement.focus();
	
	if (inputElement.selectionStart) {
		var curPos = inputElement.selectionStart;
		inputElement.value = inputElement.value.substr(0,inputElement.selectionStart) + textToInsert + inputElement.value.substr(inputElement.selectionEnd,inputElement.value.length);
		inputElement.selectionStart = curPos + textToInsert.length;
		inputElement.selectionEnd = inputElement.selectionStart;
	}
	else if (document.selection) {
		var sel = document.selection.createRange();
		sel.text = textToInsert;
	}
	else {
		inputElement.value += textToInsert;
	}
}

function NoneLink() {}

function ReturnKeyCheck(source, e) {
	var characterCode; // literal character code will be stored in this variable
	
	if (e && e.which){ //if which property of event object is supported (NN4)
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	return (characterCode == 13);
}

function NewWindowLink(a) {
	if (!window.focus) 
	{
		return true;
	}
	window.open(a.href,"_blank");
	return false;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function showTab(t)
{
	if(t == 'details')
	{
		document.getElementById('propdetails').style.visibility = 'visible';
		document.getElementById('propdetails').style.display = '';
		document.getElementById('propgallery').style.visibility = 'hidden';
		document.getElementById('propgallery').style.display = 'none';
		document.getElementById('propfloorplans').style.visibility = 'hidden';
		document.getElementById('propfloorplans').style.display = 'none';
		document.getElementById('propmaps').style.visibility = 'hidden';
		document.getElementById('propmaps').style.display = 'none';
		
		document.getElementById('tabLinkdetails').className = 'tabOn';
		if(document.getElementById('tabLinkgallery'))
		{
			document.getElementById('tabLinkgallery').className = 'tabOff';
		}
		if(document.getElementById('tabLinkfloorplans'))
		{
			document.getElementById('tabLinkfloorplans').className = 'tabOff';
		}
		document.getElementById('tabLinkmaps').className = 'tabOff';
	}
	else if(t == 'gallery')
	{
		document.getElementById('propdetails').style.visibility = 'hidden';
		document.getElementById('propdetails').style.display = 'none';
		document.getElementById('propgallery').style.visibility = 'visible';
		document.getElementById('propgallery').style.display = '';
		document.getElementById('propfloorplans').style.visibility = 'hidden';
		document.getElementById('propfloorplans').style.display = 'none';
		document.getElementById('propmaps').style.visibility = 'hidden';
		document.getElementById('propmaps').style.display = 'none';
		
		document.getElementById('tabLinkdetails').className = 'tabOff';
		if(document.getElementById('tabLinkgallery'))
		{
			document.getElementById('tabLinkgallery').className = 'tabOn';
		}
		if(document.getElementById('tabLinkfloorplans'))
		{
			document.getElementById('tabLinkfloorplans').className = 'tabOff';
		}
		document.getElementById('tabLinkmaps').className = 'tabOff';
	}
	else if(t == 'floorplans')
	{
		document.getElementById('propdetails').style.visibility = 'hidden';
		document.getElementById('propdetails').style.display = 'none';
		document.getElementById('propgallery').style.visibility = 'hidden';
		document.getElementById('propgallery').style.display = 'none';
		document.getElementById('propfloorplans').style.visibility = 'visible';
		document.getElementById('propfloorplans').style.display = '';
		document.getElementById('propmaps').style.visibility = 'hidden';
		document.getElementById('propmaps').style.display = 'none';	

		document.getElementById('tabLinkdetails').className = 'tabOff';
		if(document.getElementById('tabLinkgallery'))
		{
			document.getElementById('tabLinkgallery').className = 'tabOff';
		}
		if(document.getElementById('tabLinkfloorplans'))
		{
			document.getElementById('tabLinkfloorplans').className = 'tabOn';
		}
		document.getElementById('tabLinkmaps').className = 'tabOff';
	}
	else if(t == 'maps')
	{
		document.getElementById('propdetails').style.visibility = 'hidden';
		document.getElementById('propdetails').style.display = 'none';
		document.getElementById('propgallery').style.visibility = 'hidden';
		document.getElementById('propgallery').style.display = 'none';
		document.getElementById('propfloorplans').style.visibility = 'hidden';
		document.getElementById('propfloorplans').style.display = 'none';
		document.getElementById('propmaps').style.visibility = 'visible';
		document.getElementById('propmaps').style.display = '';	

		document.getElementById('tabLinkdetails').className = 'tabOff';
		if(document.getElementById('tabLinkgallery'))
		{
			document.getElementById('tabLinkgallery').className = 'tabOff';
		}
		if(document.getElementById('tabLinkfloorplans'))
		{
			document.getElementById('tabLinkfloorplans').className = 'tabOff';
		}
		document.getElementById('tabLinkmaps').className = 'tabOn';
	}
}

function ValidateEnquiry()
{
	var msg="";
	var f = document.getElementById('frmEnquiry');	
	
	if(f.txtName.value == "")
	{
		msg += "\r\n- Name";
	}
	
	if(f.txtEmail.value == "")
	{
		msg += "\r\n- Email";
	}
	else if(!isEmail(f.txtEmail.value))
	{
		msg += "\r\n- Valid email";
	}
	
	if(msg == "")
	{
		document.frmEnquiry.submit();
	}
	else
	{
		alert("Please complete the following:" + msg);
	}
}

function showMap()
{
	document.getElementById('mapSearch').style.visibility = 'visible';
	document.getElementById('mapSearch').style.display = '';
}

function hideMap()
{
	document.getElementById('mapSearch').style.visibility = 'hidden';
	document.getElementById('mapSearch').style.display = 'none';
}

function CountWords (this_field) 
{
	var char_count = this_field.value.length;
	var fullStr = this_field.value + " ";
	var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
	var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
	var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
	var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
	var splitString = cleanedStr.split(" ");
	var word_count = splitString.length -1;
	
	if (fullStr.length <2) {
		word_count = 0;
	}
	
	return word_count;
}

var slider;
var slider2;
var container;
var topPos;
var timerId;
var timeOut;
var maxHeight;
var moveCounter = 0;

function startScrollNews(tOut, mHeight)
{	
	slider = document.getElementById("sliderNews");	
	slider2 = document.getElementById("sliderNews2");	
	
	container = document.getElementById("newsScroller");
	topPos = 0;
	moveCounter = 0;
	timeOut = tOut * 1000;
	maxHeight = mHeight;
	
	window.setTimeout(startNews, timeOut);
}

function startNews()
{
	timerId = window.setInterval(scrollNews, 15);
}

function scrollNews()
{
	topPos -= 1;
	moveCounter++;
	
	slider.style.top = topPos + 'px';
	slider2.style.top = topPos + maxHeight + 'px';
	
	if(moveCounter == 100)
	{
		if(topPos <= (-1 * maxHeight))
		{
			topPos = 0;
			
			var tS = slider;
			var tS2 = slider2;
			
			slider = tS2;
			slider2 = tS;
		}
		
		moveCounter = 0;
		window.clearInterval(timerId);
		window.setTimeout(startNews, timeOut);			
	}
}

function addPageToFavourites()
{
	if (navigator.appName == "Microsoft Internet Explorer") // IE 
	{
		if((parseInt(navigator.appVersion) >= 4))
		{
			if(navigator.userAgent.indexOf("MSIE 7") > 0)
			{
				alert("To add this page to your favourites please either press Ctrl+D on your keyboard or click the 'Add to Favorites' button in the Internet Explorer toolbar.");
			}
			else
			{
				window.external.AddFavorite (location.href, document.title); 
			}
		}
	} 
	else 
	{
		if( window.sidebar ){
			window.sidebar.addPanel ( document.title, location.href,""); 
		}
		else{
				alert("To add this page to your favourites please press Ctrl+D on your keyboard.");
		}
	}
}

function loadRssNews() {
/*
	var rssUrl = rssNewsUrl + '?format=json';

    $.getJSON(rssUrl, function(data) {
        var $rssList = $('#rssList');

        $(data).each(function() {
            var $li = $('<li></li>');
            var $div = $('<div></div>');
            $div.addClass('rss-news');
            $li.append($div);

            $div.append($('<div/>').addClass('rss-news-title').html(this.Title));
            $div.append($('<div/>').addClass('rss-news-description').html(this.Description));
            $div.append($('<div/>').addClass('rss-news-dateAdded').html(this.DateAdded));
            $div.append($('<a/>').attr('href', this.Link).addClass('rss-news-link').html(this.Link));

            $rssList.append($li);
        });

        $('div#loadingRss').hide();
        
    });
    */
}

function forEach(list, callBack){
	for( var i = 0; i < list.length; i++ )
		callBack(list[i]);
}

function appendChild(parent, elementType){
	var newElement = document.createElement(elementType);
	parent.appendChild(newElement);
	return newElement;
}

function addClass(parent, className){
	if( parent.className == '' )
		parent.className = className;
	else
		parent.className += className;
		
	return parent;
}

function replaceClass(parent, className){
	parent.className = className;
	
	return parent;
}

function appendText(parent, text){
	var newElement = document.createTextNode(text);
	parent.appendChild(newElement);
	return parent;
}

function attr(parent, attrName, attrVal){
	parent.setAttribute(attrName, attrVal);
	return parent;
}

function rssNews_Complete(data){
//	alert('callback fn');
	
	var $rssList = $('#rssList');
	fade('rssList');
	
	rssItemCount = 0;
	rssItemCounter = 0;
	rssItems = new Array();
	
	forEach(data, function(thisObj){
		// var li = document.createElement('li');
		var div = document.createElement('div');
		addClass(div, 'rss-news');
		
		appendText(addClass(appendChild(div, 'div'), 'rss-news-title'), thisObj.Title);
		appendText(addClass(appendChild(div, 'div'), 'rss-news-description'), thisObj.Description);
		// appendText(addClass(appendChild(div, 'div'), 'rss-news-dateAdded'), thisObj.DateAdded);
		appendText(addClass(attr(appendChild(div, 'a'), 'href', thisObj.Link), 'rss-news-link'), thisObj.Link);
		
		// li.appendChild(div);
		
		// $rssList.appendChild(div);

		rssItems[rssItemCount] = div;
		rssItemCount++;
	});
	
	$('#loadingRss').style.display = 'none';
	
	populateRssPanel(1);
}

function populateRssPanel(pState)
{
	var $rssList = $('#rssList');
	
	if(pState == 0)	
	{
		fade('rssList');
		setTimeout("populateRssPanel(1)", TimeToFade);
	}
	else
	{
		if ( $rssList.hasChildNodes() )
		{
		    while ( $rssList.childNodes.length >= 1 )
		    {
			$rssList.removeChild( $rssList.firstChild );       
		    } 
		}
	
		addRssItemToPanel(1);
		addRssItemToPanel(2);
		addRssItemToPanel(3);
			
		fade('rssList');
		
		if(rssItemCount > 3)
		{
			setTimeout("populateRssPanel(0)", 30000);
		}
	}
}

function addRssItemToPanel(pos)
{
	if(pos <= rssItemCount)
	{
		var $rssList = $('#rssList');
		
		if(rssItemCounter >= rssItemCount)
		{
			rssItemCounter = 0;
		}
		
		$rssList.appendChild(rssItems[rssItemCounter]);
		replaceClass(rssItems[rssItemCounter], 'rss-news' + pos);
		rssItemCounter++
	}
}

var TimeToFade = 500.0;

function fade(eid)
{
	var element = document.getElementById(eid);
	if(element == null)
		return;

	if(element.FadeState == null)
	{
		if(element.style.opacity == null || element.style.opacity == '' || element.style.opacity == '1')
		{
			element.FadeState = 2;
		}
		else
		{
			element.FadeState = -2;
		}
	}

	if(element.FadeState == 1 || element.FadeState == -1)
	{
		element.FadeState = element.FadeState == 1 ? -1 : 1;
		element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
	}
	else
	{
		element.FadeState = element.FadeState == 2 ? -1 : 1;
		element.FadeTimeLeft = TimeToFade;
		setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "')", 33);
	}  
}

function animateFade(lastTick, eid)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
    element.style.opacity = element.FadeState == 1 ? '1' : '0';
    element.style.filter = 'alpha(opacity = '
        + (element.FadeState == 1 ? '100' : '0') + ')';
    element.FadeState = element.FadeState == 1 ? 2 : -2;
    return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
    newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
 
  setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}

function _callbackMethod(){
	if( jsonAjax.request.readyState == 4 && jsonAjax.request.status == 200 )
	{
		jsonAjax._callBackFn(eval(jsonAjax.request.responseText));
	}
}

function JsonAjaxObject(){
	this._callBackFn = null;
	this.toString = function() {return "Ajax";}
	this.makeRequest = function(_method, _url, callbackFn)
	{
		this._callBackFn = callbackFn;
		this.request = (window.XMLHttpRequest)? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");
		this.request.onreadystatechange = _callbackMethod;
		this.request.open(_method, _url, true);
		this.request.send(_url);
		this.request.contenttype = "text/html"
		this.request.charset = "ISO-8859-1"
	}

}

var jsonAjax;

function getJSON(url, callBackFn){
	var data = '';
	
	jsonAjax = new JsonAjaxObject();
	jsonAjax.makeRequest('get', url, callBackFn);
}

function loadRssNews2(){
	var rssUrl = rssNewsUrl + '?format=json';

	getJSON(rssUrl, rssNews_Complete);
}

function Ajax()
{
	this.toString = function() {return "Ajax";}
	this.makeRequest = function(_method, _url, _callbackMethod)
	{
		this.request = (window.XMLHttpRequest)? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP");
		this.request.onreadystatechange = _callbackMethod;
		this.request.open(_method, _url, true);
		this.request.send(_url);
		this.request.contenttype = "text/html"
		this.request.charset = "ISO-8859-1"

	}
	this.checkReadyState = function(_id, waitContent)
	{
		if (!waitContent) {var waitContent = "Loading...";}
		switch(this.request.readyState)
		{
			case 1: document.getElementById(_id).innerHTML = waitContent;break;
			case 2: document.getElementById(_id).innerHTML = waitContent;break;
			case 3: document.getElementById(_id).innerHTML = waitContent;break;
			case 4: return this.request.status;
		}
	}
}

function $(selector){
	var thisObj = document.getElementById(selector.replace('#', ''));

	return thisObj;
}

window.onload = function(){
	var $rssList = $('#rssList');
	
	if( $rssList )
	{
		loadRssNews2();
	}
	
	if( $('#navBar') ){
		var rightBarHeight = $('#navBar').offsetHeight
	
		if( $('#ilDiv') ){ // form
			if( $('#ilDiv').offsetHeight < rightBarHeight )
			{
				$('#ilDiv').style.height = rightBarHeight + 'px';	
			}
		}

		if( $('#divPinkBg') ){ // form result
			if( $('#divPinkBg').offsetHeight < rightBarHeight )
			{
				$('#divPinkBg').style.height = rightBarHeight + 'px';	
			}
		}
	}
}

var currentTbPage = 0;

function swapImage2(imageIndex)
{
	var image = propImages[imageIndex].Filename;
	var ext = '';

	ext = image.substring(image.length-3);

	if(ext == 'peg' || ext == 'jpg')
	{
		document.getElementById('mainPropImage').src = 'images/property/main/' + image;
	}
	else
	{
		document.getElementById('mainPropImage').src = 'images/property/' + image;
	}

	document.getElementById('mainPropImage').alt = propImages[imageIndex].AltText;
}

function noLink(){
}

function loadTbImages()
{
	var currentImage = currentTbPage * 6;

//	console.log('currentImage = ' + currentImage);
//	console.log('propImages.length = ' + propImages.length);
	
	for( var i = 0; i < 6; i++ ){
		if( currentImage < propImages.length && propImages[currentImage] != null){
			$('#propThumbnail_' + i).src = 'images/property/thumb/' + propImages[currentImage].Filename;
			$('#propThumbnail_' + i).alt = propImages[currentImage].AltText;
			attr($('#propTbLink_' + i), 'href', 'javascript:swapImage2(' + currentImage + ')');
			$('#propThumbnail_' + i).style.cursor = 'pointer';
		}
		else{
			$('#propThumbnail_' + i).src = 'images/thumb-foxgrant.gif';
			$('#propThumbnail_' + i).alt = '';

			attr($('#propTbLink_' + i), 'href', 'javascript:noLink()');
			$('#propThumbnail_' + i).style.cursor = 'default';
		}

		currentImage++;
	}
}

function nextTbPage()
{
	var maxTbPages = Math.ceil(propImages.length / 6);

	if( currentTbPage >= maxTbPages - 1 ){
		currentTbPage = 0;
	}
	else{
		currentTbPage++;
	}

	loadTbImages();
}

function prevTbPage()
{
	var maxTbPages = Math.ceil(propImages.length / 6);
	
	if( currentTbPage <= 0 ){
		currentTbPage = maxTbPages - 1;
	}
	else{
		currentTbPage--;
	}

	loadTbImages();
}


/* Video Report Dialog */
var dialogOptions = { width: 520, height: 525 }
var ajax = null;

function $(selector){
	if( selector.substring(0, 1) == '#' ){
		return document.getElementById(selector.substring(1));
	}
	else{
		return document.getElementsByTagName(selector);
	}
}

function ShowGoogleLocation(videoId)
{
	var dlg = $('#GoogleMapDialog');
	var dialogShield = $('#dialogShield');
	var closeButton = $('#CloseButton');
	
	var btns = $('#GoogleMapDialogButtons');
	var title = $('#GoogleMapDialogTitle');
	
	var videoReport = $('#GoogleMap');
	var waitMessage = $('#GoogleMapLoading');
	
	
	dlg.style.width = dialogOptions.width;
	if( document.all ){ // deal with bad web browsers
		dlg.style.height = dialogOptions.height + 50;
		$('#GoogleMapMargin').style.height = 475;
	}
	else{
		dlg.style.height = dialogOptions.height;
	}
	
	dlg.style.display = 'block';
	waitMessage.style.display = 'none';

	closeButton.onclick = function(){
		dialogShield.style.display = 'none';
		dlg.style.display = 'none';
		
		return false;
	}
	
	var calcTop = ((getPageHeight() / 2) - (dialogOptions.height / 2)) + getScrollTop();
	var calcLeft = (getPageWidth() / 2) - (dialogOptions.width / 2);

	/*
	console.log('pageHeight: ' + 	getPageHeight());
	console.log('pageWidth: ' + 	getPageWidth());
	console.log('dialogHeight: ' + 	dialogOptions.height);
	console.log('dialogWidth: ' + 	dialogOptions.width);
	console.log('scrollTop: ' + 	getScrollTop());
	console.log('dialogLeft: ' + dlg.style.left);
	console.log('dialogTop: ' + dlg.style.top);
	console.log('calc top: ' + calcTop);
	console.log('calc.left: ' + calcLeft);
	*/
	
	dlg.style.top = calcTop + 'px';
	dlg.style.left = calcLeft + 'px';
	
	/*
	console.log('dialogLeft: ' + dlg.style.left);
	console.log('dialogTop: ' + dlg.style.top);
	*/
	
	var videoHeight = dialogOptions.height - (btns.offsetHeight + title.offsetHeight);
	
	videoReport.style.height = videoHeight;
	videoReport.style.minHeight = videoHeight;
	
	dialogShield.style.height = getDocHeight() + 'px';
	dialogShield.style.width = getDocWidth() + 'px';
	dialogShield.style.display = 'block';

	// console.log('showing shield, width: ' + getDocWidth() + ', height: ' + getDocHeight());
	
	btns.style.width = dialogOptions.width + 'px';
	
	if( propLocation ){
		gMapLoadPropertyMap(propLocation.lat, propLocation.lng, 17, ''); //(lat, lng, zoom, propertyCode)
	}
}

function getScrollTop()
{
	var ScrollTop = document.body.scrollTop;
	 
	if (ScrollTop == 0)
	{
		if (window.pageYOffset)
			ScrollTop = window.pageYOffset;
		else
			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	
	return ScrollTop;
}

function getScrollLeft()
{
	var scrollLeft = document.body.scrollLeft;
	 
	if (scrollLeft == 0)
	{
		if (window.pageXOffset)
			scrollLeft = window.pageXOffset;
		else
			scrollLeft = (document.body.parentElement) ? document.body.parentElement.scrollLeft : 0;
	}
	
	return scrollLeft;
}


function getDocHeight(){ 
	if( document.height != undefined ) // good browsers
	{	
		return document.height;
	}
	else{
		var scrollHeight = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight);
		var offsetHeight = Math.max(document.documentElement.offsetHeight, document.body.offsetHeight);

		return scrollHeight < offsetHeight ? offsetHeight :  scrollHeight;
	}
}

function getDocWidth(){ 

	if (document.width != undefined) // good browsers
	{
		return document.width;
	}
	else{
		var scrollWidth = Math.max(document.documentElement.scrollWidth, document.body.scrollWidth);
		var offsetWidth = Math.max(document.documentElement.offsetWidth, document.body.offsetWidth);

		return scrollWidth < offsetWidth ? offsetWidth : scrollWidth;
	}
}

function getPageWidth()
{
	if( document.all ){ 
		var clientWidth = document.documentElement.clientWidth;
		
		if( clientWidth <= 0 ) clientWidth = document.body.clientWidth;
	
		return clientWidth; 
	} 
	else { 
		return window.innerWidth; 
	}
}

function getPageHeight()
{
	if( document.all ){ 
		var clientHeight = document.documentElement.clientHeight;
		
		if( clientHeight <= 0 ) clientHeight = document.body.clientHeight;
		
		return clientHeight; 
	} 
	else { 
		return window.innerHeight; 
	} 
}

window.onresize = function()
{
	var dialogShield = document.getElementById('dialogShield');
	
	if( dialogShield )
	{
		dialogShield.style.height = getDocHeight();
		dialogShield.style.width = getDocWidth();
	}
}

// End of Video Report Dialog


function SubmitLinkToUsProp(){
	var msg = '', f = document.frmLinkToUsProp;
	
	if( f.Name.value == '' ) msg += '\n* Name';
	
	if( f.Email.value == '' ) msg += '\n* Email address';
	
	if( f.WebsiteAddress.value == '' ) msg += '\n* Website address';
	
	if(!f.AllProperties[0].checked && !f.AllProperties[1].checked){
		msg += '\n* Property type or all properties selection';
	}
	else if( f.AllProperties[1].checked ){
		var selectedVal = f.PropertyType.options[f.PropertyType.selectedIndex].value;
		
		if( selectedVal == -1 ){
			msg += '\n* Select a property type';
		}
	}
	
	if( msg != '' ){
		alert('Please enter the following: ' + msg);
		return;
	}

	document.frmLinkToUsProp.submit();
}

