var validator = new function () {
/*Output functions*/
this.isValid = new function () {
this.socialSecNo = function (countryCode, socialSecNo) {
switch (countryCode.toUpperCase()) {
case 'FIN':
case 'FI':
return validator.isValidFinSocialSecNo(socialSecNo);
break;
case 'SWE':
case 'SE':
if (socialSecNo.length == 10) {
//Lisätään (-) merkki, koska tarkastaja vaatii sen
socialSecNo = socialSecNo.substr(0, 6) + '-' + socialSecNo.substr(6, 10);
}
return validator.isValidSweSocialSecNo(socialSecNo);
break;
default :
return true;
break;
}
};
this.date = function (str) {
var tmp = str.split('-');
var day = tmp[2];
var month = tmp[1];
var year = tmp[0];
if ((month=='04' || month=='06' || month=='09' || month==11) && day==31) {
return false;
}
if (month == '02') { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (parseInt(day)>29 || (parseInt(day)==29 && !isleap)) {
return false;
}
}
var date = new Date(year, month, day);
return !(isNaN(date));
};
this.IBAN = function (fieldName) {
// xjaxissa tehdään tarkastus ja asetetaan cookie 1:ksi, jos on tilinumero on
// IBAN
if (GetCookie(fieldName + '_is_IBAN') == '1') {
return true;
}
return false;
};
this.AccountNumber = function (countryCode, AccountNum) {
switch (countryCode.toUpperCase()) {
case 'FI':
case 'FIN':
return validator.isValidFinAccountNum(AccountNum);
break;
case 'SE':
case 'SWE':
return validator.isValidSweAccountNum(AccountNum);
break;
default :
return true;
break;
}
};
};
/*Inside functions*/
this.isValidFinSocialFormat = function(str){
if ((str.length != 10) && (str.length != 11) || (str.substring(6,7) != '-') && (str.substring(6,7) != '+') && (str.substring(6,7) != 'A')){
return false;
}
return true;
};
this.isValidFinSocialSecNo = function(num){
if (this.isValidFinSocialFormat(num)){
var variable = num.substring(0,6) + num.substring(7,10);
var lastLetter = num.substring(10,11);
var row = "0123456789ABCDEFHJKLMNPRSTUVWXY";
var checkLetter = row.substring(variable % 31, variable % 31 +1);
if (lastLetter == '') {
return false;
}else {
if (lastLetter == checkLetter)
return true;
else
return false;
}
}
return false;
};
this.isValidSweSocialSecNo = function (num) {
if(new SwePersonNummer(num).valid){
return true;
}else{
return false;
}
};
this.isValidSweAccountNum = function (Accountnum) {
var ref;
var ref_chr;
var clearing;
/*
*
* Accountnum = StripSpacesStr(Accountnum); Accountnum = DelChars(Accountnum,
* '-'); Accountnum = trim(Accountnum);
*/
while ( Accountnum.indexOf(" ") > 0 ) {
Accountnum = Accountnum.replace(/ /,"");
}
while ( Accountnum.indexOf("-") > 0 ) {
Accountnum = Accountnum.replace(/-/,"");
}
if ( Accountnum != '' )
{
Clearing = Accountnum.substr(0, 4);
ref_chr = Accountnum.charAt(Accountnum.length-1);
if (
((Clearing >= '9090') && (Clearing <= '9099')) ||
((Clearing >= '9040') && (Clearing <= '9049')) ||
((Clearing >= '9190') && (Clearing <= '9199')) ||
((Clearing >= '2300') && (Clearing <= '2399')) ||
((Clearing >= '9020') && (Clearing <= '9029')) ||
((Clearing >= '4000') && (Clearing <= '4999') && (Accountnum.length != 14)) ||
((Clearing >= '9150') && (Clearing <= '9196')) ||
((Clearing >= '9200') && (Clearing <= '9209')) ||
((Clearing >= '9100') && (Clearing <= '9109'))||
((Clearing >= '9550') && (Clearing <= '9569'))
)
{
ref = Accountnum.substr(0,Accountnum.length-1);
// Ref := copy(Accountnum, 1, Length(Accountnum));
return (mod11_chknum(ref) == ref_chr);
} else {
if ( ((Clearing >= '1200') && (Clearing <= '1399')) ||
((Clearing >= '9260') && (Clearing <= '9269')) ||
((Clearing >= '7000') && (Clearing <= '7999')) ||
((Clearing >= '9270') && (Clearing <= '9279')) ||
((Clearing >= '9170') && (Clearing <= '9179')) ||
((Clearing >= '3400') && (Clearing <= '3409')) ||
((Clearing >= '9060') && (Clearing <= '9069')) ||
((Clearing >= '1100') && (Clearing <= '1199') && (Accountnum.length != 14)) ||
((Clearing >= '1400') && (Clearing <= '2099') && (Accountnum.length != 14)) ||
((Clearing >= '3000') && (Clearing <= '3399') && (Accountnum.length != 14)) ||
((Clearing >= '3410') && (Clearing <= '3999') && (Accountnum.length != 14)) ||
((Clearing >= '9230') && (Clearing <= '9239')) ||
((Clearing >= '5000') && (Clearing <= '5999')) ||
((Clearing >= '9400') && (Clearing <= '9449')) ||
((Clearing >= '9460') && (Clearing <= '9469')) ||
((Clearing >= '9280') && (Clearing <= '9289')) ||
((Clearing >= '9250') && (Clearing <= '9259')) ||
((Clearing >= '9120') && (Clearing <= '9124')) ||
((Clearing >= '9130') && (Clearing <= '9149')) ||
((Clearing >= '9050') && (Clearing <= '9059'))
)
{
ref = Accountnum.substr(1, Accountnum.length-2);
return (mod11_chknum(ref) == ref_chr);
/*
* ref := copy(Accountnum, 2, Length(Accountnum) - 1); if (mod11_chknum(ref) =
* ref_chr) Then Result := True;
*/
} else
if (
((Clearing >= '3300') && (Clearing <= '3300') && (Accountnum.length == 14)) ||
((Clearing >= '4000') && (Clearing <= '4999') && (Accountnum.length == 14)) ||
((Clearing >= '1100') && (Clearing <= '1199') && (Accountnum.length == 14)) ||
((Clearing >= '1400') && (Clearing <= '2099') && (Accountnum.length == 14)) ||
((Clearing >= '3000') && (Clearing <= '3399') && (Accountnum.length == 14)) ||
((Clearing >= '3410') && (Clearing <= '3999') && (Accountnum.length == 14))
)
{
ref = Accountnum.substr(Accountnum.length-10, 9);
return (mod10_chknum(ref) == ref_chr);
/*
* ref := copy(Accountnum, Accountnum.length - 9, 10); if (mod10_chknum(ref) =
* ref_chr) The Result := True;
*/
} else
if ( ((Clearing >= '6000') && (Clearing <= '6999')) )
{
ref = Accountnum.substr(Accountnum.length-9, 8);
return (mod11_chknum(ref) == ref_chr);
/*
* ref := copy(Accountnum, Length(Accountnum) - 8, 9); if (mod11_chknum(ref) =
* ref_chr) Then Result := True;
*/
} else
if ( ((Clearing >= '9500') && (Clearing <= '9549')) ||
((Clearing >= '9960') && (Clearing <= '9969')) )
{
ref = Accountnum.substr(4, Accountnum.length-5);
return (mod10_chknum(ref) == ref_chr);
/*
* ref := copy(Accountnum, 5, Length(Accountnum) - 4); if
* (swe_mod10_chknum(ref) = ref_chr) Then Result := True;
*/
} else
if ( ((Clearing >= '8000') && (Clearing <= '8999'))) {
ref = Accountnum.substr(4, Accountnum.length-5);
return (mod10_chknum(ref) == ref_chr);
/*
* ref := copy(Accountnum, 5, Length(Accountnum) - 4); if
* (swe_mod10_chknum(ref) = ref_chr) Then Result := True;
*/
} else
if ( ((Clearing >= '9180') && (Clearing <= '9189')) ||
((Clearing >= '9300') && (Clearing <= '9329')) ||
((Clearing >= '9330') && (Clearing <= '9349')) ||
((Clearing >= '9570') && (Clearing <= '9579'))
)
{
ref = Accountnum.substr(4, Accountnum.length-5);
return (mod10_chknum(ref) == ref_chr);
/*
* ref := copy(Accountnum, 5, Length(Accountnum) - 4); if
* (swe_mod10_chknum(ref) = ref_chr) Then Result := True;
*/
}
}
}
return ( false );
};
this.isValidFinAccountNum = function (ref) {
var ref_chr;
if (ref != '') {
ref_chr = ref.charAt(ref.length-1);
ref = Set14chr(ref);
// Ei saa olla yli 14 merkkiä
if (ref.length > 14) {
return false;
}
if (mod10_chknum(ref) == ref_chr)
return true;
}
return false;
};
};
function SwePersonNummer(nr){
this.valid=false;
if(!nr.match(/^(\d2)(\d2)(\d2)\-(\d4)$/)){ return false; }
this.now=new Date(); this.nowFullYear=this.now.getFullYear()+""; this.nowCentury=this.nowFullYear.substring(0,2); this.nowShortYear=this.nowFullYear.substring(2,4);
this.year=RegExp.$1; this.month=RegExp.$2; this.day=RegExp.$3; this.controldigits=RegExp.$4;
this.fullYear=(this.year*1<=this.nowShortYear*1)?(this.nowCentury+this.year)*1:((this.nowCentury*1-1)+this.year)*1;
var months = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
if(this.fullYear%400==0||this.fullYear%4==0&&this.fullYear%100!=0){ months[1]=29; }
if(this.month*1<1||this.month*1>12||this.day*1<1||this.day*1>months[this.month*1-1]){ return false; }
this.alldigits=this.year+this.month+this.day+this.controldigits;
var nn="";
for(var n=0;n0; cnt--){
digit = weight * (str.charAt(cnt-1));
/* add tens digit to ones digit to the sum */
sum = sum + Math.floor(digit / 10) + (digit % 10);
weight=weight==2?1:2;
}
/* subtract ones digit of the sum from 10 return ones digit of result */
var mod = (10-sum%10)%10;
return mod;
}
function Set14chr(s){
var part1, part2, part3, InsertPos, substr, i;
if (s != '') {
s = StripSignStr(s);
InsertPos = 6;
if ((s.substr(0,1) == '4') || (s.substr(0,1) == '5') )
InsertPos = 7;
subStr = '';
for (i = s.length; i < 14; i++) {
subStr += '0';
}
part1 = s.substr(0, InsertPos);
part2 = s.substr(InsertPos, s.length-1);
return part1+ subStr +part2;
}
}
function StripSignStr(s) {
var nosign, i;
if (s != '') {
nosign = '';
for (i = 0; i < s.length; i++) {
if (s.substr(i,1) != '-') {
nosign = nosign + s.charAt(i) ;
}
}
return nosign;
}
return '';
}
function mod11_chknum( Ref )
{
var Ref_nospace;
var Ref_sum;
var Ref_chk;
var Mod_mult;
var i;
Ref_nospace = StripSpacesStr(Ref);
if ( Ref_nospace != '')
{
Ref_sum = 0;
Mod_mult = 1;
for ( i = Ref_nospace.length-1; i >= 0 ; i--)
{
Mod_mult++;
Mod_mult = (Mod_mult%11);
if ( Mod_mult == 0) Mod_mult = 1;
Ref_sum = Ref_sum + Ref_nospace[i]* Mod_mult;
}
Ref_chk = Ref_sum % 11;
if ( Ref_chk > 1 )
Ref_chk = 11 - Ref_chk;
else Ref_chk = 0;
return ( Ref_chk );
}
return ('');
}
function StripSpacesStr(str)
{
while ( str.indexOf(" ") > 0 ) {
str = str.replace(/ /,"");
}
return ( str );
}
isNextAllowed = true;
SetCookie ('top_view_exists', 0);
SetCookie ('product_view', 'base');
var prevProdCode;
function ValidateForm (currentTabId, countryCode, onlyRequired) {
if (isNextAllowed) {
HideElement ("errorMsg");
var errorMsg = '';
HideAllFieldStatusImages (currentTabId);
var notFilledRequiredFields = CheckRequiredFields (currentTabId);
if (!onlyRequired) {
var notValidFilledFieds = CheckFields (currentTabId, countryCode);
var c = 0;
var confirmErrorMsg = '';
var requiredErrorMsg = '';
}
//Required fields
for (var i in notFilledRequiredFields) {
var elm = document.getElementById(notFilledRequiredFields[i]);
if (elm.title != '') {
if (c == 0) { // First round
errorMsg = errorMsg + 'Täytä seuraavat pakolliset kentät' + ":\n";
}
errorMsg = errorMsg + elm.title + ', ';
c = c + 1;
}else{
requiredErrorMsg = 'Täytä pakolliset kentät' + ".\n";
SetFieldStatusImg (elm.id, 'error');
}
if (elm.type == 'checkbox') {
if (elm.id == 'id_confirm') {
confirmErrorMsg = 'Et voi jatkaa, ellet hyväksy sopimusta' + "\n";
}else{
confirmErrorMsg = 'Vahvistus vaaditaan.' + "\n";
}
}
}
if (c > 0) {
errorMsg = errorMsg.substr(0, errorMsg.length - 2) + "\n\n";
}
if (requiredErrorMsg && errorMsg == '') {
errorMsg = errorMsg + requiredErrorMsg;
}
if (!onlyRequired) {
if (confirmErrorMsg) {
errorMsg = errorMsg + confirmErrorMsg;
}
if (notValidFilledFieds) { // Valid
errorMsg = errorMsg + 'Virhe kentässä/kentissä' + ":\n";
errorMsg = errorMsg + notValidFilledFieds.substr(0, notValidFilledFieds.length - 2) + "\n\n";
}
// Xajax data checks.
if (GetCookie('err_msg_trade_registry_number')) {
errorMsg = errorMsg + GetCookie('err_msg_trade_registry_number') + "\n\n";
SetFieldStatusImg ('id_trade_registry_number', 'error');
}
if (GetCookie('err_msg_social_sec_no')) {
errorMsg = errorMsg + GetCookie('err_msg_social_sec_no') + "\n\n";
SetFieldStatusImg ('id_social_sec_no', 'error');
}
if (GetCookie('err_msg_ssn_under_age')) {
errorMsg = errorMsg + GetCookie('err_msg_ssn_under_age') + "\n\n";
SetFieldStatusImg ('id_social_sec_no', 'error');
}
if (GetCookie('err_msg_birthday_under_age')) {
errorMsg = errorMsg + GetCookie('err_msg_birthday_under_age') + "\n\n";
SetFieldStatusImg ('id_birthday', 'error');
}
if (GetCookie('err_msg_test_mode_email')) {
errorMsg = errorMsg + GetCookie('err_msg_test_mode_email') + "\n\n";
SetFieldStatusImg ('id_email', 'error');
}
if (GetCookie('err_msg_ws_user_email_exists')) {
errorMsg = errorMsg + GetCookie('err_msg_ws_user_email_exists') + "\n\n";
SetFieldStatusImg ('id_email', 'error');
}
if (GetCookie('err_msg_exists_in_rr')) {
errorMsg = errorMsg + GetCookie('err_msg_exists_in_rr') + "\n\n";
SetFieldStatusImg ('id_first_name', 'error');
SetFieldStatusImg ('id_last_name', 'error');
SetFieldStatusImg ('id_email', 'error');
}
if (GetCookie('err_msg_exists_in_rr2')) {
errorMsg = errorMsg + GetCookie('err_msg_exists_in_rr2') + "\n\n";
SetFieldStatusImg ('id_email', 'error');
}
if (GetCookie('err_msg_search_exists')) {
errorMsg = errorMsg + GetCookie('err_msg_search_exists') + "\n\n";
SetFieldStatusImg ('id_search', 'error');
}
if (GetCookie('err_msg_identify_company')) {
errorMsg = errorMsg + GetCookie('err_msg_identify_company') + "\n\n";
SetFieldStatusImg ('id_company_cust_code', 'error');
}
if (GetCookie('err_msg_date_saved')) {
errorMsg = errorMsg + GetCookie('err_msg_date_saved') + "\n\n";
SetFieldStatusImg ('id_date_saved', 'error');
}
if (GetCookie('err_msg_profile_image')) {
errorMsg = errorMsg + GetCookie('err_msg_profile_image') + "\n\n";
SetFieldStatusImg ('id_profile_image', 'error');
}
if (GetCookie('err_msg_prod_buying_not_allowed')) {
errorMsg = errorMsg + GetCookie('err_msg_prod_buying_not_allowed') + "\n\n";
SetFieldStatusImg ('id_rcr_product', 'error');
}
if (GetCookie('err_msg_swe_bank_paynumber_exists')) {
errorMsg = errorMsg + GetCookie('err_msg_swe_bank_paynumber_exists') + "\n\n";
SetFieldStatusImg ('id_swe_bankgiro_paynumber', 'error');
}
}
if (errorMsg) {
ShowErrorMsg (errorMsg, true, '');
return false;
}
return true;
}
}
function GoToNext (countryCode) {
ShowElement('btn_next_dis');
DisableBtn('next');
xajax_XajaxValidateForm(tabsheet.currentTabId, countryCode, xajax.getFormValues('id_frm_dlpm'));
SetButtonsText ('forward');
}
function GoToBack () {
tabsheet.Prev();
BackBtnHandler(1);
SetButtonsText ('back');
}
function BackBtnHandler (criticalTabId) {
if (navigator.appName == 'Microsoft Internet Explorer' || navigator.appName == 'Opera') {
var historyIndex = 0;
}else{
var historyIndex = 1;
}
//myc_login sivulle ei saa palata
if (
(tabsheet.GetTabIndex (tabsheet.currentTabId) == criticalTabId && history.length == historyIndex) ||
(document.referrer.match('func=myc_login') && tabsheet.GetTabIndex (tabsheet.currentTabId) == 0)
) {
//DisableBtn ('back'); //Saa palata.
EnableBtn ('back');
}else{
EnableBtn ('back');
}
}
function DisableBtn (btn) {
HideElement('btn_' + btn);
ShowElement('btn_' + btn + '_dis');
}
function EnableBtn (btn) {
HideElement('btn_' + btn + '_dis');
ShowElement('btn_' + btn);
}
function SetButtonsText (direction) {
if (tabIds.length > 1) {
var btnNext = document.getElementById('btn_next');
var btnNextDis = document.getElementById('btn_next_dis');
var currentTabIndex = tabsheet.GetTabIndex (tabsheet.currentTabId);
var btnInnerHTML = '';
var btnDisInnerHTML = '';
if (direction == 'forward') {
var nextTabIndex = currentTabIndex + 1;
}else{
var nextTabIndex = currentTabIndex - 1;
}
btnInnerHTML = btnNext.innerHTML;
btnDisInnerHTML = btnNextDis.innerHTML;
btnInnerHTML = btnInnerHTML.replace('Seuraava', 'Seuraava');
btnDisInnerHTML = btnDisInnerHTML.replace('Seuraava', 'Seuraava');
if (nextTabIndex >= (tabIds.length - 1)) {
btnInnerHTML = btnInnerHTML.replace('Seuraava', 'Seuraava');
}
if (nextTabIndex >= (tabIds.length)) {
btnDisInnerHTML = btnDisInnerHTML.replace('Seuraava', 'Seuraava');
}
btnNext.innerHTML = btnInnerHTML;
btnNextDis.innerHTML = btnDisInnerHTML;
}
}
function CheckRequiredFields (tabId) {
var tab = document.getElementById(tabId);
var errorFields = new Array ();
var lastChecked = '';
var somethingSelected = false;
var elms = tab.getElementsByTagName("*");
for(var i = 0, maxI = elms.length; i < maxI; ++i) {
var elm = elms[i];
if (IsVisible(elm) && IsVisible(elm.parentNode)) { // field & fieldset
switch(elm.type) {
case "date":
case "text":
case "email":
case "number":
case "tel":
case "textarea":
case "hidden":
case "select-one":
case "select-multiple":
case "password":
case "file":
if (elm.getAttribute('required')!=null && elm.getAttribute('required').substr(0,1) == 1 && (elm.value.trim() == '' || elm.value == '##EMPTY##')) {
errorFields.push(elm.id);
SetFieldStatusImg (elm.id, 'error');
}else{
if (elm.value != '') {
SetFieldStatusImg (elm.id, 'ok');
}
}
break;
case "checkbox":
if (elm.getAttribute('required') == 1 && !elm.checked) {
errorFields.push(elm.id);
SetFieldStatusImg (elm.id, 'error');
}else{
SetFieldStatusImg (elm.id, 'ok');
}
break;
case "button":
case "reset":
case "submit":
case "image":
case "radio":
if (lastChecked != elm.name) {
var fsElem = document.getElementById('fs_' + elm.id);
if (elm.getAttribute('required')!=null && elm.getAttribute('required').substr(0,1) == 1 && IsVisible(fsElem)) {
var radioElm = document.getElementsByName(elm.name);
somethingSelected = false;
for (var j=0; j < radioElm.length; j++) {
if (radioElm[j].checked) {
somethingSelected = true;
}
}
if (somethingSelected == false) {
errorFields.push(elm.id);
}
}
lastChecked = elm.name;
}
break;
}
}
}
return errorFields;
}
function CheckFields (tabId, countryCode) {
var tab = document.getElementById(tabId);
var errorFields = '';
var errorMsg = '';
var elms = tab.getElementsByTagName("*");
for(var i = 0, maxI = elms.length; i < maxI; ++i) {
var elm = elms[i];
if (elm.value != '' && IsVisible(elm)) {
switch(elm.name) {
case 'email':
if (!IsValidEmail(elm.value) && CheckValidValue (elm)) {
errorFields = errorFields + elm.title + ', ';
SetFieldStatusImg (elm.id, 'error');
}
break;
case 'birthday':
if (CheckValidValue (elm)) {
switch (countryCode.toLowerCase()) {
case 'fin':
var val = elm.value;
console.log(val);
var separator;
if(val.indexOf('.') !== -1){
separator = '.';
}
if(val.indexOf('-') !== -1){
separator = '-';
}
if(separator != ''){
//pad numbers, eg. "1" = "01"
var a = val.split(separator);
var new_val = '';
if(a.length == 3) {
for (var i_tmp = 0; i_tmp < a.length; i_tmp++) {
var s = a[i_tmp];
if (s.length == 1) {
s = '0' + s;
}
new_val += s + separator;
}
//remove trailing separator
new_val = new_val.substr(0, new_val.length - 1);
elm.value = new_val;
}
}
if (!IsDate (elm.value, 'dd.MM.yyyy') && !IsDate (elm.value, 'yyyy-MM-dd')) {
errorFields = errorFields + elm.title + ', ';
SetFieldStatusImg (elm.id, 'error');
}
break;
}
}
break;
case 'social_sec_no':
if (CheckValidValue (elm)) {
switch (countryCode) {
case 'FIN':
case 'SWE':
var ok = validator.isValid.socialSecNo(countryCode, elm.value);
break;
default:
ok = true;
break;
}
}else{
ok = true;
}
if (!ok) {
errorFields = errorFields + elm.title + ', ';
SetFieldStatusImg (elm.id, 'error');
}
break;
case 'date_saved':
// case 'due_date': //all date fields
if (CheckValidValue (elm)) {
var date_format = '';
if(DATEFMT=='Y-m-d'){
date_format = 'yyyy-MM-dd';
}
else {
date_format = 'dd.MM.yyyy';
}
/*switch (countryCode.toLowerCase()) {
case 'fin':
date_format = 'dd.MM.yyyy';
break;
case 'swe':
case 'nor':
date_format = 'yyyy-MM-dd';
break;
} */
if (!IsDate (elm.value, date_format)) {
errorFields = errorFields + elm.title + ', ';
SetFieldStatusImg (elm.id, 'error');
}
}
break;
case 'customer_account':
if (CheckValidValue (elm)) {
if (!IsValidIBAN(elm.name)){
if (!IsAccountNumFinOk (elm.value)) {
errorFields = errorFields + elm.title + ', ';
SetFieldStatusImg (elm.id, 'error');
}
}
}
break;
case 'swe_bankkonto_number':
if(CheckValidValue (elm)) {
if (!IsValidIBAN(elm.name)){
if(!is_accountnum_swe_ok(elm.value)){
errorFields = errorFields + elm.title + ', ';
SetFieldStatusImg (elm.id, 'error');
}
}
}
break;
case 'swe_bankgiro_paynumber':
if(CheckValidValue (elm)) {
var socialSecNo = elm.value.substr(2,11);
if(!validator.isValid.socialSecNo('SWE', socialSecNo)){
errorFields = errorFields + elm.title + ', ';
SetFieldStatusImg (elm.id, 'error');
}
}
break;
}
}
}
return errorFields;
}
function IsValidIBAN (fieldName) {
// xjaxissa tehd��n tarkastus ja asetetaan cookie 1:ksi, jos on tilinumero on
// IBAN
if (GetCookie(fieldName + '_is_IBAN') == '1') {
return true;
}
return false;
}
function RemoveInputSpaces (obj) {
obj.value = obj.value.replace(' ', '');
}
function SetFieldStatusImg (elemId, status) {
var elem = document.getElementById (elemId);
if (elem.getAttribute('class') != 'readonly') {
if (status == 'error') {
HideElement (elemId + '_img_ok');
ShowElement (elemId + '_img_error');
}else{
HideElement (elemId + '_img_error');
ShowElement (elemId + '_img_ok');
}
}
}
function ShowErrorMsg (msg, reset, header) {
ShowElement ("errorMsg");
var regX = /\n/gi;
if (!reset) {
msg = document.getElementById('errorMsg').innerHTML + msg;
}else{
if (header == '') {
header = 'Tarkasta antamasi tiedot';
}
msg = ''+header+'
' + msg;
}
msg = msg.replace(regX, "
");
document.getElementById('errorMsg').innerHTML = msg;
ScrollTo ('#errorMsg');
}
function HideAllFieldStatusImages (tabId) {
var tab = document.getElementById(tabId);
var elms = tab.getElementsByTagName("*");
for(var i = 0, maxI = elms.length; i < maxI; ++i) {
var elm = elms[i];
HideElement (elm.id + '_img_ok');
HideElement (elm.id + '_img_error');
}
}
function SendCompanyDataToFbForm () {
var url = 'index.php?func=feedback';
var feedbackText = 'Y-tunnus %_trade_registry_number% on jo rekisteröity.';
url = url + '&feedback_type=company';
url = url + '&first_name=' + GetElemValue('id_first_name');
url = url + '&last_name=' + GetElemValue('id_last_name');
url = url + '&telephone=' + GetElemValue('id_telephone');
url = url + '&mobile=' + GetElemValue('id_mobile');
url = url + '&email=' + GetElemValue('id_email');
feedbackText = feedbackText.replace('%_trade_registry_number%', GetElemValue('id_trade_registry_number'));
url = url + '&feedback=' + feedbackText;
NewWindow(url, '600px', '450px', false);
}
function SendCustomerDataToFbForm () {
var url = 'index.php?func=feedback';
url = url + '&feedback_type=customer';
url = url + '&first_name=' + GetElemValue('id_first_name');
url = url + '&last_name=' + GetElemValue('id_last_name');
url = url + '&telephone=' + GetElemValue('id_telephone');
/* url = url + '&mobile=' + GetElemValue('id_mobile'); */
url = url + '&email=' + GetElemValue('id_email');
/* url = url + '&feedback=Y-tunnus %_trade_registry_number% on jo rekisteröity.'; */
NewWindow(url, '600px', '450px', false);
}
function CheckValidValue (elm) {
if (elm.getAttribute('required').substr(2,1) == '0') {
return false;
}
return true;
}
function SetNextAllowed (val) {
isNextAllowed = val;
}
function ProductHandler (directPayProducts) {
$('#errorMsg').hide();
var showDirectPayArea = false;
var prodCode = '';
var elemRcrProduct = document.frm_dlpm.rcr_product;
var changeLabelClass = false;
var elmLabel = null;
if (elemRcrProduct[0]) {
elmLabel = document.getElementById('l_rcr_product_' + elemRcrProduct[0].value);
}else{
elmLabel = document.getElementById('l_rcr_product_' + elemRcrProduct.value);
}
if (elmLabel) {
//if (elmLabel.className == 'radio_btn' || elmLabel.className == 'radio_btn_selected') {
if (elmLabel.className.toString().indexOf('radio_btn') !=-1 || elmLabel.className.toString().indexOf('radio_btn_selected') !=-1) {
changeLabelClass = true;
}
}
if (elemRcrProduct.length > 1) {
for (var i = 0; i < elemRcrProduct.length; i++) {
currProdCode = elemRcrProduct[i].value;
if (changeLabelClass) {
elmLabel = document.getElementById('l_rcr_product_' + currProdCode);
}
if (elemRcrProduct[i].checked) {
prodCode = elemRcrProduct[i].value;
if (changeLabelClass) {
if (elmLabel) elmLabel.className = 'radio_btn_selected';
}
}else{
if (changeLabelClass) {
if (elmLabel) elmLabel.className = 'radio_btn';
}
}
}
}else{
prodCode = elemRcrProduct.value;
if (changeLabelClass) {
elmLabel = document.getElementById('l_rcr_product_' + prodCode);
if (elmLabel) elmLabel.className = 'radio_btn_selected';
}
}
//Hide date_saved. xajax_XajaxSetContractInfo () set it visible if necessary
HideField('id_date_saved');
if (prodCode == '%execute_show_all_products%') {
ChangeProductView('all');
return true;
}
for (var i = 0; i < directPayProducts.length; i++) {
if (directPayProducts[i] == prodCode) {
showDirectPayArea = true;
break;
}
}
if (showDirectPayArea) {
ShowField('id_bill_name');
ShowField('id_customer_account');
ShowField('id_due_day');
ShowField('id_swe_bankkonto_number');
ShowField('id_swe_bankgiro_paynumber');
ShowField('id_use_swe_bankgiro_personal_number');
ShowField('id_c_account_isdefault');
ShowField('id_c_account_grant_permission');
ShowField('id_difference_payment_info');
ShowField('id_direct_pay_info');
if(document.getElementById('id_use_swe_bankgiro_personal_number')) {
UseSweBankgiroPersonalNumber();
}
HideField("id_term_code");
}else{
HideField('id_bill_name');
HideField('id_customer_account');
HideField('id_due_day');
HideField('id_swe_bankkonto_number');
HideField('id_swe_bankgiro_paynumber');
HideField('id_use_swe_bankgiro_personal_number');
HideField('id_swe_bankgiro_personal_number');
HideField('id_swe_bankgiro_personal_number_help');
HideField('id_c_account_isdefault');
HideField('id_c_account_grant_permission');
HideField('id_difference_payment_info');
HideField('id_direct_pay_info');
}
//$('#img_loading').show();
//if(prodCode != prevProdCode) {
//get data
xajax_XajaxProductHandler(xajax.getFormValues('id_frm_dlpm'), showDirectPayArea);
//}
prevProdCode = prodCode;
EnableBtn('next');
}
function setProductMode(enable){
$('input[name="rcr_product"]').each(function() {
$(this).prop('disabled', !enable);
});
}
function UserTypeHandler (companyUTC) {
if (document.getElementById ('id_user_type_code')) {
var utcField = document.getElementById ('id_user_type_code');
if (document.getElementById(tabsheet.currentTabId + '_hide_utcc')) {
var hideArea = document.getElementById(tabsheet.currentTabId + '_hide_utcc');
var elms = hideArea.childNodes;
var executeFunc1 = false;
var elemId = '';
for(var i = 0, maxI = elms.length; i < maxI; ++i) {
if (elms[i].id) {
elemId = elms[i].id;
if (elemId.substr(0,5) == 'fs_id') {
if (utcField.value == companyUTC) {
HideElement (elms[i].id);
}else{
ShowElement (elms[i].id);
if (elms[i].id == 'fs_id_use_swe_bankgiro_personal_number') {
executeFunc1 = true;
}
}
}
}
}
if (executeFunc1) {
UseSweBankgiroPersonalNumber()
}
}
}
}
function UseSweBankgiroPersonalNumber () {
if (document.getElementById('id_use_swe_bankgiro_personal_number').checked) {
ShowField('id_swe_bankgiro_personal_number');
ShowField('id_swe_bankgiro_personal_number_help');
}else{
HideField('id_swe_bankgiro_personal_number');
HideField('id_swe_bankgiro_personal_number_help');
}
}
function MembershipHandler(prodCode) {
var mspField = document.getElementsByName('membership_product[]');
var mspFieldSet = document.getElementById('fs_id_linked_product_info');
// var msForm = document.getElementById('id_frm_dlpm');
var textRow = document.getElementById('text_' + prodCode);
var caller = document.getElementById('remove_' + prodCode);
var isInList = false;
var newMspField = null;
for (var i = 0; i < mspField.length; i++) {
}
for (var i = 0; i < mspFieldSet.childNodes.length; i++) {
if (mspFieldSet.childNodes[i].name == 'membership_product[]') {
var item = mspFieldSet.childNodes[i];
if (item.value == prodCode) {
mspFieldSet.removeChild(item);
isInList = true;
}
}
}
if (isInList == false) { // Add to list
var newMspField = document.createElement('input');
newMspField.setAttribute('type', 'hidden');
newMspField.setAttribute('name', 'membership_product[]');
newMspField.setAttribute('value', prodCode);
mspFieldSet.appendChild (newMspField);
}
xajax_XajaxMembershipHandler(xajax.getFormValues('id_frm_dlpm'), true);
if (isInList) {
textRow.className = 'row_over_line';
caller.innerHTML = 'Lisää';
caller.setAttribute ('title', 'Lisää');
}else{
textRow.className = '';
caller.innerHTML = 'Poista';
caller.setAttribute ('title', 'Poista');
}
}
function NetPaymentHandler (payment_method) {
HideField ('fs_id_net_payment_method');
HideField ('fs_id_invoice_info');
if (payment_method == 'net_payment') {ShowField ('fs_id_net_payment_method');}
if (payment_method == 'invoice') {ShowField ('fs_id_invoice_info');}
}
function UpdateRegisterInfo () {
if (document.getElementById('register_info')) {
var firstName = GetElemValue('id_first_name');
var lastName = GetElemValue('id_last_name');
if (firstName != '' || lastName != '') {
ShowElement('register_info');
ShowElement('ri_customer_row');
document.getElementById('ri_customer_name').innerHTML = firstName + ' ' + lastName;
}
}
}
function ChangeProductView (showNow) {
SetCookie ('top_view_exists', 1);
switch (showNow) {
case 'top_product':
SetCookie ('product_view', 'top');
HideField ('id_show_top_product');
HideField ('id_contract');
HideField ('id_show_all_product');
ShowField ('id_rcr_product');
break;
default:
var contracts = document.getElementsByName('contract');
for (var i = 0; i < contracts.length; i++) {
contracts[i].checked = false;
}
RadioViewHandler ('contract', '', 'Show');
DisableBtn('next');
SetCookie ('product_view', 'base');
HideField ('id_show_all_product');
HideField ('id_rcr_product');
ShowField ('id_show_top_product');
ShowField ('id_contract');
break;
}
}
function RadioViewHandler (fieldName, selectedVal, viewCase) {
var elem = document.getElementsByName(fieldName);
var selElem = null;
var selTxt = '';
var rvhH1Elem = document.getElementById('rvh_h1');
if (elem[0]) {
for (var i = 0; i < elem.length; i++) {
if (elem[i].value != selectedVal) {
if (viewCase == 'Hide') {
HideElement('l_'+fieldName+'_' + elem[i].value);
}else{
ShowElement('l_'+fieldName+'_' + elem[i].value);
elem[i].style.display='';
}
}else{
if (viewCase == 'Hide') {
selElem = document.getElementById('l_'+fieldName+'_' + elem[i].value);
elem[i].style.display='none'; //Valot pois
rvhH1Elem.innerHTML = selElem.innerHTML;
HideElement('l_'+fieldName+'_' + elem[i].value);
}
}
}
}
if (viewCase == 'Hide') {
ShowElement ('rvh_h1');
ShowElement ('rvh_' + fieldName);
if (fieldName == 'contract') {
// ShowField ('id_rcr_product');
}
}else{
HideElement ('rvh_h1');
HideElement ('rvh_' + fieldName);
if (fieldName == 'contract') {
HideField ('id_rcr_product');
}
}
}
function SetFieldValue (elemId, value) {
if (!document.getElementById(elemId)) {
return false;
}
var elm = document.getElementById(elemId);
switch(elm.type) {
case "text":
case "email":
case "number":
case "tel":
case "textarea":
case "hidden":
case "select-one":
case "select-multiple":
case "password":
case "file":
case "checkbox":
case "button":
case "reset":
case "submit":
case "image":
elm.value = value;
break;
case "radio":
SetCheckedValue (elm, value);
break;
}
}
function SetCheckedValue(radioObj, newValue) {
if(!radioObj)
return;
var radioLength = radioObj.length;
if(radioLength == undefined) {
radioObj.checked = (radioObj.value == newValue.toString());
return;
}
for(var i = 0; i < radioLength; i++) {
radioObj[i].checked = false;
if(radioObj[i].value == newValue.toString()) {
radioObj[i].checked = true;
}
}
}
function ShowField (elemId) {
ShowElement (elemId);
ShowElement ('fs_' + elemId); // fieldset area
}
function HideField (elemId) {
HideElement (elemId);
HideElement ('fs_' + elemId); // fieldset area
}
function SetFieldVisibility (elemId, visibility) {
SetElementVisibility (elemId, visibility)
SetElementVisibility ('fs_' + elemId, visibility); // fieldset area
}
function SetElementVisibility (elemId, visibility) {
if (document.getElementById(elemId)) {
document.getElementById(elemId).style.visibility = visibility;
}
}
function GetElemValue (elemId) {
if (document.getElementById(elemId)) {
return document.getElementById(elemId).value;
}
}
function ToggleBillingAddrFields (visible) {
billAddrFieldIds = new Array ('id_bill_name', 'id_bill_addr_address_1', 'id_bill_addr_address_2', 'id_bill_addr_address_3', 'id_bill_addr_zip', 'id_bill_addr_city', 'id_bill_addr_telephone');
var isBillAddrFieldsEmpty = IsFieldsEmpty (billAddrFieldIds);
/*Ei toimi display = 'none' takia*/
for (var i in billAddrFieldIds) {
if (visible == true) {
ShowField(billAddrFieldIds[i]);
}else{
HideField(billAddrFieldIds[i]);
}
}
if (visible == true) {
SetFocus(billAddrFieldIds[0]);
}
}
function CopyFieldValueTo (field1, field2) {
if (document.getElementById(field1)) {
if (document.getElementById(field2)) {
document.getElementById(field2).value = document.getElementById(field1).value;
}
}
}
function IsFieldsEmpty (fields) {
for (var i in fields) {
if (document.getElementById(fields[i])) {
if (document.getElementById(fields[i].value != '')) {
return false;
}
}
}
return true;
}
function ShowPopup (page, width, height) {
if (!width) width='600px';
if (!height) height = '800px';
if (page.substr(0,7) == 'http://' || page.substr(0,8) == 'https://') {
var url = page;
}else{
var url = '?action=show_popup&page=' + page
}
var newWindow = window.open (url, 'newWindow', 'width=' + width + ', height=' + height + ', scrollbars=yes');
newWindow.focus();
}
function FillField (targetId, sourceIds) {
var value = '';
for (var i in sourceIds) {
var elemId = sourceIds[i];
if (document.getElementById(elemId)) {
var elem = document.getElementById(elemId);
value = value + elem.value + ' ';
}
}
if (value) {
if (document.getElementById(targetId)) {
document.getElementById(targetId).value = value.substr(0, value.length - 1);
}
}
}
function CalcCheckLetter(num){
var rivi = "0123456789ABCDEFHJKLMNPRSTUVWXY";
return rivi.substring(num % 31, num % 31 +1);
}
function IsValidFinSocialFormat(tunnus){
if ((tunnus.length != 10) && (tunnus.length != 11) || (tunnus.substring(6,7) != '-') && (tunnus.substring(6,7) != '+') && (tunnus.substring(6,7) != 'A')){
return false;
}
return true;
}
function IsValidFinSocialSecNo(num){
if (IsValidFinSocialFormat(num)){
var variable = num.substring(0,6) + num.substring(7,10);
var lastletter = num.substring(10,11);
var checkletter = CalcCheckLetter(variable);
if (lastletter == '')
return false;
else {
if (lastletter == checkletter)
return true;
else
return false;
}
}
}
function IsValidSweSocialSecNo (num) {
if(new SwePersonNummer(num).valid){
return true;
}else{
return false;
}
}
function SwePersonNummer(nr){
this.valid=false;
if(!nr.match(/^(\d{2})(\d{2})(\d{2})\-(\d{4})$/)){ return false; }
this.now=new Date(); this.nowFullYear=this.now.getFullYear()+""; this.nowCentury=this.nowFullYear.substring(0,2); this.nowShortYear=this.nowFullYear.substring(2,4);
this.year=RegExp.$1; this.month=RegExp.$2; this.day=RegExp.$3; this.controldigits=RegExp.$4;
this.fullYear=(this.year*1<=this.nowShortYear*1)?(this.nowCentury+this.year)*1:((this.nowCentury*1-1)+this.year)*1;
var months = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
if(this.fullYear%400==0||this.fullYear%4==0&&this.fullYear%100!=0){ months[1]=29; }
if(this.month*1<1||this.month*1>12||this.day*1<1||this.day*1>months[this.month*1-1]){ return false; }
this.alldigits=this.year+this.month+this.day+this.controldigits;
var nn="";
for(var n=0;n d2) {
return 1;
}
return 0;
}
function formatDate(date,format) {
format=format+"";
var result="";
var i_format=0;
var c="";
var token="";
var y=date.getYear()+"";
var M=date.getMonth()+1;
var d=date.getDate();
var E=date.getDay();
var H=date.getHours();
var m=date.getMinutes();
var s=date.getSeconds();
var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
// Convert real date parts into formatted versions
var value=new Object();
if (y.length < 4) {y=""+(y-0+1900);}
value["y"]=""+y;
value["yyyy"]=y;
value["yy"]=y.substring(2,4);
value["M"]=M;
value["MM"]=LZ(M);
value["MMM"]=MONTH_NAMES[M-1];
value["NNN"]=MONTH_NAMES[M+11];
value["d"]=d;
value["dd"]=LZ(d);
value["E"]=DAY_NAMES[E+7];
value["EE"]=DAY_NAMES[E];
value["H"]=H;
value["HH"]=LZ(H);
if (H==0){value["h"]=12;}
else if (H>12){value["h"]=H-12;}
else {value["h"]=H;}
value["hh"]=LZ(value["h"]);
if (H>11){value["K"]=H-12;} else {value["K"]=H;}
value["k"]=H+1;
value["KK"]=LZ(value["K"]);
value["kk"]=LZ(value["k"]);
if (H > 11) { value["a"]="PM"; }
else { value["a"]="AM"; }
value["m"]=m;
value["mm"]=LZ(m);
value["s"]=s;
value["ss"]=LZ(s);
while (i_format < format.length) {
c=format.charAt(i_format);
token="";
while ((format.charAt(i_format)==c) && (i_format < format.length)) {
token += format.charAt(i_format++);
}
if (value[token] != null) { result=result + value[token]; }
else { result=result + token; }
}
return result;
}
function _isInteger(val) {
var digits="1234567890";
for (var i=0; i < val.length; i++) {
if (digits.indexOf(val.charAt(i))==-1) { return false; }
}
return true;
}
function _getInt(str,i,minlength,maxlength) {
for (var x=maxlength; x>=minlength; x--) {
var token=str.substring(i,i+x);
if (token.length < minlength) { return null; }
if (_isInteger(token)) { return token; }
}
return null;
}
function getDateFromFormat(val,format) {
val=val+"";
format=format+"";
var i_val=0;
var i_format=0;
var c="";
var token="";
var token2="";
var x,y;
var now=new Date();
var year=now.getYear();
var month=now.getMonth()+1;
var date=1;
var hh=now.getHours();
var mm=now.getMinutes();
var ss=now.getSeconds();
var ampm="";
while (i_format < format.length) {
// Get next token from format string
c=format.charAt(i_format);
token="";
while ((format.charAt(i_format)==c) && (i_format < format.length)) {
token += format.charAt(i_format++);
}
// Extract contents of value based on format token
if (token=="yyyy" || token=="yy" || token=="y") {
if (token=="yyyy") { x=4;y=4; }
if (token=="yy") { x=2;y=2; }
if (token=="y") { x=2;y=4; }
year=_getInt(val,i_val,x,y);
if (year==null) { return 0; }
i_val += year.length;
if (year.length==2) {
if (year > 70) { year=1900+(year-0); }
else { year=2000+(year-0); }
}
}
else if (token=="MMM"||token=="NNN"){
month=0;
for (var i=0; i11)) {
month=i+1;
if (month>12) { month -= 12; }
i_val += month_name.length;
break;
}
}
}
if ((month < 1)||(month>12)){return 0;}
}
else if (token=="EE"||token=="E"){
for (var i=0; i12)){return 0;}
i_val+=month.length;}
else if (token=="dd"||token=="d") {
date=_getInt(val,i_val,token.length,2);
if(date==null||(date<1)||(date>31)){return 0;}
i_val+=date.length;}
else if (token=="hh"||token=="h") {
hh=_getInt(val,i_val,token.length,2);
if(hh==null||(hh<1)||(hh>12)){return 0;}
i_val+=hh.length;}
else if (token=="HH"||token=="H") {
hh=_getInt(val,i_val,token.length,2);
if(hh==null||(hh<0)||(hh>23)){return 0;}
i_val+=hh.length;}
else if (token=="KK"||token=="K") {
hh=_getInt(val,i_val,token.length,2);
if(hh==null||(hh<0)||(hh>11)){return 0;}
i_val+=hh.length;}
else if (token=="kk"||token=="k") {
hh=_getInt(val,i_val,token.length,2);
if(hh==null||(hh<1)||(hh>24)){return 0;}
i_val+=hh.length;hh--;}
else if (token=="mm"||token=="m") {
mm=_getInt(val,i_val,token.length,2);
if(mm==null||(mm<0)||(mm>59)){return 0;}
i_val+=mm.length;}
else if (token=="ss"||token=="s") {
ss=_getInt(val,i_val,token.length,2);
if(ss==null||(ss<0)||(ss>59)){return 0;}
i_val+=ss.length;}
else if (token=="a") {
if (val.substring(i_val,i_val+2).toLowerCase()=="am") {ampm="AM";}
else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") {ampm="PM";}
else {return 0;}
i_val+=2;}
else {
if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
else {i_val+=token.length;}
}
}
// If there are any trailing characters left in the value, it doesn't match
if (i_val != val.length) { return 0; }
// Is date valid for month?
if (month==2) {
// Check for leap year
if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
if (date > 29){ return 0; }
}
else { if (date > 28) { return 0; } }
}
if ((month==4)||(month==6)||(month==9)||(month==11)) {
if (date > 30) { return 0; }
}
// Correct hours value
if (hh<12 && ampm=="PM") { hh=hh-0+12; }
else if (hh>11 && ampm=="AM") { hh-=12; }
var newdate=new Date(year,month-1,date,hh,mm,ss);
return newdate.getTime();
}
function IsAccountNumFinOk (ref){
var ref_chr;
if (ref != '') {
ref_chr = ref.charAt(ref.length-1);
ref = Set14chr(ref);
// Ei saa olla yli 14 merkki�
if (ref.length > 14) {
return false;
}
if (mod10_chknum(ref) == ref_chr)
return true;
}
return false;
}
function mod10_chknum(str) {
// var Ref, Ref_sum, Ref_14chr, reverse_Ref_14chr, Mod_mult, Mod_res, Mod_sum,
// Ref_chk, i;
str=str+''; //Convert to string
var weight=2; /* weight to apply to digit being checked */
var sum=0; /* sum of weights */
var digit; /* digit being checked */
/* compute the sum */
for (var cnt = str.length; cnt>0; cnt--){
digit = weight * (str.charAt(cnt-1));
/* add tens digit to ones digit to the sum */
sum = sum + Math.floor(digit / 10) + (digit % 10);
weight=weight==2?1:2;
}
/* subtract ones digit of the sum from 10 return ones digit of result */
var mod = (10-sum%10)%10;
return mod;
}
function Set14chr(s){
var part1, part2, part3, InsertPos, substr, i;
if (s != '') {
s = StripSignStr(s);
InsertPos = 6;
if ((s.substr(0,1) == '4') || (s.substr(0,1) == '5') )
InsertPos = 7;
subStr = '';
for (i = s.length; i < 14; i++) {
subStr += '0';
}
part1 = s.substr(0, InsertPos);
part2 = s.substr(InsertPos, s.length-1);
return part1+ subStr +part2;
}
}
function StripSignStr(s) {
var nosign, i;
if (s != '') {
nosign = '';
for (i = 0; i < s.length; i++) {
if (s.substr(i,1) != '-') {
nosign = nosign + s.charAt(i) ;
}
}
return nosign;
}
return '';
}
function mod11_chknum( Ref )
{
var Ref_nospace;
var Ref_sum;
var Ref_chk;
var Mod_mult;
var i;
Ref_nospace = StripSpacesStr(Ref);
if ( Ref_nospace != '')
{
Ref_sum = 0;
Mod_mult = 1;
for ( i = Ref_nospace.length-1; i >= 0 ; i--)
{
Mod_mult++;
Mod_mult = (Mod_mult%11);
if ( Mod_mult == 0) Mod_mult = 1;
Ref_sum = Ref_sum + Ref_nospace[i]* Mod_mult;
}
Ref_chk = Ref_sum % 11;
if ( Ref_chk > 1 )
Ref_chk = 11 - Ref_chk;
else Ref_chk = 0;
return ( Ref_chk );
}
return ('');
}
function StripSpacesStr(str)
{
while ( str.indexOf(" ") > 0 ) {
str = str.replace(/ /,"");
}
return ( str );
}
function is_accountnum_swe_ok (Accountnum){
var ref;
var ref_chr;
var clearing;
/*
*
* Accountnum = StripSpacesStr(Accountnum); Accountnum = DelChars(Accountnum,
* '-'); Accountnum = trim(Accountnum);
*/
while ( Accountnum.indexOf(" ") > 0 ) {
Accountnum = Accountnum.replace(/ /,"");
}
while ( Accountnum.indexOf("-") > 0 ) {
Accountnum = Accountnum.replace(/-/,"");
}
if ( Accountnum != '' )
{
Clearing = Accountnum.substr(0, 4);
ref_chr = Accountnum.charAt(Accountnum.length-1);
if (
((Clearing >= '9090') && (Clearing <= '9099')) ||
((Clearing >= '9040') && (Clearing <= '9049')) ||
((Clearing >= '9190') && (Clearing <= '9199')) ||
((Clearing >= '2300') && (Clearing <= '2399')) ||
((Clearing >= '9020') && (Clearing <= '9029')) ||
((Clearing >= '4000') && (Clearing <= '4999') && (Accountnum.length != 14)) ||
((Clearing >= '9150') && (Clearing <= '9196')) ||
((Clearing >= '9200') && (Clearing <= '9209')) ||
((Clearing >= '9100') && (Clearing <= '9109'))||
((Clearing >= '9550') && (Clearing <= '9569'))
)
{
ref = Accountnum.substr(0,Accountnum.length-1);
// Ref := copy(Accountnum, 1, Length(Accountnum));
return (mod11_chknum(ref) == ref_chr);
} else {
if ( ((Clearing >= '1200') && (Clearing <= '1399')) ||
((Clearing >= '9260') && (Clearing <= '9269')) ||
((Clearing >= '7000') && (Clearing <= '7999')) ||
((Clearing >= '9270') && (Clearing <= '9279')) ||
((Clearing >= '9170') && (Clearing <= '9179')) ||
((Clearing >= '3400') && (Clearing <= '3409')) ||
((Clearing >= '9060') && (Clearing <= '9069')) ||
((Clearing >= '1100') && (Clearing <= '1199') && (Accountnum.length != 14)) ||
((Clearing >= '1400') && (Clearing <= '2099') && (Accountnum.length != 14)) ||
((Clearing >= '3000') && (Clearing <= '3399') && (Accountnum.length != 14)) ||
((Clearing >= '3410') && (Clearing <= '3999') && (Accountnum.length != 14)) ||
((Clearing >= '9230') && (Clearing <= '9239')) ||
((Clearing >= '5000') && (Clearing <= '5999')) ||
((Clearing >= '9400') && (Clearing <= '9449')) ||
((Clearing >= '9460') && (Clearing <= '9469')) ||
((Clearing >= '9280') && (Clearing <= '9289')) ||
((Clearing >= '9250') && (Clearing <= '9259')) ||
((Clearing >= '9120') && (Clearing <= '9124')) ||
((Clearing >= '9130') && (Clearing <= '9149')) ||
((Clearing >= '9050') && (Clearing <= '9059'))
)
{
ref = Accountnum.substr(1, Accountnum.length-2);
return (mod11_chknum(ref) == ref_chr);
/*
* ref := copy(Accountnum, 2, Length(Accountnum) - 1); if (mod11_chknum(ref) =
* ref_chr) Then Result := True;
*/
} else
if (
((Clearing >= '3300') && (Clearing <= '3300') && (Accountnum.length == 14)) ||
((Clearing >= '4000') && (Clearing <= '4999') && (Accountnum.length == 14)) ||
((Clearing >= '1100') && (Clearing <= '1199') && (Accountnum.length == 14)) ||
((Clearing >= '1400') && (Clearing <= '2099') && (Accountnum.length == 14)) ||
((Clearing >= '3000') && (Clearing <= '3399') && (Accountnum.length == 14)) ||
((Clearing >= '3410') && (Clearing <= '3999') && (Accountnum.length == 14))
)
{
ref = Accountnum.substr(Accountnum.length-10, 9);
return (mod10_chknum(ref) == ref_chr);
/*
* ref := copy(Accountnum, Accountnum.length - 9, 10); if (mod10_chknum(ref) =
* ref_chr) The Result := True;
*/
} else
if ( ((Clearing >= '6000') && (Clearing <= '6999')) )
{
ref = Accountnum.substr(Accountnum.length-9, 8);
return (mod11_chknum(ref) == ref_chr);
/*
* ref := copy(Accountnum, Length(Accountnum) - 8, 9); if (mod11_chknum(ref) =
* ref_chr) Then Result := True;
*/
} else
if ( ((Clearing >= '9500') && (Clearing <= '9549')) ||
((Clearing >= '9960') && (Clearing <= '9969')) )
{
ref = Accountnum.substr(4, Accountnum.length-5);
return (mod10_chknum(ref) == ref_chr);
/*
* ref := copy(Accountnum, 5, Length(Accountnum) - 4); if
* (swe_mod10_chknum(ref) = ref_chr) Then Result := True;
*/
} else
if ( ((Clearing >= '8000') && (Clearing <= '8999'))) {
ref = Accountnum.substr(4, Accountnum.length-5);
return (mod10_chknum(ref) == ref_chr);
/*
* ref := copy(Accountnum, 5, Length(Accountnum) - 4); if
* (swe_mod10_chknum(ref) = ref_chr) Then Result := True;
*/
} else
if ( ((Clearing >= '9180') && (Clearing <= '9189')) ||
((Clearing >= '9300') && (Clearing <= '9329')) ||
((Clearing >= '9330') && (Clearing <= '9349')) ||
((Clearing >= '9570') && (Clearing <= '9579'))
)
{
ref = Accountnum.substr(4, Accountnum.length-5);
return (mod10_chknum(ref) == ref_chr);
/*
* ref := copy(Accountnum, 5, Length(Accountnum) - 4); if
* (swe_mod10_chknum(ref) = ref_chr) Then Result := True;
*/
}
}
}
return ( false );
}
function GetSweBankSocialSec (socialSec) {
if (socialSec) {
var yearS = '';
var yearE = 0;
var d = new Date;
var thisYear = d.getFullYear(); // t�m� vuosi
yearE = socialSec.substr(0,2);
if (thisYear - yearE < 2000) {
yearS = '19';
}else{
yearS = '20';
}
socialSec = yearS + socialSec;
socialSec = socialSec.replace("-", "");
return socialSec;
}
return '';
}
function SetFieldSummaryVisibility (fieldName){
if(document.getElementById('fs_id_' + fieldName).style.display == 'none'){
HideField('id_summary_' + fieldName);
} else {
ShowField('id_summary_' + fieldName);
}
}
function ShowMList(index) {
(index);
}
function MemberListEditCustomer (customerCode, fieldName, caller) {
newValue = prompt('Vaihda', caller.innerHTML);
if (newValue) {
xajax_XajaxEditCustomer(customerCode, fieldName, newValue);
caller.innerHTML = newValue;
}
}
function DlpmNewWinHandler () {
var currentTabIndex = tabsheet.GetTabIndex (tabsheet.currentTabId);
var nextTabId = tabsheet.GetTabId (currentTabIndex + 1);
if (!nextTabId) {
if (isNextAllowed) {
CreatePaymentWindow();
}
}
}
var tabIds = new Array ('tab2');
var elemOrigHTML = new Array;
var stepImgs = new Array ();
function Tabbar (imgDir, formTarget) {
var currentTabId;
this.imgDir = imgDir;
this.formTarget = formTarget;
this.Show = Show;
this.Hide = Hide;
this.HideAllTabs = HideAllTabs;
this.Next = Next;
this.Prev = Prev;
this.SetActive = SetActive;
this.SetClass = SetClass;
this.SetInnerHTML = SetInnerHTML;
this.SetFocusToFirstElement = SetFocusToFirstElement;
this.GetTabObject = GetTabObject;
this.GetFirstTabId = GetFirstTabId;
this.GetTabIndex = GetTabIndex;
this.GetTabId = GetTabId;
function Show (tabId) {
this.HideAllTabs ();
var tab = this.GetTabObject(tabId);
//tab.style.display = '';
$("#"+tabId).show();
this.SetActive(tabId);
this.SetFocusToFirstElement(tabId);
}
function Hide (tabId) {
var tab = this.GetTabObject(tabId);
tab.style.display = 'none';
}
function HideAllTabs () {
if (tabIds.length > 1) {
for (var i = 0; i < tabIds.length; i++) {
this.Hide(tabIds[i]);
this.SetClass ('a_' + tabIds[i], 'steps');
this.SetInnerHTML (tabIds[i], 'disable');
$("#a_"+tabIds[i]).parent().removeClass('active'); //Bootstrap
}
}
}
function Next () {
switch (this.currentTabId) {
case 'tab11':
xajax_XajaxFillSummary(xajax.getFormValues('id_frm_dlpm'));
break;
default:break;
}
var currentTabIndex = this.GetTabIndex (this.currentTabId);
var nextTabId = this.GetTabId (currentTabIndex + 1);
if (nextTabId) {
if (isNextAllowed) {
this.Show(nextTabId);
}
}else{
DisableBtn('next');
var form = document.getElementById("id_frm_dlpm");
if (this.formTarget == 'newWindow') {
form.setAttribute ('target', 'newWindow');
form.submit();
newWindow.focus();
}else{
form.setAttribute ('target', this.formTarget);
form.submit();
}
}
}
function Prev () {
HideElement ("errorMsg");
if (this.currentTabId == 'tab3') {
if (GetCookie('top_view_exists') == '1' && GetCookie('product_view') == 'base') {
xajax_XajaxResetRcrProducts(null, 'top_product', GetElemValue('id_location'));
return true;
}
}
var currentTabIndex = this.GetTabIndex (this.currentTabId);
var prevTabId = this.GetTabId (currentTabIndex - 1);
if (prevTabId) {
this.Show(prevTabId);
}else{
var backUrl = '';
if (backUrl) {
window.location = backUrl;
}else{
history.back();
}
}
}
function SetActive (tabId) {
this.currentTabId = tabId; // save to global variable
if (tabIds.length > 1) {
$("#a_"+tabId).addClass('stepsActive');
$("#a_"+tabId).parent().addClass('active'); //Bootstrap
this.SetInnerHTML (tabId, 'active');
}
}
function SetInnerHTML (tabId, state) {
var tabIndex = this.GetTabIndex(tabId);
var imgFileName = tabIndex+'_'+state+'.png';
var imgSrc = this.imgDir+'/'+imgFileName;
var imgExists = false;
var elem = document.getElementById('a_' + tabId);
if (!elemOrigHTML[tabIndex]) {
elemOrigHTML[tabIndex] = elem.innerHTML;
}
for (i=0; i < stepImgs.length; i++) {
if (stepImgs[i] === imgFileName) {
imgExists = true;
}
}
if (imgExists) {
elem.innerHTML = '';
}else{
elem.innerHTML = elemOrigHTML[tabIndex];
}
}
function SetFocusToFirstElement (tabId) {
if (document.getElementById(tabId)) {
var tab = document.getElementById(tabId);
var elms = tab.getElementsByTagName("*");
for(var i = 0, maxI = elms.length; i < maxI; ++i) {
var elm = elms[i];
if (elm.type == 'text') {
if (elm.value == '') {
elm.focus();
return true;
}
}
}
}
}
function SetClass (elemId, className) {
var elem = this.GetTabObject(elemId);
if (elem != null) {
elem.className = className;
}
}
function GetTabObject (tabId) {
return document.getElementById(tabId);
}
function GetFirstTabId () {
return tabIds[0];
}
function GetTabIndex (tabId) {
for (var i = 0; i < tabIds.length; i++) {
if (tabIds[i] == tabId) {
return i;
}
}
return false;
}
function GetTabId (tabIndex) {
for (var i = 0; i < tabIds.length; i++) {
if (i == tabIndex) {
return tabIds[i];
}
}
return false;
}
}