//collection of general utility functions  --  utilities.js
//modified by George Pavlovich 4/13/2001
//modified by Jesse Brett 6/19/2001
//reviewed by George Pavlovich 5/9/2003
/* FUNCTIONS
	disableRightClickMenu()
	NSscrollFix(val)
	showPopup(fn,wn,w,h)
	showPopupNC(fn,wn,w,h)
	autoClosePopup()
	reference(page, target)
	navToWebsite(page)
	showWebsite(fn, a, w, h)
	showWebsite2(fn, w, h)
	glossary(fn, w, h, BasePath)
	help(fn, w, h)
	showPic(fn, w, h)
	findVal(val, ary)
	getBasePath()
	getThisPage()
	getRand()
	setVariables(width, height)
	checkLocation()
	evalMove()
	MM_reloadPage(init)
	preloadImages()
	swapImgRestore()
	swapImage()
	HS_imageSwap(daImage, daSrc)
	
*/
/* VARIABLES
	childWindow
*/


//function to disable Right-Click menu. Disables for everything in BODY tag.
//not perfect - you can still click on images/links/etc, but very cross-browser & degradable
//except (naturally) doesn't work with NS5 (NS6, or whatever they're calling it these days)
function disableRightClickMenu() {
	document.oncontextmenu = function(){return false} //IE5 & NS5? disable
	if(document.layers) { //NS4 compatibility
		window.captureEvents(Event.MOUSEDOWN);
		window.onmousedown = function(e){
			if(e.target==document)return false;
		}//end function(e)
	} else {
		document.onmousedown = function(){return false}//IE4 disable
	}//end else
}//end disableRightClickMenu()

//usage: <a href="#none" onClick="Javascript:scrollJB('segALL')">scroll to segALL</a>
//use to jump to any named DIV, possibly any object (only tested w/ DIV)
//works w/ nested DIVs. Uses MM_findObj (a truly amazing function)
function NSscrollFix(val) {
if (document.layers) scrollTo(0,val); 
//if (document.layers) window.scrollTo(0,MM_findObj(name).y); 
//else MM_findObj(name).scrollIntoView(true);
}

var childWindow = null;
function showPopup(fn,wn,w,h) {
	autoClosePopup();
	if(navigator.appName=='Netscape') properties='directories=no,screenX=0,screenY=0';
	else if(navigator.appName=='Microsoft Internet Explorer') properties='channelmode=no,top=0,left=0';
	properties+=',resizable=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no';
	properties+=',width=' + w + ',height=' + h;
	childWindow = window.open(fn,wn, properties);
	onunload = autoClosePopup;
	childWindow.focus();
}
function showPopupNC(fn,wn,w,h) {
	autoClosePopup();
	if(navigator.appName=='Netscape') properties='directories=no,screenX=0,screenY=0';
	else if(navigator.appName=='Microsoft Internet Explorer') properties='channelmode=no,top=0,left=0';
	properties+=',resizable=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no';
	properties+=',width=' + w + ',height=' + h;
	childWindow = window.open(fn,wn, properties);
	childWindow.focus();
}
function autoClosePopup() {
	if (childWindow != null) {
		if (!(childWindow.closed)) childWindow.close();
		childWindow = null; 
	}
}

//usage: <a href="#none" onClick="Javascript:reference('/dod2/showglos.asp')">reference page</a>
//opens a reference page with a valid back button.  Use 'new' parameter to open in new window
function reference(page, target) {
   //use a new window OR...
//	if (target == 'new') {
		pString = page + '?back=' + location.href + '&new=true';
		showPopup(pString, 'glos', 750, 550);
//	}
	//just go to site
//	else document.location = page + '?back=' + location.href;
}

//usage: <a href="#none" onClick="Javascript:navToWebsite('http://www.altavista.com')">altavista.com</a>
function navToWebsite(page) {
   document.location =  '../../outside.asp?site=' + page + '&back=' + location.href;
}

function showWebsite(fn, a, w, h){

	window.open(fn)

}


function showWebsite_old(fn, a, w, h) { //shows an outside website in a new window w/ HS frame
	if (w) wd = w; else wd = 750;
	if (h) ht = h; else ht = 550;
	if(navigator.appName=='Netscape') properties='directories=yes,screenX=0,screenY=0';
	else if(navigator.appName=='Microsoft Internet Explorer') properties='channelmode=no,top=0,left=0';
	properties+=',resizable=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes';
	properties+=',width=' + wd + ',height=' + ht;
	if (a) site_anchor = "site_anchor=" + a + "&"; else site_anchor = "";
	var page = '../../outside.asp?'+ site_anchor + 'new=true&back=' + location.href + '&site=' + fn ;
	childWindow = window.open(page,'ws', properties);
	childWindow.focus();
}

function showWebsite2(fn,w,h) { //shows an outside website in a new window w/o HS frame
	if (w) wd = w; else wd = 765;
	if (h) ht = h; else ht = 435;
	if(navigator.appName=='Netscape') properties='directories=yes,screenX=0,screenY=0';
	else if(navigator.appName=='Microsoft Internet Explorer') properties='channelmode=no,top=0,left=0';
	properties+=',resizable=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes';
	properties+=',width=' + wd + ',height=' + ht;
	childWindow = window.open(fn,'ws', properties);
	childWindow.focus();
}

