var request;

/* trying to fix an issue with IE not loading background on a popup: */
var preloadMapMid = new Image();
preloadMapMid.src = '/images/map/popup-label/map-label-mid.png';

function createRequest() {
	try {
		request = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				request = false;
			}
		}
	}
	
	if (!request)
		alert("Error initializing XMLHttpRequest!");
}

function loadCities(id) {
	var url = "/includes/cities/" +document.getElementById(id).options[document.getElementById(id).selectedIndex].value + ".html";
	request.open("GET", url, true);
	request.onreadystatechange = updateCities;
	request.send(null);
}

function updateCities() {
	if (request.readyState == 4) {
		if (request.status == 200) {
			var response = request.responseText;

			// load the cities
		
			if (updateCities.prototype.cId == "findTabAdvanced:formpg:findCity"
				&& typeof(document.getElementById(updateCities.prototype.cId).outerHTML) != "undefined") {
					document.getElementById(updateCities.prototype.cId).outerHTML = '<select id="findTabAdvanced:formpg:findCity" name="findTabAdvanced:formpg:findCity" size="1" class="city" onchange="statewideCheck(this.id,\'findTabAdvanced:formpg:findRadius\')">' +
					response.replace(/\n/g, "") + '</select>';
			} else if (updateCities.prototype.cId == "matchTab:match:matchCity"
				&& typeof(document.getElementById(updateCities.prototype.cId).outerHTML) != "undefined") {
					document.getElementById(updateCities.prototype.cId).outerHTML = '<select id="matchTab:match:matchCity" name="matchTab:match:matchCity" size="1" class="city" onchange="statewideCheck(this.id,\'matchTab:match:matchRadius\')">' +
					response.replace(/\n/g, "") + '</select>';
			} else {
				document.getElementById(updateCities.prototype.cId).innerHTML = response.replace(/\n/g, "");
			}

			document.getElementById(updateCities.prototype.cId).selectedIndex = 0;			
		} else
			alert("status is " + request.status);
     }
}

function statewideCheck(cId,rId) {
	if (document.getElementById(cId).options.selectedIndex == 0) {
		document.getElementById(rId).selectedIndex = 0;	
		document.getElementById(rId).disabled = false;
	} else if (document.getElementById(cId).options.selectedIndex == 1) {
		document.getElementById(rId).selectedIndex = 0;	
		document.getElementById(rId).disabled = true;	
	} else {
		document.getElementById(rId).selectedIndex = 5;	
		document.getElementById(rId).disabled = false;	
	}

}

function getCities(sId,cId,rId) {
	var s = document.getElementById(sId).selectedIndex;

	if (s == 0) {
		document.getElementById(cId).innerHTML = '';
		document.getElementById(cId).options[0] = new Option('---- select a state first ----','0');
		document.getElementById(cId).disabled = false;
		document.getElementById(rId).disabled = false;
		document.getElementById(rId).selectedIndex = 0;
	} else if (s == 1) {
		document.getElementById(cId).innerHTML = '<option value="0">----<\/option>';
		document.getElementById(cId).disabled = true;
		document.getElementById(cId).selectedIndex = 0;
		document.getElementById(rId).disabled = true;
		document.getElementById(rId).selectedIndex = 0;
	} else {
		document.getElementById(cId).disabled = false;
		document.getElementById(rId).disabled = false;
		document.getElementById(rId).selectedIndex = 0;
		createRequest();
		updateCities.prototype.sId = sId;
		updateCities.prototype.cId = cId;		
		loadCities(sId);
	}
}



var lastClick = "";
var closeIcon = '<img src="/images/x-icon.png" class="f-right" onclick="closeHelp()" onmouseover="setCursor(this, \'pointer\')" onmouseout="setCursor(this, \'default\')">';
/*
	Populates the help popup with text descriptions for the
	Find LIFESTYLE MENU
*/
function loadHelp(action) 
{
	var gb = document.getElementById("glossaryBox");
	var sel = document.getElementById("findTabAdvanced:formpg:findMenu").value;

	var content = new Object();
	
	content['0'] = closeIcon + 'Please a select a search first.';
	
	content['7'] = closeIcon + 'Best public schools are rated by a combined measure of reading and math proficiency from the state standardized No Child Left Behind Tests, normalized for accurate national comparison by NeighborhoodScout\'s exclusive NAEP-based normalization. You can also search specifically by school districts that perform highest for reading proficiency or math proficiency by using advanced options, below.';
	
	content['8'] = closeIcon + 'Know which neighborhoods have appreciated the most before you buy. You can search for neighborhoods where home values have increased the most since 1990 in any area of America. You can also add advanced options, including shorter time periods and price range, below.';
	
	content['22'] = closeIcon + 'Discover the safest neighborhoods in any area, before you buy a home or move. Neighborhood crime rates are synthesized from local crime statistics from the FBI and the U.S. Justice Department. The crime index includes both violent and property crime. You can also add advanced options below.';
	
	content['1'] = closeIcon + 'Vacation home locations are a unique combination of safety from crime, educated neighbors, excellent public schools, and an enviable mix of rental properties and owner-occupied homes - all indicators of a top quality community where real estate investments are more secure. You can also add advanced options below.'; 
	
	content['2'] = closeIcon + 'Retirement dream areas are a unique combination of peace and quiet, safety from crime, a vibrant mix of educated seniors and other age groups, and diverse housing choices. You can also add advanced options below.';
	
	content['3'] = closeIcon + 'Luxury communities are a unique combination of wealthy, educated, executives, managers, and professionals. You can also add advanced options below.';
	
	content['4'] = closeIcon + 'Executive lifestyles are a unique combination of wealthy, educated, executives, managers & professionals, large homes, and high housing appreciation rates. You can also add advanced options below.';
	
	content['5'] = closeIcon + 'Top choice neighborhoods for families with children combine excellent public schools, safety from crime, owner-occupied single family homes, other families with children in the neighborhood, and many adults with college degrees or even advanced degrees. You can also add advanced options below.';
	
	content['6'] = closeIcon + 'Top choice neighborhoods for first-time homebuyers combine educated neighbors (a powerful indicator of overall neighborhood quality), with above-average rates of housing appreciation. You can also add advanced options, including the price range you want, below.';
	
	content['9'] = closeIcon + 'Top neighborhoods for young, upwardly-mobile singles are a unique combination of young singles who are educated, employed in professional or executive positions, and preferentially rent. You can also add advanced options below.';
	
	content['11'] = closeIcon + 'Spanish-speaking neighborhoods have a high proportion of people who speak Spanish at home. You can also add advanced options below.';
	
	content['12'] = closeIcon + 'Neighborhoods that contain wealthy, educated people. You can also add advanced options below.';
	
	content['13'] = closeIcon + 'Top choice neighborhoods for college students are the areas most popular with college or graduate students. You can also add advanced options below.';
	
	content['14'] = closeIcon + 'Hip and trendy neighborhoods are artsy/funky areas, like Greenwich Village or Harvard Square. You can also add advanced options below.';
	
	content['16'] = closeIcon + 'Undervalued neighborhoods/towns are areas that combine educated neighbors (a powerful indicator of overall neighborhood quality), safety from crime, excellent public schools, and a high proportion of larger, owner-occupied single-family detached homes. You can also add advanced options, including the price range you want, below.';
	
	content['36061006700'] = closeIcon + 'Located in lower Manhattan, Greenwich Village was home to the Beat Generation (including writers such as Allen Ginsburg and Jack Kerouac) and the folk music scene of the \'60s. Today, it retains a strong liberal culture and art scene, but is significantly more expensive than it was in its heyday. Find neighborhoods most similar to Greenwich Village in any area.';
	
	content['06037700700'] = closeIcon + 'Beverly Hills is a distinct city located entirely within the city of Los Angeles. It is known for its Hollywood and celebrity culture, and for its wealth, though it is not as uniformly wealthy as often portrayed. One of the most famous shopping districts in the world, Rodeo Drive, is located here. Find neighborhoods most similar to "the hills" of Beverly Hills in any area.';
	
	content['47157022021'] = closeIcon + 'Graceland, located in the city of Memphis, Tennessee, was the home of Elvis Presley. As such, tourists flock there to visit the estate of Elvis, which is now a museum. Find neighborhoods most similar to the Graceland neighborhood in any area.';
	
	content['25025020100'] = closeIcon + 'Beacon Hill is a neighborhood in Boston known for its wealth and history. Many notable historic figures lived here, including Oliver Wendell Holmes, Henry Cabot Lodge, John Hancock, and Robert Frost. Its historic architectural features include Federal-style rowhouses and brick sidewalks lit by gaslight. Find neighborhoods most similar to Beacon Hill in any area.';
	
	content['06075016600'] = closeIcon + 'Centered at the corner of Haight and Ashbury Streets in San Francisco, this neighborhood was made famous during the \'60s hippie movement. Jefferson Airplane, the Grateful Dead, and Janis Joplin all lived here. Even though it has since undergone significant gentrification, it still retains much of its liberal, bohemian culture. Find neighborhoods most similar to Haight-Ashbury in any area.';
	
	if (sel != "") 
	{
		gb.innerHTML= content[sel];
		gb.style.left = "60px";
		gb.style.top = "60px";
			if (action != "select")
				gb.style.display="block";
			else if (action == "select" && gb.style.display=="block" && lastClick == "advanced") 
				gb.style.display="none";
			else if (action == "select" && gb.style.display=="block" && lastClick == "lifestyle") 
				gb.style.display="block";
	}
}

