// /* Registration scripts */ function buildValidation(){ $('.line').each(function(){ var obj = $(this); if(obj.children('.icons').length > 0 ) { var type = obj.attr('type'); var allow = obj.attr('allowed'); var twin = obj.attr('hasTwin'); var depsWho = obj.attr('dependsWho'); var canBeEmpty = obj.attr('canBeEmpty'); switch(type) { case 'radio' : bindClickOk(obj.children('.value').children('input:radio')); break; case 'captcha' : bindFocusAndBlurHelp(obj.children('.value').children('input:text')); break; case 'input' : bindFocusAndBlurHelp(obj.children('.value').children('input:text')); break; case 'password': bindFocusAndBlurHelp(obj.children('.value').children('input:password')); break; case 'select' : bindFocusAndBlurHelp(obj.children('.value').children('select')); bindOnChange(obj.children('.value').children('select')); break; case 'multi_select' : prepareMultiChecks(obj.children('.value').children('select')); break; case 'check' : bindClickOk(obj.children('.value').children('input:checkbox')); break; } if (allow != undefined) { switch(allow) { case 'alpha' : obj.alpha({allow:" ",ichars:"'´ç¡!º\\/*-_{}[]"}); break; case 'alphanumeric': obj.alpha({allow:" ,.",ichars:"'´ç¡!º\\/*-_{}[]"}); break; case 'email' : obj.alphanumeric({allow:"@._-",ichars:",'´ç¡!º\\/*-_,ç{}[]"}); break; case 'numeric' : obj.numeric(); break; case 'date' : obj.numeric({allow:'/'}); break; case 'phone' : obj.numeric({allow:'()-+*'}); break; case 'alias' : obj.alphanumeric({ichars:"'´ç¡!º\\/* @,.¨ñ;:`Ñ"}); break; case 'password': obj.alphanumeric({ichars:" .,*"}); break; case 'ccnum' : obj.numeric({allow:'-'}); break; } } if (twin != undefined) { bindTwinKeyDown(obj.children('.value').children('input:text,input:password'), twin); } if (depsWho != undefined){ bindValidationOnDepend(obj.children('.value').children('input:text,input:password'), depsWho); } if(canBeEmpty != undefined) obj.children('.value').children('input:text, select').attr('canBeEmpty','true'); } }); } function bindValidationOnDepend(obj, depsWho){ var customValidator = obj.parent().parent().children('.error_text').children('.error_validate').attr('customValidation'); if ((customValidator != undefined)) { obj.keyup(function(){ if (window[customValidator](obj.val())) { $('#'+depsWho).removeAttr('disabled'); } else { $('#'+depsWho).attr('disabled', 'disabled'); } }); } } function bindTwinKeyDown(obj, twin) { /* var twin = $('#'+twin); obj.keyup(function(){ validateField(twin); }); */ } function bindOnChange(obj) { obj.unbind('change').bind('change', function(){ validateField(obj); }); } function bindClickOk(obj) { obj.click(function(){ if (obj.parent().parent().children('.error_text').children('div:visible').length > 0) { obj.parent().parent().children('.error_text').children('div').hide(); obj.parent().parent().children('.error_text').fadeOut('fast', function(){ $(this).parent().removeClass('error_field'); }); } if (obj.parent().parent().children('.icons').children().length > 0 ){ if (obj.attr('type') != 'checkbox') { if (obj.val() != '') { } else { obj.parent().parent().children('.error_text').children('.error_empty').show(); obj.parent().parent().addClass('error_field'); obj.parent().parent().children('.error_text').fadeIn('fast', function(){ }); } } else { if (obj.attr('checked')) { } else { obj.parent().parent().children('.error_text').children('.error_empty').show(); obj.parent().parent().addClass('error_field'); obj.parent().parent().children('.error_text').fadeIn('fast', function(){ }); } } } }); } function bindFocusAndBlurHelp(selector) { selector.focus(function(){ var obj = $(this); var firstFocus = $(this).attr('firstFocus'); if (firstFocus == 'true' && (obj.parent().parent().children('.error_text').children('div:visible').length > 0)) { obj.parent().parent().children('.error_text').fadeOut('fast', function(){ obj.parent().parent().children('.error_text').children().hide(); obj.attr('focused', 'true'); obj.attr('firstFocus', 'true'); if (obj.parent().parent().children('.special_text').length > 0) obj.parent().parent().children('.special_text').hide(); $(this).parent().removeClass('error_field'); }); } else { $(this).attr('focused', 'true'); $(this).attr('firstFocus', 'true'); if (obj.parent().parent().children('.special_text').length > 0) obj.parent().parent().children('.special_text').hide(); } }); selector.blur(function(){ var obj = $(this); $(this).attr('focused', 'false'); if ($(this).attr('removeHelp') != undefined) { $(this).removeAttr('removeHelp'); } if ($(this).attr('ignoreBlur') != undefined) return; validateField(obj); }); } function prepareMultiChecks(multiFields) { multiFields.each(function(){ var obj = $(this); obj.attr('firstMulti', 'true'); var next = obj.next(); var sibling = false; if (next.length > 0) sibling = next; else { var prev = obj.prev(); if (prev.length > 0) sibling = prev; } if (sibling) { obj.unbind('focus').bind('focus', function(){ obj.parent().parent().children('.error_text').fadeOut('fast', function(){ obj.parent().parent().children('.error_text').children().hide(); $(this).parent().removeClass('error_field'); }); obj.attr('focused', 'true'); obj.attr('firstFocus', 'true'); obj.attr('firstMulti', 'true'); }); obj.unbind('blur').bind('blur', function(){ var a = $(this).attr('id'); setTimeout(function(){multiBlurFoo(a)}, 100); }); obj.unbind('change').bind('change', function(){ var next = obj.next(); var sibling = false; if (next.length > 0) sibling = next; else { var prev = obj.prev(); if (prev.length > 0) sibling = prev; } if (sibling) { if ((obj.attr('firstMulti') != 'true') || (sibling.attr('firstMulti') != 'true')) { // So far, validate multi only by custom method var customValidator = obj.parent().parent().children('.error_text').children('.error_validate').attr('customValidation'); if ((customValidator != undefined)) { if (res = (window[customValidator](obj.val()))) { if (res === true) { if (obj.parent().parent().children('.error_text').children('.error_validate:visible').length > 0) { obj.parent().parent().children('.error_text').fadeOut('fast', function(){ $(this).parent().removeClass('error_field'); obj.parent().parent().children('.error_text').children('.error_validate').hide(); }); } } } else { obj.parent().parent().children('.error_text').children('.error_validate').show(); obj.parent().parent().addClass('error_field'); obj.parent().parent().children('.error_text').fadeIn('fast', function(){ }); } } } } }); } }); } function multiBlurFoo(id) { var obj = $('#'+id); var next = obj.next(); var sibling = false; if (next.length > 0) sibling = next; else { var prev = obj.prev(); if (prev.length > 0) sibling = prev; } if (sibling) { obj.attr('focused', 'false'); obj.attr('firstMulti', 'false'); if (sibling.attr('focused') != 'true') { if ($(this).attr('ignoreBlur') != undefined) return; else { // So far, validate multi only by custom method var customValidator = obj.parent().parent().children('.error_text').children('.error_validate').attr('customValidation'); if ((customValidator != undefined)) { if (res = (window[customValidator](obj.val()))) { if (res === true) { if (obj.parent().parent().children('.error_text').children('.error_validate:visible').length > 0) { obj.parent().parent().children('.error_text').fadeOut('fast', function(){ console.log("ERROR FADED AFTER"); obj.parent().parent().children('.error_text').children('.error_validate').hide(); $(this).parent().removeClass('error_field'); }); } else { obj.parent().parent().children('.error_text').fadeOut('fast', function(){ obj.parent().parent().children('.error_text').children('.error_validate').hide(); $(this).parent().removeClass('error_field'); }); } } } else { obj.parent().parent().children('.error_text').children('.error_validate').show(); obj.parent().parent().addClass('error_field'); obj.parent().parent().children('.error_text').show(); } } } } } else { console.log("enter there"); } } function validateField(obj, force){ var firstFocus = obj.attr('firstFocus'); var canBeEmpty = obj.attr('canBeEmpty'); if ((firstFocus == 'true') || (force != undefined)) { if ( (obj.val() == '' && canBeEmpty!='true') && (obj.parent().parent().children('.error_text').children().length > 0)) { obj.parent().parent().children('.error_text').children('.error_empty').show(); obj.parent().parent().addClass('error_field'); obj.parent().parent().children('.error_text').fadeIn('fast', function(){ }); } else { if (obj.parent().parent().children('.error_text').length > 0 ) { if (obj.parent().parent().children('.error_text').children('.error_email').length > 0) { if(validateEmail(obj.val())) { if (obj.parent().parent().children('.error_text').children('.error_twin').length > 0) { var twin = obj.parent().parent().children('.error_text').children('.error_twin').attr('twin'); if ($('#'+twin).val() != obj.val()) { obj.parent().parent().children('.error_text').children('.error_twin').show(); obj.parent().parent().addClass('error_field'); obj.parent().parent().children('.error_text').fadeIn('fast', function(){ }); } else { if (obj.parent().parent().children('.error_text').children('.error_twin:visible').length > 0) { obj.parent().parent().children('.error_text').fadeOut('fast', function(){ obj.parent().parent().children('.error_text').children('.error_twin').hide(); $(this).parent().removeClass('error_field'); }); } } } else { } } else { obj.parent().parent().children('.error_text').children('.error_email').show(); obj.parent().parent().addClass('error_field'); obj.parent().parent().children('.error_text').fadeIn('fast', function(){ }); } } else { if (obj.parent().parent().children('.error_text').children('.error_twin').length > 0) { var twin = obj.parent().parent().children('.error_text').children('.error_twin').attr('twin'); if ($('#'+twin).val() != obj.val()) { obj.parent().parent().children('.error_text').children('.error_twin').show(); obj.parent().parent().addClass('error_field'); obj.parent().parent().children('.error_text').fadeIn('fast', function(){ }); } else { if (obj.parent().parent().children('.error_text').children('.error_twin:visible').length > 0) { obj.parent().parent().children('.error_text').fadeOut('fast', function(){ obj.parent().parent().children('.error_text').children('.error_twin').hide(); $(this).parent().removeClass('error_field'); }); } } } else { if (obj.parent().parent().children('.error_text').children('.error_validate').length > 0) { var customValidator = obj.parent().parent().children('.error_text').children('.error_validate').attr('customValidation'); if ((customValidator != undefined)) { if (res = (window[customValidator](obj.val()))) { if (res === true) { if (obj.parent().parent().children('.error_text').children('.error_validate:visible').length > 0) { obj.parent().parent().children('.error_text').fadeOut('fast', function(){ obj.parent().parent().children('.error_text').children('.error_validate').hide(); $(this).parent().removeClass('error_field'); }); } } } else { obj.parent().parent().children('.error_text').children('.error_validate').show(); obj.parent().parent().addClass('error_field'); obj.parent().parent().children('.error_text').fadeIn('fast', function(){ }); } } else { } } else { } } } } } } // Check depends var depWho = obj.parent().parent().attr('dependsWho'); if (depWho != undefined) { if (!obj.parent().parent().hasClass('error_field')) { $('#'+depWho).removeAttr('disabled'); } else { $('#'+depWho).attr('disabled', 'disabled'); } } } function showFieldMessages(field, state){ var line = $('#'+field).parent().parent(); line.children('.value').children('input, select').attr('firstFocus', 'true'); if (state == 'ok') { } else { if (state == 'empty') { line.children('.error_text').children('.error_empty').show(); } else if (state == 'validate') { line.children('.error_text').children('.error_validate').show(); } else if (state== 'twin') { line.children('.error_text').children('.error_twin').show(); } else if (state == 'email') { line.children('.error_text').children('.error_email').show(); } else if (state == 'special') { line.children('.error_text').children('.error_special').show(); } line.children('.error_text').show(); line.addClass('error_field'); } } function validatePasswordFromAlias(){ var usr = $('#username').val(); var psw = $('#password'); if (psw.parent().parent().children('.icons').children('.field_empty:visible').length <= 0) { validateField(psw); } } function validatePassword(str){ if(str.length < 5) { return false; } else { if (str == $('#username').val()) return false; else return true; } } function validatePostcode() { var str=new String($('#postcode').val()); if($('#fkcountry').val()=='145') { if(str=='' || str.length < 5 ) { toggleFind192(false); return false; } else { toggleFind192(true); return true; } } else { if(str.length > 1) return true; else return false; } } function validatePhone() { var str = new String($('#phone').val()); if(str!='' && ( str.length < 11 || str.length > 12)) return false; else return true; } function validateMobile() { return true; /*var mobile = new String($('#mobile').val()); if($('#special_offers_text').attr('checked')==true && mobile=='') return false else return true;*/ } function special_offers_text_click() { obj = $('#special_offers_text'); if($('#special_offers_text:checked').length == 0) { $('#mobile').parent().parent().children('.icons').children('.field_error').hide(); $('#mobile').parent().parent().children('.error_text').children('.error_validate').hide(); $('#mobile').parent().parent().children('.error_text').fadeOut('fast', function(){ $(this).parent().removeClass('error_field'); }); showFieldMessages('mobile', 'ok'); } else if($('#mobile').val()=='') { showFieldMessages('mobile', 'validate'); } } function validateAlias(str){ if(str.length < 3) { return false; } else { var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; if(letters.indexOf(str.charAt(0).toUpperCase()) > -1) return true; else return false; } } function checkAlias(){ var alias = $('#username').val(); $.ajax({ // Configuration type : "POST", url : '/registration/aliasCheck/', data : {'alias':alias}, cache : false, // Before sending request beforeSend : function(){ $('#alias_check_show').hide(); $('#alias_check_hide').show(); }, // Successful success : function(response) { $('#alias_check_show').show(); $('#alias_check_show').attr('disabled', 'disabled'); $('#alias_check_hide').hide(); response = toJSon(response); var obj = $('#username'); if(response['resp'] == 'ok') { $('#alias_special_text').show(); } else { { if(response['resp'] == 'empty') { obj.parent().parent().children('.error_text').children('.error_empty').show(); } else if(response['resp'] == 'special') { obj.parent().parent().children('.error_text').children('.error_special').show(); } obj.parent().parent().addClass('error_field'); obj.parent().parent().children('.error_text').fadeIn('fast', function(){ }); } } } }); } function validateEmail(email) { /*var re = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|co.uk)\b/;*/ var re = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i ; return email.match(re) } var issCCEnabled = false; function ccEnabled(e) { if (e) { console.log("enabled"); $('.cc_field').removeAttr('ignoreBlur'); $('.cc_label').each(function(){ $(this).html($(this).html()+ ' *'); }); if ($('#cc_fkcountry').val() == '') $('#cc_fkcountry').val(145) ; /* Default UK */ sameCCDetails(); $('#check_error').hide(); issCCEnabled = true; } else { if ($('#has_cc:checked').length == 0)$('#check_error').hide(); $('.cc_field').val(''); $('.cc_field').each(function(){ var obj = $(this); obj.attr('ignoreBlur', 'true'); obj.attr('removeHelp', 'true'); obj.parent().parent().children('.error_text').children().hide(); if (obj.parent().parent().children('.special_text').length > 0) obj.parent().parent().children('.special_text').hide(); }); checkForSoloSwitch(); $('.cc_label').each(function(){ $(this).html($(this).html().replace(' *', '')); }); issCCEnabled = false; } } function validateCCHolder() { var name = $('#cc_holder').val(); if ($('#has_cc:checked').length > 0) { if (name == '') return false; return true; } return -1; } function validateCCCompany() { var company = $('#cc_company').val(); if ($('#has_cc:checked').length > 0) { if (company == '') return false; else return true; } return -1; } function checkForSoloSwitch(val) { if( val == 5 || val == 6 ) { $('.is_solo_switch').show(); } else { $('.is_solo_switch').hide(); var obj = $('.is_solo_switch'); obj.parent().parent().children('.error_text').children().hide(); } } function isSoloSwitch() { var val = $('#cc_company').val(); return ( val == 5 || val == 6 ); } function validateCCIssue() { var issue = $('#cc_issue').val(); if ($('#has_cc:checked').length > 0) { if (isSoloSwitch()) if (issue == '') return false; return true; } return -1; } function validateCCNumber() { var num = $('#cc_number').val(); if ($('#has_cc:checked').length > 0) { if (num == '') return false; else { return true; } } return -1; } function validateCCAddress() { var add = $('#cc_address').val(); if ($('#has_cc:checked').length > 0) { if (add == '') return false; else { return true; } } return -1; } function validateCCCity() { var city = $('#cc_city').val(); if ($('#has_cc:checked').length > 0) { if (city == '') return false; else { return true; } } return -1; } function validateCCZip() { var zip = $('#cc_zipcode').val(); if ($('#has_cc:checked').length > 0) { if (zip == '') return false; else { return true; } } return -1; } function validateCCCountry() { var country = $('#cc_fkcountry').val(); if ($('#has_cc:checked').length > 0) { if (country == '') return false; else return true; } return -1; } function validateCCExpDate() { var expY = $('#cc_exp_date_year').val(); var expM = $('#cc_exp_date_month').val(); if ($('#has_cc:checked').length > 0) { if ((expY == '') || (expM == '')) return false; else return true; } return -1; } function validateCCStartDate() { var expY = $('#cc_start_date_year').val(); var expM = $('#cc_start_date_month').val(); if ($('#has_cc:checked').length > 0) { if ((isSoloSwitch()) && (expY == '') || (expM == '')) return false; else return true; } return -1; } function validateDobMultiSelect() { var d = $('#dob_day').val(); var m = $('#dob_month').val(); var y = $('#dob_year').val(); if ((d=='') || (m == '') || (y == '')) { return false; } else { var myDate=new Date(); myDate.setFullYear(y*1,(m*1)-1,d*1); var Date18=new Date(); Date18.setYear(Date18.getYear()-18); if (myDate <= Date18) { return true; } else return false; } } function sameCCDetails() { var isCh = ($('#sameCCDetails:checked').length>0); if (isCh) { var flat = $('#flat_number').val(); var strtmp = $('#street').val(); var hn_bn = $('#hn_bn').val(); var street = (hn_bn) ? hn_bn+' '+strtmp : strtmp; street = (flat) ? flat+' '+street : street; $('#cc_holder').val($('#fname').val()+' '+$('#lname').val()); validateField($('#cc_holder'), true); $('#cc_city').val($('#city').val()); validateField($('#cc_city'), true); $('#cc_zipcode').val($('#postcode').val()); validateField($('#cc_zipcode'), true); $('#cc_fkcountry').val($('#fkcountry').val()); validateField($('#cc_fkcountry'), true); $('#cc_address').val(street); validateField($('#cc_address'), true); } } /*function checkCCEnabledAuto() { if ($('.cc_field:input[type="text"]:visible[value!=""], #cc_company[value!=""], #cc_exp_date_month[value!=""], #cc_exp_date_year[value!=""]').length > 0) { if (!issCCEnabled) { $('#has_cc').attr('checked', 'checked'); ccEnabled(true); } } else { if (issCCEnabled) { $('#has_cc').removeAttr('checked'); ccEnabled(false); } } }*/ var intCheck = false; //setInterval(function() { checkCCEnabledAuto(); }, 500); function zipCodeAutoSpace(evt) { var l = $('#postcode').val().length; if( l == 0) { toggleFind192(false); return; } if ( l >= 5 ) { toggleFind192(true); validateField($('#postcode'),false); } /*var charCode = (evt.which) ? evt.which : event.keyCode; if (charCode != 8) { if (l == 2) { setTimeout(function(){ $('#postcode').val($('#postcode').val()+' '); }, 100); return true; } else if (l == 3) { $('#postcode').val($('#postcode').val()+' '); return true; } } else { if (l == 5) { $('#postcode').val($('#postcode').val().replace(' ', '')); } return true; }*/ } function toggleFind192(status) { //console.log('status='+status); if(status==true) $('#192_address_button_id').removeAttr('disabled'); else { //console.log('disabling find'); $('#192_address_button_id').attr('disabled','disabled'); } } function checkForUK() { var postcode=$('#postcode').val(); if( ($('#fkcountry').val()=='145' ) && (postcode=='') ) toggleAddressFields(false); else toggleAddressFields(true); } function toggleAddressFields(status) { if(!status) { $('#hn_bn_id').hide(); $('#flat_number_id').hide(); $('#street_id').hide(); $('#city_id').hide(); $('#192_search_id').show(); $('#192_address_select_id').attr('disabled','disabled'); $('#192_address_searching_id').hide(); $('#192_address_button_id').show(); } else { $('#192_address_button_id').hide(); $('#192_search_id').hide(); $('#flat_number_id').show(); $('#street_id').show(); $('#city_id').show(); $('#hn_bn_id').show(); } } var addressCache={}; function search192() { //svar cpostal=#('#') var postcode = $('#postcode').val(); $.ajax({ // Configuration type : "POST", url : '/registration/searchAddress/', data : {'postcode':postcode}, cache : false, // Before sending request beforeSend : function(){ $('#192_address_button_id').hide(); $('#192_address_searching_id').show(); $('#192_address_select_id').find('option').remove(); $('#192_address_select_id').attr('disabled','disabled'); }, // Successful success : function(response) { $('#192_address_searching_id').hide(); $('#192_address_button_id').show(); var str=''; $('#192_address_select_id').append(str); addressCache={}; if(response != 'null') { response = toJSon(response); addressCache=response; //toggleFind192(false); $.each(response,function(k,v){ var str=''; $('#192_address_select_id').append(str); }); $('#192_address_select_id').removeAttr('disabled'); $('#192_address_button_id').hide(); //$('#192_manualaddress_button_id').hide(); } else { $('#192_address_select_id').removeAttr('disabled'); toggleFind192(true); } str=''; $('#192_address_select_id').append(str); } }); } function selectAddress() { var k=$('#192_address_select_id option:selected').val(); if(k=='-1') return; if(k=='-2') { $('#192_address_button_id').hide(); toggleAddressFields(true); return; } var data=addressCache[k]; var hn_bn = (data['Premise']) ? data['Premise'] : ( (data['Building']) ? data['Building'] : data['AddressLine1']); var street=data['Street']; $('#hn_bn').val(hn_bn); $('#flat_number').val(data['SubBuilding']); $('#street').val(street); $('#city').val(data['City']); $('#flat_number_id').show(); $('#street_id').show(); $('#city_id').show(); $('#hn_bn_id').show(); validateField($('#hn_bn'),true); validateField($('#flat_number'),true); validateField($('#street'),true);; validateField($('#city'),true);; } function bindEvents() { $('#regform').bind('submit', function(){ afterSubmit(); var times = $(this).attr('times'); if (times == undefined) { $(this).attr('times', 1); return true; } else { return false; } }); $('#reg_input').hover( function(){$(this).attr('src', '/images/btn_joinqsb_hover.png') }, function(){$(this).attr('src', '/images/btn_joinqsb.png') } ); } function afterSubmit() { $('body').css('cursor', 'wait'); $('#reg_input').hide(); $('#reg_input').after('
'); }