var ua = navigator.userAgent.toLowerCase();
function detect(text) {
   stringposition = ua.indexOf(text) + 1;
   data = text;
   return stringposition;
}	



function Carga () {
	Capas = document.getElementsByTagName("div");
	NumeroCapas = Capas.length;
	Links = document.getElementsByTagName("a");
	NumeroLinks = Links.length;
}

function MostrarOcultarDiv(divId) {
	var state = document.getElementById(divId).style.display;
	if(state== 'none'){
		document.getElementById(divId).style.display = 'block';
	}else{
		document.getElementById(divId).style.display = 'none';
	}
}	




/* ONBLUR DESDE JAVASCRIPT DE TODOS LOS FORMULARIOS. */			

function MarcadoresDeFormularios() {
	var inputes=document.getElementsByTagName('input');
	var textareas=document.getElementsByTagName('textarea');
	var selectes=document.getElementsByTagName('select');
	var numElementosInput = inputes.length;
	var numElementosTextareas = textareas.length;
	var numElementosSelect = selectes.length;
	for (contador=0; contador<numElementosInput; contador++) {
		if (inputes[contador].type=='radio' || inputes[contador].type=='checkbox') {
			inputes[contador].style.border="0px"
		}
		if (inputes[contador].type!='radio' && inputes[contador].type!='checkbox' && inputes[contador].type!='submit') {
			inputes[contador].onfocus= function() { this.style.border= '2px solid #6cc0ed'; this.style.color= '#000'; this.style.padding= '2px';}
			inputes[contador].onblur= function() { this.style.border= '2px solid #e0e0e0'; this.style.color= '#666'; this.style.padding= '2px';}
		}
	}
	for (contador=0; contador<numElementosTextareas; contador++) {
		textareas[contador].onfocus= function() { this.style.border= '2px solid #6cc0ed'; this.style.color= '#000'; this.style.padding= '2px';}
		textareas[contador].onblur= function() { this.style.border= '2px solid #e0e0e0'; this.style.color= '#666'; this.style.padding= '2px';}
	}		
	for (contador=0; contador<numElementosSelect; contador++) {
		selectes[contador].onfocus= function() { this.style.border= '2px solid #6cc0ed'; this.style.color= '#000';}
		selectes[contador].onblur= function() { this.style.border= '2px solid #e0e0e0'; this.style.color= '#666';}
	}			
}


function MostrarOcultarCaja(divId,ClassDiv,idPestana) {
	OcultaDivs (ClassDiv);	
	var state = document.getElementById(divId).style.display;
	if(state== 'none'){
		document.getElementById(divId).style.display = 'block';
	}else{
		document.getElementById(divId).style.display = 'none';
	}
}	

/* OCULTA TODOS LOS DIVS CON UN CLASS DETERMINADO */

function OcultaDivs(ClassDiv) {
	for (var i=0; i<NumeroCapas; i++) {
		if (detect('msie')){
			if (Capas[i].getAttribute("className")==ClassDiv) {
				Capas[i].style.display='none';
			}			
		}else{
			if (Capas[i].getAttribute("class")==ClassDiv) {
				Capas[i].style.display='none';
			}			
		}
	}
}

/* SUSTITUYE UN CLASS POR OTRO EN TODOS LOS LINKS CON UN CLASS DETERMINADO */

function CambiaClassLinks(ClassDiv,ClassDiv2) {
	
	for (var i=0; i<NumeroLinks; i++) {
		if (detect('msie')){
			if (Links[i].getAttribute("className")==ClassDiv) {
				Links[i].className=ClassDiv2;
			}			
		}else{
			if (Links[i].getAttribute("class")==ClassDiv) {
				Links[i].className=ClassDiv2;
			}			
		}
	}
}


var ContadorFotos = 1;
var TransparenciaFoto = 100;
var TiempoCambio = 3000;
var NumeroTotalFotos = 1;
var VelocidadEfecto = 25;

function CarrusellCatalogos(NumFotos) {
	NumeroTotalFotos=NumFotos;
	setTimeout ('FadeOut()',TiempoCambio);
}

function FadeOut() {
	if (TransparenciaFoto>0) {
		TransparenciaFoto--;
		if (detect('msie')){
			document.getElementById('CajaFotos').style.filter = 'alpha(opacity=' + TransparenciaFoto + ')';
		}else{
			document.getElementById('CajaFotos').style.opacity = (TransparenciaFoto/100);
		}
		setTimeout ('FadeOut()',VelocidadEfecto);
	}else{
		CambioDeFoto();
	}
}

function FadeIn() {
	if (TransparenciaFoto<100) {
		TransparenciaFoto++;
		if (detect('msie')){
			document.getElementById('CajaFotos').style.filter = 'alpha(opacity=' + TransparenciaFoto + ')';
		}else{
			document.getElementById('CajaFotos').style.opacity = (TransparenciaFoto/100);
		}
		setTimeout ('FadeIn()',VelocidadEfecto);
	}else{
		setTimeout ('FadeOut()',TiempoCambio);
	}
}

