//Modal window methods
var win = null;

// Browser Detection
var agt = navigator.userAgent.toLowerCase();

// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('hotjava')==-1));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));

var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5up  = (is_ie && !is_ie4);
  
function IgnoreEvents(e)
{
    return false;
}

function returnTrue(e)
{
    return true;
}

//Open popup window.  If Navigator, set event handlers
// THIS IS THE OLD WINDOWING FUNCTION.
// NOTE NOT HAVING THIS AS A URL IS CAUSING SOME MAC BROWSEERS
// TO NOT BE ABLE TO OPEN THE WINDOW.  THE NEW WINDOWING
// FUNCTION DOES NOT TAKE THE URL AS A PARAMETER, THEREFORE
// WILL OPEN THE WINDOW
function showFixedWindow(url,winHeight,winWidth,showScrollbars)
{
    var w = 480;
    var h = 340;
    var topPos;
    var leftPos;
    var scrollbars;
    if (document.all || document.layers) 
    {
      w = screen.availWidth;
      h = screen.availHeight;
    }
    // handle calls not done via the taglib
    if (showScrollbars ==null)
    {
    	scrollbars=0;
    }
    else
    {
    	scrollbars=showScrollbars;
    }

    leftPos = (w-winWidth)/2;
    topPos = (h-winHeight)/2;

    if (win != null)
    {
    	win.close();
    }
    win = window.open(url, "popup", "toolbar=0,scrollbars="+scrollbars+",location=0,statusbar=0,menubar=0,resizable=1,width="+winWidth+",height="+winHeight+",top="+topPos+",left="+leftPos);
 
    //setParentHandlers();
   
    win.focus();
}

//Set Parent window handlers
function setParentHandlers()
{
    if(is_ie == true)
    {
        window.onfocus = HandleFocus;
    }
    else if(is_nav == true)
    {
        window.top.captureEvents(Event.CLICK|Event.FOCUS);
        window.top.onclick=IgnoreEvents;
        window.top.onfocus=HandleFocus;
    }
}

//Get rid of specialized handlers for parent
function releaseParentHandlers()
{
    if(is_ie == true)
    {
        window.onfocus = returnTrue;
    }
    else if(is_nav == true)
    {
        window.top.releaseEvents(Event.CLICK|Event.FOCUS);
    }
}

//Transfers focus back to child if open, else releases lock on events.
function HandleFocus()
{
    if(win != null)
    {
        if(win.closed == false) 
        {
            win.focus();
            //releaseParentHandlers();
            return false;
        }
        else
        {
            releaseParentHandlers();
            return true;
        }
    }
}

// function called on the onUnload event of the window to remove any open child window
function closeChild()
{
    if (win && win.open && (win.closed==false))
    {
        win.close();
    }
}

//Open popup window.  If Navigator, set event handlers.
// This is currently used by the JSP Taglibs.  This windowing function
// should be the one used by all new code.
/*
    This needs to be embedded within a Hyperlink and should be used in conjunction
    with either the Hyperlink or PopupHyperlink JSP taglibs.
	Passing no value for showScrollbars will not render the bars
	Passing -1 for width or height will render that attribute full screen
*/	
function showFixedWindow2(winWidth,winHeight,showScrollbars)
{
    var w = 480;
    var h = 340;
    var topPos;
    var leftPos;
    var scrollbars;

    if (document.all || document.layers) 
    {
      w = screen.availWidth;
      h = screen.availHeight;
    }
    
    // See if the user specified a value, or the attribute should
    // be full screen.
    if (winWidth == -1)
    {
    	winWidth = w;
    }
    if (winHeight == -1)
    {
    	winHeight = h;
    }
    
    // handle calls not done via the taglib
    if (showScrollbars ==null)
    {
    	scrollbars=0;
    }
    else
    {
    	scrollbars=showScrollbars;
    }

    leftPos = (w-winWidth)/2;
    topPos = (h-winHeight)/2;

    if (win != null)
    {
    	win.close();
    }
    win = window.open('', "popup", "toolbar=0,scrollbars="+scrollbars+",location=0,statusbar=0,menubar=0,resizable=1,width="+winWidth+",height="+winHeight+",top="+topPos+",left="+leftPos);
 
    //setParentHandlers();
   
    win.focus();
}


function OW(strName,iW,iH,TOP,LEFT,R,S,SC,T,TB,URL,TYPE,dArg)
{
	if (TYPE=="modal" || TYPE=="modalIframe")
	{
		var sF=""
		var _rv
		sF+=T?'unadorned:'+T+';':'';
		sF+=TB?'help:'+TB+';':'';
		sF+=S?'status:'+S+';':'';
		sF+=SC?'scroll:'+SC+';':'';
		sF+=R?'resizable:'+R+';':'';
		sF+=iW?'dialogWidth:'+iW+'px;':'';
		sF+=iH?'dialogHeight:'+(parseInt(iH)+(S?42:0))+'px;':'';
		sF+=TOP?'dialogTop:'+TOP+'px;':'';
		sF+=LEFT?'dialogLeft:'+LEFT+'px;':'';
		if (TYPE=="modal")
			//_rv=window.showModalDialog(URL+"&r="+Math.round(Math.random()*1000000),dArg?dArg:"",sF);
			_rv=window.showModalDialog(URL,"",sF);
		else
		{
			var da=new Object()
			da.w=iW;
			da.h=iH;
			da.url=URL;
			_rv=window.showModalDialog("/cgi-bin/dasp/ModalIframe.asp?r="+Math.round(Math.random()*1000000),da,sF);
		}
		if ("undefined" != typeof(_rv) )
			return _rv;
	}
	else
	{
		var sF=""
		sF+=iW?'width='+iW+',':'';
		sF+=iH?'height='+iH+',':'';
		sF+=R?'resizable='+R+',':'';
		sF+=S?'status='+S+',':'';
		sF+=SC?'scrollbars='+SC+',':'';
		sF+=T?'titlebar='+T+',':'';
		sF+=TB?'toolbar='+TB+',':'';
		sF+=TB?'menubar='+TB+',':'';
		sF+=TOP?'top='+TOP+',':'';
		sF+=LEFT?'left='+LEFT+',':'';
		return window.open(URL?URL:'about:blank',strName?strName:'',sF).focus()
	}
}