/*
	Populates the help popup with text descriptions for the
	"Find" ADVANCED MENU selections
*/
function loadHelpAdvanced()
{
	var sel = document.getElementById("findTabAdvanced:formpg:findMenu").value;
	var gb = document.getElementById("glossaryBox");
    
	var content = new Object();

	content['0'] = closeIcon + 'Please a select a search first.';
		
	content['7'] = closeIcon + '<strong>Best schools:</strong> "Best district ratings" is a combined measure of both reading and math proficiency from the state standardized No Child Left Behind Tests, normalized for accurate national comparison. You can also search specifically by school districts that perform highest for reading proficiency or math proficiency.<br /><br /><strong>Average class size:</strong> The total number of students divided by the total number of full time classroom teachers in the district. Smaller classes are desirable because students tend to receive more personal attention.<br /><br /><strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison.<br /><br /><strong>Setting (based on population density:</strong> Densely urban (most densely populated), urban (densely populated), suburban (populated but spread-out), rural (country, but somewhat populated), or remote (very few people).';

	content['8'] = closeIcon + '<strong>Time period (home appreciation):</strong> The time frame for which your selected appreciation rate is calculated.<br /><br /><strong>Appreciation rate:</strong> The change in median house values in this neighborhood for the selected time period. <br /><br /><strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison.';

	content['22'] = closeIcon + '<strong>Crime search:</strong> Violent crimes include homicide and non-negligent manslaughter, forcible rape, armed robbery, and aggravated assault. Property crimes include larceny (over $50), burglary, and motor vehicle theft.<br /><br /><strong>Crime rate:</strong> Based on the number of violent and/or property crimes per 1,000 residents, or the number of crimes per square mile, depending on the type of crime search selected.<br /><br /><strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison. <br /><br /><strong>Setting (based on population density:</strong> Densely urban (most densely populated), urban (densely populated), suburban (populated but spread-out), rural (country, but somewhat populated), or remote (very few people).';

	content['1'] = closeIcon + '<strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison. <br /><br /><strong>Setting (based on population density:</strong> Densely urban (most densely populated), urban (densely populated), suburban (populated but spread-out), rural (country, but somewhat populated), or remote (very few people). <br /><br /><strong>Coastal:</strong> Neighborhoods on the ocean or tidal rivers.<br /><br /><strong>Quiet:</strong> Less densely populated, plus very few college students, children, or renters.'; 

	content['2'] = closeIcon + '<strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison. <br /><br /><strong>Setting (based on population density:</strong> Densely urban (most densely populated), urban (densely populated), suburban (populated but spread-out), rural (country, but somewhat populated), or remote (very few people).<br /><br /><strong>Coastal:</strong> Neighborhoods on the ocean or tidal rivers.'; 

	content['3'] = closeIcon + '<strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison. <br /><br /><strong>Setting (based on population density:</strong> Densely urban (most densely populated), urban (densely populated), suburban (populated but spread-out), rural (country, but somewhat populated), or remote (very few people).<br /><br /><strong>Coastal:</strong> Neighborhoods on the ocean or tidal rivers.'; 

	content['4'] = closeIcon + '<strong>Best schools:</strong> "Best district ratings" is a combined measure of both reading and math proficiency from the state standardized No Child Left Behind Tests, normalized for accurate national comparison. You can also search specifically by school districts that perform highest for reading proficiency or math proficiency alone.<br /><br /><strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison.<br /><br /><strong>Setting (based on population density:</strong> Densely urban (most densely populated), urban (densely populated), suburban (populated but spread-out), rural (country, but somewhat populated), or remote (very few people).<br /><br /><strong>Coastal:</strong> Neighborhoods on the ocean or tidal rivers.'; 

	content['5'] = closeIcon + '<strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison.<br /><br /><strong>Setting (based on population density:</strong> Densely urban (most densely populated), urban (densely populated), suburban (populated but spread-out), rural (country, but somewhat populated), or remote (very few people).';

	content['6'] = closeIcon + '<strong>Best schools:</strong> \"Best district ratings\" is a combined measure of both reading and math proficiency from the state standardized No Child Left Behind Tests, normalized for accurate national comparison. You can also search specifically by school districts that perform highest for reading proficiency or math proficiency alone.<br /><br /><strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison.<br /><br /><strong>Setting (based on population density:</strong> Densely urban (most densely populated), urban (densely populated), suburban (populated but spread-out), rural (country, but somewhat populated), or remote (very few people).';

	content['9'] = closeIcon + '<strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison.<br /><br /><strong>Average rental price</strong>:  The average price of rental housing.';

	content['11'] = closeIcon + '<strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison.<br /><br /><strong>Setting (based on population density:</strong> Densely urban (most densely populated), urban (densely populated), suburban (populated but spread-out), rural (country, but somewhat populated), or remote (very few people).';

	content['12'] = closeIcon + '<strong>Best schools:</strong> "Best district ratings" is a combined measure of both reading and math proficiency from the state standardized No Child Left Behind Tests, normalized for accurate national comparison. You can also search specifically by school districts that perform highest for reading proficiency or math proficiency alone.<br /><br /><strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison.';

	content['13'] = closeIcon + '<strong>Crime rate:</strong> Based on the number of violent and/or property crimes per 1,000 residents, or the number of crimes per square mile, depending on the type of crime search selected.<br /><br /><strong>Walkable:</strong> Easy to navigate on foot.';

	content['14'] = closeIcon + '<strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison.<br /><br /><strong>Average rental price</strong>:  The average price of rental housing.<br /><br /><strong>Ownership:</strong> The level of homeownership in the neighborhood, either predominantly owner-occupied, predominantly rental units, or a mixture of owners and renters.';

	content['16'] = closeIcon + '<strong>Median house value:</strong> The middle house value in a neighborhood, giving the best price information for comparison.<br /><br /><strong>Setting (based on population density:</strong> Densely urban (most densely populated), urban (densely populated), suburban (populated but spread-out), rural (country, but somewhat populated), or remote (very few people).<br /><br /><strong>Coastal:</strong> Neighborhoods on the ocean or tidal rivers.';


	content['36061006700'] = closeIcon + ' No advanced options for this search.';

	content['06037700700'] = closeIcon + ' No advanced options for this search.';

	content['47157022021'] = closeIcon + '  No advanced options for this search.';

	content['25025020100'] = closeIcon + '  No advanced options for this search.';

	content['06075016600'] = closeIcon + '  No advanced options for this search.';

    gb.innerHTML= content[sel];
}

