
//Abrimos el documento
function showDetail(idTab, url, target){
	//Lanzamos el ajax con los valores del formulario
	var call = new Cendojax();
	call.onLoading = function() {
		target.innerHTML = "<div style=\"height:400px; text-align:center\"><img src=\"img/loader.gif\" border=\"0\" alt=\"Cargando...\" style=\"margin-left:auto; margin-right:auto;\"/></div>";
		changeView(idTab, "pD" + idTab, target.id);
	}
	call.onComplete = function() {
		target.innerHTML = call.responseText;
		loadedDetail(idTab);
	}
	call.run(url);
}

//Lanzamos la busqueda
function showResults(idTab, url, target){
	//Lanzamos el ajax con los valores del formulario
	var call = new Cendojax();
	call.onLoading = function() {
		target.innerHTML = "<div style=\"height:400px; text-align:center\"><img src=\"img/loader.gif\" border=\"0\" alt=\"Cargando...\"/></div>";
		changeView(idTab, "pR" + idTab, target.id);
	}
	call.onComplete = function() {
		target.innerHTML = call.responseText;
		loadedResults(idTab);
	}
	call.run(url);
}

function getComunidades(field, comunidad, provincia, fieldValue, target){
	var call = new Cendojax();
	
	call.onLoading = function() {
//		target.innerHTML = "<center><img src=\"img/loader.gif\" border=\"0\" alt=\"Cargando...\"></center>";
	}

	call.onComplete = function() {
		if (target && target.options){
			target.options.length = 0;
			var values = call.responseText.split("|");
			if (call.responseText.length > 0){
				for (var i=0; i<values.length; i++){
					if (values[i].indexOf("&") != -1){
						var key = values[i].split("&")[0];
						var value = values[i].split("&")[1];
						target.options[i] = new Option(value, key);
					}
				}
			}
			//Si no se ha añadido ninguna opcion, le añadimos la de por defecto "TODAS"
			if (target.options.length == 0){
				target.options[0] = new Option("TODAS", "");
			}
			target.value = fieldValue;
			if (target.onchange)
				target.onchange();
		}
	}
	
	var url = "doAction?action=comunidades&field=" + field;
	if (comunidad.length > 0) url += "&comunidad=" + escape(comunidad);
	if (provincia.length > 0) url += "&provincia=" + escape(provincia);

	call.run(url);	
}

function toggle(_id){
	var obj = getObject(_id);
	if (obj){
		if (obj.style.display == "none")
			new Effect.SlideDown(obj, {duration: 1});
		else
			new Effect.SlideUp(obj, {duration: 1});
	}			
}
