banners = new Array();
actual = 0;

function ini_banner(cad)
{
   banners = cad.split(',');
   poner_banner(banners[actual]);
   cuadros_banner();
   cuadro_color();
   move = setTimeout("next_banner()",8000);
}


function poner_banner(cad)
{
  
  
 var divImg = document.getElementById('banner');
 tmp = new Array();
 tmp = cad.split('||');
 divImg.style.backgroundImage = 'url('+tmp[0]+')';
 divImg.style.cursor='pointer';
 addEvento(divImg,'click',function(){location.href=tmp[1];});

  //var divImg = document.getElementById('banner');
  //divImg.style.backgroundImage = 'url('+cad+')';
  //tmp = new Array();
  //tmp = cad.split('||');
  //var divTxt  = document.getElementById('txt_banner');
  //divImg.style.backgroundImage = 'url('+tmp[0]+')';
  //divTxt.innerHTML=tmp[1];
}

function cuadros_banner()
{
 var divImg = document.getElementById('navegacion');
 
 
 //left=590;
 //divs ='<div style="position:absolute;top:325px;left:570px;width:14px;height:14px;float:left; background-image:url(\'img/arrow-izq.gif\');cursor:pointer;background-repeat:no-repeat;" onclick="javascript:back_banner();"></div>';
 left=530;
 divs ='<div style="position:absolute;top:325px;left:510px;width:14px;height:14px;float:left; background-image:url(\'img/arrow-izq.gif\');cursor:pointer;background-repeat:no-repeat;" onclick="javascript:back_banner();"></div>';
 for(i=0;i<5;i++)
 {
   n = i+1; left +=4; 
   divs +='<div id="cuadro-'+i+'" style="position:absolute;top:325px;left:'+left+'px;float:left;font-family:Verdana;font-size:10px; width:13px;height:13px;border:1px solid #000;text-align:center;cursor:pointer;" onclick="javascript:aqui_banner('+i+');">'+n+'</div>' ;
   left +=14; 
 }
 //divs +='<div   style="position:absolute;top:325px;width:14px;height:14px;float:left;left:660px;background-image:url(\'img/arrow-der.gif\');cursor:pointer;background-repeat:no-repeat;" onclick="javascript:next_banner();"></div>';
 divs +='<div   style="position:absolute;top:325px;width:14px;height:14px;float:left;left:630px;background-image:url(\'img/arrow-der.gif\');cursor:pointer;background-repeat:no-repeat;" onclick="javascript:next_banner();"></div>';
 divImg.innerHTML=divs;
}

function aqui_banner(i)
{
   clearTimeout(move);
   actual = i;
   poner_banner(banners[actual]);
   cuadro_color();
   move =setTimeout("next_banner()",12000);
}

function next_banner()
{
   clearTimeout(move);
   actual++;
   if(actual > banners.length -1){actual =0;}
   poner_banner(banners[actual]);
   cuadro_color();
   move =setTimeout("next_banner()",12000);
} 

function back_banner()
{
  actual--;
  if(actual < 0){actual = banners.length -1;}
  poner_banner(banners[actual]);
  cuadro_color();
}

function cuadro_color()
{
  for(i=0;i<5;i++)
  {
      var color='';
      if(i == actual){color='#0099ff';}
     document.getElementById('cuadro-'+i).style.backgroundColor=color;
  }
}


function stopEvent()
{
    var e = window.event;
    if(!e) e = window.Event;
    e.cancelBubble = true;								    
    e.returnValue = false;
    return false;
}

 
function cambiarClase(color,id) 
{
  document.getElementById(id).style.color=color;
} 