/* Show the help popup for the lifestyle search */
function displayHelp(obj) 
{
	lastClick = "lifestyle";
	var gb = document.getElementById("glossaryBox");
	var sel = document.getElementById("findTabAdvanced:formpg:findMenu").value;
	if (sel != "")
		loadHelp("click");
}

/* Show the help popup for the advanced menu */
function displayHelpAdvanced(e) 
{
	lastClick = "advanced";

    var gb = document.getElementById("glossaryBox");
	var sel = document.getElementById("findTabAdvanced:formpg:findMenu").value;

	if (sel != "")
	{
		loadHelpAdvanced();
		/* NOTE: some hard coded positioning here... */
		gb.style.left = (945 - 570) + "px";
		gb.style.top = (310) + "px";
		gb.style.display="block";
	}

}

/*  Show or hide the advanced menu dropdown for the FIND tab */
function toggleAdvanced()
{
	//var obj = document.getElementById('findTabAdvanced:advanced');
    // findTabAdvanced:formpg:advanced
	var obj = document.getElementById('findTabAdvanced:formpg:advanced');
	var advFormState = document.getElementById("findTabAdvanced:formpg:advFormState");
    if (obj.style.display == "block")
	{
		obj.style.display="none";
		advFormState.value="0";
		document.getElementById("findTabAdvanced:formpg:advancedButton").style.backgroundImage = "url(/images/blue-module/button-plus.gif)";
		// hide the help popup only if it was launched for the advanced help button
		if (lastClick == "advanced")
			document.getElementById("glossaryBox").style.display="none";
	}
	else
	{
		advFormState.value="1";
		obj.style.display="block";
		document.getElementById("findTabAdvanced:formpg:advancedButton").style.backgroundImage = "url(/images/blue-module/button-minus.gif)";
	}
}

function toggleAdvancedModified()
{
	//var obj = document.getElementById('findTabAdvanced:advanced');
    // findTabAdvanced:formpg:advanced
	var obj = document.getElementById('findTabAdvanced:formpg:advanced');
	var advFormState = document.getElementById("findTabAdvanced:formpg:advFormState");

    if (advFormState.value=="1")
	{
        advFormState.value="1";
        obj.style.display="block";
		document.getElementById("findTabAdvanced:formpg:advancedButton").style.backgroundImage = "url(/images/blue-module/button-minus.gif)";
	}
	else
	{
		obj.style.display="none";
		advFormState.value="0";
        document.getElementById("findTabAdvanced:formpg:advancedButton").style.backgroundImage = "url(/images/blue-module/button-plus.gif)";
		// hide the help popup only if it was launched for the advanced help button
		if (lastClick == "advanced")
			document.getElementById("glossaryBox").style.display="none";
	}
}

/* Function to handle the FIND tab lifestyle option menu */
function lifestyleOptions()
{
	loadHelp("select");

	var sel = document.getElementById("findTabAdvanced:formpg:findMenu").value;
	var allopts = ["findTabAdvanced:formpg:HCOST1", "findTabAdvanced:formpg:setting",
		"findTabAdvanced:formpg:COS", "findTabAdvanced:formpg:XXX","findTabAdvanced:formpg:XXX2",
		"findTabAdvanced:formpg:XXXSIZE","findTabAdvanced:formpg:QUT", "findTabAdvanced:formpg:APPR",
		"findTabAdvanced:formpg:PCM", "findTabAdvanced:formpg:PCM2", "findTabAdvanced:formpg:PCMTYPE",
		"findTabAdvanced:formpg:RCOST1","findTabAdvanced:formpg:WLK","findTabAdvanced:formpg:OWNER",
		"findTabAdvanced:formpg:APPRTIME"];

	for (var i = 0; i < allopts.length; i++)
	{
		if (document.getElementById(allopts[i]).hasChildNodes())
		{
			for (var j = 0; j < document.getElementById(allopts[i]).childNodes.length; j++)
			{
				if (document.getElementById(allopts[i]).childNodes[j].nodeName == "SELECT")
					document.getElementById(allopts[i]).childNodes[j].selectedIndex = 0;
			}
		}
	}

	var search = new Object();

	search['0'] = new Object();
	search['0']['label'] = "Please select a search first:";
	search['0']['options'] = "";

	search['7'] = new Object();
	search['7']['label'] = "Best public schools";
	search['7']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:XXX,findTabAdvanced:formpg:XXXSIZE";

	search['8'] = new Object();
	search['8']['label'] = "Home appreciation rates";
	search['8']['options'] = "findTabAdvanced:formpg:APPRTIME,findTabAdvanced:formpg:APPR,findTabAdvanced:formpg:HCOST1";

	search['22'] = new Object();
	search['22']['label'] = "Crime rates";
	search['22']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:PCM,findTabAdvanced:formpg:PCMTYPE";

	search['1'] = new Object();
	search['1']['label'] = "Vacation home locations";
	search['1']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:COS,findTabAdvanced:formpg:QUT";

	search['2'] = new Object();
	search['2']['label'] = "Retirement dream areas";
	search['2']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:COS";

	search['3'] = new Object();
	search['3']['label'] = "Luxury communities";
	search['3']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:COS";

	search['4'] = new Object();
	search['4']['label'] = "Executive lifestyles";
	search['4']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:COS,findTabAdvanced:formpg:XXX2";

	search['5'] = new Object();
	search['5']['label'] = "Families";
	search['5']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting";

	search['6'] = new Object();
	search['6']['label'] = "First-time home buyers";
	search['6']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:XXX2";

	search['9'] = new Object();
	search['9']['label'] = "Young singles, upwardly-mobile";
	search['9']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:RCOST1";

	search['11'] = new Object();
	search['11']['label'] = "Spanish-speaking neighborhoods";
	search['11']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting";

	search['12'] = new Object();
	search['12']['label'] = "Urban sophisticates";
	search['12']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:XXX2";

	search['13'] = new Object();
	search['13']['label'] = "College students";
	search['13']['options'] = "findTabAdvanced:formpg:PCM2,findTabAdvanced:formpg:WLK";

	search['14'] = new Object();
	search['14']['label'] = "Hip and trendy neighborhoods";
	search['14']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:RCOST1,findTabAdvanced:formpg:OWNER";

	search['16'] = new Object();
	search['16']['label'] = "Great deals on great towns";
	search['16']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:COS";

	search['36061006700'] = new Object();
	search['36061006700']['label'] = "Greenwich Village &nbsp; &nbsp; &nbsp; &nbsp; No advanced options for this search";
	search['36061006700']['options'] = "";

	search['06037700700'] = new Object();
	search['06037700700']['label'] = "Beverly Hills &nbsp; &nbsp; &nbsp; &nbsp; No advanced options for this search";
	search['06037700700']['options'] = "";

	search['47157022021'] = new Object();
	search['47157022021']['label'] = "Graceland, Tennessee &nbsp; &nbsp; &nbsp; &nbsp; No advanced options for this search";
	search['47157022021']['options'] = "";

	search['25025020100'] = new Object();
	search['25025020100']['label'] = "Beacon Hill &nbsp; &nbsp; &nbsp; &nbsp; No advanced options for this search";
	search['25025020100']['options'] = "";

	search['06075016600'] = new Object();
	search['06075016600']['label'] = "Haight-Ashbury &nbsp; &nbsp; &nbsp; &nbsp; No advanced options for this search";
	search['06075016600']['options'] = "";


	var opts = search[sel]['options'].split(",");

	// reset advanced menu to empty state
	for (var j = 0; j < allopts.length; j++)
	{
		document.getElementById(allopts[j]).style.display="none";
	}
	// reset checkboxes
	document.getElementById("findTabAdvanced:formpg:coastal").checked=false;
	document.getElementById("findTabAdvanced:formpg:walkable").checked=false;
	document.getElementById("findTabAdvanced:formpg:quiet").checked=false;
	setChbxState("findTabAdvanced:formpg:coastal");
	setChbxState("findTabAdvanced:formpg:walkable");
	setChbxState("findTabAdvanced:formpg:quiet");

	if (opts.length > 1)
	{
		// display appropriate options in the advanced menu
		for (var i = 0; i < opts.length; i++)
		{
			document.getElementById(opts[i]).style.display="block";
		}
	}

	// set the label for the advanced menu
	document.getElementById("findTabAdvanced:formpg:advancedLabel").innerHTML = search[sel]['label'];

	// special positioning for certain lifestyle selections
	if (sel == "7") {
		// schools
		document.getElementById("findTabAdvanced:formpg:HCOST1").style.width = "340px";
		document.getElementById("findTabAdvanced:formpg:XXX").style.width = "340px";
		document.getElementById("findTabAdvanced:formpg:setting").style.width = "340px";

		document.getElementById("findTabAdvanced:formpg:XXXLabel").style.width = "125px";
		document.getElementById("findTabAdvanced:formpg:HCOST1Label").style.width = "125px";
		document.getElementById("findTabAdvanced:formpg:settingLabel").style.width = "125px";
		document.getElementById("findTabAdvanced:formpg:XXXSIZELabel").style.width = "125px";

	} else if (sel == "22") {
		// crime
		document.getElementById("findTabAdvanced:formpg:PCMTYPE").style.width = "360px";
		document.getElementById("findTabAdvanced:formpg:HCOST1").style.width = "360px";

		document.getElementById("findTabAdvanced:formpg:PCMLabel").style.width = "70px";
		document.getElementById("findTabAdvanced:formpg:settingLabel").style.width = "70px";
		document.getElementById("findTabAdvanced:formpg:PCMTYPELabel").style.width = "113px";
		document.getElementById("findTabAdvanced:formpg:HCOST1Label").style.width = "113px";
	} else {
		document.getElementById("findTabAdvanced:formpg:HCOST1").style.width = "auto";
		document.getElementById("findTabAdvanced:formpg:XXX").style.width = "auto";
		document.getElementById("findTabAdvanced:formpg:setting").style.width = "auto";
		document.getElementById("findTabAdvanced:formpg:PCM").style.width = "370px";
		document.getElementById("findTabAdvanced:formpg:HCOST1Label").style.width = "auto";
		document.getElementById("findTabAdvanced:formpg:settingLabel").style.width = "auto";
		document.getElementById("findTabAdvanced:formpg:XXXSIZELabel").style.width = "auto";
	}
}


