function select_by_value(select_ctrl, value) {
	for (var i = 0; i < select_ctrl.options.length; i++) {
		if (select_ctrl.options[i].value == value) {
			select_ctrl.selectedIndex = i;
			return;
		}
	}
}	

Ajax.prototype.abort = function() {
	if (this.req) this.req.abort();
	if (this.endHandler != null && !this.endHandlerCalled) {
//alert("in abort" + this.id);							
		this.endHandlerCalled = true;
		this.endHandler(null, null, this.param);
	}
}

Ajax.prototype.loadXMLDoc = function(url, sh, nh, eh) {	
	this.param = arguments[4];
	this.nodeHandler = nh;
	this.endHandler = eh;
	this.startHandler = sh;
	this.abort();
	this.endHandlerCalled = false;
	this.req = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			this.req = new XMLHttpRequest();
        } catch(e) {
			this.req = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	this.req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		this.req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		this.req = false;
        	}
		}
    }
	if(this.req) {
		var self = this;
		this.req.onreadystatechange = function() {
			// only if req shows "loaded"		
			if (self.req.readyState == 4) {
				// only if "OK"
				if (self.req.status == 200) {
					// proceso
					var response  = self.req.responseXML;
					
					if (response) {
						if (self.startHandler != null) self.startHandler(response, null, self.param);
						
						var nodo = response.firstChild;
						
						while (nodo) {
							if (self.nodeHandler != null) self.nodeHandler(response, nodo, self.param);
							nodo = nodo.nextSibling;
						}
						if (self.endHandler != null && !self.endHandlerCalled) {
//alert("in handler" + self.id);							
							self.endHandlerCalled = true;
							self.endHandler(response, nodo, self.param);
						}
					}
				} 
				else {					
					if (self.endHandler != null && !self.endHandlerCalled) {
//					alert("Problem: " + self.req.statusText);
						self.endHandlerCalled = true;
						self.endHandler(null, null, self.param);
					}
				}
			}
		};
		
		this.req.open("GET", url, true);
		this.req.send(null);
	}
	
	return true;
}

Ajax.prototype.req;
Ajax.prototype.param;
Ajax.prototype.nodeHandler;
Ajax.prototype.endHandler;
Ajax.prototype.startHandler;
Ajax.prototype.endHandlerCalled;

//var ajaxid = 0;

function Ajax() {	
	this.self = this;
	this.endHandlerCalled = true;
	
//	this.id = ++ajaxid;
}

