// ====================================================================
// breakFrames()
// Break out of frames.
// ====================================================================
function breakFrames() {
	if (window != top) top.location.href = location.href;
}

// ====================================================================
// killPopupWindow()
// Close this window if we are in a popup window. We do this so the login 
// screen doesn't appear erroneously in a popup.  A window is considered 
// a popup window if the window.name is prefixed with 'popup' 
// (i.e., window.name = 'popupchangesettings').
// ====================================================================
function killPopupWindow() {
	if(window.name != null) {
		var windowname = window.name.toLowerCase();
		var windowresult =  windowname.indexOf("popup");
		if (windowresult == 0) {
			if(window.opener != null) {
				// got opener, probably main page, reset to login so the user doesn't get confused by popup pages not working.
				window.opener.location.href = 'application_login.cfm?err=Your%20session%20has%20timed%20out.%20Please%20log%20back%20in%20to%20continue.';
			}
			window.close();
		}	
	}
}

// ====================================================================
// MM_openBrWindow(theURL,winName,features)
// Opens a popuwindow with the location of 'theURL', windowname of 
// 'winName' and the window features of 'features'.
// ====================================================================
function MM_openBrWindow(theURL,winName,features) { //v2.0
  var winVar = window.open(theURL,winName,features);
  //return winVar;
}

// ====================================================================
// maximizeAndFocus(xwidth,yheight)
// Moves window to top left corner, changes window focus to self.
// Vars xwidth and yheight are optional;
// if provided, changes window sizes to those values
// if not provided, changes window size to maximum available area.
//
// Note that this function can cause a Javascript "Access is Denied"
// error if not called onLoad().
// ====================================================================
function maximizeAndFocus(xwidth,yheight) {
	top.window.moveTo(0,0);
	
	if((xwidth == undefined) || (yheight == undefined)) {
		x = screen.availWidth;
		y = screen.availHeight;
	}
	else {
		x = xwidth;
		y = yheight;
		// don't allow x or y to be greater than screen boundaries
		if(x > screen.availWidth) {
			x = screen.availWidth;
		}
		if(y > screen.availHeight) {
			y = screen.availHeight;
		}
	}
			
	if (document.all) {
		top.window.resizeTo(x,y);
	}
	else if (document.layers||document.getElementById) {
		if (top.window.outerHeight<screen.availHeight||top.window.outerWidthscreen.availWidth){
			top.window.outerHeight = x;
			top.window.outerWidth = y;
		}
	}
	self.focus();
}

// ====================================================================
// formFocus()
// Set the focus to the first field in a form
// ====================================================================
function formFocus() {
	// send focus to the first field in a form
	if (document.forms.length > 0) {
		var TForm = document.forms[0];
		for (i=0;i<TForm.length;i++) {
			if (	(TForm.elements[i].type=="text")||
				(TForm.elements[i].type=="textarea")||
				(TForm.elements[i].type.toString().charAt(0)=="s") ) {
					document.forms[0].elements[i].focus();
					break;
			}
		}
	}
}

// ====================================================================
// setStyleDisplay(whichEl,type)
// Shows or hides any block element.
// If type = 'show' then shows it, else hides it.
// ====================================================================
function setStyleDisplay(whichEl,type)
{
	if( type == "show" ) {
		whichEl.style.display = "block";
	}
	else {
		whichEl.style.display = "none";
	}
}
		
// ====================================================================
// Cookie Functions
// WM_setCookie(), WM_readCookie(), WM_killCookie()
// A set of functions that eases the pain of using cookies.
// ====================================================================
// This next little bit of code tests whether the user accepts cookies.
var WM_acceptsCookies = false;
if(document.cookie == '') {
	document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.
	if(document.cookie.indexOf('WM_acceptsCookies=yes') != -1) {
		WM_acceptsCookies = true; 
	}// If it succeeds, set variable
} 
else { // there was already a cookie
	WM_acceptsCookies = true;
}

function WM_setCookie (name, value, hours, path, domain, secure) {
	if (WM_acceptsCookies) { // Don't waste your time if the browser doesn't accept cookies.
		var not_NN2 = (navigator && navigator.appName && (navigator.appName == 'Netscape') && navigator.appVersion && (parseInt(navigator.appVersion) == 2))?false:true;
		
		if(hours && not_NN2) { // NN2 cannot handle Dates, so skip this part
			if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
				var numHours = hours;
			} 
			else if (typeof(hours) == 'number') { // calculate Date from number of hours
				var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
			}
		}
		document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
	}
} // WM_setCookie

function WM_readCookie(name) {
	if(document.cookie == '') { // there's no cookie, so go no further
		return false; 
	}
	else { // there is a cookie
		var firstChar, lastChar;
		var theBigCookie = document.cookie;
		firstChar = theBigCookie.indexOf(name);     // find the start of 'name'
		var NN2Hack = firstChar + name.length;
		if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // if you found the cookie
			firstChar += name.length + 1; // skip 'name' and '='
			lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
			if(lastChar == -1) lastChar = theBigCookie.length;
				return unescape(theBigCookie.substring(firstChar, lastChar));
		}
		else { // If there was no cookie of that name, return false.
			return false;
		}
	}     
} // WM_readCookie

function WM_killCookie(name, path, domain) {
	var theValue = WM_readCookie(name); // We need the value to kill the cookie
	if(theValue) {
		document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
	}
} // WM_killCookie

// ====================================================================
// Preload/mouseover Photoshop functions
// newImage(), changeImages()
// ====================================================================
var preloadFlag = false;
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}