function Ajax(){

	this.method = null;
	this.action = null;
	this.asynch = true;
	this.qstring = null;
	this.pb = new Array();
	this.postParams = null;

	this.start = function(method, action){
		this.method = method;
		this.action = action;
		getAjax(this);
	}
	this.respond = function(pb){
		//this.getByNameAttr("lang", "", "");
        if (typeof this.followup == 'function') this.followup.call(this);
		else if(typeof this.followup == 'string'){eval(this.followup);}
	}


	this.addParam = function(name, value){
		if(this.qstring != null){this.qstring = this.qstring + "&";} else {this.qstring = "";}
		this.qstring = this.qstring + cleanVar(name) + "=" + cleanVar(value);
	}

	this.getByNameAttr = function(tagname, attr, attrval){
		if(this.pb[1] != null){
			var x = this.pb[1].getElementsByTagName(tagname);
			xml_doc = new ActiveXObject("Microsoft.XMLDOM"); 
			for(i=0;i<x.length;i++){
			//xml_doc.create
			}
		} else {alert("Empty Result Set");}
	}
	
}





function getAjax(x){
	var mode = 1;
	var passBack = Array(null, null);
	var http;
	var isIE = false;
	if(navigator.appName == "Microsoft Internet Explorer"){isIE = true;}
	if (window.XMLHttpRequest && !isIE){http = new XMLHttpRequest();mode=2;} 
	else if (window.ActiveXObject){http = new ActiveXObject("Microsoft.XMLHTTP");} 
	else {x.respond(passBack);}
	var useAction = x.action;
	if(x.method == "GET" && x.qstring != null){
		useAction = useAction + "?" + x.qstring;
	}
	
	http.open(x.method, useAction, x.asynch);
	if(x.method == "POST"){
		http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      	http.setRequestHeader("Content-length", x.postParams.length);
     	http.setRequestHeader("Connection", "close");
      	http.send(x.postParams);
	}
	
	
	http.onreadystatechange = function(){
		if(http.readyState == 4){
			if(http.status != 404){
				x.pb[0] = http.responseText;
				if(mode == 1){
					var xh = new ActiveXObject("Microsoft.XMLDOM");
					xh.loadXML(http.responseText);
					x.pb[1] = xh;
				} else {
					var useText = http.responseText;
					var objDOMParser = new DOMParser();
					x.pb[1] = objDOMParser.parseFromString(useText, "text/xml");
				}
			x.respond(passBack);
			} else {x.respond(passBack);}
		}
	};
	if(x.method != "POST"){http.send(x.qstring);}
	try{
	} catch (e) {x.respond(passBack);}
}

function addElement(rparent, type, rid, rclass, innerhtml) {
	var ni = document.getElementById(rparent);
	var newdiv = document.createElement(type);
	if(rclass.length > 0){
		newdiv.setAttribute('class',rclass);
		}
	if(rid.length > 0){
		newdiv.setAttribute('id',rid);
		}
	newdiv.innerHTML = innerhtml;
	ni.appendChild(newdiv);
	}

function addDirectElement(rparent, rchild) {
	var ni = document.getElementById(rparent);
	var newdiv = document.getElementById(rchild)
	ni.appendChild(newdiv);
	}

function removeElement(rparent, divID) {
	var d = document.getElementById(rparent);
	var olddiv = document.getElementById(divID);
	d.removeChild(olddiv);
	}