function trim(instr) {
	str = new String(instr);

	retstr = "";

	for (k = 0; k < str.length; k++)
    	if (str.charAt(k) != " ")
        	retstr = retstr + str.charAt(k);
  return retstr;
}

function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
}

function IsNumber(e) {
	tecla = (document.all) ? e.keyCode : e.which;
	
	if (tecla==8) return true;
	
	patron = /\d/; // Solo acepta números
	te = String.fromCharCode(tecla);
	
	return patron.test(te);
}

function disabledis(){
	document.getElementById("dis").style.display="none";		
}

function enabledis(){
		document.getElementById("dis").style.display="block";	
}

function addModulo(tipo){
	var numModulo=parseInt(document.getElementById("numModulo").value);

	var MSIE=(document.all)?true:false;
	
	if(tipo==1){
		div = document.createElement("div");
		if(MSIE) div.setAttribute("className","entrada_div");
		else div.setAttribute("class","entrada_div");
		
		label = document.createElement("label");
		if(MSIE) label.setAttribute("className","entrada_label");
		else label.setAttribute("class","entrada_label");
		label.setAttribute("for", "txt"+numModulo);
		div.appendChild(label);
		
		span = document.createElement("span");
		if(MSIE) span.setAttribute("className","entrada_label_txt");
		else span.setAttribute("class","entrada_label_txt");
		texto = document.createTextNode("Subtitulo "+numModulo+":");
		span.appendChild(texto);
		label.appendChild(span);
		
		input = document.createElement("input");
		if(MSIE) input.setAttribute("className","entrada_field");
		else input.setAttribute("class","entrada_field");
		input.setAttribute("type", "text");
		input.setAttribute("id", "subtitulo"+numModulo);
		input.setAttribute("name", "subtitulo"+numModulo);
		div.appendChild(input);

		document.getElementById("modulos").appendChild(div);
			
		div = document.createElement("div");
		if(MSIE) div.setAttribute("className","entrada_div");
		else div.setAttribute("class","entrada_div");
		
		label = document.createElement("label");
		if(MSIE) label.setAttribute("className","entrada_label");
		else label.setAttribute("class","entrada_label");
		label.setAttribute("for", "txt"+numModulo);
		div.appendChild(label);
		
		span = document.createElement("span");
		if(MSIE) span.setAttribute("className","entrada_label_txt");
		else span.setAttribute("class","entrada_label_txt");
		texto = document.createTextNode("Texto "+numModulo+":");
		span.appendChild(texto);
		label.appendChild(span);
		
		textarea = document.createElement("textarea");
		if(MSIE) textarea.setAttribute("className","entrada_area2");
		else textarea.setAttribute("class","entrada_area2");
		textarea.setAttribute("id", "txt"+numModulo);
		textarea.setAttribute("name", "txt"+numModulo);
		textarea.setAttribute("rows", "10");
		textarea.setAttribute("cols", "60");
		label.appendChild(textarea);

		document.getElementById("modulos").appendChild(div);
		tinyMCE.execCommand('mceAddControl', false, 'txt'+numModulo);
		
	}else{
		div = document.createElement("div");
		if(MSIE) div.setAttribute("className","ficha2");
		else div.setAttribute("class","ficha2");
		
		div1 = document.createElement("div");
		if(MSIE) div1.setAttribute("className","listado_datos");
		else div1.setAttribute("class","listado_datos");
		div.appendChild(div1);
		
		div2 = document.createElement("div");
		if(MSIE) div2.setAttribute("className","dato");
		else div2.setAttribute("class","dato");
		div1.appendChild(div2);
		
		span = document.createElement("span");
		if(MSIE) span.setAttribute("className","titulo");
		else span.setAttribute("class","titulo");
		texto = document.createTextNode("Nivel de Accesibilidad: ");
		span.appendChild(texto);
		div2.appendChild(span);
		
		select = document.createElement("select");
		if(MSIE) select.setAttribute("className","gestor_field");
		else select.setAttribute("class","gestor_field");
		select.setAttribute("id", "w3c"+numModulo);
		select.setAttribute("name", "w3c"+numModulo);
		div2.appendChild(select);
		
		option1 = document.createElement("option");
		option1.setAttribute("value", 0);
		option1.setAttribute("selected", "selected");
		select.appendChild(option1);
		
		textOption1 = document.createTextNode("No");
		option1.appendChild(textOption1);
		
		option2 = document.createElement("option");
		option2.setAttribute("value", 1);
		select.appendChild(option2);
		
		textOption2 = document.createTextNode("A");
		option2.appendChild(textOption2);
		
		option3 = document.createElement("option");
		option3.setAttribute("value", 2);
		select.appendChild(option3);
		
		textOption3 = document.createTextNode("AA");
		option3.appendChild(textOption3);
		
		option4 = document.createElement("option");
		option4.setAttribute("value", 3);
		select.appendChild(option4);
		
		textOption4 = document.createTextNode("AAA");
		option4.appendChild(textOption4);

		div3 = document.createElement("div");
		if(MSIE) div3.setAttribute("className","dato");
		else div3.setAttribute("class","dato");
		div3.setAttribute("class", "dato");
		div1.appendChild(div3);
		
		span = document.createElement("span");
		if(MSIE) span.setAttribute("className","titulo");
		else span.setAttribute("class","titulo");
		texto = document.createTextNode("Comunidad autonoma: ");
		span.appendChild(texto);
		div3.appendChild(span);
		
		select = document.createElement("select");
		if(MSIE) select.setAttribute("className","gestor_field");
		else select.setAttribute("class","gestor_field");
		select.setAttribute("id", "comunidad"+numModulo);
		select.setAttribute("name", "comunidad"+numModulo);
		div3.appendChild(select);
		
		option1 = document.createElement("option");
		option1.setAttribute("value", 0);
		option1.setAttribute("selected", "selected");
		select.appendChild(option1);
		
		textOption1 = document.createTextNode("A nivel estatal");
		option1.appendChild(textOption1);
				
		option3 = document.createElement("option");
		option3.setAttribute("value", 2);
		select.appendChild(option3);
		
		textOption3 = document.createTextNode("Andalucia");
		option3.appendChild(textOption3);
		
		option4 = document.createElement("option");
		option4.setAttribute("value", 3);
		select.appendChild(option4);
		
		textOption4 = document.createTextNode("Aragon");
		option4.appendChild(textOption4);
		
		option5 = document.createElement("option");
		option5.setAttribute("value", 4);
		select.appendChild(option5);
		
		textOption5 = document.createTextNode("Asturias");
		option5.appendChild(textOption5);
		
		option6 = document.createElement("option");
		option6.setAttribute("value", 5);
		select.appendChild(option6);
		
		textOption6 = document.createTextNode("Cantabria");
		option6.appendChild(textOption6);
		//Castella-Lleó
		option2 = document.createElement("option");
		option2.setAttribute("value", 1);
		select.appendChild(option2);
		
		textOption2 = document.createTextNode("Castilla y Leon");
		option2.appendChild(textOption2);

		//Fi Castella-Lleó
		
		option7 = document.createElement("option");
		option7.setAttribute("value", 6);
		select.appendChild(option7);
		
		textOption7 = document.createTextNode("Castilla-La Mancha");
		option7.appendChild(textOption7);
		
		option8 = document.createElement("option");
		option8.setAttribute("value", 7);
		select.appendChild(option8);
		
		textOption8 = document.createTextNode("Catalunya");
		option8.appendChild(textOption8);
		
		option9 = document.createElement("option");
		option9.setAttribute("value", 8);
		select.appendChild(option9);
		
		textOption9 = document.createTextNode("Ceuta");
		option9.appendChild(textOption9);
		
		option10 = document.createElement("option");
		option10.setAttribute("value", 9);
		select.appendChild(option10);
		
		textOption10 = document.createTextNode("Comunidad Valenciana");
		option10.appendChild(textOption10);
		
		option11 = document.createElement("option");
		option11.setAttribute("value", 10);
		select.appendChild(option11);
		
		textOption11 = document.createTextNode("Extremadura");
		option11.appendChild(textOption11);
		
		option12 = document.createElement("option");
		option12.setAttribute("value", 11);
		select.appendChild(option12);
		
		textOption12 = document.createTextNode("Galicia");
		option12.appendChild(textOption12);
		
		option13 = document.createElement("option");
		option13.setAttribute("value", 12);
		select.appendChild(option13);
		
		textOption13 = document.createTextNode("Islas Baleares");
		option13.appendChild(textOption13);
		
		option14 = document.createElement("option");
		option14.setAttribute("value", 13);
		select.appendChild(option14);
		
		textOption14 = document.createTextNode("Islas Canarias");
		option14.appendChild(textOption14);
		
		option15 = document.createElement("option");
		option15.setAttribute("value", 14);
		select.appendChild(option15);
		
		textOption15 = document.createTextNode("La Rioja");
		option15.appendChild(textOption15);
		
		option16 = document.createElement("option");
		option16.setAttribute("value", 15);
		select.appendChild(option16);
		
		textOption16 = document.createTextNode("Madrid");
		option16.appendChild(textOption16);
		
		option17 = document.createElement("option");
		option17.setAttribute("value", 16);
		select.appendChild(option17);
		
		textOption17 = document.createTextNode("Melilla");
		option17.appendChild(textOption17);
		
		option18 = document.createElement("option");
		option18.setAttribute("value", 17);
		select.appendChild(option18);
		
		textOption18 = document.createTextNode("Murcia");
		option18.appendChild(textOption18);
		
		option19 = document.createElement("option");
		option19.setAttribute("value", 18);
		select.appendChild(option19);
		
		textOption19 = document.createTextNode("Navarra");
		option19.appendChild(textOption19);
		
		option20 = document.createElement("option");
		option20.setAttribute("value", 19);
		select.appendChild(option20);
		
		textOption20 = document.createTextNode("Pais Vasco");
		option20.appendChild(textOption20);
		
		div4 = document.createElement("div");
		if(MSIE) div4.setAttribute("className","dato");
		else div4.setAttribute("class","dato");
		div1.appendChild(div4);
		
		span = document.createElement("span");
		if(MSIE) span.setAttribute("className","titulo");
		else span.setAttribute("class","titulo");
		texto = document.createTextNode("Titulo/Nombre: ");
		span.appendChild(texto);
		div4.appendChild(span);
		
		input = document.createElement("input");
		if(MSIE) input.setAttribute("className","gestor_field");
		else input.setAttribute("class","gestor_field");
		input.setAttribute("type", "text");
		input.setAttribute("id", "titulo"+numModulo);
		input.setAttribute("name", "titulo"+numModulo);
		div4.appendChild(input);
		
		div5 = document.createElement("div");
		if(MSIE) div5.setAttribute("className","dato");
		else div5.setAttribute("class","dato");
		div1.appendChild(div5);
		
		span = document.createElement("span");
		if(MSIE) span.setAttribute("className","titulo");
		else span.setAttribute("class","titulo");
		texto = document.createTextNode("URL: ");
		span.appendChild(texto);
		div5.appendChild(span);
		
		input = document.createElement("input");
		if(MSIE) input.setAttribute("className","gestor_field");
		else input.setAttribute("class","gestor_field");
		input.setAttribute("type", "text");
		input.setAttribute("id", "url"+numModulo);
		input.setAttribute("name", "url"+numModulo);
		div5.appendChild(input);
		
		div6 = document.createElement("div");
		if(MSIE) div6.setAttribute("className","dato");
		else div6.setAttribute("class","dato");
		div1.appendChild(div6);
		
		span = document.createElement("span");
		if(MSIE) span.setAttribute("className","titulo");
		else span.setAttribute("class","titulo");
		texto = document.createTextNode("Datos de contacto: ");
		span.appendChild(texto);
		div6.appendChild(span);
		
		input = document.createElement("input");
		if(MSIE) input.setAttribute("className","gestor_field");
		else input.setAttribute("class","gestor_field");
		input.setAttribute("type", "text");
		input.setAttribute("id", "direccion"+numModulo);
		input.setAttribute("name", "direccion"+numModulo);
		div6.appendChild(input);
		
		div7 = document.createElement("div");
		if(MSIE) div7.setAttribute("className","dato");
		else div7.setAttribute("class","dato");
		div1.appendChild(div7);
		
		span = document.createElement("span");
		if(MSIE) span.setAttribute("className","titulo");
		else span.setAttribute("class","titulo");
		texto = document.createTextNode("Telefono: ");
		span.appendChild(texto);
		div7.appendChild(span);
		
		input = document.createElement("input");
		if(MSIE) input.setAttribute("className","gestor_field");
		else input.setAttribute("class","gestor_field");
		input.setAttribute("type", "text");
		input.setAttribute("id", "telefono"+numModulo);
		input.setAttribute("name", "telefono"+numModulo);
		div7.appendChild(input);
		
		div8 = document.createElement("div");
		if(MSIE) div8.setAttribute("className","dato");
		else div8.setAttribute("class","dato");
		div1.appendChild(div8);
		
		span = document.createElement("span");
		if(MSIE) span.setAttribute("className","titulo");
		else span.setAttribute("class","titulo");
		texto = document.createTextNode("Telefono de texto: ");
		span.appendChild(texto);
		div8.appendChild(span);
		
		input = document.createElement("input");
		if(MSIE) input.setAttribute("className","gestor_field");
		else input.setAttribute("class","gestor_field");
		input.setAttribute("type", "text");
		input.setAttribute("id", "telefono_texto"+numModulo);
		input.setAttribute("name", "telefono_texto"+numModulo);
		div8.appendChild(input);
		
		div9 = document.createElement("div");
		if(MSIE) div9.setAttribute("className","dato");
		else div9.setAttribute("class","dato");
		div1.appendChild(div9);
		
		span = document.createElement("span");
		if(MSIE) span.setAttribute("className","titulo");
		else span.setAttribute("class","titulo");
		texto = document.createTextNode("Fax: ");
		span.appendChild(texto);
		div9.appendChild(span);
		
		input = document.createElement("input");
		if(MSIE) input.setAttribute("className","gestor_field");
		else input.setAttribute("class","gestor_field");
		input.setAttribute("type", "text");
		input.setAttribute("id", "fax"+numModulo);
		input.setAttribute("name", "fax"+numModulo);
		div9.appendChild(input);
		
		div10 = document.createElement("div");
		if(MSIE) div10.setAttribute("className","dato");
		else div10.setAttribute("class","dato");
		div1.appendChild(div10);
		
		span = document.createElement("span");
		if(MSIE) span.setAttribute("className","titulo");
		else span.setAttribute("class","titulo");
		texto = document.createTextNode("Email: ");
		span.appendChild(texto);
		div10.appendChild(span);
		
		input = document.createElement("input");
		if(MSIE) input.setAttribute("className","gestor_field");
		else input.setAttribute("class","gestor_field");
		input.setAttribute("type", "text");
		input.setAttribute("id", "email"+numModulo);
		input.setAttribute("name", "email"+numModulo);
		div10.appendChild(input);
		
		div11 = document.createElement("div");
		if(MSIE) div11.setAttribute("className","dato");
		else div11.setAttribute("class","dato");
		div1.appendChild(div11);
		
		span = document.createElement("span");
		if(MSIE) span.setAttribute("className","titulo");
		else span.setAttribute("class","titulo");
		texto = document.createTextNode("Comentario: ");
		span.appendChild(texto);
		div11.appendChild(span);
		
		textarea = document.createElement("textarea");
		if(MSIE) textarea.setAttribute("className","contacta_area2");
		else textarea.setAttribute("class","contacta_area2");
		textarea.setAttribute("id", "comentario"+numModulo);
		textarea.setAttribute("name", "comentario"+numModulo);
		div11.appendChild(textarea);
		
		document.getElementById("modulos").appendChild(div);	
	}
	
	document.getElementById("numModulo").value=numModulo+1;
}

