// JavaScript Document

// these are suckerfish dropdown functions - google it
sfHover = function() {
	sfTemplate("menu");
}
sfHover2 = function() {
	sfTemplate("menujr");
}
function sfTemplate(menuname) {
	if (!document.getElementById(menuname)) return;
	var sfEls = document.getElementById(menuname).getElementsByTagName("li");
	for (var i = 0; i < sfEls.length; i++) {
		if (sfEls[i].id == "search") continue;
		sfEls[i].onmouseover = function() {
			this.className += " sfhover";
		}
		sfEls[i].onmouseout = function() {
			this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) { // only supported by IE and only needed by IE!!!!! SERENDIPITY
	window.attachEvent("onload", sfHover);
	//window.attachEvent("onload", sfHover2);
}

// this is for image submit button, because it turns out that image input type is not really meant for this
function searchgo(evt) {
	document.getElementById("sform").submit();
	if (evt) {
		if (typeof evt.preventDefault != 'undefined') evt.preventDefault();
		else evt.returnValue = false;
	} 
	return false;
}

// this is to make the stylish dropdown box
window.onload = function() {
    searchboxinit(); $(document).ready(function() {
        $('#locationselect').sSelect({ ddMaxHeight: '300px' });
    });
};

// these make "Search" appear in light gray in the quick search box unless user is typing in it
var sbox;
function searchboxinit() {
	if (document.getElementById && document.getElementsByTagName) {
		var div = document.getElementById("search");
		if (!div) return;
		var inputs = div.getElementsByTagName("input");
		sbox = inputs[0];
		sbox.onblur = function() { searchboxout(); };
		sbox.onfocus = function() { searchboxin(); };
		if (document.activeElement != sbox) searchboxout();
	}
}
function searchboxout() {
	if (sbox.value == "" || sbox.value == "Search") {
		sbox.style.color = "#b8b8ae";
		sbox.value = "Search";
	}
}
function searchboxin() {
	if (sbox.value == "Search") {
		sbox.style.color = "#000";
		sbox.value = "";
	}
}

// this is for flyout divs like in corp real estate FAQs
function toggle(id) {
	var div = document.getElementById(id);
	if (!div) return;
	if (div.style.display == "block")
		div.style.display = "none";
	else
		div.style.display = "block";
}
