//variables Globales
var AjaxCallsDir = 'AjaxCalls/';

//url => url where to post the ajaxcall.
//response => name of the function which proccess the response sent by the server.
//content => An array of the names of the form variables that need to be sent to the server.
function sendAjax(url,response,contentName, contentValue) {
	var ajaxRequest = null;
	var ajaxCallback = response;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		ajaxRequest = new XMLHttpRequest();
		if (ajaxRequest.overrideMimeType) {
// 			ajaxRequest.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	// we use a javascript feature here called "inner functions"
	// using these means the local variables retain their values after the outer function
	// has returned. this is useful for thread safety, so
	// reassigning the onreadystatechange function doesn't stomp over earlier requests.

	function callback(response){
		if (ajaxRequest.readyState == 4) {
			// everything is good, the response is received
			if (ajaxRequest.status == 200) {
//				alert('El request devolvio: ' + ajaxRequest.responseText);
				ajaxCallback(ajaxRequest.responseXML);
			} else {
				// there was a problem with the request,
				// for example the response may be a 404 (Not Found)
				// or 500 (Internal Server Error) response codes
				alert('El request fallo, su status es: ' + ajaxRequest.status);
			}
		}
	}

	if (!ajaxRequest) {
		return false;
	}
	ajaxRequest.onreadystatechange = callback;
	var contentString = '';
	if (contentName){
		for (i = 0; i < contentName.length; i++ ){
			contentString += contentName[i] + '=' + contentValue[i] + '&';
		}
	}
	ajaxRequest.open('Post', url, true);
	ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

	ajaxRequest.send(contentString);
	return true;
}


function sendAjaxHtml(url,response,contentName, contentValue) {
	var ajaxRequest = null;
	var ajaxCallback = response;

	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		ajaxRequest = new XMLHttpRequest();
		if (ajaxRequest.overrideMimeType) {
// 			ajaxRequest.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	// we use a javascript feature here called "inner functions"
	// using these means the local variables retain their values after the outer function
	// has returned. this is useful for thread safety, so
	// reassigning the onreadystatechange function doesn't stomp over earlier requests.

	function callback(response){
		if (ajaxRequest.readyState == 4) {
			// everything is good, the response is received
			if (ajaxRequest.status == 200) {
//				alert('El request devolvio: ' + ajaxRequest.responseText);
				ajaxCallback(ajaxRequest.responseText);
			} else {
				// there was a problem with the request,
				// for example the response may be a 404 (Not Found)
				// or 500 (Internal Server Error) response codes
				alert('El request fallo, su status es: ' + ajaxRequest.status);
			}
		}
	}

	if (!ajaxRequest) {
		return false;
	}
	ajaxRequest.onreadystatechange = callback;
	var contentString = '';
	if (contentName){
		for (i = 0; i < contentName.length; i++ ){
			contentString += contentName[i] + '=' + contentValue[i] + '&';
		}
	}
	ajaxRequest.open('Post', url, true);
	ajaxRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

	ajaxRequest.send(contentString);
	return true;
}