function buscaText(txt,txt2){
	var buff;
	buff=txt.search(txt2);
	
	return buff;
}

function editarCanal(){
	var option = document.getElementById("canal").options[document.getElementById("canal").selectedIndex].value;
	
	if(option!=0) window.location="editCanal.php?option="+option;
}

function editarSubcanal(id){
	var option = document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	
	if(option!=0) window.location="editSubcanal.php?id="+id+"&option="+option;
}

function editarPlantilla(){
	var option = document.getElementById("plantilla").options[document.getElementById("plantilla").selectedIndex].value;
	
	if(option!=0) window.location="editPlantilla.php?option="+option;
}

function editarSubplantilla(){
	var option = document.getElementById("subplantilla").options[document.getElementById("subplantilla").selectedIndex].value;
	
	if(option!=0) window.location="editSubplantilla.php?option="+option;
}

function borrarSubcanal(id){
	var option = document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	
	if(option!=0) window.location="borrarSubcanal.php?id="+id+"&option="+option;
}

function borrarPlantilla(){
	var option = document.getElementById("plantilla").options[document.getElementById("plantilla").selectedIndex].value;
	
	if(option!=0) window.location="borrarPlantilla.php?option="+option;
}


function borrarSubplantilla(){
	var option = document.getElementById("subplantilla").options[document.getElementById("subplantilla").selectedIndex].value;
	
	if(option!=0) window.location="borrarSubPlantilla.php?option="+option;
}

