//declara variables globales
 var empresas;
 var emisorasXML;
 var flagUrchin=false;
//carrusel
var statusflag=true;
var currentItem=0;
function gomainitem(x) {
 max=0; document.formCarruselTop.segundosRestantes.value=15;
 for (i=1;i<6;i++) {
  document.getElementById('carruselIcon'+i).className='carruselOff';
  if(document.getElementById('top'+i)!=null) {
   max=i;
  } 
 }
 max-=1;
 if(x<0) x=max;
 if(x>max) x=0;
 document.getElementById('carruselContenido').style.top=-x*230+'px';
 document.getElementById('carruselIcon'+(x+1)).className='carruselOn';
 currentItem=x;
}
function ticCarruselTop() {
 if (statusflag) {
  document.formCarruselTop.segundosRestantes.value=parseInt(document.formCarruselTop.segundosRestantes.value-1);
  if (parseInt(document.formCarruselTop.segundosRestantes.value)<=0) {
   gomainitem(1+parseInt(currentItem)); 
  }
 }
 id=setTimeout("ticCarruselTop()", 1000);  
}
//escaparate
 var max_photo=10;
 var current_photo=0; 
 function goImg(x) {
  if (x<0) 
   current_photo=max_photo-1;
  else if (x>=max_photo)
   current_photo=0;
  else              
   current_photo=x;
  document.getElementById('escaparateContenido').style.left=-current_photo*157+'px';
 }
//ultimas noticias
function get_RSS(divId, section, num) {
 var html="";
 var xmlDoc=xmlLoad("/rss/"+section+".rss");
 var x=xmlDoc.getElementsByTagName("item");
 for(i=0; i< x.length && i<num; i++) {
  titulo=(x[i].childNodes[0].childNodes[0].nodeValue);
  enlace=(x[i].childNodes[1].childNodes[0].nodeValue);
  html +=   "<a href='" + enlace + 
            "' onclick=\"pageTracker._trackEvent('home','Click','viewlet_" + divId + "')\"> " + 
            titulo+"</a>";
 }
 document.getElementById(divId).innerHTML = html;
}
function xmlLoad(xmldoc) {
 var xmlRef;
 if (window.XMLHttpRequest) {
  xml=new XMLHttpRequest();
  xml.open("GET",xmldoc,false);
  xml.send(null);
  xmlRef=xml.responseXML;
 } else if (window.ActiveXObject) {
  xml=new ActiveXObject("Microsoft.XMLHTTP");
  xml.open("GET",xmldoc,false);
  xml.onreadystatechange=function() {
   if (xml.readyState==4 && xml.status==200) {
    xmlRef=xml.responseXML;
   }
  }
  xml.send(null);
 } 
 return xmlRef;
}
function loadXML(xmldoc) {
 var xmlRef;
 if (window.ActiveXObject) {
  xml=new ActiveXObject("Microsoft.XMLHTTP");
  xml.open("GET",xmldoc,false);
  xml.onreadystatechange=function() {
   if (xml.readyState==4 && xml.status==200) {
    xmlRef=xml.responseText;
   }
  }
  xml.send(null);
 } else if (window.XMLHttpRequest) {
  xml=new XMLHttpRequest();
  xml.open("GET",xmldoc,false);
  xml.send(null);
  xmlRef=xml.responseText;
 } 
 return xmlRef
}

