//动态创建script标签
	function load_script(url){  
		var head = document.getElementsByTagName('head')[0];  
		var script = document.createElement('script');  
		script.type = 'text/javascript';  
		//当前页面加载状态改变的 时候执行 
		script.onload = script.onreadystatechange = function(){  
		if((!this.readyState||this.readyState === "loaded"||this.readyState === "complete")){  
		           script.onload = script.onreadystatechange = null;  
		             if ( head && script.parentNode ) {  
		             head.removeChild( script );  
		            }  
		         }  
		     };  
		    script.src = url;  
		    head.insertBefore( script, head.firstChild );  
		}
		
function searchOnFocus(e,w,m){
	if(e.value == '请输入关键字')
	e.value='';
	e.style.color=0;
	e.style.width=w+'px';
	e.style.marginLeft=m+'px';
	document.onselectstart=function(){
		return true;
		};
		e.select();
}

function searchOnBlur(e,w,m){
	document.onselectstart=function(){
		return false;
		};
	if (e.value == '') {
	e.style.color = '#999999';
	e.style.width=w+'px';
	e.style.marginLeft=m+'px';
    e.value = "请输入关键字";
	}
}	
		
	function selectvalue(e){
		$('main_search_keywords').value=e.innerHTML;
       $('show_search_div').innerHTML="";
	   $('show_search_div').style.display="none";	
	}
	
	function chcol(e){
	e.style.backgroundColor="#71A9FA";		
	}
	function chcol1(e){
	e.style.background="transparent";		
	}
	
	//+重写bing 的sa_inst对象的apiCB函数获取匹配数据
    var sa_inst={
	apiCB:function(obj){
	if (obj.AS.Results==null) {
	$('show_search_div').innerHTML="";
	$('show_search_div').style.display="none";
		}else{
			var html="<ul id='show_search'>";
			var sug=obj.AS.Results[0].Suggests;
			for (k = 0; k < sug.length; k++) {
           html+="<li onclick='selectvalue(this)' onmouseover='chcol(this)' onmouseout='chcol1(this)'>"+sug[k].Txt+"</li>";
		}
		html+="<li style='text-align:right;'>关闭&nbsp;&nbsp;</li></ul>";
		$('show_search_div').style.display="block";	
	    $('show_search_div').innerHTML=html;
			}
		}
    }  
//+重写淘宝函数获取匹配数据
var KISSY={
	Suggest:{
		callback:function(obj){
			var sug=obj.result;
			if (sug.length == 0) {
	$('show_search_div').innerHTML="";
	$('show_search_div').style.display="none";
			}else {
				var html="<ul id='show_search'>";
				for (k = 0; k < sug.length; k++) {
				   html+="<li onclick='selectvalue(this)' onmouseover='chcol(this)' onmouseout='chcol1(this)'>"+sug[k][0]+"</li>";
				}
				html+="<li style='text-align:right;'>关闭&nbsp;&nbsp;</li></ul>";
		$('show_search_div').style.display="block";	
	    $('show_search_div').innerHTML=html;
			}
		}	
	}
}
//+重写拍拍函数
function _PP_head_callback(obj){
	var sug1=obj.list;
		if (sug1==null) {
	$('show_search_div').innerHTML="";
	$('show_search_div').style.display="none";
		}else {
		var html="<ul id='show_search'>";
			for (i = 0; i < sug1.length; i++) {
       html+="<li onclick='selectvalue(this)' onmouseover='chcol(this)' onmouseout='chcol1(this)'>"+sug1[i][0]+"</li>";
			}
			html+="<li style='text-align:right;'>关闭&nbsp;&nbsp;</li></ul>";
		$('show_search_div').style.display="block";	
	    $('show_search_div').innerHTML=html;
		}
}
//重写迅雷函数
function compResp(obj1,obj2,obj3){
	    var html="<ul id='show_search'>";
		for (k = 0; k < obj2.length; k++) {
	    html+="<li onclick='selectvalue(this)' onmouseover='chcol(this)' onmouseout='chcol1(this)'>"+obj2[k]+"</li>";				
		}
		html+="<li style='text-align:right;'>关闭&nbsp;&nbsp;</li></ul>";
		$('show_search_div').style.display="block";	
	    $('show_search_div').innerHTML=html;


}
//重写多特函数
function sendRPCDone(obj1,obj2,obj3,obj4,obj5){
		var html="<ul id='show_search'>";
		for (k = 0; k < obj3.length; k++) {
			 html+="<li onclick='selectvalue(this)' onmouseover='chcol(this)' onmouseout='chcol1(this)'>"+decodeURI(obj3[k])+"</li>";
		}
		html+="<li style='text-align:right;'>关闭&nbsp;&nbsp;</li></ul>";
		$('show_search_div').style.display="block";	
	    $('show_search_div').innerHTML=html;
}
//+重写土豆
function tui_searchHint_handler(obj){
	if (obj.length == 0) {
	$('show_search_div').innerHTML="";
	$('show_search_div').style.display="none";
	}else {
		 var html="<ul id='show_search'>";
		for (k = 0; k < obj.length; k++) {
			var num = obj[k].indexOf("#");
			var str = obj[k].substring(0, num);
   		  html+="<li onclick='selectvalue(this)' onmouseover='chcol(this)' onmouseout='chcol1(this)'>"+str+"</li>";
		}
		html+="<li style='text-align:right;'>关闭&nbsp;&nbsp;</li></ul>";
		$('show_search_div').style.display="block";	
	    $('show_search_div').innerHTML=html;		
	}
}
//+重写优酷
function showresult(obj1,obj2){
var reg = /("keyword":")(.*?)(")/g; 
	var arr=obj1.match(reg);
	if (arr == null || arr.length==1) {
	$('show_search_div').innerHTML="";
	$('show_search_div').style.display="none";
	}
	else {
		var html="<ul id='show_search'>";
		for (k = 1; k < arr.length; k++) {
			var arr1 = arr[k].split(":");
			var str = arr1[1].replace(/^"/, "").replace(/"$/, "");
        html+="<li onclick='selectvalue(this)' onmouseover='chcol(this)' onmouseout='chcol1(this)'>"+str+"</li>";
		}
		html+="<li style='text-align:right;'>关闭&nbsp;&nbsp;</li></ul>";
		$('show_search_div').style.display="block";	
	    $('show_search_div').innerHTML=html;
	}
}
	


