// JavaScript Document

function xRequest(method, url) {
	var _this= new Object();
	
	if(typeof(method) == 'string') {
		_this.method= ((method.toLowerCase() == 'post')? method.toUpperCase(): 'GET');
	}
	else {
		_this.method= 'GET';
	}
	
	_this.self= this;
	
	this.onReceive= null;
	this.onAbort= null;
	
	this.version= 'xRequest 1.0';
	
	_this.httpRequest= false;
	_this.url= url;
	_this.timerid= null;
	_this.timeout= 30000;

	if(window.XMLHttpRequest) {
		_this.httpRequest= new XMLHttpRequest();
		if(_this.httpRequest) {
			try {
				_this.httpRequest.overrideMimeType('text/html');
			}
			catch (e) {}
		}
	}
	else if(window.ActiveXObject) {
		try {
			_this.httpRequest= new ActiveXObject('Msxml2.XMLHTTP');
		}
		catch (e) {
			try {
				_this.httpRequest= new ActiveXObject('Microsoft.XMLHTTP');
			}
			catch (e) {}
		}
	}
	
	if (!_this.httpRequest) {
		alert('Cannot create an XMLHTTP instance');
		return false;
	}
	
	_this.httpRequest.onreadystatechange= function() {
		if(_this.httpRequest.readyState == 4) {
			_this.self.status= _this.httpRequest.status;
			if (_this.httpRequest.status == 200) {
				_this.self.data= _this.httpRequest.responseText;
				
				if(typeof(_this.self.onReceive) == 'function') {
					if(_this.timerid != null) {
						window.clearInterval(_this.timerid);
						_this.timerid= null;
					}
					_this.self.onReceive();
				}
			}
		}
	}
	
	this.send= function(url, data) {
		_this.httpRequest.open(_this.method, (((typeof(url) == 'string') && (url != ''))? url: _this.url)+((_this.method == 'GET')? '&r='+Math.random(): ''), true);
		if(_this.method == 'POST') {
			  _this.httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			  _this.httpRequest.setRequestHeader('Content-Length', data.length);
		}
		_this.httpRequest.send(data);
		//alert(typeof(requestabort));

		if(typeof(requestabort) == 'function') {
			_this.timerid= window.setInterval("requestabort()", _this.timeout);
		}
	}

	this.abort= function() {
		if(_this.httpRequest.readyState < 4) {
			_this.httpRequest.abort();

			if(typeof(_this.self.onAbort) == 'function') {
				_this.self.onAbort();	
			}
			
			if(_this.timerid != null) {
				window.clearInterval(_this.timerid);
				_this.timerid= null;
			}
			
			return true;
		}
		
		return false;
	}
	
	requestabort= this.abort;
}

function xForm(id, formElement) {
	var _this= new Object();
	
	_this.self= this;
	_this.iframe= document.getElementById(id);
	_this.formElement= formElement;
	var time= new Date().getTime();
	_this.id= id+time;
	
	_this.onLoad= function() {
		var content= '';

		if(typeof(_this.iframe.contentWindow) == 'object') {
			content= _this.iframe.contentWindow.document.body.innerHTML;
		}
		else {
			content= _this.iframe.document.body.innerHTML;
		}

		if(typeof(_this.self.onLoad) == 'function') {
			_this.self.onLoad(content);
		}
		_this.onLoad2();
	}
	
	_this.onLoad2= function() {
		var content= '';
			
		if(typeof(_this.iframe.contentWindow) == 'object') {
			content= _this.iframe.contentWindow.document.body.innerHTML;
		}
		else {
			content= _this.iframe.document.body.innerHTML;
		}

		if(typeof(_this.self.onLoad2) == 'function') {
			_this.self.onLoad2(content,_this.formElement);
		}
	}
	
	if(!_this.iframe) {
		if(window.addEventListener) {
			_this.iframe= document.createElement('iframe');
			_this.iframe.name= _this.id;
			_this.iframe.id= _this.id;
		}
		else {
			_this.iframe= document.createElement('<iframe id="'+_this.id+'" name="'+_this.id+'" >');
			_this.iframe.src= 'javascript:false';
		}
			_this.iframe.style.position= 'absolute';
			_this.iframe.style.left= '0px';
			_this.iframe.style.top= '0px';
			_this.iframe.style.height= '0px';
			_this.iframe.style.width= '0px'
			_this.iframe.style.display= 'none';
		
		document.body.appendChild(_this.iframe);
	} 

	this.onLoad= null;
	this.onLoad2= null;
	
	this.send= function() {
		_this.form= _this.formElement.cloneNode(true);
		var formName= _this.id+'_form';
		var formId= _this.id+'_form';
			
		if(window.addEventListener){
			_this.form.setAttribute('id', formId);
			_this.form.setAttribute('name', formName);
			_this.form.setAttribute('target', _this.id);
			_this.iframe.contentWindow.document.body.innerHTML= "";
			_this.iframe.appendChild(_this.form);
			_this.iframe.removeEventListener('load', _this.onLoad, false);
			_this.iframe.addEventListener('load', _this.onLoad, false);
		}
		else{
			var _formParent= _this.formElement.offsetParent;
			_formParent.replaceChild(_this.form, _this.formElement);

			for(var i= 0; i < _this.formElement.elements.length; i++) {
				_this.formElement.elements[i].id= '___'+_this.formElement.elements[i].id;
			}

			var _formElement= _this.form;
			_this.form= _this.formElement;
			_this.formElement= _formElement;
			
			_this.form.style.position= "absolute";
			_this.form.style.left= "-10000px";
			_this.form.style.top= "-10000px";
			_this.form.style.display= "none";
			document.body.appendChild(_this.form);
			_this.form.setAttribute('name', formName);
			_this.form.setAttribute('id', formId);
			_this.form.setAttribute('target', _this.id);
			_this.iframe.detachEvent('onload', _this.onLoad);
			_this.iframe.attachEvent('onload', _this.onLoad);
		}
		
		_this.form.submit();
	}
}

var ping_done= true;

function ping() {
	if(ping_done) {
		var req= new xRequest('get');
		req.onReceive= function() {
			ping_done= true;
			//document.title= req.data;
		}
		var d= new Date();
		req.send('/ping.php?time='+d.getTime(), null);
		ping_done= false;
	}
}

window.setInterval(ping, 300000);