function setCookie(c_name,value,expiredays,path,domain,secure )
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())+( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" );
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

//Para las horas en los layouts:
function getHour(fechaInput){
        //parametro fechaInput es la fecha de la nota
        var fechaHora = new Date();
        var dia1, dia2, hora = "";

        dia1 = fechaHora.getFullYear() + "-" + (fechaHora.getMonth()<9?"0"+(parseInt(fechaHora.getMonth())+1):(parseInt(fechaHora.getMonth())+1)) + "-" + (fechaHora.getDate()<10?"0"+fechaHora.getDate():fechaHora.getDate());

       // dia1 = fechaHora.getFullYear() + "-" + fechaHora.getMonth()+1 + "-" + (fechaHora.getDate()<10?"0"+fechaHora.getDate():fechaHora.getDate());
        dia2 = fechaInput.substr(0,10);
        if(dia1 == dia2)
                hora = fechaInput.substr(11,5);
        return hora;
}
function setHour(hour){
        document.write(getHour(hour));
}

/* Codigo que maneja pestañas */
function manageTabs ( arrayIdTabs,behaviourSelected,behaviourNormal )
{
	if ( arguments.length != 3 )
		return;
	this.tabs = arrayIdTabs;
	this.selected = behaviourSelected;
	this.normal = behaviourNormal;
	this.numTabs = arrayIdTabs.length;
}

manageTabs.prototype.show=function ( idTab )
{
	flag = false;
	if (idTab == "")
		return;
		
	/* pone todas las pesta–as como inactivas, oculta todo el contenido */
	if ( this.tabs.toString().indexOf(idTab) != -1 || (isNumeric(idTab) && parseInt(idTab) < this.numTabs && parseInt(idTab)>=0) )
	{
		flag = true;
	}
	if ( flag == true )
	{
		for ( i = 0; i < this.numTabs; ++i )
		{
			if ( this.tabs[i] == idTab || (isNumeric(idTab) && parseInt(idTab) == i) )
			{
				document.getElementById(this.tabs[i]+"_tab").className = this.selected;
				document.getElementById(this.tabs[i]+"_cont").style.display="block";
				document.getElementById(this.tabs[i]+"_cont").style.visibility="visible";
			}
			else
			{
				document.getElementById(this.tabs[i]+"_tab").className = this.normal;
				document.getElementById(this.tabs[i]+"_cont").style.display="none";
				document.getElementById(this.tabs[i]+"_cont").style.visibility="hidden";
			}
		}
	}
}

function isNumeric(input)
{
   return (input - 0) == input && input.length > 0;
}

/* fin del c—digo que maneja pesta–as */

function getClock() {
 var horaExacta = new Date;
 var hh=horaExacta.getHours(); if (hh<10) hh='0'+hh;
 var mm=horaExacta.getMinutes(); if (mm<10) mm='0'+mm;
 var ss=horaExacta.getSeconds(); if (ss<10) ss='0'+ss;
 document.getElementById("hora_exacta").innerHTML = hh+':'+mm+':'+ss;
 setTimeout("getClock()",1000);
}
function getfechaHoy(){
 var fechaHoy = new Date();
 var completeDate = "";
 switch(fechaHoy.getDay()){
 	case 1: completeDate = "Lunes ";
	break;
	case 2: completeDate = "Martes ";
	break;
	case 3: completeDate = "Mi&eacute;rcoles ";
	break;
	case 4: completeDate = "Jueves ";
	break;
	case 5: completeDate = "Viernes ";
	break;
	case 6: completeDate = "S&aacute;bado ";
	break;
	case 0: completeDate = "Domingo ";
	break;
 }
 completeDate += fechaHoy.getDate();
 switch(fechaHoy.getMonth()){
 	case 0: completeDate += " de enero de ";
	break;
	case 1: completeDate += " de febrero de ";
	break;
	case 2: completeDate += " de marzo de ";
	break;
	case 3: completeDate += " de abril de ";
	break;
	case 4: completeDate += " de mayo de ";
	break;
	case 5: completeDate += " de junio de ";
	break;
	case 6: completeDate += " de julio de ";
	break;
	case 7: completeDate += " de agosto de ";
	break;
	case 8: completeDate += " de septiembre de ";
	break;
	case 9: completeDate += " de octubre de ";
	break;
	case 10: completeDate += " de noviembre de ";
	break;
	case 11: completeDate += " de diciembre de ";
	break;
 }
 completeDate += fechaHoy.getFullYear();
 document.getElementById("fechaActual").innerHTML = completeDate;
}


/**
*   SLIDER   VIDEO Y ESCAPARATE
*/

scrollStep  =   2;
scrollSpeed = 100;
timerLeft   =   "";
timerRight  =   "";

function toLeft( id )
{
    document.getElementById( id ).scrollLeft = 0;
}    

/*function scrollDivLeft( id )
{
    clearTimeout( timerRight ); 
    document.getElementById( id ).scrollLeft += scrollStep;
    timerRight=setTimeout( "scrollDivLeft('" + id + "')", 2 );
}
*/

function scrollDivRight (id)
{
	if (document.getElementById(id).style.left=="")
	{
		document.getElementById(id).style.left=0;
	}
	clearTimeout( timerRight ); 
	valorInicio=parseInt(document.getElementById(id).style.left);
	if ( (valorInicio-10) > document.getElementById(id).offsetParent.offsetWidth-document.getElementById(id).offsetWidth)
	//alert (document.getElementById("escaparateContenido").offsetWidth);
	{
		document.getElementById(id).style.left=(valorInicio-10)+"px";
	}
	timerRight=setTimeout( "scrollDivRight('" + id + "')", scrollSpeed );

}
function addListener(element, type, expression, bubbling)
{
	bubbling = bubbling || false;
	if(window.addEventListener) // Standard
	{ 
		element.addEventListener(type, expression, bubbling);
		return true;
	}
	else if(window.attachEvent) // IE
	{
		element.attachEvent('on' + type, expression);
		return true;
	}
	else
		return false;
}
function scrollDivLeft (id)
{
	if (document.getElementById(id).style.left=="")
	{
		document.getElementById(id).style.left=0;
	}
	clearTimeout( timerRight );
	valorInicio=parseInt(document.getElementById(id).style.left);
	if ( (valorInicio+10)<0)
		document.getElementById(id).style.left=(valorInicio+10)+"px";
	else
	{
		document.getElementById(id).style.left=0+"px";
	}
	timerRight=setTimeout( "scrollDivLeft('" + id + "')", scrollSpeed );

}
/*function scrollDivRight( id )
{
    clearTimeout( timerLeft );
    document.getElementById( id ).scrollLeft -= scrollStep;
    timerLeft=setTimeout( "scrollDivRight('" + id + "')", 2 );
}*/
function toRight( id )
{
    document.getElementById( id ).scrollLeft = document.getElementById( id ).scrollWidth;
}
function stopMe()
{
    clearTimeout( timerRight );
    clearTimeout( timerLeft );
}
function escapaBuscador(formulario){
        var texto = formulario.q.value;
	texto = texto.toLowerCase();
	        texto = texto.replace(/á/g, "a");
		texto = texto.replace(/é/g, "e");
		texto = texto.replace(/í/g, "i");
		texto = texto.replace(/ó/g, "o");
		texto = texto.replace(/ú/g, "u");
		texto = texto.replace(/ñ/g, "n");
	formulario.q.value = texto;
	formulario.submit();
}

