function addEvent(obj ,evt, fnc)
    {
    if (obj.addEventListener)
        obj.addEventListener(evt,fnc,false);
    else if (obj.attachEvent)
        obj.attachEvent('on'+evt,fnc);
    else
        return false;
    return true;
    }

function removeEvent(obj ,evt, fnc)
    {
    if (obj.removeEventListener)
        obj.removeEventListener(evt,fnc,false);
    else if (obj.detachEvent)
        obj.detachEvent('on'+evt,fnc);
    else
        return false;
    return true;
    }

    //----------

function appendElement(node,tag,id,htm)
    {
    var ne = document.createElement(tag);
    if(id) ne.id = id;
    if(htm) ne.innerHTML = htm;
    node.appendChild(ne);
    }

    //----------

function showPopup(p)
    {
    greyout(true);
    document.getElementById(p).style.display = 'block';
    }

function hidePopup(p)
    {
    greyout(false);
    document.getElementById(p).style.display = 'none';
    }

    //----------

function greyout(d,z)
    {
    var obj = document.getElementById('greyout');

    if(!obj)
        {
        appendElement(document.body,'div','greyout');
        obj = document.getElementById('greyout');
        obj.style.position = 'absolute';
        obj.style.top = '0px';
        obj.style.left = '0px';
        obj.style.background = '#000';
        obj.style.display = 'none';
        obj.style.opacity = '.7';
        obj.style.filter = 'alpha(opacity=70)';
        }
       
    if(d)
        {
        var ch = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
        var cw = document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
        var sh = document.documentElement.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight;
        if(document.body.scrollHeight) sh = Math.max(sh,document.body.scrollHeight)
        var sw = document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.body.scrollWidth;
        if(document.body.scrollWidth) sh = Math.max(sh,document.body.scrollWidth)
        var wh = window.innerHeight ? window.innerHeight : document.body.offsetHeight;
        if(!z){ z = 50 }
        //obj.style.zIndex = z;
        /*obj.style.height = Math.max(wh,Math.max(sh,ch))+'px';
        obj.style.width  = Math.max(sw,cw)+'px';*/
        obj.style.height = document.body.clientHeight+'px';
        obj.style.width  = document.body.clientWidth+'px';
        obj.style.zIndex = 50;
        
        $('#greyout').fadeIn(500);
        }
    else
        $('#greyout').fadeOut(500);

    }

    //----------
