(function(e){var c=e.clx.log.logger("address.js");c.level=e.clx.log.WARN;function a(){if(!(this instanceof a)){return new a();}}e.extend(a.prototype,{revert:function(){},init:function(k,j,m,h){var l=this;l.container=k;l.id=l.container.attr("id");l.displayDiv=l.container.find("div.vcard");c.debug("Initializing account address obj: "+l.id);l.address={};l.address.company=l.displayDiv.children("div.org").text();var n=l.displayDiv.children("div.adr");l.address.country=e.trim(n.children("span.country-name").text());l.address.locality=e.trim(n.children("span.locality").text());l.address.locality=l.address.locality.substring(0,l.address.locality.length-1);l.address.postal=e.trim(n.children("span.postal-code").text());l.address.region=e.trim(n.children("span.region").text());l.address.readableAddress=n.children("div.street-address").html();var l=this;c.debug("Calling validate on ",l.container);l.validator=l.container.validate({hasErrorsKey:h,validationCompleteEvent:m,onValidationComplete:j,api:true});},save:function(){},getRadioValue:function(){return"DEFAULT_ADDRESS_SELECTION";},getCompany:function(){return this.address.company;},getCountry:function(){return this.address.country;},getLocality:function(){return this.address.locality;},getPostal:function(){return this.address.postal;},getReadableStreetAddress:function(){return this.address.readableAddress;},getStreet1:function(){return"";},getStreet2:function(){return"";},getStreet3:function(){return"";},getStreet4:function(){return"";},getRegion:function(){return this.address.region;},getSaveForLater:function(){return"";},getSelectedAddress:function(){return"";},getAlias:function(){return this.getSelectedAddress();},validateAddress:function(){e.clx.validationGroups.getGroup(this.id).validate();}});function b(){if(!(this instanceof b)){return new b();}var h=this;h.disableJavascript=false;}b.prototype=new a();e.extend(b.prototype,{getRadioValue:function(){return"NEW_ADDRESS_SELECTION";},getStreet1:function(){return this.address.street[1];},getStreet2:function(){return this.address.street[2];},getStreet3:function(){return this.address.street[3];},getStreet4:function(){return this.address.street[4];},getReadableStreetAddress:function(){var h=[this.address.street[1]];if(this.address.street[2]!=""){h.push(this.address.street[2]);}if(this.address.street[3]!=undefined&&this.address.street[3]!=""){h.push(this.address.street[3]);}if(this.address.street[4]!=undefined&&this.address.street[4]!=""){h.push(this.address.street[4]);}return h.join("<br />");},setDisableJavascript:function(h){this.disableJavascript=h;},getSaveForLater:function(){return this.saveForLater;},findAndSetSaveForLater:function(){this.saveForLater=e(jq(this.form+".saveNewAddrForLater")).attr("checked");},setSaveForLater:function(h){this.saveForLater=h;e(jq(this.form+".saveNewAddrForLater")).attr("checked",this.saveForLater);},revert:function(){this.revertFields();},revertFields:function(){var h=this;h.jqueryObject.company.val(h.address.company).resetLabel();h.jqueryObject.street[1].val(h.address.street[1]).resetLabel();h.jqueryObject.street[2].val(h.address.street[2]).resetLabel();if(h.jqueryObject.street[3]!=undefined&&h.jqueryObject.street[3]!=null){h.jqueryObject.street[3].val(h.address.street[3]).resetLabel();}if(h.jqueryObject.street[4]!=undefined&&h.jqueryObject.street[4]!=null){h.jqueryObject.street[4].val(h.address.street[4]).resetLabel();}h.setSaveForLater(h.getSaveForLater());h.jqueryObject.region.val(h.address.region).resetLabel();h.jqueryObject.locality.val(h.address.locality).resetLabel();h.jqueryObject.postal.val(h.address.postal).resetLabel();h.setDisableJavascript(true);h.jqueryObject.country.val(h.address.country).resetLabel();h.setDisableJavascript(false);h.handleCountryChangeTrigger(h.address.region);},handleCountryChangeTrigger:function(h){this.handleCountryChange(h,false);},init:function(k,j,n,h){var m=this;c.debug("This better not be blank: ",k);m.container=k;m.id=m.container.attr("id");c.debug("Initializing new or existing address obj: "+m.id);var l=m.id.split(".");m.form=l.slice(0,-1).join(".");m.preId=m.makePreId();m.save();m.setupCountrySelect();m.initZipLookup();m.setupHideTillEdit();m.initLabels();c.debug("Calling validate on ",m.container);m.validator=m.container.validate({hasErrorsKey:h,validationCompleteEvent:n,onValidationComplete:j,api:true});},cityStateChange:function(){var h=this;c.debug("Fired Change in citystate");if(h.jqueryObject.zipLookup.cityState.find("option:selected").val()=="Other"){h.jqueryObject.zipLookup.select.addClass("hidden");h.jqueryObject.zipLookup.cityStateBlock.removeClass("hidden");h.jqueryObject.locality.val("").resetLabel();h.jqueryObject.region.val("").resetLabel();}c.debug("Resetting validation on: ",h.jqueryObject.region.attr("id"));h.validator.getValidationObjectById(h.jqueryObject.locality.attr("id")).resetField();h.validator.getValidationObjectById(h.jqueryObject.region.attr("id")).resetField();},initZipLookup:function(){var h=this;h.globalTimeout;h.globalEntry;c.debug("initing zipLookup for ",h.preId);h.jqueryObject.zipLookup={label:e(jq(h.preId+".label")),cityStateBlock:e(jq(h.preId+".cityStateBlock")),cityState:e(jq(h.preId+".cityState")),select:e(jq(h.preId+".select"))};h.setRegex();h.jqueryObject.country.change(function(){h.setRegex();});if(h.jqueryObject.postal.attr("value")!=""||h.regex==undefined){h.jqueryObject.zipLookup.label.addClass("hidden");h.jqueryObject.zipLookup.cityStateBlock.removeClass("hidden");}h.jqueryObject.zipLookup.cityState.change(function(){h.cityStateChange();});h.jqueryObject.postal.keyup(function(k){switch(k.keyCode){case 9:break;default:var j=this.value.length;if(!h.disableJavascript){h.globalEntry=e(this).val();clearTimeout(h.globalTimeout);h.globalTimeout=setTimeout(function(){h.delayedZipLookup();},1000);}break;}});},delayedZipLookup:function(){var h=this;var j=h.globalEntry;if(h.jqueryObject.postal.val()==j&&h.regex!=undefined&&h.regex.test(j)){e.ajax({url:e.clx.address.fetchCityStateURL,dataType:"json",cache:false,data:({country:h.jqueryObject.country.val(),zip:j,language:e.clx.address.activeLanguage}),success:function(n){var k=[];for(var l=0;l<n.numberOfChoice-1;l++){var m=n[l].split(", ");h.jqueryObject.locality.val(m[0]).resetLabel();h.jqueryObject.region.val(m[1]).resetLabel();k.push('<option value="'+n[l]+'">'+n[l]+"</option>");}k.push('<option value="Other">'+n[n.numberOfChoice-1]+"</option>");c.debug(h.preId," -- ziplookup?? ",h.jqueryObject.zipLookup);h.jqueryObject.zipLookup.cityState.html(k.join(""));h.jqueryObject.zipLookup.label.addClass("hidden");h.jqueryObject.zipLookup.cityStateBlock.addClass("hidden");h.jqueryObject.zipLookup.select.removeClass("hidden");h.cityStateChange();}});}},setRegex:function(){var h=this;h.regex=e.clx.utils.getZipRegex(h.jqueryObject.country.val());},initLabels:function(){this.container.find("span.inputLabel input,span.inputLabel select").label();},makePreId:function(){return this.form+".newAddress";},setupHideTillEdit:function(){},save:function(){this.saveFields();},saveFields:function(){var j=this;if(j.jqueryObject==undefined||j.jqueryObject==null){j.jqueryObject={};}j.address={};j.jqueryObject.company=e(jq(j.preId+".companyName"));j.address.company=j.jqueryObject.company.val();j.jqueryObject.country=e(jq(j.preId+".country"));j.address.country=j.jqueryObject.country.val();j.jqueryObject.locality=e(jq(j.preId+".city"));j.address.locality=j.jqueryObject.locality.val();j.jqueryObject.region=e(jq(j.preId+".state"));j.address.region=j.jqueryObject.region.val();j.jqueryObject.postal=e(jq(j.preId+".zip"));j.address.postal=j.jqueryObject.postal.val();j.jqueryObject.street=[];j.address.street=[];j.jqueryObject.street[1]=e(jq(j.preId+".streetAddress"));j.address.street[1]=j.jqueryObject.street[1].val();j.jqueryObject.street[2]=e(jq(j.preId+".streetAddress2"));j.address.street[2]=j.jqueryObject.street[2].val();var h=e(jq(j.preId+".streetAddress3"));if(h.val()!=undefined){j.address.street[3]=h.val();j.jqueryObject.street[3]=h;}h=e(jq(j.preId+".streetAddress4"));if(h.val()!=undefined){j.address.street[4]=h.val();j.jqueryObject.street[4]=h;}j.findAndSetSaveForLater();},resetZip:function(k){var j=this;var h=j.jqueryObject.country.val();c.debug(k);if((h=="USA"||h=="CAN"||h=="MEX")&&(!(k!=undefined&&k))){e(jq(j.preId+".select")).addClass("hidden").val("Other");e(jq(j.preId+".label")).removeClass("hidden");e(jq(j.preId+".cityStateBlock")).addClass("hidden");}else{e(jq(j.preId+".select")).addClass("hidden").val("Other");e(jq(j.preId+".label")).addClass("hidden");e(jq(j.preId+".cityStateBlock")).removeClass("hidden");}j.setRegex();},setupCountrySelect:function(){var h=this;h.jqueryObject.country.change(function(){if(!h.disableJavascript){h.handleCountryChange();}});},handleCountryChange:function(k,j){var h=this;c.debug("handling country change with state override: "+k);h.saveZipState();c.debug("self: ",h);h.resetZip(j);c.debug("deleting state");h.validator.deleteValidationObject(h.jqueryObject.region);e(jq(h.preId+".stateSection")).load(e.clx.address.fetchStatesURL,"country="+h.jqueryObject.country.val()+"&formName="+h.preId+"&x="+new Date().getTime(),function(){e(jq(h.preId+".stateSection")).html(e.trim(e(jq(h.preId+".stateSection")).html()));h.initZipStatePostCountryChange(k);});},saveZipState:function(){var h=this;h.callbackSave={};h.callbackSave.zip=h.jqueryObject.postal.val();h.callbackSave.state=h.jqueryObject.region.val();h.callbackSave.city=h.jqueryObject.locality.val();},revertZipState:function(j){c.debug("Reverting zip state: ",j);var h=this;if(j===undefined){h.jqueryObject.region.val(h.callbackSave.state).resetLabel();}else{h.jqueryObject.region.val(j).resetLabel();}h.jqueryObject.locality.val(h.callbackSave.city).resetLabel();h.jqueryObject.postal.val(h.callbackSave.zip).resetLabel();},initZipStatePostCountryChange:function(j){var h=this;c.debug("Moving to new region: ",e(jq(h.preId+".state"))," --id: ",e(jq(h.preId+".state")).attr("id"));h.jqueryObject.region=e(jq(h.preId+".state"));c.debug("deleting zip");h.validator.deleteValidationObject(h.jqueryObject.postal);c.debug("resetting: ",h.jqueryObject.region.attr("id")," ::: ",h.preId+".state");if(h.jqueryObject.region.attr("data-requireZip")==="true"){c.debug("resetting zip data-vtype as REQUIRED");h.jqueryObject.postal.attr("data-vtype","required zip").prev("label").html(h.jqueryObject.postal.prev("label").html().replace("*","")+"*");}else{c.debug("resetting zip data-vtype as NOT REQUIRED");h.jqueryObject.postal.attr("data-vtype","zip").prev("label").html(h.jqueryObject.postal.prev("label").html().replace("*",""));}c.debug("Adding validation object: ",h.jqueryObject.region.attr("id"));h.validator.addValidationObject(h.jqueryObject.region);c.debug("adding zip + state just added");h.validator.addValidationObject(h.jqueryObject.postal);c.debug("Resetting fields");h.validator.resetFields();h.jqueryObject.region.label();h.revertZipState(j);},loadFields:function(k,j){var h=this;h.jqueryObject.company.val(k.companyname).resetLabel();h.setDisableJavascript(true);h.jqueryObject.country.val(k.country).resetLabel();h.setDisableJavascript(false);h.jqueryObject.postal.val(k.zip).resetLabel();h.jqueryObject.region.val(k.state).resetLabel();h.jqueryObject.locality.val(k.city).resetLabel();h.handleCountryChange(k.state,false);if(h.jqueryObject.street[4]!=undefined&&h.jqueryObject.street[4].val()!=null){h.jqueryObject.street[4].val(k.companystreetaddress4).resetLabel();}if(h.jqueryObject.street[3]!=undefined&&h.jqueryObject.street[3].val()!=null){h.jqueryObject.street[3].val(k.companystreetaddress3).resetLabel();}if(h.jqueryObject.street[2].val()!=null){h.jqueryObject.street[2].val(k.companystreetaddress2).resetLabel();}h.jqueryObject.street[1].val(k.companystreetaddress).resetLabel();e(jq(h.preId+".label")).addClass("hidden");e(jq(h.preId+".cityState")).val("Other");e(jq(h.preId+".cityStateBlock")).removeClass("hidden");e(jq(h.preId+".select")).addClass("hidden");c.debug(j,k.addressType);if(j&&j!=null&&j!=undefined){j.val(k.addressType);}},ajaxLoadFieldsFromAddress:function(k,j){var h=this;if(!h.disableJavascript){e.ajax({url:e.clx.address.loadAddressURL,dataType:"json",cache:false,data:{addressId:k},success:function(l){h.loadFields(l,j);}});}}});function d(j){if(!(this instanceof d)){return new d(j);}var h=this;h.ddlbObj=j;h.disableJavascript=false;}d.prototype=new b();e.extend(d.prototype,{getRadioValue:function(){return"EXISTING_ADDRESS_SELECTION";},findAndSetSaveForLater:function(){this.saveForLater=e(jq(this.form+".saveExistingAddrForLater")).attr("checked");},setSaveForLater:function(h){this.saveForLater=h;e(jq(this.form+".saveExistingAddrForLater")).attr("checked",this.saveForLater);},revert:function(){var h=this;h.setSelectedAddress(h.getSelectedAddress());h.revertFields();if(h.hide){h.jqueryObject.hideTillEdit.addClass("hidden");}},handleCountryChangeTrigger:function(h){this.handleCountryChange(h,true);},makePreId:function(){return this.form+".existingAddress";},setupHideTillEdit:function(){var h=this;c.debug(h.form," - settingup hideTillEdit");h.jqueryObject.hideTillEdit=e("."+jq(h.form+".hideTillEdit").replace("#","")).addClass("hidden");h.hide=true;h.show=false;e(jq(h.form+".editShow")).click(function(){h.show=true;h.jqueryObject.hideTillEdit.removeClass("hidden");return false;});},populateAddress:function(){var h=this;c.debug("Populating addresses for ",h.id);e.ajax({url:e.clx.address.getAddressesURL,dataType:"json",cache:false,data:({type:h.form}),success:function(k){var j=[];c.debug(k,k.addresses.NumberOfAddresses);for(i=0;i<k.addresses.NumberOfAddresses;i=i+1){c.debug(i,k.addresses[i]);e.each(k.addresses[i],function(l,m){j[j.length]='<option value="'+l+'">'+m+"</option>";});}e(jq(h.preId)).html(j.join(""));if(k.selectedAddress!=""){h.setSelectedAddress(k.selectedAddress);c.debug("running revert");h.ddlbObj.revert();}if(e.browser.msie&&e.browser.version.substr(0,3)=="6.0"){h.jqueryObject.selectedAddress.selectmenu({style:"dropdown",format:e.clx.utils.selectMenuFormatter,menuWidth:"auto",width:250,maxHeight:350,height:null,minWidth:250,onClose:function(){e("#contentForm").find("select").add(h.jqueryObject.cityState).add(h.jqueryObject.country).add(h.jqueryObject.region).removeClass("invisible");},onOpen:function(){e("#contentForm").find("select").add(h.jqueryObject.cityState).add(h.jqueryObject.country).add(h.jqueryObject.region).each(function(){if(e(this).is("select")){e(this).addClass("invisible");}});}});}else{h.jqueryObject.selectedAddress.selectmenu({style:"dropdown",format:e.clx.utils.selectMenuFormatter,menuWidth:"auto",width:250,maxHeight:350,height:null,minWidth:250});}h.jqueryObject.selectedAddress.change(function(){h.ajaxLoadFieldsFromAddress(h.getSelectedAddress(),null);});c.debug("existing id: ",e(jq(h.form+".Existing")).attr("id"));e(jq(h.form+".Existing")).click(function(){h.ajaxLoadFieldsFromAddress(h.getSelectedAddress(),null);});e(jq(h.form+".img")).addClass("hidden");e(jq(h.form+".div")).removeClass("hidden");}});},save:function(){var h=this;c.debug("In save for ",h.preId);h.saveFields();h.saveDDLBVal();if(h.show){h.hide=false;}},saveDDLBVal:function(){this.selectedAddress=this.getSelectedAddress();},getSelectedAddress:function(){c.debug("Getting selected address if: ",this.jqueryObject.selectedAddress," == null || undefined");if(this.jqueryObject.selectedAddress==null||this.jqueryObject.selectedAddress==undefined){this.jqueryObject.selectedAddress=e(jq(this.preId));}return this.jqueryObject.selectedAddress.val();},setSelectedAddress:function(h){c.debug("setting selected address to: "+h);this.jqueryObject.selectedAddress.val(h);c.debug("did it fire change? nope");},getAlias:function(){return this.getSelectedAddress();}});function g(h,k){if(!(this instanceof g)){return new g(h,k);}var j=this;j.container=h;j.id=j.container.attr("id");j.displayDiv=k;c.debug("Creating new DDLB OBJ: ",j.id," with displayDiv ",k.attr("id"));}e.extend(g.prototype,{init:function(m,r,o,l){var s=this;s.addressArray=[];s.errorMsg=m;s.validationCompleteEvent=o;var p=e(jq(s.id+".UseAccount"));var k=e(jq(s.id+".UseNew"));var h=e(jq(s.id+".UseExisting"));if(p.size()>0){c.debug("Will try to set up account address");var n=new a();n.init(p,r,o,l);s.addressArray.push(n);}if(k.size()>0){c.debug("Will try to set up new address");var q=new b();q.init(k,r,o,l);s.addressArray.push(q);}if(h.size()>0){c.debug("Will try to set up existing address");var j=new d(s);j.init(h,r,o,l);s.addressArray.push(j);}c.debug("Initializing groupInput for: ",s.container.attr("id"));s.container.groupInput();s.savedSelectedRadio=e.inputGroups.group(s.id).selectedValue();c.debug("Initialized groupInput for with value: ",s.savedSelectedRadio,"from ",s.id);},getId:function(){return this.id;},getSelectedSection:function(){return this.savedSelectedRadio;},validateAddressDDLB:function(){var h=this;var k;var j=e.inputGroups.group(h.id).selectedValue();c.debug("Got groupInput with value: ",j,"from ",h.id);c.debug("validateAddresses flag set to: ",e.clx.shipping.validateAddresses);if(j==undefined){e.event.trigger(h.validationCompleteEvent,[[h.errorMsg],"shipping"]);}else{if(!e.clx.shipping.validateAddresses){e.event.trigger(h.validationCompleteEvent,[[],"shipping"]);}else{e.each(h.addressArray,function(m,l){if(j===l.getRadioValue()){l.validateAddress();c.debug("Validating ",h.id," yields:");}});}}},populateAddresses:function(){var h=this;c.debug("populating existing addresses");e.each(h.addressArray,function(k,j){if(j instanceof d){j.populateAddress();}});},save:function(){var h=this;h.savedSelectedRadio=e.inputGroups.group(h.id).selectedValue();c.debug("Attempting to validate: ",h.id," which has ",h.savedSelectedRadio," selected.");e.each(h.addressArray,function(k,j){if(h.savedSelectedRadio!==j.getRadioValue()){c.debug("AddressDDLB - reverting for save: ",j);j.revert();}else{c.debug("AddressDDLB - saving ",j);j.save();h.saveToDisplay(j);e.clx.utils.saveToServer(j,h.id,function(){});}});},revert:function(){var h=this;c.debug("Reverting addressDDLB: ",h.id);e.each(h.addressArray,function(j,k){if(k instanceof d){k.setDisableJavascript(true);}});h.container.find('input[name="'+h.id+'.radioSelection"]').each(function(){c.debug("this.value: ",this.value,"  compared with selectedSection: "+h.getSelectedSection());if(this.value==h.getSelectedSection()){e(this).click();}else{e(this).attr("checked",false);}});e.each(h.addressArray,function(j,k){if(k instanceof d){k.setDisableJavascript(false);}c.debug("Will run revert on: ",k.id);k.revert();});},saveToDisplay:function(h){var j=this;c.debug("Saving addressDDLB: ",j.id," address: ",h.id);j.displayDiv.children("div.org").text(h.getCompany());var k=j.displayDiv.children("div.adr");k.children("span.country-name").html("&nbsp;"+h.getCountry());k.children("span.locality").html(h.getLocality()+",&nbsp;");k.children("span.postal-code").text(h.getPostal());k.children("span.region").html(h.getRegion()+"&nbsp;&nbsp;");k.children("div.street-address").html(h.getReadableStreetAddress());}});e.clx.createAddressDDLBObj=function(h,j){return new g(h,j);};function f(){if(!(this instanceof f)){return new f();}var h=this;h.disableJavascript=false;}f.prototype=new b();e.extend(f.prototype,{makePreId:function(){return this.id;},getAlias:function(){return this.alias;},setAlias:function(h){this.alias=h;},clear:function(){var h=this;e.each(h.jqueryObject,function(j,k){if(j=="country"){country=h.jqueryObject.country.val();h.jqueryObject.country.val("");}else{if(j!="zipLookup"&&j!="street"){k.val("").resetLabel();}}});e.each(h.jqueryObject.street,function(j,k){if(k!=null&&k!=undefined){k.val("").resetLabel();}});h.jqueryObject.country.val(country);h.resetZip(false);},findAndSetSaveForLater:function(){}});e.clx.createSelfStandingAddressObj=function(){return new f();};})(jQuery);;(function(b){var a=b.clx.log.logger("ieSixAppend.js");a.level=b.clx.log.WARN;b.fn.ieSixAppend=function(c){if(!(b.clx.isBrowserIESix===true||b.clx.isBrowserIESix===false)){b.clx.isBrowserIESix=(b.browser.msie&&(b.browser.version.substr(0,3)=="6.0"||b.browser.version.substr(0,3)=="7.0"));}return b(this).each(function(){a.debug("in ieSixAppend");var d;if(b.clx.isBrowserIESix){a.debug("browser is ie6 or ie7");d=c.find("input:checked");}a.debug("Appending: ",c.attr("id")," to ",b(this).attr("id"));b(this).append(c);if(b.clx.isBrowserIESix){d.each(function(){this.checked=true;});}});};})(jQuery);;$.clx.shipping={};$.clx.shipping.initializeShippingPage=function(){var j=$.clx.log.logger("shipping.js");j.level=$.clx.log.WARN;var q=false;var e=false;a();var p=null;var h=null;if($("#dropShipAddressForm").size()>0){var p=o();}if($("#interimAddressForm").size()>0){var h=y();}c();j.debug("settingup order priority section");A();var t=[];var i=0;var f=false;var r=false;$.clx.shipping.thirdPartySaveClicked=false;x();n();function n(){if(p!=null){p.populateAddresses();}if(h!=null){h.populateAddresses();}if($.clx.shipping.thirdPartyAddressDDLB!=undefined){$.clx.shipping.thirdPartyAddressDDLB.populateAddresses();}}function x(){var B=$("#contentForm");B.onCLX_ADDRESS_VALIDATION_COMPLETE(function(D,E){j.debug("triggered address validatation complete, errors: ",E);i--;$.merge(t,E);j.debug("pendingCount: ",i);if(i==0){j.debug("Pending == 0.  Firing validation Complete");if(t.length==0){j.debug("All Forms Appear Valid. Submitting..");j.debug("Appending content from: "+$("#shipToAddressOptions").attr("id"));B.ieSixAppend($("#shipToAddressOptions"));if(e){B.ieSixAppend($("#interimAddressOptions"));}if(q){B.ieSixAppend($("#thirdPartyAddressOptions"));}}j.debug("FIRING SUBMIT BASIACLLY - or error msgs: Error messages: ",t);$.event.trigger($.clx.events.validationComplete,[t,"shipping"]);}});if($("#orderHeaderForm\\.email").size()>0){j.debug("Initing email validation");$("#orderHeaderForm\\.email").validate({hasErrorsKey:"errorEmailMsg",addToFormHandler:true});}var C=$("#poNumber1").validate({hasErrorsKey:"poNumber",validationCompleteEvent:$.clx.events.addressValidationComplete,api:true});$.clx.formHandler.addButtonToIgnore("#clearOrderButton");$.clx.formHandler.addValidation("shipping",function(){t=[];i=0;j.debug("validating with standard ship option: ",$.clx.shipping.usingStandardShipOption);if(!$.clx.shipping.usingStandardShipOption){if(p!=null){i++;}if(e&&$.inputGroups.group("interimAddressOptionsGroup").selectedValue()=="true"){j.debug("Adding 1 to pending count for interim");i++;}j.debug("checking tpb sections based on: ",$.clx.shipping.enableFreightPaymentMethod);if($.clx.shipping.enableFreightPaymentMethod){var E=$.inputGroups.group("freightPaymentMethodGroup").selectedValue();if(E==="PREMACCT"){j.debug("Adding 1 to pending count for PREMACCT");i++;}else{if(E==="TPBILL"){j.debug("Adding 2 to pending count for TPBILL SECTION");i++;i++;}}}if($.clx.shipping.checkOtherField){j.debug("Adding 1 to pening count for other section");i++;}}j.debug("Comparing orderHeaderForm.submitOrderButton to: ",this.getButton().id," to determine whether to check PO number.");var D=false;if(this.getButton().id=="orderHeaderForm.submitOrderButton"){D=true;j.debug("Adding 1 to pending count for PO number");i++;}j.debug("Pending count start: ",i);if(i==0){j.debug("bypass the rest of the validation if nothing is goign to be checked");i++;$.event.trigger($.clx.events.addressValidationComplete,[]);}if(D){C.validate();}else{C.resetFields();}if(!$.clx.shipping.usingStandardShipOption){j.debug("Starting validating Drop Ship Addresses....");if(p!=null){p.validateAddressDDLB();}j.debug("Checking to see if interim address is used: ");if(e){j.debug("   Starting Validating Interim Addresses.");j.debug("Selected value: ",$.inputGroups.group("interimAddressOptionsGroup").selectedValue());if(h!=null&&$.inputGroups.group("interimAddressOptionsGroup").selectedValue()=="true"){h.validateAddressDDLB();}else{j.debug("   Not validating Interim Address. - N/A chosen");}}else{j.debug("   Not validating Interim Address.");}j.debug("Checking to see if third party address is used based on: ",$.clx.shipping.enableFreightPaymentMethod);if($.clx.shipping.enableFreightPaymentMethod){j.debug("    Validating Third party Addresses....");j.debug($.inputGroups.group("freightPaymentMethodGroup").selectedValue());if($.inputGroups.group("freightPaymentMethodGroup").selectedValue()=="PREMACCT"){j.debug("Firing validation on section: ",$.inputGroups.group("freightPaymentMethodGroup").selectedContent().attr("id"));$.clx.validationGroups.getGroup($.inputGroups.group("freightPaymentMethodGroup").selectedContent().attr("id")).validate();}else{if($.inputGroups.group("freightPaymentMethodGroup").selectedValue()=="TPBILL"){j.debug("Firing validation on thirdPartAddressDDLB");$.clx.shipping.thirdPartyAddressDDLB.validateAddressDDLB();j.debug("Firing validation on section: ",$.inputGroups.group("freightPaymentMethodGroup").selectedContent().attr("id"));$.clx.validationGroups.getGroup($.inputGroups.group("freightPaymentMethodGroup").selectedContent().attr("id")).validate();}else{j.debug("   Not validating Third Party Address. - Not Selected");}}}else{j.debug("   Not validating Third Party Address. - Not Used");}if($.clx.shipping.checkOtherField){j.debug("Firing validate on su.other field");$.clx.validationGroups.getGroup("su.other").validate();}}});}function o(){j.debug("initDropShipAddressOptions");var B=$.clx.createAddressDDLBObj($("#dropShipAddressForm"),$("#dropShipAddress .vcard"));B.init($.clx.messages.validation.dropShipError,function(D,C){j.debug("inside success");},$.clx.events.dropshipAddressValidationComplete,"dropShipError");$("#cancelShipTo,#shipToAddressOptions a.close").click(function(){j.debug("will revert dropShipDDLB");B.revert();j.debug("reverted dropShipDDLB copmlete");$("#shipToAddressOptions").overlay().close();});$("#saveShipTo").click(function(){v();});b($("#dropShipAddress"));g(B);$("#contentForm").onCLX_DROPSHIP_ADDRESS_VALIDATION_COMPLETE(function(C,D){j.debug("triggered dropship address validatation complete, errors: ",D);if(f){if(D.length>0){$.clx.formHandler.errors([$.clx.messages.validation.dropShipError]);}else{j.debug("dropShipDDLB is valid will save");B.save();if(!$.clx.shipping.validateAddresses&&B.getSelectedSection()==="NEW_ADDRESS_SELECTION"){$("#staticAddressDisplay").addClass("hidden");$("#dropShipAddNewMessage").removeClass("hidden");}else{$("#staticAddressDisplay").removeClass("hidden");$("#dropShipAddNewMessage").addClass("hidden");}if(B.getSelectedSection()==="DEFAULT_ADDRESS_SELECTION"){$("#defaultDropShipAddressLabel").removeClass("hidden");}else{$("#defaultDropShipAddressLabel").addClass("hidden");}$("#shipToAddressOptions").overlay().close();}j.debug("resetting dropshipSaveClicked to false");f=false;}else{if(D.length>0){j.debug("Setting dropShipAddNew in error");$("#dropShipAddNewMessage").addClass("error");}$.event.trigger($.clx.events.addressValidationComplete,[D]);}});return B;}function g(B){$(jq(B.getId()+".saveAddrTooltip")).tooltip({tip:jq(B.getId()+".saveAddrTip"),onBeforeLoad:function(){j.debug("ONBEFORELOAD2");},position:"bottom right"});j.debug("ONBEFORELOAD");$(jq(B.getId()+".saveAddrTip")).appendTo("body");}function y(){j.debug("initInterimAddressOptions");if($("#interimAddress").size()==0){j.debug("Interim Addresses Are de-activated.");e=false;return;}else{j.debug("Interim Addresses Are Activated.");e=true;}var B=$.clx.createAddressDDLBObj($("#interimAddressForm"),$("#interimAddress .vcard"));B.init($.clx.messages.validation.interimError,function(D,C){j.debug("inside success");},$.clx.events.interimAddressValidationComplete,"interimError");$("#interimAddressOptionsGroup").groupInput();$("#saveInterim").click(function(){u();});$("#cancelInterim,#interimAddressOptions a.close").click(function(){B.revert();$("#interimAddressOptions").overlay().close();});b($("#interimAddress"));g(B);$("#contentForm").onCLX_INTERIM_ADDRESS_VALIDATION_COMPLETE(function(C,D){j.debug("triggered interim address validatation complete, errors: ",D);if(r){if(D.length>0){$.clx.formHandler.errors([$.clx.messages.validation.interimError]);}else{B.save();m();if(!$.clx.shipping.validateAddresses&&B.getSelectedSection()==="NEW_ADDRESS_SELECTION"){$("#interimAddressDisplay").addClass("hidden");$("#interimAddNewMessage").removeClass("hidden");}else{$("#interimAddressDisplay").removeClass("hidden");$("#interimAddNewMessage").addClass("hidden");}$("#interimNotApplicable").addClass("hidden");$("#interimAddressOptions").overlay().close();}r=false;}else{if(D.length>0){j.debug("Marking interimAddNewMessage in error");$("#interimAddNewMessage").addClass("error");}$.event.trigger($.clx.events.addressValidationComplete,[D]);}});return B;}function c(){var D=$("#doNotDeviate");var B=$(("#su\\.ddlb"));j.debug("Initing do not deviate");D.add(B).change(function(){if($("#doNotDeviate").attr("checked")&&($("#su\\.ddlb option:selected").val()=="")){j.debug("marking do not deviate");$("#doNotDeviateError").removeClass("hidden");}else{j.debug("clearing do not deviate");$("#doNotDeviateError").addClass("hidden");}});var C=$("#su\\.other");B.change(function(){z(B);if(C.size()>0){if(B.val()==="other"){C.removeClass("hidden");$.clx.shipping.checkOtherField=true;}else{C.addClass("hidden");$.clx.shipping.checkOtherField=false;}}});w();$("#contentForm").onCLX_THIRDPARTY_ADDRESS_VALIDATION_COMPLETE(function(E,F){j.debug("triggered thirdParty address validatation complete, errors: ",F);if($.clx.shipping.thirdPartySaveClicked){$.clx.shipping.thirdPartySaveClicked=false;if(F.length==0){$.clx.shipping.thirdPartyAddressDDLB.save();if(!$.clx.shipping.validateAddresses&&$.clx.shipping.thirdPartyAddressDDLB.getSelectedSection()==="NEW_ADDRESS_SELECTION"){$("#thirdPartyAddressDisplay").addClass("hidden");$("#thirdPartyAddNewMessage").removeClass("hidden");}else{$("#thirdPartyAddressDisplay").removeClass("hidden");$("#thirdPartyAddNewMessage").addClass("hidden");}$("#thirdPartyAddressOptions").overlay().close();}else{$.clx.formHandler.errors([$.clx.messages.validation.thirdPartyError]);}}else{if(F.length>0){j.debug("Marking thirdPartyAddNewMessage in error");$("#thirdPartyAddNewMessage").addClass("error");}$.event.trigger($.clx.events.addressValidationComplete,[F]);}});}function w(){j.debug("initializeFreightOptions");if($("#freight\\.TPBILL").size()==0){q=false;d();return;}else{q=true;}$.clx.shipping.thirdPartyAddressDDLB=$.clx.createAddressDDLBObj($("#paymentMethodsForm\\.thirdPartyAddressForm"),$("#thirdPartyAddress .vcard"));$.clx.shipping.thirdPartyAddressDDLB.init($.clx.messages.validation.thirdPartyError,function(C,B){j.debug("inside success");},$.clx.events.thirdPartyAddressValidationComplete,"thirdPartyError");j.debug("SETTINGUP VALIDATION");b($("#thirdPartyAddress"));g($.clx.shipping.thirdPartyAddressDDLB);d();j.debug("Attaching Cancel handler.");$("#cancelThirdParty,#thirdPartyAddressOptions a.close").click(function(){$.clx.shipping.thirdPartyAddressDDLB.revert();$("#thirdPartyAddressOptions").overlay().close();});j.debug("Attaching Save handler.");$("#saveThirdParty").click(function(){s();});if($.clx.shipping.thirdPartyAddressDDLB!=undefined){$.clx.shipping.thirdPartyAddressDDLB.populateAddresses();}}function d(){var C=$("#su\\.ddlb");if($("#freightPaymentMethodGroup").size()==0){$.clx.shipping.enableFreightPaymentMethod=false;}else{$.clx.shipping.enableFreightPaymentMethod=true;}$.clx.shipping.checkOtherField=false;var D=$("#su\\.other");if(D.size()>0){$("#otherCarrier").label();if(C.find("option:selected").val()=="other"){$.clx.shipping.checkOtherField=true;}D.validate({hasErrorsKey:"emptyShipCarrierOther",validationCompleteEvent:$.clx.events.addressValidationComplete});}$("#freightPaymentMethodGroup").groupInput();if($.inputGroups.group("freightPaymentMethodGroup")!=undefined){var E=$.inputGroups.group("freightPaymentMethodGroup").selectedContent();E=E.add($.inputGroups.group("freightPaymentMethodGroup").hiddenContent());E.each(function(){j.debug("SETTINGUP validation on section: ",$(this).attr("id"));if($(this).attr("id")==="freight.PREMACCT"){$(this).validate({hasErrorsKey:"missingPaymentAcctNumMsg",validationCompleteEvent:$.clx.events.addressValidationComplete});}else{if($(this).attr("id")==="freight.TPBILL"){$(this).validate({hasErrorsKey:"invalidThirdPartyAccountNumberGiven",validationCompleteEvent:$.clx.events.addressValidationComplete});}else{}}});}var B=$("#freightPaymentMethodGroup").find("span.inputLabel input,span.inputLabel select");B.label();}function m(){j.debug("Saving mark Attention Values");var C=l("#interimMarkFor1","#permInterimMarkFor1");var B=l("#interimMarkFor2","#permInterimMarkFor2");var F=l("#interimAttention1","#permInterimAttention1");var E=l("#interimAttention2","#permInterimAttention2");var D=$.inputGroups.group("interimAddressOptionsGroup").selectedValue();if(D=="false"){$("#interimConsigneeMarkFor").addClass("hidden");$("#interimConsigneeAttention").addClass("hidden");}else{if(C||B){$("#interimConsigneeMarkFor").removeClass("hidden");}else{$("#interimConsigneeMarkFor").addClass("hidden");}if(F||E){$("#interimConsigneeAttention").removeClass("hidden");}else{$("#interimConsigneeAttention").addClass("hidden");}}}function l(B,E){var D=$(B).val();var C=$(E).html(D);if(D!=""){C.removeClass("hidden");return true;}else{C.addClass("hidden");return false;}}function z(B){if($("#freightPaymentMethodGroup").size()==0){$.clx.shipping.enableFreightPaymentMethod=false;}else{$.clx.shipping.enableFreightPaymentMethod=true;}if(B.find("option:selected").val()==""){$.clx.shipping.enableFreightPaymentMethod=false;$("#fpo").addClass("hidden");}else{$("#fpo").removeClass("hidden");var C=$("#fpo").find('input[name="paymentMethodsForm\\.selectedPaymentMethod"]:checked').attr("id");var D="";if(C!=undefined){D=$(jq(C)).val();}j.debug("running SelectFreightPayment");$("#thirdPartyAddressOptions").remove();$("#fpo1").load($.clx.address.freightPaymentFetchURL,{functionTile:$.clx.shipping.functionTile,selectedPaymentMethod:D,selectedCarrier:$(jq("su.ddlb")+" option:selected").val()},function(){w();});}}function b(B){j.debug(B.attr("id")+B.next("div").attr("id"));B.next("div").appendTo("body");j.debug("prehighlight: ",B.attr("id"));B.find("span.change").click(function(){if($(this).is(":visible")){j.debug("CLICKED span.change:",this.id);var C;if($(this).parent().parent().attr("id")=="interimAddress"){C="#interimAddressOptions";}else{if($(this).parent().parent().attr("id")=="dropShipAddress"){C="#shipToAddressOptions";}else{if($(this).parent().parent().attr("id")=="thirdPartyAddress"){C="#thirdPartyAddressOptions";}}}$(C).overlay({closeOnClick:false,closeOnEsc:false,onLoad:function(){j.debug("Adding bind for:",C);this.getOverlay().bind("keypress",{currentID:C,overlay:this.getOverlay()},k);},onClose:function(){j.debug("Removeing bind for:",C);this.getOverlay().unbind("keypress",k);},api:true,expose:{loadSpeed:200,opacity:0},left:"center",top:"center",speed:0,closeSpeed:0}).load();}});}function k(B){if(B.which==13&&!$.clx.formHandler.isOverlayOpen()){var C=B.data.currentID;if(C=="#interimAddressOptions"){u();}else{if(C=="#shipToAddressOptions"){v();}else{if(C=="#thirdPartyAddressOptions"){s();}}}return false;}}function v(){j.debug("triggering drop ship save");f=true;if(p!=null){p.validateAddressDDLB();}}function u(){j.debug("triggering interim save");if(h!=null){var B=$.inputGroups.group("interimAddressOptionsGroup").selectedValue();if(B=="true"){r=true;j.debug("Changing save to: ",r);h.validateAddressDDLB();}else{if(B=="false"){$("#interimAddressDisplay").addClass("hidden");$("#interimAddNewMessage").addClass("hidden");$("#interimNotApplicable").removeClass("hidden");$("#interimAddressOptions").overlay().close();}}}}function s(){j.debug("Save Handler for Third Party Firing..");$.clx.shipping.thirdPartySaveClicked=true;$.clx.shipping.thirdPartyAddressDDLB.validateAddressDDLB();}function A(){$("#orderPrioritySection").find("input[name=selectedOrderPriority]").each(function(){if($(this).is(":checked")){j.debug("MARKING AS SELECTED: ",$(this).attr("id"));if($(this).attr("id").match(/^standardShipOption[\d]*/)){$.clx.shipping.usingStandardShipOption=true;}else{$.clx.shipping.usingStandardShipOption=false;}}}).change(function(){if($(this).attr("id").match(/^standardShipOption[\d]*/)){if(!$.clx.shipping.usingStandardShipOption){$("#afterShipOptionsSection").addClass("hidden");if($("#markForSection").size()>0){$(".beforeShipOptionsSection").addClass("hidden");}else{$("#beforeShipOptionsSection").addClass("hidden");}$("#leftOrderPriority").addClass("hidden");$(".nonStandardPriority").removeClass("nonStandardPriority").addClass("standardPriority");$("#standardOrderPriority").appendTo("body").overlay({closeOnClick:true,closeOnEsc:true,api:true,expose:{loadSpeed:200,opacity:0},left:"center",top:"center",speed:0,closeSpeed:0}).load();$.clx.shipping.usingStandardShipOption=true;}}else{if($.clx.shipping.usingStandardShipOption){$("#afterShipOptionsSection").removeClass("hidden");if($("#markForSection").size()>0){$(".beforeShipOptionsSection").removeClass("hidden");}else{$("#beforeShipOptionsSection").removeClass("hidden");}$("#leftOrderPriority").removeClass("hidden");$(".standardPriority").removeClass("standardPriority").addClass("nonStandardPriority");$("#nonStandardOrderPriority").appendTo("body").overlay({closeOnClick:true,closeOnEsc:true,api:true,expose:{loadSpeed:200,opacity:0},left:"center",top:"center",speed:0,closeSpeed:0}).load();$.clx.shipping.usingStandardShipOption=false;}}});}function a(){$("#carrierOverlayTrigger").overlay({close:".close",onBeforeLoad:function(){this.getOverlay();if(!this.getOverlay().data("moved")){this.getOverlay().appendTo("body").data("moved","true");}},top:"25%"});}};;
