var net = new Object();
net.READY_STATE_UNINITIALIZED=0;
net.READY_STATE_LOADING=1;
net.READY_STATE_LOADED=2;
net.READY_STATE_INTERACTIVE=3;
net.READY_STATE_COMPLETE=4;


net.CLoader=function(url,onload,onerror,inputField){
	
	this.url           = url;
	this.req           = null;
	this.jres          = null;
	this.onload        = (onload)       ? onload               : this.defaultUpdateContent;
	this.onerror       = (onerror)      ? onerror              : this.defaultError;
	this.inputField    = (inputField)   ? inputField           : null;
	this.inputFieldval =  null;
	this.params	   = null;
}

net.CLoader.prototype={
	
	
	loadXMLDoc:function(params, sync){
	       
		var aasync = (sync == 1) ? false : true;  	//defaults to async  

		if(window.XMLHttpRequest){
			this.req=new XMLHttpRequest();
		}
		else {
			this.req=new ActiveXObject("Msxml2.XMLHTTP");
                if (! this.req){
                    this.req=new ActiveXObject("Microsoft.XMLHTTP");
                }
		}
		if (this.req){
			try{
				var loader=this;
				this.req.onreadystatechange=function(){
					loader.onReadyState.call(loader);
				}
				
			
			this.req.open("POST",this.url,aasync);
			this.req.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");
			this.req.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); 
			this.req.setRequestHeader("Connection", "close");
			this.req.send( params );
			}
			catch(err){
			
				this.onerror.call(this);
			}
		}
           },
onReadyState:function(){
	var req=this.req;
	if (req.readyState==net.READY_STATE_COMPLETE){
		if (req.status==200 || req.status==0){
			this.onload.call(this);
		}
		else{
		this.onerror.call(this);
		}
	}
},
defaultError:function(){
    var mess = "Server connection error. Status: " + this.req.status;
    alert( mess );
},

defaultUpdateContent:function(){
self.status = "readyState: "+this.req.readyState +"\nstatus: "+this.req.status
}

}/* END of Cloader.prototype   */


/* utilities */ 
if (!$e){
	var $e = function(id){ return document.getElementById(id); };
}

if (!addEventL){
var addEventL = function(el, etype, handler){
		if (el.attachEvent) {
			el.attachEvent('on'+etype,handler);
		}
		else {
			el.addEventListener(etype, handler, false);
		}
	}
}

if (!hasClass){
var hasClass = function(el, name){
        if (el.className && ( el.className === name || el.className.indexOf(name) )){
			return true;
		}
		else {
			return false;
		}
}
}