/* Function to handle the FIND tab lifestyle option menu */
function lifestyleOptionsModified()
{
	loadHelp("select");

	var sel = document.getElementById("findTabAdvanced:formpg:findMenu").value;
	var allopts = ["findTabAdvanced:formpg:HCOST1", "findTabAdvanced:formpg:setting",
		"findTabAdvanced:formpg:COS", "findTabAdvanced:formpg:XXX","findTabAdvanced:formpg:XXX2",
		"findTabAdvanced:formpg:XXXSIZE","findTabAdvanced:formpg:QUT", "findTabAdvanced:formpg:APPR",
		"findTabAdvanced:formpg:PCM", "findTabAdvanced:formpg:PCM2", "findTabAdvanced:formpg:PCMTYPE",
		"findTabAdvanced:formpg:RCOST1","findTabAdvanced:formpg:WLK","findTabAdvanced:formpg:OWNER",
		"findTabAdvanced:formpg:APPRTIME"];

	var search = new Object();

	search['0'] = new Object();
	search['0']['label'] = "Please select a search first:";
	search['0']['options'] = "";

	search['7'] = new Object();
	search['7']['label'] = "Best public schools";
	search['7']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:XXX,findTabAdvanced:formpg:XXXSIZE";

	search['8'] = new Object();
	search['8']['label'] = "Home appreciation rates";
	search['8']['options'] = "findTabAdvanced:formpg:APPRTIME,findTabAdvanced:formpg:APPR,findTabAdvanced:formpg:HCOST1";

	search['22'] = new Object();
	search['22']['label'] = "Crime rates";
	search['22']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:PCM,findTabAdvanced:formpg:PCMTYPE";

	search['1'] = new Object();
	search['1']['label'] = "Vacation home locations";
	search['1']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:COS,findTabAdvanced:formpg:QUT";

	search['2'] = new Object();
	search['2']['label'] = "Retirement dream areas";
	search['2']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:COS";

	search['3'] = new Object();
	search['3']['label'] = "Luxury communities";
	search['3']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:COS";

	search['4'] = new Object();
	search['4']['label'] = "Executive lifestyles";
	search['4']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:COS,findTabAdvanced:formpg:XXX2";

	search['5'] = new Object();
	search['5']['label'] = "Families";
	search['5']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting";

	search['6'] = new Object();
	search['6']['label'] = "First-time home buyers";
	search['6']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:XXX2";

	search['9'] = new Object();
	search['9']['label'] = "Young singles, upwardly-mobile";
	search['9']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:RCOST1";

	search['11'] = new Object();
	search['11']['label'] = "Spanish-speaking neighborhoods";
	search['11']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting";

	search['12'] = new Object();
	search['12']['label'] = "Urban sophisticates";
	search['12']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:XXX2";

	search['13'] = new Object();
	search['13']['label'] = "College students";
	search['13']['options'] = "findTabAdvanced:formpg:PCM2,findTabAdvanced:formpg:WLK";

	search['14'] = new Object();
	search['14']['label'] = "Hip and trendy neighborhoods";
	search['14']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:RCOST1,findTabAdvanced:formpg:OWNER";

	search['16'] = new Object();
	search['16']['label'] = "Great deals on great towns";
	search['16']['options'] = "findTabAdvanced:formpg:HCOST1,findTabAdvanced:formpg:setting,findTabAdvanced:formpg:COS";

	search['36061006700'] = new Object();
	search['36061006700']['label'] = "Greenwich Village &nbsp; &nbsp; &nbsp; &nbsp; No advanced options for this search";
	search['36061006700']['options'] = "";

	search['06037700700'] = new Object();
	search['06037700700']['label'] = "Beverly Hills &nbsp; &nbsp; &nbsp; &nbsp; No advanced options for this search";
	search['06037700700']['options'] = "";

	search['47157022021'] = new Object();
	search['47157022021']['label'] = "Graceland, Tennessee &nbsp; &nbsp; &nbsp; &nbsp; No advanced options for this search";
	search['47157022021']['options'] = "";

	search['25025020100'] = new Object();
	search['25025020100']['label'] = "Beacon Hill &nbsp; &nbsp; &nbsp; &nbsp; No advanced options for this search";
	search['25025020100']['options'] = "";

	search['06075016600'] = new Object();
	search['06075016600']['label'] = "Haight-Ashbury &nbsp; &nbsp; &nbsp; &nbsp; No advanced options for this search";
	search['06075016600']['options'] = "";


	var opts = search[sel]['options'].split(",");

	// reset advanced menu to empty state
	for (var j = 0; j < allopts.length; j++)
	{
		document.getElementById(allopts[j]).style.display="none";
	}
	document.getElementById("findTabAdvanced:formpg:coastal").checked=false;
	document.getElementById("findTabAdvanced:formpg:walkable").checked=false;
	document.getElementById("findTabAdvanced:formpg:quiet").checked=false;

	if (opts.length > 1)
	{
		// display appropriate options in the advanced menu
		for (var i = 0; i < opts.length; i++)
		{
			document.getElementById(opts[i]).style.display="block";
		}
	}

	// set the label for the advanced menu
	document.getElementById("findTabAdvanced:formpg:advancedLabel").innerHTML = search[sel]['label'];

	// special positioning for certain lifestyle selections
	if (sel == "7") {
		// schools
		document.getElementById("findTabAdvanced:formpg:HCOST1").style.width = "340px";
		document.getElementById("findTabAdvanced:formpg:XXX").style.width = "340px";
		document.getElementById("findTabAdvanced:formpg:setting").style.width = "340px";

		document.getElementById("findTabAdvanced:formpg:XXXLabel").style.width = "125px";
		document.getElementById("findTabAdvanced:formpg:HCOST1Label").style.width = "125px";
		document.getElementById("findTabAdvanced:formpg:settingLabel").style.width = "125px";
		document.getElementById("findTabAdvanced:formpg:XXXSIZELabel").style.width = "125px";
	} else if (sel == "22") {
		// crime
		document.getElementById("findTabAdvanced:formpg:PCMTYPE").style.width = "360px";
		document.getElementById("findTabAdvanced:formpg:HCOST1").style.width = "360px";

		document.getElementById("findTabAdvanced:formpg:PCMLabel").style.width = "70px";
		document.getElementById("findTabAdvanced:formpg:settingLabel").style.width = "70px";
		document.getElementById("findTabAdvanced:formpg:PCMTYPELabel").style.width = "113px";
		document.getElementById("findTabAdvanced:formpg:HCOST1Label").style.width = "113px";
	} else {
		document.getElementById("findTabAdvanced:formpg:HCOST1").style.width = "auto";
		document.getElementById("findTabAdvanced:formpg:XXX").style.width = "auto";
		document.getElementById("findTabAdvanced:formpg:setting").style.width = "auto";
		document.getElementById("findTabAdvanced:formpg:PCM").style.width = "370px";
		document.getElementById("findTabAdvanced:formpg:HCOST1Label").style.width = "auto";
		document.getElementById("findTabAdvanced:formpg:settingLabel").style.width = "auto";
		document.getElementById("findTabAdvanced:formpg:XXXSIZELabel").style.width = "auto";
	}

	// when the page is first loaded, set the state of the checkboxes
	// from the session cookie
	setCheckboxStatus();
}