function ini_noticia(cad)
 {
    var tmp=cad.split(',');
    var tmp1 = tmp[0].split('||');
    var tmp2 = tmp[1].split('||');
    var tmp3 = tmp[2].split('||');
    var divImg1=document.getElementById('nimg1');
    var divImg2=document.getElementById('nimg2');
    var divImg3=document.getElementById('nimg3');
    var divTxt1=document.getElementById('ntxt1');
    var divTxt2=document.getElementById('ntxt2');
    var divTxt3=document.getElementById('ntxt3');
    
    divImg1.style.backgroundImage='url('+tmp1[0]+')';
    divTxt1.innerHTML='<a href="'+tmp1[2]+'" style="text-decoration:none;color:black;">'+tmp1[1]+'</a>';
    addEvento(divImg1,'click',function(){newWin(tmp1[2]);});
    
    divImg2.style.backgroundImage='url('+tmp2[0]+')';
    divTxt2.innerHTML='<a href="'+tmp2[2]+'" style="text-decoration:none;color:black;">'+tmp2[1]+'</a>';
    addEvento(divImg2,'click',function(){newWin(tmp2[2]);});
    
    divImg3.style.backgroundImage='url('+tmp3[0]+')';
    divTxt3.innerHTML='<a href="'+tmp3[2]+'" style="text-decoration:none;color:black;">'+tmp3[1]+'</a>';
    addEvento(divImg3,'click',function(){newWin(tmp3[2]);});
 }
 
 function addEvento(elemento, evento, funcion) 
 {
    if (elemento.addEventListener) {elemento.addEventListener(evento, funcion, false);} 
    else {elemento.attachEvent("on"+evento, funcion);}
 }
 
function ini_evento(cad)
 {
    var tmp = cad.split(';;');
    var fecha = new Array();
    var info = new Array();
    var enlace = new Array();
    var no_repetidos = new Array();
    var fecha_no_repetida = new Array();
    var x=0;
    
    for(i=0;i<tmp.length;i++)
    {
       var tmp1 = tmp[i].split('||');
       //alert(tmp1[2]);
       fecha[i] = tmp1[0];
       info[i] = tmp1[1];
       enlace[i] = tmp1[2];
       //alert(enlace[i]);
    }    
    
    for(i=0;i<fecha.length;i++)
    {
        if(!(fecha[i] in no_repetidos)){no_repetidos[fecha[i]] =1;fecha_no_repetida[x++]=fecha[i];}
	else {no_repetidos[fecha[i]]+=1;}
    }
    anterior =0;
    for(x=0;x<fecha_no_repetida.length;x++)
   {
	rowspan=0;
	if(x == 0){id=1;}
	else
	{id = no_repetidos[fecha_no_repetida[x-1]]+anterior;}
	anterior=id;
	if(no_repetidos[fecha_no_repetida[x]] > 1){rowspan=no_repetidos[fecha_no_repetida[x]];}
	addCell(id,fecha_no_repetida[x]+"<br>",rowspan,'fecha');
    }
    
    for(i=0;i<info.length;i++)
    {
       id=i+1;
       addCell(id,'<a href="'+enlace[i]+'">'+info[i]+'</a>',0,'ev');
    }
    
    
 }
 
 function addCell(id,cad,rowspan,clase)
{
  var row = document.getElementById('tr'+id);
  var newCell = document.createElement("td");
  if(rowspan > 1){newCell.setAttribute('rowSpan', rowspan);}
  newCell.setAttribute('class', clase);
  newCell.setAttribute('className', clase);
  //newCell.appendChild( document.createTextNode(cad) );
  newCell.innerHTML=cad;
  row.appendChild(newCell);
}

function newWin(url) 
{
 window.location.href=url;
}

function newWin1(url) 
{
newWin = window.open(url,"_blank","top=0,left=0,height="+screen.availHeight+",width="+screen.availWidth+",location,scrollbars,directories,menubar,resizeable,status,toolbar");
}


function openPopup(Nombre,URL,Ancho,Alto)
{
var x=screen.width
var y=screen.height
var xx=(x-Ancho)/2
var yy=(y-Alto)/2
var Complemento="width="+Ancho+",height="+Alto+",top="+yy+",left="+xx
window.open(URL,Nombre,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,"+Complemento)
}

function popup(URL,lAncho,lAlto)
{
 var y0=screen.height
 var x0=screen.width
 var xx=(x0-lAncho)/2
 var yy=(y0-lAlto)/2
 var Complemento1="width="+lAncho+",height="+lAlto+",top="+yy+",left="+xx

 window.open(URL,"_blank","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,"+Complemento1)
} 

function popupHtml(url)
{
 var iframe = document.getElementById('contactArea');
 iframe.src=url;
 centerPopup();
 loadPopup();
}

