function InstanciaAjax() {
	try {
			objAjax = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
			try {
					objAjax= new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
					objAjax= false;
			}
	}
	if (!objAjax && typeof XMLHttpRequest!='undefined') {
			objAjax = new XMLHttpRequest();
	}
	return objAjax
}

function SacaNotaPrincipal()
{
	var miObjetoAjaxCombo = false;
	miObjetoAjaxCombo=InstanciaAjax();
	var urlAsp="/ediciononline/macro/sacaNotas.asp?tamaniofoto=244";
	miObjetoAjaxCombo.open("GET",urlAsp,true);
	miObjetoAjaxCombo.onreadystatechange=function() {
	var i=0;
	var enlacex='';
	cod_nota='';
	if (miObjetoAjaxCombo.readyState==4)
		{
			info=miObjetoAjaxCombo.responseXML;//guardo en la variable info el xml
			var num=info.getElementsByTagName('NOTA').length;//saco la cantidad de nodos
			for (i = 0; i < num; i++)
				{
				cod_nota='';
				titulo='';
				cabecera='';
				hora='';
				rutafoto='';
				sumillafoto='';
				altfoto='';
				conecciondirecta='';
				mail='';
				enlaceforo='';
				notasrelacionadas='';
				if (info.getElementsByTagName('CODNOTA').item(i).firstChild){
					cod_nota=info.getElementsByTagName('CODNOTA').item(i).firstChild.nodeValue;
				}
				else{
					cod_nota='';
				}
				if (info.getElementsByTagName('TITULO').item(i).firstChild){
					titulo=info.getElementsByTagName('TITULO').item(i).firstChild.nodeValue;
				}
				else{
					titulo='';
				}
				if (info.getElementsByTagName('CABECERA').item(i).firstChild){
					cabecera=info.getElementsByTagName('CABECERA').item(i).firstChild.nodeValue;
				}
				else{
					cabecera='';
				}
				if (info.getElementsByTagName('HORA').item(i).firstChild){
					hora=info.getElementsByTagName('HORA').item(i).firstChild.nodeValue;
				}
				else{
					hora='';
				}
				if (info.getElementsByTagName('RUTAFOTO').item(i).firstChild){
					rutafoto=info.getElementsByTagName('RUTAFOTO').item(i).firstChild.nodeValue;
				}
				else{
					rutafoto='';
				}
				if (info.getElementsByTagName('SUMILLAFOTO').item(i).firstChild){
					sumillafoto=info.getElementsByTagName('SUMILLAFOTO').item(i).firstChild.nodeValue;
				}
				else{
					sumillafoto='';
				}
				if (info.getElementsByTagName('ALTFOTO').item(i).firstChild){
					altfoto=info.getElementsByTagName('ALTFOTO').item(i).firstChild.nodeValue;
				}
				else{
					altfoto='';
				}
				if (info.getElementsByTagName('CONECCIONDIRECTA').item(i).firstChild){
					conecciondirecta=info.getElementsByTagName('CONECCIONDIRECTA').item(i).firstChild.nodeValue;
				}
				else{
					conecciondirecta='';
				}
				if (info.getElementsByTagName('MAIL').item(i).firstChild){
					mail=info.getElementsByTagName('MAIL').item(i).firstChild.nodeValue;
				}
				else{
					mail='';
				}
				if (info.getElementsByTagName('ENLACEFORO').item(i).firstChild){
					enlaceforo=info.getElementsByTagName('ENLACEFORO').item(i).firstChild.nodeValue;
				}
				else{
					enlaceforo='';
				}
				if (info.getElementsByTagName('NOTASRELACIONADAS').item(i).firstChild){
					notasrelacionadas=info.getElementsByTagName('NOTASRELACIONADAS').item(i).firstChild.nodeValue;
				}
				else{
					notasrelacionadas='';
				}
				
				if (cod_nota!=''){
					if(titulo!='') {
						document.getElementById('titulo'+i).innerHTML=titulo;
					}
					else{
						document.getElementById('titulo'+i).innerHTML='';
					}
					if (document.getElementById('rutaFoto'+i)!=null){
						if(rutafoto!='') {
							document.getElementById('rutaFoto'+i).src=rutafoto;
						}
						else{
							document.getElementById('rutaFoto'+i).src='';
						}
					}
					if (document.getElementById('sumillaFoto'+i)!=null){
						if(sumillafoto!='') {
							document.getElementById('sumillaFoto'+i).innerHTML=sumillafoto;
						}
						else{
							document.getElementById('sumillaFoto'+i).innerHTML='';
						}
					}
					if(cabecera!='') {
						document.getElementById('cabecera'+i).innerHTML=cabecera;
					}
					else{
						document.getElementById('cabecera'+i).innerHTML='';
					}
					if(notasrelacionadas!='') {
						document.getElementById('notasRelacionadas'+i).innerHTML=notasrelacionadas;
					}
					else{
						document.getElementById('notasRelacionadas'+i).innerHTML='';
					}
					if(hora!='') {
						document.getElementById('horaNota'+i).innerHTML=hora;
					}
					else{
						document.getElementById('horaNota'+i).innerHTML='';
					}
					if(conecciondirecta!='') {
						document.getElementById('coneccion'+i).innerHTML=conecciondirecta;
					}
					else{
						document.getElementById('coneccion'+i).innerHTML='';
					}
					if(mail!='') {
						document.getElementById('compartir'+i).innerHTML=mail;
					}
					else{
						document.getElementById('compartir'+i).innerHTML='';
					}
					
					if (document.getElementById('enlaceforo'+i)==null){
						if(enlaceforo=='') {
							enlaceforo='';
						}
						
						eUL = document.getElementById("container"+i);
						eLI = document.createElement("li");
						eLI.appendChild(document.createTextNode(enlaceforo));
						eLI.setAttribute('id','enlaceforo'+i);
						eUL.appendChild(eLI);
					}
					else{
						if(enlaceforo!='') {
							document.getElementById('enlaceforo'+i).innerHTML=enlaceforo;
						}
						else{
							document.getElementById('enlaceforo'+i).innerHTML='';
						}
					}
				}
				
			}
		}
	}
	miObjetoAjaxCombo.send(null);
}

