
//var ajax = new sack();

function whenLoading(){
	var e = document.getElementById('datos'); 
	e.innerHTML = "<p>Enviando petición...</p>";
}

function whenLoaded(){
	var e = document.getElementById('datos'); 
	e.innerHTML = "<p>Petición realizada...</p>";
}

function whenInteractive(){
	var e = document.getElementById('datos'); 
	e.innerHTML = "<p>Obteniendo datos...</p>";
}

function whenCompleted(){
	var e = document.getElementById('inter'); 
	e.innerHTML ="<p></p>";
}
comunidades_admin=new Array();
comunidades_admin[1]=19;comunidades_admin[2]=7;comunidades_admin[3]=11;comunidades_admin[4]=1;comunidades_admin[5]=8;comunidades_admin[6]=12;comunidades_admin[7]=4;comunidades_admin[8]=9;comunidades_admin[9]=8;comunidades_admin[10]=12;comunidades_admin[11]=1;comunidades_admin[12]=11;comunidades_admin[13]=7;comunidades_admin[14]=1;comunidades_admin[15]=13;comunidades_admin[16]=7;comunidades_admin[17]=9;comunidades_admin[18]=1;comunidades_admin[19]=7;comunidades_admin[20]=19;comunidades_admin[21]=1;comunidades_admin[22]=2;comunidades_admin[23]=1;comunidades_admin[24]=8;comunidades_admin[25]=9;comunidades_admin[26]=14;comunidades_admin[27]=13;comunidades_admin[28]=15;comunidades_admin[29]=1;comunidades_admin[30]=17;comunidades_admin[31]=18;comunidades_admin[32]=13;comunidades_admin[33]=3;comunidades_admin[34]=8;comunidades_admin[35]=5;comunidades_admin[36]=13;comunidades_admin[37]=8;comunidades_admin[38]=5;comunidades_admin[39]=6;comunidades_admin[40]=8;comunidades_admin[41]=1;comunidades_admin[42]=8;comunidades_admin[43]=9;comunidades_admin[44]=2;comunidades_admin[45]=7;comunidades_admin[46]=11;comunidades_admin[47]=8;comunidades_admin[48]=19;comunidades_admin[49]=8;comunidades_admin[50]=2;comunidades_admin[51]=10;comunidades_admin[52]=16;
function getcomunidad() {
	var prov=document.forms[0].provincia.value;
	if (prov=='') {
		document.forms[0].comunidad.value='';
	}else {
		document.forms[0].comunidad.value=comunidades_admin[prov];
	}
}

