function setUpClickToEditFields(){JQ("p.editable").each(function(){JQ(this).hover(function(){JQ(this).addClass("hovered");JQ(this).append(clickTextSpan)},function(){JQ(this).removeClass("hovered");JQ(this).find(".clickTextSpan").remove()}).click(function(){JQ(this).removeClass("hovered");JQ(this).find(".clickTextSpan").remove();var div=JQ(this).parent('div[className*="form"]');if(div.is(".form_off")){div.removeClass("form_off").addClass("form_on").next("p.disclaimer").toggle()}JQ("#"+JQ(this).attr("id").replace(/display/,"edit")).focus()})})}function setUpSecurityQuestion(){JQ("div#security_question").hover(function(){JQ(this).addClass("toEdit").find("h3").addClass("toEdit");JQ(this).find(".clickTextSpanSec span").show()},function(){JQ(this).removeClass("toEdit").find("h3").removeClass("toEdit");JQ(this).find(".clickTextSpanSec span").hide()}).bind("click",function(e){editMode=true;var $target=JQ(e.target);var wrapper=JQ("> div",this);if($target.is("input#cancelSecurity")){$divs=JQ("div",wrapper).not(".button_container",".clickTextSpanSec");JQ.each($divs,function(i,n){JQ(n).slideToggle()});JQ("input[name=passwordQuestion]").setValue(prof.passwordQuestion);JQ("input[name=passwordAnswer]").setValue(prof.passwordAnswer);JQ(this).toggleClass("editing").find("h3").toggleClass("editing");editMode=false}else{if($target.is("input#submitSecurity")){trySubmit($target);JQ(this).toggleClass("editing").find("h3").toggleClass("editing")}else{if((!$target.is("input"))){$divs=JQ("div",wrapper).not(".button_container",".clickTextSpanSec");JQ.each($divs,function(i,n){JQ(n).slideToggle()});JQ(this).toggleClass("editing").find("h3").toggleClass("editing")}}}})}function deactivateAccountModal(){JQ.blockUI({message:JQ("#deactivate_account_modal"),css:{width:"570px"}});if(typeof(window.tracking!="undefined")){tracking.click({pageName:track_site+">profile>pers_info>deactivate",prop17:"profile",prop18:"profile",eVar48:track_site+">profile>pers_info>deactivate",events:"event13"})}}function confirmAccountDeactivation(){var url=PROFILE_SERVICE_URL+"?action=deregister&busta="+parseInt(Math.random()*99999999);var req={url:url,meth:"POST",data:{},onready:function(data){var profileService=JQ.xml2json(data);var status=profileService.status;if(status=="success"){if(typeof(window.tracking!="undefined")){tracking.click({pageName:track_site+">profile>pers_info>deactivate>complete",prop17:"profile",prop18:"profile",prop21:"brand",eVar48:track_site+">profile>pers_info>deactivate",events:"event13"})}window.location.href="profile?page=deregistered&continueURL="+continueURL;CallbackManager.callbacks={};CallbackManager.callbackIndexes={}}else{JQ.unblockUI()}}};f4a.open(req);data=null}function trySubmit(JQsaveButton){JQform=JQsaveButton.parents("form");validate(JQform,function(){formUpdateSuccess(JQform)})}function validate(JQform,callback){var validForm=true;clearErrors(JQform);JQ(allFields).each(function(){showLabelError=false;if(this.formId==JQform.attr("id")){if((JQ("#edit-"+this.id,JQform).val()==""||JQ("#edit-"+this.id,JQform).val()=="-1")&&this.required!="no"){showError(this,showLabelError,false,true);validForm=false}else{if(this.validationType){if(!validateField(this)){showError(this,showLabelError,false);validForm=false}}if(this.matchField!=undefined){if(!validateMatch(this)){showError(this,showLabelError,false);validForm=false}}}}});if(validForm){postForm(JQform,callback)}else{console.log("no good")}}function validateAddress(JQform,callback){var validForm=true;clearErrors(JQform);JQ(allFields).each(function(){showLabelError=false;if(this.formId==JQform.attr("id")){if((JQ("#edit-"+this.id,JQform).val()==""||JQ("#edit-"+this.id,JQform).val()=="-1")&&this.required!="no"){showError(this,showLabelError,false,true);validForm=false}else{if(this.validationType){if(!validateField(this)){showError(this,showLabelError,false);validForm=false}}if(this.matchField!=undefined){if(!validateMatch(this)){showError(this,showLabelError,false);validForm=false}}}}});if(validForm){postAddressForm(JQform,callback)}else{}}function postForm(JQform,callback){doAction(JQform,PROFILE_SERVICE_URL,JQform.serialize(),"update",function(data){formUpdateHandleProfileService(data,JQform,callback)})}function postAddressForm(JQform,callback){console.log(JQform);JQform.find(".loading").show().end().find("p.error, p.success").hide();var action=JQform.find("input:hidden[name=action]").val();var serializedForm=JQform.serialize();doAction(JQform,PROFILE_SERVICE_URL,serializedForm,action,function(data){if(data.status=="success"){callback(data)}else{showServerError(JQform,_profileService)}})}function formUpdateSuccess(JQform){JQform.find("p.error, .loading").hide();JQform.find("p.success").show();if(typeof(window.tracking!="undefined")){tracking.click({pageName:track_site+">profile>pers_info>save",prop17:"profile",prop18:"profile",eVar48:track_site+">profile>pers_info>save",events:"event13"})}}function addressFormUpdateSuccess(JQform,profileService){var _profile=profileService.profile;JQform.find("p.error, .loading").hide();if(AddressManager.loadAddresses(_profile)){home=AddressManager.getHomeAddress();billing=AddressManager.getBillingAddress();primaryShipping=AddressManager.getPrimaryShippingAddress();if(home!=null){Render.renderAddresses(home)}if(billing!=null){Render.renderAddresses(billing)}if(primaryShipping!=null){Render.renderAddresses(primaryShipping)}toggleAll()}if(typeof(window.tracking!="undefined")){tracking.click({pageName:track_site+">profile>address_book>save",eVar48:track_site+">profile>address_book>save",events:"event13"})}}function secondaryAddressFormUpdateSuccess(JQform,profileService){loadSecondaryAddresses(handleSecondaryAddresses)}function loadProfile(callback){var url=PROFILE_SERVICE_URL+"?action=getprofile";url=url+"&busta="+parseInt(Math.random()*99999999);var req={url:url,meth:"POST",data:{},onready:function(data){data=data.replace(/\&(?!amp;)/g,"&amp;");var profileService=JQ.xml2json(data);var id=profileService.profile.id;var login=profileService.profile.login;if(id&&id!=""&&login&&login!=""){isLoggedIn=true;callback(data)}else{boot("profile?page=login&continueURL=profile%3Fpage%3Dpersonal_info","NOT LOGGED IN!")}}};f4a.open(req)}function boot(URL,comment){window.location.href=URL}function jsonifyAndPrepopulate(){loadProfile(initialHandleProfileService);if(window.handleSecondaryAddresses){setTimeout(function(){loadSecondaryAddresses(handleSecondaryAddresses)},500)}}JQ.aop.before({target:window,method:"postForm"},function(){JQ.blockUI()});JQ.aop.after({target:window,method:"formUpdateSuccess"},function(){JQ.unblockUI()});function loadSecondaryAddresses(callback){var url=PROFILE_SERVICE_URL+"?action=getsecondaryaddresses";url=url+"&busta="+parseInt(Math.random()*99999999);var req={url:url,meth:"POST",data:{},onready:function(data){data=data.replace(/\&(?!amp;)/g,"&amp;");var profileService=JQ.xml2json(data);if(profileService.secondaryAddresses!=null){var nickname=(profileService.secondaryAddresses.constructor==Array)?profileService.secondaryAddresses[0].nickname:profileService.secondaryAddresses.nickname;if(!nickname||nickname==""){unblockUI=true}else{callback(profileService)}}else{unblockUI=true}}};f4a.open(req)}function updateProfileSummary(element,profile){var nameToUse=profile.email;if((profile.firstName!="")&&(profile.lastName!="")){nameToUse=profile.firstName+" "+profile.lastName}if(profile.screenName!=""){nameToUse=profile.screenName}JQ("h1",element).html(nameToUse);minifieldH1();JQ("#profile_summary-email").html(profile.email);var loc="";var us=false;var hasCity=false;var stateChecked=true;var country=profile["homeAddress.country"];var city=profile["homeAddress.city"];var state=profile["homeAddress.state"];if(country!=""){JQ("#profile_summary-location_label").show();if(country=="US"){country="United States"}if(city.length>0){loc+=city;hasCity=true}if(country=="United States"){if(state.length>0){loc+=","+state+"<br />";us=true}}if((hasCity)&&(!us)){loc+=", "+country}else{loc+=country}JQ("#profile_summary-location").show().html(loc)}}function activateFormFields(profile,callback){if(JQ("#dob_container").is(".form_on")){toggleForm(JQ("#dob_container"))}JQ.each(checkFields,function(){var path="input[name='"+this+"']";if(JQ(path).getValue()==""){var div=JQ(path).parent('div[className*="form"]');if(div.is(".form_off")){div.removeClass("form_off").addClass("form_on").next("p.disclaimer").toggle()}}else{var div=JQ(path).parent("div[className*=form");if(div.is(".form_on")){toggleForm(div);div.next("p.disclaimer").hide()}}});if(callback){callback()}}function toggleForm(container){container.removeClass("form_on").addClass("form_off")}function cancelForm(JQCancelButton){JQform=JQCancelButton.parents("form");formID=JQform.attr("id");JQform.find(".loading").show().end().find("p.error, p.success").hide();clearErrors(JQform);if(formID=="basic_info_form"){JQform.autoFill(prof);if(JQ("#dob_container").is(".form_on")){toggleForm(JQ("#dob_container"))}JQ.each(checkFields,function(){var path="input[name='"+this+"']";if(JQ(path).getValue()!=""){var div=JQ(path).parent("div[css*=form");if(div.is(".form_on")){toggleForm(div);div.next("p.disclaimer").toggle()}}})}else{if(formID=="change_password"){JQform.find(":password").val("")}}JQform.find(".loading").hide()}function loadForm(_profile,JQform,callback){if(_profile.dobMonth){if(_profile.dobMonth.length==1){_profile.dobMonth="0"+_profile.dobMonth}}if(_profile.dobDay){if(_profile.dobDay.length==1){_profile.dobDay="0"+_profile.dobDay}}JQ("form").autoFill(_profile);if(JQform){switch(JQform.attr("id")){case"secQuestion":showSuccessfulSecSave(JQ("#questionWrapper"));break;default:JQform.populateByName(_profile,{fixText:function(id){fixedId=(id).replace(/\./i,"_");fixedId="display-"+fixedId;return fixedId}});break}}else{unblockUI=true;JQ("#basic_info_form").populateByName(_profile,{fixText:function(id){fixedId=(id).replace(/\./i,"_");fixedId="display-"+fixedId;return fixedId}})}activateFormFields(_profile,callback)}function showSuccessfulSecSave(){JQ.each($divs,function(i,n){JQ(n).toggle()})}function initialHandleProfileService(xml,JQform){xml=xml.replace(/\&(?!amp;)/g,"&amp;");profileService=JQ.xml2json(xml);prof=profileService.profile;initialScreenName=prof.screenName;initialMobileNumber=prof.mobileNumber;initialLastName=prof.lastName;updateProfileSummary(JQ("#profile_summary"),prof);loadForm(prof,null,null)}function formUpdateHandleProfileService(_profileService,JQform,callback){_prof=_profileService.profile;if(_prof!=null){if(_prof.screenName!=""){currentScreenName=true}if(_prof.mobileNumber!=""){currentMobileNumber=true}if(_prof.lastName!=""){currentLastName=true}updateProfileSummary(JQ("#profile_summary"),_prof);initialScreenName=currentScreenName;return loadForm(_prof,JQform,callback)}else{showServerError(JQform,_profileService)}}function doAction(JQform,url,data,action,callback){if(action=="logout"){data={}}ajaxProgress=true;data.action=action;url=url+"?busta="+parseInt(Math.random()*99999999);var req={url:url,meth:"POST",data:data,onready:function(data){data=data.replace(/\&(?!amp;)/g,"&amp;");var profileService=JQ.xml2json(data);var status=profileService.status;if(status=="success"){callback(profileService)}else{showServerError(JQform,profileService)}}};f4a.open(req);data=null}function showServerError(JQform,profileService){if(JQ("#delete_address_confirmation:visible").length>0){JQ("#delete_address_confirmation p").text(errorMessage);setTimeout(function(){JQ.unblockUI();JQ("#delete_address_confirmation p").text(originalRemovalText);CallbackManager.callbacks={};CallbackManager.callbackIndexes={}},5000)}else{JQ.unblockUI();var error=profileService.exceptions.error.constructor==Array?profileService.exceptions.error[0]:profileService.exceptions.error;var errorMessage=error.message;var offendingField=error.property;JQform.find(".loading").hide().end().find("p.error").html(errorMessage).show();JQform.find("[name="+offendingField+"], label[for="+offendingField+"]").addClass("error")}}function validateProtocol(){if(location.href.indexOf(".nike.com")>=1&&location.href.indexOf("env")<0){if(location.protocol=="http:"){window.location.href=location.href.replace(/http:/,"https:")}}}function loadStateList(element,country,callback){var url=PROFILE_SERVICE_URL+"?action=getstatelist";var data="country="+UPM.country;var req2={url:url,meth:"POST",data:data,onready:function(data){var stateJson=JQ.xml2json(data);element.append("<option value=' '></option>");JQ(stateJson.states.state).each(function(){element.append("<option value='"+this.code+"'>"+this.text[0]+"</option>")});if(callback!=null){callback()}}};f4a.open(req2)}function loadCountryList(element,locale,country,callback){var url=PROFILE_SERVICE_URL+"?action=getcountrylist";var data="locale="+UPM.locale;var req={url:url,meth:"POST",data:data,onready:function(data){var countryJson=JQ.xml2json(data);JQ(countryJson.countries.country).each(function(){var selected="";if(country==this.code){selected=" selected"}element.append("<option value='"+this.code+"' "+selected+">"+this.text[0]+"</option>")});if(callback!=null){callback()}}};f4a.open(req)}function disallowBadCharacters(JQinputFields){JQinputFields.keypress(function(e){if(e.which==32||(33<=e.which&&e.which<=44)||e.which==47||(58<=e.which&&e.which<=64)||(91<=e.which&&e.which<=94)||e.which==96||123<=e.which){return false}else{return true}})}function initForm(formID){JQ(fieldData[formID]).each(function(){var f=new Object();f.formId=formID;if(this.id!=undefined){f.id=this.id}else{if(this.name!=undefined){f.id=this.name}}if(this.required!=undefined){f.required=this.required}if(this.labelError!=undefined){f.labelError=this.labelError}if(this.labelServerError!=undefined){f.labelServerError=this.labelServerError}if(this.validationType!=undefined){f.validationType=this.validationType}if(this.group!=undefined){f.group=this.group;f.groupOrder=this.groupOrder;f.label=JQ("#label-"+this.group).html()}else{f.label=JQ("#label-"+f.id).html()}if(this.matchField!=undefined){f.matchField=this.matchField}allFields.push(f);f=null})}function validateEmail(email){var filter=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;showLabelError=true;return(filter.test(email))?true:false}function validateDate(m,d,y){if(m==-1&&d==-1&&y==-1){showLabelError=false;return false}else{if(m==-1||d==-1||y==-1){showLabelError=true;return false}else{showLabelError=true;m=m-1;var testDate=new Date(y,m,d);if((testDate.getFullYear()==y)&&(testDate.getMonth()==m)&&(testDate.getDate()==d)){return true}else{return false}}}}function validateZipcode(zipcode){showLabelError=true;return(zipcode.length<2||zipcode.length>9)?false:true}function validateUSPostalCode(zipcode){showLabelError=true;return(zipcode.length==5)?true:false}function validateEMEAPostalCode(zipcode){showLabelError=true;return(zipcode.length<2||zipcode.length>9)?false:true}function validateRadioButtons(f){showLabelError=true;return(JQ("input[name='"+f.id+"']:checked").val()!=undefined)?true:false}function validateName(name){var filter=/^(([a-zA-Z]+)(\s|\-){0,1})+[a-zA-Z]+$/;showLabelError=true;return(filter.test(name))?true:false}function validatePhone(f){var filter=/^((\([0-9]{1,3}\))|([0-9]+)|(\+[0-9]{1}))((\s|\-|\.|\,){0,1}[0-9])+$/;showLabelError=true;var phone=JQ("#"+f.formId+" #edit-"+f.id).val();if(phone.length>0){if(phone.length<8){return false}else{return(filter.test(phone))?true:false}}return true}function validateState(f){if(JQ("#"+f.formId+" #edit-"+f.id).val()==" "){return(JQ("#"+f.formId+" .country_select").val()=="US")?false:true}return true}function validateMatch(f){showLabelError=true;return(JQ("#edit-"+f.id).val()==JQ("#edit-"+f.matchField).val())?true:false}function validateField(f){if(f.group==undefined){if(f.validationType=="email"){return validateEmail(JQ("#"+f.formId+" #edit-"+f.id).val())}if(f.validationType=="zipcode"){return validateZipcode(JQ("#"+f.formId+" #edit-"+f.id).val())}if(f.validationType=="USPostalCode"){return validateUSPostalCode(JQ("#"+f.formId+" #edit-"+f.id).val())}if(f.validationType=="EMEAPostalCode"){return validateEMEAPostalCode(JQ("#"+f.formId+" #edit-"+f.id).val())}if(f.validationType=="radio"){return validateRadioButtons(f)}if(f.validationType=="name"){return validateName(JQ("#"+f.formId+" #edit-"+f.id).val())}if(f.validationType=="phone"){return validatePhone(f)}if(f.validationType=="state"){return validateState(f)}}else{if(f.validationType=="date"){var group=f.groupOrder.split(",");return validateDate(JQ("#edit-"+group[0]).val(),JQ("#edit-"+group[1]).val(),JQ("#edit-"+group[2]).val())}}}function showError(f,label,server,empty){if(empty==undefined){empty=false}if(f.formId){formId="#"+f.formId+" "}else{formId=""}if(label&&server&&f.labelServerError!=undefined){var labelError=f.labelServerError}else{var labelError=f.labelError}if(label){if(f.group!=undefined){if(labelError){JQ(formId+"#label-"+f.group).html(labelError.toUpperCase())}JQ(formId+"#label-"+f.group).addClass("error")}else{if(labelError){JQ(formId+"#label-"+f.id).html(labelError.toUpperCase())}JQ(formId+"#label-"+f.id).addClass("error")}}if(empty){if(f.group!=undefined){JQ(formId+"#label-"+f.group).addClass("error")}else{JQ(formId+"#label-"+f.id).addClass("error")}}if(f.group!=undefined){var group=f.groupOrder.split(",");JQ(group).each(function(){JQ(formId+"#edit-"+this).addClass("error")})}else{JQ(formId+" #edit-"+f.id).addClass("error");if(f.matchField!=undefined){JQ(formId+"#edit-"+f.matchField).addClass("error")}}}function clearErrors(JQform){JQform.find(".loading").hide().end().find("p.error").html("").hide();JQ(allFields).each(function(){if(this.group!=undefined){JQ("#label-"+this.group,JQform).html(this.label);JQ("#label-"+this.group,JQform).removeClass("error")}else{JQ("#label-"+this.id,JQform).html(this.label);JQ("#label-"+this.id,JQform).removeClass("error")}JQ("#edit-"+this.id,JQform).removeClass("error")})}function blockNonAlphaNumericChars(e){if(e.which==32||(33<=e.which&&e.which<=44)||e.which==47||(58<=e.which&&e.which<=64)||(91<=e.which&&e.which<=94)||e.which==96||123<=e.which){return false}else{return true}}function blockNonAlphaNumericCharsAllowSpaces(e){if((33<=e.which&&e.which<=44)||e.which==47||(58<=e.which&&e.which<=64)||(91<=e.which&&e.which<=94)||e.which==96||123<=e.which){return false}else{return true}}function blockNonNumericChars(e){if(e.which==32||(33<=e.which&&e.which<=44)||e.which==47||(58<=e.which&&e.which<=95)||96<=e.which){return false}else{return true}};
