var tamanoAncho=2;
var tamanoAlto=2;
var TamanoFuente=1;
var EstadoCapas="Off";

/* <![CDATA[ */
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function openwindowGaleria(id){
	window.open('/galeria/popup.php?id='+id,'Imagen','resizable=yes,menubar=no,toolbar=no,scrollbars=yes,width=468,height=300,top=50,left=50');
}

function openwindowNoticia(id){
	window.open('/noticias/popup.php?id='+id,'Imagen','resizable=yes,menubar=no,toolbar=no,scrollbars=yes,width=468,height=300,top=50,left=50');
}

function Ir(canal) {
	parent.top.location = canal;
} 	

function validarEmail(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
    return (true)
  } else {
    alert("La dirección de Email es incorrecta.");
    return (false);
  }
}

function ComprobarFormAlta(form){
	if(document.getElementById('Nombre').value==''){
		alert('El campo Nombre es obligatorio.');
		return false;
	}
	if(document.getElementById('EmailA').value==''){
		alert('El campo Email es obligatorio.');
		return false;
	}
	if(!validarEmail(document.getElementById('EmailA').value)){
		return false;
	}
	if(document.getElementById('PasswordA').value==''){
		alert('El campo Clave es obligatorio.');
		return false;
	}
	if(document.getElementById('Sector_ID').value==''){
		alert('El campo Sector es obligatorio.');
		return false;
	}
	return true;
}

function validarEmailModificar(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
    return (true)
  } else {
    alert("La dirección de Email es incorrecta.");
    return (false);
  }
}

function ComprobarFormModificar(form){
	if(document.getElementById('EmailM').value==''){
		alert('El campo Email es obligatorio .');
		return false;
	}
	if(!validarEmailModificar(document.getElementById('EmailM').value)){
		return false;
	}
	if(document.getElementById('PasswordM').value==''){
		alert('El campo Clave es obligatorio.');
		return false;
	}
	return true;
}


function validarEmailModificar(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
    return (true)
  } else {
    alert("La dirección de Email es incorrecta.");
    return (false);
  }
}


function ComprobarFormBaja(form){
	if(document.getElementById('EmailB').value==''){
		alert('El campo Email es obligatorio .');
		return false;
	}
	if(!validarEmailModificar(document.getElementById('EmailB').value)){
		return false;
	}
	if(document.getElementById('PasswordB').value==''){
		alert('El campo Clave es obligatorio.');
		return false;
	}
	return true;
}

function ConfirmarSalir(Ruta) {
	if (confirm("¿Está seguro de que desea salir?")){
		window.location = Ruta + "salir.php";
	}
}

function ConfirmarBaja(Ruta) {
	if (confirm("¿Está seguro de que desea darse de baja?")){
		window.location = Ruta + "baja.php";
	}
}


function RedimensionarFoto(IdImagen,TamanoFoto) {
		if (document.getElementById(IdImagen).width>TamanoFoto) {
			document.getElementById(IdImagen).style.width=TamanoFoto+"px";
		}else{
			document.getElementById(IdImagen).style.width=document.getElementById('FotoMostrada').width;
		} 
}

/*-----------------------------------------------------------------------------------------*/
			
function CheckEmailAddress(value){
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value)){
		return true;
	}else{
		return false;
	}
}

function VerificarMail(strMail) {
//La siguiente funcion da error si se introduce algo.usuario@dominio.es
	var patMail = /^(.+)@(.+)$/;
	var patUser = /^[a-zA-Z\d_-]+(\.[a-zA-Z\d_-]+)*$/;
	var patDomainIP = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
	var patDomain = /^[a-zA-Z\d_-]+(\.[a-zA-Z\d_-]+)+$/;
	var matchArray = strMail.match(patMail);
	if(matchArray == null){return false;}
	var user = new String(matchArray[1]);
	var domain = new String(matchArray[2]); 
	if(user.match(patUser) == null){return false;}
	var IPArray = domain.match(patDomainIP);
	if(IPArray != null){ 
		 for (var i=1;i<=4;i++) {
		  if(IPArray[i]>255){return false;}
		 }
		 return true; 
	}
	var domainArray = domain.match(patDomain);
	if(domainArray == null) {return false;}
	if(domainArray[domainArray.length - 1].length < 3 || domainArray[ domainArray.length - 1].length > 5) { return false;}
	return true;
}

function restrictLetraNum(idElementoPasarFoco){//funcion para onKeypress
	//if (event.keyCode == 13) document.getElementById(idElementoPasarFoco).focus();
	//Sólo numerico
	//if (event.keyCode < 48) event.returnValue = false;
	//if (event.keyCode > 57 && event.keyCode < 65) event.returnValue = false;
	//if (event.keyCode > 90 && event.keyCode < 97) event.returnValue = false;
	//if (event.keyCode > 122) event.returnValue = false;
}

function dateToIngles(strFecha){
	//Esta funcion cambia el formato dd/mm/yyyy por yyyy/mm/dd
	//Es util para comparar fechas como cadenas (para ver cual es mayor o menor)
	var arrayFecha = strFecha.split("/");
	var dia =  arrayFecha[0];
	var mes =  arrayFecha[1];
	var anio =  arrayFecha[2];
	return anio + "/" + mes + "/" + dia;
}
/* ]]> */