/* Close the help popup */
function closeHelp()
{
	document.getElementById("glossaryBox").style.display="none";
}

/* Set the CSS cursor style */
function setCursor(obj, cursor)
{
	if (obj && obj.style)
		obj.style.cursor = cursor;
}

/* Set the value of an input field to empty string */


function clearInputDefault(obj)
{
	var dflt = obj.defaultValue;
	if (obj.value == dflt)
		obj.value = "";
}

function resetInputDefault(obj)
{
	var dflt = obj.defaultValue;
	if (obj.value == "")
		obj.value = dflt;
}

/* Restore the default values of the LEARN and MATCH input fields */
function resetInputs()
{
	document.getElementById("learn:adr").value = "optional";
	document.getElementById("learn:csz").value = "required";

	document.getElementById("matchTab:match:matchAdr").value = "required";
	document.getElementById("matchTab:match:matchCsz").value = "required";
}

/* Functions to alternate between sign out and subscribe now */
function showSignOut() {
	document.getElementById("subscribeLinkLearn").style.display = "none";
	document.getElementById("signOutLinkLearn").style.display = "inline";
	
	document.getElementById("subscribeLinkFind").style.display = "none";
	document.getElementById("signOutLinkFind").style.display = "inline";
	
	document.getElementById("subscribeLinkMatch").style.display = "none";
	document.getElementById("signOutLinkMatch").style.display = "inline";
}

function showSubscribeNow() {
	document.getElementById("subscribeLinkLearn").style.display = "inline";
	document.getElementById("signOutLinkLearn").style.display = "none";
	
	document.getElementById("subscribeLinkFind").style.display = "inline";
	document.getElementById("signOutLinkFind").style.display = "none";
	
	document.getElementById("subscribeLinkMatch").style.display = "inline";
	document.getElementById("signOutLinkMatch").style.display = "none";
	
}

/* Functions to show and hide the sign-in popup */
function showSignIn(id) {
	if(document.getElementById(id).innerHTML.indexOf("Welcome") != -1) {
		window.location = "/servlet/membersServlet";
	} else {
//		var x = getOffset(document.getElementById(id),"x");
		var y = getOffset(document.getElementById(id),"y");
//		var xOff = -150;
		var yOff = 22;
		var obj = document.getElementById("signInBox");
//the following iframe is empty.  this is simply to fix an issue in IE 6 with the select dropdown showing thru the sign in box are in the match tab:
		var obj2 = document.getElementById("signInBoxIframe"); 
		obj.style.top = y + yOff + "px";
		obj2.style.top = y + yOff + "px";
//		obj.style.left = x + xOff + "px";
//hard-coded the x dimension to keep box from changing position based on window width:
		obj.style.left = "718px";
		obj2.style.left = "718px";
		obj.style.display="block";
		obj2.style.display="block";
	}
}

function hideSignIn() {
	document.getElementById("signInBox").style.display="none";
	document.getElementById("signInBoxIframe").style.display="none";
}

function emailPage(page) {
	if (page) {
		dest = page;
	} else {
		dest = window.location.href;
	}
	window.open('/email-page/?t='+escape(document.title)+
	'&u='+escape(dest),'','width=700,height=700,resizable');
}

function setMatchRadius() {
	var mc = document.getElementById('matchTab:match:matchCity');
	var mr = document.getElementById('matchTab:match:matchRadius');

	if (mc.value=='select0' || mc.value=='select1' ) {
		mr.value=0;
		mr.disabled=true;
	} else {
		mr.disabled=false;
		if (mr.value == 0)
			mr.selectedIndex=5; //5 miles
	}
}

function setFindRadius() {
	var fc=document.getElementById('findTabAdvanced:formpg:findCity');
	var fr=document.getElementById('findTabAdvanced:formpg:findRadius');

	if (fc.value=='select0' || fc.value=='select1') {
		fr.value=0;
		fr.disabled=true;
	} else {
		fr.disabled=false;
		if (fr.value == 0)
			fr.selectedIndex=5; //5 miles
	}
}

function checkRadius(type) {
	var fr = document.getElementById('findTabAdvanced:formpg:findRadius').value == 0;
	var fc = document.getElementById('findTabAdvanced:formpg:findCity').value; 
	var fs = document.getElementById('findTabAdvanced:formpg:findState').value;
	var fm = document.getElementById('findTabAdvanced:formpg:findMenu').value == 0;

	var mr = document.getElementById('matchTab:match:matchRadius').value == 0;
	var mc = document.getElementById('matchTab:match:matchCity').value;	
	var ms = document.getElementById('matchTab:match:matchState').value;	

	if ((type=="find" && fs != "A2" && !(fc == "select0" || fc == "select1") && fr) ||
		(type=="match" && ms != "A2" && !(mc == "select0" || mc == "select1") && mr)) {
		alert ("Please choose a radius when searching around a city.");
		return false;	
	} else if(type == "find" && fm) {
		alert ("What type of neighborhood search would you like to do? (Please select from the drop down menu)");
		return false;
	} else if((type == "find" && ((fc == "select0" && fs != "A2") || fs == "A1")) ||
		(type == "match" && ((mc == "select0" && ms != "A2") || ms == "A1"))) {
		alert ("Where do you want to search? (Please select your search area from the drop down menus");
		return false;
	} else {
		showScouting();
		return true;
	}
}


