var popupinit = false;
function initScreenOverlay() { 

    var msgbox = document.getElementById('popupDiv');
    if (msgbox == null
          || msgbox.style.display == 'none') {
       return;
    }

    if (!popupinit) {
       popupinit = true;
       addEvent(window,"resize",initScreenOverlay,false);
       addEvent(window,"scroll",initScreenOverlay,false);
    }
    var footerdiv = document.getElementById('Footer');
    var bottomOffset = document.body.clientWidth;
    if (footerdiv != null) {
       bottomOffset =  footerdiv.offsetTop;
    }
    bottomOffset = bottomOffset - 80;
    if (msgbox.style.display != 'none') {
        var offsetht = msgbox.offsetHeight;
        var offsetwd = msgbox.offsetWidth;

        var toppos =  Math.round(((document.body.clientHeight - offsetht) / 2.5) + document.body.scrollTop);
        var leftpos =  Math.round((document.body.clientWidth - offsetwd) / 4);



        var totalht = toppos +  offsetht;
        if (totalht > bottomOffset ) {
           toppos = toppos - (totalht - bottomOffset);
        }
        if (toppos < 188) {
           toppos = 188;
        }
        msgbox.style.top = toppos + "px";


        var totalwd = leftpos +  offsetwd;
        if (totalwd > 750) {
           leftpos = leftpos -(totalwd -725);
        }

        msgbox.style.left  = leftpos + "px" ;

    }
} 
 


function resetPopupFrame() { 
    var msgbox = document.getElementById('popupFrame');
    if (msgbox != null) {
       document.getElementById('popupFrame').src = '/shared/components/blank.jsp';
    }

}

function openHelp(url,e)
{
 w = 474;
 h = 408;
 openWin(url, e, w, h, true);
}

function openHelp2(url,e,v) {

   w = 474;
   h = v;
   openWin(url, e, w, h, true);
}


var cWin;
function openNewWin(url,name,w,h,scroll,chrome) {
	if(!arguments[5] )  {
		chrome = 'no';
	}
	var att = 'width='+ w +',height='+ h +',left=50,top=50,scrollbars='+ scroll +',resizable=yes,toolbar=' + chrome + ',location=' + chrome + ',status=' + chrome + ',menubar=' + chrome;
	cWin = window.open(url,name,att);
	self.name="Main";
}

function openWin(url,name,w,h,scroll) {
/*
   var msgbox = document.getElementById('popupDiv');

   if (msgbox != null) {

         if ((w+100) > document.body.clientWidth) {
            w = document.body.clientWidth -50;
         }
         if ((h+100) > document.body.clientHeight) {
            h = document.body.clientHeight -50;
         }
         msgbox.style.width = w;
         msgbox.style.height = h+50;
         
         var popupframe = document.getElementById('popupFrame');
         popupframe.style.width = w;
         popupframe.style.height = h;
         document.getElementById('popupFrame').src = url;
         show('popupDiv');
         initScreenOverlay();
   } else {
*/
      openNewWin(url,"deltaPopup",w,h,scroll);
/*
   }
*/
}


function closeWin() {
   closePopupDiv();
   if (window.opener) { 
	self.close();
   } else if (window.parent != null) {
      window.parent.closePopupDiv();
    } else if(cWin != null) { 
         cWin.close(); 
         cWin = null; 
   }
}

function closeNewWin() {
      self.close();
}


function closePopupDiv() { 
   hide('popupDiv');
   resetPopupFrame();
   closeMe();
}

function closeMe() {
	try { if(cWin != null){ cWin.close(); cWin = null; } }
	catch(e) {}
	try { if(childwin != null){ childwin.close(); childwin = null; } }
	catch(e) {}
}

// this will open a context-sensitive help window
function openNewHelpWin(url,e)
{
	w = screen.width-470;
	h = screen.height-370;
	x = e.screenX;
	y = e.screenY;
	if(x > w) { x = x-470; }
	if(y > h) { y = y-370; }
	childwin=window.open(url, "childwin", "width=470,height=370,top="+y+",left="+x+",scrollbars=yes,resizable=yes");
}
// this will open a pop-up help window
function openNewHelp2win(url,e,v)
{
	w = screen.width-470;
	h = screen.height-v;
	x = e.screenX;
	y = e.screenY;
	if(x > w) { x = x-470; }
	if(y > h) { y = y-v; }
	childwin=window.open(url, "childwin", "width=470,height="+v+",top="+y+",left="+x+",scrollbars=yes,resizable=yes");
}
