function debug(message)
{
   var debugNode = document.getElementById("debugData");
   var childNodes = debugNode.childNodes;

   var br = document.createElement("br");
   debugNode.insertBefore(br, childNodes[0]);
   var text = document.createTextNode(message);
   debugNode.insertBefore(text, childNodes[0]);
}

function setCookie( name, value, expire, path, domain ) 
{
   document.cookie = name + "=" + escape(value);
   
   if (expire == null)
   {
      var today = new Date();
      expire = new Date();
      expire.setTime( today.getTime() + 1000 * 60 * 60 * 24 * 365 );
   }
   
   document.cookie += "; expires=" + expire.toGMTString();
   
   if (path != null)
   {
      document.cookie += "; path=" + escape(path);
   }
   
   if (domain != null)
   {
      document.cookie += "; domain=" + domain;
   }
}

function getCookie(Name) 
{
   var search = Name + "=";
   
   if (document.cookie.length > 0)
   {
      offset = document.cookie.indexOf( search ); 

      if( offset != -1 ) 
      { 
         offset += search.length; 
         end = document.cookie.indexOf( ";", offset ); 

         if (end == -1 ) 
         { 
            end = document.cookie.length;
         }
         
         return unescape( document.cookie.substring( offset, end ) );
      } 
   }

   return null;
}

/* function to act like document.getElementById() where it isn't available */
if (!document.getElementById)
{
   document.getElementById = function(id)
   {
      if( document.all )
         return document.all.id;
      else
         return document.id;
   }
}

function cancelSelection()
{
   if (window.getSelection)
   {
      window.getSelection().removeAllRanges();
   }
   else if (document.selection)
   {
      document.selection.empty();
   }
   else if (document.getSelection)
   {
      // this.focus();
   }
}


function createAttribute(name, value)
{
   var attr = document.createAttribute(name);
   attr.nodeValue = value;
   return attr;
}
