dojo.require("dojo.io.*");
dojo.require("wc.render.*");
dojo.addOnLoad(function(){
if(!wc.render.getContextById("default")){
wc.render.declareContext("default",{},"");
}
if(!wc.render.getContextById("MyAccountCenterLinkDisplay_Context")){
wc.render.declareContext("MyAccountCenterLinkDisplay_Context",{workAreaMode:"myAccountMain"},"");
}
});
AddressBookFormJS={cityInputTextBoxValue:"",validateLoadFields:"",langId:"-1",storeId:"",catalogId:"",stateDivName:"stateDiv",setStateDivName:function(_1){
this.stateDivName=_1;
},setCityInputTextBoxValue:function(_2){
this.cityInputTextBoxValue=_2;
},setValidateLoadFields:function(){
this.validateLoadFields="true";
},setCommonParameters:function(_3,_4,_5){
this.langId=_3;
this.storeId=_4;
this.catalogId=_5;
},getControllerActionHandler:function(_6,_7){
dojo.debug("entering getControllerActionHandler(controller, handlerKey, actionName): "+_7);
var _8=AddressBookFormJS[_7+"s"][_6];
if(_8){
return function(_9,_a,_b){
_8(_9,_a,_b);
};
}else{
return function(_c,_d,_e){
dojo.debug("empty handler. This is a no-op");
};
}
},declareRefreshController:function(_f,_10,_11){
dojo.debug("entering AddressBookFormJS.declareRefreshController with action name = "+_10+" and controller id = "+_f);
if(wc.render.getRefreshControllerById(_f)){
dojo.debug("controller with id = "+_f+" already exists. No declaration will be done");
return;
}
wc.render.declareRefreshController({id:_f,renderContext:wc.render.getContextById("default"),url:_11,renderContextChangedHandler:function(_12,_13){
dojo.debug("entering renderContextChangedHandler for "+_f);
var _14=this;
var _15=this.renderContext;
if(!Common.getRenderContextProperty(_15,_10)){
dojo.debug("no "+_10+" is specified. This handler will not be called. Exiting...");
return;
}
if(Common.getRenderContextProperty(_15,"url")){
_14.url=Common.getRenderContextProperty(_15,"url");
}
AddressBookFormJS.getControllerActionHandler(Common.getRenderContextProperty(_15,_10),_10)(_12,_13,_14);
delete _15.properties[_10];
delete _15.properties["url"];
},modelChangedHandler:function(_16,_17){
AddressBookFormJS.getControllerActionHandler("handleModelChange",_10)(_16,_17,this);
cursor_clear();
}});
},addressFormAreaActions:{create:function(_18,_19,_1a){
_19.refresh(_1a.renderContext.properties);
_1a.renderContext.properties["addressFormAreaState"]="create";
},edit:function(_1b,_1c,_1d){
dojo.debug("starting to getting editing area");
_1c.refresh(_1d.renderContext.properties);
_1d.renderContext.properties["addressFormAreaState"]="edit";
},clean:function(_1e,_1f,_20){
_1f.setInnerHTML("");
_20.renderContext.properties["addressFormAreaState"]="clean";
},handleModelChange:function(_21,_22,_23){
_22.setInnerHTML("");
_23.renderContext.properties["addressFormAreaState"]="clean";
}},addressDisplayAreaActions:{reload:function(_24,_25,_26){
dojo.debug("reloading "+_25);
_25.refresh(_26.renderContext.properties);
},handleModelChange:function(_27,_28,_29){
dojo.debug("reloading "+_28);
_28.refresh(_29.renderContext.properties);
}},statesDisplayAreaActions:{countryUpdated:function(_2a,_2b,_2c){
dojo.debug("IN countryUpdated handler: message = "+_2a);
var _2d=_2c.renderContext.properties["paramPrefix"];
if(_2b.widgetId.match(_2d)){
dojo.debug("matchin paramPrefix: "+_2d+" refreshing "+_2b.widgetId);
_2b.refresh(_2c.renderContext.properties);
}else{
dojo.debug("no maching paramPrefix "+_2d);
}
}},toggleAddressDisplay:function(_2e,_2f,_30){
dojo.debug("toggle address display");
var _31=_2e.options[_2e.selectedIndex].value;
dojo.lang.forEach(dojo.html.getElementsByClass(_2f),function(_32){
var _33=_30+_31;
if(_32.id==_33){
_32.style.display="";
}else{
_32.style.display="none";
}
});
},updateAddressArea:function(_34){
dojo.debug("to update with params: "+_34);
wc.render.updateContext("default",_34);
dojo.debug("updateArea done");
},validateAddressForm:function(_35,_36){
var _37=false;
reWhiteSpace=new RegExp(/^\s+$/);
var _38=document.forms[_35];
var _39=_38.addressField2;
var _3a=_39.options[_39.selectedIndex].value;
Common.hideErrorNodes();
if(_38.nickName.value==""||reWhiteSpace.test(_38.nickName.value)){
Common.formErrorHandleClient("nickName",Common.errorMessages["ERROR_NicknameEmpty"],_35,_36);
_37=true;
}else{
if(!Common.isValidUTF8length(_38.nickName.value,254)){
Common.formErrorHandleClient("nickName",Common.errorMessages["ERROR_NicknameTooLong"],_35,_36);
_37=true;
}
}
if(_38.firstName.value==""||reWhiteSpace.test(_38.firstName.value)){
Common.formErrorHandleClient("firstName",Common.errorMessages["ERROR_FirstNameEmpty"],_35,_36);
_37=true;
}else{
if(!Common.isValidUTF8length(_38.firstName.value,128)){
Common.formErrorHandleClient("firstName",Common.errorMessages["ERROR_FirstNameTooLong"],_35,_36);
_37=true;
}
}
if(_38.lastName.value==""||reWhiteSpace.test(_38.lastName.value)){
Common.formErrorHandleClient("lastName",Common.errorMessages["ERROR_LastNameEmpty"],_35,_36);
_37=true;
}else{
if(!Common.isValidUTF8length(_38.lastName.value,128)){
Common.formErrorHandleClient("lastName",Common.errorMessages["ERROR_LastNameTooLong"],_35,_36);
_37=true;
}
}
if(_3a==""||reWhiteSpace.test(_3a)){
Common.formErrorHandleClient("businessTitle",Common.errorMessages["ERROR_AddressTypeEmpty"],_35,_36);
_37=true;
}else{
if(_3a=="Business"){
if(_38.officeAddress.value==""||reWhiteSpace.test(_38.officeAddress.value)){
Common.formErrorHandleClient("officeAddress",Common.errorMessages["ERROR_BusinessEmpty"],_35,_36);
_37=true;
}
if(!Common.isValidUTF8length(_38.officeAddress.value,128)){
Common.formErrorHandleClient("officeAddress",Common.errorMessages["ERROR_BusinessTooLong"],_35,_36);
_37=true;
}
}
}
if(_3a=="APO/FPO"){
if(_38.address1.value==""||reWhiteSpace.test(_38.address1.value)){
Common.formErrorHandleClient("address1",Common.errorMessages["ERROR_UnitNumberEmpty"],_35,_36);
_37=true;
}
if(!Common.isValidUTF8length(_38.address1.value,50)){
Common.formErrorHandleClient("address1",Common.errorMessages["ERROR_AddressTooLong"],_35,_36);
_37=true;
}
if(_38.address2.value==""||reWhiteSpace.test(_38.address2.value)){
Common.formErrorHandleClient("address2",Common.errorMessages["ERROR_BoxNumberEmpty"],_35,_36);
_37=true;
}
if(!Common.isValidUTF8length(_38.address2.value,50)){
Common.formErrorHandleClient("address2",Common.errorMessages["ERROR_AddressTooLong"],_35,_36);
_37=true;
}
}else{
if(_3a=="P.O. Box"){
if((_38.address1.value==""||reWhiteSpace.test(_38.address1.value))&&_38.address2.value==""){
Common.formErrorHandleClient("address1",Common.errorMessages["ERROR_POBOXAddressEmpty"],_35,_36);
_37=true;
}
if(!Common.isValidUTF8length(_38.address1.value,50)){
Common.formErrorHandleClient("address1",Common.errorMessages["ERROR_POBOXAddressTooLong"],_35,_36);
_37=true;
}
}else{
if((_38.address1.value==""||reWhiteSpace.test(_38.address1.value))&&_38.address2.value==""){
Common.formErrorHandleClient("address1",Common.errorMessages["ERROR_AddressEmpty"],_35,_36);
_37=true;
}
if(!Common.isValidUTF8length(_38.address1.value,50)){
Common.formErrorHandleClient("address1",Common.errorMessages["ERROR_AddressTooLong"],_35,_36);
_37=true;
}
}
}
if(!Common.isValidUTF8length(_38.address2.value,50)){
Common.formErrorHandleClient("address2",Common.errorMessages["ERROR_AddressTooLong"],_35,_36);
_37=true;
}
if(_38.city.value==""||reWhiteSpace.test(_38.city.value)){
Common.formErrorHandleClient("city",Common.errorMessages["ERROR_CityEmpty"],_35,_36);
_37=true;
}else{
if(!Common.isValidUTF8length(_38.city.value,128)){
Common.formErrorHandleClient("city",Common.errorMessages["ERROR_CityTooLong"],_35,_36);
_37=true;
}
}
if(_38.state.value==""||reWhiteSpace.test(_38.state.value)){
Common.formErrorHandleClient("state",Common.errorMessages["ERROR_StateEmpty"],_35,_36);
_37=true;
}else{
if(!Common.isValidUTF8length(_38.state.value,128)){
Common.formErrorHandleClient("state",Common.errorMessages["ERROR_StateTooLong"],_35,_36);
_37=true;
}
}
if(_38.country.value==""||reWhiteSpace.test(_38.country.value)){
Common.formErrorHandleClient("country",Common.errorMessages["ERROR_CountryEmpty"],_35,_36);
_37=true;
}else{
if(!Common.isValidUTF8length(_38.country.value,128)){
Common.formErrorHandleClient("country",Common.errorMessages["ERROR_CountryTooLong"],_35,_36);
_37=true;
}
}
if(_38.zipCode.value==""||reWhiteSpace.test(_38.zipCode.value)){
Common.formErrorHandleClient("zipCode",Common.errorMessages["ERROR_ZipCodeEmpty"],_35,_36);
_37=true;
}else{
if(!Common.isValidUTF8length(_38.zipCode.value,40)){
Common.formErrorHandleClient("zipCode",Common.errorMessages["ERROR_ZipCodeTooLong"],_35,_36);
_37=true;
}
}
if(_38.phone1.value!=""&&!reWhiteSpace.test(_38.phone1.value)&&!Common.isValidPhone(_38.phone1.value)){
Common.formErrorHandleClient("phone1",Common.errorMessages["ERROR_PhoneInvalid"],_35,_36);
_37=true;
}else{
if(!Common.isValidUTF8length(_38.phone1.value,32)){
Common.formErrorHandleClient("phone1",Common.errorMessages["ERROR_Phone1OnlyNum"],_35,_36);
_37=true;
}
}
if(_38.phone2.value!=""&&!reWhiteSpace.test(_38.phone2.value)&&!Common.isValidPhone(_38.phone2.value)){
Common.formErrorHandleClient("phone2",Common.errorMessages["ERROR_PhoneInvalid"],_35,_36);
_37=true;
}else{
if(!Common.isValidUTF8length(_38.phone2.value,32)){
Common.formErrorHandleClient("phone2",Common.errorMessages["ERROR_Phone2OnlyNum"],_35,_36);
_37=true;
}
}
if(!_37){
_38.phone1.value=Common.cleanPhone(_38.phone1.value);
_38.phone2.value=Common.cleanPhone(_38.phone2.value);
if(_38.address1.value==""){
if(_38.address2.value!=""){
_38.address1.value=_38.address2.value;
_38.address2.value="";
}
}
}
return !_37;
},loadFields:function(_3b){
var _3c="<input type=\"text\" name=\"city\" id=\"QAS_city\" size=\"20\" maxlength=\"40\" class=\"addressSelectSmall\"\tvalue=\"";
var _3c=_3c+_3b+"\" />";
var _3c=document.getElementById("cityTextbox").value;
if(document.getElementById("QAS_city")){
if(document.getElementById("QAS_city").nodeName=="INPUT"){
var _3d=document.getElementById("QAS_city").value;
}
}
var _3e="<select name=\"city\" id=\"QAS_city\" class=\"addressSelectSmall\" style=\"width:auto\" /><option value=\"APO\">APO</option><option value=\"FPO\">FPO</option></select>";
var _3f=document.getElementById("addressField2");
var _40=document.getElementById("company_label");
var _41=document.getElementById("address1_label");
var _42=document.getElementById("address2_label");
var _43=document.getElementById("address3_label");
var _44=document.getElementById("city_label");
var _45=document.getElementById("militaryHelpRow");
var _46=document.getElementById("cityInput");
var _47=document.getElementById("address2_star");
var _48=document.getElementById("organizationNameRow");
var _49=document.getElementById("WC_ShoppingCartAddressEntryForm_FormInput_company_1");
var _4a=_3f.options[_3f.selectedIndex].value;
if(_4a=="Residential"){
_40.innerHTML="Company:";
_41.innerHTML="Address Line 1:";
_42.innerHTML="Address Line 2:";
_43.innerHTML="Address Line 3:";
_44.innerHTML="City:";
_45.style.display="none";
if(document.getElementById("QAS_city")){
if(document.getElementById("QAS_city").nodeName=="SELECT"){
_46.innerHTML=_3c;
document.getElementById("QAS_city").value=this.cityInputTextBoxValue;
}
}
_47.style.display="none";
_48.style.display="none";
}else{
if(_4a=="Business"){
_40.innerHTML="Company:";
_41.innerHTML="Address Line 1:";
_42.innerHTML="Address Line 2:";
_43.innerHTML="Address Line 3:";
_44.innerHTML="City:";
_45.style.display="none";
if(document.getElementById("QAS_city")){
if(document.getElementById("QAS_city").nodeName=="SELECT"){
_46.innerHTML=_3c;
document.getElementById("QAS_city").value=this.cityInputTextBoxValue;
}
}
_47.style.display="none";
_48.style.display="";
}else{
if(_4a=="APO/FPO"){
_40.innerHTML="Organization:";
_41.innerHTML="Unit/Ship/PSC Number:";
_42.innerHTML="Box/Hull NUmber";
_43.innerHTML="Address Line 3:";
_44.innerHTML="APO/FPO";
_45.style.display="";
if(document.getElementById("QAS_city")){
if(document.getElementById("QAS_city").nodeName=="INPUT"){
_3d=document.getElementById("QAS_city").value;
AddressBookFormJS.setCityInputTextBoxValue(_3d);
_46.innerHTML=_3e;
}
}
_47.style.display="";
_48.style.display="none";
}else{
if(_4a=="P.O. Box"){
_40.innerHTML="Company:";
_41.innerHTML="P.O. Box:";
_42.innerHTML="Address Line 2:";
_43.innerHTML="Address Line 3:";
_44.innerHTML="City:";
_45.style.display="none";
if(document.getElementById("QAS_city")){
if(document.getElementById("QAS_city").nodeName=="SELECT"){
_46.innerHTML=_3c;
document.getElementById("QAS_city").value=this.cityInputTextBoxValue;
}
}
_47.style.display="none";
_48.style.display="none";
}else{
_40.innerHTML="Company:";
_41.innerHTML="Address Line 1:";
_42.innerHTML="Address Line 2:";
_43.innerHTML="Address Line 3:";
_44.innerHTML="City:";
_45.style.display="none";
if(document.getElementById("QAS_city")){
if(document.getElementById("QAS_city").nodeName=="SELECT"){
_46.innerHTML=_3c;
document.getElementById("QAS_city").value=this.cityInputTextBoxValue;
}
}
_47.style.display="none";
_48.style.display="none";
}
}
}
}
this.loadStatesUI("AddressForm","");
if(this.validateLoadFields=="true"){
dojo.lang.setTimeout(AddressBookFormJS,"validateAddressForm",100,"AddressForm","refreshArea");
}
},updateAddress:function(_4b,_4c){
if(this.validateAddressForm(_4b,"refreshArea")){
dojo.debug("creating with form id = "+_4b+" and  address display url is: "+_4c);
dojo.require("wc.service.*");
wc.service.declare({id:"updateAddress",actionId:"updateAddress",url:"AjaxPersonChangeServiceAddressAdd",formId:_4b,successHandler:function(_4d){
wc.render.getRefreshControllerById("MyAccountCenterLinkDisplay_Controller").url=_4c;
wc.render.updateContext("MyAccountCenterLinkDisplay_Context",{workAreaMode:"addressBook"});
},failureHandler:function(_4e){
alertDialog(_4e.errorMessageKey,AddressBookFormJS.storeId,AddressBookFormJS.catalogId,AddressBookFormJS.langId);
}});
this.validateLoadFields="false";
wc.service.invoke("updateAddress");
}else{
this.setValidateLoadFields();
}
},deleteAddress:function(_4f,_50,_51){
dojo.require("wc.service.*");
wc.service.declare({id:"AddressDelete",actionId:"AddressDelete",url:_4f,successHandler:function(_52){
wc.render.getRefreshControllerById("MyAccountCenterLinkDisplay_Controller").url=_50;
wc.render.updateContext("MyAccountCenterLinkDisplay_Context",{workAreaMode:"addressBookDelete"+_51});
},failureHandler:function(_53){
dojo.debug("error: "+_53);
alertDialog(_53.errorMessageKey,this.storeId,this.catalogId,this.langId);
}});
wc.service.invoke("AddressDelete");
},loadStatesUI:function(_54,_55){
var _56=document.getElementById(_54);
var _57=_56["country"].value;
var _58=_56["state"].value;
var _59=document.getElementById(_55+this.stateDivName);
if(countries[_57].states){
_59.innerHTML=this.createStateWithOptions(_55,_57,_58);
}else{
_59.innerHTML=this.createState(_55,_58);
}
},createStateWithOptions:function(_5a,_5b,_5c){
var _5d="";
var _5e=document.getElementById("addressField2");
for(state_code in countries[_5b].states){
if(!_5e||(_5e.options[_5e.selectedIndex].value=="APO/FPO"&&countries[_5b].states[state_code].substring(0,5)=="Armed")||(_5e.options[_5e.selectedIndex].value!="APO/FPO"&&countries[_5b].states[state_code].substring(0,5)!="Armed")){
if(state_code==_5c||countries[_5b].states[state_code]==_5c){
_5d=_5d+"<option selected = 'true' value='"+state_code+"'>"+countries[_5b].states[state_code]+"</option>";
}else{
_5d=_5d+"<option value='"+state_code+"'>"+countries[_5b].states[state_code]+"</option>";
}
}
}
var _5f="<select class='addressSelectSmallDropdown' name='state' id='"+_5a+"QAS_state'>";
_5f=_5f+_5d+"</select>";
return _5f;
},createState:function(_60,_61){
var _62=document.createElement("input");
var _63="<input class='addressSelectSmall' type='text' name='state' id='"+_60+"state' value='"+_61+"'>";
return _63;
},clearFields:function(_64){
var _65=document.forms[_64];
Common.hideErrorNodes();
var _66=document.forms[_64].getElementsByTagName("input");
for(var _67=0;_67<_66.length;_67++){
if((_66[_67].type=="text")){
_66[_67].value="";
}
}
var _68=document.forms[_64].getElementsByTagName("select");
for(var _67=0;_67<_68.length;_67++){
_68[_67].options[0].selected="1";
}
if(_65.selectShippingAddressId){
_65.selectShippingAddressId.options[0].selected="1";
}
}};

