/* ------------------------------ Begin methods for dhtml drop down and flyout menus */

/* 
	TO ACTIVATE HIDING FLASH, SEARCH ON 'HIDING FLASH' AND UNCOMMENT CODE 
	IN THIS FILE AND IN MenuBuilder.js
*/


/* Global variables */
var isCSS, isW3C, isIE4, isNN4, isIE6CSS;

/* Timing variables */
var timerID = null; 
var timerOn = false; 
var timecount = 600;


/* FOR HIDING FLASH OBJECTS ON MOUSEOVER */
var objFind = new Array();
var objStore = new Array();

/* Initialize upon load to let all browsers establish content objects.
   This is the first step in the browser compatability chain. */
function initDHTMLAPI() {
    if (document.images) {
        isCSS = (document.body && document.body.style) ? true : false;
        isW3C = (isCSS && document.getElementById) ? true : false;
        isIE4 = (isCSS && document.all) ? true : false;
        isNN4 = (document.layers) ? true : false;
        isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
         
    }
    // HIDING FLASH
    findObjs();
}
/* Set event handler to initialize API. */
window.onload = initDHTMLAPI;

/* Seek nested NN4 layer from string name. 
   Used in getRawObject() */
function seekLayer(doc, name) {
    var theObj;
    for (var i = 0; i < doc.layers.length; i++) {
        if (doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        // dive into nested layers if necessary
        if (doc.layers[i].document.layers.length > 0) {
            theObj = seekLayer(document.layers[i].document, name);
        }
    }
    return theObj;
}

/* Convert object name string or object reference into a valid element object reference.
   This is the second step in the browser compatability chain.
   Used by the getObject() method. */
function getRawObject(obj) {
    var theObj;
    if (typeof obj == "string") {
        if (isW3C) {
            theObj = document.getElementById(obj);
        } else if (isIE4) {
            theObj = document.all(obj);
        } else if (isNN4) {
            theObj = seekLayer(document, obj);
        }
    } else {
        /* pass through object reference */
        theObj = obj;
    }
    return theObj;
}

/* Convert object name string or object reference into a valid style (or NN4 layer) reference.
   This is the third step in the browser compatability chain. */
function getObject(obj) {
    var theObj = getRawObject(obj);
    if (theObj && isCSS) {
        theObj = theObj.style;
    }
    return theObj;
}

/* Set the background color of an object.
   Used for changing the bg Color of menu items. */
function setBGColor(obj, state) {
    var theObj = getObject(obj);
    var colorTo =  OFFcolor;					// bgColor default is OFF
    if (state == "on") { colorTo = ONcolor; }	// chg bgColor to ON
    if (theObj) {
		if (isNN4) {
			theObj.bgColor = colorTo;
		} else if (isCSS) {
			theObj.backgroundColor = colorTo;
		}
    }
}

/* Secondary menu color (first dropdown) */
function setTextColor (obj, state) {
    var TextOn = "#003264";
    var TextOff = "#59728F";
	
	var theObj = getObject(obj);
    var colorTo =  TextOff;						// bgColor default is OFF
    if (state == "on") { colorTo = TextOn; }	// chg bgColor to ON
    if (theObj) {
		if (isNN4) {
			theObj.color = colorTo;
		} else if (isCSS) {
			theObj.color = colorTo;
		}
    }
}

// Tertiary menu colors
function setSubTextColor (obj, state) {
    var TextOn = "#003264";
    var TextOff = "#59728F";	
	
	var theObj = getObject(obj);
    var colorTo =  TextOff;						// bgColor default is OFF
    if (state == "on") { colorTo = TextOn; }	// chg bgColor to ON
    if (theObj) {
		if (isNN4) {
			theObj.Color = colorTo;
		} else if (isCSS) {
			theObj.color = colorTo;
		}
    }
}

/* Set the visibility of an object to visible. */
function show(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "visible";
    }
}

/* Set the visibility of an object to hidden */
function hide(obj) {
    var theObj = getObject(obj);
    if (theObj) {
        theObj.visibility = "hidden";
    }
}

/* Display submenu objects */
function showSub(obj) {
	var agt=navigator.userAgent.toLowerCase(); 
    var thisObj = getRawObject(obj);

    if (thisObj ) {		
     thisObj.style.visibility = "visible";
    }
}

