// CONSTRUCTOR for the CalendarPopup Object
function CalendarPopup_bJ() {
	var c;
	if (arguments.length>0) {
		c = new PopupWindow(arguments[0]);
		}
	else {
		c = new PopupWindow();
		c.setSize(150,175);
		}
	c.offsetX = -152;
	c.offsetY = 25;
	c.autoHide();
	// Calendar-specific properties
	c.monthNames = new Array("Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre");
	c.monthAbbreviations = new Array("Jan","Féb","Mar","Avr","Mai","Jui","Jui","Aoû","Sep","Oct","Nov","Déc");
	c.dayHeaders = new Array("D","L","M","M","J","V","S");
	c.returnFunction = "CP_tmpReturnFunction_bJ";
	c.returnMonthFunction = "CP_tmpReturnMonthFunction";
	c.returnQuarterFunction = "CP_tmpReturnQuarterFunction";
	c.returnYearFunction = "CP_tmpReturnYearFunction";
	c.weekStartDay = 1;
	c.isShowYearNavigation = false;
	c.displayType = "date";
	c.disabledWeekDays = new Object();
	c.disabledDatesExpression = "";
	c.yearSelectStartOffset = 2;
	c.currentDate = null;
//	c.todayText="Aujourd'hui";
	c.todayText="";
	c.cssPrefix="";
	c.isShowNavigationDropdowns=false;
	c.isShowYearNavigationInput=false;

   c.FormName     = null ;  
   c.CHP_affJour  = null ;
   c.CHP_affJourJusquau  = null ;
   c.CHP_affJourDu = null ;
   c.CHP_affJourAu  = null ;
   c.CHP_affJourLe1  = null ;
   c.CHP_affJourLe2  = null ;
   c.CHP_affJourLe3  = null ;
   c.CHP_hiddenJour  = null ;
   c.CHP_hiddenJourJusquau  = null ;
   c.CHP_hiddenJourDu = null ;
   c.CHP_hiddenJourAu  = null ;
   c.CHP_hiddenJourLe1  = null ;
   c.CHP_hiddenJourLe2  = null ;
   c.CHP_hiddenJourLe3  = null ;    

  
  
	window.CP_calendarObject = null;
	window.CP_targetInput = null;
	window.CP_targetInputVisible = null;
	window.CP_dateFormat = "dd/MM/yyyy";
	window.CP_dateFormatVisible = "EE dd MMM yyyy";	

    c.setChampsDestination = setChampsDestination;
	c.copyMonthNamesToWindow = CP_copyMonthNamesToWindow;
	c.setReturnFunction = CP_setReturnFunction;
	c.setReturnMonthFunction = CP_setReturnMonthFunction;
	c.setReturnQuarterFunction = CP_setReturnQuarterFunction;
	c.setReturnYearFunction = CP_setReturnYearFunction;
	c.setMonthNames = CP_setMonthNames;
	c.setMonthAbbreviations = CP_setMonthAbbreviations;
	c.setDayHeaders = CP_setDayHeaders;
	c.setWeekStartDay = CP_setWeekStartDay;
	c.setDisplayType = CP_setDisplayType;
	c.setDisabledWeekDays = CP_setDisabledWeekDays;
	c.addDisabledDates = CP_addDisabledDates;
	c.addBankHolyday = CP_addBankHolyday;
	c.setYearSelectStartOffset = CP_setYearSelectStartOffset;
	c.setTodayText = CP_setTodayText;
	c.showYearNavigation = CP_showYearNavigation;
	c.showCalendar = CP_showCalendar;
	c.hideCalendar = CP_hideCalendar;
	c.getStyles = getCalendarStyles;
	c.refreshCalendar = CP_refreshCalendar;
	c.getCalendar = CP_getCalendar;
	c.select = CP_select_bJ;
	c.setCssPrefix = CP_setCssPrefix;
	c.showNavigationDropdowns = CP_showNavigationDropdowns;
	c.showYearNavigationInput = CP_showYearNavigationInput;
	c.copyMonthNamesToWindow();
	// Return the object
	return c;
	}


// Attribue les champs de destination des dates choisies
function setChampsDestination(FormName, // Nom du formulaire
                              CHP_affJour,CHP_affJourJusquau,CHP_affJourDu,CHP_affJourAu,
                              CHP_affJourLe1,CHP_affJourLe2,CHP_affJourLe3,// Noms des champs d'affichage
                              CHP_hiddenJour,CHP_hiddenJourJusquau,CHP_hiddenJourDu,CHP_hiddenJourAu,
                              CHP_hiddenJourLe1,CHP_hiddenJourLe2,CHP_hiddenJourLe3)// Noms des champs de stockage des dates
{

  this.FormName     = FormName ;  
   this.CHP_affJour  = CHP_affJour ;
   this.CHP_affJourJusquau  = CHP_affJourJusquau ;
   this.CHP_affJourDu = CHP_affJourDu ;
   this.CHP_affJourAu  = CHP_affJourAu ;
   this.CHP_affJourLe1  = CHP_affJourLe1 ;
   this.CHP_affJourLe2  = CHP_affJourLe2 ;
   this.CHP_affJourLe3  = CHP_affJourLe3 ;
   this.CHP_hiddenJour  = CHP_hiddenJour ;
   this.CHP_hiddenJourJusquau  = CHP_hiddenJourJusquau ;
   this.CHP_hiddenJourDu = CHP_hiddenJourDu ;
   this.CHP_hiddenJourAu  = CHP_hiddenJourAu ;
   this.CHP_hiddenJourLe1  = CHP_hiddenJourLe1 ;
   this.CHP_hiddenJourLe2  = CHP_hiddenJourLe2 ;
   this.CHP_hiddenJourLe3  = CHP_hiddenJourLe3 ;  
}

