// JavaScript Document
/* ---------------------- AJAX ------------------------- */

/* Ajax function class */
/* Declarations */
var arAjxXML = new Array(1);
var arStopsXML = new Array;



/* ajFetchXML function */
function ajFetchXML(url, destination, cycle, delay, noloading) {
	//alert(1);
	/* Execution timer */
	var timerOne = new Date();
	floatInt = timerOne.getTime();
	//
	
	var curInstance;
	if (cycle == null) {
		cycle = false;	
	}
	if (noloading == null) {
		noloading = false;	
	}
	
	if (arAjxXML.length == 1) {
		curInstance = 1;
		arAjxXML[1] = new AjaxCreateObjectXML;
	} else {
		var found = false;
		for (i=1;i<arAjxXML.length;i++) {
			if (arAjxXML[i].Is_Free()) {
				curInstance = i;
				found = true;
			}
		}
		
		if (!found) {
			arAjxXML.push(new AjaxCreateObjectXML);
			curInstance = arAjxXML.length;
			arAjxXML[curInstance] = new AjaxCreateObjectXML;
		}
	}
	
	if (noloading) { arAjxXML[curInstance].Set_Loading(false); }
	
	arAjxXML[curInstance].HTTP_Get(url, destination);
	
	if (arStopsXML[destination] != true) {
		if (cycle) {
			setTimeout("ajFetchXML('"+url+"','"+destination+"',true,"+delay+");",delay);
		}
	} else {
		arStopsXML[destination] = null;
	}
}

/* Ajax functions, objects, classes and callback */
function AjaxCreateObjectXML() {
	/* Declarations */
	/* Public methods */
	this.HTTP_Get = HTTP_Get;
	this.Is_Free = Is_Free;
	this.Set_Loading = Set_Loading;
		
	/* Private variables */
	var ajobj = XMLHTTP_object();
	var http_destobj = null;
	var free = true;
	var show_loading = true;

	/* Methods */
	function HTTP_Get(url, destination) {
		if (free && (url != null) && (destination != null) && ((ajobj.readyState == 0) || (ajobj.readyState == 4))) {
			http_destobj = destination;
			
			ajobj.open("GET", url, true);
			ajobj.onreadystatechange = HTTP_Get_CallBack;
			ajobj.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
			ajobj.send(null);
			free = false;
		} else {
			return false;
		}
	}
	
	/* Get CallBack (Handle received data) */
	function HTTP_Get_CallBack() {
		if (ajobj.readyState == 4) {
			var results = ajobj.responseXML;
			//alert(typeof(results));
			if ( (typeof(results)=='string' || typeof(results)=='object' ) && results != null && results != '') {
				/* Function callback evaluator */
				if (eval("typeof(" + http_destobj + ") == 'function'")) { 
					/* Function detected, pass data to function */
					eval(http_destobj + "(results);");
				} else {
					/* Not a function, pass data to the html object */
					if (typeof document.getElementById(http_destobj).innerHTML != "undefined") {
						document.getElementById(http_destobj).innerHTML = results;
					}
				}
			}
			free = true;
		}
	}
	
	/* Helpers functions */
	function Is_Free() {
		return free;	
	}
	
	function Set_Loading(value) {
		show_loading = value;
	}
	
	/* AJAX OBJECT */
	function XMLHTTP_object() {
	  var xmlhttp;
	  /*@cc_on
	  @if (@_jscript_version >= 5)
		try {
		  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		  try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		  } catch (E) {
			xmlhttp = false;
		  }
		}
	  @else
	  xmlhttp = false;
	  @end @*/
	  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
		  xmlhttp = new XMLHttpRequest();
		} catch (e) {
		  xmlhttp = false;
		}
	  }
	  return xmlhttp;
	}
}

function ajStopXML(destination) {
	arStopsXML[destination] = true;
}