﻿//OPCIONES WIDGET
function OcultarMostrarWidget(obj){	
	widgetCont=obj.parentNode.parentNode.parentNode.childNodes[1]
    estado=widgetCont.style.display
    if (estado=='none'){
        widgetCont.style.display=''
		obj.src='/images/bot_minimizar.gif'
    }else{
        widgetCont.style.display='none'
		obj.src='/images/bot_restore.gif'
    }
}

function MostrarMenu(obj){
	widgetObj=obj.parentNode.childNodes[0]
	estado=widgetObj.style.display
    if (estado=='none'){
        widgetObj.style.display=''
    }else{
        widgetObj.style.display='none'
    }   
}

function loginEmail(){
if (document.getElementById('fUser').value =='' || document.getElementById('fPass').value==''){
    alert('Datos Incompletos!')
}else{

	document.getElementById('txtemail').value = document.getElementById('fUser').value;
	document.getElementById('txtpass').value = document.getElementById('fPass').value;
	document.mailLogin.submit();
	}
}

function buscateatro(c){
	var v = c.options[c.selectedIndex].value
    if (v != "") 
    {
        document.formCine.action='http://cine.peru.com/teatro.asp?idc=1&id=' + v;
       
	document.formCine.submit();
    }
    
    
}
function buscapelicula(c){
    var v = c.options[c.selectedIndex].value
    if (v != "") 
    {
        document.formCine.action='http://cine.peru.com/pelicula.asp?idc=1&id=' + v;
        document.formCine.submit();
    }
}

function actualizaTituloWidgetRSS(idWidget, titulo){
	document.getElementById("widgetTitleText_" + idWidget).innerHTML="RSS: " + titulo
}

function AbrirCerrarObjetoMenu(obj,ubica){
    estado=obj.parentNode.childNodes[ubica].style.display
    if (estado=='none'){
        obj.parentNode.childNodes[ubica].style.display=''
    }else{
        obj.parentNode.childNodes[ubica].style.display='none'
    }
}

function capturaInfoWidgets(exep){
	widInfo='';
	//nodoPadre=document.getElementById(exep).parentNode
	colInfo='';
	filaInfo='';
	for (i=1;i<4; i++){
		rows=getWidgetsCol(i)
		iFila=1
		for (j=0;j<rows; j++){
			if (document.getElementById(aryClassElements[j].id).parentNode.style.display != 'none'){
				widInfo=widInfo + aryClassElements[j].id + ',';
				colInfo=colInfo + '' + (i) + ',';
				filaInfo=filaInfo + '' + (iFila) + ',';
				iFila++;
			}
		}
   
	}
   
	widInfo=widInfo.replace(/widget_/g,'')
	widInfo=widInfo.substring(0,widInfo.length-1)
	colInfo=colInfo.substring(0,colInfo.length-1)
	filaInfo=filaInfo.substring(0,filaInfo.length-1)
	return widInfo + '*' + colInfo + '*' + filaInfo;
}

//FIN OPCIONES WIDGET

//DOM
function getParent(element, parent){
if(typeof element=="string"){element=document.getElementById(element);};
if(!element){return null;};
var elements=[];

//if{/*string, presumes you want to locate the first parent node that is such TAG*/
parent=parent.toUpperCase();
	while(element.parentNode){
	element=element.parentNode;
	elements.unshift(element);
		if(element.nodeName && element.nodeName.toUpperCase()==parent){return elements;};
	}

return elements;
/* keep this comment to reuse freely:
http://www.fullposter.com/?1 */}


function getElementsByClassName( strClassName, obj ) {
    if ( obj.className == strClassName ) {
        aryClassElements[aryClassElements.length] = obj;
    }
    for ( var i = 0; i < obj.childNodes.length; i++ )
        getElementsByClassName( strClassName, obj.childNodes[i] );
}



//FIN DOM


//CLIMA
function verDatosClima(ciudad, grados, icono){
	document.getElementById('datoClimaCiudad').innerHTML=ciudad;document.getElementById('datoClimaTemp').innerHTML=grados + '&deg;';document.getElementById('datoClimaIcono').src=icono
}

var climaNodo1
var climaNodo2
var climaNodo3

function cargaObjetosClima(){
	climaNodo1=getParent('datoClimaCiudad', 'DIV');
	climaNodo2=getParent('datoClimaTemp', 'DIV');
	climaNodo3=getParent('datoClimaIcono', 'DIV');
}

  
function verDatosClima(infoDato1 ,infoDato2, infoDato3){
	climaNodo1[0].innerHTML=infoDato1
	climaNodo2[0].innerHTML=infoDato2
	infoDato3=infoDato3.replace("http://www.peru.com/noticias","/widgets")
	infoDato3=infoDato3.replace(".gif",".jpg")
	climaNodo3[0].innerHTML="<img src='" + infoDato3 + "' />"
}
//FIN CLIMA

