var is = {
   opera: !!window.opera,
   ie: /*@cc_on!@*/false,
   khtml: navigator.userAgent.indexOf('KHTML') > -1,
   gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
   webkit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
   mac: navigator.userAgent.indexOf('Macintosh') > -1
}

function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj.attachEvent( 'on'+type, fn );
  } else
    obj.addEventListener( type, fn, false );
}

if (!window.Node) {
   var Node = {ELEMENT_NODE : 1, TEXT_NODE : 3};
}

function checkNode(node, filter) {
   return (filter == null || node.nodeType == Node[filter] || node.nodeName.toUpperCase() == filter.toUpperCase());
}

 function getNextSibling(node, filter){
   for(var sibling = node.nextSibling; sibling != null; sibling = sibling.nextSibling) {
      if(checkNode(sibling, filter)) return sibling;
   }
   return null;
}

function getNextSiblingByElement(node){
    return getNextSibling(node, "ELEMENT_NODE");
}

Object.extend = function(dest, source, allowOverwrite) {
   for (var prop in source) {
      if (source.hasOwnProperty(prop) && (allowOverwrite || !dest.hasOwnProperty(prop)))
         dest[prop] = source[prop];
   }
   return dest;
}

Object.extend(Function.prototype,
{
   bind: function() {
      var handler = this, args = Array.slice(arguments, 0), obj = args.shift();

      return function() {
         return handler.apply(obj, args.concat(Array.slice(arguments, 0)));
      }
   }
});

if (!window.XMLHttpRequest) {
   window.XMLHttpRequest = function() {
      var types = [
         'MSXML2.XMLHTTP.6.0',
         'MSXML2.XMLHTTP.3.0'
      ];

      for (var i = 0; i < types.length; i++) {
         try {
            return new ActiveXObject(types[i]);
         }
         catch(e) {}
      }

      return undefined;
   }
}

function Ajax2() {
   this.options = {
      method:      'GET',
      async:       false,
      contentType: 'application/x-www-form-urlencoded',
      encoding:    'ISO-8859-15',
      nocache:     false
   };

   this.requestObject = new XMLHttpRequest();
}

Object.extend(Ajax2.prototype,
{

   /**
    *
    */
   sendRequest: function(url, options, data) {
      if (!data) data = '';
      
      options = Object.extend(options || {}, this.options);
      
      this.requestObject.open('GET', url, true);
      this.requestObject.onreadystatechange = this.doHandle.bind(this, options);
      this.requestObject.send(data);
   },

   /**
    *
    */
   doHandle: function(options) {
      var requestObject = this.requestObject;
      var result = null;
      if (requestObject.readyState == 4) {

         if (!requestObject.status || requestObject.status == 200) {
            result = this.parseJSON(requestObject.responseText);
            
            if (options['handler']) result = options['handler'](result);
         }
         requestObject.onreadystatechange = function() {};
      }
      return result;
   },

   parseJSON: function(string) {
      try {
         return eval('(' + string + ')');
      }
      catch (e) { alert(e) }
      return false;
   }
});