/**
 * @source ShadowDiablo
 * @copyright 2008
 */
 
/**
 * @class ajax
 * @version 1.0.1
 */
 
function ajax () {
	this.resource = 0;
	this.url      = "";
	this.postdata = new Array();
	this.datastr  = "";
	this.method   = 'GET';
		
	if ( window.XMLHttpRequest ) {
		this.resource = new XMLHttpRequest();
	}
	else if ( window.ActiveXObject ) {
		try {
			this.resource = new ActiveXObject('Msxml2.XMLHTTP');
		} catch(e) {
			this.resource = new ActiveXObject('Microsoft.XMLHTTP')	
		}
	}
		
	if ( ! this.resource ) {
		alert('Cannot establish connection. Please upgrade your internet browser.')
	}
}

ajax.prototype.connect = function( url ) {
	this.url = url;
	this.init();
}

ajax.prototype.init = function () {
	this.compressdata();
	this.resource.open( this.method, this.url, true );
	
	if ( this.method == 'GET' ) {
		this.resource.send(null);	
	}
	else {
		this.resource.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
		this.resource.send(this.datastr);
	}
}

ajax.prototype.add = function( key, value ) {
	this.postdata[ this.postdata.length ] = key + '=' + escape( value );
}

ajax.prototype.response = function () {
	return this.resource.responseText;
}

ajax.prototype.ready = function () {
	return ( this.resource.readyState == 4 && this.resource.status == 200 ) ? true : false;
}

ajax.prototype.compressdata = function() {
	var key;
	var str;
	
	if ( ! this.postdata.length ) {
		return;
	}
	
	this.method  = 'POST';
	this.datastr = this.postdata.join('&');
}

function change_data ( id, new_content ) {
	try {
		document.getElementById(id).innerHTML = new_content;
	}
	catch (e) {
		alert('Change data error with id: ' + id);
	}
}