var inicio_sesion=0;
var interval_name = 0;
function init_inicio_sesion(){
	SetCookie ("inicio_sesion", "0");
	interval_name = setInterval("check_inicio_sesion()", 1000);
}
function end_inicio_sesion(){
	eraseCookie("inicio_sesion");
	setTimeout("clearInterval("+interval_name+")",100);
}
function check_inicio_sesion(){
	var cookie=GetCookie("inicio_sesion");
	//alert(cookie);
	switch(cookie)
	{
		case "-1":
		break;
		case "0":
		break;
		case "1":
			end_inicio_sesion();
			GB_CURRENT.hide();
			document.getElementById("login").innerHTML = "Bienvenido, "+GetCookie("name");
			document.getElementById("login_footer").innerHTML = '<a href="p_contenido.php?q=m/5/212&regi=4" class="pie-txt-pre-peqazul5">Mi Cuenta</a>';
			document.getElementById("logout").innerHTML = "<a href=\"p_contenido.php?op=cs\" class='cab-txt-pre-minazul3'>Cerrar Sesion</a>";
			//cerrar ventana y cambiar mensaje en top
		break;
		case "2":
			end_inicio_sesion();
			GB_CURRENT.hide();
			document.location.href=GetCookie("redirect");
		break;
		case "3":
				end_inicio_sesion();
				GB_CURRENT.hide();
				document.location.href="p_contenido.php?q=m/1/221";
				document.getElementById("login").innerHTML = "Bienvenido, "+GetCookie("name");
				document.getElementById("login_footer").innerHTML = '<a href="p_contenido.php?q=m/5/212&regi=4" class="pie-txt-pre-peqazul5">Mi Cuenta</a>';
				document.getElementById("logout").innerHTML = "<a href=\"p_contenido.php?op=cs\" class='cab-txt-pre-minazul3'>Cerrar Sesion</a>";	

			break;
		default:
			end_inicio_sesion();
	}
}
function redirect(valor)
{
	SetCookie ("inicio_sesion", "2");
	SetCookie ("redirect", valor);
}
/*function createXMLRequest(){
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		return new XMLHttpRequest();
	}else if(window.ActiveXObject) { // IE
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				return new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){}
		}
	}
}

var http_request = createXMLRequest();

//pasamos los parametros que queremos enviar al servidor
function send(a){
	
	http_request.open('POST', 'envio_mail.php',true);
	
	//definimos el handler para la respuesta
	http_request.onreadystatechange = updateStatus;
	http_request.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    http_request.send('titulo='+document.noticia_detalles.titulo.value+"&sumario="+document.noticia_detalles.sumario.value+"&cuerpo="+document.noticia_detalles.cuerpo.value+"&changed="+document.noticia_detalles.changed.value+"&seccion="+document.noticia_detalles.seccion.value+"&imagen="+document.noticia_detalles.imagen.value+"&nid="+document.noticia_detalles.nid.value);//podemos pasar valores por post
}
*/

/*cookies*/

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


function getCookieVal (offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) 
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) 
		break; 
	}
	return null;
}

function SetCookie (name, value) 
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (2 < argc) ? argv[2] : null;
	var path = (3 < argc) ? argv[3] : null;
	var domain = (4 < argc) ? argv[4] : null;
	var secure = (5 < argc) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}
/*cookies*/

function mos_flecha(tag){
var ii = 8
var tipo= tag.substring(0,3)

for(var i=1;i<=ii;i++) {

document.getElementById(tipo+i).style.display="none"

}

document.getElementById(tag).style.display="block"

}

function pop_up(URL){ 
window.open(URL,"ventana1","width=1000, height=850, scrollbars=yes, menubar=no, location=no, resizable=no"); 
} 
function new_ven(URL){ 
window.open(URL,"ventana1","width=350, height=400, scrollbars=no, menubar=no, location=no, resizable=no"); 
} 

function Tour() {
 window.open('http://impresodigital.el-nacional.com/tourvirtualnew/tour.html', 'TOUR', 'menubar=no,status=no,toolbar=no,resizable=no,scrollbars=no, width=600,height=427');

}

function validar_busca(){
	if(document.buscar.q.value==""){
		alert("No hay palabra para hacer la busqueda");
		return false;
	}else{
		document.buscar.submit();
	}
	
}

function isEmailAddress_to(theElement, nombre_del_elemento )
{
var s = theElement.value;
	var filter=/^[A-Za-z][A-Za-z0-9_\.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if ((s.indexOf('@', 0) == -1) || (s.indexOf('.', 0) == -1)) {
		alert("Entre una direccion de corre valida ");
		theElement.focus();

	}else{
		return true;
	}
	return false;
} 