﻿function unob(o, e) {
    var link = '';
    for (i = 0; i < (e.length / 2); i++)
        link += String.fromCharCode((e.charCodeAt(i * 2) - 97) * 16 + e.charCodeAt(i * 2 + 1) - 97);
    document.location = link;        
    return false;
}

/*
showpopup

popid = ID of popup
pos = 4 char position
off = optional x,y offset
relx = position relative to this in X
rely = position relative to this in Y


rely is optional, defaults to relx

4 pos char code = (l|m|r)(l|m|r)(t|m|b)(t|m|b)
i.e. mmbt = Middle popup Middle relx Bottom popup Top rely

showpopup('popid','mmtb',{x:0,y:-10},this,this);
    
    
*/

function showpopup(popid, pos, off, relx, rely) {
    var p = document.getElementById(popid);

    var r;
    
    if (typeof relx == 'string')
        r = document.getElementById(relx);
    else
        r = relx;

    x = 0;

    for (e = r; e; e = e.offsetParent) {
        x += e.offsetLeft;
    }

    switch (pos.substring(0, 1)) {
        case 'm':
            x -= p.offsetWidth / 2;
            break;
        case 'r':
            x -= p.offsetWidth;
            break;   
    }

    switch (pos.substring(1, 2)) {
        case 'm':
            x += r.offsetWidth / 2;
            break;
        case 'r':
            x += r.offsetWidth;
            break;
    }

    rely = rely || relx;
    
    if (typeof rely == 'string')
        r = document.getElementById(rely);
    else
        r = rely;

    y = 0;

    for (e = r; e; e = e.offsetParent) {
        y += e.offsetTop;
    }

    switch (pos.substring(2, 3)) {
        case 'm':
            y -= p.offsetHeight / 2;
            break;
        case 'b':
            y -= p.offsetHeight;
            break;
    }
    
    switch (pos.substring(3, 4)) {
        case 'm':
            y += r.offsetHeight / 2;
            break;
        case 'b':
            y += r.offsetHeight;
            break;
    }

    if (off) {
        x += off.x;
        y += off.y;
    }
    
    p.style.left = x + 'px';
    p.style.top = y + 'px';
    p.className = p.className.replace('popup', 'popup-active');
}

function hidepopup(id) {
    var p = document.getElementById(id);
    p.className = p.className.replace('popup-active', 'popup');
}
