
/****************************************************************************************/

function MM_findObj(n, d) { //v4.01
  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 && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_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 MM_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 MM_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=MM_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 initializeOptionList(optList, optArray)	{
/****************************************************************************************/

	optList.options[0] = new Option("", 0);
	for (var i = 0; i <= optArray.length - 1; i++)		{
		optList.options[i + 1] = new Option(optArray[i], i + 1);
		optList.selectedIndex = 0;
	}
}		// initializeOptionList()

/****************************************************************************************/
 function setFormTop(the_form, y) {
/****************************************************************************************/
	setEleTop(the_form, y);
}		// setFormTop()

/****************************************************************************************/
 function setEleTop(the_ele, y) {
/****************************************************************************************/
	if (navigator.appVersion.indexOf("MSIE") != -1) {
		the_ele.style.top = document.body.scrollTop + y;
	}
	else {
		the_ele.style.top = window.pageYOffset + y;
	}
}	// setEleTop()

/****************************************************************************************/
 function setEleRelativeTop(the_ele, y) {
/****************************************************************************************/
	if (navigator.appVersion.indexOf("MSIE") != -1) {
		y = y - document.body.scrollTop;
	}
	else {
		y = y - window.pageYOffset;
	}

//alert("y is! " + y);

	setEleTop(the_ele, y);
}	// setEleRelativeTop()

/****************************************************************************************/
function numericizePx(px_string) { 
/****************************************************************************************/
	// simply strips "px" off of any values passed in, so we can do calcualations with CSS dimensions etc.
	var pos_px = px_string.indexOf("px");
	return parseInt(px_string.substring(0, pos_px));
}	// numericizePx()
/****************************************************************************************/

/****************************************************************************************/
function popupInputWin( pageURL, winName, popupWidth, popupHeight, includeScroll )		{
/****************************************************************************************/


	if (navigator.appName.indexOf("Microsoft") != -1)	{
		var thisWidth = document.body.offsetWidth;
		var thisHeight = document.body.offsetHeight
		var thisX = window.screenLeft;
		var thisY = window.screenTop;
	}
	else	{
		var thisWidth = window.innerWidth;
		var thisHeight = window.innerHeight				
		var thisX = window.screenX;
		var thisY = window.screenY;
	}

	var xPopup = thisX + ((thisWidth - popupWidth) / 2);
	var yPopup = thisY + ((thisHeight - popupHeight) / 2);

	if (xPopup <= 0)	{	xPopup = 1;	}
	if (yPopup <= 0)	{	yPopup = 1;	}

	var winAttributes = 	"width=" + popupWidth + "," + 
								"height=" + popupHeight + "," +
								"scrollbars=" + includeScroll + "," + 
								"resizable=yes," +
								"left=" + xPopup + "," +
								"top=" + yPopup;
	
	// var theWin = window.open("popup_choose_disc.php", "theWin", winAttributes, true );
	var theWin = window.open(pageURL, winName, winAttributes, true );
	if (theWin)	{
		// The following 2 lines are incredibly dumb but fix an issue where an existing window won't focus
		// (or return a false).
		theWin.close();
		var theWin = window.open(pageURL, winName, winAttributes, true );
		theWin.focus();
		theWin.moveTo( xPopup, yPopup );			// in case of old browsers
	}
	else {
		alert("You should have a popped up window here... if not, please disable any popup blockers.");
	}
}		// popupInputWin()

/****************************************************************************************/

function GetXmlHttpObject()
{
	var xmlHttp = null;
	
	try	{		// Firefox, Opera 8.0+, Safari
 		xmlHttp = new XMLHttpRequest();
 	}
	catch (e)	{	// Internet Explorer
 		try	{
  			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
  		}
 		catch (e)	{
  			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
	return xmlHttp;
}

/****************************************************************************************/

// found on experts exchange, courtesy of Ralph Brown: handle "knightEknight"
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}		// trim()

/****************************************************************************************/

function isFilledField(formElement)		{
	fieldValue = trim(formElement.value);
	return fieldValue.length > 0;
}		// isFilledField()

/****************************************************************************************/

function isValidEmail(addressIn)
{
	// Provided by http://javascript.internet.com
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	return filter.test(addressIn);
}

/***********************************************************************************/
function disableElement(ele_in, opa) {
/***********************************************************************************/

	ele_in.style.backgroundColor = "#FFFFFF";	// These two together fix IE's opacity and font rendering prob.															
	ele_in.style.zoom = 1;						// In a more generalized version, this color need not be white.
    ele_in.overflow = "visible";

	var opa_ie = opa * 100;
	ele_in.style.filter = "alpha(opacity=" + opa_ie + ")";
	ele_in.style.MozOpacity = "" + opa;
	ele_in.style.opacity = "" + opa;



	// Still need to figure out how to disable, not just fade it.


	// trick is to put up a div of width & height 100% that covers the bottom page via its z-element.

	// but doesn't work in IE. Won't fix for RE Phase 04.

}

/****************************************************************************************/

function enableElement(ele_in)
{
	if (ele_in) { 
		ele_in.style.filter = "alpha(opacity=100)";
		ele_in.style.MozOpacity = "1";
		ele_in.style.opacity = "1";
	}
}

/****************************************************************************************/

function enableHref(dom_id, css_class)	
{
	var ele = document.getElementById(dom_id);
	if (ele) { 
		var temp_val = ele.getAttribute('href_bak'); 
		ele.removeAttribute('href_bak');
		ele.className = css_class;
		ele.setAttribute('href', temp_val);
		// more reliable than setAttribute()
		ele.className = css_class;
		// ele.setAttribute('class', css_class);
	}
}

function disableHref(dom_id, css_class)
{
	var ele = document.getElementById(dom_id);
	if (ele) { 
		var temp_val = ele.getAttribute('href');
		ele.setAttribute('href_bak', temp_val);
		ele.className = css_class;		// more reliable than setAttribute()
		// ele.setAttribute('className', css_class);
		ele.removeAttribute('href');
	}
}

/****************************************************************************************/

var all_edit_selected_state = 0;

function toggleCheckAll(dom_id)	{
	var ckboxes = document.getElementsByName(dom_id);
	all_edit_selected_state = (all_edit_selected_state + 1) % 2;
	for (var i = 0; i < ckboxes.length; i++)	{
		ckboxes[i].checked = (all_edit_selected_state > 0);
	}	
}		// toggleCheckAll()				

/****************************************************************************************/

function areAnySelected(dom_id)
{
	var are_any = false;
	for (var i = 0; i < dom_id.length; i++)	{
		if (dom_id[i].checked)	{
			are_any = true;
			break;
		}
	}
	return are_any;
}

/****************************************************************************************/
function toggleElementVisibility(dom_id, css_visibility) 	{
/****************************************************************************************/
	var ele = document.getElementById(dom_id);
	if (ele) { ele.style.visibility = css_visibility; }
}


/****************************************************************************************/
function addJSEvent( obj, type, fn ) {
// http://ejohn.org/projects/flexible-javascript-events/
/****************************************************************************************/
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}		// addJSEvent()

/****************************************************************************************/
function rmvJSEvent( obj, type, fn ) {
// http://ejohn.org/projects/flexible-javascript-events/
/****************************************************************************************/
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}		// rmvJSEvent()


