KUS.MakeAnOffer.OfferWindow=Ext.extend(Ext.Window,{acceptOffer:function(){if(!this.quantityField.isValid()){return this.quantityField.getEl().frame("CC0000",1,{duration:0.5})}if(!this.offerField.isValid()){return this.offerField.getEl().frame("CC0000",1,{duration:0.5})}var a={id:this.getOfferId(),psid:this.getProductStylesField().getValue().getRawValue()};a.handler="Orders";a.method="acceptOffer";var b=this.acceptOfferCallback.createDelegate(this);Ext.Ajax.request({url:"/ajax",params:a,callback:b});Ext.Msg.show({title:"Adding to Cart...",closable:false,fn:function(){windw.location.href="/cart"},wait:true,modal:true,buttons:Ext.Msg.OK,msg:"<center>Adding your items to your cart...<br />If the page takes longer than 10 seconds to load please use the button below to view your cart.</center>",width:250})},acceptOfferCallback:function(b,d,a){if(!d){Ext.Msg.alert("Error","There was an error communicating with the server.");return false}var c=Ext.decode(a.responseText);if(!c.success){Ext.Msg.alert("Error",c.err_msg);return false}window.location.href="/cart"},autoHeight:true,bodyStyle:{padding:"7px 0px 5px 10px"},buttonAlign:"center",closable:false,constructor:function(a){var a=a||{};if(a.playersPackageAvailable){this.setPlayersPackageAvailable(a.playersPackageAvailable)}if(a.breakInServiceAvailable){this.setBreakInServiceAvailable(a.breakInServiceAvailable)}if(a.counter){this.setCounter(a.counter)}if(a.offer_id){this.setOfferId(a.offer_id)}this.setProductStyles(a.productStyles);this.setPid((a.pid)?a.pid:prod_id);this.setPrice((a.price)?a.price:prod_price);this.setPsid((a.psid)?a.psid:this.getProductStyles()[0].inputValue);this.setQuantity((a.quantity)?a.quantity:1);this.buttons=[this.getCancelButton()];if(!this.offerId){this.buttons.push(this.getMakeOfferButton())}else{if(this.getCounter()<6){this.buttons.push(this.getCounterOfferButton())}this.buttons.push(this.getAcceptButton(),this.getDeclineButton())}this.items=[this.getProductStylesField(),this.getAskingPriceField(),this.getQuantityField(),this.getOfferField()];if(a.playersPackageAvailable){this.items.push(this.getPlayersPackageField())}if(a.breakInServiceAvailable){this.items.push(this.getBreakInServiceField())}if(a.playersPackageAvailable||a.breakInServiceAvailable){this.labelWidth=150}this.items.push({frame:true,html:"<center>When your offer is accepted your items will automatically be added to your cart.</center>"});KUS.MakeAnOffer.OfferWindow.superclass.constructor.call(this,a)},counterOffer:function(){if(!this.quantityField.isValid()){return this.quantityField.getEl().frame("CC0000",1,{duration:0.5})}if(!this.offerField.isValid()){return this.offerField.getEl().frame("CC0000",1,{duration:0.5})}var a={id:this.getOfferId(),quantity:this.getQuantityField().getValue(),price:this.getOfferField().getValue(),psid:this.getProductStylesField().getValue().getRawValue()};a.players_package=(this.getPlayersPackageAvailable())?(this.getPlayersPackageField().getValue()?1:0):0;a.break_in_service=(this.getBreakInServiceAvailable())?(this.getBreakInServiceField().getValue()?1:0):0;a.handler="Orders";a.method="counterOffer";var b=this.counterOfferCallback.createDelegate(this);Ext.Ajax.request({url:"/ajax",params:a,callback:b})},counterOfferCallback:function(b,d,a){if(!d){Ext.Msg.alert("Error","There was an error communicating with the server.");return false}var c=Ext.decode(a.responseText);if(!c.success){Ext.Msg.alert("Error",c.err_msg);return false}this.close();Ext.Msg.alert("Success","Your offer has been submitted. You will get an email indicating whether we have accepted, declined, or countered your offer. If you receive an email indicating we have accepted your offer, your items will be placed into your cart automatically.")},declineOffer:function(){var a={id:this.getOfferId()};a.handler="Orders";a.method="declineOffer";var b=this.declineOfferCallback.createDelegate(this);Ext.Ajax.request({url:"/ajax",params:a,callback:b})},declineOfferCallback:function(b,d,a){if(!d){Ext.Msg.alert("Error","There was an error communicating with the server.");return false}var c=Ext.decode(a.responseText);if(!c.success){Ext.Msg.alert("Error",c.err_msg);return false}this.close()},defaults:{allowBlank:false,anchor:"-20",msgTarget:"side"},frame:true,getAcceptButton:function(){if(!this.acceptButton){this.acceptButton=new Ext.Action({text:"Accept",iconCls:"icon_thumb_up",handler:this.acceptOffer,scope:this})}return this.acceptButton},getAskingPriceField:function(a){if(!this.askingPriceField){this.askingPriceField=new Ext.form.DisplayField({fieldLabel:"Asking Price",value:"<b>"+Ext.util.Format.usMoney(this.getPrice())+"</b>"})}return this.askingPriceField},getBreakInService:function(){return this.breakInService},getBreakInServiceAvailable:function(){if(this.breakInServiceAvailable==undefined){this.setBreakInServiceAvailable(0)}return this.breakInServiceAvailable},getBreakInServiceField:function(){if(!this.breakInServiceField){this.breakInServiceField=new Ext.form.Checkbox({fieldLabel:'<span class="icon icon_information" ext:qwidth="220" ext:qtip="'+this.getBreakInServiceHtml()+'" ext:qtitle="Bat Break-In Service $20.00">Bat Break-In Service</span><br />(Additional $20 each)',inputValue:1,tooltip:this.getBreakInServiceHtml(),checked:this.getBreakInService()})}return this.breakInServiceField},getBreakInServiceHtml:function(){return"<center><p>Don't have the time or resources to break in your bat before your first game? Then let the professionals do it for you! We will break in your bat by hitting 100 softballs.</p><img src='/images/products/thumbs/BBIS.jpg' alt='Bat Break-In Service' /></center>"},getCancelButton:function(){if(!this.cancelButton){this.cancelButton=new Ext.Action({text:"Cancel",iconCls:"icon_cancel",handler:this.close,scope:this})}return this.cancelButton},getCounter:function(){return this.counter},getCounterOfferButton:function(){if(!this.counterOfferButton){this.counterOfferButton=new Ext.Action({handler:this.counterOffer,iconCls:"icon_arrow_redo",scope:this,text:"Counter Offer"})}return this.counterOfferButton},getDeclineButton:function(){if(!this.declineButton){this.declineButton=new Ext.Action({text:"Decline",iconCls:"icon_thumb_down",handler:this.declineOffer,scope:this})}return this.declineButton},getMakeOfferButton:function(){if(!this.makeOfferButton){this.makeOfferButton=new Ext.Action({handler:this.makeOffer,iconCls:"icon_accept",scope:this,text:"Submit Offer"})}return this.makeOfferButton},getOfferField:function(a){if(!this.offerField){this.offerField=new Ext.form.NumberField({allowBlank:false,allowNegative:false,fieldLabel:"<b>Offer Price</b><br />(Price for each item)",value:this.getPrice()})}return this.offerField},getOfferId:function(){return this.offerId},getPid:function(){return this.pid},getPlayersPackage:function(){return this.playersPackage},getPlayersPackageAvailable:function(){if(this.playersPackageAvailable==undefined){this.setPlayersPackageAvailable(0)}return this.playersPackageAvailable},getPlayersPackageField:function(){if(!this.playersPackageField){this.playersPackageField=new Ext.form.Checkbox({checked:this.getPlayersPackage(),fieldLabel:'<span class="icon icon_information" ext:qwidth="380" ext:qtip="'+this.getPlayersPackageHtml()+'" ext:qtitle="Kelly\'s Sports Bat Bag $20.00">Kelly\'s Sports Bat Bag</span><br />(Additional $20 each)',inputValue:1,name:"players_package"})}return this.playersPackageField},getPlayersPackageHtml:function(){return"<center><img src='/images/kellys_bag.jpg' alt='Bat Bag' /></center>"},getPrice:function(){return this.price},getProductStyles:function(){if(!this.productStyles){this.productStyles=[]}return this.productStyles},getProductStylesField:function(){if(!this.styleField){var a=this.getProductStyles();for(i=0;i<a.length;i++){a[i].checked=(a[i].inputValue==this.psid)}this.styleField=new Ext.form.RadioGroup({columns:1,hideLabel:true,items:a,hiddenName:"psid",allowBlank:false,msgTarget:"title",invalidClass:"none",anchor:"0"})}return this.styleField},getQuantity:function(){return this.quantity},getQuantityField:function(){if(!this.quantityField){this.quantityField=new Ext.form.NumberField({allowBlank:false,allowDecimals:false,allowNegative:false,fieldLabel:"<b>Quantity</b>",value:this.getQuantity()})}return this.quantityField},getPsid:function(){return this.psid},makeOffer:function(){if(!this.quantityField.isValid()){return this.quantityField.getEl().frame("CC0000",1,{duration:0.5})}if(!this.offerField.isValid()){return this.offerField.getEl().frame("CC0000",1,{duration:0.5})}var a={pid:this.getPid(),psid:this.getProductStylesField().getValue().getRawValue(),quantity:this.getQuantityField().getValue(),price:this.getOfferField().getValue()};a.players_package=(this.getPlayersPackageAvailable())?(this.getPlayersPackageField().getValue()?1:0):0;a.break_in_service=(this.getBreakInServiceAvailable())?(this.getBreakInServiceField().getValue()?1:0):0;a.handler="Orders";a.method="createBestOffer";var b=this.makeOfferCallback.createDelegate(this);Ext.Ajax.request({url:"/ajax",params:a,callback:b})},makeOfferCallback:function(b,d,a){if(!d){Ext.Msg.alert("Error","There was an error communicating with the server.");return false}var c=Ext.decode(a.responseText);if(!c.success){Ext.Msg.alert("Error",c.err_msg);return false}this.close();Ext.Msg.alert("Success","Your offer has been submitted. You will get an email indicating whether we have accepted, declined, or countered your offer. If you receive an email indicating we have accepted your offer, your items will be placed into your cart automatically.")},layout:"form",labelWidth:70,modal:true,setBreakInService:function(a){this.breakInService=a},setBreakInServiceAvailable:function(a){this.breakInServiceAvailable=a},setCounter:function(a){this.counter=a},setOfferId:function(a){this.offerId=a},setPid:function(a){this.pid=a},setPlayersPackage:function(a){this.playersPackage=a},setPlayersPackageAvailable:function(a){this.playersPackageAvailable=a},setPrice:function(a){this.price=a},setProductStyles:function(b){for(i=0;i<b.length;i++){var a=b[i];this.getProductStyles().push(a)}},setPsid:function(a){this.psid=parseInt(a)},setQuantity:function(a){this.quantity=a},setPsid:function(a){this.psid=a},title:"Make an Offer...",width:370});
