/* global.js - global Javascript file */

/* Function to change the background color of table rows */

/* Create array to remember which row has been clicked */
var marked_row = new Array;


/**
 *
 * @param 	object		the table row
 * @param 	integer 	the row number
 * @param 	string		the action calling this script (over, out or click)
 * @param 	string		the default background color
 * @param 	string		the color to use for mouseover
 * @param 	string		the color to use for marking a row
 *
 * @return	boolean	whether pointer is set or not
 */
function divSwap(where, what) {
		document.getElementById(where).innerHTML = what;
}
function divDefault() {
		document.getElementById("sbuinfo").innerHTML = "Welcome to Cook";
}
function changeColor(theRow, theRowNum, theRowOrgColor, theAction)
{
		var theCells = null;
		var newColor = null;

	// 1. Gets the current row and exits if the browser can't get it
		if (typeof(document.getElementsByTagName) != 'undefined') {
	theCells = theRow.getElementsByTagName('td');
		}
		else if (typeof(theRow.cells) != 'undefined') {
	theCells = theRow.cells;
		}
		else {
	return false;
		} // end 1


		// 2. Declare vars
		var rowCellsCnt	= theCells.length;
	var domDetect		= null;
	var currentColor = null;
	var newColor 		= null;

	// The colors
	var highlightColor = '#FFFECC';
	var theClickColor = '#FEFDB5';
	// The original colors
	var grid_row_regbg = '#FFFFFF';
	var grid_row_dkbg = '#F5F5F5';
	// end 2


		// 3.1 ... with DOM compatible browsers except Opera that does not return
		// 	valid values with "getAttribute"
		if (typeof(window.opera) == 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
	//currentColor = theCells[0].getAttribute('bgcolor');
	domDetect		= true;
		}
		// 3.2 ... with other browsers
		else {
			//	currentColor = theCells[0].style.backgroundColor;
	domDetect		= false;
		} // end 3


	// 4.1 Check theAction parameter from the function call -----> over
	if (theAction == 'over')
	{
		// MouseOver, then check to see if row is selected
		if (marked_row[theRowNum] == true)
		{
			// If so then change nothing
			//newColor = theClickColor;
		} else {
			// Otherwise then highlight
			newColor = highlightColor;
		}
	}
	// 4.2 Check theAction parameter from the function call -----> out
	else if (theAction == 'out')
	{
		// MouseOut, then check to see if row is selected
		if (marked_row[theRowNum] == true)
		{
			// If so then change nothing
			//newColor = theClickColor;
		} else {
			// Otherwise, then check to see what the original background color (class) was
			if (theRowOrgColor == 'grid_row_regbg') {
				// If it was the grid_row_regbg class...
				newColor = grid_row_regbg;
			} else {
				// ...or the grid_row_dkbg class
				newColor = grid_row_dkbg;
			}
		}
	}
	// 4.3 Check theAction parameter from the function call -----> click
	else if (theAction == 'click')
	{
		// MouseDown, then check to see if row is selected
		if (marked_row[theRowNum] == true)
		{
			// If it is then change to highlight...
			newColor = highlightColor;
			// ...and set indices to false
			marked_row[theRowNum] = false;
		} else {
			// Otherwise, set to clickColor...
			newColor = theClickColor;
			// ...and set indicis to true
			marked_row[theRowNum] = true;
		}
	} // 4


		// 5. Sets the new color...
		if (newColor) {
	var c = null;
	// 5.1 ... with DOM compatible browsers except Opera
		/* if (domDetect) {
			for (c = 0; c < rowCellsCnt; c++) {
		theCells[c].setAttribute('bgcolor', newColor, 0);
			} // end for
	}
	// 5.2 ... with other browsers
	else {*/
			for (c = 0; c < rowCellsCnt; c++) {
		theCells[c].style.backgroundColor = newColor;
			}
			//	}
		} // end 5

		return true;
} // end of the 'changeColor()' function



function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}



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);


var x = 0;
function SuspendLayerTimer() {
	 x = 0; 	// turn off timer
}
function ResetLayerTimer() {
	x = 10;	// set timeout in 1/10 of seconds (10 = 1 second)
}
function LayerTimeOut() {
	window.setTimeout( "LayerTimeOut()", 100); // 100 milliseconds delay
	if (x == 1) {
		x = 0;
		MM_showHideLayers('m2','','hide','m1','','hide','m3','','hide','m4','','hide','m5','','hide');
	}
	if (x > 1) x = x - 1;
}


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_showHideLayers() { //v6.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3)
		if ((obj=MM_findObj(args[i]))!=null) {
		v=args[i+2];
		if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
		obj.visibility=v;
	}
}

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 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];}
}



