﻿// JScript File

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Just some handy short hand
function ID( sID )
{
	return document.getElementById( sID );
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Trim leading and trailing white space
function trim(str)
{
	return str.replace(/^\s*|\s*$/g,"");
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Set the cookie and return true if the cookie was sucessfully set
function GetCookie( sCookieName ) 
{
	// Locate the name if it exists
	var sCookieString = "" + document.cookie;
	var nNameStart = sCookieString.indexOf( sCookieName );
	if( nNameStart == -1 || sCookieName == "" ) 
		return ""; 
	var nNameEnd = nNameStart + sCookieName.length+1

	// Locate the end of the value or use the full length
	var nValueEnd = sCookieString.indexOf( ';', nNameStart );
	if( nValueEnd == -1 ) 
		nValueEnd = sCookieString.length; 

	// Check if the value is empty (no = sign)
	if( nNameEnd >= nValueEnd )
		return "";
	
	// Return what is between the '=' and ';'
	return unescape( sCookieString.substring( nNameEnd, nValueEnd ) );
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Set the cookie and return true if the cookie was sucessfully set
function SetCookie( sName, value, nDays )
{
	var sCookieString = sName+"="+escape( value )+";EXPIRES="+GetExpiryDate( nDays );
	document.cookie = sCookieString;
	return GetCookie( name );
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Return the UTC time for # days from now
function GetExpiryDate( nDays )
{
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse( Today );
	Today.setTime( nomilli+nDays*24*60*60*1000 );
	UTCstring = Today.toUTCString();
	return UTCstring;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Load the cookie value for the control of the same name.
function LoadValueCookie( sItemName )
{
	ID( sItemName ).value = GetCookie( sItemName );
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// Determine the width of the main frame
function Width()
{
	var x;
	if( self.innerHeight ) 
	{
		// all except Explorer
		x = self.innerWidth;
	}
	else if( document.documentElement && document.documentElement.clientHeight )
	{
		// Explorer 6 Strict Mode
		x = document.documentElement.clientWidth;
	}
	else if( document.body ) 
	{
		// other Explorers
		x = document.body.clientWidth;
	}
	return x;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// Determine the height of the main frame
function Height()
{
	var y;
	if( self.innerHeight ) 
	{
		// all except Explorer
		y = self.innerHeight;
	}
	else if( document.documentElement && document.documentElement.clientHeight )
	{
		// Explorer 6 Strict Mode
		y = document.documentElement.clientHeight;
	}
	else if( document.body ) 
	{
		// other Explorers
		y = document.body.clientHeight;
	}
	return y;
}