function newSubcanal(id){
	var option;
	
	switch(id){
		case "subcanal1":
			option = document.getElementById("canal").options[document.getElementById("canal").selectedIndex].value;
			break;
			
		case "subcanal2":
			option = document.getElementById("subcanal1").options[document.getElementById("subcanal1").selectedIndex].value;
			break;
		
		case "subcanal3":
			option = document.getElementById("subcanal2").options[document.getElementById("subcanal2").selectedIndex].value;
			break;
	}
	
	window.location="newSubcanal.php?id="+id+"&option="+option;
}

function newPlantilla(id){
	var option = document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	
	window.location="newPlantilla.php?id="+id+"&option="+option;
}

function newSubplantilla(){
	var option = document.getElementById("plantilla").options[document.getElementById("plantilla").selectedIndex].value;
	
	window.location="newSubplantilla.php?option="+option;
}

function mostraSubplantilla(){
	var estat=document.getElementById("Subplantilla").style.display;
	
	if(estat=="none"){
		document.getElementById("Subplantilla").style.display="block";
	}else{
		document.getElementById("Subplantilla").style.display="none";
	}
}


function mostraSubnivell(id,nivell){
	var option = document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	var estat;
	switch(option){
		case '1':
			if(nivell=="subcanal3")document.getElementById("divSubplantilla").style.display="block";
			document.getElementById("divPlantilla").style.display="none";
			document.getElementById("divSubcanal").style.display="none";
			break;
		
		case '2':
			estat=document.getElementById("divPlantilla").style.display;
			
			if(estat=="none"){
				document.getElementById("divPlantilla").style.display="block";
				document.getElementById("divSubcanal").style.display="none";
				document.getElementById("divSubplantilla").style.display="none";
			}else{
				document.getElementById("divPlantilla").style.display="none";
			}
			break;
			
		case '3':
			estat=document.getElementById("divSubcanal").style.display;
			
			if(estat=="none"){
				document.getElementById("divSubcanal").style.display="block";
				document.getElementById("divPlantilla").style.display="none";
				document.getElementById("divSubplantilla").style.display="none";
			}else{
				document.getElementById("divSubcanal").style.display="none";
			}
			break;
	}

	
}

