/*                                                                                                                                                      
Copyright (c) 2006, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 0.1
*/ 
/**
 * @module Ssoft
 * @title  SSOFT CALENDAR Global
 */
    YAHOO.namespace("container");
    YAHOO.namespace("search.calendar");
    YAHOO.namespace("search.calendarF");
    YAHOO.namespace("target.select");
    YAHOO.util.Event.addListener(window, "load", init); 

function init()
{
    var date            = new Date();
    var fechaSalida     = new Date();
    var fechaRetorno    = new Date();
    
    this.year   = date.getFullYear();	  
    this.month  = ((date.getMonth() + 1) < 10) ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    this.day    = (date.getDate() < 10) ? "0" + date.getDate() : date.getDate();
    
    this.minDate = this.month + DATE_DELIMITER + this.day + DATE_DELIMITER + this.year;
    this.maxDate = this.month + DATE_DELIMITER + this.day + DATE_DELIMITER + (parseInt(this.year) + 1);
                
    YAHOO.search.calendar.call = new YAHOO.widget.CalendarGroup("call","Calendar",{close:true,
                                                                                        mindate: this.minDate,
                                                                                        maxdate: this.maxDate});       
                 
    YAHOO.search.calendar.call.select(date);
    YAHOO.search.calendar.call.selectEvent.subscribe(handleSelect, YAHOO.search.calendar.call, true);                                
    YAHOO.search.calendar.call.render();   
    
    YAHOO.search.calendarF.call = new YAHOO.widget.CalendarGroup("call","CalendarF",{close:true, pages:1, maxdate: this.minDate
                                                                                        });       
                 
    YAHOO.search.calendarF.call.select(date);
    YAHOO.search.calendarF.call.selectEvent.subscribe(handleSelectF, YAHOO.search.calendarF.call, true);                                
    YAHOO.search.calendarF.call.render();    
}

function handleClosed()
{
    document.body.appendChild(YAHOO.container.panelName);
    document.body.appendChild(YAHOO.container.holder);
    
    YAHOO.container.holder.style.display    = "none";
    YAHOO.container.panelName.style.display = "none";
}

