var readMode = false; var provideChangeLink = false; var showEbayLink = true; function populateCountries(mode,modeId,cartId,cartConfirmationNo,countries){ var countryDiv; var countryId; var countryName; var loadAddressSuccessHandler; var loadAddressFailureHandler; var loadStatesSuccessHandler; var loadStatesFailureHandler; if(modeId == null) modeId = ''; countryDiv = document.getElementById(modeId + 'countryDiv'); countryId = modeId + 'country'; countryName = modeId + 'country'; if(mode == 'shipping') { loadAddressSuccessHandler = loadShippingAddressSuccessHandler; loadAddressFailureHandler = loadShippingAddressFailureHandler; loadStatesSuccessHandler = loadShippingStatesSuccessHandler; loadStatesFailureHandler = loadShippingStatesFailureHandler; } else { loadAddressSuccessHandler = loadBillingAddressSuccessHandler; loadAddressFailureHandler = loadBillingAddressFailureHandler; loadStatesSuccessHandler = loadBillingStatesSuccessHandler; loadStatesFailureHandler = loadBillingStatesFailureHandler; } if(countryDiv != null && typeof(countryDiv) != 'undefined') { if(countries != null) { var countriesList = document.createElement('select'); countriesList.id = countryId; countriesList.name = countryName; countriesList.className = 'form-control'; for(countryId in countries) { if(typeof(countries[countryId]) != 'function') { var option = document.createElement('option'); option.text = countryId; option.value = countries[countryId]; try { // standards compliant; doesn't work in IE countriesList.add(option, null); } catch(ex) { // IE only countriesList.add(option); } } } if(cartConfirmationNo != null && cartConfirmationNo != '') loadAddress(mode, cartId, cartConfirmationNo, loadAddressSuccessHandler, loadAddressFailureHandler); else loadStates(cartId, cartConfirmationNo, countriesList.value, loadStatesSuccessHandler, loadStatesFailureHandler); countriesList.onchange = function(){ loadStates(cartId, cartConfirmationNo, this.value, loadStatesSuccessHandler, loadStatesFailureHandler); } if (countryDiv.firstChild == undefined) { countryDiv.appendChild(countriesList); } } else { var country = document.createElement('input'); country.type = 'text'; country.id = countryId; country.name = countryName; country.size = 20; if (countryDiv.firstChild == undefined) { countryDiv.appendChild(country); } } } } function populateStates(mode,modeId,states){ var stateDiv; var stateId; var stateName; var address; if(modeId == null) modeId = ''; stateDiv = document.getElementById(modeId + 'stateDiv'); stateId = modeId + 'state'; stateName = modeId + 'state'; if(mode == 'shipping') { address = shipAddress; } else { address = billAddress; } if(stateDiv != null && typeof(stateDiv) != 'undefined') { stateDiv.innerHTML = ''; if(states != null) { var statesList = document.createElement('select'); statesList.id = stateId; statesList.name = stateName; statesList.className = 'form-control'; for(stateDisplay in states) { if(typeof(states[stateDisplay]) != 'function') { var option = document.createElement('option'); option.value = states[stateDisplay]; option.text = stateDisplay; try { // standards compliant; doesn't work in IE statesList.add(option, null); } catch(ex) { // IE only statesList.add(option); } } } stateDiv.appendChild(statesList); if(address != null && typeof address != 'undefined') statesList.value = address['state']; } else { var state = document.createElement('input'); state.type = 'text'; state.id = stateId; state.name = stateName; if(isMarketplaceCart){ state.className = 'form-control'; state.placeholder="State" } state.size = 20; stateDiv.appendChild(state); if(address != null && typeof address != 'undefined') state.value = address['state']; } } } /** *

Handles the save shipping address event

* * @param cartId the order identifier * @param confNo the order confirmation number * @return */ function handleEditShippingAddress(cartId, confNo) { hideEl('displayShipAddress'); loadEditShippingAddress(cartId, confNo); showEl('editShipAddress'); } var shipAddress; var billAddress; /** *

Method for load address call. Takes care of populating the all address elements

* * @param response the response data * @return */ function loadAddressFields(mode,modeId,address) { var e; var countryDiv; var countryId; var phone; var fax; var loadStatesSuccessHandler; var loadStatesFailureHandler; if(modeId == null) modeId = ''; countryDiv = document.getElementById(modeId + 'country'); countryId = modeId + 'country'; phone = document.getElementById(modeId + 'phone'); fax = document.getElementById(modeId + 'fax'); if(mode == 'shipping') { loadStatesSuccessHandler = loadShippingStatesSuccessHandler; loadStatesFailureHandler = loadShippingStatesFailureHandler; } else { loadStatesSuccessHandler = loadBillingStatesSuccessHandler; loadStatesFailureHandler = loadBillingStatesFailureHandler; } if(address == null || address['countryId'] == null || address['countryId'] == '') { address['countryId'] = 1; } for ( it in address) { e = document.getElementById(modeId + it); if(it == 'countryId') { e = countryDiv; } if (e != null && typeof(e)!= 'undefined' && address[it] != null ){ if(it != 'country' && it != 'name') { e.value = address[it]; if(e.id == countryId) { loadStates(cartId, cartConfNo, e.value, loadStatesSuccessHandler, loadStatesFailureHandler); } } } if(it == 'phone' && address[it] != null && address[it].length >= 10) { phone.value = address[it].replace(/[^\d]/g, ""); } if(it == 'fax' && address[it] != null && address[it].length >= 10) { fax.value = address[it].replace(/[^\d]/g, ""); } if(e != null && it == 'name' && address[it] != null && !isMarketplaceCart) { e.value = address[it]; } if(e != null && it == 'firstName' && address[it] != null) { e.value = address[it]; } if(e != null && it == 'lastName' && address[it] != null) { e.value = address[it]; } if(e != null && it == 'city' && address[it] != null) { e.value = address[it]; } if(e != null && it == 'zip' && address[it] != null) { e.value = address[it]; } } } /** *

Takes care of loading the edit ship address section from the cached address

* * @return */ function loadEditShippingAddress(cartId, cartConfNo) { if(shipAddress == null || (typeof shipAddress == 'undefined')) { return; } loadAddressFields('shipping','',shipAddress); } /** *

Fires an ajax call to apply the coupon discount

* * @param cartId the order identifier * @param cartConfNo the order confirmation number * @param successHandler handler to invoke on success * @param failureHandler handler to invoke on failure * @return */ function applyCoupon(cartId, cartConfNo, successHandler, failureHandler) { // clear all previous Pod Messages ChkoutClearAllPodMessages(); var coupon = document.getElementById('sellerCoupon'); // check the coupon value if(!coupon) { return; } // Make an Ajax call ajaxReq( "/gatewayService?req_type=JSON", successHandler, failureHandler, { 'role':'buyer', 'resp_type':'JSON', 'serv_id' : 'buyerCheckoutService', 'verb':'applyCoupon', 'data': { 'cartId':cartId, 'cartConfirmationNo':cartConfNo, 'couponId':coupon.value } } ); } /** *

Fires an ajax call to apply the coupon discount

* * @param cartId the order identifier * @param cartConfNo the order confirmation number * @param successHandler handler to invoke on success * @param failureHandler handler to invoke on failure * @return */ function removeCoupon(cartId, cartConfNo, successHandler, failureHandler) { // clear all previous Pod Messages ChkoutClearAllPodMessages(); var coupon = document.getElementById('sellerCoupon'); // check the coupon value if(!coupon) { return; } // Make an Ajax call ajaxReq( "/gatewayService?req_type=JSON", successHandler, failureHandler, { 'role':'buyer', 'resp_type':'JSON', 'serv_id' : 'buyerCheckoutService', 'verb':'applyCoupon', 'data': { 'cartId':cartId, 'cartConfirmationNo':cartConfNo } } ); } /** *

Fires an ajax call to update the order summary

* * @param cartId the order identifier * @param cartConfNo the order confirmation number * @param reCalculate the variable to force re calculation * @return */ function updateOrderCosts(cartId, cartConfirmationNo, reCalculate) { // call function to get order summary loadOrderCosts(cartId, cartConfirmationNo, reCalculate, loadOrderCostsSuccessHandler, loadOrderCostsFailureHandler); } /** *

Fires an ajax call to send Message

* * @param cartId the order identifier * @param cartConfNo the order confirmation number * @param successHandler handler to invoke on success * @param failureHandler handler to invoke on failure * @return */ function sendMessage(cartId, cartConfNo, successHandler, failureHandler) { // clear all previous Pod Messages ChkoutClearAllPodMessages(); var sellerMessageBox = document.getElementById('sellerMessageBox'); if((!sellerMessageBox || sellerMessageBox.value == "") && !isMarketplaceCart) { ChkoutaddErrorMessageToPod("Message can't be empty"); update_msg_box(2); //error if(isMarketplaceCart){ document.getElementById("podErrorMessages").style.display="inherit"; document.getElementById("podSuccessMessages").style.display="none"; document.getElementById("podInfoMessages").style.display="none"; } return; } // make an Ajax request ajaxReq( "/gatewayService?req_type=JSON", successHandler, failureHandler, { 'role':'buyer', 'resp_type':'JSON', 'serv_id':'buyerCheckoutService', 'verb':'setBuyerNote', 'data': { 'cartId':cartId, 'cartConfirmationNo':cartConfNo, 'shippingInstructions':sellerMessageBox.value } } ); } /** *

Function to show the add note box

* * @param response the response data * @return */ function showNoteMsgBox() { showEl('cancelNoteBtn', 1); // 1 for inline showEl('addNoteMsgBox'); // block } /** *

Function to hide the add note box

* * @param response the response data * @return */ function hideNoteMsgBox() { hideEl('cancelNoteBtn'); // cancel button hideEl('addNoteMsgBox'); // if(isMarketplaceCart){ document.getElementById("podErrorMessages").style.display="none"; document.getElementById("podSuccessMessages").style.display="none"; document.getElementById("podInfoMessages").style.display="none"; } } /** *

Function to update the remaining characters for add note box

* * @return */ function updateNoteBoxCount(max) { var sellerMessageBox = document.getElementById('sellerMessageBox'); var currCount = sellerMessageBox.value.length; if (currCount <= max) { var numCharLeft = document.getElementById('numCharLeft'); numCharLeft.innerHTML = (max - currCount) ; } else { var currStr = sellerMessageBox.value; sellerMessageBox.value = currStr.substr(0,max); } } /** *

Fires an ajax call to save the address

* * @param mode the address mode --> "shipping"/"billing" * @param cartId the order identifier * @param cartConfNo the order confirmation number * @param successHandler handler to invoke on success * @param failureHandler handler to invoke on failure * @return */ function saveAddress(mode, modeId,cartId, cartConfNo, successHandler, failureHandler) { // clear all previous Pod Messages ChkoutClearAllPodMessages(); if(! validateAddress(mode,modeId)) { return; } var address = {}; if(modeId == null) modeId = ''; var e = document.getElementById(modeId + 'name'); var firstName = document.getElementById(modeId + 'firstName'); firstName = (firstName != null && typeof(firstName) != 'undefined') ? firstName.value.trim() : ""; var lastName = document.getElementById(modeId + 'lastName'); lastName = (lastName != null && typeof(lastName) != 'undefined') ? lastName.value.trim() : ""; address['name'] = firstName + " " + lastName; e = document.getElementById(modeId + 'companyName'); address['companyName'] = (e != null && typeof(e) != 'undefined') ? e.value.trim() : ""; e = document.getElementById(modeId + 'addressLine1'); address['addressLine1'] = (e != null && typeof(e) != 'undefined') ? e.value.trim() : ""; e = document.getElementById(modeId + 'addressLine2'); address['addressLine2'] = (e != null && typeof(e) != 'undefined') ? e.value.trim() : ""; e = document.getElementById(modeId + 'city'); address['city'] = (e != null && typeof(e) != 'undefined') ? e.value.trim() : ""; e = document.getElementById(modeId + 'state'); address['state'] = (e != null && typeof(e) != 'undefined') ? e.value.trim() : ""; e = document.getElementById(modeId + 'country'); address['country'] = (e != null && typeof(e) != 'undefined') ? e.value.trim() : ""; e = document.getElementById(modeId + 'country'); address['countryId'] = (e != null && typeof(e) != 'undefined') ? e.value.trim() : ""; e = document.getElementById(modeId + 'zip'); address['zip'] = (e != null && typeof(e) != 'undefined') ? e.value.trim() : ""; e = document.getElementById(modeId + 'phone'); if(isMarketplaceCart) { address['phone'] = (e != null && typeof(e) != 'undefined') ? e.value.trim().replace(/\D/g,'') : ""; } else { address['phone'] = (e != null && typeof(e) != 'undefined') ? e.value.trim() : ""; } e = document.getElementById(modeId + 'fax'); address['fax'] = (e != null && typeof(e) != 'undefined') ? e.value.trim() : ""; e = document.getElementById(modeId + 'email'); address['email'] = (e != null && typeof(e) != 'undefined') ? e.value.trim() : ""; ajaxReq( "/gatewayService?req_type=JSON", successHandler, failureHandler, { 'role':'buyer', 'verb':'setAddress', 'resp_type':'JSON', 'serv_id':'buyerCheckoutService', 'data': { 'cartId':cartId, 'cartConfirmationNo':cartConfNo, 'mode':mode, 'address':address } } ); } function validateAddress_firstName(modeId) { var isSuccess = true; if(modeId == null) modeId = ''; var e = document.getElementById(modeId + 'firstName'); if(e != null) { if( typeof e != 'undefined' && (e.value == null || e.value.trim() == "")) { if(isMarketplaceCart) { showEl(modeId + 'contactFirstNameErrorIcon', 'inline'); } else { showEl(modeId + 'contactFirstNameErrorIcon'); showEl(modeId + 'contactFirstNameErrorMessage'); } isSuccess = false; } else { if(isMarketplaceCart) { hideEl(modeId + 'contactFirstNameErrorIcon'); } else { hideEl(modeId + 'contactFirstNameErrorIcon'); hideEl(modeId + 'contactFirstNameErrorMessage'); } } } return isSuccess; } function validateAddress_lastName(modeId) { var isSuccess = true; if(modeId == null) modeId = ''; var e = document.getElementById(modeId + 'lastName'); if(e != null) { if( typeof e != 'undefined' && (e.value == null || e.value.trim() == "")) { if(isMarketplaceCart) { showEl(modeId + 'contactLastNameErrorIcon', 'inline'); } else { showEl(modeId + 'contactLastNameErrorIcon'); showEl(modeId + 'contactLastNameErrorMessage'); } isSuccess = false; } else { if(isMarketplaceCart) { hideEl(modeId + 'contactLastNameErrorIcon'); } else { hideEl(modeId + 'contactLastNameErrorIcon'); hideEl(modeId + 'contactLastNameErrorMessage'); } } } return isSuccess; } function validateAddress_name(modeId) { var isValid_firstName = validateAddress_firstName(modeId); var isValid_lastName = validateAddress_lastName(modeId); return isValid_firstName && isValid_lastName; } function validateAddress_addressLine1(modeId) { var isSuccess = true; if(modeId == null) modeId = ''; var e = document.getElementById(modeId + 'addressLine1'); if(e != null) { if(typeof e != 'undefined' && (e.value == null || e.value.trim() == "")) { if(isMarketplaceCart) { showEl(modeId + 'addressLine1ErrorIcon', 'inline'); } else { showEl(modeId + 'addressLine1ErrorIcon'); showEl(modeId + 'addressLine1ErrorMessage'); } isSuccess = false; } else { if(isMarketplaceCart) { hideEl(modeId + 'addressLine1ErrorIcon'); } else { hideEl(modeId + 'addressLine1ErrorIcon'); hideEl(modeId + 'addressLine1ErrorMessage'); } } } return isSuccess; } function validateAddress_city(modeId) { var isSuccess = true; if(modeId == null) modeId = ''; var e = document.getElementById(modeId + 'city'); if(e != null) { if( typeof e != 'undefined' && (e.value == null || e.value.trim() == "")) { if(isMarketplaceCart) { showEl(modeId + 'cityErrorIcon', 'inline'); } else { showEl(modeId + 'cityErrorIcon'); showEl(modeId + 'cityErrorMessage'); } isSuccess = false; } else { if(isMarketplaceCart) { hideEl(modeId + 'cityErrorIcon'); } else { hideEl(modeId + 'cityErrorIcon'); hideEl(modeId + 'cityErrorMessage'); } } } return isSuccess; } function validateAddress_state(modeId) { var isSuccess = true; if(modeId == null) modeId = ''; var e = document.getElementById(modeId + 'state'); if(e != null) { if(typeof e != 'undefined' && (e.value == null || e.value.trim() == "")) { if(isMarketplaceCart) { showEl(modeId + 'stateErrorIcon', 'inline'); } else { showEl(modeId + 'stateErrorIcon'); showEl(modeId + 'stateErrorMessage'); } isSuccess = false; } else { if(isMarketplaceCart) { hideEl(modeId + 'stateErrorIcon'); } else { hideEl(modeId + 'stateErrorIcon'); hideEl(modeId + 'stateErrorMessage'); } } } return isSuccess; } function validateAddress_zip(modeId) { var isSuccess = true; if(modeId == null) modeId = ''; var e = document.getElementById(modeId + 'zip'); if(e != null) { if(typeof e != 'undefined' && (e.value == null || e.value.trim() == "")) { if(isMarketplaceCart) { showEl(modeId + 'zipErrorIcon', 'inline'); } else { showEl(modeId + 'zipErrorIcon'); showEl(modeId + 'zipErrorMessage'); } isSuccess = false; } else { if(isMarketplaceCart) { hideEl(modeId + 'zipErrorIcon'); } else { hideEl(modeId + 'zipErrorIcon'); hideEl(modeId + 'zipErrorMessage'); } } } return isSuccess; } function validateAddress_email(modeId) { var isSuccess = true; if(modeId == null) modeId = ''; var e = document.getElementById(modeId + 'email'); if(e != null) { if( typeof e != 'undefined' && (e.value == null || e.value.trim() == "")) { if(isMarketplaceCart) { showEl(modeId + 'emailErrorIcon', 'inline'); } else { showEl(modeId + 'emailErrorIcon'); showEl(modeId + 'emailErrorMessage'); } isSuccess = false; } else { if(isMarketplaceCart) { hideEl(modeId + 'emailErrorIcon'); } else { hideEl(modeId + 'emailErrorIcon'); hideEl(modeId + 'emailErrorMessage'); } } } return isSuccess; } function validateAddress_phone(modeId) { var isSuccess = true; if(modeId == null) modeId = ''; var e = document.getElementById(modeId + 'phone'); if(e != null) { if( typeof e != 'undefined' && (e.value == null || e.value.trim() == "")) { if(isMarketplaceCart) { showEl(modeId + 'phoneErrorIcon', 'inline'); } else { showEl(modeId + 'phoneErrorIcon'); showEl(modeId + 'phoneErrorMessage'); } isSuccess = false; } else if(typeof e != 'undefined' && (e.value != null && e.value.trim().length > 0)) { phone = e.value.trim(); if((phone.length > 0 && !(phone.replace(/\D/g,'').length >= 10))) { if(isMarketplaceCart) { showEl(modeId + 'phoneErrorIcon', 'inline'); } else { showEl(modeId + 'phoneErrorIcon'); showEl(modeId + 'phoneErrorMessage'); } isSuccess = false; } else { if(isMarketplaceCart) { hideEl(modeId + 'phoneErrorIcon'); } else { hideEl(modeId + 'phoneErrorIcon'); hideEl(modeId + 'phoneErrorMessage'); } } } else { if(isMarketplaceCart) { hideEl(modeId + 'phoneErrorIcon'); } else { hideEl(modeId + 'phoneErrorIcon'); hideEl(modeId + 'phoneErrorMessage'); } } } return isSuccess; } function validateAddress_fax(modeId) { var isSuccess = true; if(modeId == null) modeId = ''; var e = document.getElementById(modeId + 'fax'); if(e != null) { if(typeof e != 'undefined' && (e.value != null && e.value.trim().length > 0)) { fax = e.value.trim(); if(fax.length > 0 && fax.length != 10) { if(isMarketplaceCart) { showEl(modeId + 'faxErrorIcon', 'inline'); } else { showEl(modeId + 'faxErrorIcon'); showEl(modeId + 'faxErrorMessage'); } isSuccess = false; } else { if(isMarketplaceCart) { hideEl(modeId + 'faxErrorIcon'); } else { hideEl(modeId + 'faxErrorIcon'); hideEl(modeId + 'faxErrorMessage'); } } } else { if(isMarketplaceCart) { hideEl(modeId + 'faxErrorIcon'); } else { hideEl(modeId + 'faxErrorIcon'); hideEl(modeId + 'faxErrorMessage'); } } } return isSuccess; } /** *

Validates the address fields

* * @param mode the mode of the address --> "shipping"/"billing" * @return */ function validateAddress(mode,modeId) { var isValid_name = validateAddress_name(modeId); var isValid_addressLine1 = validateAddress_addressLine1(modeId); var isValid_city = validateAddress_city(modeId); var isValid_state = validateAddress_state(modeId); var isValid_zip = validateAddress_zip(modeId); var isValid_email = validateAddress_email(modeId); var isValid_phone = validateAddress_phone(modeId); var isValid_fax = validateAddress_fax(modeId); return isValid_name && isValid_addressLine1 && isValid_city && isValid_state && isValid_zip && isValid_email && isValid_phone && isValid_fax; } /** *

Copies the Ship Address values to Bill Address Values

* * @return */ function copyShiptoBillAddressValues(){ var billAddressAsShipAddress = document.getElementById('billAddressAsShipAddress'); if(billAddressAsShipAddress != null && typeof billAddressAsShipAddress != 'undefined' && billAddressAsShipAddress.checked) { var fields = { "shipInfo$name":"billInfo$name", "shipInfo$firstName":"billInfo$firstName", "shipInfo$lastName":"billInfo$lastName", "shipInfo$addressLine1":"billInfo$addressLine1", "shipInfo$addressLine2":"billInfo$addressLine2" , "shipInfo$city":"billInfo$city", "shipInfo$zip":"billInfo$zip", "shipInfo$country":"billInfo$country", "shipInfo$phone":"billInfo$phone"}; for(var i in fields){ var srcEl = document.getElementById(i); if(srcEl != null && typeof(srcEl)!= 'undefined') { var destEl = document.getElementById(fields[i]); if(destEl != null && typeof(destEl)!= 'undefined') { destEl.value = srcEl.value; if(destEl.id == 'billInfo$country') { loadStates(cartId, cartConfNo, srcEl.value, loadBillingStatesSuccessHandler, loadBillingStatesFailureHandler); } } } } } } function addKeyUpInputListeners() { var fields = { "shipInfo$firstName" : "billInfo$firstName", "shipInfo$lastName" : "billInfo$lastName", "shipInfo$addressLine1" : "billInfo$addressLine1", "shipInfo$addressLine2" : "billInfo$addressLine2", "shipInfo$city" : "billInfo$city", "shipInfo$zip" : "billInfo$zip", "shipInfo$phone" : "billInfo$phone" }; for ( var i in fields) { Ext.get(i).on('keyup', function(t, e) { if (document.getElementById('billAddressAsShipAddress').checked) { document.getElementById(fields[e.name]).value = document.getElementById(e.name).value; } }); } } /** *

Displays the Address

* @param modeID the modeId of the UI * @address shipping/billing * @return */ function displayAddress(modeId, address) { for ( it in address) { var e = document.getElementById(modeId + it); if (e != null && typeof(e)!= 'undefined' && address[it] != null ){ if (address[it] != '') { var value = address[it]; if(it == 'name') { if(modeId == 'shipInfo$' && address['companyName'] != null && address['companyName'] != '') { value += ' (' + address['companyName'] + ')'; } value = '' + value + '
'; } else if(it == 'city' || it == 'state') { value += ', '; } else if(it == 'fax') { value += ' (fax)
'; } else { value += '
'; } e.innerHTML = value; } else { e.innerHTML = address[it]; if(it == 'zip') { e.innerHTML += "
" } } } } }