var sfsIndex       = new Object;
sfsIndex.populated = false;
 /*
 Typing a name into the suburb entry field will scroll the suburb select
 field to a matching suburb name (if any).
 */

 function sfsComplete (sList, sText) {
	 if (!document.getElementById) return;

	 var text   = document.getElementById(sText);
	 var select = document.getElementById(sList);

	 if (!sfsIndex.populated) sfsBuildIndex(sList);

	 var suburb = text.value.match(/,*([^,]+)$/);

	 if (suburb) {
	 	//trim
		 var name = suburb[1].toUpperCase().replace(/^\s*/, '').replace(/\s*$/, '');

		 for (var i = sfsIndex[name.charAt(0)]; i < select.options.length; i++) {
			 if (select.options[i].text.toUpperCase().indexOf(name) == 0) {
				 select.selectedIndex = i;
				 break;
			 }
			 else {
			 select.selectedIndex = -1;
			 }
		 }
	 }
}
/*
On click event for the suburb select box. When clicked it populates
the suburb entry field then deselects the clicked suburb. Focus is
returned to the suburb entry field.
*/
function sfsBuildIndex (sList) {
	if (!document.getElementById) return;
	var select = document.getElementById(sList);
	for (var i = select.options.length; i--;) {
		sfsIndex[select.options[i].text.toUpperCase().charAt(0)] = i;
	}
	sfsIndex.populated = true;
}

function hideElement(oE){
	if(findObj(oE)!=null)
		findObj(oE).style.display = "none";
}

function showElement(oE){
	if(findObj(oE)!=null)
		findObj(oE).style.display = "";

}

function reverseContentDisplay(d) {

	if(findObj(d).style.display == "none") { findObj(d).style.display = ""; }
	else {findObj(d).style.display = "none"; }
}

function toggle(input)
{
	if(input.checked) input.parentNode.className = 'Selected';
	else input.parentNode.className = 'UnSelected';
}

function setRadio()
{
	iNumForm = document.forms.length;
	for(i = 0; i < iNumForm; i++)
	{
		iNumElement = document.forms[i].elements.length;

		for (j = 0; j < iNumElement; j++)
			if ('radio' == document.forms[i].elements[j].type)
				toggle(document.forms[i].elements[j]);
	}
}

function quickSearch(){
	findObj('fQuickSearch').value = 1;
	return false;
}

