// Detect if browser is Netscape 3 + or IE 4 +.
function detectBrowser()
{
	var retValue = '';
	var bName = navigator.appName;
	//var bVer = parseInt(navigator.appVersion);
    if (bName == "Netscape")
    {
    	return ('NS');
    }
    else if (bName == "Microsoft Internet Explorer")
    {
    	return ('IE');
    }
    else
    {
    	return ('null');
    }
}

function detectBrowserVersion()
{

	if (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) >= 4)
	{
    	return ("IE4+");
	}

	if ( (navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4 && parseInt(navigator.appVersion) < 5))
	{
	    return ("NS4+");
	}

	if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 5)
	{
	    return("NS5+");
	}

}


function setCookieSession(session_id, session_val)
{
	document.cookie = session_id + "=" + session_val;
}


function printOut(textToPrint)
{
	document.write(textToPrint);
}

function getCookieSession(session_id)
{
	var sessionParam = session_id + "="
	var allCookies = document.cookie;
	var pos = allCookies.indexOf(sessionParam);
	if (pos != -1)
	{
		var start = pos + sessionParam.length;
		var end = allCookies.indexOf(";", start);
		if (end == -1)
		{
			end = allCookies.length;
		}
		var cookieValue = allCookies.substring(start,end);
		return (cookieValue);
	}
	return ("null");
}

function isValidUser()
{
	var isLoggedIn = getCookieSession("isLoggedIn");
	if (isLoggedIn != 'true')
	{
		window.location.href = "asm_invalidAccess.html";
	}
}

function getQueryStringArgs()
{
	//The limitation with using an object to store the qString arguments
	//is that you cannot have multiple arguments with the same name. no
	//collection functionality
	var args = new Object();

	var query = location.search.substring(1); //get query string
	//alert("queryString = " + query);
	var pairs = query.split("&");

	for(var i = 0; i < pairs.length; i++)
	{
		var pos = pairs[i].indexOf('=');  //Look for name=value pair
		if (pos != -1)					  //if not found then skip and go to the next one
		{
			var argName 	= pairs[i].substring(0,pos);  //Extract the name
			var argValue 	= pairs[i].substring(pos + 1); //Extract the value
			args[argName] 	= unescape(argValue);		 //Stort as a property.
		}

	}
	return args;  //return the object
}




function openDialog(url,name,height,width,edge,center,help,resizable,status)
{
	var netscape = (navigator.appName.indexOf('Netscape') >= 0) ? 1 : 0;
	var iexplorer = (document.all) ? 1 : 0;
	var features = '';
	var top = 0;
	var left = 0;

	if ( netscape == 1 ) {
		if ( height < screen.availHeight ) 	{
			top = Math.round( ( screen.availHeight - height ) / 2 );
			}
		if ( width < screen.availWidth )	{
			left = Math.round( ( screen.availWidth - width ) / 2 );
			}
		features = 'height=' + height + ',width=' + width + ',screenY=' + top + ',screenX=' + left + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',menubar=' + menubar + ',status=' + status + ',toolbar=' + toolbar + ',location=' + location + ',alwaysRaised=' + alwaysraised + ',dependent=' + dependent;
	}
	else if ( iexplorer == 1 )	{
		if ( height < screen.height )	{
			top = Math.round( ( screen.height - height ) / 2 );
			}
		if ( width < screen.width )		{
			left = Math.round( ( screen.width - width ) / 2 );
			}		
		features = 'dialogHeight: ' + height + 'px; dialogWidth: ' + width + 'px; dialogTop: ' + top + 'px; dialogLeft=' + left + 'px; edge: sunken; center: Yes; help: No; resizable: No; status: Yes; unadorned: Yes;';
	}
	return (window.showModalDialog(url,name,features));
}


function  openWindow(url,name,height,width,toolbar,location,status,menubar,scrollbars,resizable,alwaysraised,dependent)
 {
	var netscape = (navigator.appName.indexOf('Netscape') >= 0) ? 1 : 0;
	var iexplorer = (document.all) ? 1 : 0;
	var features = '';
	var top = 0;
	var left = 0;

	if ( netscape == 1 ) {
		if ( height < screen.availHeight ) 	{
			top = Math.round( ( screen.availHeight - height ) / 2 );
			}
		if ( width < screen.availWidth )	{
			left = Math.round( ( screen.availWidth - width ) / 2 );
			}
		features = 'height=' + height + ',width=' + width + ',screenY=' + top + ',screenX=' + left + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',menubar=' + menubar + ',status=' + status + ',toolbar=' + toolbar + ',location=' + location + ',alwaysRaised=' + alwaysraised + ',dependent=' + dependent;
	}
	else if ( iexplorer == 1 )	{
		if ( height < screen.height )	{
			top = Math.round( ( screen.height - height ) / 2 );
			}
		if ( width < screen.width )		{
			left = Math.round( ( screen.width - width ) / 2 );
			}
		if (scrollbars==1) { scrollbars = "auto"; }
		features = 'height=' + height + ',width=' + width + ',top=' + top + ',left=' + left + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',menubar=' + menubar + ',status=' + status + ',toolbar=' + toolbar + ',location=' + location;
	}
	return open(url,name,features);
}

/*************************************************
Popup DocViewer 
- Opens MS Office documents, Adobe Acrobat and Shockwave Flash files 
in a popup window with a smart "Loading..." status message
(c) 2003 Glenn G. Vergara
http://www21.brinkster.com/gver/
*************************************************/

function openDoc(filename,target)
{
	//if not IE, open link normally
	if (!document.all){
	location.href = filename;
	return;
	}
	
	var strWinHandle = target + "_WinOpenDoc"; //to ensure no global variable conflict with other script
	
	//just focus to the corresponding window if it is already open
	if (window[strWinHandle] && !window[strWinHandle].closed){
	window[strWinHandle].focus();
	return;
	}
	
	//open blank page
	window[strWinHandle] = window.open('',target,'menubar=1,location=0,toolbar=0,resizable=1,status=0'); //add other window features here
	
	//create frameset with only one frame 
	var strHTML = '<html>\n<head>\n<title>Loading...Please wait.</title>\n</head>\n';
	strHTML += '<frameset onload="window.focus()">\n<frame name="docFrame" src="/blank.html">\n</frameset>\n';
	strHTML += '</html>';
	window[strWinHandle].document.write(strHTML);
	window[strWinHandle].document.close();
	
	
	//Flash the 'Loading...' message
	strHTML = '<html><body>';
	strHTML += '<table width="100%" height="100%">';
	strHTML += '<tr><td align="center" valign="middle">';
	strHTML += '<font face="Arial" color="red">Loading...Please wait.</font><br><br>';
	//provide link to close window (for browsers with no appropriate plugin for the needed software)
	strHTML += '<font face="Arial" size="1" color="gray">If you do not have the needed software to launch the document, please <a href="javascript:top.close()">close</a> this window.</font>';
	strHTML += '</td></tr></table>';
	strHTML += '</body></html>';
	var winDocFrame = window[strWinHandle].top.frames['docFrame'];
	winDocFrame.document.write(strHTML);
	winDocFrame.document.close();
	
	//preload the document
	var doc = new Image();
	doc.onerror = function(){
		//check window if still open, the user might have closed it
		if (window[strWinHandle] && !window[strWinHandle].closed){ 
		window[strWinHandle].document.title = filename.substring(filename.lastIndexOf("/")+1); //extract just the filename
		//winDocFrame.location.replace(filename); //finally, set frame's location to the document filename
		window[strWinHandle].document.location.replace(filename)
		}
	}
	doc.src = filename; //onerror handler fires since image src is not actually an image
}
