//function realtyPreload()
//{
	//MM_preloadImages('{$theme}/images/menu/community_on.gif','{$theme}/images/menu/listings_on.gif','{$theme}/images/menu/buying_on.gif','{$theme}/images/menu/selling_on.gif','{$theme}/images/menu/relocation_on.gif','{$theme}/images/menu/financial_on.gif')
//}

function popup(page,params,w,h) 
{
	var winl=(screen.width-w) / 2;
	var wint=(screen.height-h) / 2;
	win=window.open("/index.php?s=api&a=" + page + "&params=" + params,"popup","scrollbars=yes,status=no,location=no,toolbar=no,menubar=no,directories=no,resizable=no,width="+w+",height="+h+",top="+wint+",left="+winl+"");
	if (parseInt(navigator.appVersion) >=4) { win.window.focus(); }
}

if(ap_instances == undefined) {
	var ap_instances = new Array();
	var ap_clearID = setInterval( ap_registerPlayers, 100 );
}
	
function ap_registerPlayers() {
	var objectID;
	var objectTags = document.getElementsByTagName('object');
	for(var i=0;i<objectTags.length;i++) {
		objectID = objectTags[i].id;
	if(objectID.indexOf('audioplayer') == 0) {
			ap_instances[i] = objectID.substring(11, objectID.length);
		}
	}
}

function ap_stopAll(playerID) {
	for(var i = 0;i<ap_instances.length;i++) {
		try {
			if(ap_instances[i] != playerID) { 
				document.getElementById('audioplayer' + ap_instances[i].toString()).SetVariable('closePlayer', 1);
			}	else {
				document.getElementById('audioplayer' + ap_instances[i].toString()).SetVariable('closePlayer', 0);
			}
		} catch( errorObject ) {
			// stop any errors
		}
	}
}

function popupPrint(id) 
{
	var w = 750;
	var h = 400;
	var winl=(screen.width-w) / 2;
	var wint=(screen.height-h) / 2;
	win=window.open("/index.php?s=api&a=property.print&id=" + id,"popupPrint","scrollbars=yes,status=yes,location=no,toolbar=no,menubar=yes,directories=no,resizable=yes,width="+w+",height="+h+",top="+wint+",left="+winl+"");
	if (parseInt(navigator.appVersion) >=4) { win.window.focus(); }
}

function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}

function encodeEmailAddress(emailName,emailDomain)
{
	var emailAddress = emailName + "@" + emailDomain;
	document.write("<a href='mailto:" + emailAddress + "'>" + emailAddress + "</a>");
}

/* General: Highlight a Row */
function highlightOn(divID)
{
	YAHOO.util.Dom.addClass(divID, 'highlight');
}

/* General: Turn off Highlight */
function highlightOff(divID)
{
	YAHOO.util.Dom.removeClass(divID, 'highlight');
}

function switchTab(tabID)
{
	var propertyTab1 = document.getElementById('tab1');
	var propertyTab2 = document.getElementById('tab2');
	var propertyTab3 = document.getElementById('tab3');
	var propertyTab4 = document.getElementById('tab4');
	
	if(propertyTab1) { propertyTab1.className = "tab_normal"; }
	if(propertyTab2) { propertyTab2.className = "tab_normal"; }
	if(propertyTab3) { propertyTab3.className = "tab_normal"; }
	if(propertyTab4) { propertyTab4.className = "tab_normal"; }
	
	document.getElementById(tabID).className = "tab_selected";
}

function switchListingTab(tabID)
{
	document.getElementById('listingTab1').className = "tab_normal";
	document.getElementById('listingTab2').className = "tab_normal";
	document.getElementById('listingTab' + tabID).className = "tab_selected";
	document.getElementById('listingDiv1').style.display = 'none';
	document.getElementById('listingDiv2').style.display = 'none';
	document.getElementById('listingDiv' + tabID).style.display = 'block';
}

/* Dictionary: Show Listings */
function dictionaryLetter(searchLetter)
{
	var searchColumn = "dictionary_word";
	var searchKeyword = searchLetter;
	var searchMatch = "start";
	var searchURL = "/index.php?s=api&a=dictionary.search&searchColumn=" + searchColumn + '&searchKeyword=' + searchKeyword + '&searchMatch=' + searchMatch;
	
	AjaxAPI('dictionarySearch', searchURL);
}

/* Dictionary: Show Listings */
function documentCategory(categoryTitle)
{
	form = document.searchForm;

	form.searchKeyword.value = categoryTitle;
	form.searchColumn.value = "category_title";
	
	documentSearch();
}

