var BASE = '';

function setBase(newBase) {

    BASE = newBase;

}

//vars include directories,location,resizable,menubar,toolbar,scrollbars,status
function windowopen(url, width, height, vars) {

    if(width == null) width = 300;
    if(height == null) height = 300;
    if(vars == null) vars = 'resizable,scrollbars';

    vars += ',width=' + width + ',height=' + height;

    var currentTime = new Date();

    window.open(url, currentTime.getTime(), vars);

    return false;

}

function getParam(varName, urlToParse) {

    if(urlToParse == null) urlToParse = document.location;

    var toReturn = '';

    var urlHalves = String(urlToParse).split('?');

    if(urlHalves[1]) {
        var urlVars = urlHalves[1].split('&');
        for(i=0; i<=(urlVars.length); i++) {
            if(urlVars[i]){
                var urlVarPair = urlVars[i].split('=');
                if (urlVarPair[0] && urlVarPair[0] == varName) {
                    toReturn = urlVarPair[1];
                }
            }
        }
    }

    return toReturn;

}

function getPart(number) {

    var toReturn = '';

    var location = String(document.location);
    location = location.replace(BASE, '');

    var Rs = location.split('/');

    //get rid of the last GET variable if its there
    var last = Rs.last();
    if(last.startsWith('?')) {
        Rs.splice(-1);
    }

    number--;

    if(Rs[number]) {
        return Rs[number];
    } else {
        return '';
    }

}

function redirect(page) {

    document.location.href = page;

    return false;

}

function goBack() {

    history.go(-1);

    return false;

}

var Cookie = {
    set: function(name, value, daysToExpire) {
        var expire = '';
        if (daysToExpire != undefined) {
            var d = new Date();
            d.setTime(d.getTime() + (86400000 * parseFloat(daysToExpire)));
            expire = '; expires=' + d.toGMTString();
        }
        return (document.cookie = escape(name) + '=' + escape(value || '') + expire);
    },
    get: function(name) {
        var cookie = document.cookie.match(new RegExp('(^|;)\s*' + escape(name) + '=([^;\s]*)'));
        return (cookie ? unescape(cookie[2]) : null);
    },
    erase: function(name) {
        var cookie = Cookie.get(name) || true;
        Cookie.set(name, '', -1);
        return cookie;
    }
};


function html_entity_decode(s) {
    var t=document.createElement('textarea');
    t.innerHTML = s;
    var v = t.value;
    //t.parentNode.removeChild(t);
    return v;
}


//Apply tooltips automatically
jQuery(function() {

    jQuery('.tooltip').hover(

        function(e) {

            var theTitle = jQuery(this).attr('title');
            if(!theTitle) return;

            this.t = theTitle;

            jQuery(this).removeAttr('title');

            theTitle = theTitle.replace(/(\s{1}\|{1}\s{1})/g, '<br />');

            jQuery('body').append('<p id="tooltip" style="position: absolute">' + theTitle + '</p>');

        },

        function() {

            var theTitle = this.t;
            if(!theTitle) return;

            this.title = theTitle;

            jQuery('#tooltip').remove();

        }

    );

    jQuery('.tooltip').mousemove(function(e) {

        jQuery('#tooltip')
            .css('top', (e.pageY - 10) + 'px')
            .css('left', (e.pageX + 20) + 'px');

    });

});



//Automatically add zebra's
jQuery(function() {

   jQuery('.zebra tr:nth-child(even)').addClass('even');
    jQuery('.zebra tr:nth-child(odd)').addClass('odd');

});





