/* All ajax methods used by Fanbible stored here */

/* Set variables and variable adjustment functions */

/* Query is provided by the user */
var query, resultDiv, loaderElement;
function assQuery(arg){
	query = arg;
}

/* Where the output of the ajax request will be placed */
function assResultDiv(arg){
	resultDiv = document.getElementById(arg);
}

/* What will be shown while result is being received */
function assLoaderElement(arg){
	if(arg !== 0){
		loaderElement = document.getElementById(arg);
	}
	else {
		loaderElement = 0;
	}
}

/* AJAX */
/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */


function createObject() {
	var request_type;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
		request_type = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		request_type = new XMLHttpRequest();
	}
	return request_type;
}
var http = createObject();

/* Prepare nocache variable for random number assignment */
var nocache = 0;


/* Ajax requests */

function ajax() {
	/* Assign a random number to nocache variable */
	nocache = Math.random();
	
	/* Show a waiting message in the layer */
	if(loaderElement !== 0) { loaderElement.style.display="block"; }
	
	/* Pass the login variables like a URL variable */
	http.open('get', query+"&nocache="+nocache);
	http.onreadystatechange = returnValue;
	http.send(null);
	
}
	
/* Return value */

function returnValue() {
	
	if(http.readyState == 4){
		
		/* Set useful variables */
		if(http.responseText){
		// else if login is ok show a message: "Site added+site URL"
		if(loaderElement !== 0) { loaderElement.style.display="none"; }
		
		resultDiv.innerHTML = http.responseText;
		}
		
		/* Save to history */
		document.getElementById("history").innerHTML += http.responseText;
	}
}
