function setUpClickToEditFields(){JQ("p.editable").each(function(){JQ(this).hover(function(){JQ(this).addClass("hovered");JQ(this).append(UPM.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){UPM.editMode=true;var $target=JQ(e.target);var wrapper=JQ("> div",this);$divs=JQ("div",wrapper).not(".button_container",".clickTextSpanSec");var secQClose=JQ("#default");var secQOpen=JQ("#securityQuestion");if($target.is("input#cancelSecurity")){secQClose.slideToggle();secQOpen.slideToggle();JQ("input[@name=passwordQuestion]").setValue(UPM.prof.passwordQuestion);JQ("input[@name=passwordAnswer]").setValue(UPM.prof.passwordAnswer);JQ(this).toggleClass("editing").find("h3").toggleClass("editing");UPM.editMode=false}else{if($target.is("input#submitSecurity")){trySubmit($target);JQ(this).toggleClass("editing").find("h3").toggleClass("editing")}else{if($target.is("option")){}else{if(!$target.is("input")){secQClose.slideToggle();secQOpen.slideToggle();JQ(this).toggleClass("editing").find("h3").toggleClass("editing")}}}}})}function deactivateAccountModal(){JQ.blockUI({message:JQ("#deactivate_account_modal"),css:{width:"570px",left:"50%",top:"30%","margin-left":"-570px"}});if(typeof(window.tracking!="undefined")){tracking.click({pageName:track_site+">profile>my_profile>my_settings>basic>deactivate"})}}function confirmAccountDeactivation(){var url=PROFILE_SERVICE_URL+"?action=deregister";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>my_profile>my_settings>basic>deactivate>complete"})}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-screenName").val()==""||JQ("#edit-email").val()=="")){showError(this,showLabelError,false,true);validForm=false}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){JQform.find(".loading").show().end().find("p.error, p.success").hide();JQform.find("select.state_select").removeAttr("disabled");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")){switch(JQform.attr("id")){case"basic_info_form":tracking.click({pageName:track_site+">profile>my_profile>my_settings>basic>info>save"});break;case"change_password":tracking.click({pageName:track_site+">profile>my_profile>my_settings>basic>password>save"});break;case"secQuestion":tracking.click({pageName:track_site+">profile>my_profile>my_settings>basic>security>save"});break}}if(typeof(window.ss)!="undefined"){setNavProfile(NIKEOS.ME.getCookie());ss.syncProfile(ss.DPSID);setTimeout(function(){ss.getProfileInfo(ss.DPSID)},4000);if(typeof(window.nikeplus)!="undefined"){nikeplus.plus.syncProfileSettings(function(data){});loadProfile(initialHandleProfileService)}}else{NIKEOS.log("unable to sync profile to socialsite")}}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>my_profile>my_settings>address_book>save"})}}function secondaryAddressFormUpdateSuccess(JQform,profileService){loadSecondaryAddresses(handleSecondaryAddresses)}function loadProfile(callback){console.log("------------- loadProfile");var url=PROFILE_SERVICE_URL;var data="action=getprofile";var req={url:url,meth:"POST",data: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;var screenName=profileService.profile.screenName;NIKEOS.log("data: ",profileService," : cb: ",callback);if(id&&id!=""&&login&&login!=""){isLoggedIn=true;if(screenName.length==0){boot("profile?page=update&continueURL="+escape(location.href),"NO SCREEN NAME")}else{addToCookie(profileService.profile);callback(profileService.profile)}}else{if(typeof(window.PUBLIC)=="undefined"){boot("profile?page=login&continueURL="+escape(location.href),"NOT LOGGED IN")}else{callback("public")}}}};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";var req={url:url,meth:"POST",data:{},onready:function(data){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){if(typeof(window.ss!="undefined")){ss.getProfileInfo()}}function activateFormFields(profile,callback){if(JQ("#dob_container").is(".form_on")){toggleForm(JQ("#dob_container"))}JQ.each(UPM.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(UPM.prof);if(JQ("#dob_container").is(".form_on")){toggleForm(JQ("#dob_container"))}JQ.each(UPM.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){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(data,JQform){if(data=="public"){console.log("user is not logged in - public view")}else{UPM.prof=data;UPM.initialScreenName=data.screenName;UPM.initialMobileNumber=data.mobileNumber;UPM.initialLastName=data.lastName;loadForm(data,null,null)}}function formUpdateHandleProfileService(_profileService,JQform,callback){_prof=_profileService.profile;if(_prof!=null){if(_prof.screenName!=""){UPM.currentScreenName=true}if(_prof.mobileNumber!=""){UPM.currentMobileNumber=true}if(_prof.lastName!=""){UPM.currentLastName=true}UPM.initialScreenName=UPM.currentScreenName;addToCookie(_prof);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;var req={url:url,meth:"POST",data:data,onready:function(data){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.hostname.indexOf(".nike.com")>=1&&(location.hostname.indexOf("env")==0)&&(location.hostname.indexOf("ecn")==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";if(country=="US"){country="USNT"}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="lang_locale="+UPM.locale;var req={url:url,meth:"POST",data:data,onready:function(data){var countryJson=JQ.xml2json(data);if(countryJson.countries.country){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 validateUniqueEmail(email,form){showLabelError=true;var numberLessThan=(JQ(form).find("input[@name=bvdid]").val()=="")?1:2;var foundAddress=AddressManager.findFamilyAddressByEmail(email);return(numberLessThan>foundAddress.length)?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,form){if(f.group==undefined){if(f.validationType=="email"){return validateEmail(JQ("#"+f.formId+" #edit-"+f.id).val())}if(f.validationType=="uniqueemail"){return validateUniqueEmail(JQ("#"+f.formId+" #edit-"+f.id).val(),form)}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}}function addToCookie(data){var filter=["email","screenName","id"];var filteredData={};for(var i in data){for(var j=0;j<filter.length;j++){if(i==filter[j]){filteredData[i]=data[i]}}}NIKEOS.ME.addToCookie(filteredData)};