function MostrarEnVivo(num_rango){
var rango=num_rango;
if (rango==''){
	rango=0;
}
var miObjetoAjaxEncuesta = false;
miObjetoAjaxEncuesta=InstanciaAjax();
var urlAsp="/ediciononline/macro/partidos.asp?inicio_rango="+rango;
miObjetoAjaxEncuesta.open("GET",urlAsp,true);
miObjetoAjaxEncuesta.onreadystatechange=function() {
var i=0;
if (miObjetoAjaxEncuesta.readyState==4)
	{
			document.getElementById('envivo').style.display='';
			capa = miObjetoAjaxEncuesta.responseText;
			document.getElementById('envivo').innerHTML=capa;
	}

}
miObjetoAjaxEncuesta.send(null);
setTimeout("MostrarEnVivo('');LlamadaCronometros();",20000)
}

function reloj(){ 
momentoActual = new Date() ;
hora = momentoActual.getHours() ;
minuto = Right("0" + String(momentoActual.getMinutes()),2) ;
//segundo = momentoActual.getSeconds() ;
horaImprimible = hora + ":" +  minuto ;
document.getElementById('horaPortada').innerHTML = horaImprimible;
setTimeout("reloj()",60000);
} 

function Buscar(){
document.buscadorGoogle.submit();
}

function ObtenerFecha(){
fecha = new Date() ;
dia=fecha.getDate();
dia=((dia<10)?"0":"") + dia.toString();
mes=fecha.getMonth()+1;
mes=((mes<10)?"0":"") + mes.toString();
anio=fecha.getFullYear();
ObtenerFecha=anio + '-' + mes + '-' + dia;
return ObtenerFecha;
}

