//-------------------------------------------------
// Rutinas javascript 
// Sitio > www.SWNoticias.com.ar
// Webmaster > Juan Andrés De Giuseppe 
// Email > webmaster@SWNoticias.com.ar
// Fecha > 07/07/2001
//-------------------------------------------------

var trailLength = 5;
var path = "sw-loguito.gif";  
var isIE = false;
var isNav = false;
var range = "all.";
var style = ".style";
var i, d = 0;
var topPix = ".pixelTop";
var leftPix = ".pixelLeft";
var images, storage;

function initTrail() 
{
  images = new Array();
  for (i = 0; i < parseInt(trailLength); i++) 
  {
    images[i] = new Image();
    images[i].src = path;
  }

  storage = new Array(); 

  for (i = 0; i < images.length * 3; i++) 
    storage[i] = 0;

  for (i = 0; i < images.length; i++)          // make divs for IE and layers for Navigator
    (isIE) ? document.write('<div id="obj' + i + '" style="position: absolute; z-Index: 100; height: 0; width: 0"><img src="' + images[i].src + '"><\/div>') : document.write('<layer name="obj' + i + '" width="0" height="0" z-index="100"><img src="' + images[i].src + '"><\/layer>');
  
  trail();
}

function trail() 
{
  for (i = 0; i < images.length; i++) 
  {
    eval("document." + range + "obj" + i + style + topPix + "=" + storage[d]);
    eval("document." + range + "obj" + i + style + leftPix + "=" + storage[d+1]);
    d = d + 2;
  }

  for (i = storage.length; i >= 2; i--)
    storage[i] = storage[i-2];

  d = 0;
  clearTimeout(timer);
  var timer = setTimeout("trail()", 5);
}

function processEvent(e) 
{ 
  if (isIE) 
  {
    storage[0] = window.event.y+document.body.scrollTop + 15;
    storage[1] = window.event.x+document.body.scrollLeft + 7;
  } 
  else 
  {
    storage[0] = e.pageY + 15;
    storage[1] = e.pageX + 7;
  }
}

function activarRastro() 
{
  if (rastroChecked == "CHECKED")
  {
    if (document.layers) 
      isNav = true, range = "layers.", style = "", topPix = ".top", leftPix = ".left";
    else if (document.all) 
      isIE = true;

    if (isNav) 
      document.captureEvents(Event.MOUSEMOVE);

    if (isIE || isNav) 
    {
      initTrail();
      document.onmousemove = processEvent;
    }
  }
}

//-------------------------------------------------

function mOvr(src,clrOver) 
{
  if (!src.contains(event.fromElement)) 
  {
    src.style.cursor = 'hand';
    if (clrOver == 1)
      src.bgColor = "#003399";
    else
      src.bgColor =  "#6699FF";
  }
}

function mOut(src,clrIn) 
{
  if (!src.contains(event.toElement)) 
  {
    src.style.cursor = 'default';
    if (clrIn == 1)
      src.bgColor = "#0066CC";
    else
      src.bgColor =  "#003399";
  }
}

function mClk(src) 
{
  if(event.srcElement.tagName=='TD')
    src.children.tags('A')[0].click();
}

//-------------------------------------------------

function cuentaRegresiva(fecha, evento, url)
{
  now = new Date(); 
  ann = new Date(fecha); 
  ann - now 

  seconds = Math.round((ann - now) / 1000);
  minutes = Math.round(seconds / 60); 
  hours = Math.round(minutes / 60); 
  days = Math.round(hours / 24); 

  if (days >= -1)
  {
    document.write("<tr align='left' valign='middle' bgcolor='#98CCFF'>");
    document.write("<td bgcolor='#0066CC' height='6'>");
    document.write("<table width='100%' border='0'>");
    document.write("<tr><td height='7'>");
    document.write("<div align='center'><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#FFFF99'><b>");
  
    if (days == -1)
      document.write("HOY</b></font></div>");
    else
      document.write(days + "</b> d&iacute;as</font></div>");
  
    document.write("</td></tr><tr><td height='2'>");
    document.write("<div align='center'><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#FFFFFF'>");

	if (typeof(url) == "undefined")
	  document.write(evento);
	else  
	  document.write("<a href='" + url + "'>" + evento + "</a>");

	document.write("</font></div>");
    document.write("</td></tr></table></td>");
	document.write("</tr>");
  }
}

//-------------------------------------------------

function menu(sLink, sTexto)
{
  colorMenu = 1;
  document.write("<tr align='left' valign='middle' bgcolor='#98CCFF'>");
  linea = "";
  linea += "<td onClick='mClk(this);' onMouseOut='mOut(this, colorMenu);'";
  linea += " onmouseover='mOvr(this, colorMenu);' vAlign='left' width='171' bgcolor='#0066CC' height='12'>";
  linea += " <a style='COLOR: rgb(255,255,153); TEXT-DECORATION: none' href='";
  linea += sLink + "'><font face='Verdana' size='1'>";
  linea += sTexto + "</font></a></td>";
  document.write(linea);
  document.write("</tr>");
}

//-------------------------------------------------

function pregunta(sLink, sRespuesta)
{
  if (typeof(iPos) == "undefined")
    iPos = 1;                             //Inicializo variable

  colorPregunta = 2;
  aRespuestas[iPos] = sRespuesta;
  document.write("<tr align='left' valign='middle' bgcolor='#98CCFF'>");
  linea = "";
  linea = linea + "<td onClick='alert(aRespuestas[" + iPos + "]);' onMouseOut='mOut(this, colorPregunta);'"; 
  linea = linea + " onMouseOver='mOvr(this, colorPregunta);' valign='left' bgcolor='#003399'";
  linea = linea + " height='12' style='padding-left: 6; padding-top: 1; padding-bottom: 1' colspan='2'> ";
  linea = linea + " <a style='COLOR: rgb(255,255,153); TEXT-DECORATION: none' href='#preguntas' </a>";
  linea = linea + " <font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#FFFFFF'>";
  linea = linea + sLink + "</font></td>";
  document.write(linea);
  document.write("</tr>");
  iPos++;
}

//-------------------------------------------------

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, expires, path, domain, secure) 
{
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

function updateCookie () 
{
  var expdate = new Date ();
  expdate.setTime (expdate.getTime() + (365 * 24 * 60 * 60 * 1000)); // un año
  SetCookie ("Rastro", document.Form.rastro.checked, expdate);
  window.location = ("index.htm");
}

function getCookieData () 
{
  rastroChecked = (GetCookie('Rastro') == "true" ) ? "CHECKED" : "";
  ultimaVisita = GetCookie('ultimaVisita');
  anteriorVisita = GetCookie('anteriorVisita');
}

//-------------------------------------------------

function fijarFecha () 
{
  var expdate = new Date ();
  var hoy = new Date ();
  expdate.setTime (expdate.getTime() + (365 * 24 * 60 * 60 * 1000)); // un año

  SetCookie ("anteriorVisita", ultimaVisita, expdate);
  SetCookie ("ultimaVisita", hoy, expdate);
}

//-------------------------------------------------


//-------------------------------------------------

// Usado en la cuenta regresiva / 10 minutos
setTimeout("history.go(0);", 1000 * 60 * 10);  

// Fijo texto por defecto en barra de estado
window.defaultStatus = 'La página de Silbido - Noticias diarias de Star Wars';

// Llamo a la rutina para levantar las cookies
getCookieData();

// Muestra rastro del mouse (si está habilitado)
activarRastro(); 

//-------------------------------------------------
