/*!
* cxSelect 1.3.2
* http://code.ciaoca.com/
* https://github.com/ciaoca/cxSelect
* E-mail: ciaoca@gmail.com
* Released under the MIT license
* Date: 2013-05-15
*/
!function(a){a.fn.cxSelect=function(b){var c={settings:a.extend({},a.cxSelect.defaults,b),dom:{box:this}};c.init=function(){var c,b=this;if(b.dom.box.length&&b.settings.selects.length){for(b.selectArray=[],b.selectSum=b.settings.selects.length,c=0;c<b.selectSum&&b.dom.box.find("select."+b.settings.selects[c]);c++)b.selectArray.push(b.dom.box.find("select."+b.settings.selects[c]));b.selectSum=b.selectArray.length,b.selectSum&&("string"==typeof b.settings.url?a.getJSON(b.settings.url,function(a){b.dataJson=a,b.buildContent()}):"object"==typeof b.settings.url&&(b.dataJson=b.settings.url,b.buildContent()))}},c.isArray=function(a){return"function"==typeof Array.isArray?Array.isArray(a):"[object Array]"===Object.prototype.toString.call(a)},c.getIndex=function(a){return this.settings.required?a:a-1},c.getNewOptions=function(b,c){var d,e,f,g,h;if(b)return d=this.settings.firstTitle,e=this.settings.firstValue,f=b.data("firstTitle"),g=b.data("firstValue"),h="",("string"==typeof f||"number"==typeof f||"boolean"==typeof f)&&(d=f.toString()),("string"==typeof g||"number"==typeof g||"boolean"==typeof g)&&(e=g.toString()),this.settings.required||(h='<option value="'+e+'">'+d+"</option>"),a.each(c,function(a,b){h+="string"==typeof b.v||"number"==typeof b.v||"boolean"==typeof b.v?'<option value="'+b.v+'">'+b.n+"</option>":'<option value="'+b.n+'">'+b.n+"</option>"}),h},c.buildContent=function(){var b,a=this;a.dom.box.on("change","select",function(){a.selectChange(this.className)}),b=a.getNewOptions(a.selectArray[0],a.dataJson),a.selectArray[0].html(b).prop("disabled",!1).trigger("change"),a.setDefaultValue()},c.setDefaultValue=function(a){var b,c;a=a||0,b=this,a>=b.selectSum||!b.selectArray[a]||(c=b.selectArray[a].data("value"),("string"==typeof c||"number"==typeof c||"boolean"==typeof c)&&(c=c.toString(),setTimeout(function(){b.selectArray[a].val(c).trigger("change"),a++,b.setDefaultValue(a)},1)))},c.selectChange=function(a){var b,c,d,e,f,g;for(a=a.replace(/ /g,","),a=","+a+",",b=[],g=0;g<this.selectSum;g++)b.push(this.getIndex(this.selectArray[g].get(0).selectedIndex)),"number"==typeof c&&g>c&&(this.selectArray[g].empty().prop("disabled",!0),"none"===this.settings.nodata?this.selectArray[g].css("display","none"):"hidden"===this.settings.nodata&&this.selectArray[g].css("visibility","hidden")),a.indexOf(","+this.settings.selects[g]+",")>-1&&(c=g);for(d=c+1,e=this.dataJson,g=0;d>g;g++){if("undefined"==typeof e[b[g]]||this.isArray(e[b[g]].s)===!1||!e[b[g]].s.length)return;e=e[b[g]].s}this.selectArray[d]&&(f=this.getNewOptions(this.selectArray[d],e),this.selectArray[d].html(f).prop("disabled",!1).css({display:"",visibility:""}).trigger("change"))},c.init()},a.cxSelect={defaults:{selects:[],url:null,nodata:null,required:!1,firstTitle:"请选择",firstValue:"0"}}}(jQuery);