﻿var divDlgLast='';


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';
}




// For IE, toggle visiblity of certain controls which are rendered as windows 
// (They will unfortunately sit atop our modal dialog box)
function inf(h){

    tag=document.getElementsByTagName('select');
    for(i=tag.length-1;i>=0;i--)
        if(tag[i].getAttribute('propReq')==undefined)
            tag[i].style.visibility=h;
    return 0;    

    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;
}


//Toggle the background div
function ol(d){

    var p='px';
    var obol=$('ol');
    
    if(d=='block'){ 
        obol.style.height=pageHeight()+p;
        obol.style.width=pageWidth()+p;
        obol.style.top=posTop()+p;
        obol.style.left=posLeft()+p;
    }
    obol.style.display=d;
}



//Show the dialog box
function sm(obl, wd, ht){

    var h='hidden';
    var b='block';
    var p='px';
   
    // Setup and show the background div
    ol(b);
    
    var obbx=$(obl);
    divDlgLast=obl;
    
    // Set div to display='block' so that we can read offsetWidth and offsetHeight (otherwise =0) but first turn visibility off
    obbx.style.visibility='hidden';
    obbx.style.display=b;
        
    if(!(wd>0)) wd=obbx.offsetWidth; else obbx.style.width=wd+p;
    if(!(ht>0)) ht=obbx.offsetHeight; else obbx.style.height=ht+p;

    inf(h); //For ie, hide rendered-as-windows controls
    
    // Position and show our dialog DIV
    var tp=posTop()+((pageHeight()-ht)/2)-12;
    var lt=posLeft()+((pageWidth()-wd)/2)-12;
    obbx.style.top=(tp<0?0:tp)+p;
    obbx.style.left=(lt<0?0:lt)+p;
    
    inf(h); //For ie, hide rendered-as-windows controls
    obbx.style.visibility='visible';
    return false;
}

//Hide the modal box
function hm(){
    $('ol').style.display='none';
    $(divDlgLast).style.display='none';
    $(divDlgLast).style.width='auto';
    $(divDlgLast).style.height='auto';
    inf('visible');
}


function initmb(){

    // Set windows events which will reposition and/or resize background div when browser is scrolled or resized
    window.onscroll = scrollFix; 
    window.onresize = sizeFix;
    return 0;
    
    // Dynamically create Overlay DIV (background div which will have shaded PNG file as background image)
    var obody=document.getElementsByTagName('body')[0];
    var frag=document.createDocumentFragment();
    var obol=document.createElement('div');
    obol.setAttribute('id','ol');
    obol.style.display='none';
    obol.style.position='absolute';
    obol.style.top=0;
    obol.style.left=0;
    obol.style.zIndex=998;
    obol.style.width='100%';
    frag.appendChild(obol);
    
    
}


                  


