// <!--- opening a window to total "full screen" can be confusing - it makes the user think they have lost all of their windows - it is our convention that we open them *almost* full screen, and we should be consistent --->
var maxWidth = 750, maxHeight = 500, amp = "&";
try {
	if (screen && screen.availWidth && screen.availHeight) {
		maxWidth = screen.availWidth - 45;
		maxHeight = screen.availHeight - 125;
	} else if (self.screen && self.screen.width && self.screen.height) {
		maxWidth = self.screen.width - 45;
		maxHeight = self.screen.height - 125;
	}
} catch (e) {
	maxWidth = 750;
	maxHeight = 500;
}

if (document.images) {
	// preload images for all subpages
	img1 = new Image();
	img2 = new Image();
	img3 = new Image();
	img4 = new Image();
	img5 = new Image();
	img1.src = "/root/images/nav/company_state3.jpg";
	img2.src = "/root/images/nav/solutions_state3.jpg";
	img3.src = "/root/images/nav/clients_state3.jpg";
	img4.src = "/root/images/nav/news_state3.jpg";
	img5.src = "/root/images/nav/careers_state3.jpg";
}

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_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];}
}

var childWindow = null;
function openNewWindow(theURL,winName,features) {
	if (childWindow)
		{
		if (childWindow.close) childWindow.close();
		}
	childWindow = window.open(theURL,winName,features);
}


// Checks that the email address is properly formatted
function isEmail(ms) {
	var emailRE = /^[A-Za-z0-9\(\)\_\.\-]+\@[A-Za-z0-9\(\)\_\.\-]+\.[A-Za-z0-9\(\)\_\.\-]+$/;
	var trimmedEmail = Trim(ms.value);

	if (!trimmedEmail.match(trimmedEmail)) {
		return false;
	} else {
		return true;
	}
}

// Checks if field is filled out
function isFilled(ms) {
	if (ms.value == "" ||
		ms.value == null) {
		return false;
	} else {
		return true;
	}
}

function printAlert(message, useLastLineBreak) {
	if (typeof useLastLineBreak == 'undefined') {
		useLastLineBreak = true;
	}
	var theAlert = "_____________________________________     \n\n" + message;
	if (useLastLineBreak) {
		theAlert = theAlert + "\n";
	}
	theAlert = theAlert + "_____________________________________     ";
	alert(theAlert);
}

function expandCollapse(obj) {
	try {
		var showobj1 = document.getElementById(obj + "1");
		var showobj2 = false;  // this is not required
		if (document.getElementById(obj + "2")) {
			// if you want to swap two sections, you need a 2nd obj, but its not required
			showobj2 = document.getElementById(obj + "2");
		}
		var imgobj = document.getElementById("img" + obj);
		var innerHTML_obj = document.getElementById(obj + "_txt");

		if (showobj1) {
			targetState = (showobj1.style.display == "none" ? "" : "none");
		} else if (showobj2) {
			targetState = (showobj2.style.display == "none" ? "" : "none");
		}
		if (showobj2) {
			var oppState = (targetState == "none" ? "" : "none");
		}
		var imgState = (targetState == "none" ? "open" : "close");

		if (showobj1 && showobj1.style.display != targetState) {
			showobj1.style.display = targetState;
		}
		if (showobj2 && showobj2.style.display != oppState) {
			showobj2.style.display = oppState;
		}
		if (imgobj) imgobj.src = "/root/images/list_" + imgState + ".gif";

		if (innerHTML_obj) {
			// toggle the associated text with consistent verbiage
			if (innerHTML_obj.innerHTML == "hide") {
				innerHTML_obj.innerHTML = "view";
			} else {
				innerHTML_obj.innerHTML = "hide";
			}
		}
	} catch (e) {
		errorHandler(e, true, true, true, "expand/collapse error:", "obj=" + obj);
	}
}

function goToURL(theURL) {
	window.location = theURL;
}




// trim functions to be able to ignore white space when checking input fields
function LTrim(str) {
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      var j=0, i = s.length;
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      s = s.substring(j, i);
   }
   return s;
}
function RTrim(str) {
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      var i = s.length - 1;
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      s = s.substring(0, i+1);
   }
   return s;
}
function Trim(str) {
   return RTrim(LTrim(str));
}
