//==JavaScript Document==//
function ajaxRoutine(){
	this.ajaxobj=false;
	this.filetype="txt";
	this.basedomain="http://"+window.location.hostname;
	this.addrandomnumber=0; //Set to 1 or 0. See documentation.
	
	this.init=function(){
		var ajaxObject=false;
		if (window.XMLHttpRequest){ // if Mozilla, Safari etc
			ajaxObject=new XMLHttpRequest()
			if (ajaxObject.overrideMimeType){
				ajaxObject.overrideMimeType('text/xml');
			}
		}
		else if (window.ActiveXObject){ // if IE
			try {
				ajaxObject=new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e){
				try{
					ajaxObject=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e){
					alert("Your browser is old, it doesn't support AJAX");	
				}
			}
		}
		//alert(ajaxObject);
		return(ajaxObject);
	}
	
	this.getAjaxRequest=function(url, parameters, handleAjaxResponse, filetyp){
		this.ajaxobj=this.init();
		if (addrandomnumber==1) //Further defeat caching problem in IE?
		var parameters=parameters+"&ajaxcachebust="+new Date().getTime();
		if (this.ajaxobj){
			this.filetype=filetyp;
			this.ajaxobj.onreadystatechange=handleAjaxResponse;
			this.ajaxobj.open('GET', url+"?"+parameters, true);
			this.ajaxobj.send(null);
		}
	}
	
	this.postAjaxRequest=function(url, parameters, handleAjaxResponse, filetyp){
		this.ajaxobj=this.init();
		if (this.ajaxobj){
			this.filetype=filetyp;
			this.ajaxobj.onreadystatechange = handleAjaxResponse;
			this.ajaxobj.open('POST', url, true);
			this.ajaxobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			this.ajaxobj.setRequestHeader("Content-length", parameters.length);
			this.ajaxobj.setRequestHeader("Connection", "close");
			this.ajaxobj.send(parameters);
		}
	}
	
	this.isAjaxResponseReady=function(){
		if (this.ajaxobj.readyState == 4){ //==if request of file completed==//
			if (this.ajaxobj.status==200 || window.location.href.indexOf("http")==-1){ //==if request was successful or running script locally==//
				return(true);
			}
		}
	}
	
	this.trapAjaxResponse=function(){
		if(this.filetype=='txt'){
			return(this.ajaxobj.responseText);
		}
		else{
			return(this.ajaxobj.responseXML);
		}
	}
}