// Temporary default functions to be called when items clicked, so no error is thrown
function CP_tmpReturnFunction_bJ(y,m,d) 
{
    if (window.CP_targetInput!=null) 
    {
       var b_multiHoraire=false;
       var dt = new Date(y,m-1,d,0,0,0);
        if (window.CP_calendarObject!=null) 
        { 
            window.CP_calendarObject.copyMonthNamesToWindow(); 
        }


        if (y==0 && m == 0 && d== 0 )
        {              
            window.CP_targetInput.value = '';
            window.CP_targetInputVisible.value ='';
        }
        else
        {
            window.CP_targetInput.value = formatDate(dt,window.CP_dateFormat);
            window.CP_targetInputVisible.value = formatDate(dt,window.CP_dateFormatVisible);        
        }
        affEcranControle(window.CP_targetInput) ;
        nombrePixelDate(window.CP_targetInputVisible) ;
            
        if ( window.CP_targetInput.id == this.CHP_hiddenJour )
        {
            document.forms[this.FormName].elements[this.CHP_affJourJusquau].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourDu].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourAu].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourLe1].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourLe2].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourLe3].value = '';

            document.forms[this.FormName].elements[this.CHP_hiddenJourJusquau].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourDu].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourAu].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourLe1].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourLe2].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourLe3].value = '';
            
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourJusquau]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourDu]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourAu]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourLe1]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourLe2]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourLe3]) ;
        }
        else if( window.CP_targetInput.id == this.CHP_hiddenJourJusquau )
        {
            document.forms[this.FormName].elements[this.CHP_affJour].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourDu].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourAu].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourLe1].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourLe2].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourLe3].value = '';
            
            document.forms[this.FormName].elements[this.CHP_hiddenJour].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourDu].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourAu].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourLe1].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourLe2].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourLe3].value = '';
            
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJour]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourDu]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourAu]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourLe1]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourLe2]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourLe3]) ;
        }
        else if( window.CP_targetInput.id == this.CHP_hiddenJourDu || window.CP_targetInput.id == this.CHP_hiddenJourAu)
        {
            document.forms[this.FormName].elements[this.CHP_affJour].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourJusquau].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourLe1].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourLe2].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourLe3].value = '';
            
            document.forms[this.FormName].elements[this.CHP_hiddenJour].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourJusquau].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourLe1].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourLe2].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourLe3].value = '';
                        
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJour]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourJusquau]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourLe1]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourLe2]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourLe3]) ;
        }
        else if ( window.CP_targetInput.id == this.CHP_hiddenJourLe1 || window.CP_targetInput.id == this.CHP_hiddenJourLe2 || window.CP_targetInput.id == this.CHP_hiddenJourLe3)
        {   
            document.forms[this.FormName].elements[this.CHP_affJour].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourDu].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourAu].value = '';
            document.forms[this.FormName].elements[this.CHP_affJourJusquau].value = '';
            
            document.forms[this.FormName].elements[this.CHP_hiddenJour].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourDu].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourAu].value = '';
            document.forms[this.FormName].elements[this.CHP_hiddenJourJusquau].value = '';
            
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJour]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourDu]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourAu]) ;
            nombrePixelDate(document.forms[this.FormName].elements[this.CHP_affJourJusquau]) ;
                      
            if(document.forms[this.FormName].elements[this.CHP_affJourLe2].value != '' || document.forms[this.FormName].elements[this.CHP_affJourLe3].value != '')
            {
                b_multiHoraire=true;
            }
        }
        
        
        if(b_multiHoraire)
        {
            autoriserMultiHoraire();
        }
        else
        {
            interdireMultiHoraire();
        }
          
       
    }
    else 
    {
	    alert('Use setReturnFunction() to define which function will get the clicked results!'); 
	}
}


// Simple method to interface popup calendar with a text-entry box

function CP_select_bJ(HiddenInputobj,AffInputobj, linkname) {

	var selectedDate=(arguments.length>3)?arguments[3]:null;
	if (!window.getDateFromFormat) 
	{
		alert("calendar.select: To use this method you must also include 'date.js' for date formatting");
		return;
	}
	if (this.displayType!="date"&&this.displayType!="week-end") 
	{
		alert("calendar.select: This function can only be used with displayType 'date' or 'week-end'");
		return;
	}
	if (HiddenInputobj.type!="text" && HiddenInputobj.type!="hidden" && HiddenInputobj.type!="textarea")
	{ 
		alert("calendar.select: Input object passed is not a valid form input object"); 
		window.CP_targetInput=null;
		return;
	}
	if (HiddenInputobj.disabled) { return; } // Can't use calendar input on disabled form input!
  
	window.CP_targetInput = HiddenInputobj;
	window.CP_targetInputVisible = AffInputobj;	

	
	window.CP_calendarObject = this;
	this.currentDate=null;
	var time=0;
	if (selectedDate!=null) 
	{
		time = getDateFromFormat(selectedDate,format)
	}
	else if (HiddenInputobj.value!="") 
	{
		time = getDateFromFormat(HiddenInputobj.value,window.CP_dateFormat);
	}
	if (selectedDate!=null || HiddenInputobj.value!="") 
	{
		if (time==0) 
		{ 
		    this.currentDate=null; 
		}
		else 
		{ 
		this.currentDate=new Date(time); 
		}
	}

	
	this.showCalendar(linkname);

}