/* SearchTypes
	0 = LOGOonline
	1 = LOGOVideo
	2 = Web
*/
var searchType="0";
var toggleSearchType = searchType;

/* Search Type Labels */
var label_0 = "Search LogoTV.com";
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";


function getBaseURL() {
    var url = location.href;  /* entire url including querystring - also: window.location.href;*/
    var baseURL = url.substring(0, url.indexOf('/', 14));


    if (baseURL.indexOf('http://localhost') != -1) {
        /* Base Url for localhost */
        var url = location.href;  /* window.location.href;*/
        var pathname = location.pathname;  /*  window.location.pathname; */
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);

        return baseLocalUrl + "/";
    }
    else {
        /*  Root Url for domain name */
        return baseURL + "/";
    }

}

baseURL=getBaseURL();
if ((baseURL.indexOf("logotv")==-1 && baseURL.indexOf("logoonline")==-1) || (baseURL.indexOf("community.logotv")!=-1)) {
	baseURL="http://www.logotv.com/";
}

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=baseURL+"search/video/?q="+escape(searchString);
		  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=baseURL+"search/?q="+escape(searchString);
		  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);
	}
}


