String.prototype.LTrim = function(){return LTrim(this);}
function LTrim(str)
{
var i;
for(i=0;i<str.length;i++)
{
if(str.charAt(i)!=" "&&str.charAt(i)!=" ")break;
}
str=str.substring(i,str.length);
return str;
}

var g_stype = "search";

function setstype(index) {
	//9 BT http://bt.xunlei.com/bt_search?s=qq&id=2
	// 10 找到 http://www.wnpso.com1.xunlei.com/found?s=qq
	g_stype = index;
}

function check()
{
  var url;

  var s_key = document.getElementById("searchbox1").value;
  var s_channel =document.getElementById("channel_id").value;

  s_key = s_key.LTrim();
  if (s_key == "搜索超过10万部影视内容" || s_key ==""){
	  alert("请输入搜索关键字!") ;
	  document.getElementById("searchbox1").value = "" ;
	  document.getElementById("searchbox1").focus();
	  return false ;
  }
  //s_key = encodeURIComponent(s_key);
  //if( g_stype == 'websearch' ){
	//submitToGoogle('websearch');
	//return;
	//url = "http://web.gougou.com/search?search="+s_key+"&id=1" ;
  //}

  var host = "http://"+location.host+"/index.php?";
  url = host+"ctrl=web&q="+s_key;


  if (g_stype == 'news') {
		 url =  host+"ctrl=News&q="+s_key+"&s=news";
  }
  else if (g_stype == 'video') {
	   url =  host+"ctrl=video&q="+s_key+"&s=video";
  }
  else if (g_stype == 'image') {
  	url =  host+"ctrl=image&q="+s_key+"&s=image";
		//url = url + "&s=image" ;
  }
  else if (g_stype == 'dict') {
		url =  host+"ctrl=dict&q="+s_key+"&s=dict";
  }
  else if (g_stype == 'mobileweb')
  {
	   url = url + "&s=mobileweb" ;
  }
else if (g_stype == 'search')
  {
	   url = url + "&s=web&channel="+s_channel  ;
  }  //url = url + "&id=2" ;
  location.href=url;

}


function submitToGoogle(channelname) {

 	var s_key = document.getElementById("searchbox1").value;
	document.gform1.q.value=s_key;
	document.gform1.channel.value=channelname;
	document.gform1.submit();
	return;
}

function searchWordSbt(keywords){
	if(keywords.length>=2){
		window.open('http://www.gougou.com/search?search='+encodeURIComponent(keywords) + '&id=2');
	}
}

var pre_searchtype = "search" ;
function changeSearchType(type) {
	if ($("searchType_"+pre_searchtype)) {
		$("searchType_"+pre_searchtype).className = "" ;
	}
	pre_searchtype = type ;
	$("searchType_"+type).className = "currA" ;
	setstype(type) ;
	if ($("searchbox1").value == '搜索超过10万部影视内容') {
		$("searchbox1").value = "" ;
	}
	else {
		$("searchbox1").value = $("searchbox1").value + "" ;
	}
	$("searchbox1").focus() ;
}

function $(item){
	return document.getElementById(item);
}
