// JavaScript Document

var contadorVerificacion = 1;

function recargarImagenCaptcha ()
{
	document.getElementById('codigoVerificacion').innerHTML = "<img alt='Código Verificación' title='Código Verificación' width='173' height='45' style='margin-top: 5px; border: 1px solid #8d998c;' src='includes/imagenGen.php?num=" + contadorVerificacion + "' border='0' />";
	
	contadorVerificacion++;
	
	return false;	
}

function enviarOpinion ()
{
	var nombre 	= document.getElementById('opinion_nombre').value;
	var texto	= document.getElementById('opinion_texto').value;
	
	if ( ( nombre == "" ) || ( texto == "" ) )
	{
		alert ( 'Debes rellenar todos los campos' );
	}
	else
	{
		document.getElementById('formOpinar').submit();
	}
}

function enviarRompeDestinos ()
{
	var nombre 		= document.getElementById('rompe_nombre').value;
	var mail		= document.getElementById('rompe_mail').value;
	var destinos	= document.getElementById('rompe_destinos').value;
	
	if ( ( nombre == "" ) || ( mail == "" ) || ( destinos == "" ) )
	{
		alert ( 'Debes rellenar todos los campos' );
	}
	else if ( validaEmail ( mail ) == false )
	{
		alert ( 'El formato del mail no es correcto' );
	}
	else if ( validaVariosEmails ( destinos ) == false )
	{
		alert ( 'El formato de los destinos no es correcto' );
	}
	else
	{
		document.getElementById('formRompe').submit();
	}
}

function validaEmail (mail)
{
	var filter=/^[A-Za-z0-9][A-Za-z0-9_.\-]*@[A-Za-z0-9_\-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	
	if (mail.length == 0 )		return false;
	
	if (filter.test(mail))		return true;
	else						return false;
}

function validaVariosEmails (mails)
{
	// Separados por comas
	
	var filter=/^([A-Za-z0-9][A-Za-z0-9_.\-]*@[A-Za-z0-9_\-]+\.[A-Za-z0-9_.]+[A-za-z]([\s]?|[\s]?,[\s]?))+$/;
	
	if (mails.length == 0 )		return false;
	
	if (filter.test(mails))		return true;
	else						return false;
}

function mostrarBloqueProblematica ( nombreid )
{
	var menu_id		= 'm_' + nombreid;
	var bloque_id	= 'b_' + nombreid;
	
	document.getElementById('m_queeschagas').style.display		= "none";
	document.getElementById('m_transmite').style.display		= "none";
	document.getElementById('m_diagnostico').style.display		= "none";
	document.getElementById('m_tratamiento').style.display		= "none";
	document.getElementById('m_barreras').style.display			= "none";
	
	document.getElementById(menu_id).style.display				= "block";
	
	document.getElementById('b_queeschagas').style.display		= "none";
	document.getElementById('b_transmite').style.display		= "none";
	document.getElementById('b_diagnostico').style.display		= "none";
	document.getElementById('b_tratamiento').style.display		= "none";
	document.getElementById('b_barreras').style.display			= "none";
	
	document.getElementById(bloque_id).style.display			= "block";	
	
	return false;
}


function mostrarBloqueExperiencia ( nombreid )
{
	var menu_id		= 'm_' + nombreid;
	var bloque_id	= 'b_' + nombreid;
	
	document.getElementById('m_experiencia').style.display		= "none";
	document.getElementById('m_tratar').style.display			= "none";
	
	document.getElementById(menu_id).style.display				= "block";
	
	document.getElementById('b_experiencia').style.display		= "none";
	document.getElementById('b_tratar').style.display			= "none";
	
	document.getElementById(bloque_id).style.display			= "block";	
	
	return false;
}

function mostrarBloqueActualidad ( nombreid )
{
	var menu_id		= 'm_' + nombreid;
	var bloque_id	= 'b_' + nombreid;
	
	document.getElementById('m_agenda').style.display		= "none";
	document.getElementById('m_noticias').style.display			= "none";
	
	document.getElementById(menu_id).style.display				= "block";
	
	document.getElementById('b_agenda').style.display		= "none";
	document.getElementById('b_noticias').style.display			= "none";
	
	document.getElementById(bloque_id).style.display			= "block";	
	
	return false;
}

function mostrarBloqueAccion ( nombreid )
{
	var menu_id		= 'm_' + nombreid;
	var bloque_id	= 'b_' + nombreid;
	
	document.getElementById('m_mejorespruebas').style.display	= "none";
	document.getElementById('m_efectivos').style.display		= "none";
	document.getElementById('m_curacion').style.display			= "none";
	document.getElementById('m_estrategias').style.display		= "none";
	document.getElementById('m_gobiernos').style.display		= "none";
	
	document.getElementById(menu_id).style.display				= "block";
	
	document.getElementById('b_mejorespruebas').style.display	= "none";
	document.getElementById('b_efectivos').style.display		= "none";
	document.getElementById('b_curacion').style.display			= "none";
	document.getElementById('b_estrategias').style.display		= "none";
	document.getElementById('b_gobiernos').style.display		= "none";
	
	document.getElementById(bloque_id).style.display			= "block";	
	
	return false;
}

function mostrarCapaFondoOscuro ()
{
	var arrayPageSize = getTamPagina ();
	$('divFondoOscuro').style.height = arrayPageSize[1] + 'px';
		
	new Effect.Appear ( 'divFondoOscuro' , { 
			duration: 0.5, 
			from: 0.0, 
			to: 0.5,
			afterUpdate: (function(){ $('divFondoOscuro').style.visibility = 'visible'; }),
			afterFinish: (function(){ $('divVideo').style.visibility = 'visible'; })
	} );
}

function ocultarCapaFondoOscuro ()
{
	new Effect.Appear ( 'divFondoOscuro' , { 
			duration: 0.5, 
			from: 0.5, 
			to: 0.0,
			afterUpdate: (function(){ $('divVideo').style.visibility = 'hidden'; }),
			afterFinish: (function(){ $('divFondoOscuro').style.visibility = 'hidden'; })
	} );
}

function getTamPagina () 
{ 
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}