//------------------------- Image Rollover Effects ----------------------------//

var cache = new Object;

function preload( name,image )
{
    if (document.images)
	{
		cache[name] = new Image();
		cache[name].src = image;
	}
}

function rollover( name )
{

    if (document.images)
	{
	  	var x;
	  	eval("x = document['" + name + "']" );
	  	cache.image = x;
	  	cache.src   = x.src;
		if( typeof(cache[name]) == "object" )
	  		x.src = cache[name].src;
	}
}

function restore()
{
	if (document.images)
	  cache.image.src = cache.src;
}


function goHistory( index )
{
	if( parent == self )
	{
		history.go( index );
	}
	else
	{
		history.back();
	}
}


//---------------------- Menu Rollover Effects -----------------------------------//

var imgMenuItemOn     = new Image;
var imgMenuItemOff    = new Image;
var imgMenuDefaultOn  = new Image;
var imgMenuDefaultOff = new Image;
var imgMenuNextOn     = new Image;
var imgMenuNextOff    = new Image;
var imgMenuBackOn     = new Image;
var imgMenuBackOff    = new Image;
var imgSubMenuOn      = new Image;
var imgSubMenuOff     = new Image;

imgMenuItemOn.src     = "/images/menu/itemOn.gif";
imgMenuItemOff.src    = "/images/menu/item.gif";
imgMenuDefaultOn.src  = "/images/menu/defaultOn.gif";
imgMenuDefaultOff.src = "/images/menu/default.gif";
imgMenuNextOn.src     = "/images/menu/nextOn.gif";
imgMenuNextOff.src    = "/images/menu/next.gif";
imgMenuBackOn.src     = "/images/menu/backOn.gif";
imgMenuBackOff.src    = "/images/menu/back.gif";
imgSubMenuOn.src      = "/images/menu/subMenuOn.gif";
imgSubMenuOff.src     = "/images/menu/subMenu.gif";


function menuOn( Item,Image )
{
	Item.style.background = "url('/images/menu/" + Image + "On.gif')";
	Item.style.cursor = "hand";
}

function menuOff( Item,Image )
{
	Item.style.background = "url('/images/menu/" + Image + ".gif')";
}

function subMenuOn( Item,ID )
{
	Item.style.background = "url('/images/menu/subMenuOn.gif')";
	cswmShow( ID, ID, 'right', -2,1 );
	Item.style.cursor = "hand";
}

function subMenuOff( Item )
{
	Item.style.background = "url('/images/menu/subMenu.gif')";
	cswmHide();
}


//---------------------- Button Rollover Effects ---------------------------------//

var imgButtonItemOn     = new Image;
var imgButtonItemOff    = new Image;
var imgButtonDefaultOn  = new Image;
var imgButtonDefaultOff = new Image;

imgButtonItemOn.src     = "/images/buttons/itemOn.gif";
imgButtonItemOff.src    = "/images/buttons/item.gif";
imgButtonDefaultOn.src  = "/images/buttons/defaultOn.gif";
imgButtonDefaultOff.src = "/images/buttons/default.gif";


function buttonOn( Item,Image )
{
	Item.style.background = "url('/images/buttons/" + Image + "On.gif')";
	Item.style.cursor = "hand";
}

function buttonOff( Item,Image )
{
	Item.style.background = "url('/images/buttons/" + Image + ".gif')";
}



//---------------------- Table Row MouseOver Highlighting -------------------------//

function highlight_on( Row )
{
	Row.style.backgroundColor = "#9999BB";
}

function highlight_off( Row, Style )
{
	if (Style == 'True' )
		Row.style.backgroundColor = "#312F4D";
	else
		Row.style.backgroundColor = "#69789C";
}

function headline_on( Row )
{
	Row.style.backgroundColor = "#E5EBFA";
}

function headline_off( Row )
{
	Row.style.backgroundColor = "transparent";
}


//--------------------- InfoTip DHTML Popup Handling ------------------------------//

var tipElement = new Object;

function infoTipOn( ID )
{
	var screenX = document.body.clientWidth;
	var screenY = document.body.clientHeight;

	tipElement = eval("document.all." + ID + ".style");

	if( event.x + 300 > screenX )
		tipElement.left = (event.x > 310)? event.x-305: 10;
	else tipElement.left = parseInt( event.x+10 );

	if( event.y + 200 > screenY )
		tipElement.top = event.y-115;
	else
		tipElement.top = parseInt( event.y+20 );

	tipElement.zIndex = "50";
	tipElement.visibility = "visible";
}

