var whatDefault	= new Array();

whatDefault['1']	= 'Search for company name';
whatDefault['2']	= 'Search for product';
whatDefault['3']	= 'Search for product type';


function setWhat(form){
	curSrch	= trim(form.q.value);
	curType	= form.searchtype.value;
	txtColor= "#000";
	//if(curSrch==whatDefault[curType]){ form.q.value = ""; }
	form.q.value = "";
	document.getElementById('q').style.color = txtColor;
}

function validTnetSearch(search){
	search.q.value	= trim(search.q.value);
	curType	= search.searchtype.value;
	if(search.q.value == whatDefault[curType] || search.q.value.length < 1){
		alert("Please enter a keyword");
		return false;
	}
}


function changeSearch(searchtype){
	document.searchform.q.value = trim(document.searchform.q.value);
	var defaultStr	= 0;
	var newtab = "tablink-"+searchtype;
	var oldtab = "tablink-"+document.searchform.searchtype.value;
	if(document.searchform.q.value == whatDefault['1'])	{ defaultStr++; }
	if(document.searchform.q.value == whatDefault['2'])	{ defaultStr++; }
	if(document.searchform.q.value == whatDefault['3'])	{ defaultStr++; }

	document.searchform.searchtype.value = searchtype;

	if(defaultStr < 1 && document.searchform.q.value.length > 0){
		document.searchform.submit();
		return;
	} else {
		var txtColor;
		if(newtab!=oldtab){
			document.getElementById(oldtab).className = "search_tga";
			document.getElementById(newtab).className = "search_tga_n";
		}
		document.searchform.q.value	= whatDefault[searchtype];
		if(searchtype!="2"){ txtColor= "#999"; }
		else {document.searchform.q.focus(); }
		document.getElementById('q').style.color = txtColor;
	}
}

function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