function envia_pos() {
	if (document.forms[0].posicion.selectedIndex!=0) {
		var ajax = new sack();
		ajax.requestFile = "/admin/posicion.php";
		ajax.method = 'post';
		ajax.element = 'datos';
		ajax.setVar("pos",document.forms[0].posicion.value);
		ajax.setVar("tab",document.forms[0].tab.value);
		ajax.onLoading = whenLoading;
		ajax.onLoaded = whenLoaded; 
		ajax.onInteractive = whenInteractive;
		ajax.onCompletion = whenCompleted;
		ajax.runAJAX();
	}else {
		alert('Por favor, elige la posición');
	}
}
function envia_pos_com() {
	if (document.forms[0].comunidad.selectedIndex!=0) {
		if (document.forms[0].posicion.selectedIndex!=0) {
			var ajax = new sack();
			ajax.requestFile = "/admin/posicion.php";
			ajax.method = 'post';
			ajax.element = 'datos';
			ajax.setVar("pos",document.forms[0].posicion.value);
			ajax.setVar("tab",document.forms[0].tab.value);
			ajax.setVar("com",document.forms[0].comunidad.value);
			ajax.onLoading = whenLoading;
			ajax.onLoaded = whenLoaded; 
			ajax.onInteractive = whenInteractive;
			ajax.onCompletion = whenCompleted;
			ajax.runAJAX();
		}else {
			alert("Elige la posición por favor");
		}
	}else {
		alert("Elige la comunidad por favor");
	}
}
function envia_com() {
	if (document.forms[0].comunidad.selectedIndex!=0) {
		var ajax = new sack();
		ajax.requestFile = "/admin/posicion.php";
		ajax.method = 'post';
		ajax.element = 'datos';
		ajax.setVar("tab",document.forms[0].tab.value);
		ajax.setVar("com",document.forms[0].comunidad.value);
		ajax.onLoading = whenLoading;
		ajax.onLoaded = whenLoaded; 
		ajax.onInteractive = whenInteractive;
		ajax.onCompletion = whenCompleted;
		ajax.runAJAX();
	}else {
		alert("Elige la comunidad por favor");
	}
}
function comprobar_calendario() {
	var check =document.getElementsByName('dias_m[]');
	selected = false
	x=0;
   	while (!selected && (x <check.length)) {
 		if ((check[x].checked) && (check[x].disabled==false)) {   
     		selected = true;  
   		}
   		x++;
   	}
   	return selected;
}
function envia_especial(tipo) {
	//Se le pasa tipo: 0 => home nacional , 1 => home comunidad
	var mensaje="Por favor, rellene los siguientes campos:\n";
	var com=true;
	if (tipo==1) {
		if (document.forms[0].comunidad.selectedIndex==0) {
			mensaje+="Comunidad\n";
			com=false;
		}
	}
	if (document.forms[0].titulo.value=='') {
		mensaje+="Título\n";
		com=false;
	}
	if (document.forms[0].texto.value=='') {
		mensaje+="Texto\n";
		com=false;
	}
	if (document.forms[0].imagen.value=='') {
		mensaje+="Imagen\n";
		com=false;
	}
	if (document.forms[0].tarifa.value=='') {
		mensaje+="Tarifa\n";
		com=false;
	}
	if (document.forms[0].enlace.value=='') {
		mensaje+="Enlace\n";
		com=false;
	}
	if (!comprobar_calendario()) {
		mensaje+="Algun día en el calendario\n";
		com=false;
	}
	if (com==false) {
		alert(mensaje);
		return false;
	}else {
		return true;
	}
}
function envia_recomendados(tipo) {
	//Se le pasa tipo: 0 => home nacional , 1 => home comunidad
	var mensaje="Por favor, rellene los siguientes campos:\n";
	var com=true;
	if (tipo==1) {
		if (document.forms[0].comunidad.selectedIndex==0) {
			mensaje+="Comunidad\n";
			com=false;
		}
	}
	if (document.forms[0].nombre.value=='') {
		mensaje+="Nombre\n";
		com=false;
	}
	if (document.forms[0].localidad.value=='') {
		mensaje+="Localidad\n";
		com=false;
	}
	if (document.forms[0].tipo.value=='') {
		mensaje+="Tipo\n";
		com=false;
	}
	if (document.forms[0].enlace.value=='') {
		mensaje+="Enlace\n";
		com=false;
	}
	if (document.forms[0].posicion.value=='') {
		mensaje+="Posición\n";
		com=false;
	}
	if (!comprobar_calendario()) {
		mensaje+="Algun día en el calendario\n";
		com=false;
	}
	if (com==false) {
		alert(mensaje);
		return false;
	}else {
		return true;
	}
}
function envia_proponemos(tipo) {
	//Se le pasa tipo: 0 => home nacional , 1 => home comunidad
	var mensaje="Por favor, rellene los siguientes campos:\n";
	var com=true;
	if (tipo==1) {
		if (document.forms[0].comunidad.selectedIndex==0) {
			mensaje+="Comunidad\n";
			com=false;
		}
	}
	if (document.forms[0].titulo.value=='') {
		mensaje+="Título\n";
		com=false;
	}
	if (document.forms[0].encabezamiento.value=='') {
		mensaje+="Encabezamiento\n";
		com=false;
	}
	if (document.forms[0].texto.value=='') {
		mensaje+="Texto\n";
		com=false;
	}
	if (document.forms[0].imagen.value=='') {
		mensaje+="Imagen\n";
		com=false;
	}
	if (document.forms[0].tarifa.value=='') {
		mensaje+="Tarifa\n";
		com=false;
	}
	if (document.forms[0].enlace.value=='') {
		mensaje+="Enlace\n";
		com=false;
	}
	if (document.forms[0].posicion.value=='') {
		mensaje+="Posición\n";
		com=false;
	}
	if (!comprobar_calendario()) {
		mensaje+="Algun día en el calendario\n";
		com=false;
	}
	if (com==false) {
		alert(mensaje);
		return false;
	}else {
		return true;
	}
}
