// JavaScript Document


// ***********************************************************************************************************
// Report Errors    ******************************************************************************************
// ***********************************************************************************************************

//function reportError(msg, url, line) {
//	alert("Error: " + msg + "\nUrl: " + url + "\nLine: " + line);
//	return true;
//	}
//window.onerror = reportError;



// ***********************************************************************************************************
// Array of Trade Objects    *********************************************************************************
// ***********************************************************************************************************

var tradeArray = Array();
function TradeElement(trade, specialty, highlight) {
	this.trade = trade;
	this.specialty = specialty;
	this.highlight = highlight;
	}




// ***********************************************************************************************************
// User Event Handlers    ************************************************************************************
// ***********************************************************************************************************

function goSearch() {
	var aString = document.getElementById('tSearchIt').value.replace(/&/, 'and');
	aString = aString.replace(/\s(?=$)/, "");
	aString = aString.replace(/-/g, "--");
	aString = aString.replace(/\s/g, "-");
	aString += cityString + ".asp";
	document.getElementById('postForm').action = aString;
	document.getElementById('postForm').submit();
	}

function ifEnter(e) {
	if (window.event) key = window.event.keyCode;
	else if (e) key = e.which;
	if (key==13) goSearch();
	}

function scrollToAlpha() {
	var posX = document.getElementById('startAlphaList').offsetLeft;
	var posY = document.getElementById('startAlphaList').offsetTop; 
	scrollTo(posX,posY);
	}
	
function pushButton(tc) {
	var tb = document.getElementsByName('tradeButton');
	tb[tc].className = 'tradeD';
	}
	
function mouseOverButton(tc) {
	var tb = document.getElementsByName('tradeButton');
	tb[tc].className = 'tradeO';
	}
	
function mouseOutButton(tc) {
	var tb = document.getElementsByName('tradeButton');
	tb[tc].className = 'trade';
	}




// ***********************************************************************************************************
// Program Event Handlers    *********************************************************************************
// ***********************************************************************************************************

//function setMenuForm(s, aString, sString, siString) {
//	var a2String = aString.replace(/&/, 'and');
//	a2String = a2String.replace(/-/g, "--");
//	a2String = a2String.replace(/\s/g, "-");
//	a2String += cityString + ".asp";
//	document.menuForm.specialty.value = sString;
//	document.menuForm.searchIt.value = siString.replace(/`/g, "'");;
//	document.menuForm.action = a2String;
//	if (s) document.menuForm.submit();
//	}
	




//function makeTSearchBox(tradeString) {
//	var tString = "<select class='tSearch' name='tSearchIt' onchange='makeSSearchBox(" + '""' + ");'>";
//	var trades = tradeString.split(";");
//	for (i=0; i<trades.length; i++) {
//		if (i==0) tString += "<option value='All'>" + trades[i] + "</option>";	
//		else      tString += "<option value='" + trades[i] + "'>" + trades[i] + "</option>";	
//		}
//	tString += "</select><br/>";
//	tString += "<span name='sSearchBox' id='sSearchBox' style='display:none'><select class='sSearch' name='sSearchIt'></select><br/></span>"
//	tString += "<span id='searchSpan' style='display:none'></span><font class='search'>Search </font>";
//	tString += "<input class='search' name='searchMe' size='20' value='' onkeypress='ifEnter(event);' />";
//	tString += "<input class='bSearch' type='button' value='Go' onclick='goSearch();' />";
//	window.tSearch.innerHTML = tString;
//	}
	
function makeSSearchBox(isString) {
	var tString = document.getElementById('tSearchIt').value;
	tString = tString.replace(/\s(?=$)/, "");
	var sString = "";
	for (i=0; i<document.getElementById('sSearchIt').options.length; i++) document.getElementById('sSearchIt').options[i] = null;
	document.getElementById('sSearchIt').options[0] = new Option("All", "");
	document.getElementById('sSearchIt').options[0].selected = "selected";
	for (i=0; i<tradeArray.length; i++) {
		if (tradeArray[i].trade == tString)
			sString = tradeArray[i].specialty;
		}
	if (sString=="" || sString=="null")
		document.getElementById('sSearchBox').style.display = "none";
	else {
		var specialties = sString.split(",");
		for (i=0; i<specialties.length; i++) {
			document.getElementById('sSearchIt').options[i+1] = new Option(specialties[i].replace(/^\s/, ""), specialties[i].replace(/^\s/, "" ));
			if (document.getElementById('sSearchIt').options[i+1].value == isString) document.getElementById('sSearchIt').options[i+1].selected = "selected";
			}
		document.getElementById('sSearchBox').style.display = "block";
		}	
	}

function setHeaders() {
	ssValue = specialtyString.replace(/%/g, "");
	for (i=0; i<document.getElementById('tSearchIt').options.length; i++) {
		tString = document.getElementById('tSearchIt').options[i].value;
		tString = tString.replace(/\s(?=$)/, "");
		if (tString==tradeFile)
			document.getElementById('tSearchIt').options[i].selected = "selected";
		}
	makeSSearchBox(ssValue);
	for (i=0; i<document.getElementById('sSearchIt').options.length; i++) {
		if (document.getElementById('sSearchIt').options[i].value==ssValue)
			document.getElementById('sSearchIt').options[i].selected = "selected";
		}
	}

function setFootHeaders(picTotal, adTotal) {
	ssValue = document.menuForm.specialty.value.replace(/undefined/, "")
	siValue = document.menuForm.searchIt.value.replace(/undefined/, "")
	siValue = siValue.replace(/`/g, "'");
	tsString = "<font class='trade'>" + tradeFile + "</font>";
	if (ssValue!="") tsString += ": <font class='specialty'>" + ssValue + "</font>";
	if (siValue!="") {
		if (tradeFile=="") document.adHeader.innerHTML = "Search for <font class='search'>" + siValue + "</font>"; 
		else document.adHeader.innerHTML = tsString + ": Search for <font class='search'>" + siValue + "</font>"; 
		window.alphaHeader.innerHTML = " &nbsp; ";
		}
	else { 
		document.adHeader.innerHTML = tsString;
	}
		window.alphaHeader.innerHTML = "<a class='alphaHeader' title='Go to Directory Listings' href='javascript: scrollToAlpha()'>Directory</a> &nbsp; ";
	//	window.alphaHeader2.innerHTML = "<a class='alphaHeader' title='Go to Ad Listings' href='javascript: scrollTo(0,0)'>Ads</a> &nbsp; ";
//		}
	document.adHeader.innerHTML += " (" + picTotal + " of " + adTotal + ")";
	for (i=0; i<document.tSearchIt.options.length; i++) {
		if (document.tSearchIt.options[i].value==tradeFile)
			document.tSearchIt.options[i].selected = "selected";
		}
	window.makeSSearchBox(document.menuForm.specialty.value);
	for (i=0; i<window.sSearchIt.options.length; i++) {
		if (window.sSearchIt.options[i].value==ssValue)
			window.sSearchIt.options[i].selected = "selected";
		}
	}







