
if (!Object.prototype.hasOwnProperty) {
	Object.prototype.hasOwnProperty = function(n) {
		try {
			var t = 'prototype', p = this.constructor[t];
			while (p)	{
				if (p[n] == this[n]) return false;
				p = p[t];
			}
		}	catch (e) { }
		return true;
	}
}

var __EB = {
	
	A: function(o, t, h) {
		if((o == document || o == window) && (t == 'DOMContentLoaded' || t == 'init')){
			h.G = h.G || this.G++;
			this.I.Hs = this.I.Hs || {};
			this.I.Hs[h.G] = h;
		}
		else if (o.addEventListener) o.addEventListener(t, h, false);
		else {
			h.G = h.G || this.G++;
			o.Es = o.Es || {};
			var Hs = o.Es[t];
			if (!Hs) {
				Hs = o.Es[t] = {};
				if (o["on" + t]) Hs[0] = o["on" + t];
			}
			Hs[h.G] = h;
			o["on" + t] = this.H;
		}
	},
	
	R: function(o, t, h) {
		if (o.removeEventListener) o.removeEventListener(t, h, false);
		else if (o.Es && o.Es[t] && h.G) delete o.Es[t][h.G];
	},
	
	H: function (ev) {
		ev = ev || __EB.F(((this.ownerDocument || this.document || this).parentWindow || window).event);
		var hs = this.Es[ev.type];
		for (var p in hs) {
			this.he = hs[p];
			if (this.he(ev) === false) return false;
		}
		return true;
	},
	
	F:  function (ev) { ev.preventDefault = this.F1; ev.stopPropagation = this.F2; return ev; },
	F1: function() { this.returnValue = false; },
	F2: function() { this.cancelBubble = true; },
	G: 1,
	
	I: function(){	
		var i = __EB.I;
		if(!i.Hs || i.done === true) return false;
		
		i.done = true;
		for(var p in i.Hs){
			if(i.Hs.hasOwnProperty(p)) {
				if(i.Hs[p]() === false) return false;
			}
		}
		return true;
	}
}

if(document.addEventListener) document.addEventListener('DOMContentLoaded', __EB.I, false);
/*@cc_on @if (@_win32)document.write("<script id=__ie defer src=//:><\/script>");document.getElementById("__ie").onreadystatechange=function(){if(this.readyState=="complete")__EB.I();}; @end @*/
if(/WebKit/i.test(navigator.userAgent)) __EB.saf = setInterval(function() { if(/loaded|complete/.test(document.readyState)) { if(__EB.saf) clearInterval(__EB.saf); __EB.I(); }	},10);

window.events = __EB; events.add = __EB.A; events.remove = __EB.R;
//events.add(window, 'load', events.I);

String.prototype.trim = function() { return this.replace(/^\s+/g, "").replace(/\s+$/g, ""); };

function Ajax(){
	this.xhr = null;
	this.waitingHandler = null;
	this.doneHandler = null;
	this.errorHandler = null;
	this.timeout = null;
	this.timeoutID = null;
	
	var that = this;
	
	this.handle = function(){
		if(that.xhr.readyState == 4){
			if(that.xhr.status == '200'){
				if(typeof that.doneHandler == 'function') that.doneHandler(that.xhr.responseText, that.xhr.responseXML);
			}
			else if(that.errorHandler){
				that.errorHandler(that.xhr.status, that.xhr.statusText);
			}
		}
		else if(that.waitingHandler) {
			that.waitingHandler(that.xhr.readyState);
		}
	}
	
	this.create();
}

Ajax.prototype = {
	
	create: function(){
		if(window.XMLHttpRequest) 
			this.xhr = new XMLHttpRequest();
		else if(window.ActiveXObject) {
			this.xhr = new ActiveXObject("Msxml2.XMLHTTP");
			if(!this.xhr) this.xhr = new ActiveXObject("Microsoft.XMLHTTP");
		}
		//if(!this.xhr) this.xhr.send = function(){ alert('Your browser doesn\'t support AJAX capability'); };
	},
	
	
	send: function(action, url, data){
		
		if(!this.xhr) return;
		
		try {
			if(action.toUpperCase() == "POST") {
				this.xhr.open(action, url, true);
				this.xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				this.xhr.onreadystatechange = this.handle;
				this.xhr.send(data);
			}
			else {
				this.xhr.open(action, url + (data ? '?' + data : ''), true);
				this.xhr.onreadystatechange = this.handle;
				this.xhr.send(null);
			}
			if(this.timeout) this.timeoutID = setTimeout(this.timeout);
		}
		catch(e){}
	},
	
	cancel: function(){
		if(that.timeoutID) {
			clearTimeout(that.timeoutID);
			that.timeoutID = null;
		}
		that.xhr.abort();
	}
	
}



