var WS = " \t\n\r\b"; var reEmail = /^.+\@.+\..+$/; var rePhone="\,\-\(\)" //var reInteger = /\d+$/ //var reAlphaNum = /^[a-zA-Z0-9áéíóúÁÉÍÓÚ \.\-,'\/\\&\?!"£$%^*()+={}:@~;'#|<>?\t\n\r]+$/ var reAlpha = /[a-zA-ZáéíóúÁÉÍÓÚ\s\b]/ var reAlphaNumeric = /[a-zA-ZáéíóúÁÉÍÓÚ\s\b\d]/ var reInteger = /[\d\s\b]/ // This empty array is used in submitform, and is set to one of the populated arrays, depending on the form type var fields = new Array(); // Age is displaying on the results page var age = 0; // These arrays are sent into validateAllFields() // Each array represents a form // Each row of an array, represents a field in a form // Types of validtion, 0 = String validation, 1 = DOB validation // Type of validation // Field to validate // Validation function // Error message string var changeAddressFields = new Array( [0, "ca_firstname", isAlpha, "Your first name"], [0, "ca_surname", isAlpha, "Your surname"], [1, "ca_dob_day", "ca_dob_month", "ca_dob_year"], [0, "ca_policy1", isAlphaNumeric, "Your plan number"], [0, "ca_newAddress", isAlphaNumeric, "Your new postal address"], [0, "ca_email", isEmail, "Your contact email address"], [0, "ca_phoneNo", isNumeric, "Your contact phone number"] ); var correctNameFields = new Array( [0, "cn_firstname", isAlpha, "Your first name"], [0, "cn_surname", isAlpha, "Your surname"], [1, "cn_dob_day", "cn_dob_month", "cn_dob_year"], [0, "cn_policy1", isAlphaNumeric, "Your plan number"], [0, "cn_email", isEmail, "Your contact email address"], [0, "cn_phoneNo", isNumeric, "Your contact phone number"] ); var generalEnquiryFields = new Array( [0, "gen_firstname", isAlpha, "Your first name"], [0, "gen_surname", isAlpha, "Your surname"], [1, "gen_dob_day", "gen_dob_month", "gen_dob_year"], [0, "gen_plan", isAlphaNumeric, "Your plan number"], [0, "gen_question", isAlpha, "Your question"], [0, "gen_email", isEmail, "Your contact email address"], [0, "gen_phoneNo", isNumeric, "Your contact phone number"] ); var feedbackFields = new Array( [0, "fb_firstname", isAlpha, "Your first name"], [0, "fb_surname", isAlpha, "Your surname"], [0, "fb_email", isEmail, "Your contact email address"], [0, "fb_phoneNo", isNumeric, "Your contact phone number"], [0, "fb_comments", isAlphaNumeric, "Your comments"] ); var financialReviewFields = new Array( [0, "rev_firstname", isAlpha, "Your first name"], [0, "rev_surname", isAlpha, "Your surname"], [0, "rev_email", isEmail, "Your contact email address"], [0, "rev_phoneNo1", isNumeric, "Your contact phone number"], [0, "rev_callTime1", isAlphaNumeric, "Appropriate time to call"] ); var pensionReviewFields = new Array( [0, "rev_firstname", isAlpha, "Your first name"], [0, "rev_surname", isAlpha, "Your surname"], [0, "rev_email", isEmail, "Your contact email address"], [0, "rev_phoneNo1", isNumeric, "Your contact phone number"], [0, "rev_callTime1", isAlphaNumeric, "Appropriate time to call"] ); var quickQuoteFields = new Array( [0, "gq_firstname", isAlpha, "Your first name"], [0, "gq_surname", isAlpha, "Your surname"], [0, "gq_phone", isNumeric, "Your contact phone number"], [0, "gq_email", isEmail, "Your contact email address"] ); var planValueFields = new Array( [0, "rv_firstname", isAlpha, "Your first name"], [0, "rv_surname", isAlpha, "Your surname"], [1, "rv_dob_day", "rv_dob_month", "rv_dob_year"], [0, "rv_plan", isAlphaNumeric, "Your plan number"], [0, "rv_email", isEmail, "Your contact email address"], [0, "rv_phone", isNumeric, "Your contact phone number"] ); var lifeTermAmountFields = new Array( [2, "coverTypeCd", "", "What would like to calculate the cost of?"], [2, "jointLife", "", "How many people would you like to cover?"], [1, "dateOfBirth1Day", "dateOfBirth1Month", "dateOfBirth1Year"], [2, "sexCd1", "", "Are you male or female?"], [2, "smokerCd1", "", "Do you smoke?"], [0, "premiumAmt", isNumeric, "How much would you like to contribute?"], [2, "frequencyCd", "", "How often will you make your contribution?"], [0, "term", isNumeric, "How many years do you want to contribute for?"], [2, "indexation", "", "Do you want your contributions to increase with inflation?"], [2, "conversion", "", "Would you like the option to switch policy at a later stage?"], [3, "", "", ""], [1, "dateOfBirth2Day", "dateOfBirth2Month", "dateOfBirth2Year"], [2, "sexCd2", "", "Are you male or female?"], [2, "smokerCd2", "", "Do you smoke?"], [0, "emailAddress", isEmail, "Please enter a valid email address"] ); var lifeTermSumFields = new Array( [2, "coverTypeCd", "", "What would like to calculate the cost of?"], [2, "jointLife", "", "How many people would you like to cover?"], [1, "dateOfBirth1Day", "dateOfBirth1Month", "dateOfBirth1Year"], [2, "sexCd1", "", "Are you male or female?"], [2, "smokerCd1", "", "Do you smoke?"], [0, "lifeCoverAmt", isNumeric, "How much do you want your life insured for?"], [4, "sicCoverAmt", isNumeric, "How much serious illness cover do you want?"], [2, "frequencyCd", "", "How often will you make your contribution?"], [0, "term", isNumeric, "How many years do you want to contribute for?"], [2, "indexation", "", "Do you want your contributions to increase with inflation?"], [2, "conversion", "", "Would you like the option to switch policy at a later stage?"], [3, "", "", ""], [1, "dateOfBirth2Day", "dateOfBirth2Month", "dateOfBirth2Year"], [2, "sexCd2", "", "Are you male or female?"], [2, "smokerCd2", "", "Do you smoke?"], [0, "emailAddress", isEmail, "Please enter a valid email address"] ); var lifeMortgageFields = new Array( [2, "coverTypeCd", "", "What would like to calculate the cost of?"], [2, "jointLife", "", "How many people would you like to cover?"], [1, "dateOfBirth1Day", "dateOfBirth1Month", "dateOfBirth1Year"], [2, "sexCd1", "", "Are you male or female?"], [2, "smokerCd1", "", "Do you smoke?"], [0, "lifeCoverAmt", isNumeric, "How much do you want your life insured for?"], [4, "sicCoverAmt", isNumeric, "How much serious illness cover do you want?"], [2, "frequencyCd", "", "How often will you make your contribution?"], [0, "term", isNumeric, "How many years do you want to contribute for?"], [3, "", "", ""], [1, "dateOfBirth2Day", "dateOfBirth2Month", "dateOfBirth2Year"], [2, "sexCd2", "", "Are you male or female?"], [2, "smokerCd2", "", "Do you smoke?"], [0, "emailAddress", isEmail, "Please enter a valid email address"] ); var savingsAmount = new Array( [0, "premiumAmt", isNumeric, "How much would you like to contribute?"], [2, "frequencyCd", "", "How often will you make your contribution?"], [2, "indexation", "", "Do you want your contributions to increase with inflation?"] ); var savingsFund = new Array( [0, "savingsTargetAmt", isNumeric, "How much is your target fund?"], [0, "term", isNumeric, "How many years do you want to contribute for?"], [2, "frequencyCd", "", "How often will you make your contribution?"], [2, "indexation", "", "Do you want your contributions to increase with inflation?"] ); var pensionSalary = new Array( [1, "dateOfBirth1Day", "dateOfBirth1Month", "dateOfBirth1Year"], [2, "sexCd1", "", "Are you male or female?"], [0, "retirementAge", isNumeric, "What is your retirement age?"], [0, "income", isNumeric, "What is your annual income before tax?"], [2, "frequencyCd", "", "How often will you make your contribution?"], [0, "salaryPct", isNumeric, "What percent of your annual income would you like your pension to be?"], [2, "indexation", "", "Do you want your contributions to increase with inflation?"] ); var pensionFund = new Array( [1, "dateOfBirth1Day", "dateOfBirth1Month", "dateOfBirth1Year"], [2, "sexCd1", "", "Are you male or female?"], [0, "retirementAge", isNumeric, "What is your retirement age?"], [0, "income", isNumeric, "What is your annual income before tax?"], [2, "frequencyCd", "", "How often will you make your contribution?"], [0, "targetFundAmt", isNumeric, "How much would you like your target fund to be at retirement?"], [2, "indexation", "", "Do you want your contributions to increase with inflation?"] ); var select = new Array( [2, "quickQuoteId", "", "Please select a quote."] ); //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Window functions function openWindow() { popupWin = window.open('http://www.irishlife.ie/retail/services/tip.jsp', 'remote', 'dependent,width=300,height=100, left=450,top=300') } function closeWindow() { if(navigator.userAgent.indexOf("Firefox")!=-1) { window.open('','_parent',''); } window.close(); } function openWindow(page_loc, width, height, isPrintable, hasScroll) { var printMenu = 0; var scroll = 0; if(isPrintable == true) printMenu = 1; else printMenu = 0; if(hasScroll == true) scroll = 1; else scroll = 0; var options = "width=" + width + ",height=" + height + ",location=0,menubar=0,scrollbars=" + scroll + ",status=1,titlebar=0,toolbar=" + printMenu + ",resizable=0"; var newWin1 = window.open(page_loc,'new_win',options); } // end function openWindow // Function only used to open a full browser window to display the Find a Financial Advisor page as the current use of target=_blank is no longer // compatibly with the properties.js file function openAdvisor(page_loc) { var options = "width=760,height=500,location=1,menubar=1,scrollbars=1,status=1,titlebar=1,toolbar=1,resizable=1"; var newWin1 = window.open(page_loc,'new_win',options); } // end function openAdvisor function popUpWindow() { window.open('tip.htm','jav','width=300,height=200,resizable=yes'); } function changeToYes(id) { document.getElementById(id).value = "Yes"; } function removeS() { document.getElementById("life_question").innerHTML = "How much do you want your life insured for?"; } function insertS() { document.getElementById("life_question").innerHTML = "How much do you want your lifes insured for?"; } function submitOnce(form) { var theForm = document.forms[form]; for (i=0; i < theForm.length; i++) { var tempobj = theForm.elements[i] if(tempobj.type != null && tempobj.type.toLowerCase() == "button") { tempobj.disabled = true } } return false } function disableSubmit(form) { submitOnce(form); document.forms[form].submit(); } //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // ValidateDOB helper function s function getAge(day,month,year) { now = new Date(); thisDay = now.getDate(); thisMonth = now.getMonth()+1; thisYear = now.getFullYear(); var yearsold = thisYear - year, monthsold = 0, daysold = 0; if (thisMonth >= month) monthsold = thisMonth - month; else { yearsold--; monthsold = thisMonth + 12 - month; } if (thisDay >= day)daysold = thisDay - day; else { if (monthsold > 0) monthsold--; else { yearsold--; monthsold+=11; } daysold = thisDay + 31 - day; } if (yearsold <= 0) return 0; return yearsold; } function isMonth(month) { if(month < 1 || month > 12) { return false; } else { return true; } } function isDay(day) { if(day < 1 || day > 31) { return false; } else { return true; } } function daysInFeb (year) { return ( ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) )) ? 29 : 28 ); } function daysInMonth(n) { var val = 31; if (n==4 || n==6 || n==9 || n==11) {val = 30} if (n==2) {val = 29} return parseInt(val); } function isDate (day, month, year) { if ( isDay(day) == false || isMonth(month) == false) return false; var intYear = parseInt(year); var intMonth = parseInt(month); var intDay = parseInt(day); if (intDay > daysInMonth(intMonth)) return false; if ((intMonth == 2) && (intDay > daysInFeb(intYear))) return false; return true; } //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Onkeydown disabling keys functions function isAlpha(isa) { return reAlpha.test(isa) } function isEmail(ise) { return (ise == null || reEmail.test(ise)); } function isNumeric(isn) { return reInteger.test(isn); } function isAlphaNumeric(isan) { return reAlphaNumeric.test(isan); } function disableNumbers(event) { var keynum var keychar if(window.event) // IE { keynum = event.keyCode } else if(event.which) // netscape/Firefox/opera { keynum = event.which } if(keynum != 37 && keynum != 38 && keynum != 39 && keynum != 40 && keynum != 46 && keynum != 192) { keychar = String.fromCharCode(keynum) return isAlpha(keychar) } } function disableLetters(e) { var keynum; var keychar; if(window.event) // IE { keynum = e.keyCode; } else if(e.which) // netscape/Firefox/opera { keynum = e.which; } if(keynum != 37 && keynum != 38 && keynum != 39 && keynum != 40 && keynum != 46 && keynum != 96 && keynum != 97 && keynum != 98 && keynum != 99 && keynum != 100 && keynum != 101 && keynum != 102 && keynum != 103 && keynum != 104 && keynum != 105) { keychar = String.fromCharCode(keynum); return isNumeric(keychar); } } function disableLettersPhone(e) { var keynum; var keychar; if(window.event) // IE { keynum = e.keyCode; } else if(e.which) // netscape/Firefox/opera { keynum = e.which; } if(keynum != 32 && keynum != 37 && keynum != 38 && keynum != 39 && keynum != 40 && keynum != 46 && keynum != 96 && keynum != 97 && keynum != 98 && keynum != 99 && keynum != 100 && keynum != 101 && keynum != 102 && keynum != 103 && keynum != 104 && keynum != 105 && keynum !=107 && keynum != 109 && keynum != 16 && keynum != 187 && keynum != 189 && keynum != 190 && keynum != 222) { keychar = String.fromCharCode(keynum); return isNumeric(keychar); } } function display(id) { if (document.getElementById(id) != null) { document.getElementById(id).style.display = ''; } } function hide(id) { document.getElementById(id).style.display = 'none'; } function checkRadio(name, i, id) { document.forms[0].elements[name][i].checked=true; } function disableField(name) { document.forms[0].elements[name].disabled=true; document.forms[0].elements[name].value=""; } function enableField(name) { document.forms[0].elements[name].disabled=false; } function focusOn(name) { document.forms[0].elements[name].focus(); } function focusOnRadio(name) { document.forms[0].elements[name][0].focus(); } //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Onblur validation function s function validateString(vs_value, test_type) { if(vs_value == "") { return false; } else if(test_type(vs_value) == false) { return false; } else { return true; } } function validateDOB(day, month, year) { if(day == "" || month == "" || year == "") { return false; } else if( isNumeric(day) == false || isNumeric(month) == false || isNumeric(year) == false || isDate(day, month, year) == false || getAge(day, month, year) < 12 || getAge(day, month, year) > 200) { return false; } else { // Needs to be set to check if the term is valid age = getAge(day, month, year); return true; } } //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // Validate all funcion function validateAllFields() { var message = "Please correct the following form field:\n\n" var error = 0; var i = -1; for(i = 0; error != 1 && i < fields.length; i++) { switch(fields[i][0]) { case 0: if (validateString(document.forms[0].elements[fields[i][1]].value, fields[i][2], fields[i][3]) == false) { message += fields[i][3]; error = 1; } break; case 1: if (validateDOB(document.forms[0].elements[fields[i][1]].value, document.forms[0].elements[fields[i][2]].value, document.forms[0].elements[fields[i][3]].value, fields[i][4]) == false) { message += "What is your date of birth?"; error = 1; } break; case 2: // Radio 2 button validation. Finds out how many radio buttons there are first var radioButtons = document.getElementsByName(fields[i][1]); var buttonChecked = false; for(var j = 0; j < radioButtons.length; j++) { if(document.forms[0].elements[fields[i][1]][j].checked == true) { buttonChecked = true; } } if(buttonChecked == false) { message += fields[i][3]; error = 1; } break; case 3: // Joint life validation. If this is true, then need to perform validation on 2nd person details if ( document.forms[0].elements["jointLife"][0].checked == true ) { i = fields.length; } break; case 4: // sicCoverAmt validation. If coverTypeCd is L, then we don't need to validate sicCoverAmt. If it's LSA, then we do. if ( document.forms[0].elements["coverTypeCd"][1].checked == true ) { if (validateString(document.forms[0].elements[fields[i][1]].value, fields[i][2], fields[i][3]) == false) { message += fields[i][3]; error = 1; } } break; default: } } if(error == 1) { alert(message); if(fields[i-1][0] != 2) { document.forms[0].elements[fields[i-1][1]].focus(); } else { document.forms[0].elements[fields[i-1][1]][0].focus(); } return false; } else { return true; } } function submitform(formType) { if(formType == "changeAddress") fields = changeAddressFields; else if(formType == "correct_name") fields = correctNameFields; else if(formType == "generalEnquiry") fields = generalEnquiryFields; else if(formType == "feedback") fields = feedbackFields; else if(formType == "financialReview") fields = financialReviewFields; else if(formType == "pensionReview") fields = pensionReviewFields; else if(formType == "quickQuote") fields = quickQuoteFields; else if(formType == "planValue") fields = planValueFields; else if(formType == "life_term_amount") fields = lifeTermAmountFields; else if(formType == "lifeTermSum") fields = lifeTermSumFields; else if(formType == "lifeMortgage") fields = lifeMortgageFields; else if(formType == "savingsAmount") fields = savingsAmount; else if(formType == "savingsFund") fields = savingsFund; else if(formType == "pensionSalary") fields = pensionSalary; else if(formType == "pensionFund") fields = pensionFund; else if(formType == "select") fields = select; if(validateAllFields() == true) { submitOnce(0); document.forms[0].submit(); } } function navigate(url, divId, pageNo, items) { parms='pageNo=' + pageNo + 'items='+items; executeAjaxRequest(url, divId, parms); } /***************************************************** * * AJAX functions * * The following three functions are a basic implementation of AJAX. * To use call executeAjaxRequest with the following parameters: * url: the url to use, i.e., the httprequest * divId: the name of the div tag on the page where the * response html is to be inserted. ******************************************************/ var req; var waitDivName; var responseDivName; /* This function loads the client association details * into the divId panel. It calls functions located in javascript_functions.js. * */ function executeAjaxRequest(url, divId, parms) { waitDivName = divId+'Wait'; responseDivName = divId+'Response'; document.getElementById(responseDivName).style.display='none'; document.getElementById(waitDivName).style.display='block'; var callback = processAjaxResponse; executeXhr(callback, url, parms); } function executeXhr(callback, url, parms) { // branch for native XMLHttpRequest object if (window.XMLHttpRequest) { req = new XMLHttpRequest(); req.onreadystatechange = callback; req.open("POST", url, true); req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); req.send(parms); } // branch for IE/Windows ActiveX version else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); if (req) { req.onreadystatechange = callback; req.open("POST", url, true); req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); req.send(parms); } } } function processAjaxResponse() { // only if req shows "loaded" if (req.readyState == 4) { // only if "OK" if (req.status == 200) { document.getElementById(responseDivName).innerHTML = req.responseText; } else { document.getElementById(responseDivName).innerHTML = '
Could not retrieve data.