Utilities = {};

Utilities.includeJS = function(filepaths)
{
	for(var i=0; i<filepaths.length; i++)
	{
		document.write('<script type="text/javascript" src="'+filepaths[i]+'"></script>');
	}
}

Utilities.includeCSS = function(filepaths)
{
	for(var i=0; i<filepaths.length; i++)
	{
		document.write('<link href="'+filepaths[i]+'" rel="stylesheet" type="text/css" />');
	}
}

Utilities.getElement = function(i) { return document.getElementById(i); }

Utilities.disableSelection = function (element)
{
	element.onselectstart = function() {
	return false;
	};
	element.unselectable = "on";
	element.style.MozUserSelect = "none";
	element.style.cursor = "default";
}


Utilities.debug = function(val)
{
	this.getElement('debug').innerHTML += val +"<br/>";
}

Utilities.toggle = function(id)
{
	this.getElement(id).style.display = (this.getElement(id).style.display == '') ? 'none' : '';
}

Utilities.createElement = function(e, obj)
{
	var a = document.createElement(e);
	for(prop in obj)
	{
		a[prop] = obj[prop];
	}
	return a;
}

Utilities.appendChild = function()
{
	if(this.appendChild.arguments.length > 1)
	{
		var a = this.appendChild.arguments[0];
		for(i=1; i<this.appendChild.arguments.length; i++)
		{
			if(arguments[i])
			{
				a.appendChild(this.appendChild.arguments[i]);
			}
		}
		return a;
	}
	else
	{
		return null;
	}
}

// TODO: Addition
Utilities.removeChildren = function(node)
{
	if(node == null) { return; }
	
	while(node.hasChildNodes())
	{
		node.removeChild(node.firstChild);
	}
}

Utilities.IsNumeric = function (value)
{
	if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
  	return true;
}

Utilities.imgSwap = function (oImg)
{
   var strOver  = "On"    // image to be used with mouse over
   var strOff = "Off"     // normal image
   var strImg = oImg.src
   if (strImg.indexOf(strOver) != -1) 
	  oImg.src = strImg.replace(strOver,strOff)
   else
	  oImg.src = strImg.replace(strOff,strOver)
}

Utilities.showpic = function(pic,header,header_color,background_color,message,x,y)
{
  	oPopUp.display();
	Utilities.getElement('oPopUpHeadText').innerHTML = header;
	Utilities.getElement('oPopUpContentText').style.textAlign='center';
	Utilities.getElement('oPopUpContentText').innerHTML = '<img height="280" border="1" align="center" src="'+pic+'"/>';

}

// calculate the ASCII code of the given character
Utilities.CalcKeyCode = function(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

Utilities.checkNumber = function(val) {
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = Utilities.CalcKeyCode(lchar);

  /* Check if the keyed in character is a number
     do you want alphabetic UPPERCASE only ?
     or lower case only just check their respective
     codes and replace the 48 and 57 */

  if (cCode < 48 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}

Utilities.Get_Cookie = function ( name ) 
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

Utilities.Delete_Cookie = function( name, path, domain ) 
{
	if ( Utilities.Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}



