// JavaScript Document
function FW_Ajax(FW_Ajax_URL, FW_Ajax_id, FW_Ajax_fun) {
	
	//llamada al servidor solicitándo la página
	var FW_Ajax_call = function (FW_Ajax_URL) {
	
		if (FW_Ajax_id != '') {
			//dejo un mensaje de cargando
			document.getElementById(FW_Ajax_id).innerHTML= "Cargando...";
		}
		
		pars = '';
		var myAjax = new Ajax.Request(
			FW_Ajax_URL, 
			{ 
				method: 'get',
				evalScripts: true,
				parameters: pars,
				encoding: 'UTF-8',
				contentType: 'text/html',
				onComplete: FW_Ajax_responder
			}
		);
		
	}
	
	//respuesta del servidor
	function FW_Ajax_responder(originalRequest)
	{
		
		//devuelvo la petición al que la ha solicitado
		if (typeof(FW_Ajax_fun) != 'undefined' && FW_Ajax_fun != '') {
			
			//ejecuto la función
			var FW_Ajax_execute_fun = new FW_Ajax_fun(originalRequest);
			
		} else { 
		
			//document.getElementById(FW_Ajax_id).innerHTML = originalRequest.responseText;

			var scs=originalRequest.responseText.extractScript();    //capturamos los scripts 
			document.getElementById(FW_Ajax_id).innerHTML =originalRequest.responseText.stripScript();    //eliminamos los scripts... ya son innecesarios 
			scs.evalScript();  
			
			//equivalente a document.getElementById
			//$(FW_Ajax_id).innerHTML = originalRequest.responseText;		
		}
		
	} 
	
	//compruebo si ha pasado una función a la que enviar los datos
	var FW_Ajax_call_execute = new FW_Ajax_call("?ajax=" + FW_Ajax_URL);
	
}
	
	
	

