var Class = {
   create: function() {
     return function() {
       this.initialize.apply(this, arguments);
     }
   }
};
var Try = {
   these: function() {
     var returnValue;

     for (var i = 0; i < arguments.length; i++) {
       var lambda = arguments[i];
       try {
         returnValue = lambda();
         break;
       } catch (e) {}
     }

     return returnValue;
   }
};
var Abstract = new Object();
Object.extend = function(destination, source) {
   for (property in source) {
     destination[property] = source[property];
   }
   return destination;
};
Function.prototype.bind = function(object) {
   var __method = this;
   return function() {
     __method.apply(object, arguments);
   }
};
var Ajax = {
     getTransport: function() {
         return Try.these(
             function() {return new ActiveXObject('Msxml2.XMLHTTP')},
             function() {return new ActiveXObject('Microsoft.XMLHTTP')},
             function() {return new XMLHttpRequest()}
         ) || false;
     }
};
Ajax.Base = function() {};
Ajax.Base.prototype = {
   setOptions: function(options) {
     this.options = {
       method:'post',
       asynchronous: true,
       parameters: ''
     }
     Object.extend(this.options, options || {});
   },
   responseIsSuccess: function() {
     return this.transport.status == undefined
         || this.transport.status == 0 
         || (this.transport.status >= 200 && this.transport.status < 300);
   },
   responseIsFailure: function() {
     return !this.responseIsSuccess();
   }
};

Ajax.Request = Class.create();
Ajax.Request.Events =   ['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
Ajax.Request.prototype = Object.extend(new Ajax.Base(),{
   initialize: function(url, options) {
     this.transport = Ajax.getTransport();
     this.setOptions(options);
     this.request(url);
   },
   request: function(url) {
     var parameters = this.options.parameters || '';
     if (parameters.length > 0) parameters += '&_=';

     try {
       this.url = url;
       if (this.options.method == 'get' && parameters.length > 0)
         this.url += (this.url.match(/\?/) ? '&' : '?') + parameters;
       this.transport.open(this.options.method, this.url, 
     this.options.asynchronous);
    if (this.options.asynchronous) {
         this.transport.onreadystatechange = this.onStateChange.bind(this);
         setTimeout((function() {this.respondToReadyState(1)}).bind(this), 10);
       }
   this.setRequestHeaders();
       var body = this.options.postBody ? this.options.postBody : parameters;
       this.transport.send(this.options.method == 'post' ? body : null);
     } catch (e) {
       this.dispatchException(e);
     }
    },
setRequestHeaders: function() {
     var requestHeaders =   ['X-Requested-With', 'XMLHttpRequest'];

     if (this.options.method == 'post') {
       requestHeaders.push('Content-type', 
         'application/x-www-form-urlencoded');
       if (this.transport.overrideMimeType)
         requestHeaders.push('Connection', 'close');
     }
     if (this.options.requestHeaders)
       requestHeaders.push.apply(requestHeaders, this.options.requestHeaders);

     for (var i = 0; i < requestHeaders.length; i += 2)
       this.transport.setRequestHeader(requestHeaders[i], requestHeaders[i+1]);
   },
   onStateChange: function() {
     var readyState = this.transport.readyState;
     if (readyState != 1)
       this.respondToReadyState(this.transport.readyState);
   },
   header: function(name) {
     try {
       return this.transport.getResponseHeader(name);
     } catch (e) {}
   },
   evalJSON: function() {
     try {
       return eval(this.header('X-JSON'));
     } catch (e) {}
   },
   evalResponse: function() {
     try {
       return eval(this.transport.responseText);
     } catch (e) {
       this.dispatchException(e);
     }
   },
   respondToReadyState: function(readyState) {
     var event = Ajax.Request.Events[readyState];
     var transport = this.transport, json = this.evalJSON();

     if (event == 'Complete') {
       try {
         (this.options['on' + this.transport.status]
          || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
          || function(){})(transport, json);
       } catch (e) {
         this.dispatchException(e);
       }
       if ((this.header('Content-type') || '').match(/^text\/javascript/i))
         this.evalResponse();
     }
    
     try {
       (this.options['on' + event] || function(){})(transport, json);
     } catch (e) {
       this.dispatchException(e);
     }
     if (event == 'Complete')
       this.transport.onreadystatechange = function(){};
   },
   dispatchException: function(exception) {
     (this.options.onException || function(){})(this, exception);
   }

   }
);
function $(element) {
   
     return  document.getElementById(element);

 }
 function $F(element) {

     return document.getElementById(element).value;

 }
