$( document ).ready(function() { var dm = document.getElementById('footer'); if(dm){ dm.addEventListener('dragstart',drag_start,false); document.body.addEventListener('dragover',drag_over,false); document.body.addEventListener('drop',drop,false); } if($('form[name="person_info"] #accounts').length){ var dperror = $('#direct_pay_err').html() != ''; $('form[name="person_info"]').find('.directpay').each(function() { //show fields on error if (dperror) { $(this).show(); //hide field readonly value (span) var field_val = $(this).prev('span#s_' + $(this).prop('name')); if ($(field_val).length) { $(field_val).hide(); } } $(this).on('keydown, change', function () { var chkConfirm = $('form[name="person_info"]').find('.checkbox.directpay.confirm'); if ($(chkConfirm).length) { $(chkConfirm).show(); $(chkConfirm).prop('required', true); } $('form[name="person_info"]').find('input[name="account_changed"]').val(1); }); }); if(dperror){ //open tab $('form[name="person_info"] .nav-tabs').find('li.accounts a').click(); } } if($('form[name="person_info"]').length){ $('form[name="person_info"] input.address').each(function(){ $(this).on('keydown, change', function () { $('form[name="person_info"]').find('input[name="address_changed"]').val(1); }); }); if($('form[name="person_info"] ul.nav li').length) { $('form[name="person_info"] ul.nav li').on('click', function() { if ($(this).hasClass('tab_custom') || $(this).hasClass('invoices') || $(this).hasClass('invoice_history') || $(this).hasClass('history') || $(this).hasClass('autocharge_subscription')) { //hide elements HideElement('btn_edit'); HideElement('btn_save'); HideElement('btn_cancel'); HideElement('password'); HideElement('giro'); HideElement('rr_mydetails_menu'); HideElement('calendar_sync'); HideElement('rr_customer_consent'); } else { //display elements if($('form[name="person_info"]').data('edit') == 1){ //is in edit mode ShowElement('btn_save'); ShowElement('btn_cancel'); } else { ShowElement('btn_edit'); } ShowElement('password'); ShowElement('giro'); ShowElement('rr_mydetails_menu'); ShowElement('calendar_sync'); ShowElement('rr_customer_consent'); } }); } } if($('#stop_contract_reason').length){ $('#stop_contract_reason').on('change', function(){ if($(this).val() == 'X') { $('#stop_contract_x').show(); } else{ $('#stop_contract_x').hide(); } }); } $('#select_location.v2 a').on('click', function(e) { if ($(this).hasClass('scroll')) { //mobile navigation up/down in list if ($(this).hasClass('down')) { $(this).closest('.list-group').removeClass('visible-xs').addClass('hidden-xs'); $(this).closest('.list-group').next('.list-group').removeClass('hidden-xs').addClass('visible-xs'); $(this).closest('.list-group').next('.list-group').find('.up').removeClass('hidden-xs').addClass('visible-xs'); } else if ($(this).hasClass('up')) { $(this).closest('.list-group').removeClass('visible-xs').addClass('hidden-xs'); $(this).closest('.list-group').prev('.list-group').removeClass('hidden-xs').addClass('visible-xs'); $(this).closest('.list-group').next('.list-group').find('.down').removeClass('hidden-xs').addClass('visible-xs'); } } else { if (($('body').hasClass('training_card') || $('body').hasClass('lite_webshop')) && $('body').hasClass('v2')) { $('#select_location .list-group-item').removeClass('active'); $(this).closest('.list-group-item').addClass('active'); Cookie.set('tc_selected_location', $(this).closest('.list-group-item').data('value')); $('#select_location button').html($(this).closest('.list-group-item').data('name') + ' '); //show location description, if found $('.location_description').hide(); if($('#tc_select_location').hasClass('centers')){ $('.location_description[data-name="'+ $(this).closest('.list-group-item').data('name') +'"]').show(); } else{ $('.location_description[data-value="'+ $(this).closest('.list-group-item').data('value') +'"]').show(); } if($('#select_location').data('role-filter')){ if($('body').hasClass('lite_webshop')){ webshop.filter.execute(true); } else { if ($('.centers_area').length) { trainingCard.filter.setLinkedContracts(); } trainingCard.filter.execute(true); } } if($('body').hasClass('lite_webshop')) { webshop.stepInto('tc_select_product'); webshop.summary.show(); } else { trainingCard.stepInto('tc_select_product'); trainingCard.summary.show(); //todo: summary is fetched twice when changing center } selectLocationClickReady($(this)); } if($('body').hasClass('play')) { selectLocationClickReady($(this)); } } }); //reservation pay if ($('#table_rsv_list').length && $('#chk_select_all_rows').length) { document.getElementById('chk_select_all_rows').checked = false; var row_select_checkboxes = document.getElementsByClassName("select_rsv"); for (var i = 0; i < row_select_checkboxes.length; i++) { row_select_checkboxes[i].checked = false; } $('button[name="rsv_pay"]').prop('disabled', true); } }); function removeAutocharge() { var modal = { title: 'Poista maksukortti', body: 'Haluatko poistaa maksukortin? Huomioithan että asiakkuutesi jatkuu kuitenkin kuten ennen ja jatkossa saat laskut joko paperisena tai e-laskulla.', buttons: {accept: 'Ok', reject: 'Keskeytä'} }; showConfirmation(function(status) { if (status) { window.location = 'index.php?func=md_rm_credit_card'; } return false; }, modal); } function addAutocharge() { window.location = 'index.php?func=md_add_credit_card'; } function selectLocationClickReady(item){ //overridable function. }; function ToggleLayer(whichLayer){ var elem, vis; if( document.getElementById ) // this is the way the standards work elem = document.getElementById( whichLayer ); else if( document.all ) // this is the way old msie versions work elem = document.all[whichLayer]; else if( document.layers ) // this is the way nn4 works elem = document.layers[whichLayer]; vis = elem.style; // if the style.display value is blank we try to figure it out here if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined) vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none'; vis.display = (vis.display==''||vis.display=='block')?'none':'block'; } function SearchPage () { // variables this.errorMsg = ''; // methods this.ShowSelectedObjects = ShowSelectedObjects; this.ShowElement = ShowElement; this.HideElement = HideElement; this.HighLight = HighLightInput; this.SetFontColor = SetFontColor; this.AutoComplete = AutoComplete; this.MoveOptions = MoveOptions; this.HandleEnterKey = HandleEnterKey; this.OnSubmit = SearchOnSubmit; this.WeekdayHandler = WeekdayHandler; this.CheckBoxSelectAll = CheckBoxSelectAll; this.Submit = SubmitSearchForm; } function HighLightRows (iTableIds) { // rivien väritys var currentTable = null; var currentTr = null; var trCounter = 0; var info = ''; if (iTableIds) { tableIds = iTableIds; }else{ tableIds = tableIdArray; // global } for (var i = 0; i < tableIds.length; i++) { currentTable = document.getElementById (tableIds[i]); // loopataan taulun rivit trCounter = 0; for (var j = 0; j < currentTable.rows.length; j++) { currentTr = currentTable.rows[j]; if(currentTr.className != 'highlighted' ){ currentTr.style.background=''; if (currentTr.style.display != 'none') { if (trCounter % 2 == 1) { currentTr.style.background='#e8e5e5'; } trCounter++; } }else trCounter++; } } } function ShowSelectedObjects () { var checkBoxList = new Array(); var currentItem = null; var counter = 0; var objectClassList = new Array; var nameParts = new Array; checkBoxList = GetElementIds (document.getElementById('objClassOpt'), 'checkbox'); for (var i = 0; i < checkBoxList.length; i++) { currentItem = document.getElementById(checkBoxList[i]); HideElement ('objChild_' + currentItem.id); if (currentItem.checked) { // käsketään näyttämään tämän objektit nameParts = currentItem.name.split("["); objectClassList.push(nameParts[1].substr(0, nameParts[1].length - 1)); counter++; } } if (counter > 0) { ShowElement ('objectOpt'); ShowElement ('id_objects_0'); xajax_ShowObjects (objectClassList); // call xajax function }else{ HideElement ('objectOpt'); HideElement ('id_objects_0'); document.getElementById('objectOpt').innerHTML = ''; } } function ShowElement(id) { if (typeof(id) == 'string') { if (document.getElementById(id) != undefined) { document.getElementById(id).style.display=''; } }else{ id.style.display=''; } } function HideElement(id) { if (typeof(id) == 'string') { if (document.getElementById(id) != undefined) { document.getElementById(id).style.display='none'; } }else{ id.style.display='none'; } } function ToggleElement(id) { if (typeof(id) == 'string') { if($('#'+id).length){ $('#'+id).toggle(); } }else{ $(id).toggle(); } } function IsVisible (elem) { return elem.style.display!="none"; } function GetElementIds (targetElem, elemType) { if (window.elemList === undefined) { var elemList = new Array (); } for (var i = 0; i < targetElem.childNodes.length; i++) { if (targetElem.childNodes[i].type == elemType) { elemList.push(targetElem.childNodes[i].id); }else{ var newSearch = GetElementIds (targetElem.childNodes[i], elemType); if (newSearch != '') { for (var j = 0; j < newSearch.length; j++){ elemList.push(newSearch[j]); } } } } return elemList; } function SetFocus (elemId){ if (document.getElementById(elemId)) { document.getElementById(elemId).focus(); } } function SetFocusToFirst (form_name) { var form = document.forms[form_name]; for(var i=0; i0) { theSel.options[theIndex] = null; } } function MoveOptions(theSelFrom, theSelTo) { var selLength = theSelFrom.length; var selectedText = new Array(); var selectedValues = new Array(); var selectedCount = 0; var i; // Find the selected Options in reverse order // and delete them from the 'from' Select. for(i=selLength-1; i>=0; i--) { if(theSelFrom.options[i].selected) { selectedText[selectedCount] = theSelFrom.options[i].text; selectedValues[selectedCount] = theSelFrom.options[i].value; deleteOption(theSelFrom, i); selectedCount++; } } // Add the selected text/values in reverse order. // This will add the Options to the 'to' Select // in the same order as they were in the 'from' Select. for(i=selectedCount-1; i>=0; i--) { addOption(theSelTo, selectedText[i], selectedValues[i]); } if(NS4) history.go(0); } function DeleteEmptyOptions (elemId) { var selectElem = document.getElementById (elemId); for(var i = 0; i < selectElem.length; i++) { if(selectElem.options[i].value == ''){ deleteOption(selectElem, i); } } } function HandleEnterKey (e, caller, func, param1, param2) { var key; if(window.event) key = window.event.keyCode; // IE else key = e.which; // firefox if (key == '13') { if (func == 'Autocomplete') { this.MoveOptions (param1, param2); } return false; } } function SubmitSearchForm () { document.getElementById('searchMain').submit(); } function ValidateForm(form, a){ var x,i; for (i = 0; i < a.length; i++) { x = document.getElementById(a[i]).value; if (x=='') return false; } SubmitForm(form); return true; } function WeekdayHandler (caller) { var dayOfWeekAll = document.getElementById('idDayOfWeekAll'); var checkBoxList = GetElementIds (document.getElementById('dayOfWeeks'), 'checkbox'); var selectedItems = 0; for (var i = 0; i < checkBoxList.length; i++) { currentItem = document.getElementById(checkBoxList[i]); if (currentItem.checked) { selectedItems = selectedItems + 1; } if (caller == 'idDayOfWeekAll') { if (dayOfWeekAll.checked) { currentItem.checked = true; }else{ currentItem.checked = false; } } } if (caller == 'idDayOfWeekAll') { if (selectedItems > 0) { // eka päälle jos mitään ei ole valittu, eli maanantai //document.getElementById(checkBoxList[0]).checked = true; } }else{ if (selectedItems > 0) { dayOfWeekAll.checked = false; }else{ dayOfWeekAll.checked = true; } if (selectedItems == checkBoxList.length) { dayOfWeekAll.checked = true; } if (selectedItems == 0) { WeekdayHandler('idDayOfWeekAll'); } } } function CheckBoxSelectAll (caller, selectAllId, areaId) { var chkSelectAll = document.getElementById(selectAllId); var checkBoxList = GetElementIds (document.getElementById(areaId), 'checkbox'); var selectedItems = 0; for (var i = 0; i < checkBoxList.length; i++) { currentItem = document.getElementById(checkBoxList[i]); if (currentItem.checked) { selectedItems = selectedItems + 1; } if (caller == selectAllId) { if (chkSelectAll.checked) { currentItem.checked = true; }else{ currentItem.checked = false; } } } if (caller == selectAllId) { //if (selectedItems > 0) { // eka päälle jos mitään ei ole valittu, eli maanantai //document.getElementById(checkBoxList[0]).checked = true; //} }else{ if (selectedItems > 0) { chkSelectAll.checked = false; }else{ chkSelectAll.checked = true; } if (selectedItems == checkBoxList.length) { chkSelectAll.checked = true; } if (selectedItems == 0) { CheckBoxSelectAll(selectAllId, selectAllId, areaId); } } } function SearchOnSubmit () { // Select all from instructor multiple select var selObj = document.getElementById('idInstructors'); for (i = 0; i < selObj.length; i++) { selObj.options[i].selected = true; } return true; } function EmptySelectList(elemId) { selElem = document.getElementById(elemId); selElem.options.length = 0; } function SetMyDetailsToEditState (edit) { if(edit){ $('form[name="person_info"]').data('edit', 1); $('form[name="person_info"] input,form[name="person_info"] select').prev('span').hide(); $('form[name="person_info"] input,form[name="person_info"] select, form[name="person_info"] .input-group-btn').show(); $('form[name="person_info"] tr.readonly').hide(); HideElement('btn_edit'); HideElement('btn_my_contract'); HideElement('btn_print'); HideElement('btn_to_start_page'); HideElement('password'); HideElement('giro'); HideElement('rr_mydetails_menu'); HideElement('calendar_sync'); ShowElement('btn_save'); ShowElement('btn_cancel'); } else { $('form[name="person_info"]').data('edit', 0); $('form[name="person_info"] input,form[name="person_info"] select').prev('span').show(); $('form[name="person_info"] input,form[name="person_info"] select, form[name="person_info"] .input-group-btn').hide(); $('form[name="person_info"] tr.readonly').show(); ShowElement('btn_edit'); ShowElement('btn_my_contract'); ShowElement('btn_print'); ShowElement('btn_to_start_page'); ShowElement('password'); ShowElement('giro'); ShowElement('rr_mydetails_menu'); ShowElement('calendar_sync'); HideElement('btn_save'); HideElement('btn_cancel'); } } function CheckMyDetailsForm () { var ret = true; var err = ''; var direct_pay_err = ''; //reset $('#required_fields').show(); $('#error_msg').hide(); $('#direct_pay_err').hide(); if (!IsValidEmail (document.getElementById('i_email').value)) { alert ('Sähköpostiosoite ei ole oikeaa muotoa.'); ret = false; } //check required fields $("form[name='person_info'] input").each(function(){ if($(this).is(':required') && $(this).val() == ''){ err += $(this).closest('tr').find('th').html() + '
'; } }); //direct pay $(('form[name="person_info"]')).find('input.directpay').each(function() { if($('form[name="person_info"]').find('input[name="account_changed"]').val() == 1){ if($(this).val() && !$(this).is(':disabled') && !$(this).prop('readonly')) { switch ($(this).attr('name')) { case 'customer_account': if (validator.isValid.AccountNumber('FIN', $(this).val())) { Cookie.set($(this).attr('name') + '_is_valid', '1'); } else { Cookie.set($(this).attr('name') + '_is_valid', '0'); } break; case 'swe_bankkonto_number': if (validator.isValid.AccountNumber('SWE', $(this).val())) { Cookie.set($(this).attr('name') + '_is_valid', '1'); } else { Cookie.set($(this).attr('name') + '_is_valid', '0'); } break; case 'swe_bankgiro_paynumber': var socialSecNo = $(this).val(); socialSecNo = socialSecNo.trim(); if (socialSecNo.length > 11) { socialSecNo = socialSecNo.substr(2, 11); //strip the beginning '19'/'20' } if (socialSecNo.length == 10) { //Lisätään (-) merkki, koska tarkastaja vaatii sen socialSecNo = socialSecNo.substr(0, 6) + '-' + socialSecNo.substr(6, 10); } if (!validator.isValid.socialSecNo('SWE', socialSecNo)) { $(this).addClass('invalid'); direct_pay_err += 'Virheellinen henkilötunnus
'; } break; } } } }); var chkConfirm = $('form[name="person_info"]').find('.checkbox.directpay.confirm'); if($(chkConfirm).prop('required')){ if(!$(chkConfirm).find('input').prop('checked')){ direct_pay_err += 'Sinun tulee hyväksyä suoraveloitukseen liittyviä sopimusehtojamme'; //open tab $('form[name="person_info"] .nav-tabs').find('li.accounts a').click(); } } if(err != ''){ ret = false; $('#error_msg').html('Täytä seuraavat pakolliset kentät:
' + err); $('#error_msg').show(); $('#required_fields').hide(); } if(direct_pay_err != ''){ ret = false; $('#direct_pay_err').html(direct_pay_err); $('#direct_pay_err').show(); //open tab } return ret; } function SubmitMyDetails() { if(CheckMyDetailsForm()){ document.forms['person_info'].submit(); } } function IsValidEmail (email){ var filter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w+)+$/i if (filter.test(email)){ return true; }else{ return false; } } function SetCookie(c_name,value,expiredays,path) { var exdate=new Date(); if (!expiredays) {expiredays = 365;} exdate.setDate(exdate.getDate()+expiredays); if(path){ document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toUTCString())+";path="+path+(window.location.protocol.indexOf('https') > -1 ? ';SameSite=None;Secure' : ''); } document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toUTCString())+(window.location.protocol.indexOf('https') > -1 ? ';SameSite=None;Secure' : ''); } function GetCookie(c_name) { if (document.cookie.length>0) { c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1) { c_start=c_start + c_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length; return unescape(document.cookie.substring(c_start,c_end)); } } return ""; } function DeleteCookie( name, path, domain ) { if (GetCookie(name)) { document.cookie = name + "=" +((path) ? ";path=" + path : "") +((domain) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT"; } } function CookieEnabled() { var cookieEnabled = false; SetCookie('ktopq3op4tkq3opk', 'T'); if(GetCookie('ktopq3op4tkq3opk')) { cookieEnabled = true; } DeleteCookie('ktopq3op4tkq3opk'); return cookieEnabled; } function serialize (mixed_value) { // http://kevin.vanzonneveld.net // + original by: Arpad Ray (mailto:arpad@php.net) // + improved by: Dino // + bugfixed by: Andrej Pavlovic // + bugfixed by: Garagoth // + input by: DtTvB // (http://dt.in.th/2008-09-16.string-length-in-bytes.html) // + bugfixed by: Russell Walker (http://www.nbill.co.uk/) // + bugfixed by: Jamie Beck (http://www.terabit.ca/) // + input by: Martin (http://www.erlenwiese.de/) // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // - depends on: utf8_encode // % note: We feel the main purpose of this function should be to ease the // transport of data between php & js // % note: Aiming for PHP-compatibility, we have to translate objects to // arrays // * example 1: serialize(['Kevin', 'van', 'Zonneveld']); // * returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}' // * example 2: serialize({firstName: 'Kevin', midName: 'van', surName: // 'Zonneveld'}); // * returns 2: // 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}' var _getType = function (inp) { var type = typeof inp, match; var key; if (type == 'object' && !inp) { return 'null'; } if (type == "object") { if (!inp.constructor) { return 'object'; } var cons = inp.constructor.toString(); match = cons.match(/(\w+)\(/); if (match) { cons = match[1].toLowerCase(); } var types = ["boolean", "number", "string", "array"]; for (key in types) { if (cons == types[key]) { type = types[key]; break; } } } return type; }; var type = _getType(mixed_value); var val, ktype = ''; switch (type) { case "function": val = ""; break; case "boolean": val = "b:" + (mixed_value ? "1" : "0"); break; case "number": val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value; break; case "string": mixed_value = this.utf8_encode(mixed_value); val = "s:" + encodeURIComponent(mixed_value).replace(/%../g, 'x').length + ":\"" + mixed_value + "\""; break; case "array": case "object": val = "a"; /* * if (type == "object") { var objname = * mixed_value.constructor.toString().match(/(\w+)\(\)/); if * (objname == undefined) { return; } objname[1] = * this.serialize(objname[1]); val = "O" + objname[1].substring(1, * objname[1].length - 1); } */ var count = 0; var vals = ""; var okey; var key; for (key in mixed_value) { ktype = _getType(mixed_value[key]); if (ktype == "function") { continue; } okey = (key.match(/^[0-9]+$/) ? parseInt(key, 10) : key); vals += this.serialize(okey) + this.serialize(mixed_value[key]); count++; } val += ":" + count + ":{" + vals + "}"; break; case "undefined": // Fall-through default: // if the JS object has a property which contains a null // value, the string cannot be unserialized by PHP val = "N"; break; } if (type != "object" && type != "array") { val += ";"; } return val; } function unserialize (data) { // http://kevin.vanzonneveld.net // + original by: Arpad Ray (mailto:arpad@php.net) // + improved by: Pedro Tainha (http://www.pedrotainha.com) // + bugfixed by: dptr1988 // + revised by: d3x // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + input by: Brett Zamir (http://brett-zamir.me) // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: Chris // + improved by: James // + input by: Martin (http://www.erlenwiese.de/) // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: Le Torbi // + input by: kilops // + bugfixed by: Brett Zamir (http://brett-zamir.me) // - depends on: utf8_decode // % note: We feel the main purpose of this function should be to ease the // transport of data between php & js // % note: Aiming for PHP-compatibility, we have to translate objects to // arrays // * example 1: // unserialize('a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}'); // * returns 1: ['Kevin', 'van', 'Zonneveld'] // * example 2: // unserialize('a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}'); // * returns 2: {firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'} var that = this; var utf8Overhead = function(chr) { // http://phpjs.org/functions/unserialize:571#comment_95906 var code = chr.charCodeAt(0); if (code < 0x0080) { return 0; } if (code < 0x0800) { return 1; } return 2; }; var error = function (type, msg, filename, line){throw new that.window[type](msg, filename, line);}; var read_until = function (data, offset, stopchr){ var buf = []; var chr = data.slice(offset, offset + 1); var i = 2; while (chr != stopchr) { if ((i+offset) > data.length) { error('Error', 'Invalid'); } buf.push(chr); chr = data.slice(offset + (i - 1),offset + i); i += 1; } return [buf.length, buf.join('')]; }; var read_chrs = function (data, offset, length){ var buf; buf = []; for (var i = 0;i < length;i++){ var chr = data.slice(offset + (i - 1),offset + i); buf.push(chr); length -= utf8Overhead(chr); } return [buf.length, buf.join('')]; }; var _unserialize = function (data, offset){ var readdata; var readData; var chrs = 0; var ccount; var stringlength; var keyandchrs; var keys; if (!offset) {offset = 0;} var dtype = (data.slice(offset, offset + 1)).toLowerCase(); var dataoffset = offset + 2; var typeconvert = function(x) {return x;}; switch (dtype){ case 'i': typeconvert = function (x) {return parseInt(x, 10);}; readData = read_until(data, dataoffset, ';'); chrs = readData[0]; readdata = readData[1]; dataoffset += chrs + 1; break; case 'b': typeconvert = function (x) {return parseInt(x, 10) !== 0;}; readData = read_until(data, dataoffset, ';'); chrs = readData[0]; readdata = readData[1]; dataoffset += chrs + 1; break; case 'd': typeconvert = function (x) {return parseFloat(x);}; readData = read_until(data, dataoffset, ';'); chrs = readData[0]; readdata = readData[1]; dataoffset += chrs + 1; break; case 'n': readdata = null; break; case 's': ccount = read_until(data, dataoffset, ':'); chrs = ccount[0]; stringlength = ccount[1]; dataoffset += chrs + 2; readData = read_chrs(data, dataoffset+1, parseInt(stringlength, 10)); chrs = readData[0]; readdata = readData[1]; dataoffset += chrs + 2; if (chrs != parseInt(stringlength, 10) && chrs != readdata.length){ error('SyntaxError', 'String length mismatch'); } // Length was calculated on an utf-8 encoded string // so wait with decoding readdata = that.utf8_decode(readdata); break; case 'a': readdata = {}; keyandchrs = read_until(data, dataoffset, ':'); chrs = keyandchrs[0]; keys = keyandchrs[1]; dataoffset += chrs + 2; for (var i = 0; i < parseInt(keys, 10); i++){ var kprops = _unserialize(data, dataoffset); var kchrs = kprops[1]; var key = kprops[2]; dataoffset += kchrs; var vprops = _unserialize(data, dataoffset); var vchrs = vprops[1]; var value = vprops[2]; dataoffset += vchrs; readdata[key] = value; } dataoffset += 1; break; default: error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype); break; } return [dtype, dataoffset - offset, typeconvert(readdata)]; }; return _unserialize((data+''), 0)[2]; } function utf8_encode ( argString ) { // http://kevin.vanzonneveld.net // + original by: Webtoolkit.info (http://www.webtoolkit.info/) // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: sowberry // + tweaked by: Jack // + bugfixed by: Onno Marsman // + improved by: Yves Sucaet // + bugfixed by: Onno Marsman // + bugfixed by: Ulrich // * example 1: utf8_encode('Kevin van Zonneveld'); // * returns 1: 'Kevin van Zonneveld' var string = (argString+''); // .replace(/\r\n/g, "\n").replace(/\r/g, // "\n"); var utftext = ""; var start, end; var stringl = 0; start = end = 0; stringl = string.length; for (var n = 0; n < stringl; n++) { var c1 = string.charCodeAt(n); var enc = null; if (c1 < 128) { end++; } else if (c1 > 127 && c1 < 2048) { enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128); } else { enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128); } if (enc !== null) { if (end > start) { utftext += string.substring(start, end); } utftext += enc; start = end = n+1; } } if (end > start) { utftext += string.substring(start, string.length); } return utftext; } function utf8_decode ( str_data ) { // http://kevin.vanzonneveld.net // + original by: Webtoolkit.info (http://www.webtoolkit.info/) // + input by: Aman Gupta // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: Norman "zEh" Fuchs // + bugfixed by: hitwork // + bugfixed by: Onno Marsman // + input by: Brett Zamir (http://brett-zamir.me) // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // * example 1: utf8_decode('Kevin van Zonneveld'); // * returns 1: 'Kevin van Zonneveld' var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0; str_data += ''; while ( i < str_data.length ) { c1 = str_data.charCodeAt(i); if (c1 < 128) { tmp_arr[ac++] = String.fromCharCode(c1); i++; } else if ((c1 > 191) && (c1 < 224)) { c2 = str_data.charCodeAt(i+1); tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = str_data.charCodeAt(i+1); c3 = str_data.charCodeAt(i+2); tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return tmp_arr.join(''); } function jsleep(s){ s=s*1000; var a=true; var n=new Date(); var w; var sMS=n.getTime(); while(a){ w=new Date(); wMS=w.getTime(); if(wMS-sMS>s) a=false; } } function getElementsByClassName( strClassName, obj ) { var ar = arguments[2] || new Array(); var re = new RegExp("\\b" + strClassName + "\\b", "g"); if ( re.test(obj.className) ) { ar.push( obj ); } for ( var i = 0; i < obj.childNodes.length; i++ ) getElementsByClassName( strClassName, obj.childNodes[i], ar ); return ar; } function enableDisableByClass (idClassName,ctrlElement) { var elements = getElementsByClassName(idClassName,document.body); for(i=0;i<'+'head'+'>'); win.document.write(''+headerAndTitle+'<\/title>'); // win.document.write('<link rel="stylesheet" href="css\/style.css" // type="text\/css">'); if(css != ""){ if (css.constructor.toString().indexOf("Array")){ for(i=0;i<count(css);i++) { win.document.write('<link rel="stylesheet" type="text/css" media="all" href="index.php?get_file&case=css_file&filename=' + css[i] + '" />'); } } else { win.document.write('<link rel="stylesheet" type="text/css" media="all" href="index.php?get_file&case=css_file&filename=' + css + '" />'); } } win.document.write('<'+'\/'+'style'+'><'+'\/'+'head'+'><'+'body class="printable_tab"'+'>'); win.document.write('<h1 style="font-size:13px;text-align:left;">'+headerAndTitle+'<\/h1>'); win.document.write(content.innerHTML); win.document.write('<'+'\/'+'body'+'><'+'\/'+'html'+'>'); win.document.close(); win.print(); win.close(); } formsSubmitted = new Array; function SubmitForm(form_name, dis_elem_on_click) { var form = document.forms[form_name]; var disElem = null; var formSubmitted = false; if (form.btn_submit) { btn_submit = form.btn_submit; }else{ btn_submit = document.createElement("input"); btn_submit.style.display = 'none'; btn_submit.type = 'submit'; btn_submit.name = 'btn_submit'; btn_submit.id = 'id_btn_submit'; btn_submit.value = 'x'; $(form).append(btn_submit); //form.appendChild(btn_submit); } if (!InArray(form_name, formsSubmitted)) { btn_submit.click(); // Submit // Onko onsubmit tarkastajaa if ($(form).attr('onsubmit')) { var onSubmit = $(form).attr('onsubmit'); eval ("FuncXXX111 = function(){"+onSubmit+"}"); if (FuncXXX111()) { // Jos onsubmit tarkastaja meni läpi formSubmitted = true; } }else{ formSubmitted = true; } } if (formSubmitted) { document.body.style.cursor = 'wait'; formsSubmitted.push(form_name); } } function SubmitFormWithEnter(myfield,e) { var keycode; if (window.event){ keycode = window.event.keyCode; } else if (e){ keycode = e.which; } else{ return true; } if (keycode == 13){ SubmitForm(myfield.form.name); return false; } else{ return true; } } function CancelEvents (e) { if (!e) e = window.event; //IE9 & Other Browsers if (e.stopPropagation) { e.stopPropagation(); } //IE8 and Lower else { e.cancelBubble = true; } } function NewWindow (url, width, height, scrollbars, setFocus) { if (setFocus == undefined) { setFocus = true; } if (!width) width='600px'; if (!height) height = '800px'; if (scrollbars) { scrollbars = 'yes' }else{ scrollbars = 'no'; } var newWindow = window.open (url, 'newWindow', 'width=' + width + ', height=' + height + ', scrollbars='+scrollbars); if (setFocus) { newWindow.focus(); } } function CreatePaymentWindow () { if (Modernizr.touch) { //No new window. form target="newWindow" open new tab } else { NewWindow ('','1024px','768px', true, false); } } function ReplaceAll(txt, replace, with_this) { return txt.replace(new RegExp(replace, 'g'),with_this); } function CloseLightBox() { window.top.SexyLightbox.close(); } function InArray(needle, haystack) { for(var key in haystack){ if(needle == haystack[key]){ return true; } } return false; } function ShowPageLoading () { ShowElement('img_loading'); } function HidePageLoading () { HideElement('img_loading'); } function PositionLoadingIcon(top, left) { //moves the loading icon to the desired position (% or px) $('#img_loading').css("position", "absolute"); $('#img_loading').css("top", top); $('#img_loading').css("left", left); $('#img_loading').css("z-index", "100001"); } function TabSelect (selected) { var tabsDiv = document.getElementsByTagName ('div'); var tabsA = document.getElementsByTagName ('a'); for (var i = 0; i < tabsDiv.length; i++) { if (tabsDiv[i].className == 'tab') { if (tabsDiv[i].id == 'div_' + selected) { ShowElement(tabsDiv[i].id); }else{ HideElement(tabsDiv[i].id); } } } for (var i = 0; i < tabsA.length; i++) { if (tabsA[i].className == 'tab' || tabsA[i].className == 'tab selected') { if (tabsA[i].id == selected) { tabsA[i].className = 'tab selected'; }else{ tabsA[i].className = 'tab'; } } } } function ExpandHandler (caller) { expandArea = document.getElementById ('div_'+caller.id); if (IsVisible(expandArea)) { HideElement ('div_'+caller.id); caller.className = 'expand'; }else{ ShowElement ('div_'+caller.id); caller.className = 'expand opened'; } } function MainMenuHandler () { var currentDisplay = document.getElementById('menu_container').style.display; if (currentDisplay != 'block') { document.getElementById('menu_container').style.display = 'block'; HideElement ('content'); HideElement ('menu_action'); }else{ HideElement ('menu_container'); ShowElement ('content'); ShowElement ('menu_action'); } } function ActionMenuHandler () { if (document.getElementById('menu_action')) { var currentDisplay = document.getElementById('menu_action').style.display; if (currentDisplay != 'block') { document.getElementById('menu_action').style.display = 'block'; HideElement ('content'); HideElement ('menu_container'); }else{ HideElement ('menu_action'); ShowElement ('content'); ShowElement ('menu_container'); } } } clickcounter = 0; function PreventDblClick () { clickcounter = clickcounter +1; if (clickcounter > 1) { clickcounter = 0; return false; } return true; } function dump(obj) { var out = ''; for (var i in obj) { out += i + ": " + obj[i] + "\n"; } alert(out); // or, if you wanted to avoid alerts... var pre = document.createElement('pre'); pre.innerHTML = out; document.body.appendChild(pre) } /* Drag and drop footer (needed in edit mode) */ function drag_start(event) { var style = window.getComputedStyle(event.target, null); event.dataTransfer.setData("text/plain", (parseInt(style.getPropertyValue("left"),10) - event.clientX) + ',' + (parseInt(style.getPropertyValue("top"),10) - event.clientY)); } function drop(event) { var offset = event.dataTransfer.getData("text/plain").split(','); var dm = document.getElementById('footer'); dm.style.position = 'fixed'; dm.style.height = '45px'; dm.style.width = '1200px'; dm.style.left = event.clientX + 'px'; dm.style.top = event.clientY + 'px'; event.preventDefault(); return false; } function drag_over(event) { event.preventDefault(); return false; } function changeLanguage(lang) { var currentURL = window.location.href; //remove previous lang parameters currentURL = currentURL.replace('&lang=1', ''); currentURL = currentURL.replace('&lang=2', ''); currentURL = currentURL.replace('&lang=3', ''); window.location.href = currentURL+'&lang='+lang; } function parseDate(str){ var tmp, day, month, year, date; if (DATEFMT == 'd.m.Y') { tmp = str.split('.'); day = tmp[0]; month = tmp[1]; year = tmp[2]; } else{ tmp = str.split('-'); day = tmp[2]; month = tmp[1]; 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; } } date = new Date(year, month, day); if(!isNaN(date)){ return date; } return false; } function isContinuousContract(d){ return d.getFullYear() == 2100; } function showCustomerContract(code) { var url = 'index.php?func=rd_show_cust_contract&l_menu=0&left_banner=0&top_banner=0&shopping_cart=0&main_menu=0&show_header=0&code='+code; var rs = $.get(url); rs.success(function (html) { var modal = { title: 'Näytä sopimustiedot', body: html, buttons: {accept: 'Ok', reject: 'Keskeytä'} }; showConfirmation(null, modal); //hide modal cancel button $('#dialog-confirmation .user-reject').hide(); }); } function showPageInModal(title, url, buttons) { var rs = $.get(url); rs.success(function (html) { var modal = { title: title, body: html, buttons: {} }; if(typeof(buttons.accept) !== 'undefined'){ modal.buttons.accept = buttons.accept; } if(typeof(buttons.reject) !== 'undefined'){ modal.buttons.reject = buttons.reject; } showConfirmation(null, modal); }); } //FRIEND BOOKING function showFriendBooking(bookingUrl, module, amIIn) { try { bookingUrl = encodeURI(bookingUrl); var url = 'index.php?func=customer_relationship&l_menu=0&left_banner=0&top_banner=0&shopping_cart=0&main_menu=0&show_header=0&is_'+ module +'=1&select_mode=multiple&amIIn='+amIIn+'&do_rsv_url=' + bookingUrl; $.get(url, function (html) { var modal = { title: 'Valitse osallistujat', body: html, buttons: {accept: '', reject: 'Sulje'} }; showConfirmation( function(status){ if(status) { //do nothing } return false; }, modal); //hide modal ok button $('#dialog-confirmation .user-accept').hide(); //hide 'powered by' $('#dialog-confirmation #powered_by').hide(); }); } catch (e) { console.log('Error in showFriendBooking: '+ e.message); } } function getFriendsToBook() { var friendsToBook = []; $('.friend_booking').each(function () { if ($(this).prop('checked')) { friendsToBook.push($(this).val()); } }); return friendsToBook; } function getFriendBookingQuerystring() { try { var ret = ''; var friendsToBook = getFriendsToBook(); if(friendsToBook.length > 0) { for(var friend in friendsToBook) { ret += 'customer_code[]=' + friendsToBook[friend] + '&'; } } if (ret != '') { ret = 'friend_booking=1&' + ret; } return ret; } catch (e) { console.log('Error in getFriendBookingQuerystring: '+ e.message); } } function getStopContractInfoText(reasonNumber) { switch(reasonNumber) { case '1': return '<div id="stop_contract_info_text_' + reasonNumber + '"></div>'; break; case '2': return '<div id="stop_contract_info_text_' + reasonNumber + '"></div>'; break; case '3': return '<div id="stop_contract_info_text_' + reasonNumber + '"></div>'; break; case '4': return '<div id="stop_contract_info_text_' + reasonNumber + '"></div>'; break; case '5': return '<div id="stop_contract_info_text_' + reasonNumber + '"></div>'; break; case 'X': return '<div id="stop_contract_info_text_' + reasonNumber + '"></div>'; break; } return getCustomStopContractInfoText(reasonNumber); //should never come here, custom function } function stopContractSubmit() { if ($('#show_info_text').length) { var modal = { title: 'Ennen kun lähdet...', body: getStopContractInfoText($('#stop_contract_reason').val()), buttons: {accept: 'Haluan irtisanoa asiakkuuteni', reject: 'Haluan jatkaa asiakkuutta'} }; showConfirmation(function(status){ if (status) { return document.forms['frm_stop_contract'].submit(); } else { return false; } }, modal); return false; } else { return document.forms['frm_stop_contract'].submit(); } } function getParsedQueryString () { var parsedParameters = {}, uriParameters = location.search.substr(1).split('&'); for (var i = 0; i < uriParameters.length; i++) { var parameter = uriParameters[i].split('='); parsedParameters[parameter[0]] = decodeURIComponent(parameter[1]); } return parsedParameters; } function selectAllRsvRows(checked) { $('.select_rsv').prop('checked', checked); updateReservationPayButton(); } function selectRsvRow() { updateReservationPayButton(); } function updateReservationPayButton() { var rsv_count = 0; var total = 0; var currency = ''; $('.select_rsv').each(function() { if ($(this).prop('checked')) { rsv_count++; total += parseFloat($(this).closest('tr').data('total')); if ($(this).closest('tr').data('currency')) { currency = $(this).closest('tr').data('currency'); } } }); if (total > 0) { $('button[name="rsv_pay"]').html('Maksa vuorot <span class="badge">' + rsv_count + '</span> ' + total.toFixed(2) + ' '+currency); $('button[name="rsv_pay"]').prop('disabled', false); } else { $('button[name="rsv_pay"]').html('Maksa vuorot'); $('button[name="rsv_pay"]').prop('disabled', true); } }