//<script language="javascript">
// Purpose:		A library of common javascript functions produced for use by
//				Klixo Ltd and its clients
// Version:		1.0.101
// Date:		28-Jun-2004
// Authors:		daniel@klixo.net
// Comments:	(c)2004 Klixo Ltd. All rights reserved. http://klixo.net.nz/
//				These functions are optimised for cross-browser compatibility

function kxSaveSetting(sName, sValue, dExpiry)
{
	// Purpose:		Saves a value into the cookie. 
	// Version:		1.4.156
	// Date:		28-Aug-2006
	// Author:		daniel@klixo.net.nz
	// COmments:	dExpiry is optional date object that contains an expiry date for the
	//				cookie, otherwise expiry will be set 1 year into the future	
	var dDate = new Date();
	
	if (dExpiry)
	{
		dDate = dExpiry;
	}
	else
	{
		var lYear = dDate.getYear() + 1;
		dDate.setFullYear(lYear);
	}
	
	var sCookie = sName + "=" + escape(sValue) + "; expires=" + dDate.toGMTString();
	document.cookie = sCookie;
}

function kxGetSetting(sName, sDefault)
{
	// Purpose:		Gets a named value from the cookie. If the value can't be found 
	//				then the default is returned
	// Version:		1.4.156
	// Date:		28-Aug-2006
	// Author:		daniel@klixo.net.nz
	var oCookie;
	var i;
	var oItem;

	oCookie = document.cookie.split("; ");
		
	for (i = 0; i < oCookie.length; i++)
	{
		var oItem = oCookie[i].split("=");
			
		if (sName == oItem[0])
		{
			sDefault = unescape(oItem[1]);
			break;
		}
	}

	return sDefault;
}


function StartTimer(lDuration, oCallback)
{
	// Purpose:		Starts a timer and returns a handle to the timer 
	// Version:		1.0.101
	// Date:		11-Oct-2004
	// Author:		daniel@klixo.net
	// Comments:	
	if (window.setInterval)
	{
		return window.setInterval(oCallback, lDuration, "javascript");
	}
	else
	{
		// Timer not supported so call the callback function now
		call(oCallback);
	}
}
                      
function StopTimer(lHandle)
{
	// Purpose:		Cancels a timeout timer
	// Version:		1.0.101
	// Date:		23-Aug-2004
	// Author:		daniel@klixo.net
	// Comments:	
    	
	if (window.clearInterval)
	{
		window.clearInterval(lHandle);
	}
}

function StartTimeout(lDuration, oCallback)
{
	// Purpose:		Starts a Timeout timer and returns a handle to the timer 
	// Version:		1.0.101
	// Date:		23-Aug-2004
	// Author:		daniel@klixo.net
	// Comments:	
	if (window.setTimeout)
	{
		return window.setTimeout(oCallback, lDuration, "javascript");
	}
	else
	{
		// Timer not supported so call the callback function now
		call(oCallback);
	}
}
                      
function StopTimeout(lHandle)
{
	// Purpose:		Cancels a timeout timer
	// Version:		1.0.101
	// Date:		23-Aug-2004
	// Author:		daniel@klixo.net
	// Comments:	
    	
	if (window.clearTimeout)
	{
		window.clearTimeout(lHandle);
	}
}

function PrintWindow()
{
	// Purpose:		Prints the contents of the window using 
	// Version:		1.0.101
	// Date:		23-Aug-2004
	// Author:		daniel@klixo.net
	// Comments:	
    window.print();
}

function OpenWindow(sURL, sID, sWidth, sHeight)
{
	// Purpose:		Opens a popup style window with the given dimensions
	// Version:		1.0.101
	// Date:		23-Aug-2004
	// Author:		daniel@klixo.net
	// Comments:
	//		sID = an object name for the window, e.g: winPopup. This can be used to
	//		reference the window later in code or by using the TARGET property of 
	//		the A tag.
	var oWindow;
                    		
	oWindow = window.open(sURL, sID, 'height=' + sHeight + ',width=' + sWidth 
		+ ',location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes,resizable=yes');
	oWindow.focus();
    	
	return oWindow;
}

function PreLoadImage(sSrc)
{
	// Purpose:		Background loads an image from sSrc
	// Version:		1.0.101
	// Date:		16-Aug-2004
	// Author:		daniel@klixo.net
	// Comments:	
	var oImage = new Image();
			
	oImage.src = sSrc;
}
		
function SwapImage(oImage, sSrc)
{
	// Purpose:		Changes the src of an image to display sSrc
	// Version:		1.0.101
	// Date:		16-Aug-2004
	// Author:		daniel@klixo.net
	// Comments:	
	oImage.src = sSrc;
}

function HandleError(e)
{
	// Purpose:		Generic Error Handler
	// Version:		1.0.101
	// Date:		30-Jul-2004
	// Author:		daniel@klixo.net
	// Comments:	Supports IE and NN6		
	alert('AN ERROR HAS OCCURRED\n' + e);
}

function GetObject(sID)
{
	// Purpose:		Gets a DHTML object based on its ID
	// Version:		1.0.101
	// Date:		28-Jun-2004
	// Author:		daniel@klixo.net
	// Comments:	Supports IE and NN6
    return document.getElementById(sID);
}
	
function DisplayObject(sID, bDisplay)
{
	// Purpose:		Shows or hides a DHTML object by setting its display style
	//				property.
	// Version:		1.0.101
	// Date:		28-Jun-2004
	// Author:		daniel@klixo.net
	// Comments:	Supports IE and NN6
   var oObject;
   var sDisplay;
                       
   if(bDisplay == false)
   {
       sDisplay = "none";
   }
   else
   {
       sDisplay = "block";
   }
                       
   oObject = GetObject(sID);
   oObject.style.display = sDisplay; 
                       
   return true;
}
	
function Navigate(oWindow, sURL)
{
	// Purpose:		Navigates oWindow to sURL
	// Version:		1.0.101
	// Date:		28-Jun-2004
	// Author:		daniel@klixo.net
	// Comments:	Supports IE and NN6
                       
	oWindow.location = sURL;
		                       
	return true;
}





//</script>