/*///////////////////////////////////////////////////////////////
/	Autor 			: Faustino Posas
/	Fecha 			: 02 de Enero de 2009
/	Funcion name 	: showCalendar()
/	Proposito 		: Muestra el calendario y setea los valores en el control que es pasado como parametro
/	Parametros		: control : El ID del control que será el contenedor de la fecha
/	Return			: None
*////////////////////////////////////////////////////////////////	
function showCalendarRango(control, fechaini, fechafin)
{
    var cBrowser        = new BROWSER();  
                      
    YAHOO.target.select = document.getElementById(control);
    
    var date            = new Date();
    
    this.year   = date.getFullYear();	  
    this.month  = ((date.getMonth() + 1) < 10) ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    this.day    = (date.getDate() < 10) ? "0" + date.getDate() : date.getDate();
    
    this.minDate = this.month + DATE_DELIMITER + this.day + DATE_DELIMITER + this.year;                

    YAHOO.search.calendar.call.cfg.setProperty("mindate", this.minDate);
            
    var txtFechaSalida  = document.getElementById(fechaini);
    var txtFechaRetorno = document.getElementById(fechafin);
    var fechaSalida     = new Date();
    var fechaRetorno    = new Date();

    var selFechaSaldia  = "";
    var selFechaRetorno = "";
            
    if (txtFechaSalida.value.trim() != "")
    {
        fechaSalida.setDateTime(txtFechaSalida.value);
        selFechaSaldia = fechaSalida.format(DATE_SHORT_FORMAT, DATE_FORMAT_MDY);
        YAHOO.search.calendar.call.addRenderer(selFechaSaldia, YAHOO.search.calendar.call.renderCellStyleSelected);                    
        
        if (YAHOO.target.select.id == fechafin)
        {
            YAHOO.search.calendar.call.cfg.setProperty("mindate", txtFechaSalida.value);
        }
        else
        {
            YAHOO.search.calendar.call.cfg.setProperty("mindate", this.minDate);
        }
    }
    
    if (txtFechaRetorno.value.trim() != "")
    {
        fechaRetorno.setDateTime(txtFechaRetorno.value);
        selFechaRetorno = fechaRetorno.format(DATE_SHORT_FORMAT, DATE_FORMAT_MDY)
        YAHOO.search.calendar.call.addRenderer(selFechaRetorno, YAHOO.search.calendar.call.renderCellStyleSelected);                    
    }
}
function showCalendar(control)
{
    YAHOO.target.select=document.getElementById(control)
    YAHOO.search.calendar.call.oDomContainer.style.left=getAbsoluteLeft(control) + "px";
    YAHOO.search.calendar.call.oDomContainer.style.top=(getAbsoluteTop(control) + YAHOO.target.select.offsetHeight) + "px";
    YAHOO.search.calendar.call.oDomContainer.style.display='block';     
}
/*///////////////////////////////////////////////////////////////
/	Autor 			: Faustino Posas
/	Fecha 			: 02 de Enero de 2009
/	Funcion name 	: handleSelect()
/	Proposito 		: Es llamada cuando es selecionada una fecha en el calendario
/	Parametros		: type : 
                      args : Array que contiene las fechas seleccionadas
                      obj  :
/	Return			: None
*////////////////////////////////////////////////////////////////	
function handleSelect(type,args,obj) {
	var dates   = args[0]; 
	var date    = dates[0];

    this.year   = date[0];	  
    this.month  = (date[1] < 10) ? "0" + date[1] : date[1];
    this.day    = (date[2] < 10) ? "0" + date[2] : date[2];
                    

    switch (DATE_FORMAT_DEFAULT)
    {
        case DATE_FORMAT_YMD:
            YAHOO.target.select.value = this.year + DATE_DELIMITER + this.month + DATE_DELIMITER + this.day;
            break;
            
        case DATE_FORMAT_MDY:
            YAHOO.target.select.value = this.month + DATE_DELIMITER + this.day + DATE_DELIMITER + this.year;
            break;
            
        case DATE_FORMAT_DMY:
            YAHOO.target.select.value = this.day + DATE_DELIMITER + this.month + DATE_DELIMITER + this.year;
            break;
    }                                        
    
    YAHOO.search.calendar.call.hide();
}
function handleSelectF(type,args,obj) 
{
	var dates   = args[0]; 
	var date    = dates[0];

    this.year   = date[0];	  
    this.month  = (date[1] < 10) ? "0" + date[1] : date[1];
    this.day    = (date[2] < 10) ? "0" + date[2] : date[2];
                    

    switch (DATE_FORMAT_DEFAULT)
    {
        case DATE_FORMAT_YMD:
            YAHOO.target.select.value = this.year + DATE_DELIMITER + this.month + DATE_DELIMITER + this.day;
            break;
            
        case DATE_FORMAT_MDY:
            YAHOO.target.select.value = this.month + DATE_DELIMITER + this.day + DATE_DELIMITER + this.year;
            break;
            
        case DATE_FORMAT_DMY:
            YAHOO.target.select.value = this.day + DATE_DELIMITER + this.month + DATE_DELIMITER + this.year;
            break;
    }                                        
    YAHOO.search.calendarF.call.hide();
}

function showCalendarF(control)
{
    YAHOO.target.select=document.getElementById(control)
    YAHOO.search.calendarF.call.oDomContainer.style.left=getAbsoluteLeft(control) + "px";
    YAHOO.search.calendarF.call.oDomContainer.style.top=(getAbsoluteTop(control) + YAHOO.target.select.offsetHeight) + "px";
    YAHOO.search.calendarF.call.oDomContainer.style.display 	    = 'block';
}
var syncyear = function(type)
{       
    YAHOO.util.Dom.get("yearselect").value = parseInt(myCal.pages[0].getDateByCellId("newcalelement_0_cell17").getFullYear());
}  

var changeYear = function()
{
    YAHOO.search.calendarF.call.setYear(parseInt(YAHOO.util.Dom.get("yearselect").value));
    YAHOO.search.calendarF.call.render();
}
 
var nextyear = function(e)
{
    YAHOO.search.calendarF.call.nextYear();
}

