function readKey(e)  {
    var keynum

    if(window.event) {
        keynum = e.keyCode
    }
    else if(e.which) {
        keynum = e.which
    }

    return keynum;
}

function getInt(a) {

    a = parseInt(a);

    if (isNaN(a)) a = 0;

    return a;
}

function getCookie(name) {
        var cookie = " " + document.cookie;
        var search = " " + name + "=";
        var setStr = null;
        var offset = 0;
        var end = 0;
        if (cookie.length > 0) {
                offset = cookie.indexOf(search);
                if (offset != -1) {
                        offset += search.length;
                        end = cookie.indexOf(";", offset)
                        if (end == -1) {
                                end = cookie.length;
                        }
                        setStr = unescape(cookie.substring(offset, end));
                }
        }
        return(setStr);
}

function setCookie (name, value, expires, path, domain, secure) {

      document.cookie = name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires : "") +
        ((path) ? "; path=" + path : "; path=/") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function var_dump(vr,recursive,indent) {

    var result = "";

    if (!indent) indent = "";

    if (typeof(vr) == 'object') {

        result = result + "\n";   

        for (key in vr) {
            if (recursive) {
                result = result + indent + "[" + key + "]=>" + var_dump(vr[key], indent+"\t")+"\n";
            } else {
                result = result + "[" + key + "]=>" + vr[key] + "\n";
            }
        }

    } else {

        result = vr;
    }

    return result;
}

function serialize(vr) {

    var result = "";
    var items = Array();

    if (typeof(vr) == 'object') {

        result += "{";

        for (key in vr) {
            items[items.length] = key + ":" + serialize(vr[key]);
        }

        result += items.join(",");

        result += "}";

    } else {

        result = escape(vr);
    }

    return result;
}

function urlenc(str) {
    var result = "";
    var a;
    
    if (typeof(str) != "string") return "";

    for (i=0;i<str.length;i++) {

        a=str.charCodeAt(i);

        result += "x" + a;
    }

    return result;
}

function urldec(str) {
    var result = "";
    var a, l; 
    var s = "";

    if (typeof(str) != "string") return "";

    l = str.split("x");

    for (key in l) {

        if (!l[key].length) continue;
        a = parseInt(l[key]);

        result += String.fromCharCode(a);
    }

    return result;
}

function getInt(val) {

    var rv = parseInt(val);
    if (isNaN(rv)) rv = 0;

    return rv;
}

function getFloat(val) {

    var rv = parseFloat(val);
    if (isNaN(rv)) rv = 0;

    return rv;
}

function trim(val) {
    var i, v, rv;

    v = val.split(' ');
    rv = Array();
    for (i=0; i<v.length; i++) {
        if (v[i].length) rv.push(v[i]);
    }

    return rv.join(' ');
}

function chr(code) {
    return String.fromCharCode(code);
}

typeof(indexOf) == 'function' || (indexOf = function(a, v) {
       for(var i = a.length; i-- && a[i] !== v;);
       return i;
});

function change_lang(lang) {

    setCookie('lang', lang, '', '/', 'data-bank.com.ua');

    window.location.replace('/');
    //window.setTimeout('history.go(0)', 3000);
}

function dialog_show(url, width, height, fixed) {

    var qpos;

    popup_name = 'popup'+url.replace(/\//g,'_').replace(/\./g,'_');
    qpos = popup_name.indexOf('?');
    if (qpos != -1) popup_name = popup_name.substring(0,qpos);

    if (eval('typeof('+popup_name+')') !== 'undefined') {
        eval(popup_name+'.close()');
    }

    if (!fixed) {
        var sb = 1;
    } else {
        var sb = 0;
    }

    if (width && height) {
        eval(popup_name+'=window.open(url, \''+popup_name+'\', \'fullscreen=0, width=\'+width+\', height=\'+height+\', resizable=1, status=0, scrollbars=\'+sb)');
    } else {
        eval(popup_name+'=window.open(url, \''+popup_name+'\', \'fullscreen=1, resizable=1, status=0, scrollbars=\'+sb)');
    }
    eval(popup_name+'.focus()');
}

function callDialog(url, width, height, fixed) {

    dialog_show(url, width, height, fixed);

    return false;
}