function keySuggestion(){
	//+百度
	this.baidu=function(stype){
     window.baidu = {
	 	sug: function(data){
	 		if (data.s == "") {
	$('show_search_div').innerHTML="";
	$('show_search_div').style.display="none";
	 		}
	 		else {
				var html="<ul id='show_search'>";
	 			for (k = 0; k < data.s.length; k++) {
			 html+="<li onclick='selectvalue(this)' onmouseover='chcol(this)' onmouseout='chcol1(this)'>"+data.s[k]+"</li>";
	 			}
				html+="<li style='text-align:right;'>关闭&nbsp;&nbsp;</li></ul>";
		$('show_search_div').style.display="block";	
	    $('show_search_div').innerHTML=html;
	 		}
	 	}
	 }
	switch(stype){
	case "baidu":
	load_script("http://suggestion.baidu.com/su?wd="+encodeURI($('main_search_keywords').value)+"&p=3"); 
	break;
	case "mbaidu":
	load_script("http://nssug.baidu.com/su?wd="+encodeURI($('main_search_keywords').value)+"&prod=mp3"); 
	break;
	case "ibaidu":
	load_script("http://nssug.baidu.com/su?wd="+encodeURI($('main_search_keywords').value)+"&prod=image"); 
	break;
	case "vbaidu":
	load_script("http://nssug.baidu.com/su?wd="+encodeURI($('main_search_keywords').value)+"&prod=video"); 
	break;
	case "wbaidu":
	load_script("http://nssug.baidu.com/su?wd="+encodeURI($('main_search_keywords').value)+"&prod=zhidao"); 
	break;
	default:
	load_script("http://suggestion.baidu.com/su?wd="+encodeURI($('main_search_keywords').value)+"&p=3"); 	
	}	
}	
	//youdao
	this.youdao=function(){
	load_script("http://bj1.api.bing.com/qsonhs.aspx?FORM=ASAPIH&mkt=zh-CN&type=cb&cb=sa_inst.apiCB&q="+encodeURI($('main_search_keywords').value)+"&cp=1&o=s"); 
	}
	//搜狗
	this.sogou=function(){
	window.sogou={
	sug:function(data,p){
	if (data[1]=="") {
	$('show_search_div').innerHTML="";
	$('show_search_div').style.display="none";
	 }else {
		var html="<ul id='show_search'>";
	 for (k = 0; k < data[1].length; k++) {
         html+="<li onclick='selectvalue(this)' onmouseover='chcol(this)' onmouseout='chcol1(this)'>"+data[1][k]+"</li>";
	 }
	 html+="<li style='text-align:right;'>关闭&nbsp;&nbsp;</li></ul>";
		$('show_search_div').style.display="block";	
	    $('show_search_div').innerHTML=html;
	 		}
		}
	}
	load_script("http://sugg.sogou.com/sugg/ajaj_json.jsp?key="+encodeURI($('main_search_keywords').value)+"&type=web&pr=web"); 	
	}

   //bing
	this.bing=function(){
	load_script("http://bj1.api.bing.com/qsonhs.aspx?FORM=ASAPIH&mkt=zh-CN&type=cb&cb=sa_inst.apiCB&q="+encodeURI($('main_search_keywords').value)+"&cp=1&o=s"); 
	}
	//yahoo
	this.yahoo=function(){
	load_script("http://bj1.api.bing.com/qsonhs.aspx?FORM=ASAPIH&mkt=zh-CN&type=cb&cb=sa_inst.apiCB&q="+encodeURI($('main_search_keywords').value)+"&cp=1&o=s"); 
	}
	
	//淘宝网
	this.staobao=function(){
	load_script("http://suggest.taobao.com/sug?code=utf-8&extras=1&callback=KISSY.Suggest.callback&q="+encodeURI($('main_search_keywords').value)); 
	}
	//拍拍网
	this.spaipai=function(){
	load_script("http://search.paipai.com/cgi-bin/isuggest_v6?KeyWord="+$('main_search_keywords').value+"&dTag=smartDrawCallBack"); 	
	
	}
	//卓越网
	this.sjyjo=function(){
	load_script("http://completion.amazon.cn/search/complete?method=completion&q="+encodeURI($('main_search_keywords').value)+"&search-alias=aps&client=amazon-search-ui&mkt=3240&x=updateISSCompletion&sc=1"); 		
	if(completion[1]==""){
	$('show_search_div').innerHTML="";
	$('show_search_div').style.display="none";	
	}else{
	var html="<ul id='show_search'>";
	  for (k = 0; k < completion[1].length; k++) {
      html+="<li onclick='selectvalue(this)' onmouseover='chcol(this)' onmouseout='chcol1(this)'>"+completion[1][k]+"</li>";
	 	}
		html+="<li style='text-align:right;'>关闭&nbsp;&nbsp;</li></ul>";
		$('show_search_div').style.display="block";	
	    $('show_search_div').innerHTML=html;
		}
	}
	//京东网
	this.sbuy360=function(){	
	load_script("http://search.360buy.com/ks?keyword="+encodeURI($('main_search_keywords').value)); 
	if(text==""){
	$('show_search_div').innerHTML="";
	$('show_search_div').style.display="none";
	}else{
		var html="<ul id='show_search'>";
		var arr=text.split("|");
		for (k = 0; k < arr.length-1; k++) {
	 		var num=arr[k].indexOf(",");
			var str=arr[k].substring(0,num);
         html+="<li onclick='selectvalue(this)' onmouseover='chcol(this)' onmouseout='chcol1(this)'>"+str+"</li>";
		 }
		 html+="<li style='text-align:right;'>关闭&nbsp;&nbsp;</li></ul>";
		$('show_search_div').style.display="block";	
	    $('show_search_div').innerHTML=html;
	}
	}
	//当当
	this.sdangdang=function(){
		load_script("http://suggest.taobao.com/sug?code=utf-8&extras=1&callback=KISSY.Suggest.callback&q="+encodeURI($('main_search_keywords').value)); 
	}
	//迅雷
	this.dxunlei=function(){	
	load_script("http://ac.xunlei.com/complete?ac="+encodeURI($('main_search_keywords').value));	
	}
	//verycd
	this.dverycd=function(){	
	load_script("http://ac.xunlei.com/complete?ac="+encodeURI($('main_search_keywords').value));	
	}
	//射手
	this.dshooter=function(){	
	load_script("http://ac.xunlei.com/complete?ac="+encodeURI($('main_search_keywords').value));	
	}
	//多特
	this.dduote=function(){	
	load_script("http://www.duote.com/autoPatch.as.php?cmd=getKey&word="+encodeURI($('main_search_keywords').value)); 
	}
	//土豆
	this.vtudou=function(){
	load_script("http://hint.tudou.com/hint?q="+encodeURI($('main_search_keywords').value)+"&type=programs&jsoncallback=tui_searchHint_handler"); 	
	}
	//优酷
	this.vyouku=function(){	
	load_script("http://tip.so.youku.com/search_keys?k="+encodeURI($('main_search_keywords').value)+"&type=video"); 		
	}
	
	
	
	
	
	
			
	}
		