/* Timer functions */
function startTime() {  
	if (timerOn == false) {  
		timerID=setTimeout( "hideAll()" , timecount);  
		timerOn = true;  
	}  
} 

function stopTime() {
	/* HIDING FLASH */
	var isMac = navigator.userAgent.indexOf("Mac") != -1
	if (isMac) 
	{
		fob('off');
	}
	// remove flash objects only if NS7 or before
	var agt=navigator.userAgent.toLowerCase();
	var rv = geckoGetRv();
	if (agt.indexOf('gecko') != -1)
	{
		if (rv < 1.0002)
		{ 
			fob('off'); //style.left = -9999
		}
	}
	  
	if (timerOn) {  
		clearTimeout(timerID);  
		timerID = null;  
		timerOn = false;  
	}  
} 

/* Begin HIDING FLASH methods */

/* Toggle visibility of flash objects */
function fob (swish) { 
	var agt=navigator.userAgent.toLowerCase();
	var j;
	if (swish == "on")
	{
		for (j = 0; j < objStore.length; j++)
		{
			document.getElementById(objStore[j].value).style.left =0;
		}
	}
	if (swish == "off")
	{
		for (j = 0; j < objStore.length; j++)
		{
			document.getElementById(objStore[j].value).style.left =-9999;
		}
	}
}

/* Find and store all div's containing flash objects */
/* 
	Sample div containing flash object: <div id="flashObj_" style="position:relative; left:0;"> 
	where the '_' is any suffix to the required 'flashObj' prefix
*/
function findObjs() 
{
	var trackInputs = 0;
	var str = "";
	var objs = document.getElementsByTagName("div"); //document.all.tags("div") is (IE only)
	for (var i = 0; i < objs.length; i++)
	{
		objFind[i] = new String();
		objFind[i].value = objs[i].id;
		
		var idmatch = new RegExp("flashObj");
		var mresult = objFind[i].value.match(idmatch);
		
		str += objFind[i].value + "\n"; // testing - collect all div objects
		
		if (mresult != null)
		{
			objStore[trackInputs] = new String();
			objStore[trackInputs].value = objFind[i].value;
			trackInputs++;
		}
	}
}

/*
 returns -1 for non-gecko browsers, 
          0 for pre Netscape 6.1/Gecko 0.9.1 browsers
          number > 0 where each portion of 
			the rv value delimited by . 
			will be treated as value out of 100.
			e.g. for rv: 3.12.42, 
			getGeckoRv() returns 3.1242

geckoGetRv() Examples  
Browser			|  Branch Tag	| geckoGetRv()
-----------------------------------------------
Netscape 6.1	|	0.9.2		|	0.0902
Netscape 6.2	|	0.9.4		|	0.0904
NS 6.2.1		|	0.9.4		|	0.0904
Netscape 6.2.2	|   0.9.4.1		|	0.090401
Netscape 6.2.3	|   0.9.4.1		|	0.090401
CompuServe 7	|   0.9.4.2		|	0.090402
Netscape 7.0	|   1.0.1		|	1.0001
Netscape 7.01	|   1.0.2		|	1.0002
*/
function geckoGetRv()
{
	if (navigator.product != 'Gecko')
	{
		return -1;
	}
	var rvValue = 0;
	var ua      = navigator.userAgent.toLowerCase();
	var rvStart = ua.indexOf('rv:');
	var rvEnd   = ua.indexOf(')', rvStart);
	var rv      = ua.substring(rvStart+3, rvEnd);
	var rvParts = rv.split('.');
	var exp     = 1;

	for (var i = 0; i < rvParts.length; i++)
	{
		var val = parseInt(rvParts[i]);
		rvValue += val / exp;
		exp *= 100;
	}

	return rvValue;
}

/* End HIDING FLASH methods */

function ChangeNumericStyle(inVal, delta)
{
	var re = /(-?)(\d+)(\w+)/;
	re.exec(inVal);
	var SignVal = RegExp.$1;
	var numVal = RegExp.$2;
	var strVal = RegExp.$3;

	if(SignVal)
	{
		numVal = SignVal + RegExp.$2;
		strVal = RegExp.$3;
	}
	else
	{
		numVal = RegExp.$2;
		strVal = RegExp.$3;
	}
	numVal *= 1;
	numVal += delta;
	return numVal + strVal;
}