/* Cookie function */
function readCookie(name) {
	var ca = document.cookie.split(';');
	var nameEQ = name + "=";
	for(var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
		}
	return null;
}

/*
function dd_StatusBarMsg(msgStr) { //v1.0 www.dazdezines.com/mme
	status=msgStr;
	document.MM_returnValue = true;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}
*/

var openImg = new Image();
openImg.src = "/img/open.gif";
var closedImg = new Image();
closedImg.src = "/img/closed.gif";

function showBranch(branch){
	var objBranch = document.getElementById(branch).style;
	if(objBranch.display=="block")
		objBranch.display="none";
	else
		objBranch.display="block";
}

function swapFolder(img){
	objImg = document.getElementById(img);
	if(objImg.src.indexOf('/img/closed.gif') > -1)
		objImg.src = openImg.src;
	else
		objImg.src = closedImg.src;
}


var txtsize_arr = new Array (3);								// Create Array to hold CSS class names
txtsize_arr[0] = "medium";
txtsize_arr[1] = "large";
txtsize_arr[2] = "xlarge";

function createCookie2(name,value,days)						// FUNCTION cookie creator
{
	if (days)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function cFont(toValue)										// FUNCTION to change font size
{
		var allDivs=document.getElementsByTagName("BODY");
		for (i=0;i<allDivs.length;i++)
	{
	allDivs[i].className=txtsize_arr[toValue];
		}
	createCookie2("cook_txtsize", toValue, 365);
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 7;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Revision of Flash required
var requiredRevision = 0;
// the version of javascript supported
var jsVersion = 1.0;
// -----------------------------------------------------------------------------

var isIE	= (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
jsVersion = 1.1;
// JavaScript helper required to detect Flash Player PlugIn version information
function JSGetSwfVer(i){
	// NS/Opera version >= 3 check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
			descArray = flashDescription.split(" ");
			tempArrayMajor = descArray[2].split(".");
			versionMajor = tempArrayMajor[0];
			versionMinor = tempArrayMajor[1];
			if ( descArray[3] != "" ) {
				tempArrayMinor = descArray[3].split("r");
			} else {
				tempArrayMinor = descArray[4].split("r");
			}
			versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
			flashVer = versionMajor + "." + versionMinor + "." + versionRevision;
				} else {
			flashVer = -1;
		}
	}
	// MSN/WebTV 2.6 supports Flash 4
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4;
	// WebTV 2.5 supports Flash 3
	else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3;
	// older WebTV supports Flash 2
	else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2;
	// Can't detect in all other cases
	else {
		flashVer = -1;
	}
	return flashVer;
}
// If called with no parameters this function returns a floating point value
// which should be the version of the Flash Player or 0.0
// ex: Flash Player 7r14 returns 7.14
// If called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
{
	 reqVer = parseFloat(reqMajorVer + "." + reqRevision);
		 // loop backwards through the versions until we find the newest version
	for (i=25;i>0;i--) {
		if (isIE && isWin && !isOpera) {
			versionStr = VBGetSwfVer(i);
		} else {
			versionStr = JSGetSwfVer(i);
		}
		if (versionStr == -1 ) {
			return false;
		} else if (versionStr != 0) {
			if(isIE && isWin && !isOpera) {
				tempArray 	= versionStr.split(" ");
				tempString	= tempArray[1];
				versionArray			= tempString .split(",");
			} else {
				versionArray			= versionStr.split(".");
			}
			versionMajor			= versionArray[0];
			versionMinor			= versionArray[1];
			versionRevision 	= versionArray[2];

			versionString 		= versionMajor + "." + versionRevision; 	// 7.0r24 == 7.24
			versionNum	= parseFloat(versionString);

			postURL("/flashVersion.do", "version="+versionMajor+"&subVersion="+versionRevision);
		// is the major.revision >= requested major.revision AND the minor version >= requested minor
			if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
				return true;
			} else {
				return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
			}
		}
	}
	return (reqVer ? false : 0.0);
}

function postURL(url, query) {
	if (url != "") {
		//whatNext = next;
		if (window.XMLHttpRequest) { // Non-IE browsers
			req = new XMLHttpRequest();
			try {
			  req.open("POST", url, true);
			  req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			  req.send(query);
			} catch (e) {
				//alert(e);
			}

		} else if (window.ActiveXObject) { // IE
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req) {
			    req.open("POST", url, true);
			    req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			    req.send(query);
			  }
		}
	}
}

startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		if (navRoot != null)	{
			for (var i=0; i < navRoot.childNodes.length; i++) {
	node = navRoot.childNodes[i];
	if (node.nodeName=="LI") {
		node.onmouseover=function() {
			this.className+=" over";
		}
		node.onmouseout=function() {
			this.className=this.className.replace(" over", "");
		}
	}
			}
		}
	}
}


window.onload=startList;