/* Utility function to get X and Y offsets of an element */
function getOffset(obj,d) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	if (d == "x")
		return curleft;
	else if (d == "y")
		return curtop;
}


/* Initialize the event handlers for the LEARN, FIND, and MATCH tabs */
function initTabs()
{
	// These are the hyperlinks that fire the click event
	var links = new Array (document.getElementById("_idJsp9"), document.getElementById("_idJsp12"), document.getElementById("_idJsp15"));

	// These are the DIVs that are the actual tabs
	var tabs = new Array (document.getElementById("tab1"), document.getElementById("tab2"), document.getElementById("tab3"));

	for (var i = 0; i < links.length; i++)
	{
		if (links[i] == null) continue;
		if (links[i].parentNode.className.indexOf("active") != -1)
			tabs[i].style.display = "block";
		else
			tabs[i].style.display = "none";
	}
/*
	for (var i = 0; i < links.length; i++)
	{
		links[i].onclick = function ()
		{
			resetInputs();

			for (var j = 0; j < links.length; j++)
			{
				if (this == links[j])
				{
					links[j].parentNode.className = "active";
					tabs[j].style.display = "block";
				}
				else
				{
					links[j].parentNode.className = "";
					tabs[j].style.display = "none";
				}
			}

			return false;
		}
	}
*/
}


function tabClick(lnk)
{
	// These are the hyperlinks that fire the click event
	var links = new Array (document.getElementById("_idJsp9"), document.getElementById("_idJsp12"), document.getElementById("_idJsp15"));

	// These are the DIVs that are the actual tabs
	var tabs = new Array (document.getElementById("tab1"), document.getElementById("tab2"), document.getElementById("tab3"));

	for (var i = 0; i < links.length; i++)
	{
		if (links[i].parentNode.className.indexOf("active") != -1)
			tabs[i].style.display = "block";
		else
			tabs[i].style.display = "none";
	}

//	resetInputs();

	for (var j = 0; j < links.length; j++)
	{
		if (document.getElementById(lnk) == links[j])
		{
			links[j].parentNode.className = "active";
			tabs[j].style.display = "block";
		}
		else
		{
			links[j].parentNode.className = "";
			tabs[j].style.display = "none";
		}
	}

}

function setChbxState(id) {
	var chbx = document.getElementById(id);
	document.cookie = id+"="+chbx.checked+"; path=/";
}

function setCheckboxStatus() {
	var chbxs = ["findTabAdvanced:formpg:walkable","findTabAdvanced:formpg:coastal",
		"findTabAdvanced:formpg:quiet"];

	for (var i = 0; i < chbxs.length; i++) {
		document.getElementById(chbxs[i]).checked = readCookie(chbxs[i]);
	}

	function readCookie(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 && c.substring(nameEQ.length,c.length) == 'true') return true;
		}
		return false;
	}
}

function checkExclude(obj)
{
	var sel = document.getElementById("findTabAdvanced:formpg:findMenu").value.toString();
	if (sel == "9" || sel == "14")
	{
		if (obj == document.getElementById("findTabAdvanced:formpg:medianHouseValue"))
			document.getElementById("findTabAdvanced:formpg:averageRentalPrice").selectedIndex = 0;
		else if (obj == document.getElementById("findTabAdvanced:formpg:averageRentalPrice"))
			document.getElementById("findTabAdvanced:formpg:medianHouseValue").selectedIndex = 0;
	}
}

function showScouting() {
	var h=document.documentElement.clientHeight;
	var w=document.documentElement.clientWidth;
	var scoutingSize=237;

	if (navigator.userAgent.indexOf("MSIE 6.0") != -1) {
		var n = document.getElementById("tab1").getElementsByTagName("input");
		for (var i = 0; i < n.length; i++) {
			n[i].style.visibility = "hidden";
		}
		
		o = document.getElementById("tab2").getElementsByTagName("select"), document.getElementById("tab2").getElementsByTagName("input");
		for (var i = 0; i < o.length; i++) {
			if (o[i].style)
			o[i].style.visibility = "hidden";
		}
		
		p = document.getElementById("tab3").getElementsByTagName("select"), document.getElementById("tab3").getElementsByTagName("input");
		for (var i = 0; i < p.length; i++) {
			if (p[i].style)
			p[i].style.visibility = "hidden";
		}
	}

	document.getElementById("scouting").style.left=(w-scoutingSize)/2+"px";
	document.getElementById("scouting").style.top=(h-scoutingSize)/2+"px";
	document.getElementById("scouting").style.display="block";
	document.getElementById("greyOut").style.width=w+"px";
	document.getElementById("greyOut").style.display="block";

	if (document.getElementById("front-page-movie")) {
		document.getElementById("front-page-movie").style.display="none";
	} else if (document.getElementById("flash1")) {
		document.getElementById("flash1").style.display="none";
	} else if (document.getElementsByTagName("embed").length > 0) {
		for (var i = 0;i < document.getElementsByTagName("embed").length;i++) {
			document.getElementsByTagName("embed")[i].style.display="none";
		}

	}
}

function hideScouting() {
	if (document.getElementById("scouting") == null) return;
	document.getElementById("scouting").style.display="none";
	document.getElementById("greyOut").style.display="none";

	if (document.getElementById("front-page-movie")) {
		document.getElementById("front-page-movie").style.display="block";
	} else if (document.getElementById("flash1")) {
		document.getElementById("flash1").style.display="block";
	} else if (document.getElementsByTagName("embed").length > 0) {
		for (var i = 0;i < document.getElementsByTagName("embed").length;i++) {
			document.getElementsByTagName("embed")[i].style.display="block";
		}
	}
}

function closeErrBox() 
{
	document.getElementById("errBox").style.display="none";
}

function pingServer()
{
	document.getElementById("periodicPingForm:periodicPingButton").click();
}