//HORA FECHA

var horaNodo1
var horaNodo2
var horaNodo3
var horaNodo4
var horaNodo5

function cargaObjetosHora(){
	horaNodo1=getParent('datoHora', 'DIV');
	horaNodo2=getParent('datoSecs', 'DIV');
	horaNodo3=getParent('datoAnio', 'DIV');
	horaNodo4=getParent('datoMes', 'DIV');
	horaNodo5=getParent('datoDia', 'DIV');
	
}


 function makeArray() {
for (i = 0; i<makeArray.arguments.length; i++)
this[i + 1] = makeArray.arguments[i];
}

function mostrarFecha(){
var months = new makeArray('ener','febrero','marzo','abril','mayo',
'junio','julio','agosto','setiembre','octubre','noviembre','diciembre');
var date = new Date();
var day = date.getDate();
var month = date.getMonth() + 1;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;

horaNodo3[0].innerHTML=year
horaNodo4[0].innerHTML=months[month] 
horaNodo5[0].innerHTML=day 
}

function iniciaReloj()
{
var thetime=new Date();
//var mins=new Date();
//var secn=new Date();
 
var nhours=thetime.getHours();
var nmins=thetime.getMinutes();
var nsecn=thetime.getSeconds();
var AorP=" ";
 
if (nhours>=12)
    AorP="p.m.";
else
    AorP="a.m.";
 
if (nhours>=13)
    nhours-=12;
 
if (nhours==0)
 nhours=12;
 
if (nsecn<10)
 nsecn="0"+nsecn;
 
if (nmins<10)
 nmins="0"+nmins;
 
mostrarFecha()

horaNodo1[0].innerHTML=nhours+":"+nmins+":";
horaNodo2[0].innerHTML=nsecn
setTimeout('iniciaReloj()',1000);
 
} 

//FIN HORA FECHA

//TIPO CAMBIO
var cambioNodo1
var cambioNodo2
var cambioNodo3

function cargaObjetosCambio(){
	cambioNodo1=getParent('datoCambioCompra', 'DIV');
	cambioNodo2=getParent('datoCambioVenta', 'DIV');
	cambioNodo3=getParent('datoCambioIcono', 'DIV');
}

function verDatosCambio(infoDato1 ,infoDato2, infoDato3){
	cambioNodo1[0].innerHTML=infoDato1.slice(0,5) ;
	cambioNodo2[0].innerHTML=infoDato2.slice(0,5);
	cambioNodo3[0].innerHTML="<img src='/widgets/images/" + infoDato3 + "' />"
}

//FIN TIPO CAMBIO

//BOLSA

function verDatosBolsa(valor){
    nodoBolsa1=getParent('tablaSubieron', 'DIV');
    nodoBolsa2=getParent('tablaBajaron', 'DIV');
	nodoBolsa1[0].style.display="none";
	nodoBolsa2[0].style.display="none";
	if (valor==1) nodoBolsa1[0].style.display="";
	if (valor==2) nodoBolsa2[0].style.display="";
}

//FIN BOLSA

//HOROSCOPO
var nodosSignos = new Array();
function cargaDatosSignos(){
    for (i=1; i<13; i++){
        nodosSignos[i-1]=getParent('horoscopoSigno_' + i, 'DIV');        
	}
	//alert(nodosSignos.length)
}

function verSigno(indice){
   // alert(indice)
	for (i=0; i<12; i++){		
		nodosSignos[i][0].style.display="none"
	}
	
	nodosSignos[indice-1][0].style.display=""
}

function verSignoOLD(indice){
	for (i=1; i<13; i++){
		nodo=getParent('horoscopoSigno_' + i, 'DIV');
		nodo[0].style.display="none"
	}
	nodo=getParent('horoscopoSigno_' + indice, 'DIV');
	nodo[0].style.display=""
}

function verDatosCambio(infoDato1 ,infoDato2, infoDato3){
	cambioNodo1[0].innerHTML=infoDato1.slice(0,5) ;
	cambioNodo2[0].innerHTML=infoDato2.slice(0,5);
	cambioNodo3[0].innerHTML="<img src='/widgets/images/" + infoDato3 + "' />"
}

//FIN HOROSCOPO

//AJAX WIDGET INFO

