/**
 *	Search class
 *	@author	Daniel Hong
 *	@copy	February 2008
 */
var QuickSearch = {
	
	DropDownSearch	: null,
	IndustryField	: null,
	IndustryValue	: null,
	SearchField		: null,
	
	//	Prepares the form with event handlers
	Prepare : function() {
		var Links;
		this.DropDownSearch = document.getElementById("dropDownSearch").getElementsByTagName("ul")[0].getElementsByTagName("ul")[0];
		this.IndustryField = document.getElementById("industry_field");
		this.IndustryValue = document.getElementById("industry_value");
		this.SearchField = document.getElementById("srch_fld");				
		Links = this.DropDownSearch.getElementsByTagName("a");
		
		// set dynamic events
		this.DropDownSearch.onmouseover = new Function("QuickSearch.ShowIndustry(1);");
		this.DropDownSearch.onmouseout = new Function("QuickSearch.ShowIndustry(0);");
		
		for(i=0; i<Links.length; i++) {
			Links[i].onclick = new Function("return QuickSearch.SetIndustry(this);");
		}
	},
			
	//	Set the industry to the hidden form field
	SetIndustry : function(AObj) {
		var SearchIndustry = document.getElementById("search_industry");
		var Industry = AObj.innerHTML;
		
		this.IndustryField.value = Industry;
		SearchIndustry.innerHTML = Industry;
		
		// this.IndustryValue.value = AObj.value;
		this.IndustryValue.value = AObj.getAttribute('value');
		
		this.DropDownSearch.style.cssText = "left:-999em;";
		
		return false;
	},
	
	//	Shows the industry list
	ShowIndustry : function(MakeVisible, AObj) {
		if (AObj) { AObj.blur(); }
		
		this.DropDownSearch.style.cssText = (MakeVisible) ? "left:auto;" : "left:-999em;";
		
		return false;
	},
	
	/**
	 *	A very simple JavaScript validation
	 *	Important: data should still be validated server side
	 */
	Validate : function() {
		if (this.IndustryField.value == "" || 
			(this.SearchField.value == "" || 
			 this.SearchField.value == "City, State or Zip")) {
			return false;
		}
		else {
			//alert(this.IndustryField.value);
			//alert(this.SearchField.value);
			return true;
		}
	}
}

function searchClick()
{
    if (!QuickSearch.Validate())
    {
        alert("Industry and City, State or Zip must be entered.");
        return false;
    }
    return true;
}

function ShowSection(skinPath, BtnObj, BoxNum, Jump) {
	if (BtnObj.src.indexOf("plus") > 0) {
		BtnObj.src = skinPath + "images/btn-minus-blk.jpg";
	}
	else {
		BtnObj.src = skinPath + "images/btn-plus-blk.jpg";
	}
	
	var BoxID = "sub_box_" + BoxNum;
	if (document.getElementById(BoxID)) {
		var SubBox = document.getElementById(BoxID);
		
		if (SubBox.style.display == "none") {
			SubBox.style.display = "block";
		}
		else {
			if (Jump == null) {
				SubBox.style.display = "none";
			}
		}
	}
	
	return false;
}