function preloadImg() { //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=preloadImg.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 restoreImg() { //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 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=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImg() { //v3.0
  var i,j=0,x,a=swapImg.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function showHideAgent(theID,imgID) {
	var agentID = document.getElementById(theID);
	//var overImg = document.getElementById(imgID);
	if(agentID.style.display == "none") {
		agentID.style.display = "";
		// 070215 SIMPLY - Make button and text change color / selected state
		document.getElementById('bAgent').style.color='#FFCC33';
		document.getElementById('bAgent').style.backgroundColor='#4904C1';
		document.getElementById('bAgentImg').src='/images/FindAAgent02.gif';
	} else {
		agentID.style.display = "none";
		// 070215 SIMPLY - Make button and text change color / unselected state
		document.getElementById('bAgent').style.color='#BBA5E3';
		document.getElementById('bAgent').style.backgroundColor='#2F0B6F';
		document.getElementById('bAgentImg').src='/images/FindAAgent.gif';
	}

}
var tid="";
function showReq(theid){
	// FindAgent Visuals
	document.getElementById("findAgent").style.display = "none";
	document.getElementById("imgfindAgent").src="images/findAgent.gif";
	document.getElementById("bfindAgent").style.backgroundColor = "#2F0B6F";

	// Auctions Visuals
	document.getElementById("Auctions").style.display = "none";
	document.getElementById("imgAuctions").src="images/Auctions.gif";
	document.getElementById("bAuctions").style.backgroundColor = "#2F0B6F";

	// OpenHomes Visuals
	document.getElementById("OpenHomes").style.display = "none";
	document.getElementById("imgOpenHomes").src="images/OpenHomes.gif";
	document.getElementById("bOpenHomes").style.backgroundColor = "#2F0B6F";

	// ACTIVE ITEM Visuals
	document.getElementById(theid).style.display = "";
	document.getElementById("b"+theid).style.backgroundColor = "#4904C1";
	tid=theid;
	setTimeout("setImg()",100) //document.getElementById("img"+theid).src="images/"+theid+"02.gif";
}

function setImg()
{
	theid=tid;
	document.getElementById("img"+theid).src="images/"+theid+"02.gif";
}
function myResetForm(i){
	document.getElementById(i).reset();
}
function mySubmitForm(i){

		document.getElementById(i).submit();
}


function GetAgencyOffice(agency,changeElementId,className)
{
	//The Element ID whose content will be changed by the response text.
	changeId = changeElementId;
	fAgencyID = agency.options[agency.selectedIndex].value;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return '';
	}
	var url= '/homes/dropdown_agency_office.php?fAgencyID='+fAgencyID + '&fClassName=' + className;

	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetChainAgency(chain,changeElementId,className)
{
	//The Element ID whose content will be changed by the response text.
	changeId = changeElementId;
	fChainID = chain.options[chain.selectedIndex].value;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return '';
	}
	var url= '/homes/dropdown_agency_office.php?fChainIDForAgency='+fChainID + '&fClassName=' + className;

	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetChainOffice(chain,changeElementId)
{
	changeId = changeElementId;
	fChainID = chain.options[chain.selectedIndex].value;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return '';
	}
	var url= '/homes/dropdown_agency_office.php?fChainID='+fChainID;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetRegion(suburb,changeElementId)
{
	changeId = changeElementId;
	fSuburbID = suburb.options[suburb.selectedIndex].value;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return '';
	}
	var url= '/homes/dropdown_agency_office.php?fSuburbID='+fSuburbID;
	//alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetSuburb(postCode,changeElementId, className)
{
	changeId = changeElementId;
	fPostCode = postCode.value;
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return '';
	}
	//var url= 'property_add2_ajax.php?fOfficeID='+fOfficeID;
	var url= '/homes/dropdown_agency_office.php?fPostCode=' + fPostCode + '&fClassName=' + className;
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetSaleAgent(office,changeElementId)
{
	changeId = changeElementId;
	fOfficeID = office.options[office.selectedIndex].value;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return '';
	}
	//var url= 'property_add2_ajax.php?fOfficeID='+fOfficeID;
	var url= '/homes/dropdown_agency_office.php?fOfficeID='+fOfficeID;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetAgencyOffice_Reports (agency, changeElementId, dropDownName, onchange) {
	var url= '/homes/dropdown_agency_office.php?fAgencyIDForOffice=' + agency.options[agency.selectedIndex].value + '&fDropDown=' + dropDownName + '&onChangeText=' + onchange;
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return '';
	}

	xmlHttp.onreadystatechange = function() {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
										document.getElementById(changeElementId).innerHTML=xmlHttp.responseText;
									}
								 }
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetOfficeStaff (office, changeElementId, dropDownName) {
	var url= '/homes/dropdown_agency_office.php?fOfficeIDForStaff=' + office.options[office.selectedIndex].value + '&fDropDown=' + dropDownName;
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return '';
	}

	xmlHttp.onreadystatechange = function() {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
										document.getElementById(changeElementId).innerHTML=xmlHttp.responseText;
									}
								 }
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetAgencySuburb (agency, changeElementId, dropDownName) {
	var url= '/homes/dropdown_agency_office.php?fAgencyIDForSuburb=' + agency.options[agency.selectedIndex].value + '&fDropDown=' + dropDownName;
	var xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return '';
	}

	xmlHttp.onreadystatechange = function() {
									if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
										document.getElementById(changeElementId).innerHTML=xmlHttp.responseText;
									}
								 }
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function GetPropertyType(listingType, changeElementId, dropDownName) {
	var listType = listingType.options[listingType.selectedIndex].value;
	var url= '/homes/dropdown_agency_office.php?fListingType=' + listType + '&fDropDown=' + dropDownName;
	sendAjaxRequest(url, changeElementId);
}

function sendAjaxRequest(url, changeElementId) {
	changeId = changeElementId;
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request");
		return '';
	}

	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function GetXmlHttpObject(handler)
{
	var objXMLHttp=null;
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return objXMLHttp
}
function stateChanged()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById(changeId).innerHTML=xmlHttp.responseText;
		//alert(xmlHttp.responseText);
	}
}

function clearSearchField(tfObj, checkVal) {
	if (tfObj.value == checkVal) {
		tfObj.value = "";
	}
}
function validateDate(fld) {
    var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
    var errorMessage = 'Please enter valid date as month, day, and four digit year.\nYou may use a slash or hyphen to separate the values.\nFormay dd/mm/yyyy.';
    if (!(fld.value.match(RegExPattern)) && (fld.value!='')) {
        YAHOO.example.cal_simple.showCalendar(1)
        fld.focus();
    }
}

function showPopup(url, width1, height1) {
	winProperties = "width="+width1+",height="+height1+",toolbar=no,location=no,menubar=no,scrollbars=yes,resizable=no,status=no";
    newWindow = window.open(url,"Details",winProperties);
    newWindow.focus();
}