var NamedPlant = Ext.data.Record.create([
   			{name:'id',mapping:'id'},
   			{name:'name',type:'string',mapping:'name'}
   		]);

var ds = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: webroot+'/search/search.htm?method=getSearchKeyword'
        }),
        reader: new Ext.data.JsonReader({
            root: 'results',
            totalProperty: 'totalCount',
            id: 'id'
        }, NamedPlant)
    });
ds.on("load",keyload);

function searchEngingTypeClick(thisobject){
	var searchType = thisobject.value;
	if(thisobject.value=="insuranceproduct"){
		document.getElementById("searchtypeselect").style.display="";
		document.getElementById("btnadvancedsearch").style.display="";
	}else{
		document.getElementById("searchtypeselect").style.display="none";
		document.getElementById("btnadvancedsearch").style.display="none";	
	}
	
	var typeId = "24";
	if(searchType=="insuranceproduct"){
		typeId = "20";
	}else if(searchType=="information"){
		typeId = "21";	
	}else if(searchType=="company"){
		typeId = "25";	
	}else if(searchType=="propernoun"){
		typeId = "22";
	}else if(searchType=="question"){
		typeId = "23";	
	}
	
	ds.load({params:{start:1, limit:12,searchtype:typeId}});	
}

function searchClick(){
	var varSearchType = document.getElementById("searchtypeselect");
	document.getElementById("searchinsuredtypeid").value=varSearchType.value;
	document.getElementById("searchinsuredtypename").value=varSearchType.options[varSearchType.selectedIndex].text;	
	document.getElementById("searchkeyword").value=document.getElementById("searchcontent").value=='请输入查询关键字'?'':document.getElementById("searchcontent").value;
	
	if(document.getElementById("searchkeyword").value===""){return;}

	document.getElementById("searchform").action=webroot+"/search/search.htm?method="+obtainSearchTypeUrl();
	document.getElementById("searchform").submit();		
}

function obtainSearchTypeUrl(){
	var rbArray = document.getElementsByName("rbsearchtype");
	var rbValue = "";
	var rbMethod = "";
	
	for(var i=0;i<rbArray.length;i++){
		if(rbArray[i].checked){
			rbValue = rbArray[i].value;
			break;
		}
	}
	
	if(rbValue=="insuranceproduct"){
		rbMethod = "searchInsuranceProductIndex";
	}else if(rbValue=="information"){
		rbMethod = "searchInformationIndex";	
	}else if(rbValue=="company"){
		rbMethod = "searchInsuranceCompanyIndex";	
	}else if(rbValue=="propernoun"){
		rbMethod = "searchProperNounIndex";
	}else if(rbValue=="question"){
		rbMethod = "23";	
	}
	
	return rbMethod;
}

function hrefSearchClick(thisobj){
	document.getElementById("searchinsuredtypeid").value="-1";
	document.getElementById("searchinsuredtypename").value="";	
	document.getElementById("searchkeyword").value=thisobj;
		
	document.getElementById("searchform").action=webroot+"/search/search.htm?method="+obtainSearchTypeUrl();
	document.getElementById("searchform").submit();	
}

function keyload(dsparam,records,op){
	var render = "<strong>热门关键字：</strong>";
	var record = null;
	for(var i=0;i<records.length;i++){
			record = records[i];
			var promotion = '<span>'+'<a href="javascript:hrefSearchClick('+"'"+'{0}'+"'"+')" title="{0}" class="font12whtie">{1}</a></span>';
			   	render = render+String.format(promotion,""+record.data['name']+"",record.data['name']);
	}
	
	document.getElementById("keyworddiv").innerHTML = render;
}
Ext.onReady(function(){ds.load({params:{start:1, limit:12,searchtype:20}});});
