function checkUsername(obj, errObj, crossDomainCallback) { var fieldVal = $.trim($(obj).val()); var result = false; if (validate(obj, errObj)) { var regexp = new RegExp("^[a-zA-Z]{1}\\w{5,}$"); if (!fieldVal.match(regexp)) { $(obj).attr("tooltip","Your Username must be between 6-20 alphanumeric characters."); $(obj).tipsy("show"); setFocus(obj); return false; } $.ajax({ url: 'http://friends.shanghaidaily.com/validateDuplicate.jhtml', type: 'GET', dataType: 'jsonp', async: false, data: "action=checkDuplicate&field=username&value="+fieldVal, success: function (data) { data = data.occupied; if (data=='true') { $(obj).attr("tooltip","Sorry, that Username is already taken. Please enter another one."); $(obj).tipsy("show"); setFocus(obj); } else { crossDomainCallback(); } } }); } return result; } function checkEmailAddress(obj, errObj, crossDomainCallback) { var fieldVal = $.trim($(obj).val()); var result = false; if (validate(obj, errObj)) { if (!isEmailFormatValid(fieldVal)) { $(obj).attr("tooltip","Please enter your Email Address in the correct format. e.g. john@gmail.com."); $(obj).tipsy("show"); setFocus(obj); return false; } $.ajax({ url: 'http://friends.shanghaidaily.com/validateDuplicate.jhtml', type: 'GET', dataType: 'jsonp', async: false, data: "action=checkDuplicate&field=emailaddress&value="+fieldVal, success: function (data) { data = data.occupied; if (data=='true') { $(obj).attr("tooltip","This email address has been used already. Please register with other email address."); $(obj).tipsy("show"); setFocus(obj); } else { crossDomainCallback(); } } }); } return result; } function checkCaptcha(obj, errObj, crossDomainCallback){ var fieldVal = $.trim($(obj).val()); var result = false; if (validate(obj, errObj)) { $.ajax({ url: '/captcha/search.jhtml', type: 'GET', dataType: 'text', async: false, data: "action=captchaCheck&captchaCode="+fieldVal, success: function (data) { data = $.trim(data); if (data=='false') { $("#captchaCode").attr("tooltip","signup.captcha.err.incorrect"); $("#captchaCode").tipsy("show"); setFocus($("#captchaCode")); }else{ result = true; } } }); } return result; } function checkPassword(obj, usernameObj) { var fieldVal = $.trim($(obj).val()); var usernameVal; if($(usernameObj).length) { usernameVal = $(usernameObj).val(); } if (validate(obj)) { var regexp = new RegExp("^\\w{6,}$"); if (!fieldVal.match(regexp)) { $(obj).attr("tooltip","Please enter your Password. Your Password must be between 6-20 alphanumeric characters"); $(obj).tipsy("show"); setFocus(obj); return false; } if (fieldVal==usernameVal) { $(obj).attr("tooltip","Your Password must be different from your Username."); $(obj).tipsy("show"); setFocus(obj); return false; } return true; } return false; } function checkPassword2(obj, obj1) { var fieldVal = $.trim($(obj).val()); var passwordVal = $.trim($(obj1).val()); if (validate(obj)) { if (fieldVal!=passwordVal) { $(obj).attr("tooltip","Your Passwords do not match. Please try again."); $(obj).tipsy("show"); setFocus(obj); return false; } return true; } return false; } function checkSpokenLanguages(selObj, obj1, obj2, obj3, errObj) { initSpokenLanguages(selObj, obj1, obj2, obj3) return validate(obj1, errObj); } function initSpokenLanguages(selObj, obj1, obj2, obj3) { var lang1Id = $(obj1).attr("id"); var lang2Id = $(obj2).attr("id"); var lang3Id = $(obj3).attr("id"); // Enable all options $(selObj).each(function() { $(this).children().each(function() { $(this).removeAttr('disabled'); }); }); // Disable the selected option $('#'+lang1Id+' > option').each(function() { if ($(this).val()!=0 && ($(this).val()==$('#'+lang2Id).val() || $(this).val()==$('#'+lang3Id).val())) { $(this).attr('disabled','disabled'); } }); $('#'+lang2Id+' > option').each(function() { if ($(this).val()!=0 && ($(this).val()==$('#'+lang1Id).val() || $(this).val()==$('#'+lang3Id).val())) { $(this).attr('disabled','disabled'); } }); $('#'+lang3Id+' > option').each(function() { if ($(this).val()!=0 && ($(this).val()==$('#'+lang1Id).val() || $(this).val()==$('#'+lang2Id).val())) { $(this).attr('disabled','disabled'); } }); // Disable spokenLanguages2 if ($('#'+lang1Id).val() > 0) { $('#'+lang2Id).removeAttr('disabled'); } else { // Enable back the spokenLanguages2 item $('#'+lang1Id+' > option').each(function() { if ($(this).val()==$('#'+lang2Id).val()) { $(this).removeAttr('disabled'); } }); $('#'+lang3Id+' > option').each(function() { if ($(this).val()==$('#'+lang2Id).val()) { $(this).removeAttr('disabled'); } }); $('#'+lang2Id).attr('disabled','disabled'); $('#'+lang2Id+' option:first').attr('selected', 'selected'); } // Disable spokenLanguages3 if ($('#'+lang2Id).val() > 0) { $('#'+lang3Id).removeAttr('disabled'); } else { // Enable back the spokenLanguages3 item $('#'+lang1Id+' > option').each(function() { if ($(this).val()==$('#'+lang3Id).val()) { $(this).removeAttr('disabled'); } }); $('#'+lang2Id+' > option').each(function() { if ($(this).val()==$('#'+lang3Id).val()) { $(this).removeAttr('disabled'); } }); $('#'+lang3Id).attr('disabled','disabled'); $('#'+lang3Id+' option:first').attr('selected', 'selected'); } } function checkGender(obj, errObj) { return validate(obj, errObj); } function checkBirth(yearObj, monthObj, dayObj, errObj) { errObj = errObj==null ? dayObj : errObj; if (validate(yearObj, errObj)) { if (validate(monthObj, errObj)) { if (validate(dayObj, errObj)) { var birthYear = $(yearObj).val(); var birthMonth = $(monthObj).val(); var birthDay = $(dayObj).val(); var birthdayObj = new Date(); birthdayObj.setYear(birthYear); birthdayObj.setMonth(birthMonth-1); birthdayObj.setDate(birthDay); birthdayObj.setHours(0); birthdayObj.setMinutes(0); birthdayObj.setSeconds(0); var server18 = 912096000000; var user18 = birthdayObj.getTime(); if (server18-user18<0) { $(errObj).attr("tooltip","Sorry, Members must be at least 18 years old to use the Service."); $(errObj).tipsy("show"); setFocus(errObj); return false; } var dayobj = new Date(birthYear, birthMonth-1, birthDay) if ((dayobj.getMonth()+1!=birthMonth)||(dayobj.getDate()!=birthDay)||(dayobj.getFullYear()!=birthYear)) { $(errObj).attr("tooltip","Sorry, the date you entered is invalid. Please try again."); $(errObj).tipsy("show"); setFocus(errObj); return false; } return true; } } } return false; } function checkMaritalStatus(obj) { return validate(obj); } function checkEthnicity(obj) { return validate(obj); } function checkFirstName(obj) { var result = false; if (validate(obj)) { result = true; if ($(obj).val().length < 3||$(obj).val().length > 20) { $(obj).attr("tooltip","Your Firstname must be between 3-20 alphanumeric characters."); $(obj).tipsy("show"); setFocus(obj); result = false; } } return result; } function checkMyCity(countryObj, regionObj, cityObj, errObj) { return validate(countryObj, errObj) && validate(regionObj, errObj) && validate(cityObj, errObj) } function checkCountry(obj) { return validate(obj); } function checkRegion(obj) { return validate(obj); } function checkCity(obj) { return validate(obj); } function checkProfession(obj) { return validate(obj); } function checkEducation(obj) { return validate(obj); } function checkReligion(obj) { return validate(obj); } function checkThoughtsOnSmoking(obj) { return validate(obj); } function checkThoughtsOnAlcohol(obj) { return validate(obj); } function checkThoughtsOnKids(obj) { return validate(obj); } function checkTitle(obj) { var result = false; if (validate(obj)) { result = true; if ($(obj).val().length < 20) { $(obj).attr("tooltip","You should have at least 20 characters for Headline"); $(obj).tipsy("show"); setFocus(obj); result = false; } } return result; } function checkIntroduction(obj) { var result = false; if (validate(obj)) { result = true; if ($(obj).val().length < 30) { $(obj).attr("tooltip","You should have at least 30 characters for Introducation"); $(obj).tipsy("show"); setFocus(obj); result = false; } } return result; } ////////////////////////////////////////////////////////////////////////// function getDefaultMatchAge(birthYear) { var year = "2016"; var matchAgeLower = year-birthYear - 5; if (matchAgeLower < 18) { matchAgeLower = 18; } var matchAgeUpper = year-birthYear + 5; if (matchAgeUpper > 80) { matchAgeUpper = 80; } var matchAge = new Object(); matchAge.lower = matchAgeLower; matchAge.upper = matchAgeUpper; return matchAge; } function getDefaultMatchGender(gender) { var matchGender = gender==1 ? "2" : "1"; return matchGender; } var OptionDisabledSupport = new function() { this.previouslySelectedIndices = new Array(); this.init = function() { selects = document.getElementsByTagName("select"); for (var i=0;i -1) { if (select.options[select.selectedIndex].disabled) { select.selectedIndex = OptionDisabledSupport.previouslySelectedIndices[select]; if (select.options[select.selectedIndex].disabled) { select.selectedIndex = -1; } } } } checkSpokenLanguages('spokenLanguages','spokenLanguages1','spokenLanguages2','spokenLanguages3'); } } if (window.attachEvent) window.onload = OptionDisabledSupport.init;