var ARRAY_FOR_RRICE_RECORD=[{name:"categoryName",type:"string"},{name:"specId",type:"int"},{name:"maker",type:"string"},{name:"model",type:"string"},{name:"price",type:"int"},{name:"shop",type:"string"},{name:"shopUrl",type:"string"}];var arrayForCombination=[{name:"shop",type:"string"},{name:"shopUrl",type:"string"},{name:"sum",type:"int"},{name:"price1",type:"int"},{name:"price2",type:"int"}];Ext.ns("Ext.pp");Ext.ns("Ext.ux.grid");Ext.pp.ModelSearchForm=Ext.extend(Ext.FormPanel,{onRender:function(A,B){Ext.pp.ModelSearchForm.superclass.onRender.call(this,A,B);Ext.apply(this.getForm(),{url:this.config.url,classId:this.initialConfig.classId})},initComponent:function(){if(!this.config){this.config={url:"http://www.parts-price.com/search/searchmodel.html"}}Ext.applyIf(this,{url:this.config.url,standardSubmit:true,labelWidth:58,autoHeight:true,width:238,frame:true,collapsible:true,collapsed:true,header:true,title:"型式検索(全カテゴリ対象)",onSubmit:Ext.emptyFn,submit:function(){this.getForm().getEl().dom.submit()},buttons:[{text:"検索",handler:function(){var C=this.ownerCt;if(C.getForm().isValid()){if(C.url){C.getForm().getEl().dom.action=C.url}if(C.baseParams){for(B in C.baseParams){C.add({xtype:"hidden",name:B,value:C.baseParams[B]})}C.doLayout()}C.getForm().submit()}}}]});Ext.pp.ModelSearchForm.superclass.initComponent.call(this);this.add(new Ext.form.Hidden({name:"cmd",value:this.initialConfig.cmd}));var A=this.getComboParamArray();for(var B=0;B<A.length;++B){this.add(new Ext.form.ComboBox(A[B]))}},getComboParamArray:function(){var A=new Array();A.push({xtype:"combo",listClass:"textleft",value:this.initialConfig.formConfig["modelinit"],width:160,autoHeight:true,store:this.getModelStore(),name:"model",forceSelection:false,typeAhead:false,selectOnFocus:false,queryParam:"query",displayField:"model",valueField:"model",mode:"remote",minChars:3,triggerAction:"query",emptyText:"型式を入力してください",fieldLabel:"型式"});return A},getModelStore:function(){var D=Ext.data.Record.create([{name:"specId"},{name:"model"},{name:"url"}]);var A=new Ext.data.JsonReader({root:"model"},D);var C=new Ext.data.ScriptTagProxy({url:"http://www.parts-price.com/phps/form/models.php",method:"GET",nocache:true,callbackParam:"callback"});var B=new Ext.data.Store({reader:A,proxy:C});return B}});Ext.reg("modelsearchform",Ext.pp.ModelSearchForm);Ext.pp.ClassSearchForm=Ext.extend(Ext.pp.ModelSearchForm,{initComponent:function(){this.config={url:document.URL};Ext.applyIf(this,{title:this.initialConfig.formConfig["categoryName"]+"価格検索",autoHeight:true});Ext.pp.ClassSearchForm.superclass.initComponent.call(this);this.add(new Ext.form.Hidden({name:"classid",value:this.initialConfig.classId}))},getComboParamArray:function(){var A=new Array();if(this.initialConfig.formConfig["makerField"]){A.push(this.getMakerComboParam())}for(var B=1;B<4;B++){if(this.initialConfig.formConfig["spec"+B+"Field"]){A.push(this.getSpecComboParam(B))}}A.push(this.getPriceComboParam());return A},getPriceComboParam:function(){return{store:this.getPriceStore(),width:160,value:this.initialConfig.formConfig["priceinit"],listClass:"textleft",forceSelection:true,typeAhead:false,selectOnFocus:false,displayField:"title",hiddenName:"price",valueField:"price",triggerAction:"all",mode:"local",emptyText:"すべて",fieldLabel:"価格帯"}},getPriceStore:function(){var E=new Array(this.initialConfig.formConfig["prices"].length);E[0]=new Array("ALL","すべて");for(var D=1;D<this.initialConfig.formConfig["prices"].length;++D){E[D]=new Array(this.initialConfig.formConfig["prices"][D-1]+"-"+(this.initialConfig.formConfig["prices"][D]-1),this.initialConfig.formConfig["priceTitles"][D])}var F=Ext.data.Record.create([{name:"price",mpping:1},{name:"title",mpping:2}]);var A=new Ext.data.ArrayReader({id:0},F);var C=new Ext.data.MemoryProxy(E);var B=new Ext.data.Store({reader:A,proxy:C});B.load();return B},getSpecComboParam:function(A){return{store:this.getSpecStore(A),width:160,listClass:"textleft",value:this.initialConfig.formConfig["spec"+A+"init"],forceSelection:true,typeAhead:false,selectOnFocus:false,displayField:"title",hiddenName:"spec"+A,valueField:"spec"+A,triggerAction:"all",emptyText:"すべて",minChars:1,mode:"local",fieldLabel:this.initialConfig.formConfig["spec"+A+"Label"]}},getSpecStore:function(C){var D=this.initialConfig.formConfig["spec"+C+"Value"];var E=Ext.data.Record.create([{name:("spec"+C),mpping:1},{name:"title",mpping:2}]);var A=new Ext.data.ArrayReader({id:0},E);var B=new Ext.data.Store({reader:A,proxy:new Ext.data.MemoryProxy(D)});B.load();return B},getMakerComboParam:function(){return{xtype:"combo",width:160,value:this.initialConfig.formConfig["makerinit"],listClass:"textleft",store:this.getMakerStore(),name:"maker",forceSelection:false,typeAhead:true,selectOnFocus:true,displayField:"makerName",hiddenName:"makerid",valueField:"makerId",mode:"remote",minChars:1,triggerAction:"all",emptyText:"全メーカー",fieldLabel:"メーカー"}},getMakerStore:function(){var C=Ext.data.Record.create([{name:"makerId"},{name:"makerName"},{name:"url"}]);var A=new Ext.data.JsonReader({root:"maker"},C);var B=new Ext.data.ScriptTagProxy({url:"http://www.parts-price.com/phps/form/makers.php",nocache:true,callbackParam:"callback"});return new Ext.data.Store({reader:A,proxy:B,baseParams:{classid:this.initialConfig.classId}})}});Ext.reg("classsearchform",Ext.pp.ClassSearchForm);var setMiniPrice=function(G){var A=G.getStore();A.on("update",function(I,J,L){var K=A.getSortState();if(K==undefined){K={field:"price",direction:"asc"}}A.sort(K.field,K.direction)});var F=A.getCount();var D=new Array("rakuten","yahoo","amazon","kakakucom","ecnavi","coneco");for(var C=0;C<A.getCount();C++){var H=A.getAt(C);for(var B=0;B<D.length;++B){var E=new Ext.pp.MinPriceFromApi(H,D[B]);E.load()}}};Ext.pp.MinPriceFromApi=function(B,A){this.modelName=B.get("model");this.rec=B;this.apiUrl=A;this.getRecord=function(){var C=Ext.data.Record.create([{name:"specId",type:"int",mapping:"SPEC"},{name:"shopName",type:"string",mapping:"SHOPNAME"},{name:"shopUrl",type:"string",mapping:"SHOPURL"},{name:"price",type:"int",mapping:"PRICE"}]);return C};this.getReader=function(){var C=new Ext.data.JsonReader({totalProperty:"count",root:"items"},this.getRecord());return C};this.getProxy=function(){var C=new Ext.data.ScriptTagProxy({url:"http://www.parts-price.com/phps/"+this.apiUrl+"/byname.php",nocache:true,callbackParam:"callback"});return C};this.getStore=function(){var C=new Ext.data.Store({reader:this.getReader(),proxy:this.getProxy(),listeners:{load:function(F,I,J){var H=F.getCount();for(var E=0;E<H;++E){var G=J.rec.get("price");var D=I[E].get("price");if(G>D){J.rec.set("price",D)}}}}});return C};this.load=function(){if(this.modelName.toUpperCase().indexOf("</A>",0)!=-1){var E=this.modelName.toUpperCase().indexOf(">",0)+1;var D=this.modelName.toUpperCase().indexOf("</A>");this.modelName=this.modelName.substr(E,D-E)}var C=this.getStore();C.load({params:{modelname:this.modelName},rec:this.rec})}};function searchPriceById(A){searchPrice(A,document.URL)}function searchNewItemPrice(A){searchPrice(A,"http://www.parts-price.com/search/searchmodel.html")}function searchPrice(A,B){var E=document.createElement("form");E.id="priceSearchForm";E.method="POST";E.action=B;document.body.appendChild(E);var D=document.createElement("input");D.type="hidden";D.name="specid";D.value=A;E.appendChild(D);var D=document.createElement("input");D.type="hidden";D.name="cmd";D.value="result";E.appendChild(D);var F=new Array("spec1","spec2","spec3","maker","price","model");if(typeof config!="undefined"){for(var C=0;C<F.length;++C){if(config[(F[C]+"init")]){var D=document.createElement("input");D.type="hidden";D.name=F[C];D.value=config[(F[C]+"init")];E.appendChild(D)}}}E.submit()}var setApiPrice=function(D){var A=D.getStore();var B=new Array("rakuten","yahoo","kakakucom","ecnavi","coneco","amazon");var C=new Ext.pp.PriceFromApi(specId,B,A);C.load()};Ext.pp.PriceFromApi=function(B,C,A){this.modelName=A.getAt(0).get("modelname");this.makerName=A.getAt(0).get("makername");this.specId=B;this.priceStore=A;this.apiUrls=C;this.getRecord=function(){var D=Ext.data.Record.create([{name:"specId",type:"int",mapping:"SPEC"},{name:"shopName",type:"string",mapping:"SHOPNAME"},{name:"shopUrl",type:"string",mapping:"SHOPURL"},{name:"price",type:"int",mapping:"PRICE"}]);return D};this.getReader=function(){var D=new Ext.data.JsonReader({totalProperty:"count",root:"items"},this.getRecord());return D};this.getProxy=function(){var D=new Ext.data.HttpProxy({url:"http://www.parts-price.com/phps/"+this.apiUrls.shift()+"/byid.php",method:"GET",nocache:true});return D};this.getStore=function(){var D=new Ext.data.Store({reader:this.getReader(),proxy:this.getProxy(),listeners:{load:function(R,E,H){var P=H.store;var N=R.getCount();var Q=Ext.data.Record.create([{type:"string",name:"shopname"},{type:"string",name:"modelname"},{type:"string",name:"makername"},{type:"string",name:"shop"},{type:"int",name:"price"},{type:"int",name:"difference"},{type:"string",name:"button"}]);var O=new Array();for(var L=0;L<N;++L){var K=E[L].get("shopName");var J=E[L].get("shopUrl");var G='<a href="'+J+'" target="_blank">'+K+"</a>";var I=new Q({shopname:K,makername:H.makername,modelname:H.modelname,shop:G,price:E[L].get("price"),difference:0,button:""});O.push(I)}P.add(O);if(!Ext.isIE6){var F=P.getSortState();if(F==undefined){F={field:"price",direction:"asc"}}P.sort(F.field,F.direction)}if(H.apiurls.length>0){var M=new Ext.pp.PriceFromApi(H.specid,H.apiurls,P);M.load()}else{var F=P.getSortState();if(F==undefined){F={field:"price",direction:"asc"}}P.sort(F.field,F.direction)}}}});return D};this.load=function(){var D=this.getStore();D.load({params:{specid:this.specId},store:this.priceStore,apiurls:this.apiUrls,specid:this.specId,makername:this.makerName,modelname:this.modelName})}};updateCombinationGrid=function(){if(combiGrid!=undefined){combiGrid.reconfigure(combiGrid.getDataStore(),new Ext.grid.ColumnModel(combiGrid.getColumnsArray()))}else{combiGrid=new Ext.pp.CombinationGrid({renderTo:"combination-list",title:"組み合わせ価格"})}};Ext.pp.CombinationGrid=Ext.extend(Ext.grid.GridPanel,{initComponent:function(){Ext.apply(this,{autoScroll:true,autoHeight:true,collapsible:true,closable:true,ds:this.getDataStore(),selModel:new Ext.grid.RowSelectionModel({singleSelect:false}),header:true,columns:this.getColumnsArray()});Ext.pp.CombinationGrid.superclass.initComponent.call(this)},getColumnsArray:function(){var C=new Array({id:"shop",header:"販売店",width:110,sortable:false,dataIndex:"shop",hideable:false,renderer:function(H,G,D,I,F,E){return D.get("shopUrl")}});var A=listGrid.getStore();for(var B=0;B<A.getCount();B++){C.push({header:A.getAt(B).get("model"),width:90,sortable:false,dataIndex:"price"+(B+1),hideable:false,renderer:japanMoneyRenderer})}C.push({header:"合計",width:90,sortable:true,dataIndex:"sum",hideable:false,renderer:japanMoneyRenderer});return C},getRecordArray:function(){var A=listGrid.getStore();if(A.getCount()>2){for(var B=2;B<A.getCount();B++){var C={name:("price"+(B+1)),type:"int"};arrayForCombination.push(C)}}return arrayForCombination},getReader:function(){return new Ext.data.JsonReader({root:"price"},new Ext.data.Record.create(this.getRecordArray()))},getSpecId:function(){var A=listGrid.getStore();var C=new Array();for(var B=0;B<A.getCount();B++){C.push(A.getAt(B).get("specId"))}return C.join(",")},getDataStore:function(){return new Ext.data.Store({reader:this.getReader(),pruneModifiedRecords:true,baseParams:{specid:this.getSpecId()},autoLoad:true,proxy:new Ext.data.HttpProxy({url:"http://www.parts-price.com/phps/parts-price/combination.php",method:"POST",nocache:true}),sortInfo:{field:"sum",direction:"ASC"}})}});Ext.reg("combigrid",Ext.pp.CombinationGrid);Ext.pp.CalculateGrid=Ext.extend(Ext.grid.GridPanel,{initComponent:function(){Ext.apply(this,{autoScroll:true,enableColumnResize:true,autoHeight:true,collapsible:true,closable:true,enableDragDrop:true,ds:this.getDataStore(),selModel:new Ext.grid.RowSelectionModel({singleSelect:false}),view:new Ext.grid.GroupingView({forceFit:false,showGroupName:false,enableGroupingMenu:false,enableNoGroups:false,hideGroupedColumn:true}),plugins:new Ext.ux.grid.GridSummary(),tbar:[{iconCls:"simulator-remove",icon:"http://www.parts-price.com/images/icons/delete.gif",disabled:true,text:"削除",tooltip:"選択した商品を表から削除します",handler:function(btn,event){var grid=listGrid;var removeRecs=new Array();var records=grid.getSelectionModel().getSelections();for(var i=0;i<records.length;++i){grid.getStore().remove(records[i]);var rec={makername:records[i].get("maker"),modelname:records[i].get("model"),shopname:records[i].get("shop")};removeRecs.push(rec)}var myForm=document.createElement("FORM");myForm.id="listDeleteForm";document.body.appendChild(myForm);var form=new Ext.form.BasicForm(myForm,{method:"POST",url:"http://www.parts-price.com/phps/deleteshoppinglist.php"});form.submit({params:{list:Ext.util.JSON.encode(removeRecs)},success:function(f,a){document.body.removeChild(document.getElementById("listDeleteForm"));var store=listGrid.getStore();var sortState=store.getSortState();store.sort(sortState.field,sortState.direction)},failure:function(f,a){}})}},{iconCls:"simulator-excel",icon:"http://www.parts-price.com/images/icons/excel.gif",disabled:true,text:"Excel",tooltip:"表の内容をEXCELファイルに変換します",handler:function(btn,evnt){var grid=listGrid;var store=grid.getStore();var params=new Array();for(var i=0;i<store.getCount();i++){var rec=store.getAt(i);var param={};for(var j=0;j<ARRAY_FOR_RRICE_RECORD.length;j++){var name=ARRAY_FOR_RRICE_RECORD[j].name;param[name]=rec.get(name)}params.push(param)}var data=Ext.util.JSON.encode(params);var myForm=document.createElement("FORM");document.body.appendChild(myForm);with(myForm){method="post";action="http://www.parts-price.com/phps/toexcel.php";target="_blank"}var param=document.createElement("input");param.setAttribute("type","hidden");param.setAttribute("name","store");param.setAttribute("value",data);myForm.appendChild(param);with(myForm){submit()}document.body.removeChild(myForm)}},{iconCls:"simulator-go",icon:"http://www.parts-price.com/images/icons/calculator_go.png",disabled:true,text:"to iPhone",tooltip:"表の内容をiPhoneに送ります",handler:function(btn,evnt){Ext.Msg.prompt("メールアドレスの入力","メールアドレス",function(btn,text){if(btn!="ok"){return }if(!text.match("^[0-9A-Za-z._-]+@[0-9A-Za-z.-]+$")){Ext.Msg.alert("メールアドレスのエラー","メールアドレスが不正です。最初からやり直してください");return }var myForm=document.createElement("FORM");myForm.id="iphoneForm";document.body.appendChild(myForm);var form=new Ext.form.BasicForm(myForm,{baseParams:{email:text},method:"POST",url:"http://www.parts-price.com/phps/toiphone.php",reader:new Ext.data.JsonReader({root:"messages"},Ext.data.Record.create([{name:"msg",type:"string"}]))});var grid=listGrid;var store=grid.getStore();var params=new Array();for(var i=0;i<store.getCount();i++){var rec=store.getAt(i);var param={};for(var j=0;j<ARRAY_FOR_RRICE_RECORD.length;j++){var name=ARRAY_FOR_RRICE_RECORD[j].name;param[name]=rec.get(name)}params.push(param)}var data=Ext.util.JSON.encode(params);form.submit({params:{store:data},success:function(f,a){Ext.Msg.alert('<div style="text-align:center;">メール送信完了',"指定されたアドレス宛にメールを送信しました。<br />iPhoneで受信後，指定されたURLにアクセスしてください。</div>");document.body.removeChild(document.getElementById("iphoneForm"))},failure:function(f,a){Ext.Msg.alert("エラー","送信に失敗しました。メールアドレスの入力からやり直してください。");document.body.removeChild(document.getElementById("iphoneForm"))}})})}}],header:true});Ext.applyIf(this,{columns:[{id:"model",header:"型式",width:200,sortable:false,dataIndex:"model",summaryType:"count",hideable:false,summaryRenderer:function(v,params,data){return"("+v+"点)"}},{header:"分類",width:10,sortable:false,dataIndex:"categoryName",hideable:true,summaryType:"count"},{header:"価格",width:80,sortable:false,dataIndex:"price",renderer:japanMoneyRenderer,hideable:false,summaryType:"sum"},{header:"販売店",width:200,sortable:false,dataIndex:"shop",hideable:false,summaryType:"onceCount",renderer:function(value,metadata,record,rowIndex,colIndex,store){return record.get("shopUrl")},summaryRenderer:function(v,params,data){return"("+v+"軒)"}}]});Ext.pp.CalculateGrid.superclass.initComponent.call(this);this.getSelectionModel().on("selectionchange",function(sm){var records=sm.getSelections();var tbar=listGrid.getTopToolbar();tbar.items.get(0).setDisabled((records.length==0))});this.getStore().on("add",function(s,recs,idx){var tbar=listGrid.getTopToolbar();tbar.items.get(1).setDisabled(false);tbar.items.get(2).setDisabled(false);if(s.getCount()>1){updateCombinationGrid()}});this.getStore().on("remove",function(s,rec,idx){var tbar=listGrid.getTopToolbar();tbar.items.get(1).setDisabled((s.getCount()==0));tbar.items.get(2).setDisabled((s.getCount()==0));if(s.getCount()>1){updateCombinationGrid()}else{if(combiGrid!=undefined){combiGrid.hide()}}});this.getStore().on("load",function(s,rec,opt){var tbar=listGrid.getTopToolbar();tbar.items.get(1).setDisabled((s.getCount()==0));tbar.items.get(2).setDisabled((s.getCount()==0));if(s.getCount()>1){updateCombinationGrid()}});this.getColumnModel().setHidden(1,true)},getReader:function(){return new Ext.data.JsonReader({root:"list"},new Ext.data.Record.create([{name:"categoryName",type:"string",mapping:"categoryname"},{name:"specId",type:"int",mapping:"specid"},{name:"maker",type:"string",mapping:"makername"},{name:"model",type:"string",mapping:"modelname"},{name:"price",type:"int",mapping:"price"},{name:"shop",type:"string",mapping:"shopname"},{name:"shopUrl",type:"string",mapping:"shopurl"}]))},getDataStore:function(){return new Ext.data.GroupingStore({reader:this.getReader(),autoLoad:true,proxy:new Ext.data.HttpProxy({url:"http://www.parts-price.com/phps/shoppinglist.php",method:"GET",nocache:true}),sortInfo:{field:"model",direction:"ASC"},groupField:"categoryName"})}});Ext.reg("calcgrid",Ext.pp.CalculateGrid);function addShoppingList(rowindex){var rec=priceGrid.getStore().getAt(rowindex);var params={};var fieldNames=new Array("shopname","makername","modelname","shop","price");params.specid=specId;for(var i=0;i<fieldNames.length;i++){params[fieldNames[i]]=rec.get(fieldNames[i])}var myForm=document.createElement("FORM");myForm.id="listForm";document.body.appendChild(myForm);var form=new Ext.form.BasicForm(myForm,{method:"POST",url:"http://www.parts-price.com/phps/addshoppinglist.php"});form.submit({params:{rec:Ext.util.JSON.encode(params)},success:function(f,a){document.body.removeChild(document.getElementById("listForm"));var ListRecord=Ext.data.Record.create(ARRAY_FOR_RRICE_RECORD);var rec=new ListRecord({categoryName:a.result.json.categoryname,specId:eval(a.result.json.specid),maker:a.result.json.makername,model:a.result.json.modelname,price:eval(a.result.json.price),shop:a.result.json.shopname,shopUrl:a.result.json.shop});var store=listGrid.getStore();store.add(rec);var sortState=store.getSortState();store.sort(sortState.field,sortState.direction);tabView.selectTab(3)},failure:function(f,a){}})}Ext.pp.ContactPanel=Ext.extend(Ext.Panel,{initComponent:function(){Ext.apply(this,{id:"contact-panel",title:"お問い合わせフォーム",height:600,renderTo:"contact-form",autoScroll:true,header:true,layout:"border",items:[{xtype:"contactformpanel"},{region:"center",html:'<div id="contact-response">お問い合わせ，ありがとうございます。<br /></div>'}]});Ext.pp.ContactPanel.superclass.initComponent.call(this)}});Ext.reg("contactpanel",Ext.pp.ContactPanel);Ext.pp.ContactFormPanel=Ext.extend(Ext.FormPanel,{onRender:function(A,B){Ext.pp.ContactFormPanel.superclass.onRender.call(this,A,B);Ext.apply(this.getForm(),{url:"http://www.parts-price.com/contact.html",method:"POST"})},initComponent:function(){Ext.apply(this,{border:false,title:"お問い合わせ",region:"north",labelWidth:60,autoHeight:true,frame:true,autoScroll:true,collapsible:true,header:true,buttons:[{text:"送信",id:"contact-submit",handler:function(){var A=this.ownerCt.getForm();A.submit({success:function(C,D){var B=document.getElementById("contact-response");var E=Ext.util.JSON.decode(D.response.responseText);B.innerHTML=E.msg;C.reset()},failure:function(B,C){alert("送信できませんでした。再度送信してください。")}})}}],items:[new Ext.form.TextField({fieldLabel:"お名前",width:500,allowBlank:false,name:"Name"}),new Ext.form.TextField({fieldLabel:"e-mail",name:"email",width:500,vtype:"email",vtypeText:"メールアドレスを入力してください。"}),new Ext.form.TextArea({fieldLabel:"内容",name:"comments",width:500,height:200,grow:false,allowBlank:false}),new Ext.form.Hidden({name:"formid",value:"feedbackForm"})]});Ext.pp.ContactFormPanel.superclass.initComponent.call(this)}});Ext.reg("contactformpanel",Ext.pp.ContactFormPanel);
