//window.onerror=TrapError;	
// convert all characters to lowercase to simplify testing
var agt=navigator.userAgent.toLowerCase();

// *** BROWSER VERSION ***
// Note: On IE5, these return 4, so use is_ie5up to detect IE5.
var is_major=parseInt(navigator.appVersion);

var is_ie		= ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3		= (is_ie && (is_major < 4));
var is_ie4		= (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie5		= (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5	= (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
//var is_chrome	= (agt.indexOf("chrome") != -1)
var is_ie5up	= (is_ie && !is_ie3 && !is_ie4);
//is_ie5up = (is_chrome || is_ie5up);
var is_ie5_5up	=(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6     = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.") != -1) );
var is_ie6up   = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
var is_ie7     = (is_ie && (is_major == 4) && (agt.indexOf("msie 7.") != -1) );
var is_ie7up   = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5 && !is_ie6);

//Validates to ensure that the provided password meets a la mode's minimum standards 
//for strength and does not contain characters that are incompatible with our systems.
function IsValidPassword(szPassword)
{
	var nLowerAlpha = 0;
	var nUpperAlpha = 0;
	var nNumeric = 0;
	var nSpecial = 0;
	var nExclude = 0;
	var nMatchCount = 0;

	if(szPassword.length < 8)
		return false;

	var Special = "!@#$%^&*()_+-=;:[{]}\|.>,</?`~";
	var LowerAlpha = "abcdefghijklmnopqrstuvwxyz";
	var UpperAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var Numeric = "0123456789";
	var Exclude = "\\\"'"; //Currently Merak CertMail does not allow these three characters.

	for(i=0;i<szPassword.length;i++)
	{
		if(Special.indexOf(szPassword.charAt(i)) >= 0)
			nSpecial = 1;
		else if(LowerAlpha.indexOf(szPassword.charAt(i)) >= 0)
			nLowerAlpha = 1;
		else if(UpperAlpha.indexOf(szPassword.charAt(i)) >= 0)
			nUpperAlpha = 1;
		else if(Numeric.indexOf(szPassword.charAt(i)) >= 0)
			nNumeric = 1;
		else if(Exclude.indexOf(szPassword.charAt(i)) >= 0)
			nExclude = 1;
	}
	nMatchCount = nSpecial + nLowerAlpha + nUpperAlpha + nNumeric;
	if(nMatchCount >= 3 && nExclude == 0)
		return true;
	else
		return false;	
}
function ChangeImage(obj, ImagePath)
	{
		obj.src = ImagePath
	}    
	
function PreLoadImage(aryImages)
{
   	for(loop = 0; loop < aryImages.length; loop++)
    	{
    		var an_image = new Image();
    		an_image.src = aryImages[loop];
    	}		
}

function TrapError(msg)
	{
	alert(msg);
	return true;
	}	

function move_in(img_name,img_src)
	{
	document[img_name].src=img_src;
	}

function move_out(img_name,img_src)
	{
	document[img_name].src=img_src;
	}
	
	
function OpenWindowCentered(szURL, szWindowName, nHeight, nWidth, bytSizable, bytScrollBars)
	{
	//Centers a window and removes toolbars and such
	//1=True; 0=False
	var intTop = (screen.availHeight - nHeight) / 2;
	var intLeft = (screen.availWidth - nWidth) / 2;
				
	return window.open(szURL, szWindowName, "toolbar=no,  top=" + intTop + ", left=" + intLeft + ", location=no, directories=no, menubar=no, status=no, scrollbars=" + bytScrollBars + ", resizable=" + bytSizable + ", width=" + nWidth + ", height="+ nHeight + "");				
	}
		
	
function setRadioValue(radioName, value)
	{
	var collection = document.getElementsByName(radioName);
	
	for (i=0;i<collection.length;i++)
		{
		if (collection[i].value == value)
			{
			collection[i].checked = true;
			}
		}	
	}			
	
function getRadioValue(radioName)
	{
	var collection = document.getElementsByName(radioName);

	for (i=0;i<collection.length;i++)
		{
		if (collection[i].checked)
			return(collection[i].value);
		}
	}	
	
function toggle(e) 
	{
	if (e.style.display == "none") 
		{
		e.style.display = "";
		} 
	else 
		{
		e.style.display = "none";
		}
	}	
	
function ValidImage(szFileName)
	{
	//Valid Image Extensions
	var nLen = szFileName.length;
	var szExt = szFileName.substring(nLen - 3, nLen);
	
	switch(szExt.toLowerCase())
		{
		case "jpg":
			return(true);
		case "gif":
			return(true);
		case "bmp":
			return(true);
		case "png":
			return(true);
		default:
			return(false);
		}
	}
function imgTag()
	{
		if (document.selection.type == "Control")
		{ 
			var oRange = document.selection.createRange();
			if (oRange(0).tagName == 'IMG')
			{
				return(true);
			}				
		}
		return(false);
	}
	
function validEmail(szEmail) {
	var nIndexAT = szEmail.indexOf("@",1);
	var nIndexDot = szEmail.indexOf(".", nIndexAT);
	var nCounter, nIndexBad;
	var szInvalid = "/,;"

	if(szEmail != null || szEmail != "") {
		if (nIndexAT < 0 || nIndexDot < 0) {
			return false;
		} 
		for(nCounter=0; nCounter < szInvalid.length; nCounter++) {
			if (szEmail.indexOf(szInvalid.charAt(nCounter)) >= 0) {
				return false;
				break;
			}
		}
	}
	return true
}

function test(){
alert("test")
}

/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}

function TellMeMore(Left, Top, Width, Height, Text, Control)
{
	var szHtml = "<table width=100% cellspacing=3 cellpadding=3 border=0>";
	szHtml += "<tr><td colspan=3></td></tr>";
	szHtml += "<tr><td></td><td><div style='FONT-SIZE: 8pt; COLOR: #666666; FONT-FAMILY: Verdana;HEIGHT: 200px; Width: 100%;OVERFLOW-X: hidden; OVERFLOW: auto;'>";
	szHtml += "<p> <font face='Verdana' size='1'>";
	szHtml += Text;
	szHtml += "</font></p>";
	szHtml += "</div></td><td></td></tr>";
	szHtml += "<tr><td colspan=3></td></tr></table>";
	var oPopup = window.createPopup();
	oPopup.document.body.style.backgroundColor = "#FFFFC1";
	oPopup.document.body.style.border = "solid black 1px";
	oPopup.document.body.innerHTML = szHtml;
	oPopup.show(Left, Top, Width, Height, Control);
}

function resizeMe() {
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") 
		{
			top.moveTo(0,0);
			top.outerWidth=document.body.scrollWidth+70;
			top.outerHeight=document.body.scrollHeight+70;
		}
		else 
		{
			top.moveTo(0,0);
			top.resizeTo(300,200);
			top.resizeTo(document.body.scrollWidth+70,document.body.scrollHeight+70);
		}
	}
}