function mostraSubnivell2(id){
	var option = document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
	var estat;
	switch(option){
		case '1':
			document.getElementById("divPlantilla2").style.display="none";
			document.getElementById("divSubcanal2").style.display="none";
			break;
		
		case '2':
			estat=document.getElementById("divPlantilla2").style.display;
			
			if(estat=="none"){
				document.getElementById("divPlantilla2").style.display="block";
				document.getElementById("divSubcanal2").style.display="none";
			}else{
				document.getElementById("divPlantilla2").style.display="none";
			}
			break;
			
		case '3':
			estat=document.getElementById("divSubcanal2").style.display;
			
			if(estat=="none"){
				document.getElementById("divSubcanal2").style.display="block";
				document.getElementById("divPlantilla2").style.display="none";
			}else{
				document.getElementById("divSubcanal2").style.display="none";
			}
			break;
	}

	
}

function disp_confirm(){
	var i=0;
	var borrar=0;
	while(i<document.getElementById["numModulo"].value || !borrar){
		if(document.getElementById["borra"+i].checked==true) borrar=1;
		i++;
	}
	if(borrar==1){
		if (!confirm("Desea borrar los modulos marcados?")) window.location.href="gestContenido.php";
		else document.getElementById["entrada"].submit();
	}else{
		document.getElementById["entrada"].submit();
	}
}