// Declare map!
try {
	ETMap = new mapAttributeSet();
	ETMap.mapDiv = "map1";
	ETMap.mapPointsLat = "mapPointsLat";
	ETMap.mapPointsLon = "mapPointsLon";
	ETMap.mapLabelTitle = "mapTitles";
	ETMap.mapLabelText = "mapLabels";
	ETMap.mapLegend = "mapMarkers";
} catch(e) {
	// No maps on this page.  Do nothing.
}

function ToggleVisibility(WhichForm) {
	// Declare for use later
        var TheFormDiv;
	// e.g. "events box", "music box"
        var DynamicClass = WhichForm.toLowerCase() + " box";
	// Each tab in the search box thing
        var AllTheForms = new Array("Food","Music","Events","Movies","Free");
	// Loop through all of them until we find a match
        for(var i = 0; i < AllTheForms.length; i++) {
		// This is the div we want to make visible
                 TheFormDiv = "SearchFormContent" + AllTheForms[i];
		// Match; show div, assign css class
                if(AllTheForms[i].toLowerCase() == WhichForm.toLowerCase()) {
                        document.getElementById('DynamicDiv').className = DynamicClass;
                        document.getElementById(TheFormDiv).style.visibility = 'visible';
                        document.getElementById(TheFormDiv).style.display = 'block';
		// No match; hide div
                } else {
                        document.getElementById(TheFormDiv).style.visibility = 'hidden';
                        document.getElementById(TheFormDiv).style.display = 'none';
                }
        }
}

function TransformForm(WhichForm) {
        if(!WhichForm) { WhichForm = "Free"; }
	// Change image mapped img src.  Take out "temp_" when adding Nightlife search back.
        TheImg = "/images/etweb/events_tabs_" + WhichForm.toLowerCase() + ".gif";
        document.images['SearchFormTabs'].src = TheImg;
	// Show appropriate div, hide all others, assign css class
        ToggleVisibility(WhichForm);
}

function ETClearValue(x) {
	if(x.value == "Name" || x.value == "Nightlife (bars/nightclubs)" || x.value == "Title") {
		x.value='';
	}
}

function in_array(needle,haystack) {
	function equals(a,b) {
		return (a == b);
	}
	for (var i = 0; i < haystack.length; i++) {
		if (equals(haystack[i],needle)) {
			return true;
		}
	}
	return false;
}

function SetFormAction(WhichForm) {
	var music = [56];
	var foodday = new Array(79,104,105,103);
	var wine = [114];
	var art = new Array(85,96,97);
	var books = new Array(75,107,108,225,109);
	var performance = new Array(54,122,69,123,124,168,152,153,176,177,178);
	var entertainment = [121];
	var hg = new Array(80,119,120,182);
	var travel = [93];
	var living = new Array(161,162,163,164,165,125,112,183,184,185,186);
	var kiddo = new Array(163,168,169);
	var pets = [110];
	var health = new Array(48,116,117,118,179);
	var outdoors = new Array(74,154,156,147,148,149,150,160);
	var business = [171];
	var events = new Array(76,98,99,151,100,111,101,180,181);


	var TheCategory = WhichForm.SearchCategory.value;

        if(in_array(TheCategory,music)) {
                WhichForm.action = "/music/index.ssf";
        } else if(in_array(TheCategory,foodday)) {
                WhichForm.action = "/foodday/index.ssf";
        } else if(in_array(TheCategory,wine)) {
                WhichForm.action = "/wine/index.ssf";
		} else if(in_array(TheCategory,art)) {
				WhichForm.action = "/art/index.ssf";
		} else if(in_array(TheCategory,books)) {
				WhichForm.action = "/books/index.ssf";
		} else if(in_array(TheCategory,performance)) {
				WhichForm.action = "/performance/index.ssf";
		} else if(in_array(TheCategory,hg)) {
				WhichForm.action = "/hg/index.ssf";
		} else if(in_array(TheCategory,travel)) {
				WhichForm.action = "/travel/index.ssf";
		} else if(in_array(TheCategory,living)) {
				WhichForm.action = "/living/index.ssf";
		} else if(in_array(TheCategory,kiddo)) {
				WhichForm.action = "/kiddo/index.ssf";
		} else if(in_array(TheCategory,pets)) {
				WhichForm.action = "/pets/index.ssf";
		} else if(in_array(TheCategory,health)) {
				WhichForm.action = "/health/index.ssf";
		} else if(in_array(TheCategory,outdoors)) {
				WhichForm.action = "/outdoors/index.ssf";
		} else if(in_array(TheCategory,business)) {
				WhichForm.action = "/business/index.ssf";
		} else if(in_array(TheCategory,events)) {
				WhichForm.action = "/events/index.ssf";
        } else {
                WhichForm.action = "/events/index.ssf";
        }
}

function MatchDates(TheForm,ThisIndex) {
	if(ThisIndex == 0) { ThisIndex = 1; }
	TheForm.SearchDateEnd.options[ThisIndex-1].selected = true;
}
