// Modal Dialog Box
// copyright 8th July 2006 by Stephen Chapman
// http://javascript.about.com/
// permission to use this Javascript on your web page is granted
// provided that all of the code in this script (including these
// comments) is used without any alteration
var topPanel = "143";
var leftPanel = "130";

var topPanelFD = "143";
var leftPanelFD = "230";

var topRef = 0;
var leftRef = 0;

function pageWidth() {
    return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

function pageHeight() {
    return window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null;
}

function posLeft() {
    return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

function posTop() {
    return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}
function $(x) {
    return document.getElementById(x);
}
function scrollFix() {
    var obol = $('ol');
    obol.style.top = posTop() + 'px';
    obol.style.left = posLeft() + 'px';
}
function sizeFix() {
    var obol = $('ol');
    obol.style.height = pageHeight() + 'px';
    obol.style.width = pageWidth() + 'px';
}
function scrollFixFD() {
    scrollFix();
    var obol = $('olFD');
    obol.style.top = posTop() + 'px';
    obol.style.left = posLeft() + 'px';
}
function sizeFixFD() {
    sizeFix();
    var obol = $('olFD');
    obol.style.height = pageHeight() + 'px';
    obol.style.width = pageWidth() + 'px';
}

function kp(e) {
    ky = e ? e.which : event.keyCode;
    if (ky == 88 || ky == 120)
        hm();
    return false;
}

function inf(h) {
    tag = document.getElementsByTagName('select');

    for (i = tag.length - 1; i >= 0; i--)
        tag[i].style.visibility = h;

    tag = document.getElementsByTagName('iframe');

    for (i = tag.length - 1; i >= 0; i--)
        tag[i].style.visibility = h;

    tag = document.getElementsByTagName('object');

    for (i = tag.length - 1; i >= 0; i--)
        tag[i].style.visibility = h;

}

function getModalStyle() {
    //if (isIE6) {
    //    var dd = getDocumentDimensions();
    //    return { 'background-color': o.modalColor, 'height': dd[0], 'left': getDistanceToBodyFromLeft(), 'opacity': 0, 'position': 'absolute', 'top': 0, 'width': dd[1], 'z-index': o.zIndex - 1 };
    //}
    //else
    return { backgroundColor: '#000', height: '100%', left: 0, opacity: 0, position: 'fixed', top: 0, width: '100%', zIndex: 1 };
}

function sm(wd, ht, positionLeft) //20090914
{

    var h = 'hidden';
    var b = 'block';
    var p = 'px';
    var obol = $('ol');

    obol.style.height = pageHeight() + p;
    obol.style.width = pageWidth() + p;
    obol.style.top = posTop() + p;
    obol.style.left = posLeft() + p;
    //obol.style.display=b;
    var modal = new Element('div', { 'id': 'bModal' });
    modal.setStyle(getModalStyle());
    $$('body')[0].insert({ top: modal });
    modal.fade({ duration: 0.25, from: 0, to: 0.5 });

    var tp = posTop() + ((pageHeight() - ht) / 2) - 12;
    var lt = posLeft() + ((pageWidth() - wd) / 2) - 12;

    var obbx = $('mbox');
    obbx.style.top = topPanel + p;

    if (positionLeft <= 0)
        obbx.style.left = leftPanel + p;
    else
        obbx.style.left = positionLeft + p;

    if (wd == null)
        obbx.style.width = "auto";
    else
        obbx.style.width = wd + p;

    if (ht == null)
        obbx.style.height = "auto";
    else
        obbx.style.height = ht + p;

    obbx.style.position = "absolute";
    obbx.style.display = b;
    return false;

}

function smFD(wd, ht, positionLeft) //20090914
{

    var h = 'hidden';
    var b = 'block';
    var p = 'px';
    var obol = $('olFD');

    obol.style.height = pageHeight() + p;
    obol.style.width = pageWidth() + p;
    obol.style.top = posTop() + p;
    obol.style.left = posLeft() + p;
    obol.style.display = b;
    var tp = posTop() + ((pageHeight() - ht) / 2) - 12;
    var lt = posLeft() + ((pageWidth() - wd) / 2) - 12;

    var obbx = $('mboxFD');
    obbx.style.top = topPanelFD + p;

    if (positionLeft <= 0)
        obbx.style.left = leftPanelFD + p;
    else
        obbx.style.left = positionLeft + p;

    if (wd == null)
        obbx.style.width = "auto";
    else
        obbx.style.width = wd + p;

    if (ht == null)
        obbx.style.height = "auto";
    else
        obbx.style.height = ht + p;

    obbx.style.position = "absolute";
    obbx.style.display = b;
    return false;
}


function hm() {
    $('bModal').remove();
    var v = 'visible';
    var n = 'none';
    //$('ol').style.display=n;
    $('mbox').style.display = n;
    inf(v);
    document.onkeypress = '';
}

function hmFD() {
    var v = 'visible';
    var n = 'none';
    $('olFD').style.display = n;
    $('mboxFD').style.display = n;
    inf(v);
    document.onkeypress = '';
}

//function initmb(objdiv,wd,ht)
function initmb(objdiv, wd, ht, positionLeft)//20090914
{
    if ($('ol') != null) {
        if (objdiv.style.display == "none")
            objdiv.style.display = "block";
    } else {
        var ab = 'absolute';
        var n = 'none';
        var obody = document.getElementsByTagName('body')[0];
        var frag = document.createDocumentFragment();
        var obol = document.createElement('div');
        obol.setAttribute('id', 'ol');
        obol.style.display = n;
        obol.style.position = ab;
        obol.style.top = 0;
        obol.style.left = 0;
        obol.style.zIndex = 9908;
        obol.style.width = '100%';
        frag.appendChild(obol);
        var obbx = document.createElement('div');
        obbx.setAttribute('id', 'mbox');
        obbx.style.display = n;
        obbx.style.position = ab;
        obbx.style.zIndex = 9909;
        var obl = document.createElement('span');
        obbx.appendChild(obl);
        if (objdiv.style.display == "none")
            objdiv.style.display = "block";
        obl.appendChild(objdiv);
        frag.insertBefore(obbx, obol.nextSibling);
        obody.insertBefore(frag, obody.firstChild);
        window.onscroll = scrollFix;
        window.onresize = sizeFix;
    }
    sm(wd, ht, positionLeft);
}

function initmbFD(objdiv, wd, ht, positionLeft)//20090914
{
    var ab = 'absolute';
    var n = 'none';
    var obody = document.getElementsByTagName('body')[0];
    var frag = document.createDocumentFragment();
    var obol = document.createElement('div');
    obol.setAttribute('id', 'olFD');
    obol.style.display = n;
    obol.style.position = ab;
    obol.style.top = 0;
    obol.style.left = 0;
    obol.style.zIndex = 9910; //998
    obol.style.width = '100%';
    frag.appendChild(obol);
    var obbx = document.createElement('div');
    obbx.setAttribute('id', 'mboxFD');
    obbx.style.display = n;
    obbx.style.position = ab;
    obbx.style.zIndex = 9911; //999
    var obl = document.createElement('span');
    obbx.appendChild(obl);
    //var obbxd=document.createElement('div');
    //obbxd.setAttribute('id','mbd');
    if (objdiv.style.display == "none")
        objdiv.style.display = "block";

    obl.appendChild(objdiv); //obl.appendChild(obbxd);
    frag.insertBefore(obbx, obol.nextSibling);
    obody.insertBefore(frag, obody.firstChild);
    window.onscroll = scrollFixFD;
    window.onresize = sizeFixFD;
    //sm(wd,ht);
    smFD(wd, ht, positionLeft); //20090914

}


//window.onload = initmb;

                  
