﻿

function OpenRadWindow(url, title, width, height) {
    var radWindow = window.top.radopen(url, null);

    radWindow.SetSize(width, height);
    radWindow.SetTitle(title);
    radWindow.Center();
}

function enableTab(id) {    
    document.getElementById(id).className = "act";
    document.getElementById(id + "Content").style.display = "block";
}

function disableTab(id) {    
    document.getElementById(id).className = null;
    document.getElementById(id + "Content").style.display = "none";
}

function toggle(num) {
    for (i = 1; i < 1000; i++) {

        answer = document.getElementById("answer" + i);
        question = document.getElementById("question" + i);

        state = "none";
        if (i == num) state = "block";
        if (answer == null) break;

        if (i == num && answer.style.display == state) state = state == "none" ? "block" : "none";
        if (state == "none") {
            question.setAttribute("class", "faqQuestion");
        }
        else {
            question.setAttribute("class", "faqQuestionAct");
        }     
        answer.style.display = state;

    }
}


function newWin(href) {
    window.open(href);
    return false;
}

function login() 
{
    html = '';
    html += '<form action="https://www.multipluscard.hr/Account/LogOn" method="post" id="loginForm" style="height:1px;overflow:hidden;">';    
    html += '<input type="hidden" name="UserName" value="' + document.getElementById("UserName").value + '"/>';
    html += '<input type="hidden" name="Password" value="' + document.getElementById("Password").value + '"/>';
    html += '</form>';
    document.getElementById("fd").innerHTML = html;
    document.getElementById("loginForm").submit();
}

function register() {
    html = '';
    html += '<form action="https://www.multipluscard.hr/Account/Register" method="post" id="registerForm" style="height:1px;overflow:hidden;">';    
    html += '<input type="hidden" name="CardCode" value="' + document.getElementById("CardCode").value + '"/>';
    html += '<input type="hidden" name="UserName" value="' + document.getElementById("UserName").value + '"/>';
    html += '</form>';
    document.getElementById("fd").innerHTML = html;
    document.getElementById("registerForm").submit();
}


var siteRoot = '';

function setSiteRoot(value) {
    siteRoot = value;
}

function generatePostback(controlId, e) {
    if (e.keyCode != 13) return;

    __doPostBack(controlId, '');
}
function generateClientClick(controlId, e) {
    if (e.keyCode != 13) return;

    //document.getElementById(controlId).click();
    raiseEventClick(document.getElementById(controlId));
}

function raiseEvent(element, event) {
    if (document.createEvent) {
        var eventObject = document.createEvent('MouseEvents');
        eventObject.initEvent(event, true, false);
        element.dispatchEvent(eventObject);
    }
    else if (document.createEventObject) {
        element.fireEvent('on' + event);
    }
}
function raiseEventClick(element) {
    raiseEvent(element, 'click');
}

function cancelEventBubbling(e) {
    if (!e) e = window.event;
    if (e) e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}

function stringEndsWith(testString, endingString) {
    if (endingString.length > testString.length) return false;
    return testString.indexOf(endingString) == (testString.length - endingString.length);
}

function checkIntegerValue(element) {
    val = parseInt(element.value);
    if (element.value != "") {
        if (isNaN(val)) {
            val = "";
        }
        element.value = val;
    }
}


/*
function checkType(obj, defaultValue) {    
    if (obj.value != defaultValue) {
        obj.setAttribute('type', 'password');        
    } else {
        obj.setAttribute('type', 'text');    
    }
    obj.focus();
}
*/


// Example 2 (JS part 1)
function changeInputType(
  oldElm, // a reference to the input element
  iType, // value of the type property: 'text' or 'password'
  iValue, // the default value, set to 'password' in the demo
  blankValue, // true if the value should be empty, false otherwise
  noFocus) {  // set to true if the element should not be given focus
    if (!oldElm || !oldElm.parentNode || (iType.length < 4) ||
    !document.getElementById || !document.createElement) 
    {

        return;
    }

    var isMSIE = /*@cc_on!@*/false; //http://dean.edwards.name/weblog/2007/03/sniff/

    if (!isMSIE) {
        var newElm = document.createElement('input');
        newElm.type = iType;
    } else {
        var newElm = document.createElement('span');
        newElm.innerHTML = '<input type="' + iType + '" name="' + oldElm.name + '">';
        newElm = newElm.firstChild;
    }
    var props = ['name', 'id', 'className', 'size', 'tabIndex', 'accessKey'];
    for (var i = 0, l = props.length; i < l; i++) {
        if (oldElm[props[i]]) newElm[props[i]] = oldElm[props[i]];
    }
    newElm.onfocus = function() {
        return function() {
            if (this.hasFocus) return;
            var newElm = changeInputType(this, 'password', iValue,
      (this.value.toLowerCase() == iValue.toLowerCase()) ? true : false);
            if (newElm) newElm.hasFocus = true;
        } 
    } ();
    newElm.onblur = function() {
        return function() {
            if (this.hasFocus)
                if (this.value == '' || (this.value.toLowerCase() == iValue.toLowerCase())) {
                changeInputType(this, 'text', iValue, false, true);
            }
        } 
    } ();
    // hasFocus is to prevent a loop where onfocus is triggered over and over again
    newElm.hasFocus = false;
    // some browsers need the value set before the element is added to the page
    // while others need it set after
    if (!blankValue) newElm.value = iValue;
    oldElm.parentNode.replaceChild(newElm, oldElm);
    if (!isMSIE && !blankValue) newElm.value = iValue;
    if (!noFocus || typeof (noFocus) == 'undefined') {
        window.tempElm = newElm;
        setTimeout("tempElm.hasFocus=true;tempElm.focus();", 1);
    }
    return newElm;
}


// Example 2 (JS part 2)
LoadHandler.add(function() {
    // Normally I use object detection, however, in this case since I need to 
    // detect Konqueror and Safari which don't have unique objects,
    // I will use the user agent string to detect them. Only use this type of 
    // detection as a last resort.
    // I'm doing this because example 2 crashes Konqueror 3.4 and Safari 1.0

    var ua = navigator.userAgent.toLowerCase();
    if (!((ua.indexOf('konqueror') != -1) && /khtml\/3\.[0-4]/.test(ua)) &&
    !(((ua.indexOf('safari') != -1) && !window.print))) {

        // Set the third value to the text you want to appear in the field.
        changeInputType(document.forms[0].Password, 'text', 'Lozinka...', false, true);
    }
});

