// *********************************************************************
// *                   INITIALIZATION				       *
// *********************************************************************

AttachEvent(window, 'load', InstanciateSupervisor);

// *********************************************************************
// *                   INCLUDES					       *
// *********************************************************************

function include(fileName)
{
  var Head = document.getElementsByTagName('head')[0];
  var Script = document.createElement('script');
  Script.setAttribute('type','text/javascript');
  Script.setAttribute('src',fileName);
  Head.appendChild(Script);
}

//include('FLOATER/FLOATER.js');
//include('SUPERVISOR/SUPERVISOR.js');
//include('AJAX/AJAX.js');
//include('XMLDOM/XMLDOM.js');

// *********************************************************************
// *                   EXCEPTIONS				       *
// *********************************************************************

function Exception(number, message)
{
   this.number = number;
   this.message = message;
}

// *********************************************************************
// *                   POINT				     	       *
// *********************************************************************

function Point(x, y)
{
   this.x = x;
   this.y = y;
}

// *********************************************************************
// *                   OFFSET POSITIONS			     	       *
// *********************************************************************

function offsetLeft(obj)
{
   if(obj.offsetParent) { return (obj.offsetLeft + offsetLeft(obj.offsetParent)); }
   else { return (obj.offsetLeft); }
}

function offsetTop(obj)
{
   if(obj.offsetParent) { return (obj.offsetTop + offsetTop(obj.offsetParent)); }
   else { return (obj.offsetTop); }
}

function offsetPosition(obj, position)
{
   if(!position) { var position = new Point(0, 0); }
   position.x += obj.offsetLeft;
   position.y += obj.offsetTop;
   if(obj.offsetParent)
   { return offsetPosition(obj.offsetParent, position); }
   else { return position; }
}

// *********************************************************************
// *                   STARTWITH			     	       *
// *********************************************************************

String.prototype.startWith = function(s)
{
   try { return (this.substring(0, s.length) == s); } catch(e) { return false; }
}

// *********************************************************************
// *                   ENDWITH				 	       *
// *********************************************************************

String.prototype.endWith = function(s)
{
   try { return (this.substring(this.length - 1) == s); } catch(e) { return false; }
}

// *********************************************************************
// *                   	TRIM				     	       *
// *********************************************************************

String.prototype.trim = function()
{   return this.replace(/^\s*|\s*$/g, ""); }

// *********************************************************************
// *                   REPLACEALL			     	       *
// *********************************************************************

String.prototype.replaceAll = function(strFind, strReplace)
{
   if (!strFind) { return this; }
   if (!strReplace) { strReplace = ''; }
   strFind = strFind.replace(/(\^|\$|\[|\]|\(|\)|\||\*|\+|\.|\?|\{|\}|\\)/gi, '\\$1');
   return this.replace(new RegExp(strFind, 'g'), strReplace);
}

// *********************************************************************
// *                   TOINTEGER			     	       *
// *********************************************************************

String.prototype.toInteger = function()
{ return parseInt(this); }

// *********************************************************************
// *                   TOFLOAT				     	       *
// *********************************************************************

String.prototype.toFloat = function()
{ return parseFloat(this); }

// *********************************************************************
// *                   TOBOOLEAN			     	       *
// *********************************************************************

String.prototype.toBoolean = function()
{
   switch(this.toLowerCase())
   {
      case 'true': return true;
      case 'false': return false;
      default: throw new Exception('toBoolean failed: cannot parse value.');
   }
}

// *********************************************************************
// *                   UNIQID				     	       *
// *********************************************************************

function UniqID()
{
   InstanciateSupervisor();
   var uniqID = new Date().getTime();
   uniqID = (uniqID <= supervisor.customs['Supervisor_UNIQID']) 
   ? ++supervisor.customs['Supervisor_UNIQID'] : uniqID;
   supervisor.customs['Supervisor_UNIQID'] = uniqID;
   return uniqID;
}

// *********************************************************************
// *                   INSTACIATE SUPERVISOR		     	       *
// *********************************************************************

function InstanciateSupervisor()
{
   if(supervisor == null)
   {
      supervisor = new Supervisor();
      supervisor.customs['Supervisor_zIndex'] = 100;
      supervisor.customs['Supervisor_UNIQID'] = 0;
   }
}

// *********************************************************************
// *                   EVENTS MANAGEMENT	     	      	       *
// *********************************************************************

function AttachEvent(object, eventName, action)
{
   if (object.attachEvent){ object.attachEvent('on' + eventName, action); }
   else { object.addEventListener(eventName, action, false); }
}

function DetachEvent(object, eventName, action)
{
   if (object.detachEvent){ object.detachEvent('on' + eventName, action); }
   else { object.removeEventListener(eventName, action, false); }
}