/* SearchTypes
	0 = LOGOonline
	1 = LOGOVideo
	2 = Web
*/
var searchType="0";
var toggleSearchType = searchType;

/* Search Type Labels */
var label_0 = "Search LOGO";
var label_1 = "Search LOGO Video";
var label_2 = "Search The Web";


var defaultSearchString = label_0;
var url="http://www.logotv.com/search/index.jhtml?searchterm="+defaultSearchString+"&searchtype=all_logoonline&resulttype=pages";


function runPortableSearch(fieldName, searchType){
	if(document.getElementById(fieldName).value == "" || document.getElementById(fieldName).value == window["label_"+searchType]){
		//do nothing
	} else {
		searchType = searchType;
		searchString = document.getElementById(fieldName).value;
		switch(searchType)
		{
		case "1":
		  // Is a video Search
		  url="http://www.logotv.com/search/index.jhtml?searchterm="+escape(searchString)+"&searchtype=all_logoonline&resulttype=video";
		  document.location.href=url;
		  break;
		case "2":
		  // Is a Web Search
		  url="http://search.live.com/results.aspx?q="+escape(searchString)+"&mkt=en-us&FORM=VCM003";
		  window.open(url);
		  break;
		default:
		  // Is a site Search
		  url="http://www.logotv.com/search/index.jhtml?searchterm="+escape(searchString)+"&searchtype=all_logoonline&resulttype=pages";
		  document.location.href=url;
		}
	}
}

function removePortableDefaultSearchText(fieldName, searchType){
	if(document.getElementById(fieldName).value == window["label_"+searchType]){
		document.getElementById(fieldName).value = "";
	}
}

function resetPortableDefaultSearchText(fieldName, searchType){
	if(document.getElementById(fieldName).value == ""){
		document.getElementById(fieldName).value = window["label_"+searchType];
	}
}


function toggle_divs(active_id, inactive_id, inactive_id2, fieldName, type) {
	toggleSearchType = type;
	defaultSearchString = window["label_"+searchType];
	document.getElementById(active_id).setAttribute("class", 'active');
	document.getElementById(active_id).setAttribute("className", 'active');
	document.getElementById(inactive_id).setAttribute("class", 'inactive');
	document.getElementById(inactive_id).setAttribute("className", 'inactive');
	document.getElementById(inactive_id2).setAttribute("class", 'inactive');
	document.getElementById(inactive_id2).setAttribute("className", 'inactive');
	document.getElementById(active_id).blur();

	if(document.getElementById(fieldName).value == ""|| document.getElementById(fieldName).value == label_1 || document.getElementById(fieldName).value == label_2 || document.getElementById(fieldName).value == label_0){
		document.getElementById(fieldName).value = window["label_"+toggleSearchType];
	} else {
		searchString = document.getElementById(fieldName).value;
	}
}


/*  Listen for ENTER/RETURN key and SUBMIT  */
function handleKeyPress(e){
	var key=e.keyCode || e.which;
	if (key==13){
		runPortableSearch('search2', toggleSearchType);
	}
}

