/*  
Jose Manuel Gonzalez
07/10/2006

Estas funciones fueron sacadas del sitio web de JS Calendar
Ayudan en el manejo de los calendarios

 */

var oldLink = null;
// code to change the active stylesheet
function setActiveStyleSheet(link, title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}

// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked)
  {
  	/* Si se necesita que no se cierre con un click, entonces comentar esta linea */
    cal.callCloseHandler();
  }
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks on the "Close" button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  _dynarch_popupCalendar = null;
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id, format, showsTime, nombreBoton, CerrarCalendario) {
    
    var closeCalendario = closeHandler;
    if (typeof CerrarCalendario == "function") 
    {
    	closeCalendario = CerrarCalendario;
    }


		Calendar.setup({
              inputField    : id,
              button        : nombreBoton,
              align         : "Br",
              yearStep			: 1,
              daFormat			: format,
              ifFormat			: format,
              showsTime			: showsTime,
              onClose				: closeCalendario
              
            });

  return false;
}

