// Some global variables for openPopup() below
var WindowObjectReference = null; // global variable for openPopup()
var popupFeatures = 'scrollbars,resizable,location=0,statusbar=0,'
	+ 'menubar=0,';
var defaultWidth = 500;
var defaultHeight = 400;

///////////// ADD COMMAS TO A NUMBER //////////////
function addCommas(n) {
	n = n.toString(); // Convert number to string
	var len = n.length;
	var fn='';
	if (len > 3) { // If over 3 digits, add commas
		for (i = len-3; i > 0; i -= 3) {
			fn = "," + n.substr(i,3) + fn;
		}
		return(n.substr(0, i+3) + fn);
	} else {
		return(n); // Otherwise, just return original number
	}
}

////////////////// WINDOW POPUPS ///////////////////////////////// 
// Return the parameters to center a popup window on the browser screen
function windowCenteringInfo(myWidth, myHeight) {
	var info = '';
	if (window.screen) {
		var x_pos = parseInt(screen.availWidth/2) - (myWidth/2);
		var y_pos = parseInt(screen.availHeight/2) - (myHeight/2);
		info += ",left=" + x_pos; // offset from left
		info += ",screenX=" + x_pos; 
		info += ",top=" + y_pos; // offset from top
		info += ",screenY=" + y_pos; 
	}
	return info;
}
// Window popup function and associated variables; adapted from developer.mozilla.org
// Usage: <a href="http://www.nceo.org/" target="aName" onclick="openPopup(this.href, this.target);">link text</a>
// Or with optional params: ...onclick="openPopup(this.href, this.target, 200, 300)...
// Don't use _blank as target because it will open a new tab (FF) or window (MSIE) as well as the popup
function openPopup(strUrl, strWindowName, width, height) {
	if ((typeof(width) == 'undefined') || (typeof(height) == 'undefined')) {
		width = defaultWidth; 
		height = defaultHeight;
	}
	// strWindowName = strWindowName ? strWindowName : '_blank';
	popupFeatures += 'width=' + width + ',height=' + height;
	popupFeatures += windowCenteringInfo(width, height);
	// Create window (for this popup only) if it doesn't exist; otherwise, just bring to front
	if (WindowObjectReference == null || WindowObjectReference.closed) {
		WindowObjectReference = window.open(strUrl, strWindowName, popupFeatures);
		WindowObjectReference.focus();
	}
	WindowObjectReference.focus();
	// Cancel link in calling window if popup was created
	return (WindowObjectReference) ? false : true;
}

// Rollover effects for form buttons
function buttonOver(theButton) { theButton.className = "submitover" }
function buttonDown(theButton) { theButton.className = "submitdown"; }
function buttonOut(theButton, restoreStyle) { theButton.className = restoreStyle; }

// Confirm form submission
function confirmSubmission(message) {
	// In case message is omitted
	if (!message) message = 'Do you want to submit the form?';
	var goAhead = confirm(message);
    return goAhead;
}
	
////////////////// DROP-DOWN MENUS /////////////////////////////////
// From http://www.htmldog.com/articles/suckerfish/dropdowns/ --works with CSS-formatted lists
sfHover = function() {
	if (document.getElementById("nav")) { // If on a menu page (if not, this avoids a JS error)
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
// if (window.attachEvent) window.attachEvent("onload", sfHover); // see init() below 

/* 
  ------------------------------------------------
  PVII Equal CSS Columns scripts -Version 2
  Copyright (c) 2005 Project Seven Development
  www.projectseven.com
  Version: 2.1.0
  ------------------------------------------------
  http://www.projectseven.com/tutorials/css/pvii_columns/
*/
function P7_colH2(){ //v2.1.0 by PVII-www.projectseven.com
 var i,oh,h=0,tg,el,np,dA=document.p7eqc,an=document.p7eqa;if(dA&&dA.length){
 for(i=1;i<dA.length;i+=2){dA[i+1].style.paddingBottom='';}for(i=1;i<dA.length;i+=2){
 oh=dA[i].offsetHeight;h=(oh>h)?oh:h;}for(i=1;i<dA.length;i+=2){oh=dA[i].offsetHeight;
 if(oh<h){np=h-oh;if(!an&&dA[0]==1){P7_eqA2(dA[i+1].id,0,np);}else{
 dA[i+1].style.paddingBottom=np+"px";}}}document.p7eqa=1;
 document.p7eqth=document.body.offsetHeight;
 document.p7eqtw=document.body.offsetWidth;}
}
function P7_eqT2(){ //v2.1.0 by PVII-www.projectseven.com
 if(document.p7eqth!=document.body.offsetHeight||document.p7eqtw!=document.body.offsetWidth){P7_colH2();}
}
function P7_equalCols2(){ //v2.1.0 by PVII-www.projectseven.com
 // Next line added by SR: exit if no sidebox div on this page (as on CGI page template)
 if (document.getElementById('sidebox') == 'undefined') { return; }
 var c,e,el;if(document.getElementById){document.p7eqc=new Array();
 document.p7eqc[0]=arguments[0];for(i=1;i<arguments.length;i+=2){el=null;
 c=document.getElementById(arguments[i]);if(c){e=c.getElementsByTagName(arguments[i+1]);
 if(e){el=e[e.length-1];if(!el.id){el.id="p7eq"+i;}}}if(c&&el){
 document.p7eqc[document.p7eqc.length]=c;document.p7eqc[document.p7eqc.length]=el}}
 setInterval("P7_eqT2()",10);}
}
function P7_eqA2(el,p,pt){ //v2.1.0 by PVII-www.projectseven.com
 var sp=10,inc=20,g=document.getElementById(el);np=(p>=pt)?pt:p;
 g.style.paddingBottom=np+"px";if(np<pt){np+=inc;
 setTimeout("P7_eqA2('"+el+"',"+np+","+pt+")",sp);}
}

////////////////// FUNCTIONS CALLED AFTER PAGE LOADS //////////////////// 
/* Invoked upon onload; can call multiple functions */
function init() {
	// PVII equal columns: 
	// Apply vertical space as needed below last <p> tag in mainbox and sidebox columns
	// Disable by setting noEqualCols before this script runs
	if (typeof noEqualCols == 'undefined') { P7_equalCols2(0,'mainbox','P','sidebox','P'); }
	if (window.attachEvent) { sfHover(); } // for MSIE (would screw up Firefox)
}

////////////////// SET WINDOW.ONLOAD HANDLER ////////////////////////////
window.onload=init;
