function showLoading(){$j(".frmGreg").hide();$j("#ajaxSpinner").show()}function hideLoading(){$j("#ajaxSpinner").hide()}$j(document).ready(function(){loadQuestionaire()});function loadQuestionaire(){$j.get("/glovebox/registration/questionaire",function(data){$j("#ajaxResponse").html(data);initQuestionaireBindings();hideLoading()});showLoading()}function initQuestionaireBindings(){$j("#currentMember").click(function(){$j("#question2").show()});$j("#nonMember").click(function(){loadRegistrationForm()});$j("#currentMember").click(function(){loadRewardsValidation()})}function initRewardsValidationBindings(){$j("#rewardsValidation #submit").click(function(){submitRewardsValidationForm()})}function loadRewardsValidation(){$j.get("/glovebox/registration/rewards_validation",function(data){$j("#ajaxResponse").html(data);initRewardsValidationBindings();hideLoading()});showLoading()}function submitRewardsValidationForm(){$j.post("/glovebox/registration/rewards_validation",$j("#rewardsValidation").serialize(),function(data){$j("#ajaxResponse").html(data);initRewardsValidationBindings();initRewardsCustomerInfoBindings();hideLoading()});showLoading()}function initRewardsCustomerInfoBindings(){$j("#rewardsCustomerInfo #submit").click(function(){submitRewardsCustomerInfoForm()})}function submitRewardsCustomerInfoForm(){showLoading();$j.post("/glovebox/registration/rewards_customer_info",$j("#rewardsCustomerInfo").serialize(),function(data){$j("#ajaxResponse").html(data);initRewardsCustomerInfoBindings();initRegistrationFormBindings();hideLoading()})}function loadRegistrationForm(){var customerId=$j("#customerId").val();var request="/glovebox/registration/customer_profile";$j.get(request,function(data){$j("#ajaxResponse").html(data);initRegistrationFormBindings();hideLoading()});showLoading()}function submitRegistrationForm(){$j.post("/glovebox/registration/customer_profile",$j("#registrationForm").serialize(),function(data){$j("#ajaxResponse").html(data);initRegistrationFormBindings();initPreferencesFormBindings();hideLoading()});showLoading()}function initRegistrationFormBindings(){$j("#textNumberLabel, #textNumberInput").hide();$j("#reminderViaText").click(function(){$j("#textNumberLabel, #textNumberInput").show()});var customerId=$j("#customerId").val();if(customerId){$j("#emailAndPassword").hide()}$j("#registrationForm #previous").click(function(){loadQuestionaire()});$j("#registrationForm #continue").click(function(){submitRegistrationForm()});$j(".preferenceForm").click(function(){loadPreferencesForm()});$j(".vehiclesForm").click(function(){loadVehiclesForm()});$j(".storesForm").click(function(){skipVehicle()})}function loadPreferencesForm(){$j.get("/glovebox/registration/contact_preferences",function(data){$j("#ajaxResponse").html(data);initPreferencesFormBindings();hideLoading()});showLoading()}function submitPreferencesForm(){$j.post("/glovebox/registration/contact_preferences",$j("#contactPreferences").serialize(),function(data){$j("#ajaxResponse").html(data);initVehicleFormBindings();hideLoading()});showLoading()}function initPreferencesFormBindings(){$j(".previous").click(function(){loadRegistrationForm()});$j(".save").click(function(){submitPreferencesForm()});$j(".continue").click(function(){loadVehiclesForm()});$j(".profile").click(function(){loadRegistrationForm()});$j(".vehiclesForm").click(function(){loadVehiclesForm()});$j(".storesForm").click(function(){loadVehiclesForm()})}function loadVehiclesForm(){$j.get("/glovebox/registration/your_vehicles",function(data){$j("#ajaxResponse").html(data);initVehicleFormBindings();hideLoading()});showLoading()}function initVehicleFormBindings(){$j("#addAVehicle").click(function(){createYMME({},false,true,false,doVehicleAdd)});$j("#addAnotherVehicle").click(function(){});$j("#saveAndContinue").click(function(){});$j(".profile").click(function(){loadRegistrationForm()});$j(".preferenceForm").click(function(){loadPreferencesForm()});$j(".storesForm").click(function(){skipVehicle()})}function doVehicleAdd(){if(doYmmeRefresh==true){$j.post("/glovebox/registration/add_vehicle",null,function(data){$j("#ajaxResponse").html(data);initVehicleFormBindings()});doYmmeRefresh=false;PreSimpleSwapOnload();SimpleSwapSetup()}}function saveVehicle(){$j.post("/glovebox/registration/save_vehicle",$j("#vehicleForm").serialize(),function(data){$j("#ajaxResponse").html(data);if($j("#hasErrors").val()!="true"){createYMME({},false,true,false,doVehicleAdd)}initVehicleFormBindings();hideLoading()});showLoading()}function saveVehicleAndContinue(){var mileage=replaceAll($j("#lastKnownMileage").val(),",","");$j("#lastKnownMileage").val(mileage);var mileage=replaceAll($j("#averageAnnualMileage").val(),",","");$j("#averageAnnualMileage").val(mileage);$j.post("/glovebox/registration/save_vehicle_continue",$j("#vehicleForm").serialize(),function(data){$j("#ajaxResponse").html(data);initSearchStores();hideLoading()});showLoading()}function skipVehicle(){var tsTimeStamp=new Date().getTime();$j.get("/glovebox/registration/your_stores",{time:tsTimeStamp},function(data){$j("#ajaxResponse").html(data);initSearchStores();hideLoading()});showLoading()}function preferredStore(storeKey,location,phone,addressLine1,addressLine2,distance,zip){this.storeKey=storeKey;this.location=location;this.phone=phone;this.addressLine1=addressLine1;this.addressLine2=addressLine2;this.distance=distance;this.zip=zip;this.getDistanceFromZip=function(){return this.distance+" from "+this.zip};this.toString=function(){return this.storeKey+", "+this.location+", "+this.phone+", "+this.addressLine1+", "+this.addressLine2+", "+this.distance+", "+this.zip}}var prefStores={};function initSearchStores(){initStoresBindings();$j("#searchByZipCode").click(function(){searchStores()});$j("#continue").click(function(){var favStores="";for(storeKey in prefStores){if(prefStores[storeKey]){favStores+=storeKey+","}}favStores=favStores.substring(0,favStores.length-1);$j(this).attr("href","/glovebox/registration/save_stores?favStores="+favStores);return true});$j(".profile").click(function(){loadRegistrationForm()});$j(".preferenceForm").click(function(){loadPreferencesForm()});$j(".vehiclesForm").click(function(){loadVehiclesForm()});$j(".skip").click(function(){$j(this).attr("href","/glovebox/registration/save_stores");return true})}function searchStores(){var zipCode=$j("#zipCode").val();$j.post("/glovebox/registration/your_stores?zipCode="+zipCode,$j("#storesLookup").serialize(),function(data){$j("#gregStoreAjaxSearch").html(data);initStoresBindings()})}function initStoresBindings(){$j(".addPrefStore").click(function(){var pStoreKey=$j(this).parent().attr("id");var pLocation=$j("#"+pStoreKey+" .gregStoreText .strLocation").text();var pPhone=$j("#"+pStoreKey+" .gregStoreText .strPhone").text();var pAddressLine1=$j("#"+pStoreKey+" .gregStoreText .strAddressLine1").text();var pAddressLine2=$j("#"+pStoreKey+" .gregStoreText .strAddressLine2").text();var pDistance=$j("#"+pStoreKey+" .gregStoreDistance").text();var pZip=$j("#"+pStoreKey+" .gregStoreText .strZip").text();var prefStore=new preferredStore(pStoreKey,pLocation,pPhone,pAddressLine1,pAddressLine2,pDistance,pZip);prefStores[pStoreKey]=prefStore;constructPrefStoreDiv();$j("#"+pStoreKey).hide();return false});$j(".gregPrefStoreRemove").click(function(){var prefStore=$j(this).parent().parent();var prefStoreID=prefStore.attr("id").replace("prefStore","");delete prefStores[prefStoreID];constructPrefStoreDiv();$j("#"+prefStoreID).show();return false})}function constructPrefStoreDiv(){$j("#gregPrefStoreListing").html("");for(storeKey in prefStores){if(prefStores[storeKey]){var prefStore=prefStores[storeKey];$j("#gregPrefStoreListing").append("<div id='prefStore"+storeKey+"' class='gregSection gregSectionPrefStore'></div>");$j("#prefStore"+storeKey).append("<img src='/images/registration/greg_hdr_prefered.png' class='gregSectionHdr gregSectionHdrPrefStore' />");$j("#prefStore"+storeKey).append("<div class='gregPrefStore'></div>");$j("#prefStore"+storeKey+" .gregPrefStore").append('<a href="#" class="gregPrefStoreRemove">remove</a>');$j("#prefStore"+storeKey+" .gregPrefStore").append('<div class="gregPrefStoreRow"><div class="gregPrefStoreLabel">Location</div><div class="gregPrefStoreData"><strong>'+prefStore.location+"</strong></div></div>");$j("#prefStore"+storeKey+" .gregPrefStore").append('<div class="gregPrefStoreRow"><div class="gregPrefStoreLabel">Phone Number</div><div class="gregPrefStoreData">'+prefStore.phone+"</div></div>");$j("#prefStore"+storeKey+" .gregPrefStore").append('<div class="gregPrefStoreRow"><div class="gregPrefStoreLabel">Address</div><div class="gregPrefStoreData">'+prefStore.addressLine1+"<br/>"+prefStore.addressLine2+"</div></div>");$j("#prefStore"+storeKey+" .gregPrefStore").append('<div class="gregPrefStoreRow"><div class="gregPrefStoreLabel">Distance</div><div class="gregPrefStoreData">'+prefStore.getDistanceFromZip()+"</div></div>");$j("#prefStore"+storeKey+" .gregPrefStore").append('<div class="clear">&nbsp;</div>');$j("#prefStore"+storeKey).append('<div class="gregPrefStoreHR">&nbsp;</div>')}}$j("#gregPrefStoreListing .gregSectionPrefStore:first img").removeClass("gregSectionHdrPrefStore");$j("#gregPrefStoreListing .gregSectionPrefStore:first img").attr("src","/images/registration/greg_hdr_prefered1.png");$j("#gregPrefStoreListing .gregSectionPrefStore:first").removeClass("gregSectionPrefStore");var secondPrefStore=$j("#gregPrefStoreListing").children().get(1);if(secondPrefStore){var secondId=$j(secondPrefStore).attr("id");$j("#"+secondId+" img").attr("src","/images/registration/greg_hdr_prefered2.png")}var found=new Boolean(false);for(storeKey in prefStores){if(prefStores[storeKey]){found=new Boolean(true)}}if(found!=true){$j("#gregPrefStoreListingNone").show()}else{$j("#gregPrefStoreListingNone").hide()}initStoresBindings()};