function infoTipOff()
{
	tipElement.visibility = "hidden";
}



//--------------------- Carriage Return Handling in Forms ------------------------//

function onReturn( Handler )
{
	if (event.keyCode == 13)
	{
		eval( Handler + "();" );
	}
}


//---------------------------- Popup Window Functions ----------------------------//


function help( Topic )
{
	location.href = '/help/default.asp?topic=' + Topic;
}

function messagePopup( msgName )
{
	openWin('/help/popup.asp?message=' + msgName,'message',480,180,"center");
}

function openWin( sSource, sName, iWidth, iHeight, sPosition )
{
	var xOffset = 0, yOffset = 0;
	var sFeatures = "";
	var noFrame   = false;
	var newWindow;

	// Check to see if 'noFrame' is specified in the position

	if( sPosition.slice(0,7) == "noFrame" )
	{
		noFrame = true;
		sPosition = sPosition.slice(8);
	}

	// Work out how big the screen is

	if (document.all)
	    var xMax = screen.width, yMax = screen.height;
	else if (document.layers)
	    var xMax = window.outerWidth, yMax = window.outerHeight;
    	else
	    var xMax = 800, yMax=600;

	// Work out the window positioning

	if (sPosition == "bottomLeft")
	{
		xOffset = 0;
		yOffset = (yMax - iHeight) - 60;
	}
	else if (sPosition == "topRight")
	{
		xOffset = (xMax - iWidth) - 8;
		yOffset = 0;
	}
	else if ( sPosition.match("[0123456789*]+:[0123456789*]+") )
	{
		xOffset = sPosition.substring( 0, sPosition.indexOf(":",0))
		yOffset = sPosition.substring( xOffset.length+1,sPosition.length );

		if( xOffset == "*" ) xOffset = (xMax - iWidth)/2;
		if( yOffset == "*" ) yOffset = (yMax - iHeight)/2;
	}
	else //center
	{
		xOffset = (xMax - iWidth)/2;
		yOffset = (yMax - iHeight)/2;
	}

	// Set the features of the window

	sFeatures = "width=" + iWidth + ",height=" + iHeight + ",scrollbars=yes";

	if (xOffset > 0 || yOffset > 0)
	{
		sFeatures = sFeatures + ",left=" + xOffset + ",top=" + yOffset;
		sFeatures = sFeatures + ",screenX="+ xOffset + ",screenY=" + yOffset;
	}

	// Open the new window with the calculated attributes

	if (noFrame)
	{
		sFeatures = "fullscreen," + sFeatures;
		newWindow = window.open( sSource, sName, sFeatures);
		newWindow.blur();
		window.focus();
		newWindow.resizeTo(iWidth,iHeight);
		newWindow.moveTo(xOffset,yOffset);
	}
	else
	{
		newWindow = window.open( sSource,sName,sFeatures );

		if (newWindow.opener == null)
		{
			newWindow.opener = self;
		}
	}

	newWindow.focus();
}


//---------------------- Disable Right Click -------------------------------------//

var message="";

function clickIE()
{
	if (document.all) {(message);return false;}
}

function clickNS(e)
{
	if(document.layers||(document.getElementById&&!document.all))
	{
	if (e.which==2||e.which==3) {(message);return false;}
	}
}

function disableRightClick()
{
	if (document.layers)
		{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
	else
		{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
}


//------------------- Validate Email Address for Correct Syntax ------------------//

function validateEmail(strEmail)
{
	var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var reg1    = new RegExp(reg1str);
    var reg2    = new RegExp(reg2str);
    var reg3    = new RegExp("\s");

    return (!reg1.test(strEmail) && reg2.test(strEmail) && (strEmail.indexOf(" ")<0)) ;
}


//------------------------ Miscellanious -----------------------------------------//

function printDoc()
{
   if (window.print)
   {
		if ( top.window != window )
		{
			top.frames[1].window.focus();
		}

   		window.print();
   }
   else
   {
       alert('Your browser doesn\'t support printing from this link. Use ctrl-p instead.')
   }
}

