function signInOnPage() { var signInForm = document.getElementById('signInForm'); if (validateSignInFormOnPage(signInForm)) { signInForm.submit(); } } function validateSignInFormOnPage(theForm) { resetErrors(theForm); var result = true; if (!validEmail(theForm.Email)) result = false; if (theForm.Password.value.trim().length < 8) { displayError('customerPassword', "Tu contraseña debe tener al menos 8 caracteres"); result = false; } return result; } function signIn() { var signInForm = document.getElementById('signInForm'); if (validateSignInForm(signInForm)) { signInForm.submit(); } } function goToRegister() { location.href = "registro" + window.location.search; } function goToSignIn() { location.href = "ingreso" + window.location.search; } function validateSignInForm(theForm) { resetErrors(theForm); var result = true; if (!validEmail(theForm.Email)) result = false; if (theForm.Password.value.trim().length < 8) { displayError('customerPassword', "Tu contraseña debe tener al menos 8 caracteres"); result = false; } return result; } function emailPassword() { var passwordForm = document.getElementById('passwordForm'); resetErrors(passwordForm); if (validEmail(passwordForm.Email)) passwordForm.submit(); } function resetPassword() { var resetPasswordForm = document.getElementById('resetPasswordForm'); resetErrors(resetPasswordForm); if (validatePasswordForm(resetPasswordForm)) resetPasswordForm.submit(); } function validatePasswordForm(theForm) { resetErrors(theForm); var result = validEmail(theForm.Email); result = validPassword(theForm); return result; } function validPassword(theForm) { var result = true; var validRegEx = /^[a-zA-Z0-9ÀàÂâÆæÇçÈèÉéÊêËëÎîÏïÔôŒœÙùÛûÜü]*$/; if (theForm.Password.value.trim().length < 8) { displayError('customerPassword', "Tu contraseña debe tener al menos 8 caracteres"); result = false; } else if (theForm.Password.value.trim().search(validRegEx) == -1) { displayError('customerPassword', "Tu contraseña sólo puede contener números y letras"); result = false; } if (theForm.PasswordCopy.value.trim() != theForm.Password.value.trim()) { displayError('customerPasswordCopy', "Las contraseñas no coinciden"); result = false; } return result; } function register() { var registerForm = document.getElementById('registerForm'); if (validateRegisterForm(registerForm)) { document.getElementById('registerButton').disabled = 'true'; registerForm.submit(); } } function validateRegisterForm(theForm) { resetErrors(theForm); var result = validEmail(theForm.Email); if (theForm.EmailCopy.value.trim() != theForm.Email.value.trim()) { displayError('emailAddressCopy', "Las direcciones de correo electrónico no coinciden"); result = false; } if (theForm.Name.value.trim() == '') { displayError('customerName', "Por favor, introduce un nombre"); result = false; } if (!validPassword(theForm)) { result = false; } if (!validatePhoneNumber(theForm.Telephone.value)){ result = false; } return result; } function validatePhoneNumber(inputToValidate){ //Populate the default validation for success var result = true; var errorMessage = ""; //Regex pattern for whitespace digits and + which is all allowable characters var allowableCharacters = new RegExp("^\\\+?[\\\d|\\\s]+$"); if (inputToValidate === null || inputToValidate.trim() === ""){ errorMessage = "Por favor, introduce un número de teléfono"; } else if (inputToValidate.length > 15){ errorMessage = "El número de teléfono no puede tener más de 15 dígitos"; } else if (! allowableCharacters.test(inputToValidate)){ errorMessage = "El número de teléfono solo puede contener números y el signo + al inicio"; } if (errorMessage){ displayError('customerTelephone', errorMessage); result = false; } return result; } function changeCountry(country,formID) { var theForm = document.getElementById(formID); resetErrors(theForm); var postCode = document.getElementById('customerPostcode'); if ($("#countryID").val() == 25 || $("#countryID").val() == 24) { $("#customerRegion").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#lookupPostcodeForm").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#optionalPostCodetxt").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); if ($("#countryID").val() == 25 ) { $("#postCodetxt").removeClass('mainForm__Content--Hide').addClass('mainForm__Content--Show'); $("#customerPostcode").removeClass('mainForm__Content--Hide').addClass('mainForm__Content--Show'); $("#providencetxt").removeClass('mainForm__Content--Hide').addClass('mainForm__Content--Show'); $("#regionCodeCA").removeClass('mainForm__Content--Hide').addClass('mainForm__Content--Show'); $("#statetxt").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#zipcodetxt").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#regionCodeUS").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); } else { $("#postCodetxt").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#providencetxt").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#regionCodeCA").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#customerPostcode").removeClass('mainForm__Content--Hide').addClass('mainForm__Content--Show'); $("#statetxt").removeClass('mainForm__Content--Hide').addClass('mainForm__Content--Show'); $("#zipcodetxt").removeClass('mainForm__Content--Hide').addClass('mainForm__Content--Show'); $("#regionCodeUS").removeClass('mainForm__Content--Hide').addClass('mainForm__Content--Show'); } $("#regiontxt").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#customerRegion").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#lookupPostcodeForm").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); } else { $("#postCodetxt").removeClass('mainForm__Content--Hide').addClass('mainForm__Content--Show'); $("#customerPostcode").removeClass('mainForm__Content--Hide').addClass('mainForm__Content--Show'); if($("#countryID").val() == 23){ $("#lookupPostcodeForm").removeClass('mainForm__Content--Hide').addClass('mainForm__Content--Show'); }else{ $("#lookupPostcodeForm").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); } $("#providencetxt").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#regionCodeCA").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#statetxt").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#zipcodetxt").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#regionCodeUS").removeClass('mainForm__Content--Show').addClass('mainForm__Content--Hide'); $("#regiontxt").removeClass('mainForm__Content--Hide').addClass('mainForm__Content--Show'); $("#customerRegion").removeClass('mainForm__Content--Hide').addClass('mainForm__Content--Show'); } } function addAddress() { var addForm = document.getElementById('addAddressForm'); if (validateAddressForm(addForm)) addForm.submit(); } function validateAddressForm(theForm) { resetErrors(theForm); var result = true; if (theForm.Name.value.trim() == '') { displayError('customerName', "Por favor, introduce un nombre"); result = false; } if (theForm.Address1.value.trim() == '') { displayError('customerAddress1', "Por favor, introduce una dirección"); result = false; } if (theForm.Name.value.length > 35){ displayError('customerName', "Nombre demasiado largo (35 caracteres como máximo)"); result = false; } if (theForm.Address1.value.length > 35){ displayError('customerAddress1', "línea de dirección demasiado larga (35 caracteres como máximo)"); result = false; } if (theForm.Address2.value.length !== '' && theForm.Address2.value.length > 35 ){ displayError('customerAddress2', "línea de dirección demasiado larga (35 caracteres como máximo)"); result = false; } if (theForm.City.value.trim() == '') { displayError('customerCity', "Por favor, especifica una población/ciudad"); result = false; } if (theForm.Postcode.value.trim() == '') { displayError('customerPostcode', "Por favor, introduce un código postal"); result = false; } if ($("#countryID").val() == 24 && theForm.regionCodeUS.options.selectedIndex == 0) { displayError('regionCodeUS', "Por favor, especifica un estado"); result = false; } else if ($("#countryID").val() == 25 && theForm.regionCodeCA.options.selectedIndex == 0) { displayError('regionCodeCA', "Por favor, especifica una provincia"); result = false; } return result; } function useAddress(ID) { var addressForm = document.getElementById('useAddressForm' + ID); addressForm.Actn.value = 'use'; addressForm.submit(); } function editAddress(ID) { var addressForm = document.getElementById('useAddressForm' + ID); addressForm.Actn.value = ID; addressForm.action = "editar-dirección"; addressForm.submit(); } function deleteAddress(ID) { if (confirm('Are you sure?')) { var addressForm = document.getElementById('useAddressForm' + ID); addressForm.Actn.value = 'delete'; addressForm.submit(); } } function lookupPostcode() { if (validateLookupPostcodeForm(document.getElementById('lookupPostcodeForm'))) { var anim = loadingAnim('PCLoader', 26); xmlHttp('/SubArea/customer/lookup-postcode-server.aspx?PC=' + document.getElementById('Postcode2Lookup').value , function (HTML) { if (HTML == 'FAIL3') { displayError('Postcode2Lookup', "No se encuentra la dirección para este código postal, por favor introduce la dirección completa a continuación"); anim.stopAnimation(); } else if (HTML.substring(0, 4) == 'FAIL') { displayError('Postcode2Lookup', "La búsqueda de este código postal falló, por favor introduce dirección completa a continuación"); anim.stopAnimation(); } else { document.getElementById('possAddresses').innerHTML = HTML; anim.stopAnimation(); } }, true); } } function selectMyAddress() { var addressData = document.getElementById('addressSelector').value; var country = document.getElementById("countryID"); var addressFields = addressData.split("|"); document.getElementById('customerAddress1').value = addressFields[0]; if (addressFields[1] != "") { document.getElementById('customerAddress2').value = addressFields[1]; } document.getElementById('customerCity').value = addressFields[2]; document.getElementById('customerPostcode').value = addressFields[4]; document.getElementById('possAddresses').innerHTML = ''; document.getElementById('customerName').focus(); } function validateLookupPostcodeForm(theForm) { document.getElementById('possAddresses').innerHTML = ''; resetErrors(theForm); var result = true; var validPostcodeRegEx = /(GIR 0AA|[A-PR-UWYZ]([0-9][0-9A-HJKPS-UW]?|[A-HK-Y][0-9][0-9ABEHMNPRV-Y]?) ?[0-9][ABD-HJLNP-UW-Z]{2})/i; if (theForm.Postcode2Lookup.value.trim().search(validPostcodeRegEx) == -1) { displayError('Postcode2Lookup', "Tu código postal no es un código postal válido en el Reino Unido"); result = false; } return result; } function updateAddress(checkout) { var updateForm = document.getElementById('updateAddressForm'); resetErrors(updateForm); if (checkout) updateForm.Next.value = 'checkout' else updateForm.Next.value = 'addressbook' if (validateAddressForm(updateForm)) updateForm.submit(); } function updateInvoiceAddress(checkout) { var updateForm = document.getElementById('updateInvoiceAddress'); resetErrors(updateForm); if (validateAddressForm(updateForm)) updateForm.submit(); } function chooseShipping() { var shippingForm = document.getElementById('shippingForm'); shippingForm.submit(); } function updateProfile() { var profileForm = document.getElementById('profileForm'); if (validateProfileForm(profileForm)) profileForm.submit(); } function validateFormOnLoad(formName, validationFunction){ validationFunction(document.getElementById(formName)); } function validateProfileForm(theForm) { resetErrors(theForm); var result = true; if (theForm.Name.value.trim() == '') { displayError('customerName', "Por favor, introduce un nombre"); result = false; } if (!validatePhoneNumber(theForm.Telephone.value)){ result=false; } return result; } function changeEmail() { document.getElementById('emailForm').submit(); } function updateEmail() { var emailForm = document.getElementById('emailForm'); if (validateEmailForm(emailForm)) { emailForm.Email.value = emailForm.Email.value.trim(); emailForm.submit(); } } function emailCheck(email) { return (email.toString().search(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/) == 0); } function validateEmailForm(theForm) { resetErrors(theForm); var result = validEmail(theForm.Email); if (theForm.EmailCopy.value.trim() != theForm.Email.value.trim()) { displayError('emailAddressCopy', "Las direcciones de correo electrónico no coinciden"); result = false; } if (theForm.Password.value.trim().length < 8) { displayError('customerPassword', "Tu contraseña debe tener al menos 8 caracteres"); result = false; } return result; } function updatePassword() { var passwordForm = document.getElementById('passwordForm'); if (validateUpdatePasswordForm(passwordForm)) passwordForm.submit(); } function validateUpdatePasswordForm(theForm) { resetErrors(theForm); var validRegEx = /^[a-zA-Z0-9ÀàÂâÆæÇçÈèÉéÊêËëÎîÏïÔôŒœÙùÛûÜü]*$/; var result = true; if (theForm.customerNewPassword.value.trim().length < 8) { displayError('customerNewPassword', "Tu contraseña debe tener al menos 8 caracteres"); result = false; } else if (theForm.customerNewPassword.value.trim().search(validRegEx) == -1) { displayError('customerNewPassword', "Tu contraseña sólo puede contener números y letras"); result = false; } if (theForm.customerPasswordCopy.value.trim() != theForm.customerNewPassword.value.trim()) { displayError('customerPasswordCopy', "Las contraseñas no coinciden"); result = false; } return result; } function isEmailAddr(email) { var result = false; var theStr = new String(email); var index = theStr.indexOf("@"); if (index > 0) { var pindex = theStr.indexOf(".", index); if ((pindex > index + 1) && (theStr.length > pindex + 1)) result = true; } return result; } function validEmail(formField) { if (formField.value.trim() == '') { displayError('emailAddress', "Por favor, introduce una dirección de correo electrónico"); return false; } if (!emailCheck(formField.value.trim())) { displayError('emailAddress', "La dirección de correo electrónico es inválida"); return false; } if ((formField.value.length < 3) || !isEmailAddr(formField.value)) { displayError('emailAddress', "La dirección de correo electrónico no es válida"); formField.focus(); return false; } return true; } function reOrderProduct(Product, archiveID, orderID) { $('#orderItems').replaceWith($('#order-details_loading_wheel')); $('#order-details_loading_wheel').show(); $('

' + "Añadiendo " + Product + " a la cesta... "+ '

').appendTo('#order');//During redesign we should look for a way to have this in the DOM $.ajax({ url: '/SubArea/customer/cloneToBasket.aspx?AID=' + archiveID + '&OID=' + orderID +'&R=' + Math.random(), cache: false, success: function () { window.location = '/checkout/'; } }); } function launchEmailClientReply(orderID) { var subject = "Re: Clarification required for order " + orderID var body = "\n\n\n--------------------------------------\n"+"Email sent by TShirt Studio:"+"\n\n" var uri = "mailto:contact@tshirtstudio.com?subject=" + subject + "&body=" + encodeURIComponent(body) + escape(document.getElementById('email').innerHTML); location.href = uri return false; } function showOrderDetails(orderID){ $.ajax({ url: '/subarea/customer/order-detailsajax.aspx?ID_Order= '+ orderID +'&R='+ Math.random(), cache: false, success: function (res) { $('#order').append(res); if (($('#order').children().length) > 1){ $('#order-details_loading_wheel').hide(); } else{ $('#order').append("

" + "Lo sentimos, se ha producido un error al recibir tus datos. Ponte en contacto con el servicio de atención al cliente, por favor. "+ "

"); $('#order-details_loading_wheel').hide(); } } }); } function loadMoreOrderRows(){ var loadMoreButton = $('#loadMoreOrderRowsBtn'); var loadMoreSpinner = $('#loadMoreOrderRowsSpinner'); var currentRowCount = document.getElementsByName("orderRow").length; var totalRows = parseInt(document.getElementById("totalOrders").value); $.ajax({ url:'/SubArea/customer/sec-myAccount-row.aspx?offSet=' + currentRowCount, cache:false, beforeSend: function() { loadMoreSpinner.show(); loadMoreButton.hide(); disableSearchBtn(true); }, success:function(res) { res=JSON.parse(res); if(res.returnUrl != ""){ window.location.href = res.returnUrl; } else{ $('#ordersForm').append(res.stringifiedHTML); //Update currentRowCount now that we had added more rows currentRowCount = document.getElementsByName("orderRow").length; document.getElementById("currentRowCount").value = currentRowCount; loadMoreSpinner.hide(); disableSearchBtn(false); if (currentRowCount < totalRows){ loadMoreButton.show(); } } } }) } function toggleAdditionalOrderRows(event, caller){ event.preventDefault(); //Toggle the collapsible $(caller).siblings("[name='additionalOrderRows']").slideToggle(250); //Rotate the Chevron var toggleOrderBtnChevron = $(caller).children("[name='toggleOrderBtn__Chevron']") if (toggleOrderBtnChevron.hasClass("toggleOrderBtn__Chevron--rotate")){ toggleOrderBtnChevron.removeClass("toggleOrderBtn__Chevron--rotate"); } else{ toggleOrderBtnChevron.addClass("toggleOrderBtn__Chevron--rotate"); } //Change the button text var toggleOrderBtnSpan = $(caller).children("[name='toggleOrderBtn__Span']"); var currentBtnText = toggleOrderBtnSpan.text(); var newBtnText = toggleOrderBtnSpan.attr("data-altText"); toggleOrderBtnSpan.text(newBtnText); toggleOrderBtnSpan.attr("data-altText", currentBtnText); } function searchOrderRows(event){ event.preventDefault(); var orderNumber = document.getElementById("myAccount__searchForm").myAccount__searchInput.value; //Hide Form and load more button then show a loading spinner and disable the search button to prevent spam clicks $("#ordersForm").hide(); $("#loadMoreOrderRowsBtn").hide(); $("#myAccount__errorMessage").removeClass("myAccount__errorMessage--show"); $("#loadMoreOrderRowsSpinner").show(); disableSearchBtn(true); //Validate that the orderNumber provided is a positive, whole number that can be parsed to an int or that it is empty (which means load all) if(orderNumber === "" || !orderNumber.includes(".") && !orderNumber.includes("-") && $.isNumeric(orderNumber) && orderNumber.length <= 10){ $.ajax({ url:'/SubArea/customer/sec-myAccount-row.aspx?offSet=0&orderID=' + orderNumber, cache:false, success:function(res) { res = JSON.parse(res) if(res.returnUrl != ""){ window.location.href = res.returnUrl; } else if (res.stringifiedHTML != ""){ $("#ordersForm").children("[name='orderRow']").remove(); $("#ordersForm").append(res.stringifiedHTML); $("#ordersForm").show(); var currentRowCount = document.getElementsByName("orderRow").length; var totalRows = parseInt(document.getElementById("totalOrders").value); if(!res.orderSearchFound && currentRowCount < totalRows){ $("#loadMoreOrderRowsBtn").show(); } } else if (!res.orderSearchFound){ $("#myAccount__errorMessage").addClass("myAccount__errorMessage--show"); } }, complete:function(){ $("#loadMoreOrderRowsSpinner").hide(); disableSearchBtn(false); } }) } else{ $("#myAccount__errorMessage").addClass("myAccount__errorMessage--show"); $("#loadMoreOrderRowsSpinner").hide(); disableSearchBtn(false); } } function disableSearchBtn(disable){ var SearchButton = document.getElementById("myAccount__searchButton"); if (SearchButton != null){ if(disable){ SearchButton.disabled = true; SearchButton.classList.add("myAccount__searchBtn--disable"); } else{ SearchButton.disabled = false; SearchButton.classList.remove("myAccount__searchBtn--disable"); } } } function openOptionDialog(o) { mmClose(!1, '#'+o), $(".overlay").fadeIn("fast"), $('#'+o).addClass("displayFlex").removeClass("displayNone") document.getElementById(o).scrollIntoView({behavior: "smooth", block: "end", inline: "nearest"}) } function deleteAccountValid() { restartErrors('deleteAccountModal') var passcodeInput = document.getElementById('deleteAccountInput').value.toUpperCase(); var passcodeInput = passcodeInput.replace(/\s+/g, '') if (passcodeInput == "ELIMINAR") { deleteAccount() } } function changeButtonState() { passcodeInput = document.getElementById('deleteAccountInput').value.toUpperCase() passcodeInput = passcodeInput.replace(/\s+/g, '') button = document.getElementById('deleteAccountButton') if(passcodeInput == "ELIMINAR" && button.disabled == false) { button.classList.remove("disabled"); } else { button.classList.add("disabled"); } } function deleteAccount() { $.ajax({ url:'/SubArea/customer/delete-myAccountAjax.aspx', cache:false, success:function(res) { res = JSON.parse(res); if(res.returnUrl != "") { window.location.href = res.returnUrl; } else { document.getElementById('deleteAccountButton').classList.add("disabled") document.getElementById('deleteAccountButton').disabled = true for (var i = 0; i < res.messageList.length; i++) { displayError('deleteAccountInput',res.messageList[i].Message) } } } }); } function restartErrors(ID) { var errorBackgrounds = document.getElementById(ID).querySelectorAll("input, textarea"); for (var i = 0; i < errorBackgrounds.length; i++) { if(errorBackgrounds[i].style.background == "pink") { errorBackgrounds[i].style.background = ""; } } var errors = document.getElementById(ID).querySelectorAll(".errorText"); for (var i = 0; i < errors.length; i++) { errors[i].remove(); } }