function CambioDeFoto() {
	if (ContadorFotos<NumeroTotalFotos) {
		ContadorFotos++;
	}else{
		ContadorFotos=1;
	}	
	document.getElementById('CajaFotos').src='http://www.dicom-medios.com/clientes/diaslibres/img/visor/foto'+ContadorFotos+'.jpg';
	document.getElementById('CajaFotos').onload = function () {
		setTimeout ('FadeIn()',500);
	}
}





	function CheckEmailAddress(value){
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value)){
			return true;
		}else{
			return false;
		}
	}
	function validar(form){
		if(document.getElementById('Nombre').value==''){
			alert('El campo nombre y apellidos es obligatorio');
			document.getElementById('Nombre').focus();
			return false;
		}else{
			if(document.getElementById('Nombre').value.length<3){
				alert('El campo nombre y apellidos es demasiado corto (mínimo 3 carácteres)');
				document.getElementById('Nombre').focus();
				return false;
			}	
		}
		if(document.getElementById('Email').value==''){
			alert('El campo E-mail es obligatorio');
			document.getElementById('Email').focus();
			return false;
		}else{
			if(!CheckEmailAddress(document.getElementById('Email').value)){
				alert('Revise su E-mail, es incorrecto');
				document.getElementById('Email').focus();
				return false;
			}
		}
		if(document.getElementById('Texto').value==''){
			alert('El campo texto del mensaje es obligatorio');
			document.getElementById('Texto').focus();
			return false;
		}else{
			if(document.getElementById('Texto').value.length>2000){
				alert('El contenido del campo texto del mensaje tiene demasiados carácteres (máximo 2000 carácteres)');
				document.getElementById('Texto').focus();
				return false;
			}	
		}
		return true;
	}

	



/*---------------------------------------------------------------------*/

/* FUNCION QUE MUESTRA UN CUBREPAGINAS. */
/* ---- Abel Tena - 26 marzo 2009 ---- */

function mostrarFoto(NombreFoto,TextoFoto){
	if (detect('msie')){ 	
		var ScrollDePantalla =  window.document.documentElement.scrollTop;
		var TotalPantalla =  window.document.documentElement.scrollBottom;
	}else{
		var ScrollDePantalla =  window.pageYOffset;	
	}	
	document.getElementById('FotoPopUp').src=NombreFoto;
	document.getElementById('FotoPopUp').alt=TextoFoto;
	if (TextoFoto!="") {
		document.getElementById('TextoFotoPopUp').style.display = 'block';
	}
	document.getElementById('TextoFotoPopUp').innerHTML=TextoFoto;
	document.getElementById('Cubrepaginas').style.marginTop=(ScrollDePantalla)+"px";	
	document.getElementById('Cubrepaginas').style.display = 'block';
	
	if (detect('msie')){ 
		document.getElementById('CuerpoPrincipal').scroll = 'no';
	}else{	
		document.getElementById('CuerpoPrincipal').style.overflow = 'hidden';
	}	
	
	document.getElementById('PopUpFoto').style.display = 'block';	
	centradoEnPagina();
}

function ocultarCubrepaginasFoto(){
	document.getElementById('FotoPopUp').alt="";
	document.getElementById('Cubrepaginas').style.display = 'none';
	document.getElementById('PopUpFoto').style.display = 'none';
	document.getElementById('TextoFotoPopUp').style.display = 'none';
	document.getElementById('EnlaceFoto').style.marginTop= "0px";
	
	if (detect('msie')){ 
		document.getElementById('CuerpoPrincipal').scroll = 'yes';	
	}else{	
		document.getElementById('CuerpoPrincipal').style.overflow = 'auto';
	}
	
}

function centradoEnPagina() {
	setTimeout("CalcularCentradodeFoto()",700);
}


function CalcularCentradodeFoto() {
	var altoImagen = document.getElementById('FotoPopUp').clientHeight;
	if (detect('msie')){ 	
		var altoDePantalla = document.body.clientHeight;
		var altoDePantalla = document.documentElement.clientHeight;
		var ScrollDePantalla =  window.document.documentElement.scrollTop;
	}else{
		var altoDePantalla =  window.innerHeight;	
		var ScrollDePantalla =  window.pageYOffset;	
	}

	if (altoDePantalla-altoImagen>0) {
		var margenImagen = ((altoDePantalla-altoImagen)/2);
	}else{
		var margenImagen = 0;
	}
	var espaciadoSuperior=parseInt(ScrollDePantalla)+parseInt(margenImagen)-20;
	document.getElementById('PopUpFoto').style.marginTop= ""+espaciadoSuperior+"px";
}