/* Event initialzation for the page... fired after window.onload */
function initBlueModule()
{

	initTabs();

	if (document.getElementById('findTabAdvanced:formpg:lifeHelp'))
	{
		addEvent(document.getElementById('findTabAdvanced:formpg:lifeHelp'), "click", displayHelp, false);

		addEvent(document.getElementById('findTabAdvanced:formpg:lifeHelp'), "mouseover",
			function() {setCursor(document.getElementById('findTabAdvanced:formpg:lifeHelp'), "pointer");}, false);

		addEvent(document.getElementById('findTabAdvanced:formpg:lifeHelp'), "mouseout",
			function() {setCursor(document.getElementById('findTabAdvanced:formpg:lifeHelp'), "default");}, false);
	}

	if (document.getElementById('findTabAdvanced:formpg:RCOST1a'))
	{
		addEvent(document.getElementById('findTabAdvanced:formpg:RCOST1a'), "change",
			function() { document.getElementById('findTabAdvanced:formpg:HCOST1a').selectedIndex=0 }, false);
	}

	if (document.getElementById('findTabAdvanced:formpg:HCOST1a'))
	{
		addEvent(document.getElementById('findTabAdvanced:formpg:HCOST1a'), "change",
			function() { document.getElementById('findTabAdvanced:formpg:RCOST1a').selectedIndex=0 }, false);
	}

	if (document.getElementById('findTabAdvanced:formpg:advancedHelp'))
	{
		document.getElementById('findTabAdvanced:formpg:advancedHelp').onclick = function (e) { displayHelpAdvanced(e) }

		addEvent(document.getElementById('findTabAdvanced:formpg:advancedHelp'), "mouseover",
			function() {setCursor(document.getElementById('findTabAdvanced:formpg:advancedHelp'), "pointer");}, false);

		addEvent(document.getElementById('findTabAdvanced:formpg:advancedHelp'), "mouseout",
			function() {setCursor(document.getElementById('findTabAdvanced:formpg:advancedHelp'), "default");}, false);
	}

	if (document.getElementById('findTabAdvanced:formpg:walkable')) {
		addEvent(document.getElementById('findTabAdvanced:formpg:walkable'), "click",
			function() { setChbxState("findTabAdvanced:formpg:walkable"); }, false);
	}

	if (document.getElementById('findTabAdvanced:formpg:coastal')) {
		addEvent(document.getElementById('findTabAdvanced:formpg:coastal'), "click",
			function() { setChbxState("findTabAdvanced:formpg:coastal"); }, false);
	}

	if (document.getElementById('findTabAdvanced:formpg:quiet')) {
		addEvent(document.getElementById('findTabAdvanced:formpg:quiet'), "click",
			function() { setChbxState("findTabAdvanced:formpg:quiet"); }, false);
	}

	if (document.getElementById("errClose"))
	{
		addEvent(document.getElementById('errClose'), "click",
			function() { document.getElementById("errBox").style.display='none';return false }, false);
	}

	if (document.getElementById("findTabAdvanced:formpg:findCity"))
	{
		var fc=document.getElementById("findTabAdvanced:formpg:findCity");
		var fs=document.getElementById("findTabAdvanced:formpg:findState");
		var fr=document.getElementById('findTabAdvanced:formpg:findRadius');
		if (fc.options[0].selected || (fc.options[1] && fc.options[1].selected && fc.options[1].text == "statewide search") ||
			(fs.options[1] && fs.options[1].selected && fs.options[1].text == "nationwide search"))
		{
			fr.selectedIndex = 0;
			fr.disabled=true;
		}
	}

	if (document.getElementById("matchTab:match:matchCity"))
	{
		var mc=document.getElementById("matchTab:match:matchCity");
		var ms=document.getElementById("matchTab:match:matchState");
		var mr=document.getElementById("matchTab:match:matchRadius");

		if (mc.options[0].selected || (mc.options[1] && mc.options[1].selected &&	mc.options[1].text == "statewide search") ||
			(ms.options[1] && ms.options[1].selected &&	ms.options[1].text == "nationwide search"))
		{
			mr.selectedIndex = 0;
			mr.disabled=true;
		}
	}

	addEvent(document.getElementById("matchTab:match:matchState"), "change", disableMatchRadius, false);
	addEvent(document.getElementById("findTabAdvanced:formpg:findState"), "change", disableFindRadius, false);

	if (document.getElementById("temp:temp-command"))
		addEvent(document.getElementById("temp:temp-command"), "click", closeErrBox, false);
		
  	if (document.getElementById("findTabAdvanced:formpg:findRadius")) {
		for (var i=0; i < document.getElementById("findTabAdvanced:formpg:findRadius").options.length; i++) {
			if (document.getElementById("findTabAdvanced:formpg:findRadius").options[i].selected == true) {
				document.getElementById("findTabAdvanced:formpg:findRadius").options[i].selected = true;
			}
		}
  	}	
	
}



/* Enables top 10 nav mouseover effect for IE 6 */
function initTop10Nav()
{
	if (navigator.userAgent.indexOf("MSIE 6") != -1) {

		var nav = document.getElementById("top10Nav");
		if (nav)
		{
			var nodes = nav.getElementsByTagName("td");
			for (var i = 0; i < nodes.length; i++)
			{
				nodes[i].onmouseover = function ()
				{
					if (this.className == "one")
					{
						this.style.cursor="pointer";
						this.style.backgroundColor = "#E5E5BA";
						this.style.color = "#555";
						this.nextSibling.style.backgroundColor = "#ffc";
						if (this.nextSibling.nextSibling)
							this.nextSibling.nextSibling.style.backgroundColor = "#ffc";
					}
					else if (this.className == "two")
					{
						this.style.cursor="pointer";
						this.previousSibling.style.backgroundColor = "#E5E5BA";
						this.previousSibling.style.color = "#555";
						this.style.backgroundColor = "#ffc";
						if (this.nextSibling)
							this.nextSibling.style.backgroundColor = "#ffc";
					}
					else if (this.className == "three")
					{
						this.style.cursor="pointer";
						this.previousSibling.previousSibling.style.backgroundColor = "#E5E5BA";
						this.previousSibling.previousSibling.style.color = "#555";
						this.previousSibling.style.backgroundColor = "#ffc";
						this.style.backgroundColor = "#ffc";
					}
				}

				nodes[i].onmouseout = function ()
				{
					if (this.className == "one")
					{
						document.body.style.cursor="default";
						this.style.backgroundColor = "#7c7c7c";
						this.style.color = "#CBCBCB";
						this.nextSibling.style.backgroundColor = "#dadada";
						if (this.nextSibling.nextSibling)
							this.nextSibling.nextSibling.style.backgroundColor = "#dadada";
					}
					else if (this.className == "two")
					{
						document.body.style.cursor="default";
						this.previousSibling.style.backgroundColor = "#7c7c7c";
						this.previousSibling.style.color = "#CBCBCB";
						this.style.backgroundColor = "#dadada";
						if (this.nextSibling)
							this.nextSibling.style.backgroundColor = "#dadada";
					}
					else if (this.className == "three")
					{
						document.body.style.cursor="default";
						this.previousSibling.previousSibling.style.backgroundColor = "#7c7c7c";
						this.previousSibling.previousSibling.style.color = "#CBCBCB";
						this.previousSibling.style.backgroundColor = "#dadada";
						this.style.backgroundColor = "#dadada";
					}
				}
			}
		}
	}
}


function makeBar()
{
	return createBar(160,15,'white',1,'white','#9fbd58',85,5,3,"");
}


function disableMatchRadius()
{
	document.getElementById("matchTab:match:matchRadius").selectedIndex=0;
	document.getElementById("matchTab:match:matchRadius").disabled=true;
}

function disableFindRadius()
{
	document.getElementById("findTabAdvanced:formpg:findRadius").selectedIndex=0;
	document.getElementById("findTabAdvanced:formpg:findRadius").disabled=true;
}


/* initialization */
function hideErrBox() {

}

// === Browser Dection Script (use sparingly!) ===============================================================================

/*
Browser Detect Script
from http://www.quirksmode.org/js/detect.html

Reference: 
Browser name: BrowserDetect.browser 
Browser version: BrowserDetect.version 
OS name: BrowserDetect.OS 
*/
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


// === Tabs ==========================================================================================================

function tabSwitch(obj) {
	var tab = obj.parentNode.id;
	var content = tab.replace("tab-","content-"); //set the name of the content div, which should always follow this naming pattern
	
	tabsOff("tab-block"); //change all tabs to disabled class
	tabContentOff("tab-content"); //hide all content under the tabs

	if (typeof(pageTracker) != "undefined") { //don't fire this if pageTracker doesn't exist (the user clicked on the link before the google analytics library loaded)
		pageTracker._trackPageview('/location-data/' + tab.replace('tab-','') + '/tab'); //for google analytics 
	}

	//if popups exist on this page (from the map) make sure to hide them on tab click
	if (document.getElementById("closePopUP")) {
		hidePopup("mapPopUP");
	}
	if (document.getElementById("nhoodclosePopUP")) {
		hidePopup("nhoodmapPopUP");
	}
	
	//select the tab to display
//new and improved! simplified version:
	tabOn(tab);
	if (document.getElementById(content)) document.getElementById(content).style.display="block";


if (tab == "tab-map") {
	//this is to resolve an issue (specifically in IE) with the map looking screwed up when going from display: none to display: block
	map.checkResize();
}
	
//old:
/*
	switch (tab) {
		case "tab-overview":
			tabOn("tab-overview");
			if (document.getElementById("overview-content")) document.getElementById("overview-content").style.display="block";
			break;
		case "tab-schools":
			tabOn("tab-schools");
			if (document.getElementById("schools-content")) document.getElementById("schools-content").style.display="block";
			break;
		case "tab-crime":
			tabOn("tab-crime");
			if (document.getElementById("crime-content")) document.getElementById("crime-content").style.display="block";
			break;
		case "tab-appr":
			tabOn("tab-appr");
			if (document.getElementById("appr-content")) document.getElementById("appr-content").style.display="block";
			break;
		case "tab-data":
			tabOn("tab-data");
			if (document.getElementById("data-content")) document.getElementById("data-content").style.display="block";
			break;
		case "tab-realtor":
			tabOn("tab-realtor");
			if (document.getElementById("realtor-content")) document.getElementById("realtor-content").style.display="block";
			break;
		default: //description tab is available on all pages, so it's the default
			tabOn("tab-desc");
			if (document.getElementById("desc-content")) document.getElementById("desc-content").style.display="block";
	}
*/
}