function UsuariosUnicos()
{
ruta="http://www.elcomercio.com.pe/edicionOnline/xml/usuarios.xml"
if (window.ActiveXObject)
{
	var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	xmlDoc.async=false;
	xmlDoc.load(ruta);
	xmlObj=xmlDoc.documentElement; 
}
else if (document.implementation && document.implementation.createDocument)
	{
		xmlDoc=document.implementation.createDocument("","",null);
		xmlDoc.async=false;
		xmlDoc.load(ruta);
		xmlObj=xmlDoc.documentElement;
		
	}
	else
	{
		alert('Your browser cannot handle this script');
	}
var usuario=xmlObj.getElementsByTagName('V').item(0).firstChild.nodeValue;
document.getElementById('usuariosUnicos').innerHTML='<strong>' +  usuario +'</strong> <a href="#">Usuarios &uacute;nicos</a>';
}

function verify() 
{ 
 if (xmlDoc.readyState != 4) 
 { 
   return false; 
 } 
}

//function UsuariosUnicos(){
//loadXML(ruta);
//var usuario=xmlObj.getElementsByTagName('V').item(0).firstChild.nodeValue;
//document.getElementById('usuariosUnicos').innerHTML='<strong>' +  usuario +'</strong> <a href="#">Usuarios &uacute;nicos</a>';
//}

function IrAudio(cod_seccion){
window.open("/ediciononline/macro/audios.asp?cod_seccion="+cod_seccion,"","width=400,height=100,scrollbars=none,top=10,left=50");
}

function PopUpCorreccion(cod_nota,titulo_nota,mail_nota){
window.open("/ediciononline/macro/correccion.asp?cod_nota="+cod_nota+"&titulo_nota="+titulo_nota+"&mail_nota="+mail_nota,"","width=630,height=400,scrollbars=no,top=100,left=350");
}

function EnviarEditor(correo){
window.open("/ediciononline/macro/enviar.asp?mail="+correo,"","width=250,height=250,scrollbars=no,top=50,left=150");
}

function IrEdicionPasada(fecha){
window.open('http://www.elcomercio.com.pe/edicionimpresa/html/' + fecha + '/ImpresaIndex.html','','toolbar=yes,scrollbars=yes,resizable=yes,height=600,width=800')
}

function PopUpRecomienda(pagina,flag) {
//flag=1 hacen click de portada de la online
//flag=2 hacen click en la nota interna
day = new Date();
id = day.getTime();
if (parseInt(flag)==2){
	URL = "/ediciononline/macro/recomienda.asp?pag=" + pagina +"&nombre1="+document.getElementById('su_nombre').value+"&nombre2="+document.getElementById('nombre_amigo').value+"&email2="+document.getElementById('email_amigo').value + "&flag=" + flag;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=200,height=80,left=80,top=30');");
	document.getElementById('Compartir').style.display='none';
	}
else{
	URL = "/ediciononline/macro/recomienda.asp?pag=" + pagina + "&flag=" + flag;
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=250,height=180,left=80,top=80');");
	}
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function fecha(){
var dtToday= new Date();
var iDay= dtToday.getDate();
var iNumberMonth= dtToday.getMonth();
var iNumberDay= dtToday.getDay();
var iFullYear= dtToday.getFullYear();
var sMonths= String("Enero    Febrero  Marzo    Abril    Mayo     Junio    Julio    Agosto   SetiembreOctubre  NoviembreDiciembre");
var sMonth= sMonths.substr((iNumberMonth*9),9);
var sDays= String("Lunes    Martes   MiércolesJueves   Viernes  Sábado   Domingo  ");
var sDay= sDays.substr(((iNumberDay-1)*9),9);
document.getElementById('hora_publicacion').innerHTML='Edición: ' + sDay + ", " + iDay + " de " +  sMonth
//document.write(sDay + ", " + iDay + " de " +  sMonth);	
}

function IrAnteriores(){
Calendar.getFullYear()>=2006 ? Calendar.setMonth(Calendar.getMonth() - 1) : Calendar.setMonth(Calendar.getMonth())
Calendar.toDOC();
}

function IrPosteriores(){
var _diaHoyCompleto=new Date();
var _anioHoy=_diaHoyCompleto.getFullYear();
Calendar.getFullYear()<=_anioHoy ? Calendar.setMonth(Calendar.getMonth() + 1) : Calendar.setMonth(Calendar.getMonth())
Calendar.toDOC();
}

