$(document).ready(function (){
	$("#formNoticiasSubmit").click(submitFormNoticias);  
	
    
}
);

/* METODOS PARA AÑADIR/BORRAR DELEGACIONES */
function addDelegation()
{
	var field_area = document.getElementById('seccion1');	
	
	//Contamos cuantos elementos tenemos de cada tipo
	var n_rows = $("#num_addresses").val();
	
	//var n_rows_plus = (n_rows * 1)+ 1 ;	
	var n_rows_plus = n_rows*1;
	
	/*if(n_rows==0){
		$("#removebutton").css({display:"inline"});
		//$("#boton_0").css({display:"inline"});
	}*/
	
	//Incrementamos el numero de ternas de tres
	$("#num_addresses").val(n_rows_plus+1);
	
	//Para los 8 campos
	
	var input_id = document.createElement("input");		
	input_id.setAttribute('id', 'otrosid_' + n_rows_plus); 				
	input_id.setAttribute('name', 'otrosid_' + n_rows_plus); 				
	input_id.setAttribute('type', 'hidden');
	input_id.setAttribute('value', '');
	field_area.appendChild(input_id);
		
	var tr1 = document.createElement("tr");		
	tr1.setAttribute('id', 'row1_' + n_rows_plus); 				
						
	field_area.appendChild(tr1);	
		
	/* Denominacion */
	var td1 = document.createElement("td");		
	td1.setAttribute('id', 'td1_' + n_rows_plus);
	td1.setAttribute('class', 'izq');
	tr1.appendChild(td1);
		
	var text1 = document.createElement("label");	
	text1.setAttribute('id', 'otros_denominacionlabel_' + n_rows_plus);	
	text1.setAttribute('for', 'otros_denominacion_' + n_rows_plus);	
	td1.appendChild(text1);
	$('#otros_denominacionlabel_' + n_rows_plus).text('Denominación:');
		
	var td2 = document.createElement("td");		
	td2.setAttribute('id', 'td2_' + n_rows_plus);
	td2.setAttribute('colspan','3');
	td2.colSpan=3;
	tr1.appendChild(td2);
		
	var input1 = document.createElement("input");		
	input1.setAttribute('id', 'otros_denominacion_' + n_rows_plus); 				
	input1.setAttribute('name', 'otros_denominacion_' + n_rows_plus); 				
	input1.setAttribute('type', 'text');
	input1.setAttribute('value', ' ');
	input1.setAttribute('class', 'inputlong');
	input1.setAttribute((document.all ? 'className' : 'class'), "inputlong");
	td2.appendChild(input1);
	
	var td3 = document.createElement("td");		
	td3.setAttribute('id', 'td3_'+n_rows_plus); 				
	tr1.appendChild(td3);
		
	var text=document.createTextNode("\u00a0");	
	td3.appendChild(text);

	/* Calle */
/***	
	var td3 = document.createElement("td");		
	td3.setAttribute('id', 'td3_'+n_rows_plus); 				
	tr1.appendChild(td3);
		
	var text2 = document.createElement("label");	
	text2.setAttribute('id', 'otros_callelabel_'+n_rows_plus);	
	text2.setAttribute('for', 'otros_calle_'+n_rows_plus);	
	td3.appendChild(text2);
	$('#otros_callelabel_'+n_rows_plus).text('Calle:');
		
	var td4 = document.createElement("td");		
	td4.setAttribute('id', 'td4_'+n_rows_plus); 				
	tr1.appendChild(td4);
		
	var input2 = document.createElement("input");		
	input2.setAttribute('id', 'otros_calle_'+n_rows_plus); 				
	input2.setAttribute('name', 'otros_calle_'+n_rows_plus); 				
	input2.setAttribute('type', 'text'); 				
	td4.appendChild(input2);
		
	var td15 = document.createElement("td");		
	td15.setAttribute('id', 'td15_'+n_rows_plus); 				
	td15.setAttribute('colspan', '4'); 				
	tr1.appendChild(td15);
***/
	
	var tr2 = document.createElement("tr");		
	tr2.setAttribute('id', 'row2_' + n_rows_plus); 				
	field_area.appendChild(tr2);

	var td4 = document.createElement("td");		
	td4.setAttribute('id', 'td4_' + n_rows_plus); 				
	td4.setAttribute('class', 'izq'); 				
	tr2.appendChild(td4);
		
	var text2 = document.createElement("label");	
	text2.setAttribute('id', 'otros_callelabel_' + n_rows_plus);	
	text2.setAttribute('for', 'otros_calle_' + n_rows_plus);	
	td4.appendChild(text2);
	$('#otros_callelabel_'+n_rows_plus).text('Calle:');
		
	var td5 = document.createElement("td");		
	td5.setAttribute('id', 'td5_'+n_rows_plus); 				
	tr2.appendChild(td5);
		
	var input2 = document.createElement("input");		
	input2.setAttribute('id', 'otros_calle_'+n_rows_plus); 				
	input2.setAttribute('name', 'otros_calle_'+n_rows_plus); 				
	input2.setAttribute('type', 'text'); 				
	td5.appendChild(input2);
		
	var td6 = document.createElement("td");		
	td6.setAttribute('id', 'td6_'+n_rows_plus); 				
	tr2.appendChild(td6);
	
	/* Codigo postal */
	var text3=document.createElement("label");	
	text3.setAttribute('id', 'otros_postallabel_'+n_rows_plus);	
	text3.setAttribute('for', 'otros_postal_'+n_rows_plus);	
	td6.appendChild(text3);
	$('#otros_postallabel_'+n_rows_plus).text('Código postal:');
	
	var td7 = document.createElement("td");		
	td7.setAttribute('id', 'td7_'+n_rows_plus); 				
	tr2.appendChild(td7);
	
	var input3=document.createElement("input");		
	input3.setAttribute('id', 'otros_postal_'+n_rows_plus); 				
	input3.setAttribute('name', 'otros_postal_'+n_rows_plus); 				
	input3.setAttribute('maxlength', '5'); 				
	input3.setAttribute('type', 'text'); 				
	td7.appendChild(input3);

	var td8 = document.createElement("td");		
	td8.setAttribute('id', 'td8_'+n_rows_plus); 				
	tr2.appendChild(td8);
		
	var text=document.createTextNode("\u00a0");	
	td8.appendChild(text);
	
	var tr3 = document.createElement("tr");		
	tr3.setAttribute('id', 'row3_'+n_rows_plus); 				
	field_area.appendChild(tr3);
	
	
	var td9 = document.createElement("td");		
	td9.setAttribute('id', 'td9_'+n_rows_plus); 				
	td9.setAttribute('class', 'izq'); 				
	tr3.appendChild(td9);
		
			
	/* Telefono */
	var text4=document.createElement("label");	
	text4.setAttribute('id', 'otros_tellabel_'+n_rows_plus);	
	text4.setAttribute('for', 'otros_tel_'+n_rows_plus);	
	td9.appendChild(text4);
	$('#otros_tellabel_'+n_rows_plus).text('Teléfono:');
	
	var td10 = document.createElement("td");		
	td10.setAttribute('id', 'td10_'+n_rows_plus); 				
	tr3.appendChild(td10);
		
	var input4=document.createElement("input");		
	input4.setAttribute('id', 'otros_tel_'+n_rows_plus); 				
	input4.setAttribute('name', 'otros_tel_'+n_rows_plus); 				
	input4.setAttribute('type', 'text'); 				
	td10.appendChild(input4);
		
	var td11 = document.createElement("td");		
	td11.setAttribute('id', 'td11_'+n_rows_plus); 				
	tr3.appendChild(td11);
	
	/* Email */
	var text5=document.createElement("label");	
	text5.setAttribute('id', 'otros_maillabel_'+n_rows_plus);	
	text5.setAttribute('for', 'otros_mail_'+n_rows_plus);	
	td11.appendChild(text5);
	$('#otros_maillabel_'+n_rows_plus).text('Email:');
		
	var td12 = document.createElement("td");		
	td12.setAttribute('id', 'td12_'+n_rows_plus); 				
	tr3.appendChild(td12);
		
	var input5=document.createElement("input");		
	input5.setAttribute('id', 'otros_mail_'+n_rows_plus); 				
	input5.setAttribute('name', 'otros_mail_'+n_rows_plus); 				
	input5.setAttribute('type', 'text'); 				
	td12.appendChild(input5);
	
	var td13 = document.createElement("td");		
	td13.setAttribute('id', 'td13_'+n_rows_plus); 				
	tr3.appendChild(td13);
		
	var text=document.createTextNode("\u00a0");	
	td13.appendChild(text);
	
/***		
	var tr3 = document.createElement("tr");		
	tr3.setAttribute('id', 'row3_'+n_rows_plus); 				
	field_area.appendChild(tr3);
***/

	var tr4 = document.createElement("tr");		
	tr4.setAttribute('id', 'row4_' + n_rows_plus); 				
	field_area.appendChild(tr4);
		
	/* Web */
	var td14 = document.createElement("td");		
	td14.setAttribute('id', 'td14_'+n_rows_plus); 				
	td14.setAttribute('class', 'izq'); 				
	tr4.appendChild(td14);
		
	var text6=document.createElement("label");	
	text6.setAttribute('id', 'otros_weblabel_'+n_rows_plus);	
	text6.setAttribute('for', 'otros_web_'+n_rows_plus);	
	td14.appendChild(text6);
	$('#otros_weblabel_'+n_rows_plus).text('Web:');
		
	var td15 = document.createElement("td");		
	td15.setAttribute('id', 'td15_'+n_rows_plus); 				
	td15.setAttribute('colspan','3');
	td15.colSpan=3;
	tr4.appendChild(td15);
		
	var input6=document.createElement("input");		
	input6.setAttribute('id', 'otros_web_'+n_rows_plus); 				
	input6.setAttribute('name', 'otros_web_'+n_rows_plus); 				
	input6.setAttribute('type', 'text');
	input6.setAttribute('class','inputlong');
	input6.setAttribute('class', 'inputlong');
	input6.setAttribute((document.all ? 'className' : 'class'), "inputlong");
	
	//	input6.setAttribute('width','100%');
	
	td15.appendChild(input6);
	
	
	//var td16 = document.createElement("td");		
	//td16.setAttribute('id', 'td16_'+n_rows_plus); 				
	//td16.setAttribute('colspan', '2'); 				
	//tr4.appendChild(td16);
	
	//var text=document.createTextNode("\u00a0");	
	//td16.appendChild(text);
	
	//var td19 = document.createElement("td");		
	//td19.setAttribute('id', 'td19_'+n_rows_plus); 				
	//td16.setAttribute('colspan', '2'); 				
	//tr4.appendChild(td19);
	
	//var text=document.createTextNode("\u00a0");	
	//td19.appendChild(text);

	var td17 = document.createElement("td");		
	td17.setAttribute('id', 'td17_'+n_rows_plus); 				
	td17.setAttribute('align', 'right'); 				
	tr4.appendChild(td17);
	
	var input7=document.createElement("input");		
	input7.setAttribute('id', 'boton_'+n_rows_plus); 				
	input7.setAttribute('name', 'boton_'+n_rows_plus); 				
	input7.setAttribute('type', 'button'); 				
	input7.setAttribute('title', 'Borrar'); 				
	input7.setAttribute('label', 'Borrar'); 				
	input7.setAttribute('value', 'Borrar'); 				
	
	//input7.setAttribute('onclick', 'removeRow('+n_rows_plus+')'); 				
	input7.onclick = function() { removeRow(n_rows_plus) };

	td17.appendChild(input7);
						
	var tr5 = document.createElement("tr");		
	tr5.setAttribute('id', 'row5_'+n_rows_plus); 				
	field_area.appendChild(tr5);
		
	var td18 = document.createElement("td");		
	td18.setAttribute('id', 'td18_'+n_rows_plus); 				
	//td18.setAttribute('colspan', '5'); 				
	td18.colSpan=5;
	tr5.appendChild(td18);
		
	var text7=document.createTextNode("\u00a0");	
	td18.appendChild(text7);
	
		if (n_rows_plus>=1){
			//$("#removebutton").css({display:"none"});
			$("#boton_0").css({display:"block"});
		}
		
		
		
}

