﻿function $(id) {
    return document.getElementById(id);
}
Function.prototype.bind = function() {
    if (arguments.length < 2 && arguments[0] == null) {
        return this;
    }
    var __method = this, args = $A(arguments), object = args.shift();
    return function() {
        return __method.apply(object, args.concat($A(arguments)));
    };
};

var isArray = function(testVar) {
    return Array == testVar.constructor ? 1 : String != testVar.constructor && null != testVar.length && !testVar.alert && !testVar.nodeType ? 2 : 0;
};

var $A = function(variable) {
    switch (isArray(variable)) {
        case 1:
            return variable;
        case 2:
            var arr = [], i = -1, len = variable.length;
            while (++i < len) {
                arr[i] = variable[i];
            }
            return arr;
        default:
            return [variable];
    }

};


var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);

addEvent = function(elm, evType, func, useCapture) {
    if (typeof useCapture == 'undefined') {
        useCapture = false;
    }
    if (typeof evType == 'undefined') {
        evType = 'click';
    }
    if (elm.addEventListener) {
        elm.addEventListener(evType, func, useCapture);
        return true;
    }
    else if (elm.attachEvent) {
        var r = elm.attachEvent('on' + evType, func);
        return true;
    }
    else {
        elm['on' + evType] = func;
    }
};



Array.prototype.push = function(value) {
    this[this.length] = value;
    return this.length;
}
function in_array(needle, haystack) {
    if (typeof needle == 'string' || typeof needle == 'number') {
        for (var i in haystack) {
            if (haystack[i] == needle) {
                return true;
            }
        }
    }
    return false;
}
function getUrlParam(name) {
    var params = location.search;
    if (!params) { return; }
    params = params.substring(1);
    var tmp, reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "gi");
    tmp = reg.exec(params);
    if (tmp) { return (tmp[2]); }
    return null;
}
function getWindowSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return ([myWidth, myHeight]);
}
function setTab(name, cursel, n) {
    for (i = 1; i <= n; i++) {
        var menu = $("menu_"+ name + i);
        var con = $("con_" + name + "_" + i);
        menu.className = i == cursel ? "hover" : "";
        con.style.display = i == cursel ? "block" : "none";
    }
} 