/* hides <select> and <applet> objects (for IE only) */

/*
* Funcion para cambiar el css dependiendo del dia de la semana que sea.
* Autor: Jose Escobar Belmonte
*/

dia=3;

function resetFormNew()
{
 document.forms[0].reset();
 var d=new Date();
 var valor=d.getDay()%3;
 if (dia!=valor)
 {
 document.getElementById('estilo').href="/default/css/default" + valor + ".css";
 dia=valor;
 }
}

function resetForm()
{
 document.forms[0].reset();
}

function setMid(mid)
{
  var action = document.forms[0].action;
  document.forms[0].action = action + "?smid=" + mid;
}

function goMid(mid)
{
  var action = document.forms[0].action;
  var index = action.indexOf('?');
  if (index != -1)
  {
    action = action.substring(0, index) + "?xmid=" + mid;
  }
  else
  {
    action = action + "?xmid=" + mid;   
  }
  document.forms[0].action = action;
  document.forms[0].submit();
}

function goTopic(topic)
{
  var action = document.forms[0].action;
  var index = action.indexOf('?');
  if (index != -1)
  {
    action = action.substring(0, index) + "?topic=" + topic;
  }
  else
  {
    action = action + "?topic=" + topic;
  }
  document.forms[0].action = action;
  document.forms[0].submit();
}

var jscalendarIe = document.all;
var buttonPushed = false;

function jsHideElement(elmID, overDiv)
{
  if (jscalendarIe)
  {
    for( i = 0; i < document.all.tags( elmID ).length; i++)
    {
      obj = document.all.tags( elmID )[i];
      if( !obj || !obj.offsetParent)
        continue;

      // Find the element's offsetTop and offsetLeft relative to the BODY tag.
      objLeft   = obj.offsetLeft;
      objTop    = obj.offsetTop;
      objParent = obj.offsetParent;

      while( objParent.tagName.toUpperCase() != "BODY" )
      {
        objLeft  += objParent.offsetLeft;
        objTop   += objParent.offsetTop;
        objParent = objParent.offsetParent;
      }

      objHeight = obj.offsetHeight;
      objWidth = obj.offsetWidth;

      // Find the element's offsetTop and offsetLeft relative to the BODY tag.
      overDivLeft   = overDiv.offsetLeft;
      overDivTop    = overDiv.offsetTop;
      overDivParent = overDiv.offsetParent;

      while (overDivParent.tagName.toUpperCase() != "BODY")
      {
        overDivLeft  += overDivParent.offsetLeft;
        overDivTop   += overDivParent.offsetTop;
        overDivParent = overDivParent.offsetParent;
      }

      if ((overDivLeft + overDiv.offsetWidth ) <= objLeft);
      else if(( overDivTop + overDiv.offsetHeight ) <= objTop);
      else if( overDivTop >= ( objTop + objHeight ));
      else if( overDivLeft >= ( objLeft + objWidth ));
      else obj.style.visibility = "hidden";
    }
  }
}

/*
* shows <select> and <applet> objects (for IE only)
*/
function jsShowElement(elmID)
{
  if (jscalendarIe)
  {
    for (i = 0; i < document.all.tags( elmID ).length; i++)
    {
      obj = document.all.tags( elmID )[i];

      if (!obj || !obj.offsetParent)
        continue;

      obj.style.visibility = "";
    }
  }
}

function jsHideElement2(elmID, overDiv)
{
  if (jscalendarIe)
  {
    for (i = 0; i < document.all.tags( elmID ).length; i++)
    {
      obj = document.all.tags( elmID )[i];

      if (!obj || !obj.offsetParent)
        continue;

      obj.style.visibility = "hidden";
    }
  }
}

//toggles layer visibility on and off
function show(id)
{
  var element = document.getElementById(id);
  if (element != null)
  {
    element.style.visibility = "visible";
  }
}

function hide(id)
{
  var element = document.getElementById(id);
  if (element != null)
  {
    element.style.visibility = "hidden";
  }
}

function push(id)
{
  var element = document.getElementById(id);
  if (element != null)
  {
    if (element.style.visibility == "hidden") 
    {
      show(id);
      jsHideElement2('select', document.getElementById(id));
    }
    else
    {
      hide(id);    
      jsShowElement('select');
    }
    buttonPushed = true;
  }
}

function pushOutside(id)
{
  if (!buttonPushed)
  {
    hide(id);
    jsShowElement('select');
  }
  buttonPushed = false;
}

function checkMaxLength(field, limit)
{
  if (field.value.length >= limit) field.value = field.value.substring(0, limit - 1);
}

function popUp(URL) 
{
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=580,height=550');");
}

function ChangeUrl(formulaire)
{
  if (formulaire.ListeUrl.selectedIndex != 0)
  {
    location.href = formulaire.ListeUrl.options[formulaire.ListeUrl.selectedIndex].value;
  }
  else 
  {
    alert('Tienes que elegir un destino.');
  }
}
