Buyma.Request={selects:["lstCategory1","lstCategory2","lstCategory3"],init:function(){this._setChangeHandler();$(".popup_box_rss").dialog({bgiframe:true,modal:true,autoOpen:false,draggable:false,resizable:false,width:390,title:"RSSリーダーで購読",close:function(event,ui){$("#comment_error").hide();}});$(".popup_rss").click(function(){$(".popup_box_rss").dialog("open");});},_removeSelect:function(depth){var select_node=this.selects[depth];$("#"+select_node+"wrap").slideUp().empty();},_appendSelect:function(depth){var select_node=this.selects[depth];var class_name=depth==1?"lstCategory":"";$("#"+select_node+"wrap").append('<select name="'+select_node+'" id="'+select_node+'" class="'+class_name+'">').fadeIn();},_appendOptions:function(depth,children){var select_node=this.selects[depth];$('<option value="">全て</option>').appendTo("#"+select_node);$.each(children,function(key,value){$('<option value="'+key+'">'+value+"</option>").appendTo("#"+select_node);});},_disableSelect:function(depth){var self=this.selects[depth-1];var wrap_div=$("#"+self).parent(".lstCategoryWrap");wrap_div.addClass("loading");$("#"+self).get(0).disabled=true;if(depth==2){$("#"+this.selects[depth-2]).get(0).disabled=true;}},_enableSelect:function(depth){var self=this.selects[depth-1];var wrap_div=$("#"+self).parent(".lstCategoryWrap");wrap_div.removeClass("loading");$("#"+self).get(0).disabled=false;if(depth==2){$("#"+this.selects[depth-2]).get(0).disabled=false;}},_setChangeHandler:function(){var bm_req=this;$(".lstCategory").unbind("change");$(".lstCategory").bind("change",function(){var category_id=this.options[this.selectedIndex].value;var depth=this.id.replace(/lstCategory/,"");bm_req._removeSelect(2);if(depth==1){bm_req._removeSelect(1);}if(category_id==""){return;}$.ajax({dataType:"jsonp",type:"GET",url:"/api/categoryselect/getchild/",cache:false,data:{category_id:category_id},beforeSend:function(){bm_req._disableSelect(depth);},success:function(res){bm_req._removeSelect(depth);if(res.child_num>0){bm_req._appendSelect(depth);bm_req._appendOptions(depth,res.children);bm_req._setChangeHandler();}bm_req._enableSelect(depth);},error:function(x,textStatus,errorThrown){bm_req._enableSelect(depth);}});});},makeUrl_reqSearch:function(){var ls_url;var cnd_cate="";var cnd_keyword="";var cnd_brand="";var cnd_sts="";var form=document.formcond;var c1=form.lstCategory1;var c2=form.lstCategory2;var c3=form.lstCategory3;if(c3&&c3.options[c3.selectedIndex].value!=0){cnd_cate=c3.options[c3.selectedIndex].value;}else{if(c2&&c2.options[c2.selectedIndex].value!=0){cnd_cate=c2.options[c2.selectedIndex].value;}else{if(c1.options[c1.selectedIndex].value!=0){cnd_cate=c1.options[c1.selectedIndex].value;}else{cnd_cate="";}}}cnd_keyword=form.txtKeyword.value;cnd_brand=form.brandNm.value;index=form.lstResponseSeiyaku.selectedIndex;if(form.lstResponseSeiyaku.options[index].value!=0){cnd_sts=form.lstResponseSeiyaku.options[index].value;}form.post_action.value="1";form.cat.value=cnd_cate;ls_url=this._makeUrl_reqCom(cnd_keyword,cnd_brand,cnd_cate,cnd_sts);form.action=ls_url;form.submit();return;},_makeUrl_reqCom:function(ps_freewd,ps_brand,ps_cate,ps_sts){var cnd_kwd=ps_freewd;var cnd_brand=ps_brand;var cnd_cate=ps_cate;var cnd_sts=ps_sts;var ls_pos;var ls_strwk;var ls_url="/request/r/";var index=0;ls_pos=ls_url.indexOf("/cat/",11);if(ls_pos==-1){ls_pos=ls_url.indexOf("/cat/",11);}if(ls_pos!=-1){ls_strwk=ls_url.substring(ls_pos+5,ls_pos+5+4);if(ls_strwk.match(/\D\D\D\D/g)){ls_pos=-1;}}if(ps_brand!=""){ls_url+="_"+ps_brand+"/";}if(ls_pos!=-1&&cnd_cate!=""){ls_strwk=ls_url;ls_url=ls_strwk.substring(0,ls_pos+5)+cnd_cate+ls_strwk.substring(ls_pos+5+4,ls_strwk.length);ls_url=ls_url+"/";}if(ls_pos!=-1&&cnd_cate==""){ls_strwk=ls_url;ls_url=ls_strwk.substring(0,ls_pos)+ls_strwk.substring(ls_pos+5+4,ls_strwk.length);ls_url=ls_url+"/";ls_url=ls_url.replace("//","/");}if(ls_pos==-1&&cnd_cate!=""){if(ls_url=="/request/r/"){ls_url=ls_url+"cat/"+cnd_cate+"/";}else{ls_url=ls_url+"cat/"+cnd_cate+"/";}}cnd_kwd=cnd_kwd.replace(/^[ ]+|[ ]+$/g,"");if(cnd_kwd!=""){ls_url=ls_url+"key/";ls_url=ls_url.replace("//","/");}if(cnd_kwd!=""){ls_url=ls_url+encodeURI(cnd_kwd);}if(cnd_kwd!=""){ls_url=ls_url+"/";}if(cnd_sts!=""){ls_url=ls_url+"res/";ls_url=ls_url.replace("//","/");}if(cnd_sts!=""){ls_url=ls_url+cnd_sts;}if(cnd_sts!=""){ls_url=ls_url+"/";}return ls_url;}};$(function(){Buyma.Request.init();});
