function MM_findObj(n, d) { //v3.0
  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); 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];}
}
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];}}
}
//mailwin
function mailwin(theurl) {
	window.open(strWebRoot + "inc/mailpage.cfm?theurl="+theurl,"mailwin","width=400,height=280,status=no,scrollbars=yes,location=no,toolbar=no,menubar=no,resizable=yes");
}

function IsNumeric(val) {
	var ValidChars = "0123456789.";
	for (i=0; i<val.length; i++) {
		if (ValidChars.indexOf(val.charAt(i)) == -1) return false
	}
	return true
}

function IsEmpty(val) {
	for (i=0; i<val.length; i++) { 
		if (val.charAt(i) != ' ') return false
	}
	return true
}

function IsValidEmail(val) {
	var iLen = val.length;
	if 	((iLen < 6) || (val.indexOf('@') < 1) || ((val.charAt(iLen - 3) != '.') && (val.charAt(iLen - 4) != '.')) ) return false
	return true
}

function NumCBGroupChecked(f,strName){
	var colEl = f.elements;
	var iChecked = 0;
	for (var i=0; i<colEl.length; i++){
		el = colEl[i];
		if (el.name && (el.name == strName) && el.checked) iChecked++;
	}
	return iChecked;
}

function LTrim(s) {
	var whitespace = ' \t\n\r';
	if (s.length == 0) return s;
	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(s) {
	var whitespace = ' \t\n\r';
	if (s.length == 0) return s;
	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(s) {
   return RTrim(LTrim(s));
}

// Pops up a generic window
function PopWindow(strWindowName){
	var objForm = document.forms["data_form"];
	var intWidth = 510;
	var intHeight = 600;
	var intWindowWidth = (window.innerWidth) ? (window.innerWidth) : ( (document.body.clientWidth) ? document.body.clientWidth : 0 );
	var intWindowHeight = (window.innerHeight) ? (window.innerHeight) : ( (document.body.clientHeight) ? document.body.clientHeight : 0 );
	var intTop = Math.floor((intWindowHeight / 2) - (intHeight / 2));
	var intLeft = Math.floor((intWindowWidth / 2) - (intWidth / 2));
	var strProperties = "resizable=no,";
	
	// set top and left to zero
	intTop = 50;
	intLeft = 50;
	
	// Set up properties
	strProperties = (strProperties + "width=" + intWidth + ",height=" + intHeight + ",top=" + intTop + ",left=" + intLeft + ",status=yes");
	
	
	objWindow = window.open(
		"", 
		strWindowName, 
		strProperties
		);
		
	// Move the window to the center if it didn't center when openening
	objWindow.moveTo(intLeft, intTop);
		
	objWindow.focus();
}

function PopWindowURL(strWindowName, url){
	var objForm = document.forms["data_form"];
	var intWidth = 510;
	var intHeight = 600;
	var intWindowWidth = (window.innerWidth) ? (window.innerWidth) : ( (document.body.clientWidth) ? document.body.clientWidth : 0 );
	var intWindowHeight = (window.innerHeight) ? (window.innerHeight) : ( (document.body.clientHeight) ? document.body.clientHeight : 0 );
	var intTop = Math.floor((intWindowHeight / 2) - (intHeight / 2));
	var intLeft = Math.floor((intWindowWidth / 2) - (intWidth / 2));
	var strProperties = "resizable=no,";
	
	// set top and left to zero
	intTop = 50;
	intLeft = 50;
	
	// Set up properties
	strProperties = (strProperties + "width=" + intWidth + ",height=" + intHeight + ",top=" + intTop + ",left=" + intLeft + ",status=yes");
	
	
	objWindow = window.open(
		url, 
		strWindowName, 
		strProperties
		);
		
	// Move the window to the center if it didn't center when openening
	objWindow.moveTo(intLeft, intTop);
		
	objWindow.focus();
}

/*-------------------------------------------------------------------- 
 * javascript method: "pxToEm"
 * by:
   Scott Jehl (scott@filamentgroup.com) 
   Maggie Wachs (maggie@filamentgroup.com)
   http://www.filamentgroup.com
 *
 * Copyright (c) 2008 Filament Group
 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
 *
 * Description: Extends the native Number and String objects with pxToEm method. pxToEm converts a pixel value to ems depending on inherited font size.  
 * Article: http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/
 * Demo: http://www.filamentgroup.com/examples/pxToEm/	 	
 *							
 * Options:  	 								
 		scope: string or jQuery selector for font-size scoping
 		reverse: Boolean, true reverses the conversion to em-px
 * Dependencies: jQuery library						  
 * Usage Example: myPixelValue.pxToEm(); or myPixelValue.pxToEm({'scope':'#navigation', reverse: true});
 *
 * Version: 2.0, 08.01.2008 
 * Changelog:
 *		08.02.2007 initial Version 1.0
 *		08.01.2008 - fixed font-size calculation for IE
--------------------------------------------------------------------*/

Number.prototype.pxToEm = String.prototype.pxToEm = function(settings){
	//set defaults
	settings = jQuery.extend({
		scope: 'body',
		reverse: false
	}, settings);
	
	var pxVal = (this == '') ? 0 : parseFloat(this);
	var scopeVal;
	var getWindowWidth = function(){
		var de = document.documentElement;
		return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	};	
	
	/* When a percentage-based font-size is set on the body, IE returns that percent of the window width as the font-size. 
		For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size. 	
		When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size) 
		to get an accurate em value. */
				
	if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
		var calcFontSize = function(){		
			return (parseFloat($('body').css('font-size'))/getWindowWidth()).toFixed(3) * 16;
		};
		scopeVal = calcFontSize();
	}
	else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };
			
	var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
	return result;
};