var INDEPENDENT = 1; var INDEPENDENT_AGRARIAN = 5; var ALAVA_ID = 3; var GUIPUZCOA_ID = 4; var VIZCAYA_ID = 5; var NAVARRA_ID = 2; var PROVINCE_ALAVA_ID = 1; var PROVINCE_GUIPUZCOA_ID = 20; var PROVINCE_VIZCAYA_ID = 48; var MALE = 0; var FEMALE = 1; var SUGGESTED_QUOTATION = 0.306; var SUGGESTED_QUOTATION_AGRARIAN_1 = 0.1875; var SUGGESTED_QUOTATION_AGRARIAN_2 = 0.2650; var SUGGESTED_QUOTATION_AGRARIAN_1ST_TRANCHE = 1050.90 * 12.0; var SUGGESTED_OVER_50_MIN = 0; var SUGGESTED_OVER_50_MAX = 0; var SUGGESTED_LESS_THAN_50_MIN = 0; var SUGGESTED_LESS_THAN_50_MAX = 0; var prefix = "userData_"; var prefix2 = "userData$"; function UpdateQuotationLimits(less50Min, less50Max, over50Min, over50Max) { SUGGESTED_OVER_50_MIN = over50Min; SUGGESTED_OVER_50_MAX = over50Max; SUGGESTED_LESS_THAN_50_MIN = less50Min; SUGGESTED_LESS_THAN_50_MAX = less50Max; } function ChangeQuotationRegime() { var sel = document.getElementById(prefix + "SelectQuotationRegime"); var val = sel.options[sel.selectedIndex].value; var sal = document.getElementById(prefix + 'TextSalary'); var ecAct = document.getElementById(prefix + 'TextEconomicActivities'); if (val == INDEPENDENT || val == INDEPENDENT_AGRARIAN) { document.getElementById(prefix + 'spanQuotation').style.display = ""; document.getElementById(prefix + 'spanQuotationGroup').style.display = "none"; if (parseFloat(sal.value) > 0 && parseFloat(ecAct.value) <= 0) { var tmp = ecAct.value; ecAct.value = sal.value; sal.value = tmp; } userData_CompareValidatorSalary.operator = "GreaterThanEqual"; userData_ComparevalidatorEconomicActivities.operator = "GreaterThan"; ValidatorValidate(userData_CompareValidatorSalary); ValidatorValidate(userData_ComparevalidatorEconomicActivities); FillQuotation(); } else { if (parseFloat(ecAct.value) > 0 && parseFloat(sal.value) <= 0) { var tmp = sal.value; sal.value = ecAct.value; ecAct.value = tmp; } userData_CompareValidatorSalary.operator = "GreaterThan"; userData_ComparevalidatorEconomicActivities.operator = "GreaterThanEqual"; ValidatorValidate(userData_CompareValidatorSalary); ValidatorValidate(userData_ComparevalidatorEconomicActivities); document.getElementById(prefix + 'spanQuotation').style.display = "none"; document.getElementById(prefix + 'spanQuotationGroup').style.display = ""; } } function CheckQuotationVisibility() { var sel = document.getElementById(prefix + "SelectQuotationRegime"); var val = sel.options[sel.selectedIndex].value; if (val == INDEPENDENT || val == INDEPENDENT_AGRARIAN) { document.getElementById(prefix + 'spanQuotation').style.display = ""; document.getElementById(prefix + 'spanQuotationGroup').style.display = "none"; } else { document.getElementById(prefix + 'spanQuotation').style.display = "none"; document.getElementById(prefix + 'spanQuotationGroup').style.display = ""; } } function QuotationRegimeChanged() { var obj; var sal = document.getElementById(prefix + 'TextSalary'); var ecAct = document.getElementById(prefix + 'TextEconomicActivities'); obj = document.getElementById(prefix + 'lstRetirementAge'); obj.selectedIndex = 0; obj.onchange(); var sel = document.getElementById(prefix + "SelectQuotationRegime"); var val = sel.options[sel.selectedIndex].value; if (val == INDEPENDENT || val == INDEPENDENT_AGRARIAN) { userData_CustomValidatorQuotation.enabled = true; document.getElementById(prefix + 'spanQuotation').style.display = ""; document.getElementById(prefix + 'spanQuotationGroup').style.display = "none"; if (parseFloat(sal.value) > 0 && parseFloat(ecAct.value) <= 0) { var tmp = ecAct.value; ecAct.value = sal.value; sal.value = tmp; } userData_CompareValidatorSalary.operator = "GreaterThanEqual"; userData_ComparevalidatorEconomicActivities.operator = "GreaterThan"; ValidatorValidate(userData_CompareValidatorSalary); ValidatorValidate(userData_ComparevalidatorEconomicActivities); FillQuotation(); } else { if (parseFloat(ecAct.value) > 0 && parseFloat(sal.value) <= 0) { var tmp = sal.value; sal.value = ecAct.value; ecAct.value = tmp; } userData_CompareValidatorSalary.operator = "GreaterThan"; userData_ComparevalidatorEconomicActivities.operator = "GreaterThanEqual"; ValidatorValidate(userData_CompareValidatorSalary); ValidatorValidate(userData_ComparevalidatorEconomicActivities); FillQuotation(); userData_CustomValidatorQuotation.isvalid = true; ValidatorUpdateDisplay(userData_CustomValidatorQuotation); userData_CustomValidatorQuotation.enabled = false; document.getElementById(prefix + 'spanQuotation').style.display = "none"; document.getElementById(prefix + 'spanQuotationGroup').style.display = ""; document.getElementById(prefix + 'TextQuotation').value = ""; } } function checkVar(what) { } function FnUseProvinces() { var exists = false; try { exists = Boolean(typeof UseProvinces != 'undefined' && UseProvinces); } catch (e) { exists = false; } if (exists) { return UseProvinces; } else { return false; } } function changeResidence(lst) { var id = parseInt(lst.options[lst.selectedIndex].value); if ( (!FnUseProvinces() && (id == ALAVA_ID || id == GUIPUZCOA_ID || id == VIZCAYA_ID)) || (FnUseProvinces() && (id == PROVINCE_ALAVA_ID || id == PROVINCE_GUIPUZCOA_ID || id == PROVINCE_VIZCAYA_ID)) ) { document.getElementById(prefix + 'spanProductType').style.display = ""; } else { document.getElementById(prefix + 'spanProductType').style.display = "none"; document.getElementById(prefix + 'SelectProductType').selectedIndex = 0; } } function ClientValidateQuotation(source, arguments) { if (!userData_CustomValidatorQuotation.enabled) { arguments.IsValid = true; return; } arguments.IsValid = false; ValidatorValidate(userData_RequiredFieldValidatorBirthday); if (!userData_RequiredFieldValidatorBirthday.isvalid) { document.getElementById(prefix + 'TIFCalendarBirthday').select(); arguments.IsValid = true; return; } ValidatorValidate(userData_CompareValidatorBirthday); if (!userData_CompareValidatorBirthday.isvalid) { document.getElementById(prefix + 'TIFCalendarBirthday').select(); arguments.IsValid = true; return; } ValidatorValidate(userData_RangeAgeValidator); if (!userData_RangeAgeValidator.isvalid) { document.getElementById(prefix + 'TIFCalendarBirthday').select(); arguments.IsValid = true; return; } ValidatorValidate(userData_CompareValidatorQuotation); if (!userData_CompareValidatorQuotation.isvalid) { document.getElementById(prefix + 'TextQuotation').select(); arguments.IsValid = true; return; } var currentYear = new Date().getFullYear(); var birthdayDate = string2fecha(document.getElementById(prefix + 'TIFCalendarBirthday').value); var birthday = birthdayDate.getFullYear(); var age = currentYear - birthday; var quotation = parseInt(formatoEscritura(document.getElementById(prefix + 'TextQuotation').value, tifdsep, tiftsep, 0)); var index; try { if (document.getElementsByName(prefix2 + "SelectSex")[1].checked) { index = MALE; } else { index = FEMALE; } } catch (e) { index = document.getElementsByName(prefix2 + "SelectSex")[0].value; } if (age >= 0 && age <= 49) { if (quotation >= SUGGESTED_LESS_THAN_50_MIN && quotation <= SUGGESTED_LESS_THAN_50_MAX) { arguments.IsValid = true; } else { // We permit that the number are formatted according to the regional configuration. userData_CustomValidatorQuotation.errormessage = 'Dato incorrecto:
La cotización debe estar entre ' + formatoLectura(String(SUGGESTED_LESS_THAN_50_MIN), tifdsep, tiftsep, 0) + ' y ' + formatoLectura(String(SUGGESTED_LESS_THAN_50_MAX), tifdsep, tiftsep, 0); userData_CustomValidatorQuotation.innerHTML = "
" + userData_CustomValidatorQuotation.errormessage + "
"; document.getElementById(prefix + 'TextQuotation').select(); arguments.IsValid = false; } return; } else if (age >= 50) { if (quotation >= SUGGESTED_OVER_50_MIN && quotation <= SUGGESTED_OVER_50_MAX) { arguments.IsValid = true; } else { userData_CustomValidatorQuotation.errormessage = 'Dato incorrecto:
La cotización debe estar entre ' + formatoLectura(String(SUGGESTED_OVER_50_MIN), tifdsep, tiftsep, 0) + ' y ' + formatoLectura(String(SUGGESTED_OVER_50_MAX), tifdsep, tiftsep, 0); userData_CustomValidatorQuotation.innerHTML = "
" + userData_CustomValidatorQuotation.errormessage + "
"; document.getElementById(prefix + 'TextQuotation').select(); arguments.IsValid = false; } return; } arguments.IsValid = false; return; } function CalculateAge(calendar) { var currentYear = new Date().getFullYear(); var calendarDate = string2fecha(calendar); var age = currentYear - calendarDate.getFullYear(); return age; } function FillQuotation() { var age; var quotation; var salary; var obj; ValidatorValidate(userData_RequiredFieldValidatorBirthday); if (!userData_RequiredFieldValidatorBirthday.isvalid) { document.getElementById(prefix + 'TIFCalendarBirthday').select(); arguments.IsValid = true; return; } ValidatorValidate(userData_CompareValidatorBirthday); if (!userData_CompareValidatorBirthday.isvalid) { document.getElementById(prefix + 'TIFCalendarBirthday').select(); arguments.IsValid = true; return; } ValidatorValidate(userData_RangeAgeValidator); if (!userData_RangeAgeValidator.isvalid) { document.getElementById(prefix + 'TIFCalendarBirthday').select(); arguments.IsValid = true; return; } salary = parseFloat(formatoEscritura(document.getElementById(prefix + 'TextEconomicActivities').value, tifdsep, tiftsep, 0)); var sel = document.getElementById(prefix + "SelectQuotationRegime"); var qr = parseInt(sel.options[sel.selectedIndex].value); if (qr == INDEPENDENT_AGRARIAN) { quotation = (Math.min(SUGGESTED_QUOTATION_AGRARIAN_1ST_TRANCHE, salary) * SUGGESTED_QUOTATION_AGRARIAN_1) + (Math.max(salary - SUGGESTED_QUOTATION_AGRARIAN_1ST_TRANCHE, 0) * SUGGESTED_QUOTATION_AGRARIAN_2); } else { quotation = salary * SUGGESTED_QUOTATION; } obj = document.getElementById(prefix + 'TextQuotation'); obj.value = formatoLectura(String(parseInt(quotation)), tifdsep, tiftsep, 0); age = CalculateAge(document.getElementById(prefix + 'TIFCalendarBirthday').value); var index; try { if (document.getElementsByName(prefix2 + "SelectSex")[1].checked) { index = MALE; } else { index = FEMALE; } } catch (e) { index = document.getElementsByName(prefix2 + "SelectSex")[0].value; } if (age >= 0 && age <= 49) { obj.value = String(parseInt(Math.max(Math.min(quotation, SUGGESTED_LESS_THAN_50_MAX), SUGGESTED_LESS_THAN_50_MIN))); obj.value = formatoLectura(obj.value, tifdsep, tiftsep, 0); ValidatorValidate(userData_CustomValidatorQuotation); return; } else if (age >= 50) { obj.value = String(parseInt(Math.max(Math.min(quotation, SUGGESTED_OVER_50_MAX), SUGGESTED_OVER_50_MIN))); obj.value = formatoLectura(obj.value, tifdsep, tiftsep, 0); ValidatorValidate(userData_CustomValidatorQuotation); return; } arguments.IsValid = false; return; } function BlurBirthday() { if (document.getElementById(prefix + 'TIFCalendarBirthday').value != "") { if (document.getElementById(prefix + 'TextQuotation').value != "") { if (userData_CustomValidatorQuotation.enabled) { ValidatorValidate(userData_CustomValidatorQuotation); } } else { BlurSalary(); } } } function BlurSex() { if (userData_CustomValidatorQuotation.enabled) { ValidatorValidate(userData_CustomValidatorQuotation); } } function BlurSalary() { if ((document.getElementById(prefix + 'TextEconomicActivities').value != "") && (document.getElementById(prefix + 'spanQuotation').style.display == "")) { FillQuotation(); } } function ShowFirstDescendant() { var i; var obj; for (i = 1; i <= 10; i++) { obj = document.getElementById(prefix + 'Desc' + i + '_Fila'); if (obj.style.display == 'none') { obj.style.display = ''; obj = document.getElementById(prefix + 'Desc' + i + '_TextBoxAge'); obj.focus(); break; } } } function OccultDescendant(index) { var obj; obj = document.getElementById(prefix + 'Desc' + index + '_TextBoxAge'); obj.value = ''; obj = document.getElementById(prefix + 'Desc' + index + '_DropdownlistIncapacity'); obj.selectedIndex = 0; obj = document.getElementById(prefix + 'Desc' + index + '_Fila'); obj.style.display = 'none'; var numVisibles = 0 for (i = 1; i <= 10; i++) { obj = document.getElementById(prefix + 'Desc' + i + '_Fila'); if (obj.style.display != 'none') { numVisibles++; } } if (numVisibles == 0) { document.getElementById(prefix + 'cntDesc').style.display = 'none'; document.getElementById(prefix + 'DropdownlistDesc').selectedIndex = 0; } } function ChangeDesc(index) { if (index == 0) { var i; for (i = 1; i <= 10; i++) { OccultDescendant(i); } document.getElementById(prefix + 'cntDesc').style.display = 'none'; } else { document.getElementById(prefix + 'cntDesc').style.display = ''; ShowFirstDescendant(); } } function ShowFirstAscendant() { var i; var obj; for (i = 1; i <= 10; i++) { obj = document.getElementById(prefix + 'Asc' + i + '_Fila'); if (obj.style.display == 'none') { obj.style.display = ''; obj = document.getElementById(prefix + 'Asc' + i + '_TextBoxAge'); obj.focus(); break; } } } function OccultAscendant(index) { var obj; obj = document.getElementById(prefix + 'Asc' + index + '_TextBoxAge'); obj.value = ''; obj = document.getElementById(prefix + 'Asc' + index + '_DropdownlistIncapacity'); obj.selectedIndex = 0; obj = document.getElementById(prefix + 'Asc' + index + '_Fila'); obj.style.display = 'none'; var numVisibles = 0 for (i = 1; i <= 10; i++) { obj = document.getElementById(prefix + 'Asc' + i + '_Fila'); if (obj.style.display != 'none') { numVisibles++; } } if (numVisibles == 0) { document.getElementById(prefix + 'cntAsc').style.display = 'none'; document.getElementById(prefix + 'DropdownlistAsc').selectedIndex = 0; } } function ChangeAsc(index) { if (index == 0) { var i; for (i = 1; i <= 10; i++) { OccultAscendant(i); } document.getElementById(prefix + 'cntAsc').style.display = 'none'; } else { document.getElementById(prefix + 'cntAsc').style.display = ''; ShowFirstAscendant(); } } function SendNewProfile() { var Q1 = document.getElementById("SelectId1").options[document.getElementById("SelectId1").selectedIndex].value; var Q2 = document.getElementById("SelectId2").options[document.getElementById("SelectId2").selectedIndex].value; var Q3 = document.getElementById("SelectId3").options[document.getElementById("SelectId3").selectedIndex].value; var M1 = 0; var M2 = 0; var M3 = 0; var M4 = 0; if (Q1 == "0") { SelectProfile(0); //Garantizado return; } else { switch (Q1) { case "1": M1++; break; case "2": M2++; break; case "3": M3++; break; case "4": M4++; break; default: break; } switch (Q2) { case "1": M1++; break; case "2": M2++; break; case "3": M3++; break; case "4": M4++; break; default: break; } switch (Q3) { case "1": M1++; break; case "2": M2++; break; case "3": M3++; break; case "4": M4++; break; default: break; } if (M1 == 3 || M1 == 2) { SelectProfile(1); return; } else if (M2 == 3 || M2 == 2) { SelectProfile(2); return; } else if (M3 == 3 || M3 == 2) { SelectProfile(3); return; } else if (M4 == 3 || M4 == 2) { if (RecommendedProductsByAge) { SelectProfile(3); } else { SelectProfile(4); } return; } } SetProfileFromBirthdayAndRetirementDate(); } function SetProfileFromBirthdayAndRetirementDate() { var currentYear = new Date().getFullYear(); var birthday = document.getElementById(prefix + "TIFCalendarBirthday").value; var retirementAge = document.getElementById(prefix + "lstRetirementAge").value; var retirementYear = string2fecha(birthday).getFullYear() + parseInt(retirementAge); var yearsToRetirement = retirementYear - currentYear; var age = currentYear - string2fecha(birthday).getFullYear(); if (age < 31) { SelectProfile(5); //Agresivo } else if (age < 40) { SelectProfile(4); //Dinamico } else if (age < 50) { SelectProfile(3); //Moderado } else if (age < 60) { SelectProfile(2); //Conservador } else { SelectProfile(1); //Defensivo } } /* function SetProfileFromBirthdayAndRetirementDateRiskAppetive() { var currentYear = new Date().getFullYear(); var birthday = document.getElementById(prefix + "TIFCalendarBirthday").value; var retirementAge = document.getElementById(prefix + "lstRetirementAge").value; var retirementYear = string2fecha(birthday).getFullYear() + parseInt(retirementAge); var yearsToRetirement = retirementYear - currentYear; var age = currentYear - string2fecha(birthday).getFullYear(); var riskAppetite = document.getElementById(prefix + "SelectRiskAppetite").value; if (age > 50 && riskAppetite == 0) { SelectProfile(1); //Defensivo } else if ((age < 51 && riskAppetite == 0) || (age > 50 && riskAppetite == 2) || (age > 40 && riskAppetite == 1)) { SelectProfile(2); //Conservador } else if ((age < 41 && riskAppetite == 1) || (age > 30 && age < 51 && riskAppetite == 2) || (age > 50 && riskAppetite == 3) || (age > 60 && riskAppetite == 4)) { SelectProfile(3); //Moderado } else if ((age < 31 && riskAppetite == 2) || (age < 51 && riskAppetite == 3) || (age > 50 && age < 61 && riskAppetite == 4)) { SelectProfile(4); //Dinamico } else { SelectProfile(5); //Agresivo } var ArrayOfInputs = document.getElementsByTagName("input"); for (var z = 0; z < ArrayOfInputs.length; z++) { if (ArrayOfInputs[z].type != "submit") { if (ArrayOfInputs[z].addEventListener) { ArrayOfInputs[z].addEventListener('blur', PrefnOnUpdateValidators, false); } else { ArrayOfInputs[z].attachEvent('onblur', PrefnOnUpdateValidators); } } } }*/ function SelectOptionWithValue(select, value) { var i; for (i = 0; i < select.length; i++) { if (select.options[i].value == value) { select.selectedIndex = i; break; } } } function SelectProfile(i) { SelectOptionWithValue(document.getElementById(prefix + "SelectProfile"), i); } function MarriedChange() { var lstMarried = document.getElementById(prefix + 'SelectMarried'); var married = (parseInt(lstMarried.options[lstMarried.selectedIndex].value) == 1); var divAge = document.getElementById(prefix + "pnPartnerAge"); if (married) { divAge.style.display = ""; userData_RequiredFieldValidatorPartnerBirthday.enabled = true; } else { divAge.style.display = "none"; userData_RequiredFieldValidatorPartnerBirthday.enabled = false; } }