/* Dictionary: Show Listings */
function documentSearch()
{
	form = document.searchForm;
	
	if (form.searchKeyword.value == "") { alert("Please enter a search keyword."); form.searchKeyword.focus(); return (false);}
	
	var searchColumn = form.searchColumn.value;
	var searchKeyword = form.searchKeyword.value;
	var searchURL = "index.php?s=api&a=library.search&searchColumn=" + searchColumn + '&searchKeyword=' + searchKeyword;
	
	AjaxAPI('librarySearch', searchURL);
}

/* General: Submit Form */
function searchAPI(divID,url)
{
	AjaxAPI(divID, url);
}

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_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_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 showElement(id) {

if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + id + ".style.visibility = 'visible'");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[id].visibility = 'visible';
}
if (document.getElementById && !document.all) {
divname = document.getElementById(id);
divname.style.visibility = 'visible';
}};

function hideElement(id) {

if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + id + ".style.visibility = 'hidden'");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[id].visibility = 'hidden';
}
if (document.getElementById && !document.all) {
divname = document.getElementById(id);
divname.style.visibility = 'hidden';
}};

/* Validate Add/Edit Listing */
function listingValidate(form)
{
	/* Verify a listing price or explaination is defined */
	if (form.listing_price.value == "") { alert("Please enter a price or set it to '0' if not applicable.\nYou can then explain in the Description section (i.e. call me, negotiable, etc)."); form.listing_price.focus(); return (false); }
	
	/* Make sure the propert type is selected */
	if (form.listing_type.value == "") { alert("Please select the property type."); form.listing_type.focus(); return (false); }
  
	/* Verify listing address is not empty */
	if (form.listing_address.value == "") { alert("Please enter the street address."); form.listing_address.focus(); return (false); }
	if (form.listing_city.value == "") { alert("Please enter the city."); form.listing_city.focus(); return (false); }
	if (form.listing_state.value == "") { alert("Please select the state."); form.listing_state.focus(); return (false); }
	if (form.listing_zipcode.value == "") { alert("Please enter the zip code."); form.listing_zipcode.focus(); return (false); }
	
	/* Customer information */
	if (form.listing_agent_name.value == "") { alert("Please enter your name."); form.listing_agent_name.focus(); return (false); }
	if (form.listing_agent_email.value == "") { alert("Please enter your e-mail address."); form.listing_agent_email.focus(); return (false); }
	
  return (true);
}

function highlight(cell,color) {
//set cross-browser DOM
  if (document.all) {
	 docObj = eval("document.all." + cell + ".style");
  } else {
	 docObj = eval("document." + cell);
  }
//change highlight color
  docObj.background = color;
}

function showPropertyElement(id) {

divname = document.getElementById(id);
if(divname) { divname.style.display = 'block'; }
};

function hidePropertyElement(id) {

divname = document.getElementById(id);
if(divname) { divname.style.display = 'none'; }

};
   
function switchmenus()
{
  highlight("linkSimilar1","#ffffff");
  highlight("linkSimilar2","#ffffff");
  highlight("linkSchools1","#ffffff");
  highlight("linkSchools2","#ffffff")
  highlight("linkCommunity1","#ffffff");
  highlight("linkCommunity","#ffffff");
}

var activeOption = 0;

function divOn() {
activeOption = 1;
};

function divOff() {
activeOption = 0;
};

function divCheck() {
	if (activeOption == 0) 
	{
		//hideElement('contentSimilar');
		hidePropertyElement('contentSimilar');
		//hideElement('contentSchools');
		hidePropertyElement('contentSchools');
		//hideElement('contentCommunity');
		hidePropertyElement('contentCommunity');
		//hideElement('contentContact'); 
		hidePropertyElement('contentContact'); 
	} else { return false; }
};

function realtyLoad()
{
	/* Check which functions we can load */
	if(typeof window.realtyPreload == "function") window.realtyPreload();
	if(typeof window.loadLocalSearch == "function") window.loadLocalSearch();
	if(typeof window.realtyMap == "function") window.realtyMap();
}

function realtyUnload()
{
	/* Check if we should clean up the Google Maps code */
	if(typeof window.MapUnload == "function") window.MapUnload();
}

/* Ajax Functionality */
function AjaxAPI(divID,divURL,AjaxCallback,parseMethod,parseParams)
{
	/* Use Get or Post method */
	var AjaxMethod = (parseMethod == 'POST') ? 'POST' : 'GET';
	var AjaxParams = (parseParams !== undefined) ? parseParams : null;

	// Check if a custom callback was used
	if(!AjaxCallback)
	{
		// Create the standard callback function
		var AjaxCallback = {
			// Success function
			success: function(o) {
				if(o.responseText !== undefined && divID !== null)
				{
					// Load the contents into the div
					document.getElementById(divID).innerHTML = o.responseText;
				}},
			// Failure function
			failure: function(o) { }
		};
	}
	
	YAHOO.util.Connect.asyncRequest(AjaxMethod, divURL, AjaxCallback, AjaxParams);
}