/* 
	Using javascriptt files like this makes it easy to have frequently used code
	at one central location. All the HTML files can refer to this javascript
	and in that way it is possible to repeat the same kind of functionality. 
	This also saves on bandwidth, because less code has to be duplicated in the 
	individual webpages.
*/


function IsArray(obj) 
{
res = (obj.constructor.toString().indexOf("Array") == -1)	?	true : false;
return res;
}

function Trim(text)
{
return text.replace(/^\s*|\s*$/g,"");
}

function ReplaceAll(string,text,by)
{
var s = string.toString();
while(s.indexOf(text)	>	-1)
	{	s	=	s.replace(text,by);	}
return s;
}

function ValidEmail(address)
{
var a		=	address.indexOf('@');
var n		=	address.substring(0,a);
var h		=	address.substring(a+1);
var d		=	h.indexOf('.');
a			=	h.indexOf('@');
var res	=	((n	!=	'')	&&	(h	!=	'')	&&	(d	>	0)	&&	(d	<	h.length)	&&	(a	==	-1));
return res;
}

// Cross browser way of getting a reference to an object
function GetObjectByID(theid)
{
var res;
// First try using the level 1 DOM (IE 5, NS 6)
if (document.getElementById)
	{	
		res = document.getElementById(theid);	
	}
// Then try using older versions of IE
else if (document.all)
	{	
		res = document.all[theid];	
	}
// Then try using older versions of NS
else if (document.layers)
	{	
		res = document.layers[theid];	
	}	
// Finally try with an eval
else 
	{	
		res = eval(theid);	
	}
return res;
}

function GetObjectStyleByID(theid)
{
var res = null;
var o	=	GetObjectByID(theid);
if (o)
	{	
		res	=	(o.style)	?	o.style	:	o;	
	}
return res;
}

function ToggleCheckbox(formname,checkboxname,docheckbox,divname)
{
var frm	=	eval('document.' + formname);
if (frm)
	{
	var cb	=	eval('frm.' + checkboxname);
	var ds	=	GetObjectStyleByID(divname);
	if (cb && ds)
		{
		if (docheckbox)
			{	
				cb.checked	=	!cb.checked;	
			}
		ds.display	=	(cb.checked)	?	'block'	:	'none';
		}
	}
}
