var NamedPlant = Ext.data.Record.create([
   			{name:'id',mapping:'id'},
   			{name:'name',type:'string',mapping:'name'}
   		]);

var propertiesds = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: webroot + '/system/getsysparamter.htm?method=findGroupJson'
        }),
        reader: new Ext.data.JsonReader({
            root: 'results',
            totalProperty: 'totalCount',
            id: 'id'
        }, NamedPlant)
    });
propertiesds.on("load",propertiesLoad);

var targetctds = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: webroot + '/system/getsysparamter.htm?method=findCustomerTypeTargetJson'
        }),
        reader: new Ext.data.JsonReader({
            root: 'results',
            totalProperty: 'totalCount',
            id: 'id'
        }, NamedPlant)
    });
targetctds.on("load",targetsLoad);


var insuranceoptions;
function propertiesLoad(dsparam){
	var dsLength = dsparam.getTotalCount();
	if(insuranceoptions==null)
		insuranceoptions = document.getElementById("instypeoptions");
		
	for(var i=0;i<dsLength;i++){
		var record = dsparam.getAt(i);
		insuranceoptions.options.add(new Option(record.data["name"],record.data["id"]));
	}
}

function targetsLoad(dsparam){
	var dsLength = dsparam.getTotalCount();
	
	var	targetoptions = document.getElementById("protargetoptions");
		
	for(var i=0;i<dsLength;i++){
		var record = dsparam.getAt(i);
		targetoptions.options.add(new Option(record.data["name"],record.data["id"]));
	}

}

function productCommonSearchClick(){
	document.getElementById("searchinsuredtypeid").value="-1";
	document.getElementById("searchinsuredtypename").value="";	
	document.getElementById("searchkeyword").value=document.getElementById("productsearchkey").value=='请输入产品关键字'?'':document.getElementById("productsearchkey").value;
	document.getElementById("searchproperties").value=document.getElementById("instypeoptions").value;
	document.getElementById("searchtarget").value=document.getElementById("protargetoptions").value;	
	document.getElementById("searchform").action=webroot+"/search/search.htm?method=searchInsuranceProductIndex";
	document.getElementById("searchform").submit();
}

function inspropertychange(proobject,elementid){
	var temp = document.getElementById(elementid);
	var sLength = temp.options.length;

	for(var j=0;j<sLength;j++){
		temp.remove(0);
	}
	
	temp.options.add(new Option("所有",""));	
	if(proobject.value==="")return;
	
	var pid = proobject.value;
	insuranceoptions = temp;
	propertiesds.load({params:{id:pid}});
}

Ext.onReady(function(){
	propertiesds.load({params:{id:'1902'}});
	targetctds.load();
});