function removeRow(pos){
	
	
	var n_rows = $("#num_addresses").val();
	var n_rows_minus = (n_rows * 1)-1 ;

	if (pos==0){
		
			$("#otros_denominacion_0").val("");
			$("#otros_calle_0").val("");
			$("#otros_postal_0").val("");
			$("#otros_tel_0").val("");
			$("#otros_mail_0").val("");
			$("#otros_web_0").val("");
			$("#otrosid_0").val("");
			
			if (document.getElementById('num_addresses').value<=1){
		
				return false;
			}
	}

	if (pos==n_rows_minus)
		removeDelegation();
	else{
		
		for (var i=pos; i<n_rows_minus; i++){
			//var aux=i+1;
			
			
			$("#otros_denominacion_"+i).val($("#otros_denominacion_"+(i+1)).val().length>0?$("#otros_denominacion_"+(i+1)).val():"");
			$("#otros_calle_"+i).val($("#otros_calle_"+(i+1)).val().length>0?$("#otros_calle_"+(i+1)).val():"");
			$("#otros_postal_"+i).val($("#otros_postal_"+(i+1)).val().length>0?$("#otros_postal_"+(i+1)).val():"");
			$("#otros_tel_"+i).val($("#otros_tel_"+(i+1)).val().length>0?$("#otros_tel_"+(i+1)).val():"");
			$("#otros_mail_"+i).val($("#otros_mail_"+(i+1)).val().length>0?$("#otros_mail_"+(i+1)).val():"");
			$("#otros_web_"+i).val($("#otros_web_"+(i+1)).val().length>0?$("#otros_web_"+(i+1)).val():"");
			$("#otrosid_"+i).val($("#otrosid_"+(i+1)).val().length>0?$("#otrosid_"+(i+1)).val():"");
		}
		
		
		var campo_address = document.getElementById('row1_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
		var campo_address = document.getElementById('row2_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
		var campo_address = document.getElementById('row3_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
		var campo_address = document.getElementById('row4_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
		var campo_address = document.getElementById('row5_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
		
		
		/*if (n_rows_minus<=1){
			//$("#removebutton").css({display:"none"});
			$("#boton_0").css({display:"none"});
		}*/
		
		$("#num_addresses").val(n_rows_minus);
	}
		
	
	return false;
}

function removeDelegation()
{	
	//Contamos cuantos elementos tenemos de cada tipo
	var n_rows = $("#num_addresses").val();
	var n_rows_minus = (n_rows * 1) - 1 ;
	//alert("VALE="+n_rows_minus);

	var campo_address = document.getElementById('row1_' + n_rows_minus);
		
	campo_address.parentNode.removeChild(campo_address);
		
	var campo_address = document.getElementById('row2_'+n_rows_minus);
			
	campo_address.parentNode.removeChild(campo_address);
			
	var campo_address = document.getElementById('row3_'+n_rows_minus);
			
	campo_address.parentNode.removeChild(campo_address);
	
	var campo_address = document.getElementById('row4_'+n_rows_minus);
			
	campo_address.parentNode.removeChild(campo_address);
		
	var campo_address = document.getElementById('row5_'+n_rows_minus);
		
	campo_address.parentNode.removeChild(campo_address);
		
		/*if (n_rows_minus<=1){
			//$("#removebutton").css({display:"none"});
			$("#boton_0").css({display:"none"});
		}*/
		
	$("#num_addresses").val(n_rows_minus);
}

/******** FIN DE METODOS PARA AÑADIR/BORRAR DELEGACIONES ********************/

/******** METODOS PARA AÑADIR/BORRAR REDES SOCIALES ********************/
function addNetwork() {

	var field_area = document.getElementById('seccion2');
	
	
	//Contamos cuantos elementos tenemos de cada tipo
	var n_rows = $("#num_networks").val();
		
	var n_rows_plus = n_rows*1;
		
	//Incrementamos el nÃºmero de ternas de tres
	$("#num_networks").val(n_rows_plus+1);
	
		var tr1 = document.createElement("tr");		
		tr1.setAttribute('id', 'tr1_net_'+n_rows_plus); 				
						
		field_area.appendChild(tr1);	
		
		

		/* Nombre */
		var td3 = document.createElement("td");		
		td3.setAttribute('id', 'td3_net_'+n_rows_plus); 				
		td3.setAttribute('class', 'izq'); 				
		tr1.appendChild(td3);
		
		var text2=document.createElement("label");	
		text2.setAttribute('id', 'redlabel_'+n_rows_plus);	
		text2.setAttribute('for', 'red_'+n_rows_plus);	
		td3.appendChild(text2);
		$('#redlabel_'+n_rows_plus).text('Nombre red social:');
		
		var td4 = document.createElement("td");		
		td4.setAttribute('id', 'td4_net_'+n_rows_plus); 				
		tr1.appendChild(td4);
		
		
		var input2=document.createElement("select");		
		input2.setAttribute('id', 'red_'+n_rows_plus); 				
		input2.setAttribute('name', 'red_'+n_rows_plus); 				
		//input2.setAttribute('type', 'text'); 				
		td4.appendChild(input2);
		/***************************************************************/
		$.ajax({
		        url: "getNetworks.php",
		        type: "POST",
		        dataType: "xml",		        
		        data: {},
		        error: function(req, err, obj) {
		            alert('Error: ' + req.status + err);
		        },
		        success: function(xml) {
		        	
		        	
		        	
		            var res = $("res",xml).text();
		            var text = $("text",xml).text();		            
		            var num_redes = $("num_redes",xml).text();		            
		            if (res == "OK") {
			        	
		            	$("#red_"+n_rows_plus).text('');
		            	
		            	$("#red_"+n_rows_plus).append('<option value="" checked >Seleccione:</option>');
		            	
		            	//var id = '';
						//var name = '';
						//var colegio = '';
						//var position = 1;
		            	
			        	$("redes", xml).each(function() {
							
							var id = $("id",this).text();
							var name = $("name",this).text(); 
							
							

							$("#red_"+n_rows_plus).append('<option value="'+id+'">'+name+'</option>');
							
							
							
			        	})
			        	
			        	$("#red_"+n_rows_plus)[0].checked=true;	
		            } else 
		            	alert (text);
		        }
		    });
		/***************************************************************/
		
		
		
		/* URL */
		var td1 = document.createElement("td");		
		td1.setAttribute('id', 'td1_net_'+n_rows_plus); 				
		tr1.appendChild(td1);
		
		var text1=document.createElement("label");	
		text1.setAttribute('id', 'urllabel_'+n_rows_plus);	
		text1.setAttribute('for', 'url_'+n_rows_plus);	
		td1.appendChild(text1);
		$('#urllabel_'+n_rows_plus).text('URL:');
		
		var td2 = document.createElement("td");		
		td2.setAttribute('id', 'td2_net_'+n_rows_plus); 				
		tr1.appendChild(td2);
		
		var input1=document.createElement("input");		
		input1.setAttribute('id', 'url_'+n_rows_plus); 				
		input1.setAttribute('name', 'url_'+n_rows_plus); 				
		input1.setAttribute('type', 'text'); 				
		td2.appendChild(input1);
		
		var td5 = document.createElement("td");		
		td5.setAttribute('id', 'td5_net_'+n_rows_plus); 				
		td5.setAttribute('align', 'right'); 				
		//td5.setAttribute('colspan', '3'); 				
		td5.colSpan=3;
		tr1.appendChild(td5);
		
		var input3=document.createElement("input");		
		input3.setAttribute('id', 'botonnet_'+n_rows_plus); 				
		input3.setAttribute('name', 'botonnet_'+n_rows_plus); 				
		input3.setAttribute('type', 'button'); 				
		input3.setAttribute('title', 'Borrar'); 				
		input3.setAttribute('label', 'Borrar'); 				
		input3.setAttribute('value', 'Borrar'); 				
		
		//input3.setAttribute('onclick', 'removeRowNet('+n_rows_plus+')'); 				
		input3.onclick = function() { removeRowNet(n_rows_plus) };
		td5.appendChild(input3);
		
		
		var tr3 = document.createElement("tr");		
		tr3.setAttribute('id', 'tr3_net_'+n_rows_plus);
		field_area.appendChild(tr3);
		
		var td6 = document.createElement("td");		
		td6.setAttribute('id', 'td6_net_'+n_rows_plus); 				
		//td6.setAttribute('colspan', '5'); 				
		td6.colSpan=5;
		tr3.appendChild(td6);
		
		var text3=document.createTextNode("\u00a0");	
		td6.appendChild(text3);
				
		if (n_rows_plus>=1){
			//$("#removebutton").css({display:"none"});
			$("#botonnet_0").css({display:"block"});
		}
		
			
		
		
}

function removeRowNet(pos){
	
	
	var n_rows = $("#num_networks").val();
	var n_rows_minus = (n_rows * 1)-1 ;
	
	if (pos==0){
			$("#url_0").val("");
			$("#red_0").val("");
			if (document.getElementById('num_networks').value<=1)
				return false;
			
	}
		
	if (pos==n_rows_minus)
		removeNetwork();
	else{
		
		for (var i=pos; i<n_rows_minus; i++){
			//var aux=i+1;
			
			$("#url_"+i).val($("#url_"+(i+1)).val().length>0?$("#url_"+(i+1)).val():"");
			$("#red_"+i).val($("#red_"+(i+1)).val().length>0?$("#red_"+(i+1)).val():"");
			
		}
		
		
		var campo_address = document.getElementById('tr1_net_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
		var campo_address = document.getElementById('tr3_net_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
				
				
		/*if (n_rows_minus<=1){
			//$("#removebutton").css({display:"none"});
			$("#botonnet_").css({display:"none"});
		}*/
		
		$("#num_networks").val(n_rows_minus);
	}
		
	
	return false;
}

function removeNetwork(){
	
	//Contamos cuantos elementos tenemos de cada tipo
	var n_rows = $("#num_networks").val();
	var n_rows_minus = (n_rows * 1)-1 ;
	//alert("VALE="+n_rows_minus);
	
	    
		var campo_address = document.getElementById('tr1_net_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
		var campo_address = document.getElementById('tr3_net_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
			
		/*if (n_rows_minus<=1){
			//$("#removebutton").css({display:"none"});
			$("#botonnet_").css({display:"none"});
		}*/
		
		$("#num_networks").val(n_rows_minus);
		
		
	
}


/******** FIN DE METODOS PARA AÑADIR/BORRAR REDES SOCIALES ********************/

/******** METODOS PARA AÑADIR/BORRAR CONTACTOS ********************/
function addContact() {

	var field_area = document.getElementById('seccion3');
	
	
	//Contamos cuantos elementos tenemos de cada tipo
	var n_rows = $("#num_contacts").val();
		
	var n_rows_plus = n_rows*1;
		
	//Incrementamos el nÃºmero de ternas de tres
	$("#num_contacts").val(n_rows_plus+1);
	
	
	var input_id=document.createElement("input");		
	input_id.setAttribute('id', 'id_contact_'+n_rows_plus); 				
	input_id.setAttribute('name', 'id_contact_'+n_rows_plus); 				
	input_id.setAttribute('type', 'hidden'); 				
	input_id.setAttribute('value', ''); 				
	field_area.appendChild(input_id);
	
		var tr1 = document.createElement("tr");		
		tr1.setAttribute('id', 'tr1_contact_'+n_rows_plus); 				
		field_area.appendChild(tr1);	
		
		/* nombre */
		var td1 = document.createElement("td");		
		td1.setAttribute('id', 'td1_contact_'+n_rows_plus); 				
		tr1.appendChild(td1);
		
		var text1=document.createElement("label");	
		text1.setAttribute('id', 'nom_contactlabel_'+n_rows_plus);	
		text1.setAttribute('for', 'nom_contact_'+n_rows_plus);	
		text1.setAttribute('class', 'izq');	
		td1.appendChild(text1);
		$('#nom_contactlabel_'+n_rows_plus).text('Nombre:');
		
		var td2 = document.createElement("td");		
		td2.setAttribute('id', 'td2_contact_'+n_rows_plus); 				
		tr1.appendChild(td2);
		
		var input1=document.createElement("input");		
		input1.setAttribute('id', 'nom_contact_'+n_rows_plus); 				
		input1.setAttribute('name', 'nom_contact_'+n_rows_plus); 				
		input1.setAttribute('type', 'text'); 				
		td2.appendChild(input1);

		/* Apellidos */
		var td3 = document.createElement("td");		
		td3.setAttribute('id', 'td3_contact_'+n_rows_plus); 				
		tr1.appendChild(td3);
		
		var text2=document.createElement("label");	
		text2.setAttribute('id', 'ape_contactlabel_'+n_rows_plus);	
		text2.setAttribute('for', 'ape_contact_'+n_rows_plus);	
		text2.setAttribute('class', 'izq');	
		td3.appendChild(text2);
		$('#ape_contactlabel_'+n_rows_plus).text('Apellidos:');
		
		var td4 = document.createElement("td");		
		td4.setAttribute('id', 'td4_contact_'+n_rows_plus); 				
		tr1.appendChild(td4);
		
		var input2=document.createElement("input");		
		input2.setAttribute('id', 'ape_contact_'+n_rows_plus); 				
		input2.setAttribute('name', 'ape_contact_'+n_rows_plus); 				
		input2.setAttribute('type', 'text'); 				
		td4.appendChild(input2);
		
		var td7 = document.createElement("td");		
		td7.setAttribute('id', 'td7_contact_'+n_rows_plus); 				
		//td7.setAttribute('colspan', '1'); 				
		tr1.appendChild(td7);
		
		var input4=document.createElement("input");		
		input4.setAttribute('id', 'botoncontact_'+n_rows_plus); 				
		input4.setAttribute('name', 'botoncontact_'+n_rows_plus); 				
		input4.setAttribute('type', 'button'); 				
		input4.setAttribute('title', 'Borrar'); 				
		input4.setAttribute('label', 'Borrar'); 				
		input4.setAttribute('value', 'Borrar'); 				
		//input4.setAttribute('onclick', 'removeRowContact('+n_rows_plus+')'); 
		input4.onclick = function() { removeRowContact(n_rows_plus) };				
		td7.appendChild(input4);
		
				
			
		/*********************************/
		var tr2 = document.createElement("tr");		
		tr2.setAttribute('id', 'tr2_contact_'+n_rows_plus); 				
						
		field_area.appendChild(tr2);	
		
		/* Posicion */
		var td5 = document.createElement("td");		
		td5.setAttribute('id', 'td5_contact_'+n_rows_plus); 				
		tr2.appendChild(td5);
		
		var text3=document.createElement("label");	
		text3.setAttribute('id', 'pos_contactlabel_'+n_rows_plus);	
		text3.setAttribute('for', 'pos_contact_'+n_rows_plus);	
		text3.setAttribute('class', 'izq');	
		td5.appendChild(text3);
		$('#pos_contactlabel_'+n_rows_plus).text('Cargo:');
		
		var td6 = document.createElement("td");		
		td6.setAttribute('id', 'td6_contact_'+n_rows_plus); 				
		//td6.setAttribute('colspan', '4'); 				
		td6.colSpan=4;
		tr2.appendChild(td6);
		
		var input3=document.createElement("input");		
		input3.setAttribute('id', 'pos_contact_'+n_rows_plus); 				
		input3.setAttribute('name', 'pos_contact_'+n_rows_plus); 				
		input3.setAttribute('type', 'text'); 				
		td6.appendChild(input3);

		
		
		/*********************************/
		
				
		
		var tr4 = document.createElement("tr");		
		tr4.setAttribute('id', 'tr4_contact_'+n_rows_plus); 				
		field_area.appendChild(tr4);
		
		var td8 = document.createElement("td");		
		td8.setAttribute('id', 'td8_contact_'+n_rows_plus); 				
		//td8.setAttribute('colspan', '5'); 				
		td8.colSpan=5;
		tr4.appendChild(td8);
		
		var text4=document.createTextNode("\u00a0");	
		td8.appendChild(text4);
		
		//alert("VALE="+n_rows_plus);
		if (n_rows_plus>=1){
			//$("#removebutton").css({display:"none"});
			$("#botoncontact_0").css({display:"block"});
		}
		
}

function removeRowContact(pos){
	//alert("ENTRO1");
	
	var n_rows = $("#num_contacts").val();
	var n_rows_minus = (n_rows * 1)-1 ;
	//alert("ENTRO2="+n_rows_minus);
	
	
	if (pos==0){
			$("#id_contact_0").val("");
			$("#nom_contact_0").val("");
			$("#ape_contact_0").val("");
			$("#pos_contact_0").val("");
			if (document.getElementById('num_contacts').value<=1)
				return false;
			
	}
		
	if (pos==n_rows_minus)
		removeContact();
	else{
		
		for (var i=pos; i<n_rows_minus; i++){
			//var aux=i+1;
			
			$("#id_contact_"+i).val($("#id_contact_"+(i+1)).val().length>0?$("#id_contact_"+(i+1)).val():"");
			$("#nom_contact_"+i).val($("#nom_contact_"+(i+1)).val().length>0?$("#nom_contact_"+(i+1)).val():"");
			$("#ape_contact_"+i).val($("#ape_contact_"+(i+1)).val().length>0?$("#ape_contact_"+(i+1)).val():"");
			$("#pos_contact_"+i).val($("#pos_contact_"+(i+1)).val().length>0?$("#pos_contact_"+(i+1)).val():"");
			
		}
		
		
		var campo_address = document.getElementById('tr1_contact_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
		var campo_address = document.getElementById('tr2_contact_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
		var campo_address = document.getElementById('tr4_contact_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
				
		/*if (n_rows_minus<=1){
			//$("#removebutton").css({display:"none"});
			$("#botoncontact_").css({display:"none"});
		}*/
		
		$("#num_contacts").val(n_rows_minus);
	}
		
	
	return false;
}

function removeContact(){
	//alert("ENTRO3");
	//Contamos cuantos elementos tenemos de cada tipo
	var n_rows = $("#num_contacts").val();
	var n_rows_minus = (n_rows * 1)-1 ;
	//alert("VALE="+n_rows_minus);
	
	    
		var campo_address = document.getElementById('tr1_contact_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
		var campo_address = document.getElementById('tr2_contact_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
		var campo_address = document.getElementById('tr4_contact_'+n_rows_minus);
		
		campo_address.parentNode.removeChild(campo_address);
		
		
		
		/*if (n_rows_minus<=1){
			//$("#removebutton").css({display:"none"});
			$("#botoncontact_").css({display:"none"});
		}*/
		
		$("#num_contacts").val(n_rows_minus);
		
		
	
}


/******** FIN DE METODOS PARA AÑADIR/BORRAR REDES SOCIALES ********************/
_wbvfREEmail = /^[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$/i;
function wbvfIsEmail (value) {
     return _wbvfREEmail.test (value);
}
   
function submitObservatorio(sent) {
	
		
   // var _ok = wbValidateFormL(document.getElementById('observatorio'),'es');
   var _ok = true;
   var _ok = checkTab(1);
   if (!_ok){
   		muestra_capa_1();
   		return false;
   }
   _ok = checkTab(2);
   if (!_ok){
   		muestra_capa_2();
   		return false;
   }
   
   if (sent!=1){
	   _ok = checkTab(7);
	   if (!_ok){
	   		showUserSubmit();
	   		return false;
	   }
   }
		
	if (_ok){
		var f = document.getElementById('observatorio');	
		var i;		
		var _id = f.id.value;
		var _cif = f.cif.value;
		var _denom_1 = f.denom_1.value;
		var _siglas = f.siglas.value;
		var _fundadores = f.fundadores.value;
		
		var aux=false;
		var _num_public = f.num_public.value;
		var _p_publicas='';
		for (i=0; i<_num_public; i++){
			
			if (document.getElementById('p_publicas_'+i).checked){
				
				aux=true;
				_p_publicas=_p_publicas+'|'+document.getElementById('p_publicas_'+i).value;
			}
		}
		
		if (aux)
				_p_publicas=_p_publicas+'|';
				
		aux=false;
		var _num_private = f.num_private.value;
		var _p_private='';
		for (i=0; i<_num_private; i++){
			
			if (document.getElementById('p_private_'+i).checked){
				
				aux=true;
				_p_private=_p_private+'|'+document.getElementById('p_private_'+i).value;
			}
		}
		if (aux)
				_p_private=_p_private+'|';
		
		var _denom_2 = f.denom_2.value;
		
		var _year = f.year_cons_y.value+"-"+f.year_cons_m.value+"-"+f.year_cons_d.value;
		var _year_ins = f.year_ins_y.value+"-"+f.year_ins_m.value+"-"+f.year_ins_d.value;
		
		
		var _ambito = $("#ambito option:selected").val();
		
		
		var _calle_1 = f.calle_1.value;
		var _postal_1 = f.postal_1.value;
				
		
		var _calle_2 = f.calle_2.value;
		var _postal_2 = f.postal_2.value;
		
		if (_postal_2.length>0){
		     		if (_postal_2.length!=5){
		     			muestra_capa_2();
		     			alert("El código postal debe tener 5 dígitos");
		     			f.postal_2.focus();
		     			return false;
		     		}else if(isNaN(_postal_2)){
		     			muestra_capa_2();
		     			alert("El código postal debe ser numérico");
		     			f.postal_2.focus();
		     			return false;
		     		}
	     }
	     		
		
		var _tel_2 = f.tel_2.value;
		var _mail_2 = f.mail_2.value;
		if ((_mail_2.length>0)&&(!wbvfIsEmail (_mail_2))){
	     			
			muestra_capa_2();
			alert("El campo email tiene formato incorrecto");
			f.mail_2.focus();
			return false;
	    }
		var _web_2 = f.web_2.value;
		
		var _num_spain = f.num_spain.value;
		var _num_ext = f.num_ext.value;
		
		
		aux=false;
		var _num_areas = f.num_areas.value;
		var _areas='';
		var num_checked=0;
		for (i=0; i<_num_areas; i++){
			
			if (document.getElementById('areas_'+i).checked){
				
				aux=true;
				_areas=_areas+'|'+document.getElementById('areas_'+i).value;
				num_checked++;
				if (num_checked>4){
					alert("Sólo se pueden marcar 4 opciones para el campo Areas de actividad principales")
					muestra_capa_3();
					return false;
				}
			}
		}
		if (aux)
				_areas=_areas+'|';
				
		aux=false;
		var _num_tipos = f.num_tipos.value;
		var _num_tipos_gest = f.num_tipos_gest.value;
		/*
		var _num_tipos_gestion = f._num_tipos_gestion.value;
		if (!document.getElementById('gestion').checked){
			
		}*/
		var _tipos='';
		var _tipos_type='';
		
		for (i=0; i<_num_tipos; i++){
			
			if (document.getElementById('tipos_'+i).checked){
				aux=true;
				_tipos=_tipos+'|'+document.getElementById('tipos_'+i).value;
			}
		}
		
		for (i=0; i<_num_tipos_gest; i++){
			
			if (document.getElementById('tiposgest_'+i).checked){
				if (document.getElementById('tiposgest_type_' + i).value == "") {
					alert("Tiene que indicar qué tipo de Entidad o Centro ha seleccionado")
					muestra_capa_3();
					return false;
				}
				aux=true;
				_tipos=_tipos+'|'+document.getElementById('tiposgest_'+i).value;
				_tipos_type=_tipos_type+'|'+document.getElementById('tiposgest_ID_'+i).value+'//'+document.getElementById('tiposgest_type_' + i).value;
			}
		}
		
		
		if (aux) {
				_tipos=_tipos+'|';
				_tipos_type=_tipos_type+'|';
		}
		
		
		var _id_pres = f.id_pres.value;		
		var _nom_pres = f.nom_pres.value;		
		var _ape_pres = f.ape_pres.value;
		var _id_direc = f.id_direc.value;		
		var _nom_direc = f.nom_direc.value;		
		var _ape_direc = f.ape_direc.value;		
				
		
		
		//var _patronos_area = f.patronos_area.value;		
		var _fundacional = f.fundacional.value;		
		var _activos = f.activos.value;
		var _ingresos = f.ingresos.value;
		var _gastos = f.gastos.value;
		var _excedente = f.excedente.value;		
		
		aux=false;
		var _num_donaciones = f.num_donaciones.value;
		var _donaciones='';
		num_checked=0;
				
		for (i=0; i<_num_donaciones; i++){
			
			if (document.getElementById('donaciones_'+i).checked){
				
				aux=true;
				_donaciones=_donaciones+'|'+document.getElementById('donaciones_'+i).value;
				num_checked++;
				if (num_checked>3){
					alert("Sólo se pueden marcar 3 opciones para las Principales fuentes de ingresos")
					muestra_capa_4();
					return false;
				}
			}
		}
		if (aux)
				_donaciones=_donaciones+'|';
				
				
		aux=false;
		var _num_ventas = f.num_ventas.value;
		var _ventas='';
		for (i=0; i<_num_ventas; i++){
			
			if (document.getElementById('ventas_'+i).checked){
				
				aux=true;
				_ventas=_ventas+'|'+document.getElementById('ventas_'+i).value;
				num_checked++;
				if (num_checked>3){
					alert("Sólo se pueden marcar 3 opciones para las Principales fuentes de ingresos")
					muestra_capa_4();
					return false;
				}
			}
		}
		if (aux)
				_ventas=_ventas+'|';
				
		aux=false;
		var _num_rendimiento = f.num_rendimiento.value;
		var _rendimiento='';
		for (i=0; i<_num_rendimiento; i++){
			
			if (document.getElementById('rendimiento_'+i).checked){
				
				aux=true;
				_rendimiento=_rendimiento+'|'+document.getElementById('rendimiento_'+i).value;
				num_checked++;
				if (num_checked>3){
					alert("Sólo se pueden marcar 3 opciones para las Principales fuentes de ingresos")
					muestra_capa_4();
					return false;
				}
			}
		}
		if (aux)
				_rendimiento=_rendimiento+'|';
				
		var _total_patronos = f.total_patronos.value;		
		var _cargo_patronos = f.cargo_patronos.value;
		var _total_empleados = f.total_empleados.value;
		//var _cargo_empleados = f.cargo_empleados.value;
		var _total_voluntarios = f.total_voluntarios.value;	
		//var _cargo_voluntarios = f.cargo_voluntarios.value;
		var _total_indirecto = f.total_indirecto.value;
		var _sent = sent;
		
		if (sent!=1){
			var _datos_1 = f.datos_1.value;	
			var _datos_2 = f.datos_2.value;	
			var _datos_3 = f.datos_3.value;	
			
			
		}
		
		var _idsend = f.idsend.value;	
		var _observaciones = f.observaciones.value;	
		
		aux=false;
		var _num_benjur = f.num_benjur.value;
		var _benjur='';
		for (i=0; i<_num_benjur; i++){
			
			if (document.getElementById('benjur_'+i).checked){
				
				aux=true;
				_benjur=_benjur+'|'+document.getElementById('benjur_'+i).value;
			}
		}
		if (aux)
				_benjur=_benjur+'|';
				
		aux=false;
		var _num_benfis = f.num_benfis.value;
		var _benfis='';
		num_checked=0;
		for (i=0; i<_num_benfis; i++){
			
			if (document.getElementById('benfis_'+i).checked){
				
				aux=true;
				_benfis=_benfis+'|'+document.getElementById('benfis_'+i).value;
				num_checked++;
				if (num_checked>4){
					alert("Sólo se pueden marcar 4 opciones en el campo Personas físicas")
					muestra_capa_3();
					return false;
				}
			}
		}
		if (aux)
				_benfis=_benfis+'|';
		
		var _n_directos = f.n_directos.value;	
		var _num_addresses = $("#num_addresses").val();	
		var _num_networks = $("#num_networks").val();	
		var _num_contacts = $("#num_contacts").val();	
		
	}

	
	if(_ok) {
		  // alert("ID="+_id);
		var data = {id: _id, 
					cif: _cif, 
					denom_1: _denom_1,
					siglas: _siglas,
					fundadores: _fundadores,
					p_publicas: _p_publicas,
					p_private: _p_private,
					denom_2: _denom_2,
					year: _year,
					year_ins: _year_ins,
					
					ambito: _ambito,
					
					calle_1: _calle_1,
					postal_1: _postal_1,
					
					
					
					calle_2: _calle_2,
					postal_2: _postal_2,
					tel_2: _tel_2,
					mail_2: _mail_2,
					web_2: _web_2,
					
					num_spain: _num_spain,
					num_ext: _num_ext,
					num_addresses: _num_addresses,
					num_networks: _num_networks,
					num_contacts: _num_contacts,
					
					id_pres : _id_pres,
					nom_pres : _nom_pres,
					ape_pres : _ape_pres,
					id_direc : _id_direc,
					nom_direc : _nom_direc,
					ape_direc : _ape_direc,
					
					areas: _areas,
					tipos: _tipos,
					tipos_type: _tipos_type,
					//patronos_area: _patronos_area,
					fundacional: _fundacional,
					activos: _activos,
					ingresos: _ingresos,
					gastos: _gastos,
					excedente: _excedente,
					donaciones: _donaciones,
					ventas: _ventas,
					rendimiento: _rendimiento,
					total_patronos: _total_patronos,
					cargo_patronos: _cargo_patronos,
					total_empleados: _total_empleados,
					//cargo_empleados: _cargo_empleados,
					total_voluntarios: _total_voluntarios,
					//cargo_voluntarios: _cargo_voluntarios,
					total_indirecto: _total_indirecto,
					benjur: _benjur,
					benfis: _benfis,
					n_directos: _n_directos,
					datos_1: _datos_1,
					datos_2: _datos_2,
					datos_3: _datos_3,
					observaciones: _observaciones,
					sent: _sent,
					idsend: _idsend
					};
				
					
			
			for(i=0;i<_num_addresses;i++){
				
	     		var _otrosid = f.elements['otrosid_' + i].value;
	     		var _otros_denominacion=f.elements['otros_denominacion_' + i].value;
	     		var _otros_calle=f.elements['otros_calle_' + i].value;
	     		var _otros_postal=f.elements['otros_postal_' + i].value;
	     		var _otros_tel=f.elements['otros_tel_' + i].value;
	     		var _otros_mail=f.elements['otros_mail_' + i].value;
	     		var _otros_web=f.elements['otros_web_' + i].value;
				
	     		if ((_otros_mail.length>0)&&(!wbvfIsEmail (_otros_mail))){
	     			
		     			muestra_capa_2();
			     		alert("El campo email tiene formato incorrecto");
			     		f.elements['otros_mail_' + i].focus();
			     		return false;
	     			
	     		}
	     		if (_otros_postal.length>0){
		     		if (_otros_postal.length!=5){
		     			muestra_capa_2();
		     			alert("El código postal debe tener 5 dígitos");
		     			f.elements['otros_postal_' + i].focus();
		     			return false;
		     		}else if(isNaN(_otros_postal)){
		     			muestra_capa_2();
		     			alert("El código postal debe ser numérico");
		     			f.elements['otros_postal_' + i].focus();
		     			return false;
		     		}
	     		}
	     		
				if (_otrosid == undefined){
					_otrosid="";
				}
				data['otrosid_' + i] = _otrosid;
				
				if (_otros_denominacion != undefined){
					data['otros_denominacion_' + i] = _otros_denominacion;
				}
				if (_otros_calle != undefined){
					data['otros_calle_' + i] = _otros_calle;
				}
				if (_otros_postal != undefined){
					data['otros_postal_' + i] = _otros_postal;
				}
				if (_otros_tel != undefined){
					data['otros_tel_' + i] = _otros_tel;
				}
				if (_otros_mail != undefined){
					data['otros_mail_' + i] = _otros_mail;
				}
				if (_otros_web != undefined){
					data['otros_web_' + i] = _otros_web;
				}
				/*alert ("ID="+_otrosid);
				alert ("DENOM="+_otros_denominacion);
				alert ("CALLE="+_otros_calle);
				alert ("POSTAL="+_otros_postal);
				alert ("TEL="+_otros_tel);
				alert ("MAIL="+_otros_mail);
				alert ("WEB="+_otros_web);
				*/
			}
			
			for(i=0;i<_num_networks;i++){
				
	     		var _url = f.elements['url_' + i].value;
	     		var _red=f.elements['red_' + i].value;
	     		
								
				if (_url != undefined){
					data['url_' + i] = _url;
				}
				if (_red != undefined){
					data['red_' + i] = _red;
				}
				
			}
			
			for(i=0;i<_num_contacts;i++){
				
	     		var _nom_contact = f.elements['nom_contact_' + i].value;
	     		var _ape_contact =f.elements['ape_contact_' + i].value;
	     		var _pos_contact =f.elements['pos_contact_' + i].value;
	     		var _id_contact =f.elements['id_contact_' + i].value;

	     		data['id_contact_' + i] = _id_contact;			
	     		
				if (_nom_contact != undefined){
					data['nom_contact_' + i] = _nom_contact;
				}
				if (_ape_contact != undefined){
					data['ape_contact_' + i] = _ape_contact;
				}
				if (_pos_contact != undefined){
					data['pos_contact_' + i] = _pos_contact;
				}
								
			}
        
        $.ajax({
	           url: "sendForm.php",
	           type: "POST",
	           dataType: "text",
	           data: data,	           		
	           error: function(req, err, obj) {
	           	alert('error : ' + err);
	           },
	           success: function(txt) {
	           	
		           	if (txt!="ERR"){
		           		alert("La informacion se ha enviado correctamente. Gracias por su colaboración."); 
		           		self.location = self.location.href;
		           		return false;
		           	}else{
		       			alert("Se ha producido un error al enviar el formulario. Por favor, inténtelo de nuevo pasados unos minutos."+txt);
		       			self.location = "formulario.html";
		       			return false;
		           	}
	       
	        	}            
	        
	        
			});
		
			
	}
	
	return false;

}

function copyFields(){
	
	var f = document.getElementById('observatorio');
	if (f.mismo.checked){
		if ((f.calle_1.value.length>0)&&(f.calle_1.value!=undefined)){
			f.calle_2.value=f.calle_1.value;
			f.calle_2.disabled=true; 
		}
		
		if ((f.postal_1.value.length>0)&&(f.postal_1.value!=undefined)){
			f.postal_2.value=f.postal_1.value;
			f.postal_2.disabled=true; 
		}
		
		
		
	}else{
		f.calle_2.disabled=false; 
		f.postal_2.disabled=false;
		
	}
	
	return false;
}


function checkUser(){
	
	var _ok = wbValidateFormL(document.getElementById('login'),'es');
	if (_ok){
		var f = document.getElementById('login');
		var _usuario = f.usuario.value;
		var _clave = f.clave.value;
		
		var data = {usuario: _usuario, 
					clave: _clave};
					
		$.ajax({
	           url: "checkLogin.php",
	           type: "POST",
	           dataType: "text",
	           data: data,	           		
	           error: function(req, err, obj) {
	           	alert('error : ' + err);
	           },
	           success: function(txt) {
	           	
		           	if (txt=="OK"){
		           		//alert("Se ha autenticado correctamente"); 
		           		self.location = self.location.href;
		           		return false;
		           	}else{
		       			alert("El usuario/contraseña no es válido.");
		       			self.location = self.location.href;
		       			return false;
		           	}
	       
	        	}            
	        
	        
			});
		
		
	}
	
	return false;
}
function checkUser2(url){
	
	var _ok = wbValidateFormL(document.getElementById('login2'),'es');
	if (_ok){
		var f = document.getElementById('login2');
		var _usuario = f.usuario.value;
		var _clave = f.clave.value;
		
		var data = {usuario: _usuario, 
					clave: _clave};
					
		$.ajax({
	           url: "checkLogin.php",
	           type: "POST",
	           dataType: "text",
	           data: data,	           		
	           error: function(req, err, obj) {
	           	alert('error : ' + err);
	           },
	           success: function(txt) {
	           	
		           	if (txt=="OK"){
		           		alert("Se ha autenticado correctamente"); 
		           		self.location = "http://www.fundaciones.org"+url;
		           		return false;
		           	}else{
		       			alert("El usuario/contraseña no es válido.");
		       			self.location = self.location.href;
		       			return false;
		           	}
	       
	        	}            
	        
	        
			});
		
		
	}
	
	return false;
}

function closeSession(){
	
	
				$.ajax({
	           url: "closeSession.php",
	           type: "POST",
	           dataType: "text",
	           
	           error: function(req, err, obj) {
	           	alert('error : ' + err);
	           },
	           success: function(txt) {
	           		           	
		           	alert("Su sesión se ha cerrado correctamente"); 
		           	self.location = self.location.href;
		           	
	       
	        	}            
	        
	        
			});
		
		
	
	
	return false;
}

function checkTab(tab){
	var minYear=1900;
	var maxYear=2100;
	var daysInMonth = DaysArray(12);
	var f = document.getElementById('observatorio');
	if (tab==1){
		//var _ok = wbValidateFormL(document.getElementById('observatorio1'),'es')
		
		if (!f.cif.value.length>0){
			muestra_capa_1();
			alert("El campo obligatorio NIF está vacío");
			f.cif.focus();
			return false;
			
		}else if (!f.denom_1.value.length>0){
			muestra_capa_1();
			alert("El campo obligatorio Denominación está vacío");
			f.denom_1.focus();
			return false;
			
		}
		else if ((f.year_cons_d.value.length>0)||(f.year_cons_m.value.length>0)||(f.year_cons_y.value.length>0))
		{
		
			if ((f.year_cons_d.value.length<1 || f.year_cons_d.value<1 || f.year_cons_d.value>31 || (f.year_cons_m.value==2 && f.year_cons_d.value>daysInFebruary(f.year_cons_y.value)) || f.year_cons_d.value > daysInMonth[f.year_cons_m.value])){
				muestra_capa_1();
				f.year_cons_d.focus();
				alert("Debe insertar una fecha válida de Fecha de Constitucion");
				return false;
			}
				
				
			
			else if ((f.year_cons_m.value.length<1 || f.year_cons_m.value<1 || f.year_cons_m.value>12)){
				muestra_capa_1();
				f.year_cons_m.focus();
				alert("Debe insertar una fecha válida de Fecha de Constitucion");
				return false;
			}
				
				
				
			else if (f.year_cons_y.value.length != 4 || f.year_cons_y.value==0 || f.year_cons_y.value<minYear || f.year_cons_y.value>maxYear){
				muestra_capa_1();
				f.year_cons_y.focus();
				alert("Por favor, introduzca cuatro dígitos entre "+minYear+" y "+maxYear);
				return false;
			}
		}
		else if ((f.year_ins_d.value.length>0)||(f.year_ins_y.value.length>0)||(f.year_ins_m.value.length>0)){
			if ((f.year_ins_d.value.length<1 || f.year_ins_d.value<1 || f.year_ins_d.value>31 || (f.year_ins_m.value==2 && f.year_ins_d.value>daysInFebruary(f.year_ins_y.value)) || f.year_ins_d.value > daysInMonth[f.year_ins_m.value])){
				muestra_capa_1();
				f.year_ins_d.focus();
				alert("Debe insertar una fecha válida de Fecha de inscripción");
				return false;
			}
				
				
			
			else if ((f.year_ins_m.value.length<1 || f.year_ins_m.value<1 || f.year_ins_m.value>12)){
				muestra_capa_1();
				f.year_ins_m.focus();
				alert("Debe insertar una fecha válida de Año de inscripción");
				return false;
			}
				
				
				
			else if (f.year_ins_y.value.length != 4 || f.year_ins_y.value==0 || f.year_ins_y.value<minYear || f.year_ins_y.value>maxYear){
				muestra_capa_1();
				f.year_ins_y.focus();
				alert("Por favor, introduzca cuatro dígitos entre "+minYear+" y "+maxYear);
				return false;
			}
		}
		
		
		
		
		
	}else if (tab==2){
		if (!f.calle_1.value.length>0){
			muestra_capa_2();
			alert("Hay campos sin rellenar del domicilio estatutario");
			f.calle_1.focus();
			return false;
			
		}
		if (!f.postal_1.value.length>0){
			muestra_capa_2();
			alert("Hay campos sin rellenar del domicilio estatutario");
			f.postal_1.focus();
			return false;
			
		}
		if (f.postal_1.value.length>0){
		     		if (f.postal_1.value.length!=5){
		     			muestra_capa_2();
		     			alert("El código postal debe tener 5 dígitos");
		     			f.postal_1.focus();
		     			return false;
		     		}else if(isNaN(f.postal_1.value)){
		     			muestra_capa_2();
		     			alert("El código postal debe ser numérico");
		     			f.postal_1.focus();
		     			return false;
		     		}
	    }
	    if (!f.calle_2.value.length>0){
			muestra_capa_2();
			alert("Hay campos sin rellenar en los datos de contacto");
			f.calle_2.focus();
			return false;
			
		}
		if (!f.postal_2.value.length>0){
			muestra_capa_2();
			alert("Hay campos sin rellenar en los datos de contacto");
			f.postal_2.focus();
			return false;
			
		}
		if (f.postal_2.value.length>0){
		     		if (f.postal_2.value.length!=5){
		     			muestra_capa_2();
		     			alert("El código postal de contacto debe tener 5 dígitos");
		     			f.postal_2.focus();
		     			return false;
		     		}else if(isNaN(f.postal_2.value)){
		     			muestra_capa_2();
		     			alert("El código postal de contacto debe ser numérico");
		     			f.postal_3.focus();
		     			return false;
		     		}
	    }
	    if (!f.tel_2.value.length>0){
			muestra_capa_2();
			alert("Hay campos sin rellenar en los datos de contacto");
			f.tel_2.focus();
			return false;
	    }
	    if (!f.mail_2.value.length>0){
			muestra_capa_2();
			alert("Hay campos sin rellenar en los datos de contacto");
			f.mail_2.focus();
			return false;
		}
		
	}else if (tab==7){
		
	
		if (!f.datos_1.value.length>0){
			alert("Debe especificar el nombre de la persona que ha rellenado el formulario");
			f.datos_1.focus();
			return false;
			
		}else if (!f.datos_2.value.length>0){
			alert("Debe especificar los apellidos de la persona que ha rellenado el formulario");
			f.datos_2.focus();
			return false;
			
		}else if (!f.datos_3.value.length>0){
			alert("Debe especificar el email de la persona que ha rellenado el formulario");
			f.datos_3.focus();
			return false;
			
		}else if (!wbvfIsEmail (f.datos_3.value)){
			alert("El campo email tiene un formato incorrecto");
			f.datos_3.focus();
			return false;
		}
	}
	
	
	return true;
}

function compruebaAreas(pos,num,checked){
	if (checked){
		var aux=0;
		for (var i=0; i<num; i++){
			if (document.getElementById('areas_'+i).checked){
				aux++;
				if (aux>4){
					alert("El máximo son 4 opciones")
					document.getElementById('areas_'+pos).checked=false;
					break;
				}
			}
			
		}
	}
	return false;
	
}
/*
function compruebaTipos(pos,num,checked){
	if (checked){
		var aux=0;
		for (var i=0; i<num; i++){
			if (document.getElementById('tipos_'+i).checked){
				aux++;
				if (aux>3){
					alert("El máximo son 3 opciones")
					document.getElementById('tipos_'+pos).checked=false;
					break;
				}
			}
			
		}
	}
	return false;
	
}
*/
function compruebaPersFis(pos,num,checked){
	if (checked){
		var aux=0;
		for (var i=0; i<num; i++){
			if (document.getElementById('benfis_'+i).checked){
				aux++;
				if (aux>4){
					alert("El máximo son 4 opciones")
					document.getElementById('benfis_'+pos).checked=false;
					break;
				}
			}
			
		}
	}
	return false;
	
}


function habilitaGestion(){
	
	if (document.getElementById('gestion').checked)
		$("#trGestion").css({ display: "block" });	
	else{
		
		$("#trGestion").css({ display: "none" });	
		_num_tipos_gest = document.getElementById('num_tipos_gest').value;
		for (i=0; i<_num_tipos_gest; i++){
			var object = eval("document.observatorio.tiposgest_"+i);
			object.checked=false;
			var object = eval("document.observatorio.tiposgest_type_"+i);
			object.value='';
			object.disabled= true;
		}
	}
		
	
	return false;
	
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function fechaMayorOIgualQue(day0,month0,year0,day1,month1,year1){ 
    var bRes = false; 
    
    if (year0 > year1) bRes = true; 
    else { 
     if (year0 == year1){ 
      if (month0 > month1) bRes = true; 
      else { 
       if (month0 == month1) 
        if (day0 >= day1) bRes = true; 
      } 
     } 
    } 
    return bRes; 
   }  
   
function compruebaFuentes(tipo,pos,num_donaciones,num_ventas,num_rendimiento,checked){
	if (checked){
		var aux=0;
		for (var i=0; i<num_donaciones; i++){
			if (document.getElementById('donaciones_'+i).checked){
				aux++;
				if (aux>3){
					alert("El máximo son 3 opciones entre donaciones, ventas y rendimiento")
					document.getElementById(tipo+pos).checked=false;
					return false;
				}
			}
			
		}
		
		for (var i=0; i<num_ventas; i++){
			if (document.getElementById('ventas_'+i).checked){
				aux++;
				if (aux>3){
					alert("El máximo son 3 opciones entre donaciones, ventas y rendimiento")
					document.getElementById(tipo+pos).checked=false;
					return false;
				}
			}
			
		}
		for (var i=0; i<num_rendimiento; i++){
			if (document.getElementById('rendimiento_'+i).checked){
				aux++;
				if (aux>3){
					alert("El máximo son 3 opciones entre donaciones, ventas y rendimiento")
					document.getElementById(tipo+pos).checked=false;
					return false;
				}
			}
			
		}
	}
	return false;
	
}

function menuLateral(){
	var aux=document.getElementById("organosgob");
	if(aux.style.display=="none")
		aux.style.display="inline";
	else
		aux.style.display="none";
}





function submitFormNoticias(){
	
	
	var _swlang = document.getElementById('swlang').value;
	
	if (document.getElementById('imagen').value.length>0){
		var imagenAChequear = new Image;
		imagenAChequear.src= document.getElementById('imagen').value;
		while (!imagenAChequear.complete)
			sleep(1);
	}
	
	
	
	
	if (!(_swlang.length>0))
		_swlang = "es";
	var _ok = wbValidateFormL(document.getElementById('FormNoticias'),"es");
	
	
	
	if (_ok){
		var _titulo_noticia = document.getElementById('titulo_noticia').value;
		var _texto_noticia = document.getElementById('texto_noticia').value;
		var _fundacion = document.getElementById('fundacion').value;
		var _persona_contacto = document.getElementById('persona_contacto').value;
		var _mail = document.getElementById('mail').value;
		var _web = document.getElementById('web').value;
		//var _imagen = document.getElementById('imagen').value;
		var _img_width = imagenAChequear.width;
		var _img_height = imagenAChequear.height;
		var _img_name = imagenAChequear.name;
		var _img_type = imagenAChequear.type;
		
	
		var _captcha= document.getElementById('captcha').value;
		//alert("VALE="+ImageInfo.getField(_imagen, "format"));
		return false;
			
		var data = {titulo_noticia: _titulo_noticia,
				 texto_noticia: _texto_noticia,
				 fundacion: _fundacion,
				 persona_contacto: _persona_contacto,
				 mail: _mail,
				 web: _web,
				 imagen: _imagen,
				 captcha: _captcha};
				 
		$.ajax({
		           url: "sendFormNoticias.php",
		           type: "POST",
		           dataType: "text",
		           data: data,	           		
		           error: function(req, err, obj) {
		           	alert('ERROR : ' + err);
		           },
		           success: function(txt){
		           		
		           		alert(txt);
		           		if (txt == "captcha_err"){
		           			alert("La respuesta de seguridad no es correcta (es necesario respetar las mayúsculas)")
		           			return false;
		           		}else if (txt == "OK"){
		           			alert("Su noticia se ha enviado correctamente. Muchas gracias");
		           			self.location = _swlang+"/formulario_noticias";
		           		}else{
		           			alert(txt);
		           			return false;
		           		}
		        	}            
				});
	}	
	return false;
}
