// ====================================================================
// 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";
	}
}
		
// ====================================================================
// OverLIB_String
// Makes strings OVERLIB friendly.
// Removes quotes(") and single quotes (') and replaces them.
// ====================================================================
function OverLIB_String(theString) {

	var newString = new String(theString);
	
	newString = newString.replace(/"/g,"&quot;");		
	newString = newString.replace(/'/g,"&rsquo;");
	
	return newString;
}


// ====================================================================
// Preload/mouseover Photoshop functions
// newImage(), changeImages()
// ====================================================================
var selected = '';
var preloadFlag = false;

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

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_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function changeImagesArray(array) {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<array.length; i+=2) {
			document[array[i]].src = array[i+1];
		}
	}
}

function changeImages() {
	changeImagesArray(changeImages.arguments);
}

function toggleImages() {
	for (var i=0; i<toggleImages.arguments.length; i+=2) {
		if (selected == toggleImages.arguments[i])      changeImagesArray(toggleImages.arguments[i+1]);
	}
}