﻿/******************************************************************************
*
*	Name:			IsNS()
*	Author:			Rudi Mostert
*	Description:	Checks if the browser is a Netscape browser.
*
******************************************************************************/
function IsNS()
{
	return navigator.appName.indexOf("Netscape") != -1;
}
/******************************************************************************
*
*	Name:			AddOnloadEvent()
*	Author:			Rudi Mostert
*	Description:	Allows any function to be executed when the page
*					has finished loading.
*
******************************************************************************/
function AddOnloadEvent(fnc)
{
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else 
      window.onload = fnc;
  }
}
/******************************************************************************
*
*	Name:			Floater()
*	Author:			Rudi Mostert
*	Description:	Creates a new floating element that floats to a point on
*					the screen.
*
******************************************************************************/
function Floater(id, sx, sy)
{
	var el=document.getElementById?document.getElementById(id):document.all?document.all[id]:document.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(document.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

	el.Float=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : IsNS() ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = IsNS() ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += IsNS() ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.Float()", 10);
	}
	return el;
}
/******************************************************************************
*
*	Name:			SwapImage()
*	Author:			Riekert Strydom
*	Description:	Performs a rollover for images.
*
******************************************************************************/
function SwapImage( sender, src )
{
	sender.src = src;
}
/******************************************************************************
*
*	Name:			ShowLoadingPanel()
*	Author:			Rudi Mostert
*	Description:	Shows the loading panel.
*
******************************************************************************/
function ShowLoadingPanel()
{
	var loading = document.getElementById("divLoadingPanel");
	if(loading)
	{
		loading.style.visibility = "visible";
		loading.style.top = 0;
		loading.style.left = 0;
		loading.style.width = screen.availWidth + "px";
		loading.style.height = screen.availHeight + "px";
	}
}
/******************************************************************************
*
*	Name:			HideLoadingPanel()
*	Author:			Rudi Mostert
*	Description:	Hides the loading panel.
*
******************************************************************************/
function HideLoadingPanel()
{
	var loading = document.getElementById("divLoadingPanel");
	if(loading)
	{
		loading.style.visibility = "hidden";
		loading.style.top = 0;
		loading.style.left = 0;
		loading.style.width = "0px";
		loading.style.height = "0px";
	}
}
/******************************************************************************
*
*	Name:			GetInputValue()
*	Author:			Rudi Mostert
*	Description:	Gets the value from an input element. Currently it
*					only works for textboxes.
*
******************************************************************************/
function GetInputValue( id )
{
	var result = null;
	var ctrl = document.getElementById(id);
	if(ctrl)result = ctrl.value;
	return result;
}
/******************************************************************************
*
*	Name:			SetInputValue()
*	Author:			Rudi Mostert
*	Description:	Sets the value for an input element. Currently it
*					only works for textboxes.
*
******************************************************************************/
function SetInputValue( id, value )
{
	var ctrl = document.getElementById(id);
	if(ctrl)ctrl.value = value;
}
/******************************************************************************
*
*	Name:			StayAlive()
*	Author:			Rudi Mostert
*	Description:	Makes a request to the server to keep the session alive.
*					This function should be called using a timeout.
*
******************************************************************************/
function StayAlive( url, interval )
{
	window.status = "Link to Server Refreshed " + new Date();
	var img = new Image(1,1);
	img.src = url + "?sid=" + Math.random();
	
	setTimeout( "StayAlive('" + url + "'," + interval + ")",interval);
}
/******************************************************************************
*
*	Name:			Debug()
*	Author:			Rudi Mostert
*	Description:	Writes to the debug window.
*
******************************************************************************/
function Debug( text, append )
{
	var d = document.getElementById("debug");
	if(d)
	{
		d.style.display = 'block';
		if(append)d.innerHTML += text + "<br/>";
		if(!append)d.innerHTML = text;
	}
}