function ActualizarInfoWidgetMovi(){
	infoWidgets=capturaInfoWidgets('')
	usuarioId=document.getElementById("hfUser").value
	//alert(infoWidgets)
	if (usuarioId != ''){
		MiPeru.ScriptProxy.ajaxRequest.ActualizaInfoPagina(infoWidgets,exitoActualizaInfo)
	//	alert(44)
	}
	setCookie('MiPeruWidgetInfo',infoWidgets,1000)
}

function exitoActualizaInfo()
{
  // alert('ok')  
}
var keySearch=""
function setClave(valor){
	ucCabecera1_ValidationSummary1.showmessagebox = 'True'
	keySearch=valor
}

function searchEnter(valor){	
	if (window.event && window.event.keyCode == 13){
		keySearch=valor
		buscarWidgets()
	}
	
}

function buscarWidgets(){
	//alert(8)
    //key=document.getElementById("cajaBuscador").value
	//alert(key)
    if (keySearch != ""){
        document.location="catalogo.aspx?key=" + keySearch
    }else{
        alert("Ingrese un texto de búsqueda!")
    }
}

function CerrarWidget(obj){
	idWidget=obj.parentNode.parentNode.parentNode.parentNode.id
		
	if (idWidget=='widget_1'){
		//alert('Las titulares de Peru.com siempre lo acompañaran...jeje')		
	}else{
		widgetObj=obj.parentNode.parentNode.parentNode.parentNode.parentNode
    	widgetObj.style.display='none'
		infoWidgets=capturaInfoWidgets(idWidget)
	
		usuarioId=document.getElementById("hfUser").value
		if (usuarioId != ''){
			MiPeru.ScriptProxy.ajaxRequest.ActualizaInfoPagina(infoWidgets,exitoActualizaInfo)
		}
		//alert(infoWidgets)
		setCookie('MiPeruWidgetInfo',infoWidgets,1000)
	}   
}

function getWidgetsCol(idCol){
	aryClassElements.length = 0;
    getElementsByClassName( 'widgetClass', document.getElementById('ul' + idCol) );
	altura=0
	return aryClassElements.length
}

function setCookie(NameOfCookie, value, expiredays) 
{
    var ExpireDate = new Date ();
    ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));


    document.cookie = NameOfCookie + "=" + escape(value) + 
    ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function getCookie(NameOfCookie)
{


    if (document.cookie.length > 0) 
    { 

        begin = document.cookie.indexOf(NameOfCookie+"="); 
        if (begin != -1) // Note: != means "is not equal to"
        { 
            begin += NameOfCookie.length+1; 
            end = document.cookie.indexOf(";", begin);
            if (end == -1) end = document.cookie.length;
            return unescape(document.cookie.substring(begin, end)); 
        } 
    }
    return null; 


}
//FIN AJAX WIDGET INFO

//NOTICIAS HOMEPAGE
var enlaceNotaPrincipal
	var enlaceNotaHome = new Array();
var enlaceNota = new Array();

function getElementsByClassHome( strClassName, obj ) {
    if ( obj.className == strClassName ) {
        nodosHome[nodosHome.length] = obj;
    }
    for ( var i = 0; i < obj.childNodes.length; i++ )
        getElementsByClassHome( strClassName, obj.childNodes[i] );
}

function getNodosHome(){
	nodosHome.length = 0;
    getElementsByClassHome( 'noticiaTextoDetalle', document.getElementById('listaNotasHome') );
	return nodosHome.length
}

function verNotaPrincipal(valor, obj){  
        for(i=0; i<5; i++){
            nodosHome[i].style.display='none'  
            document.getElementById("Cuadro" + (i+1)).style.backgroundColor='#CCCCCC';         
        }        
        document.getElementById("Cuadro" + valor).style.backgroundColor='White';
        nodosHome[valor-1].style.display=''
        enlaceNotaPrincipal=enlaceNotaHome[valor];
    }
    
//    function verNotaPrincipalOLD(valor){
//        for(i=1; i<6; i++){
//            document.getElementById("notaPortada_" + i).style.display='none'
//            document.getElementById("Cuadro" + i).style.backgroundColor='#CCCCCC';
//        }
//        document.getElementById("Cuadro" + valor).style.backgroundColor='White';
//        document.getElementById("notaPortada_" + valor).style.display=''
//        enlaceNotaPrincipal=enlaceNotaHome[valor];
//    }
    function irNotaPrincipal(){
        //alert(99)
        window.open(enlaceNotaPrincipal,"peru")
    }
    
    function windowopens(url){
	window.open(url,'futbol')
}
//FIN NOTICIAS HOMEPAGE