﻿var countryArrayGlobal=new Array("Default","GB","DE","SG","ES","SE","AU","MY");var maxAddressFieldsNumber=6;function setIcon1(id,status){var icon=document.getElementById(id);if(!icon)return;switch(status){case "pass":icon.src="../../../images/icon_pass.gif";break;case "fail":icon.src="../../../images/icon_failed.gif";break;case "required":icon.src="../../../images/Icon_Required.gif";break;}icon.style.display="inline";};function setIconAndColorArray(status,inputBoxIdArray,iconId){var len=0;if(inputBoxIdArray&&inputBoxIdArray.length>0){len=inputBoxIdArray.length;}if(status=="pass"){setIcon1(iconId,"pass");for(var i=0;i<len;i++){setColor("pass",inputBoxIdArray[i]);}}else{setIcon1(iconId,"fail");for(var i=0;i<len;i++){setColor("fail",inputBoxIdArray[i]);}}};function setColor(status,inputId){var tmpEle=document.getElementById(inputId);if(!tmpEle)return;if(status=="pass"){var tmpClassNm=tmpEle.className;tmpClassNm=tmpClassNm.replace(/FailInput/g,"");tmpEle.className=tmpClassNm;}else if(status=="fail"){var tmpClassNm=tmpEle.className;if(tmpClassNm.indexOf("FailInput")== -1){tmpEle.className+=" FailInput";}}};function setIconAndColor(status,inputId,iconId){if(status=="pass"){setIcon1(iconId,"pass");var tmpEle=document.getElementById(inputId);if(tmpEle){var tmpClassNm=tmpEle.className;tmpClassNm=tmpClassNm.replace(/FailInput/g,"");tmpEle.className=tmpClassNm;}}else{setIcon1(iconId,"fail");var tmpEle=document.getElementById(inputId);if(tmpEle){var tmpClassNm=tmpEle.className;if(tmpClassNm.indexOf("FailInput")== -1){tmpEle.className+=" FailInput";}}}};function validateNonEmpty2(id,iconID){if(!document.getElementById(id).value||isEmpty(document.getElementById(id).value)){setIconAndColor("fail",id,iconID);return false;}else{setIconAndColor("pass",id,iconID);return true;}};function validateNonDigit(id,iconID){if(!document.getElementById(id).value|| !isNoDigit(document.getElementById(id).value)){setIconAndColor("fail",id,iconID);return false;}else{setIconAndColor("pass",id,iconID);return true;}};function checkNumberString(id,minLength,maxLength){var result=true;var str=document.getElementById(id).value;var result=(str&&isNumber(str));if(minLength)result&=(str.length>=minLength);if(maxLength)result&=(str.length<=maxLength);return result;};function validateNumerString(id,iconId,minLength,MaxLength){if(!checkNumberString(id,minLength,MaxLength)){setIconAndColor("fail",id,iconId);return false;}else{setIconAndColor("pass",id,iconId);return true;}};function validateSelect(id,iconId){var a=document.getElementById(id).value;if(a==""){setIconAndColor("fail",id,iconId);return false;}else{setIconAndColor("pass",id,iconId);return true;}};function validateDob(finalCheck){var ids=new Array("dobDay","dobMonth","dobYear");var month=document.getElementById("dobMonth").value;var day=document.getElementById("dobDay").value;var year=document.getElementById("dobYear").value;if(day==""||month==""||year==""){if(finalCheck){setIconAndColorArray("fail",ids,"iconDob");return false;}setIconAndColorArray("pass",ids,"iconDob");setDisplay("iconDob","none");}else{if(year<maxYear||(year==maxYear&&month<maxMonth)||(year==maxYear&&month==maxMonth&&day<=maxDay)){setIconAndColorArray("pass",ids,"iconDob");return true;}else{setIconAndColorArray("fail",ids,"iconDob");return false;}}};function validateEmail(){var email=document.getElementById("email").value;if(email&&isEmail(email)){setIconAndColor("pass","email","iconEmail");return true;}else{setIconAndColor("fail","email","iconEmail");return false;}};function validateReEmail(){var email=document.getElementById("email").value;var reEmail=document.getElementById("reEmail").value;if(email==reEmail){setIconAndColor("pass","reEmail","iconReEmail");return true;}else{setIconAndColor("fail","reEmail","iconReEmail");return false;}};function validatePhoneAreaCode(areaID,phoneID,iconID){var areaCode=document.getElementById(areaID).value;if(areaCode&&areaCode.length>0){if(checkNumberString(areaID,0,6)){setColor("pass",areaID);setDisplay(iconID,"none");}else{setIconAndColor("fail",areaID,iconID);}}else{setColor("pass",areaID);setDisplay(iconID,"none");}var phoneNo=document.getElementById(phoneID).value;if(phoneNo&&phoneNo.length>0){return validatePhoneNo(phoneID,areaID,iconID);}};function validatePhoneNo(phoneID,areaID,iconID){var areaCode=document.getElementById(areaID).value;var tmp=true;if(areaCode&&areaCode.length>0){tmp=checkNumberString(areaID,0,6);if(!tmp){setIconAndColor("fail",areaID,iconID);}else{setColor("pass",areaID);}}var result=checkNumberString(phoneID,5,20);if(!result){setIconAndColor("fail",phoneID,iconID);}else if(tmp){setIconAndColorArray("pass",new Array(phoneID,areaID),iconID);}else{setColor("pass",phoneID);}return tmp&&result;};function validatePostalCode(id,iconID){var result=true;var str=document.getElementById(id).value;if(document.getElementById('country').value.toLowerCase()=="gb"){result=(str&&/^(\w|\d)(\w|\s|\d)+(\w|\d)$/.test(str));result&=(str.length>=3);result&=(str.length<=15);if(result){setIconAndColor("pass",id,iconID);return true;}else{setIconAndColor("fail",id,iconID);return false;}}else{if(str&&str.length>0){if(str.length<3){setIconAndColor("fail",id,iconID);return false;}else{setIconAndColor("pass",id,iconID);return true;}}else{setIconAndColor("pass",id,iconID);document.getElementById(iconID).style.display="none";return true;}}};function validatePassword(finalCheck,pwdID,rePwdID,iconPwd){var password=document.getElementById(pwdID).value;if(password&&password.length>=6&&password.length<=12){setIconAndColor("pass",pwdID,iconPwd);var strength=evalPasswordStrength(password);for(var i=1;i<=5;i++){if(i==strength)setDisplay("strength"+i,"inline");else setDisplay("strength"+i,"none");}return true;}else{for(var i=2;i<=5;i++){setDisplay("strength"+i,"none");}setDisplay("strength1","inline");setIconAndColor("fail",pwdID,iconPwd);return false;}};function evalPasswordStrength(pwd){var score=1;if(pwd.length<6)return 1;if(pwd.match(/[a-z]/))score++;if(pwd.match(/[A-Z]/))score++;if(pwd.match(/\d+/))score++;if(pwd.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/))score++;return score;};function validateRePassword(rePwdID,pwdID,iconRePwd){var pwd=document.getElementById(pwdID).value;var rePwd=document.getElementById(rePwdID).value;if(pwd==rePwd){setIconAndColor("pass",rePwdID,iconRePwd);return true;}else{setIconAndColor("fail",rePwdID,iconRePwd);return false;}};function isArrayContains(arrayList,toBeFound){if(!arrayList||arrayList.length==0|| !toBeFound){return false;}var arrLen=arrayList.length;for(var i=0;i<arrLen;i++){if(arrayList[i]==toBeFound){return true;}}return false;};function countryChanged(onlyAddr){var lsCountry=document.getElementById('country');var countryCode=lsCountry.value;var tmpArray=countryPhone[countryCode].split(":");var countryPhoneCode=tmpArray[0];var continentCode=tmpArray[1];document.getElementById("homeTel1").value=countryPhoneCode;document.getElementById("mobilePhone1").value=countryPhoneCode;hidAllAddrFormat();if(isArrayContains(countryArrayGlobal,countryCode)){for(var i=1;i<=maxAddressFieldsNumber;i++){var tempEle=document.getElementById(countryCode+"Row"+i);if(tempEle){setDisplay(countryCode+"Row"+i,"");}}}else{for(var i=1;i<=maxAddressFieldsNumber;i++){var tempEle=document.getElementById("DefaultRow"+i);if(tempEle){setDisplay("DefaultRow"+i,"");}}}if(onlyAddr){return;}setCurrByCountry(countryCode,continentCode);setDisplay("iconCurrency","none");};function setCurrByCountry(countryCode,contiCode){if(countryCurrencymap[countryCode]){selCurr(countryCurrencymap[countryCode]);}else{if(contiCode=="EU"){selCurr("EUR");}else{selCurr("USD");}}};function selCurr(curr){var currSel=document.getElementById("currency");var selLen=currSel.options.length;var tempI=0;for(tempI=0;tempI<selLen;tempI++){if(currSel.options[tempI].value==curr){currSel.options[tempI].selected=true;}else{currSel.options[tempI].selected=false;}}};function hidAllAddrFormat(){for(var i=1;i<=maxAddressFieldsNumber;i++){var cclen=countryArrayGlobal.length;for(var j=0;j<cclen;j++){var tempEle=document.getElementById(countryArrayGlobal[j]+"Row"+i);if(tempEle){setDisplay(countryArrayGlobal[j]+"Row"+i,"none");}}}};function selectMale(){document.getElementById("male").checked=true;document.getElementById("female").checked=false;};function selectFemale(){document.getElementById("male").checked=false;document.getElementById("female").checked=true;};function titleChanged(){var title=document.getElementById("title").value;if(title=="Mr"){selectMale()}else{selectFemale();}};function ValidateLoginName(){var loginName=document.getElementById("loginName");var iconLoginName=document.getElementById("iconLoginName");var isValid=IsValidLoginName(loginName.value);if(!isValid){setIconAndColor("fail","loginName","iconLoginName");}else{setIconAndColor("pass","loginName","iconLoginName");}return isValid;};function isTcTick(){var a=document.getElementById("tcCheck").value;return a&&(a=="1");};function ValidateAllInput(){return(validateNonDigit('firstName','iconFirstName')&&validateNonEmpty2('firstName','iconFirstName')&&validateNonDigit('lastName','iconLastName')&&validateNonEmpty2('lastName','iconLastName')&&validateDob(true)&&validateEmail()&&validateReEmail()&&validatePostalCode('postalcode','iconPostalcode')&&validateAddrByCountry()&&validatePhoneNo('homeTel3','homeTel2','iconHomeTel')&&validatePhoneNo('mobilePhone3','mobilePhone2','iconMobilePhone')&&ValidateLoginName()&&validatePassword(true,'password','rePassword','iconPassword')&&validateRePassword('rePassword','password','iconRePassword')&&validateSelect('currency','iconCurrency')&&validateSelect('secureQue','iconSecureQue')&&validateNonEmpty2('secureAns','iconSecureAns')&&validateNumerString('pin','iconPin',4,4)&&validateNumerString('VCode','iconVCode',6,6)&&isTcTick())};function validateAddrByCountry(){var countryCode=document.getElementById("country").value;switch(countryCode){case "GB":return validateNonEmpty2('premiseGB','iconPremiseGB')&&validateNonEmpty2('addressGB','iconAddressGB')&&validateNonEmpty2('localityGB','iconLocalityGB')&&validateNonEmpty2('cityGB','iconCityGB')&&validateNonEmpty2('countyGB','iconCountyGB');case "DE":return validateNonEmpty2('addressDE','iconAddressDE')&&validateNonEmpty2('premiseDE','iconPremiseDE')&&validateNonEmpty2('cityDE','iconCityDE');case "SG":return validateNonEmpty2('premiseSG','iconPremiseSG')&&validateNonEmpty2('addressSG','iconAddressSG');case "ES":return validateNonEmpty2('premiseES','iconPremiseES')&&validateNonEmpty2('addressES','iconAddressES')&&validateNonEmpty2('localityES','iconLocalityES')&&validateNonEmpty2('cityES','iconCityES');case "SE":return validateNonEmpty2('premiseSE','iconPremiseSE')&&validateNonEmpty2('addressSE','iconAddressSE')&&validateNonEmpty2('citySE','iconCitySE');case "AU":return validateNonEmpty2('premiseAU','iconPremiseAU')&&validateNonEmpty2('addressAU','iconAddressAU')&&validateNonEmpty2('cityAU','iconCityAU')&&validateNonEmpty2('stateAU','iconStateAU');case "MY":return validateNonEmpty2('premiseMY','iconPremiseMY')&&validateNonEmpty2('addressMY','iconAddressMY')&&validateNonEmpty2('cityMY','iconCityMY')&&validateNonEmpty2('localityMY','iconLocalityMY')&&validateNonEmpty2('stateMY','iconStateMY');default:return validateNonEmpty2('premiseDefault','iconPremiseDefault')&&validateNonEmpty2('addressDefault','iconAddressDefault')&&validateNonEmpty2('cityDefault','iconCityDefault')&&validateNonEmpty2('stateDefault','iconStateDefault');}};function hidLginNmSuggDiv(){document.getElementById("suggDiv").style.display="none";};function hidTip(){document.getElementById("tipDiv").style.display="none";};function getY(oElementID){var oElement=document.getElementById(oElementID);var iReturnValue=0;while(oElement!=null){iReturnValue+=oElement.offsetTop;oElement=oElement.offsetParent;}return iReturnValue;};function getX(oElementID){var oElement=document.getElementById(oElementID);var iReturnValue=0;while(oElement!=null){iReturnValue+=oElement.offsetLeft;oElement=oElement.offsetParent;}return iReturnValue;};function showTip(inputID,Xamount,Yamount){if(document.getElementById("suggDiv").style.display!="none"){return;}var len=inputID.length;var inputIDNoCC=inputID;if(inputID.indexOf("Default")!= -1){inputIDNoCC=inputID.substring(0,len-7);}else if(inputID.indexOf("GB")==len-2||inputID.indexOf("DE")==len-2||inputID.indexOf("SG")==len-2||inputID.indexOf("ES")==len-2||inputID.indexOf("SE")==len-2||inputID.indexOf("AU")==len-2||inputID.indexOf("MY")==len-2){inputIDNoCC=inputID.substring(0,len-2);}var tipDiv=document.getElementById("tipDiv");document.getElementById("tipContent").innerHTML=document.getElementById(inputIDNoCC+"TipTmpl").innerHTML;tipDiv.style.left=getX(inputID)+Xamount;tipDiv.style.top=getY(inputID)+Yamount;tipDiv.style.display="block";};function displayEditLN(){var cfm=document.getElementById("cfmLoginNm");var cfmDisplay=document.getElementById("dispLgNm");var lgN=document.getElementById("loginName");lgN.value=cfmDisplay.innerHTML;cfm.style.display="none";setDisplay("edtLoginNm","block");document.getElementById("loginNameChecked").value="0";document.getElementById("suggDiv").style.display="none";lgN.focus();};function displayCfmLN(cfmedLN){var edit=document.getElementById("edtLoginNm");var cfmDisplay=document.getElementById("dispLgNm");edit.style.display="none";setDisplay("cfmLoginNm","block");cfmDisplay.innerHTML=cfmedLN;document.getElementById("loginNameChecked").value="1";document.getElementById("suggDiv").style.display="none";};function AlertLoginNameInvalid(){alert(msgInvalidLoginName);};function showSugguestion(suggList){var ul=document.getElementById("suggListOL");var suggDiv=document.getElementById("suggDiv");var tmpStr="";if(suggList&&suggList.length>0){for(var i=0;i<suggList.length;i++){tmpStr+="<li><a href='#' onclick=\"pressCheckLginNm2('"+suggList[i]+"');\">"+suggList[i]+"</a></li>";}}else{tmpStr="<li>"+cannotFindSuggestion+"</li>"}ul.innerHTML=tmpStr;suggDiv.style.display="block";setIconAndColor("fail","loginName","iconLoginName");document.getElementById("loginName").select();};function toggleNextBt(){var dis=document.getElementById("nextBtDisabled");var bt=document.getElementById("nextBt");if(document.getElementById("tcCheck").checked){dis.style.display="none";bt.style.display="block";}else{dis.style.display="block";bt.style.display="none";}};function pressCheckLoginName(){if(ValidateLoginName()){setHidLoginNameForm();document.getElementById("onlyDoCheckSuggest").value="1";document.getElementById("checkNSuggestLoginNameForm").submit();}};function pressCheckLginNm2(lginm){document.getElementById("loginName").value=lginm;pressCheckLoginName();};function checkLoginNameRegister(){if(ValidateLoginName()){setHidLoginNameForm();document.getElementById("onlyDoCheckSuggest").value="0";document.getElementById("checkNSuggestLoginNameForm").submit();}};function setHidLoginNameForm(){document.getElementById("hidLoginName").value=document.getElementById("loginName").value;document.getElementById("hidFirstName").value=document.getElementById("firstName").value;document.getElementById("hidLastName").value=document.getElementById("lastName").value;document.getElementById("hidDobDay").value=document.getElementById("dobDay").value;document.getElementById("hidDobMonth").value=document.getElementById("dobMonth").value;document.getElementById("hidDobYear").value=document.getElementById("dobYear").value;document.getElementById("hidEmail").value=document.getElementById("email").value;}