function tabOn(selectedTab) {
	//display tab by changing class to 'active'
	var theNode = document.getElementById(selectedTab);
	theNode.className = "active";
}


function tabContentOff(idName) {
	//loop through 'tabContent' childnodes and hide each one
	var childNodeArray = (document.getElementById(idName).childNodes);
	for (var i = 0; i < childNodeArray.length; i++){
		if (childNodeArray[i].nodeType == 1) { //check for text node
			childNodeArray[i].style.display="none";
		}
	}
}

function tabsOff(idName) 
{
	//loop through 'tabBlock' childnodes and remove class
	var childNodeArray = (document.getElementById(idName).childNodes);
	for (var i = 0; i < childNodeArray.length; i++){
		if (childNodeArray[i].nodeType == 1) { //check for text node
			childNodeArray[i].className = "";
		}
	}
}		



// === Rounded Corners ================================================================================================

/* 
The following adds several additional divs to any element labeled with the class "rounded"
This allows us to add rounded corners to the site without lots of extraneous markup in the content/XHTML for each corner image
This will work on all modern browsers, and will degrade to a simple square box on older browsers or people with js disabled.
*/

function applyRoundedCorners() {
	roundedCorners('box-effect');
	roundedCorners('header-effect');
}

function clearInnerHTML(obj) {
	// so long as obj has children, remove them
	while(obj.firstChild) obj.removeChild(obj.firstChild);
}


function roundedCorners(theClassName) {
	var arrRoundedElements = getElementsByClassName(document, 'div', theClassName); //place all instances of the rounded class into an array
	for (var i = 0; i < arrRoundedElements.length; i++) { //loop through array from above

		var original = arrRoundedElements[i];

		var cornerClasses = ['rounded-content','rounded-top','rounded-right', 'rounded-left','rounded-topLeft','rounded-topRight','rounded-bottom','rounded-bottomRight','rounded-bottomLeft']; //class names of all the divs we're attaching

		var totalDivs = cornerClasses.length - 1;

		if (theClassName == 'header-effect'){
			totalDivs = totalDivs - 3; //if this is a 'tab' leave off the last 3 divs (creates a square bottom of box)
		}

		//NOTE: myDiv* is a dynamically created varible, which is why it's needs to be a property of the window object
		window["myDiv0"] = document.createElement('div'); //create outer div
		window["myDiv0"].className = original.className.replace(theClassName, 'rounded-js'); //rename the original class to rounded-js, still carrying over all the other class names
		original.parentNode.replaceChild(window["myDiv0"], original); // swap out the original content with our new outer most div
		original.className = cornerClasses[0]; //change the name of the original classname to whats assigned to 0, aka rounded-content from cornerClasses 
		
		//create nodes
		var currentNode = 0; //node we are currently working with, starts with the one we created above
		for (var j = 1; j <= totalDivs; j++) {
			window["myDiv" + j] = document.createElement('div'); //generate div and assign it to a variable named myDiv#
			window["myDiv" + j].className = cornerClasses[j]; //give that a class name
			window["myDiv" + currentNode].appendChild(window["myDiv" + j]); //append new div to currentNode
			currentNode++;
		}

		window["myDiv" + totalDivs].appendChild(original); //finally, insert the original content into the last div we created
	}
}


// === Popup ==========================================================================================================

function popupClickEvent(event) {
	window.open(this.href,'','width=600,height=500,scrollbars,resizable');
	event.preventDefault ? event.preventDefault() : event.returnValue = false; //cancel click action
}

function applyPopups() {
	var aryPopups = getElementsByClassName(document, 'a', 'popup'); //place all instances of the class into an array
	for (var i = 0; i < aryPopups.length; i++) { // now add an event to each of the elements we have found
		addEvent(aryPopups[i], "click", popupClickEvent, false);
	}
}


// === Auto Select Tab ================================================================================================

//function to parse thru a query string
function getQueryValue(ji) {
	hu = window.location.search.substring(1);
	gy = hu.split("&");
	for (i=0;i<gy.length;i++) {
		ft = gy[i].split("=");
		if (ft[0] == ji) {
			return ft[1];
		}
	}
}

//executes immediately:
var anchorValue = location.hash.substring(1); //grab everything after pound symbol
var selectTab;

if (anchorValue) { //check that there's an anchor
	//Check for "goto-" at the beginning of the anchor tag, if found, we want to use this to open a tab.
	//This was added so we can open a tab, without jumping down to the anchor (which is the name of the tab).
	//We didn't want to use a URL query parameter, so this is the alternative. (example: #goto-tab-crime)
	if (anchorValue.indexOf("goto-") == 0) { //check for goto- in the first part of the string
		anchorValue = anchorValue.replace("goto-","");
	}
	//check against allowed tabs names
	if (anchorValue == 'tab-map' || anchorValue == 'tab-overview' || anchorValue == 'tab-schools' || anchorValue == 'tab-appr' || anchorValue == 'tab-crime' || anchorValue == 'tab-desc' || anchorValue == 'tab-realtor') {
		selectTab = anchorValue;
	}
}

//called on page load:
function autoSelectTab() {
	if ((selectTab) && document.getElementById(selectTab)) {
		tabSwitch(document.getElementById(selectTab).firstChild);
	}
}

// === Global Functions ===============================================================================================

/*
addEvent and removeEvent elimate the differences betweens browsers when attaching
and removing events.  The following addEvent function also allows us to use 'this'
in IE in the functions that are called via event attaching.
*/

function addEvent( obj, type, fn )
{
	if (obj == null) return;
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn )
{
	if (obj.removeEventListener)
		obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent)
	{
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}

//retreives all classes with a certain name and places them in an array:
function getElementsByClassName(oElm, strTagName, strClassName) {
	if(!oElm.getElementsByTagName) {return false; } //check for exisitence of getElementsByTagName
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
			oElement = arrElements[i];
			if(oRegExp.test(oElement.className)){
				arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

// === Init Page ======================================================================================================

//function that fires all the onload functions in one place

function initPage() {
	if (typeof(map) != "undefined") {
		//This checks to see if the map object exists, and if it does, we are on a page that is also loading the gmap.js file.
		//We need to initialize the map here rather than in gmap.js so that everything get's loaded in the correct order.
		initMaps();
	}
	applyRoundedCorners();
	applyPopups();
	initBlueModule();
	//autoSlectTab(); //moved to initMaps(); cause we need to wait until the map is completely loaded before switching tabs
}

// === Load/Unload Events =============================================================================================

addEvent(window, "load", initPage, false);
/*
moved to single function:
addEvent(window, "load", applyRoundedCorners, false); //adds rounded corner style to all 'rounded' classes
addEvent(window, "load", applyPopups, false); //adds a popup click event to all 'popup' classes
addEvent(window, "load", initBlueModule, false);
addEvent(window, "load", autoSlectTab, false); //select tab on a page if they have selectTab defined
*/
addEvent(window, "unload", hideErrBox, false);
addEvent(window, "unload", hideScouting, false);




