/*******Cookie*******/
function ponValor(nombre, valor, dias)
{
	if(typeof(dias) == "undefined") dias = 7;
	// Si no se proporciona el tercer argumento
	// (dias), entonces una semana por defecto.
	var fecha = new Date;
	fecha.setTime(fecha.getTime() + dias * 24 * 3600000);
	// 3600000 milisegundos por hora
	var caduca = "; expires=" + fecha.toGMTString();
	var galleta = nombre + "=" + valor + caduca;
	document.cookie = galleta;
}

function borraValor(nombre)
{ // Basta con que sea una fecha pasada
	ponValor(nombre, "", -1); // Ayer
}

function dameValor(nombre)
{
	var ini = document.cookie.indexOf(nombre);
	if(ini == -1)
		return ""; // No existe ese valor
	var sep = document.cookie.indexOf("=", ini);
	var fin = document.cookie.indexOf(";", ini);
	if(fin == -1) // El último no acaba en ;
		fin = document.cookie.length;
	return document.cookie.substring(sep+1, fin);
}

function registrarDatos() {
	// Vamos a guardar en una cookie el campo acepto durante 7 dias, cuando el usuario pulse en entrar
	var nombre="acepto";
	var valor=true;
	ponValor(nombre, valor, 7);
}
/*******Cookie*******/


// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		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
		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 = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
	
function showLightbox()
{
	//Comprobamos si están las cookies habilitadas
	document.cookie="check=1; path=/;expires= Sun, 21 Jun 2900 00:00:01 GMT;";
	var cook=document.cookie;
	if(cook.indexOf("check=1")!=-1) {
	//Cookies habilitadas
		if (dameValor('acepto'))
		{
			document.getElementById('over').style.display='none';
			document.getElementById('fade').style.display='none';	
		}
		else
		{
			var fade = document.getElementById('fade');
			var over = document.getElementById('over');
			var arrayPageSize = getPageSize();
			
			fade.style.height = (arrayPageSize[1] + 'px');
			fade.style.display = 'block';
			over.style.display = 'block';
		}
	}
	//Borramos la cookie de comprobación
	document.cookie="check=1; path=/;expires= Sun, 21 Jun 1900 00:00:01 GMT;";
}

function hideLightbox()
{
	registrarDatos();
	document.getElementById('over').style.display='none';
	document.getElementById('fade').style.display='none';
}

