var a,ParamsAbbr={producer:"p",master:"m",brand:"b",serial:"s",cartype:"t"},ParamsGos={style:"normal",color:"#efefef",align:"center"},backgroup="#efefef",requestDatalist={},loadJS={lock:false,ranks:[],callback:function(b,c){this.lock=false;c&&c((new Date).valueOf()-b.valueOf());this.read()},read:function(){if(!this.lock&&this.ranks.length){var b=document.getElementsByTagName("head")[0];if(!b){d.length=0;d=null;throw new Error("HEAD\u4e0d\u5b58\u5728");}var c=this,d=this.ranks.shift(),f=new Date,e=
document.createElement("script");this.lock=true;e.onload=e.onreadystatechange=function(){if(!(e&&e.readyState&&e.readyState!="loaded"&&e.readyState!="complete")){e.onload=e.onreadystatechange=e.onerror=null;e.src="";e.parentNode.removeChild(e);e=null;c.callback(f,d.callback);f=d=null}};e.charset=d.charset||"gb2312";e.src=d.src;b.appendChild(e)}},push:function(b,c,d){this.ranks.push({src:b,charset:c,callback:d});this.read()}},DomHelper={cancelClick:function(b){if(window.event&&window.event.cancelBubble&&
window.event.returnValue){window.event.cancelBubble=true;window.event.returnValue=false}else if(b&&b.stopPropagation&&b.preventDefault){b.stopPropagetion();b.preventDefault()}},addEvent:function(b,c,d,f){if(b.addEventListener){b.addEventListener(c,d,f);return true}else if(b.attachEvent)return b.attachEvent("on"+c,d);else b["on"+c]=d},createOption:function(b){if(b==null)return null;var c=document.createElement("OPTION");c.setAttribute("value",b.value);c.appendChild(document.createTextNode(b.text));
if(b.bgcolor!=null)c.style.backgroundColor=b.bgcolor;return c},createGroupOption:function(b){if(b!=null){var c=document.createElement("OPTGROUP");c.label=b.text;c.style.fontStyle=b.style;c.style.background=b.color;c.style.textAlign=b.align;return c}},getSelectElementValue:function(b){if(!(b==null||!b))return b.options[b.selectedIndex].value},clearDomObject:function(b){if(b)for(var c=b.firstChild;c!=null;){b.removeChild(c);c=b.firstChild}}};
function BindSelect(b,c,d,f,e,h,i,g){this.SelectList=c;this.CheckData=d;this.Abbreviation=e;this.groupOprtionStyle=h;this.Data=f;this.Url=b;this.EnCode=i;this.optionBackColor=g}a=BindSelect.prototype;
a.BindList=function(b,c){if(b==null||b==""){for(index in this.SelectList){b=index;break}this.BindList(b,0)}else{var d=this.Data[b];if(c==0&&typeof d!="undefined"&&d!=null)this.AddOption(b,d);else if(c==0)this.GetDataList(b,0);else{var f={},e=this.getRelatObjctType(b,-1),h=this.Abbreviation[b];if(!(this.Data==null||typeof this.Data[e]=="undefined"||this.Data[e]==null)){e=this.Data[e][this.Abbreviation[e]+c];if(!(typeof e=="undefined"||e==null))if(e.nl==null||e.nl.length<1)this.GetDataList(b,c);else if(!(typeof d==
"undefined"||d==null)){c=e.nl.length;for(var i=0;i<c;i++){var g=h+e.nl[i],j=d[g];typeof j=="undefined"||j==null||(f[g]=j)}this.AddOption(b,f)}}}}};a.getDataListByType=function(b){if(!(this.Data==null||this.Data[b]==null)){var c=[];for(index in this.Data[b])c.push(index);return c}};
a.GetDataList=function(b,c){var d=this.Url+"?"+this.SelectList[b].condition.replace(/@pid@/gi,c),f=b+"_"+c+"_"+this.SelectList[b].datatype+"_"+this.SelectList[b].serias;if(typeof this.SelectList.include!="undefined"&&this.SelectList.include!=null)f=f+"_"+this.SelectList.include;var e=this;loadJS.push(d,this.EnCode,function(){e.CallBackOpertion(b,c,f)})};
a.CallBackOpertion=function(b,c,d){var f=requestDatalist[d];d=this.Abbreviation[b];if(typeof f=="undefined"||f==null)this.BindDefaultValue(b);else{var e=[];if(this.CheckData!=null)e=this.CheckData(f);else{var h=RegExp(d,"gi");for(var i in f)e.push(i.replace(h,""))}i={};h=e.length;for(var g=0;g<h;g++){var j=e[g],k=f[d+j];if(!(typeof k=="undefined"||k==null)){i[d+j]=k;if(typeof this.Data[b]=="undefined"||this.Data[b]==null)this.Data[b]={};this.Data[b][d+j]=k}}if(c>0){f=this.getRelatObjctType(b,-1);
d=this.Abbreviation[f];this.Data[f][d+c].nl=e}this.AddOption(b,i)}};a.GetValue=function(b){if(!(this.SelectList==null||b=="")){b=this.SelectList[b.toLowerCase()];if(!(b==null||b.selectid==""))if(b=document.getElementById(b.selectid))return DomHelper.getSelectElementValue(b)}};a.GetValueObject=function(b){var c=this.GetValue(b),d=this.SelectList[b].value,f=this.Data[b];b.toLowerCase();for(index in f)if(f[index][d]==c)return f[index]};
a.AddOption=function(b,c){b=b.toLowerCase();var d=document.getElementById(this.SelectList[b].selectid);if(!(!d||d.nodeName.toLowerCase()!="select")){this.BindDefaultValue(b);var f=this.SelectList[b];if(c!=null){var e={},h=0;for(var i in c){var g=c[i];g=g.goid;if(!(typeof g=="undefined"||g==null))if(typeof e[g]=="undefined"){e[g]=1;h++}}e={};var j=document.createDocumentFragment(),k=0,o={};for(i in c){g=c[i];if(g!=null){var l=g[f.value],m=g[f.text];if(b=="master"||b=="producer")m=g.tSpell+" "+m;if(!(l==
null||l==""||m==null||m=="")){var n=g.goid;if((b=="master"||b=="producer")&&o[g.tSpell]==null){o[g.tSpell]="";k++}l={value:l,text:m};if((b=="master"||b=="producer")&&k%2==0)l.bgcolor=this.optionBackColor;if(h>=2&&e[n]==null){e[n]=1;n=this.groupOprtionStyle;n.text=g.goname;j.appendChild(DomHelper.createGroupOption(n))}j.appendChild(DomHelper.createOption(l))}}}d.appendChild(j);c=this.getRelatObjctType(b,1);if(c!=null){var p=this;d.onchange=function(){p.DropDownChange(b,f.value)};this.BindDefaultValue(c)}}}};
a.getRelatObjctType=function(b,c){b=this.getIndexType(b);var d=[];for(obj in this.SelectList)d.push(obj);b+=c;if(b<0||b>d.length)return null;return d[b]};a.getIndexType=function(b){var c=0;for(obj in this.SelectList){if(obj==b.toLowerCase())return c;c++}};
a.getDefaultValue=function(b){switch(b){case "producer":return{value:"0",text:"\u8bf7\u9009\u62e9\u5382\u5546"};case "master":return{value:"0",text:"\u8bf7\u9009\u62e9\u54c1\u724c"};case "brand":return{value:"0",text:"\u8bf7\u9009\u62e9\u54c1\u724c"};case "serial":return{value:"0",text:"\u8bf7\u9009\u62e9\u7cfb\u5217"};case "cartype":return{value:"0",text:"\u8bf7\u9009\u62e9\u8f66\u6b3e"};default:return null}};
a.DropDownChange=function(b,c){var d=this.GetValue(b),f=this.getRelatObjctType(b,1),e=this.Data[b],h=this.Abbreviation[b.toLowerCase()];h=new RegExp(h,"g");for(index in e)if(e[index][c]==d){this.BindList(f,index.replace(h,""));return}this.BindList(b,0)};a.BindDefaultValue=function(b){var c=this.SelectList[b];if(c!=null)if(c.selectid=="")this.BindDefaultValue(this.getRelatObjctType(b,1));else{if(c=document.getElementById(c.selectid)){var d=this.getRelatObjctType(b,1);DomHelper.clearDomObject(c);c.appendChild(DomHelper.createOption(this.getDefaultValue(b)))}this.BindDefaultValue(d)}};
function InitDropDownList(b,c,d,f){this.slist=b;this.abbrlist=ParamsAbbr;this.gosobject=ParamsGos;this.url=c;this.EnCode=d;this.CheckData=f;this.BindSelect={}}InitDropDownList.prototype.InitBindSelect=function(){this.BindSelect=new BindSelect(this.url,this.slist,this.CheckData,{},this.abbrlist,this.gosobject,this.EnCode,backgroup);this.BindSelect.BindList()};