function MostrarSubmenu(IdMenu) {
	document.getElementById('SubMenu'+IdMenu).style.display = 'block';
	document.getElementById(IdMenu).style.backgroundColor = '#e8e8e8';
	document.getElementById(IdMenu).style.color ='#002b6c';
}

function OcultarSubmenu(IdMenu) {
	document.getElementById('SubMenu'+IdMenu).style.display = 'none';
	document.getElementById(IdMenu).style.backgroundColor = '#3e0000';
	document.getElementById(IdMenu).style.backgroundColor = '#001D3E';
	document.getElementById(IdMenu).style.color ='#fff';	
}


function AumentarFuente() {
	if (TamanoFuente<1.2) {
		TamanoFuente=TamanoFuente+0.1;
		document.getElementById('TresColumnas').style.fontSize=TamanoFuente+"em";
	}
}

function ReducirFuente() {
	if (TamanoFuente>1) {
		TamanoFuente=TamanoFuente-0.1;
		document.getElementById('TresColumnas').style.fontSize=TamanoFuente+"em";
	}
}

function charactermax(id,idreturn){
	var longit = document.getElementById(id).value.length;
	if(!longit) {longit = '0';}
	document.getElementById(idreturn).innerHTML = longit;

	if (longit>2500) {
		document.getElementById('Contador').style.color= '#990000';
		document.getElementById('Contador').style.fontWeight= 'bold';
	}else{
		if (longit>2200 && longit<2500) {
			document.getElementById('Contador').style.color= '#ff6000';
		}else{
			document.getElementById('Contador').style.color= '#999999';
		}
		document.getElementById('Contador').style.fontWeight= 'normal';
	}
}


function CorregirFormulario(elemento,Variable) {
	if (document.getElementById(elemento).value==Variable) {
		document.getElementById(elemento).value="";
	}
}





/* FUNCIONES PARA POPUPS POR CAPAS */


function VerCreciente(NombreCapa, ancho, alto) {
	if (EstadoCapas=="Off") {
		document.getElementById(NombreCapa).style.display = "block";
		redibujarCreciente(NombreCapa,ancho, alto);	
		tamanoAncho=20;
		tamanoAlto=11;	
	}
}

function redibujarCreciente(NombreCapa2, ancho, alto) {
	if (tamanoAncho<ancho || tamanoAlto<alto)  {
		if (tamanoAncho<ancho)  {
			tamanoAncho=tamanoAncho+20;
			document.getElementById(NombreCapa2).style.width = tamanoAncho+"px";
			document.getElementById(NombreCapa2).style.marginLeft = ((385-(tamanoAncho/2))+10)+"px";		
		}
		if (tamanoAlto<alto) {
			tamanoAlto=tamanoAlto+10;
			document.getElementById(NombreCapa2).style.height = tamanoAlto+"px";
			document.getElementById(NombreCapa2).style.marginTop = (200-(tamanoAlto/2))+"px";		
		}
		setTimeout("redibujarCreciente('"+NombreCapa2+"',"+ancho+", "+alto+")",5);
	}else{
		document.getElementById('Contenido'+NombreCapa2).style.display='block';
		EstadoCapas="On";
	}
}

function OcultarMenguante(NombreCapa) {
	if (EstadoCapas=="On") {
		document.getElementById('Contenido'+NombreCapa).style.display='none';
		redibujarMenguante(NombreCapa);
	}
}

function redibujarMenguante(NombreCapa2) {
	if (tamanoAncho>21 && tamanoAlto>11)  {
		tamanoAncho=tamanoAncho-20;
		document.getElementById(NombreCapa2).style.width = tamanoAncho+"px";
		document.getElementById(NombreCapa2).style.marginLeft = ((385-(tamanoAncho/2))+10)+"px";		
		tamanoAlto=tamanoAlto-10;
		document.getElementById(NombreCapa2).style.height = tamanoAlto+"px";
		document.getElementById(NombreCapa2).style.marginTop = (200-(tamanoAlto/2))+"px";		
		setTimeout("redibujarMenguante('"+NombreCapa2+"')",5);
	}else {
		tamanoAncho=2;
		tamanoAlto=2;
		document.getElementById(NombreCapa2).style.display = "none";
		EstadoCapas="Off";
	}
}

	/* MENUS DESPLEGABLES */
		
		function OcultarMenus() {
			var mylist=document.getElementById('MenuInterior');
			var listitems= mylist.getElementsByTagName('ul');
			for (i=0; i<listitems.length; i++) {
				if (listitems[i].className=='Submenu') {
					listitems[i].style.display= 'none';
				}
			} 
		}
		
		function AbrirSubMenu(MenuAMostrar) {
			OcultarMenus();
			if (document.getElementById('Submenu'+MenuAMostrar).style.display != 'block') {
				document.getElementById('Submenu'+MenuAMostrar).style.display = 'block';			
			}else{
				document.getElementById('Submenu'+MenuAMostrar).style.display = 'none';	
				var opcionElegida = document.getElementById('Opcion'+MenuAMostrar);
			}
		}
		
		function ActivarMenu(MenuAActivar) {
			document.getElementById('Opcion'+MenuAActivar).style.color = '#000000';			
		}
		
		function ActivarSubMenu(MenuAActivar,SubMenuAActivar) {
			var SubMenus=document.getElementById('Submenu'+MenuAActivar);	
			var MisOpciones= SubMenus.getElementsByTagName('a');
			MisOpciones[SubMenuAActivar-1].className="Activo";
		}