var Utils = {

	blayer: 'shadow_layer',

	browser: {
		IE:     !!(window.attachEvent && !window.opera),
    IE7:    (typeof document.addEventListener != 'function' && window.XMLHttpRequest),
    Opera:  !!window.opera,
		WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
		Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1
	},

	init: function()
	{
		if(document.layers)
		{
			if( window.onresize )
				this.old_resize = window.onResize;
			//window.captureEvents(Event.RESIZE);
			window.onresize = Utils.resize;
		}
		else
		{
			if( window.onResize )
				this.old_resize = window.onResize;

			window.onresize = Utils.resize;
		}

	},

	bodyWidth: function()
	{
		if( document.documentElement && document.documentElement.scrollWidth )
			return document.documentElement.scrollWidth;
		else if( document.body && document.body.scrollWidth )
			return document.body.scrollWidth;

		return document.body.scrollWidth;
	},
	windowWidth: function()
	{
		if( document.documentElement && document.documentElement.clientWidth )
			return document.documentElement.clientWidth;
		else if( document.body && document.body.clientWidth )
			return document.body.clientWidth;

		return 0;
	},

	bodyHeight: function()
	{
		var myWidth = 0, myHeight = 0;
		if( document.documentElement && document.documentElement.scrollHeight )
			return document.documentElement.scrollHeight;
		else if( document.body && document.body.scrollHeight )
			return document.body.scrollHeight;

		return document.body.clientHeight;
	},
	windowHeight: function()
	{
		if( document.documentElement && document.documentElement.clientHeight )
			return document.documentElement.clientHeight;
		else if( document.body && document.body.clientHeight )
			return document.body.clientHeight;

		return 0;
	},
	windowScrollHeight: function ()
	{
		if( window.pageYOffset )
			return window.pageYOffset;
		if( window.scrollY )
			return window.scrollY;

		return 0;
	},

	blockSite: function( order )
	{
		var block = document.getElementById( this.blayer );
		if( !block )
			return;

		block.style.display = 'block';
		block.style.display.zindex = order;
		block.style.width = this.bodyWidth() + "px";//this.getWidth( document.body ) + 'px';
		block.style.height = this.bodyHeight() + "px";//this.getHeight( document.body ) + 'px';
	},

	clearSite: function()
	{
		var block = document.getElementById( this.blayer );
		if( !block )
			return;

		block.style.display = 'none';
	},

	findPosX: function(obj)
	{
		var curleft = 0;
		if(obj.offsetParent)
			while(1)
			{
			  curleft += obj.offsetLeft;
			  if(!obj.offsetParent)
				break;
			  obj = obj.offsetParent;
			}
		else if(obj.x)
			curleft += obj.x;
		return curleft;
	},

	findPosY: function(obj)
	{
		var curtop = 0;
		if(obj.offsetParent)
			while(1)
			{
			  curtop += obj.offsetTop;
			  if(!obj.offsetParent)
				break;
			  obj = obj.offsetParent;
			}
		else if(obj.y)
			curtop += obj.y;
		return curtop;
	},

	getWidth: function( obj )
	{
		return obj.offsetWidth;
	},
	getHeight: function( obj )
	{
		return obj.offsetHeight;
	},

	getCursorPosition: function(e)
	{
	    e = e || window.event;
	    var cursor = {x:0, y:0};
		if( !e )
			return [0,0];
	    if (e.pageX || e.pageY) {
	        cursor.x = e.pageX;
	        cursor.y = e.pageY;
	    }
	    else {
	        var de = document.documentElement;
	        var b = document.body;
	        cursor.x = e.clientX +
	            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
	        cursor.y = e.clientY +
	            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
	    }
	    return cursor;
	},

	resize: function()
	{
		if( this.old_resize )
			this.old_resize();
		var block = document.getElementById( Utils.blayer );
		if( !block )
			return;
		if( block.style.display != "block" )
			return;
		block.style.width = Utils.bodyWidth() + "px";
		block.style.height = Utils.bodyHeight() + "px";
	},

	disableEnterKey: function(e)
	{
	     var key;

	     if(window.event)
	          key = window.event.keyCode;     //IE
	     else
	          key = e.which;     //firefox

	     if(key == 13)
	          return false;
	     else
	          return true;
	},


	/** BETA **/

	/**
    * Returns an HTMLElement reference
    * @param {String | HTMLElement} Accepts either a string to use as an ID for getting a DOM reference, or an actual DOM reference.
    * @return {HTMLElement} A DOM reference to an HTML element.
    */
    get: function(el) {
      if (typeof el == 'string') { // accept object or id
         el = document.getElementById(el);
      }

      return el;
    },

   /**
    * Normalizes currentStyle and ComputedStyle.
    * @param {String | HTMLElement} Accepts either a string to use as an ID for getting a DOM reference, or an actual DOM reference.
    * @param {String} property The style property whose value is returned.
    * @return {String} The current value of the style property.
    */
    getStyle: function(el, property) {
      var value = null;
      var dv = document.defaultView;

      el = this.get(el);

      if (property == 'opacity' && el.filters) {// IE opacity
         value = 1;
         try {
            value = el.filters.item('DXImageTransform.Microsoft.Alpha').opacity / 100;
         } catch(e) {
            try {
               value = el.filters.item('alpha').opacity / 100;
            } catch(e) {}
         }
      }
      else if (el.style[property]) {
         value = el.style[property];
      }
      else if (el.currentStyle && el.currentStyle[property]) {
         value = el.currentStyle[property];
      }
      else if ( dv && dv.getComputedStyle )
      {  // convert camelCase to hyphen-case

         var converted = '';
         for(i = 0, len = property.length;i < len; ++i) {
            if (property.charAt(i) == property.charAt(i).toUpperCase()) {
               converted = converted + '-' + property.charAt(i).toLowerCase();
            } else {
               converted = converted + property.charAt(i);
            }
         }

         if (dv.getComputedStyle(el, '').getPropertyValue(converted)) {
            value = dv.getComputedStyle(el, '').getPropertyValue(converted);
         }
      }

      return value;
    },

	/**
    * Gets the current position of an element based on page coordinates.  Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
    * @param {String | HTMLElement} Accepts either a string to use as an ID for getting a DOM reference, or an actual DOM reference.
    */
    getXY: function(el) {
      el = this.get(el);

      // has to be part of document to have pageXY
      if (el.parentNode === null || this.getStyle(el, 'display') == 'none') {
         return false;
      }

      /**
       * Position of the html element (x, y)
       * @private
       * @type Array
       */
      var parent = null;
      var pos = [];
      var box;

      if (el.getBoundingClientRect) { // IE
         box = el.getBoundingClientRect();
         var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
         var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;

         return [box.left + scrollLeft, box.top + scrollTop];
      }
      else if (document.getBoxObjectFor) { // gecko
         box = document.getBoxObjectFor(el);
         pos = [box.x, box.y];
      }
      else { // safari/opera
         pos = [el.offsetLeft, el.offsetTop];
         parent = el.offsetParent;
         if (parent != el) {
            while (parent) {
               pos[0] += parent.offsetLeft;
               pos[1] += parent.offsetTop;
               parent = parent.offsetParent;
            }
         }

         // opera & (safari absolute) incorrectly account for body offsetTop
         var ua = navigator.userAgent.toLowerCase();
         if (
            ua.indexOf('opera') != -1
            || ( ua.indexOf('safari') != -1 && this.getStyle(el, 'position') == 'absolute' )
         ) {
            pos[1] -= document.body.offsetTop;
         }
      }

      if (el.parentNode) { parent = el.parentNode; }
      else { parent = null; }

      while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') {
         pos[0] -= parent.scrollLeft;
         pos[1] -= parent.scrollTop;

         if (parent.parentNode) { parent = parent.parentNode; }
         else { parent = null; }
      }

      return pos;
    },

   /**
    * Gets the current X position of an element based on page coordinates.  The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
    * @param {String | HTMLElement} Accepts either a string to use as an ID for getting a DOM reference, or an actual DOM reference.
    */
    getX: function(el) {
      return this.getXY(el)[0];
    },

   /**
    * Gets the current Y position of an element based on page coordinates.  Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
    * @param {String | HTMLElement} Accepts either a string to use as an ID for getting a DOM reference, or an actual DOM reference.
    */
    getY: function(el) {
      return this.getXY(el)[1];
    }
}

function Checkbox( el, id )
{
  DisableCB();
  var p = document.getElementById( "cb_" + id );
  if ( !p )
    return;
  if( p.value == "0" )
  {
    el.innerHTML = "&times;";
    p.value = "1";
  }
  else
  {
    el.innerHTML = "&nbsp;"
    p.value = "0";
  }
}

function DisableCB()
{
  var i, el;
  for( i = 1; i<40; i++ )
  {
    el = document.getElementById( 'cb_' + i );
    if( el )
    {
      el.value = "0";
      el = document.getElementById( 'dcb_' + i );
      if( el )
        el.innerHTML = "&nbsp;";
    }
    else
      break;
  }
}

Utils.init();