// sitewide search functionality
function _fisearch(f) {
	if (!f) f = document.forms['fisearch'];
	if (!f) return false;
	var crit = f.crit.value;
	var t = f.elements["fistype"];
	var parent = document.getElementById("mainSearchForm2");
	
	var myDate = new Date();
	var formattedDate =(myDate.getMonth()+1) + '/' + myDate.getDate() + '/' + myDate.getFullYear();
	var formattedDateWeek =(myDate.getMonth()+1) + '/' + (myDate.getDate() +7) + '/' + myDate.getFullYear();
	
	if (_getCheckedValue(t) == "yp") {
		f.action = 'http://xxxxxxxxxxxx.localconnect.com/search.aspx';
		f.appendChild(_createElement("input", "hidden", "keyword", crit));
		f.appendChild(_createElement("input", "hidden", "location", "Bend"));
	}
	
	if (_getCheckedValue(t) == "pg") {
		f.action = 'http://yellowpages.bendbulletin.com/search.pg';
		f.appendChild(_createElement("input", "hidden", "q", crit));
		f.appendChild(_createElement("input", "hidden", "z", "Bend, OR"));
	}
	
	if (_getCheckedValue(t) == "web") {
		f.action = 'http://www.google.com/custom';
		f.appendChild(_createElement("input", "hidden", "q", crit));
		f.appendChild(_createElement("input", "hidden", "client", "pub-3973738856221390"));

		f.appendChild(_createElement("input", "hidden", "forid", "1"));
		f.appendChild(_createElement("input", "hidden", "sa", "utf-8"));
		f.appendChild(_createElement("input", "hidden", "oe", "utf-8"));
		f.appendChild(_createElement("input", "hidden", "cof", "GALT:#008000;GL:1;DIV:#336699;VLC:663399;AH:center;BGC:FFFFFF;LBGC:336699;ALC:0000FF;LC:0000FF;T:000000;GFNT:0000FF;GIMP:0000FF;FORID:1;"));
		f.appendChild(_createElement("input", "hidden", "h1", "en"));
	}
	
	if (_getCheckedValue(t) == "restaurant") {
		f.removeChild(document.getElementById("mainSearchFormCategory"));
		f.removeChild(document.getElementById("mainSearchFormProfile"));
		f.removeChild(document.getElementById("mainSearchFormDaterange"));
		f.action = '/apps/pbcs.dll/ptshowguide?';
		
		f.appendChild(_createElement("input", "hidden", "filter", crit));
		
		f.appendChild(_createElement("input", "hidden", "category", "RESTAURANTGUIDE"));
		f.appendChild(_createElement("input", "hidden", "mode", "search"));
		f.appendChild(_createElement("input", "hidden", "First", "1"));
		f.appendChild(_createElement("input", "hidden", "Number", "90"));
		f.appendChild(_createElement("input", "hidden", "profile", "1019"));
		f.appendChild(_createElement("input", "hidden", "MainCat", "2680"));
	}
	
	if (_getCheckedValue(t) == "etCal") {
		f.removeChild(document.getElementById("mod_search_searchword"));
		f.removeChild(document.getElementById("mainSearchFormCategory"));
		f.removeChild(document.getElementById("mainSearchFormProfile"));
		f.removeChild(document.getElementById("mainSearchFormDaterange"));
		f.action = '/apps/pbcs.dll/section';
			
		f.appendChild(_createElement("input", "hidden", "SearchEventKeyword", crit));
		
		f.appendChild(_createElement("input", "hidden", "category", "EVENTCALENDAR"));
		f.appendChild(_createElement("input", "hidden", "tpl", "BB_EventSearch"));
		f.appendChild(_createElement("input", "hidden", "profile", "1111"));
		f.appendChild(_createElement("input", "hidden", "SearchDate", formattedDate));
		f.appendChild(_createElement("input", "hidden", "SearchDateEnd", formattedDateWeek));
	}
	
	if (_getCheckedValue(t) == "gArchive") {
		var googleClientID = "bendbulletin";
		// var googleClientID = "st_petersburg"
		f.removeChild(document.getElementById("mod_search_searchword"));
		f.removeChild(document.getElementById("mainSearchFormCategory"));
		f.removeChild(document.getElementById("mainSearchFormProfile"));
		f.removeChild(document.getElementById("mainSearchFormDaterange"));
		f.action = '/apps/pbcs.dll/section';
		f.appendChild(_createElement("input", "hidden", "Category", "NEWSPRINTARCHIVE"));
		f.appendChild(_createElement("input", "hidden", "profile", "1194"));
		f.appendChild(_createElement("input", "hidden", "h1", "en"));
		f.appendChild(_createElement("input", "hidden", "q", crit));
		f.appendChild(_createElement("input", "hidden", "gaurl", 'http://news.google.com/newspapers/p/'+googleClientID+''));
	}
	
	return true;
}

function _getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function _createElement(el, type, name, value) {
	var e = document.createElement(el);
	e.setAttribute("type", type);
	e.setAttribute("name", name);
	e.setAttribute("value", value);
	return e;
}