//usage: <a href="#none" onClick="Javascript:glossary('liver', 500, 100);">liver</a>
// -OR-  <a href="#none" onClick="Javascript:glossary('liver');">liver</a>
function glossary(fn, w, h) {
    //if (modulePath == "") modulePath = '../../scripts/glossary.asp?item=';
	if(navigator.appName=='Netscape') properties='directories=no,screenX=50,screenY=50';
	else if(navigator.appName=='Microsoft Internet Explorer') properties='channelmode=no,top=50,left=50';
	properties+=',resizable=yes,location=no,menubar=no,scrollbars=no,status=no,toolbar=no';
	if (w) properties+=',width=' + w;
	else properties+=',width=200'; //default width if none specified
	if (h) properties+=',height=' + h;
	else properties+=',height=50'; //default height if none specified
//edit this hard-coded string to show where the glossary.asp page is located
	var filePage = '../../scripts/glossary.asp?item=' + fn;
	glossWindow = window.open(filePage,'GL', properties);
	glossWindow.focus();
}
//usage: <a href="#none" onClick="Javascript:help(1, 500, 100);">question 1</a>
// -OR-  <a href="#none" onClick="Javascript:help(2);">question 2</a>
function help(fn, w, h) {
	if(navigator.appName=='Netscape') properties='directories=no,screenX=50,screenY=50';
	else if(navigator.appName=='Microsoft Internet Explorer') properties='channelmode=no,top=50,left=50';
	properties+=',resizable=yes,location=no,menubar=no,scrollbars=no,status=no,toolbar=no';
	if (w) properties+=',width=' + w;
	else properties+=',width=600'; //default width if none specified
	if (h) properties+=',height=' + h;
	else properties+=',height=250'; //default height if none specified
//edit this hard-coded string to show where the help.asp page is located
	filePage = '../../scripts/help.asp?item=' + fn;
	helpWindow = window.open(filePage,'HP', properties);
	helpWindow.focus();
}
//usage: <a href="#none" onClick="Javascript:showPic('/images/pic.gif', 500, 100);">pic</a>
// -OR-  <a href="#none" onClick="Javascript:glossary('/images/pic.gif');">pic</a>
function showPic(fn, w, h) {
	if(navigator.appName=='Netscape') properties='directories=no,screenX=50,screenY=50';
	else if(navigator.appName=='Microsoft Internet Explorer') properties='channelmode=no,top=50,left=50';
	properties+=',resizable=yes,location=no,menubar=no,scrollbars=no,status=no,toolbar=no';
	if (w) properties+=',width=' + w;
	else properties+=',width=200'; //default width if none specified
	if (h) properties+=',height=' + h;
	else properties+=',height=50'; //default height if none specified
	picWindow = window.open('','PIC', properties);
	picWindow.document.open();
	picWindow.document.write("<html><body onblur='self.close()'><img src='"+fn+"'><br><center><a href='javascript:self.close()'>Close this Window</a></center></body></html>");
	picWindow.document.close();
	picWindow.focus();
}

function findVal(val, ary){
	for (i=0; i<ary.length; i++) {
      if (ary[i] == val) return i;
   }
	return -1;
}
function getBasePath(){ //returns site path (e.g. www.website.com/site/
	var index1=location.href.indexOf("?");
   if(index1<1) index1=location.href.indexOf("#");
   if(index1<1) index1=location.href.length;
   var index=location.href.lastIndexOf("/",index1)+1;
   if(index<1) index=location.href.lastIndexOf("\\",index1)+1;
   if(index<1) index=location.href.length;
   return location.href.substring(0,index);
}
function getThisPage(){ //returns current page (e.g. main.asp) 
	var index1=location.href.indexOf("?");
   if(index1<1) index1=location.href.indexOf("#");
   if(index1<1) index1=location.href.length;
   var index=location.href.lastIndexOf("/",index1)+1;
   if(index<1) index=location.href.lastIndexOf("\\",index1)+1;
   if(index<1) index=location.href.length;
   return location.href.substring(index,index1);
}
function getRand(){
	var rand = Math.round(Math.random() * 10000);
	return rand;
}
//begin branding functions
function setVariables(width, height) {
	imgwidth = width;
	imgheight = height;
	if (document.layers) {
		horz=".left";
		vert=".top";
		docStyle="document.";
		styleDoc="";
		innerW="window.innerWidth";
		innerH="window.innerHeight";
		offsetX="window.pageXOffset";
		offsetY="window.pageYOffset";
	} else {
		horz=".pixelLeft";
		vert=".pixelTop";
		docStyle="";
		styleDoc=".style";
		innerW="document.body.clientWidth";
		innerH="document.body.clientHeight";
		offsetX="document.body.scrollLeft";
		offsetY="document.body.scrollTop";
   }
}
function checkLocation() {
	objectXY="branding";
	var availableX=eval(innerW);
	var availableY=eval(innerH);
	var currentX=eval(offsetX);
	var currentY=eval(offsetY);
	x=availableX-(imgwidth+30)+currentX;
	y=availableY-(imgheight+20)+currentY;
	evalMove();
	setTimeout("checkLocation()",5);
}
function evalMove() {
	eval(docStyle + objectXY + styleDoc + horz + "=" + x);
	//eval(docStyle + objectXY + styleDoc + horz + "=10");
	eval(docStyle + objectXY + styleDoc + vert + "=" + y);
}

//end branding functions

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function HS_imageSwap(daImage, daSrc){
  if ((x=MM_findObj(daImage)) !=null) x.src = daSrc;
}
