//********************************************************************
//*	       Name:	common_scripts.js
//*	Description:	JavaScript functions
//*	    Created:	09/28/2006
//*	    Updated:	09/28/2006
//********************************************************************

//********************************************************************
//* init()
//* Great window.onload hack from http://dean.edwards.name/
//* Takes care of funky screen remnants due to resizing DOM elements
//********************************************************************
function init() {
       // quit if this function has already been called
       if (arguments.callee.done) return;

       // flag this function so we don't do the same thing twice
       arguments.callee.done = true;
	   
	   //* Call the IE select text fix function
	   fnFixSelectBug();
	   
	   //* Call the fix content height function
       fnFixContentHeight();
   }

   /* for Mozilla */
   if (document.addEventListener) {
       document.addEventListener("DOMContentLoaded", init, null);
   }

   /* for Internet Explorer */
   /*@cc_on @*/
   /*@if (@_win32)
       document.write("<script defer src=_includes/ie_onload.js><"+"/script>");
   /*@end @*/

   /* for other browsers */
   window.onload = init;

//********************************************************************
//* fnFixContentHeight()
//* Compare the content column height with the height of the subnav bar.
//* If the content is shorter then it is automatically adjusted so it doesn't look like shit.
//********************************************************************
function fnFixContentHeight() {
	var objMainContainer = document.getElementById('MainContainer');
	var intMainContainer, y;
	
	// all except Explorer
	if (self.innerHeight) {
		y = self.innerHeight;
	}
	// Explorer 6 Strict Mode
	else if (document.documentElement && document.documentElement.clientHeight) {
		y = document.documentElement.clientHeight;
	}
	// other Explorers
	else if (document.body)
	{
		y = document.body.clientHeight;
	}
	
	// Get the height of the main container
	if (objMainContainer.offsetHeight) {
		intMainContainer = objMainContainer.offsetHeight;
	}
	else if (objMainContainer.style.pixelHeight) {
		intMainContainer = objMainContainer.style.pixelHeight;
	}
	
	if (intMainContainer < y) {
		objMainContainer.style.height = y + 'px';
	}
	else {
		objMainContainer.style.height = intMainContainer + 'px';
	}
}

//********************************************************************
//* fnFixSelectBug()
//* Fixes a bug in IE6 that screws up selecting text on a page with either
//* absolute positioning or floats (various reports of both).
//********************************************************************
function fnFixSelectBug() {
	if (window.createPopup && document.compatMode &&  
	document.compatMode=="CSS1Compat")
	{
	  document.onreadystatechange = onresize = function fixIE6AbsPos() 
	  {
		if (!document.body) return; 
		if (document.body.style.margin != "0px") document.body.style.margin = 0; 
		onresize = null; 
		document.body.style.height = 0; 
		setTimeout(function(){ document.body.style.height =  
	document.documentElement.scrollHeight+'px'; }, 1); 
		setTimeout(function(){ onresize = fixIE6AbsPos; }, 100); 
	  }
	}
}

//********************************************************************
//* fnPopupWindow(strFileName)
//* Opens a new popup window
//* strFileName = The name of the page to display in the window
//* intWinWidth = The desired width of the popup window
//* intWinHeight = The desired height of the popup window
//********************************************************************
function fnPopupWindow(strFileName, intWinWidth, intWinHeight) {
	var winWidth = intWinWidth;
	var winHeight = intWinHeight;
	var scrWidth = (screen.width - winWidth)/2;
	var scrHeight = (screen.height - winHeight)/2;
	winPopup = window.open(strFileName, 'winPopup', 'width=' + winWidth + ', height=' + winHeight + ', top=' + scrHeight + ', left=' + scrWidth + ', toolbar=no, menubar=no, scrollbars=yes, resizable=yes');
	if (window.focus) {
		winPopup.focus();
	}
	return false;
}

//********************************************************************
//* fnFormFocus(objElement, blnEvent)
//* Changes the background color of a form element when it is in focus
//* objElement = The form element to change
//* blnEvent = Whether the element is in or out of focus
//********************************************************************
function fnFormFocus(objElement, blnEvent) {
	if (blnEvent == 0) {
		objElement.style.backgroundColor = '#FFFFFF';
	}
	else {
		objElement.style.backgroundColor = '#FFFFCC';
	}
}

//********************************************************************
//* fnCheckEmail(strEmail)
//* Check if the string is a valid e-mail address. Returns true or false.
//* strEmail = The string to validate
//********************************************************************
function fnCheckEmail(strEmail) {
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(strEmail)) {
		return true;
	}
	else {
		return false;
	}
}

//********************************************************************
//* fnEmailProt(strEmail)
//* Replaces the text with a valid ampersand then opens the mail window
//********************************************************************
function fnEmailPot(strProtEmail) {
	var CleanEmail = strProtEmail.replace("[at]", "@");
	document.location.href='mailto:' + CleanEmail;
}