
function AssoloCalendar(idOrEl,myConfigs) 
{
	this.Configs = {
		mesi : ['Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio', 'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre'],
		mesiAbbr : ['Gen', 'Feb', 'Mar', 'Apr', 'Mag', 'Giu', 'Lug', 'Ago', 'Set', 'Ott', 'Nov', 'Dic'],
		giorni : ['Lu', 'Ma', 'Me', 'Gi', 'Ve', 'Sa', 'Do'],
		NessunaValue: "Nessuna",
		ShowNessunaBtn: true,
		ShowSalvaBtn: true,
		ShowAnnullaBtn: true,
		ShowInlineEdit: true,
		ShowNavigationGiorno: true,
		ShowLongNavigation: true,
		ShowShortNavigationMese: true,
		ShowShortNavigationAnno: true,
		NavigationAnnoBiennale: true,
		ShowBottomToolBar: true,
		OpenedMode: false,
		IsBorderLess: true,
		DisableEventOnOtherMonths: true,
		afterSaveEventHandler: null,
		afterDateSelectEventHandler: null,
		afterFilterMeseSelectEventHandler: null,
		afterFilterAnnoSelectEventHandler: null,
		HighLightDates: null,
		calendarBtn: "calendarBtn",
		calendarAnnullaBtn: "calendarAnnullaBtn",
		calendarAnnullaDiv: "calendarAnnullaDiv",
		calendarNessunaBtn: "calendarNessunaBtn",
		calendarNessunaDiv: "calendarNessunaDiv",
		calendarSalvaBtn: "calendarSalvaBtn",
		calendarSalvaDiv: "calendarSalvaDiv",
		calendarDiv: "calendarDiv",
		calendarTableDiv: "calendarTableDiv",
		calendarMainTable: "calendarMainTable",
		calendarTableHeader: "calendarTableHeader",
		calendarTable: "calendarTable",
		calendarToolBoxLongNavTable: "calendarToolBoxLongNavTable",
		calendarToolBoxShortNavTable: "calendarToolBoxShortNavTable",
		calendarOthermonth: "calendarOthermonth",
		calendarEveryDay: "calendarEveryDay",
		calendarLabelWeekday: "calendarLabelWeekday",
		calendarLabelWeekend: "calendarLabelWeekend",
		calendarWeekend: "calendarWeekend",
		calendarToday: "calendarToday",
		calendarBusyDay: "calendarBusyDay",
		calendarSelected: "calendarSelected",
		calendarToolBoxBtnDiv: "calendarToolBoxBtnDiv",
		calendarToolBoxBtnTable: "calendarToolBoxBtnTable",
		calendarToolBoxLongNavTableSelected: "calendarToolBoxLongNavTableSelected",
		calendarToolBoxLongNavTableUnselected: "calendarToolBoxLongNavTableUnselected",
		calendarFrecciaLMeseDiv : "calendarFrecciaLMeseDiv",
		calendarFrecciaRMeseDiv : "calendarFrecciaRMeseDiv",
		calendarAnnoSelected: "calendarAnnoSelected",
		calendarAnnoUnselected: "calendarAnnoUnselected",
		LimiteRangeAnnoFrom: '', 
		LimiteRangeAnnoTo: '',
        CalendarSottoInput: false
    };
	this.theInput = null;
	this.theShowButton = null;
	this.DivCalendar = null;
	this.giorno= 0;
	this.mese = 0;
	this.anno = 0;


    if (typeOf(idOrEl) == 'string') {
        this.id = idOrEl;
        this.theInput = document.getElementById(this.id);
    } else {
        this.theInput = idOrEl;
        this.id = this.theInput.id;
    }

	if (myConfigs) {
		if (isdefined(myConfigs.mesi))  this.Configs.mesi  = myConfigs.mesi;
		if (isdefined(myConfigs.mesiAbbr))  this.Configs.mesiAbbr  = myConfigs.mesiAbbr;
		if (isdefined(myConfigs.giorni))  this.Configs.giorni  = myConfigs.giorni;
		if (isdefined(myConfigs.ShowNessunaBtn))  this.Configs.ShowNessunaBtn  = myConfigs.ShowNessunaBtn;
		if (isdefined(myConfigs.ShowSalvaBtn))  this.Configs.ShowSalvaBtn  = myConfigs.ShowSalvaBtn;
		if (isdefined(myConfigs.ShowAnnullaBtn))  this.Configs.ShowAnnullaBtn  = myConfigs.ShowAnnullaBtn;
		if (isdefined(myConfigs.ShowInlineEdit))  this.Configs.ShowInlineEdit  = myConfigs.ShowInlineEdit;
		if (isdefined(myConfigs.ShowLongNavigation))  this.Configs.ShowLongNavigation = myConfigs.ShowLongNavigation;
		if (isdefined(myConfigs.ShowNavigationGiorno))  this.Configs.ShowNavigationGiorno = myConfigs.ShowNavigationGiorno;
		if (isdefined(myConfigs.ShowShortNavigationMese))  this.Configs.ShowShortNavigationMese = myConfigs.ShowShortNavigationMese;
		if (isdefined(myConfigs.ShowShortNavigationAnno))  this.Configs.ShowShortNavigationAnno = myConfigs.ShowShortNavigationAnno;
		if (isdefined(myConfigs.NavigationAnnoBiennale))  this.Configs.NavigationAnnoBiennale = myConfigs.NavigationAnnoBiennale;
		if (isdefined(myConfigs.ShowBottomToolBar))  this.Configs.ShowBottomToolBar = myConfigs.ShowBottomToolBar;
		if (isdefined(myConfigs.OpenedMode))  this.Configs.OpenedMode = myConfigs.OpenedMode;
		if (isdefined(myConfigs.afterDateSelectEventHandler))  this.Configs.afterDateSelectEventHandler = myConfigs.afterDateSelectEventHandler;
		if (isdefined(myConfigs.afterSaveEventHandler))  this.Configs.afterSaveEventHandler = myConfigs.afterSaveEventHandler;
		if (isdefined(myConfigs.afterFilterMeseSelectEventHandler))  this.Configs.afterFilterMeseSelectEventHandler = myConfigs.afterFilterMeseSelectEventHandler;
		if (isdefined(myConfigs.afterFilterAnnoSelectEventHandler))  this.Configs.afterFilterAnnoSelectEventHandler = myConfigs.afterFilterAnnoSelectEventHandler;
		if (isdefined(myConfigs.calendarBtn))  this.Configs.calendarBtn = myConfigs.calendarBtn;
		if (isdefined(myConfigs.calendarAnnullaBtn))  this.Configs.calendarAnnullaBtn = myConfigs.calendarAnnullaBtn;
		if (isdefined(myConfigs.calendarAnnullaDiv))  this.Configs.calendarAnnullaDiv = myConfigs.calendarAnnullaDiv;
		if (isdefined(myConfigs.calendarNessunaBtn))  this.Configs.calendarNessunaBtn = myConfigs.calendarNessunaBtn;
		if (isdefined(myConfigs.calendarNessunaDiv))  this.Configs.calendarNessunaDiv = myConfigs.calendarNessunaDiv;
		if (isdefined(myConfigs.calendarSalvaBtn))  this.Configs.calendarSalvaBtn = myConfigs.calendarSalvaBtn;
		if (isdefined(myConfigs.calendarSalvaDiv))  this.Configs.calendarSalvaDiv = myConfigs.calendarSalvaDiv;
		if (isdefined(myConfigs.calendarDiv))  this.Configs.calendarDiv = myConfigs.calendarDiv;
		if (isdefined(myConfigs.calendarTableDiv))  this.Configs.calendarTableDiv = myConfigs.calendarTableDiv;
		if (isdefined(myConfigs.calendarMainTable))  this.Configs.calendarMainTable = myConfigs.calendarMainTable;
		if (isdefined(myConfigs.calendarTableHeader))  this.Configs.calendarTableHeader = myConfigs.calendarTableHeader;
		if (isdefined(myConfigs.calendarTable))  this.Configs.calendarTable = myConfigs.calendarTable;
		if (isdefined(myConfigs.calendarToolBoxLongNavTable))  this.Configs.calendarToolBoxLongNavTable = myConfigs.calendarToolBoxLongNavTable;
		if (isdefined(myConfigs.calendarToolBoxShortNavTable))  this.Configs.calendarToolBoxShortNavTable = myConfigs.calendarToolBoxShortNavTable;
		if (isdefined(myConfigs.calendarOthermonth))  this.Configs.calendarOthermonth = myConfigs.calendarOthermonth;
		if (isdefined(myConfigs.calendarWeekend))  this.Configs.calendarWeekend = myConfigs.calendarWeekend;
		if (isdefined(myConfigs.calendarEveryDay))  this.Configs.calendarEveryDay = myConfigs.calendarEveryDay;
		if (isdefined(myConfigs.calendarLabelWeekday))  this.Configs.calendarLabelWeekday = myConfigs.calendarLabelWeekday;
		if (isdefined(myConfigs.calendarLabelWeekend))  this.Configs.calendarLabelWeekend = myConfigs.calendarLabelWeekend;
		if (isdefined(myConfigs.calendarToday))  this.Configs.calendarToday = myConfigs.calendarToday;
		if (isdefined(myConfigs.calendarBusyDay))  this.Configs.calendarBusyDay = myConfigs.calendarBusyDay;
		if (isdefined(myConfigs.calendarSelected))  this.Configs.calendarSelected = myConfigs.calendarSelected;
		if (isdefined(myConfigs.calendarToolBoxBtnDiv))  this.Configs.calendarToolBoxBtnDiv = myConfigs.calendarToolBoxBtnDiv;
		if (isdefined(myConfigs.calendarToolBoxBtnTable))  this.Configs.calendarToolBoxBtnTable = myConfigs.calendarToolBoxBtnTable;
		if (isdefined(myConfigs.calendarToolBoxLongNavTableSelected))  this.Configs.calendarToolBoxLongNavTableSelected = myConfigs.calendarToolBoxLongNavTableSelected;
		if (isdefined(myConfigs.calendarToolBoxLongNavTableUnselected))  this.Configs.calendarToolBoxLongNavTableUnselected = myConfigs.calendarToolBoxLongNavTableUnselected;
		if (isdefined(myConfigs.NessunaValue))  this.Configs.NessunaValue = myConfigs.NessunaValue;
		if (isdefined(myConfigs.DisableEventOnOtherMonths))  this.Configs.DisableEventOnOtherMonths = myConfigs.DisableEventOnOtherMonths;
		if (isdefined(myConfigs.calendarFrecciaLMeseDiv))  this.Configs.calendarFrecciaLMeseDiv = myConfigs.calendarFrecciaLMeseDiv;
		if (isdefined(myConfigs.calendarFrecciaRMeseDiv))  this.Configs.calendarFrecciaRMeseDiv = myConfigs.calendarFrecciaRMeseDiv;
		if (isdefined(myConfigs.calendarAnnoSelected))  this.Configs.calendarAnnoSelected = myConfigs.calendarAnnoSelected;
		if (isdefined(myConfigs.calendarAnnoUnselected))  this.Configs.calendarAnnoUnselected = myConfigs.calendarAnnoUnselected;
		if (isdefined(myConfigs.LimiteRangeAnnoFrom))  this.Configs.LimiteRangeAnnoFrom = myConfigs.LimiteRangeAnnoFrom;
		if (isdefined(myConfigs.LimiteRangeAnnoTo))  this.Configs.LimiteRangeAnnoTo = myConfigs.LimiteRangeAnnoTo;
		if (isdefined(myConfigs.CalendarSottoInput))  this.Configs.CalendarSottoInput = myConfigs.CalendarSottoInput;
	}

// alert(this.theInput);
	
	if (this.theInput) 
	{
		if (this.Configs.OpenedMode) {
			this.makeDivCalendar();
			this.setDate(this.theInput.value);
		} else {
            this.theShowButton = document.createElement("input");
            this.theShowButton.id = this.id + "_showbtn";
            this.theShowButton.type = "button";
            this.theShowButton.value = " ";
            this.theShowButton.className = this.Configs.calendarBtn;
            var oSelf = this;
            function hideMyCalendar(event) {
                oSelf.hideCalendar(event);
            }
            function showMyCalendar(event) {
                oSelf.showCalendar(event);
            }
            
            this.theShowButton.onclick = showMyCalendar;
            
            if (this.theInput.nextSibling) {
                this.theInput.parentNode.insertBefore(this.theShowButton, this.theInput.nextSibling); 
            } else {
                this.theInput.parentNode.appendChild(this.theShowButton); 
            }
            
            if (!this.Configs.ShowSalvaBtn) {
                try {
                    this.theInput.addEventListener('focus', showMyCalendar, true);
                } catch(err) {
                    this.theInput.attachEvent('onfocus', showMyCalendar );
                }
                
                try {
                    this.theInput.addEventListener('blur', hideMyCalendar, true);
                } catch(err) {
                    this.theInput.attachEvent('onblur', hideMyCalendar );
                }
            }
		}
	} else {
		alert("Errore interno #8751: elemento "+this.id+" non trovato!");
	}
}

AssoloCalendar.prototype.HideMeseLookUp = function(event)
{
	this.MeseField.innerHTML = this.MeseLookUp.options[this.MeseLookUp.selectedIndex].text;
	this.MeseLookUp.parentNode.insertBefore(this.MeseField, this.MeseLookUp.nextSibling); 
	this.MeseLookUp.parentNode.removeChild(this.MeseLookUp);

	this.setPage(parseInt(this.MeseLookUp.selectedIndex+1),this.anno);

	if (this.Configs.afterFilterMeseSelectEventHandler) 
		this.Configs.afterFilterMeseSelectEventHandler(this, parseInt(this.MeseLookUp.selectedIndex+1),this.anno);
}

AssoloCalendar.prototype.HideMeseLookUpESC = function(event)
{
	this.MeseLookUp.parentNode.insertBefore(this.MeseField, this.MeseLookUp.nextSibling); 
	this.MeseLookUp.parentNode.removeChild(this.MeseLookUp);
}
AssoloCalendar.prototype.ShowMeseLookUp = function(event)
{
	if (!this.MeseLookUp) {
		this.MeseLookUp = document.createElement("select");

		var curOpt = null;
		for(var i=0;i<12;i++) {
			curOpt = document.createElement("option");
			curOpt.text = this.Configs.mesi[i];
			curOpt.Value = i+1;
			this.MeseLookUp.appendChild(curOpt);
		}
	}

	for(var i=0;i<12;i++) {
		if (this.Configs.mesi[i] == this.MeseField.innerHTML) {
			this.MeseLookUp.options[i].selected = true;
		}
	}
	
	var oSelf = this;
	this.MeseLookUp.onchange = function(event){ oSelf.HideMeseLookUp(event); };
	this.MeseLookUp.onkeypress = function(event){ oSelf.HideMeseLookUpESC(event); };

	this.MeseField.parentNode.insertBefore(this.MeseLookUp, this.MeseField.nextSibling); 
	this.MeseField.parentNode.removeChild(this.MeseField);
	
	this.MeseLookUp.focus();
}


AssoloCalendar.prototype.HideAnnoTextBox = function(event)
{
	var ev = event || window.event;
	if (ev.keyCode == 13) {
		this.AnnoField.innerHTML = this.AnnoTextBox.value;
		this.AnnoTextBox.parentNode.insertBefore(this.AnnoField, this.AnnoTextBox.nextSibling); 
		this.AnnoTextBox.parentNode.removeChild(this.AnnoTextBox);

		this.setPage(this.mese, parseInt(this.AnnoTextBox.value));

		if (this.Configs.afterFilterAnnoSelectEventHandler) 
			this.Configs.afterFilterAnnoSelectEventHandler(this, parseInt(this.AnnoTextBox.value));
	} else if (ev.keyCode == ((window.event) ? 27 : ev.DOM_VK_ESCAPE )) {
		this.AnnoTextBox.parentNode.insertBefore(this.AnnoField, this.AnnoTextBox.nextSibling); 
		this.AnnoTextBox.parentNode.removeChild(this.AnnoTextBox);
	}
}

AssoloCalendar.prototype.ShowAnnoTextBox = function(event)
{
	if (!this.AnnoTextBox) {
		this.AnnoTextBox = document.createElement("input");
	}
	this.AnnoTextBox.value = this.AnnoField.innerHTML;
	
	var oSelf = this;
	this.AnnoTextBox.onkeypress = function(event){ oSelf.HideAnnoTextBox(event); };

	this.AnnoField.parentNode.insertBefore(this.AnnoTextBox, this.AnnoField.nextSibling); 
	this.AnnoField.parentNode.removeChild(this.AnnoField);
	
	this.AnnoTextBox.focus();
}

AssoloCalendar.prototype.makeLongNavigation = function()
{
	var oSelf = this;

	this.calendarToolBoxLongNavTable = document.createElement("table");
	if (this.Configs.IsBorderLess) {
		this.calendarToolBoxLongNavTable.border = "0";
		this.calendarToolBoxLongNavTable.cellPadding = "0";
		this.calendarToolBoxLongNavTable.cellSpacing = "0";
	}
	//this.calendarToolBoxLongNavTable.style.width="100%";
	this.calendarToolBoxLongNavTable.className = this.Configs.calendarToolBoxLongNavTable;
	var CurBody = document.createElement("tbody");
	this.calendarToolBoxLongNavTable.appendChild(CurBody);
	
	var CurRow = CurBody.insertRow(-1);
	
	var CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarFrecciaLMeseDiv+"'>&lt;</div>";
	CurCell.onclick = function(event){ 
			if (oSelf.CurrentMese == 1) { 
				oSelf.setPage(12,oSelf.CurrentAnno-1); 
				
				if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
					oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
			} else {
				oSelf.setPage(oSelf.CurrentMese-1,oSelf.CurrentAnno); 
				
				if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
					oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
			}
		};
	
	CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarToolBoxLongNavTableUnselected+"'>"+this.Configs.mesiAbbr[0]+"</div>";
	CurCell.onclick = function(event){ 
			oSelf.setPage(1,oSelf.CurrentAnno); 

			if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
				oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
		};

	CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarToolBoxLongNavTableUnselected+"'>"+this.Configs.mesiAbbr[1]+"</div>";
	CurCell.onclick = function(event){ 
			oSelf.setPage(2,oSelf.CurrentAnno); 
			
			if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
				oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
		};

	CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarToolBoxLongNavTableUnselected+"'>"+this.Configs.mesiAbbr[2]+"</div>";
	CurCell.onclick = function(event){ 
			oSelf.setPage(3,oSelf.CurrentAnno); 

			if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
				oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
		};

	CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarToolBoxLongNavTableUnselected+"'>"+this.Configs.mesiAbbr[3]+"</div>";
	CurCell.onclick = function(event){ 
			oSelf.setPage(4,oSelf.CurrentAnno); 
			
			if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
				oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
		};

	CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarToolBoxLongNavTableUnselected+"'>"+this.Configs.mesiAbbr[4]+"</div>";
	CurCell.onclick = function(event){ 
			oSelf.setPage(5,oSelf.CurrentAnno); 
			
			if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
				oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
		};

	CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarToolBoxLongNavTableUnselected+"'>"+this.Configs.mesiAbbr[5]+"</div>";
	CurCell.onclick = function(event){ 
			oSelf.setPage(6,oSelf.CurrentAnno); 
			
			if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
				oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
		};

	var CurRow = CurBody.insertRow(-1);
	
	CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarToolBoxLongNavTableUnselected+"'>"+this.Configs.mesiAbbr[6]+"</div>";
	CurCell.onclick = function(event){ 
			oSelf.setPage(7,oSelf.CurrentAnno); 
			
			if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
				oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
		};
	
	CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarToolBoxLongNavTableUnselected+"'>"+this.Configs.mesiAbbr[7]+"</div>";
	CurCell.onclick = function(event){ 
			oSelf.setPage(8,oSelf.CurrentAnno); 
			
			if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
				oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
		};
	
	CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarToolBoxLongNavTableUnselected+"'>"+this.Configs.mesiAbbr[8]+"</div>";
	CurCell.onclick = function(event){ 
			oSelf.setPage(9,oSelf.CurrentAnno); 
			
			if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
				oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
		};
	
	CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarToolBoxLongNavTableUnselected+"'>"+this.Configs.mesiAbbr[9]+"</div>";
	CurCell.onclick = function(event){ 
			oSelf.setPage(10,oSelf.CurrentAnno); 
			
			if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
				oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
		};
	
	CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarToolBoxLongNavTableUnselected+"'>"+this.Configs.mesiAbbr[10]+"</div>";
	CurCell.onclick = function(event){ 
			oSelf.setPage(11,oSelf.CurrentAnno); 
			
			if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
				oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
		};
	
	CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarToolBoxLongNavTableUnselected+"'>"+this.Configs.mesiAbbr[11]+"</div>";
	CurCell.onclick = function(event){ 
			oSelf.setPage(12,oSelf.CurrentAnno); 
			
			if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
				oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
		};
	
	CurCell = CurRow.insertCell(-1);
	CurCell.innerHTML = "<div class='"+this.Configs.calendarFrecciaRMeseDiv+"'>&gt;</div>";
	CurCell.onclick = function(event){ 
			if (oSelf.CurrentMese == 12) {
				oSelf.setPage(1,oSelf.CurrentAnno+1); 
				
				if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
					oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
			} else {
				oSelf.setPage(oSelf.CurrentMese+1,oSelf.CurrentAnno); 
				
				if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
					oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
			}
		};
	
    if (!this.CellToolBox) {
        CurRow = this.CurTableBody.insertRow(-1);
        this.CellToolBox = CurRow.insertCell(-1);
    }
	this.CellToolBox.appendChild(this.calendarToolBoxLongNavTable);
}

AssoloCalendar.prototype.ClickAnnoFieldBiennale = function (event)
{
	if (this.Configs.LimiteRangeAnnoFrom && (this.CurrentAnno == parseInt(this.Configs.LimiteRangeAnnoFrom))) {
		return false;
	} else {
		this.setPage(this.CurrentMese,this.CurrentAnno-1); 
		if (this.Configs.afterFilterAnnoSelectEventHandler) this.Configs.afterFilterAnnoSelectEventHandler(this, this.CurrentAnno);
	}
}
AssoloCalendar.prototype.ClickNextAnnoFieldBiennale = function (event)
{
	if (this.Configs.LimiteRangeAnnoTo && (this.CurrentAnno == parseInt(this.Configs.LimiteRangeAnnoTo))) {
		return false;
	} else {
		this.setPage(this.CurrentMese,this.CurrentAnno+1); 
		if (this.Configs.afterFilterAnnoSelectEventHandler) this.Configs.afterFilterAnnoSelectEventHandler(this, this.CurrentAnno); 
	}
}

AssoloCalendar.prototype.makeDivCalendar = function()
{
    var oSelf = this;
    var CurBody = null;
    var CurRow = null;
    var CurCell = null;
    var CurDiv = null;
    var CurTable = null;

    this.DivCalendar = document.createElement("div");
    this.DivCalendar.id = this.id + "_divCal";
    this.DivCalendar.className = this.Configs.calendarDiv;

    if (!this.Configs.OpenedMode) { 
        this.DivCalendar.style.position = "absolute";
        this.DivCalendar.style.display = "none";
    }
    
    this.TableCalendar = document.createElement("table");
    if (this.Configs.IsBorderLess) {
        this.TableCalendar.border = "0";
        this.TableCalendar.cellPadding = "0";
        this.TableCalendar.cellSpacing = "0";
    }
    //this.TableCalendar.style.width="100%";
    //this.TableCalendar.style.height="100%";
    this.TableCalendar.id = this.id + "_tableCal";
    this.TableCalendar.className = this.Configs.calendarTable;
    this.DivCalendar.appendChild(this.TableCalendar);

    this.CurTableBody = document.createElement("tbody");
    this.TableCalendar.appendChild(this.CurTableBody);
    
    if (this.Configs.ShowShortNavigationMese || this.Configs.ShowShortNavigationAnno) 
    {
        CurRow = this.CurTableBody.insertRow(-1);
        this.CellToolBox = CurRow.insertCell(-1);
        CurTable = document.createElement("table");
        if (this.Configs.IsBorderLess) {
            CurTable.border = "0";
            CurTable.cellPadding = "0";
            CurTable.cellSpacing = "0";
        }			
        //CurTable.style.width="100%";
        CurTable.className = this.Configs.calendarToolBoxShortNavTable;
        CurBody = document.createElement("tbody");
        CurTable.appendChild(CurBody);
        CurRow = CurBody.insertRow(-1);
        
        if (this.Configs.ShowShortNavigationMese) {
            CurCell = CurRow.insertCell(-1);
            CurCell.innerHTML = "&lt;";
            CurCell.onclick = function(event){ 
                    if (oSelf.CurrentMese==1) {
                        oSelf.setPage(12,oSelf.CurrentAnno-1);
                        
                        if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
                            oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
                    } else {
                        oSelf.setPage(oSelf.CurrentMese-1,oSelf.CurrentAnno); 
                        
                        if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
                            oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno); 
                    }
                };
        
            this.MeseField = CurRow.insertCell(-1);
            if (this.Configs.ShowInlineEdit) {
                this.MeseField.onclick = function(event){ oSelf.ShowMeseLookUp(event); };
            }
            
            CurCell = CurRow.insertCell(-1);
            CurCell.innerHTML = "&gt;";
            CurCell.onclick = function(event){ 
                    if (oSelf.CurrentMese==12) {
                        oSelf.setPage(1,oSelf.CurrentAnno+1);
                        
                        if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
                            oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno);
                    } else {
                        oSelf.setPage(oSelf.CurrentMese+1,oSelf.CurrentAnno); 
                            
                        if (oSelf.Configs.afterFilterMeseSelectEventHandler) 
                            oSelf.Configs.afterFilterMeseSelectEventHandler(oSelf, oSelf.CurrentMese,oSelf.CurrentAnno); 
                    }
                };
        }
        
        if (this.Configs.ShowShortNavigationAnno) {
            if (this.Configs.NavigationAnnoBiennale) 
            {
                this.AnnoField = CurRow.insertCell(-1);
                this.AnnoField.onclick = function(event){ oSelf.ClickAnnoFieldBiennale(event); };
                
                //CurCell = CurRow.insertCell(-1);
                //CurCell.innerHTML = "&nbsp;";

                this.NextAnnoField = CurRow.insertCell(-1);
                this.NextAnnoField.innerHTML = "&gt;";
                this.NextAnnoField.onclick = function(event){ oSelf.ClickNextAnnoFieldBiennale(event); };
            } else {
                CurCell = CurRow.insertCell(-1);
                CurCell.innerHTML = "&lt;";
                CurCell.onclick = function(event){ 
                        oSelf.setPage(oSelf.CurrentMese,oSelf.CurrentAnno-1); 

                        if (oSelf.Configs.afterFilterAnnoSelectEventHandler) 
                            oSelf.Configs.afterFilterAnnoSelectEventHandler(oSelf, oSelf.CurrentAnno); 
                    };
                this.AnnoField = CurRow.insertCell(-1);
                if (this.Configs.ShowInlineEdit) {
                    this.AnnoField.onclick = function(event){ oSelf.ShowAnnoTextBox(event); };
                }
                CurCell = CurRow.insertCell(-1);
                CurCell.innerHTML = "&gt;";
                CurCell.onclick = function(event){ 
                        oSelf.setPage(oSelf.CurrentMese,oSelf.CurrentAnno+1); 

                        if (oSelf.Configs.afterFilterAnnoSelectEventHandler) 
                            oSelf.Configs.afterFilterAnnoSelectEventHandler(oSelf, oSelf.CurrentAnno); 
                    };
            }
        }
        this.CellToolBox.appendChild(CurTable);
    }
    
    if (this.Configs.ShowLongNavigation) {
        this.makeLongNavigation();
    }
    
    if (this.Configs.ShowNavigationGiorno)
    {
        CurRow = this.CurTableBody.insertRow(-1);
        CurCell = CurRow.insertCell(-1);
        
        CurDiv = document.createElement("div");
        CurDiv.className = this.Configs.calendarTableDiv;
        MainTable = document.createElement("table");
        if (this.Configs.IsBorderLess) {
            MainTable.border = "0";
            MainTable.cellPadding = "0";
            MainTable.cellSpacing = "0";
        }			
        //MainTable.style.width="100%";
        MainTable.className = this.Configs.calendarMainTable;
        var CurTHead = MainTable.createTHead();
        CurTHead.className = this.Configs.calendarTableHeader;
        CurDiv.appendChild(MainTable);
        CurCell.appendChild(CurDiv);
        
        CurRow = CurTHead.insertRow(-1);
        for (i in this.Configs.giorni) {
            CurCell = CurRow.insertCell(-1);
            CurCellDiv = document.createElement("div");
            CurCellDiv.innerHTML = this.Configs.giorni[i];
            CurCell.appendChild(CurCellDiv);

            if (i < 5) {
                CurCellDiv.className = this.Configs.calendarLabelWeekday;
            } else {
                CurCellDiv.className = this.Configs.calendarLabelWeekend;
            } 
        }
        
        this.TableCalendarBody = document.createElement("tbody");
        MainTable.appendChild(this.TableCalendarBody);
    }
    
    if (this.Configs.ShowBottomToolBar) {
        CurRow = this.CurTableBody.insertRow(-1);
        CurCell = CurRow.insertCell(-1);
        CurDiv = document.createElement("div");
        CurDiv.className = this.Configs.calendarToolBoxBtnDiv;
        CurCell.appendChild(CurDiv);
        CurTable = document.createElement("table");
        if (this.Configs.IsBorderLess) {
            CurTable.border = "0";
            CurTable.cellPadding = "0";
            CurTable.cellSpacing = "0";
        }
        //CurTable.style.width="100%";
        CurTable.className = this.Configs.calendarToolBoxBtnTable;
        CurDiv.appendChild(CurTable);
        
        CurBody = document.createElement("tbody");
        CurTable.appendChild(CurBody);
        CurRow = CurBody.insertRow(0);
        
        if (this.Configs.ShowAnnullaBtn) {
            this.theAnnullaButton = document.createElement("input");
            this.theAnnullaButton.id = this.id + "_annullabtn";
            this.theAnnullaButton.type = "button";
            this.theAnnullaButton.className = this.Configs.calendarAnnullaBtn;
            this.theAnnullaButton.onclick = function(event){ oSelf.Annulla(event); };
            CurCell = CurRow.insertCell(-1);
            CurDiv = document.createElement("div");
            CurDiv.className = this.Configs.calendarAnnullaDiv;
            CurDiv.appendChild(this.theAnnullaButton);
            CurCell.appendChild(CurDiv);
        }
        if (this.Configs.ShowNessunaBtn) {
            this.theNessunaButton = document.createElement("input");
            this.theNessunaButton.id = this.id + "_nessunabtn";
            this.theNessunaButton.type = "button";
            this.theNessunaButton.className = this.Configs.calendarNessunaBtn;
            this.theNessunaButton.onclick = function(event){ oSelf.Nessuna(event); };
            CurCell = CurRow.insertCell(-1);
            CurDiv = document.createElement("div");
            CurDiv.className = this.Configs.calendarNessunaDiv;
            CurDiv.appendChild(this.theNessunaButton);
            CurCell.appendChild(CurDiv);
        }
        
        if (this.Configs.ShowSalvaBtn) {
            this.theSalvaButton = document.createElement("input");
            this.theSalvaButton.id = this.id + "_salvabtn";
            this.theSalvaButton.type = "button";
            this.theSalvaButton.className = this.Configs.calendarSalvaBtn;
            this.theSalvaButton.onclick = function(event){ oSelf.Salva(event); };
            CurCell = CurRow.insertCell(-1);
            CurDiv = document.createElement("div");
            CurDiv.className = this.Configs.calendarSalvaDiv;
            CurDiv.appendChild(this.theSalvaButton);
            CurCell.appendChild(CurDiv);
        }
    }
    
    if (this.theInput.nextSibling) {
        this.theInput.parentNode.insertBefore(this.DivCalendar, this.theInput.nextSibling); 
    } else {
        this.theInput.parentNode.appendChild(this.DivCalendar); 
    }    
}

AssoloCalendar.prototype.setDate = function(newValue)
{
	var regexpDate = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2,4}$/;
	if (regexpDate.test(newValue)) {
		var parts = newValue.split(RegExp.$1);
		this.giorno= parts[0];
		this.mese = parts[1];
		this.anno = parts[2];
		if (parseInt(this.anno,10) < 100) this.anno = parseInt(this.anno,10) + 2000;
	} else {
		var Today = new Date();
		this.giorno= Today.getDate();
		this.mese = Today.getMonth()+1;
		this.anno = Today.getFullYear();
	}
	this.giorno = parseInt(this.giorno, 10);
	this.mese  = parseInt(this.mese, 10);
	this.anno  = parseInt(this.anno, 10);

	this.setPage(this.mese, this.anno);
	
}

AssoloCalendar.prototype.setNewDate = function(event, el)
{
	this.setDate(""+el.giorno+"."+el.mese+"."+el.anno+"");
	
	if (this.Configs.afterDateSelectEventHandler) 
		this.Configs.afterDateSelectEventHandler(this, el.giorno, el.mese, el.anno);	

    if (!this.Configs.ShowSalvaBtn) {
        this.AnnullaEventHide = false;
        this.Salva(event);
    }        
}

AssoloCalendar.prototype.hideCalendar = function()
{
    this.AnnullaEventHide = false;

    var oSelf = this;
    setTimeout(function() { if (oSelf.AnnullaEventHide) { oSelf.theInput.focus(); } else { oSelf.DivCalendar.style.display = "none"; } }, 200);

    return true;
}

AssoloCalendar.prototype.setPage = function(Mese, Anno)
{
    this.AnnullaEventHide = true;

	if (this.Configs.LimiteRangeAnnoFrom) {
		if (Anno < this.Configs.LimiteRangeAnnoFrom) Anno = parseInt(this.Configs.LimiteRangeAnnoFrom);
	}
	if (this.Configs.LimiteRangeAnnoTo) {
		if (Anno > this.Configs.LimiteRangeAnnoTo) Anno = parseInt(this.Configs.LimiteRangeAnnoTo);
	}

	if (this.Configs.NavigationAnnoBiennale) 
	{	
		if (this.Configs.LimiteRangeAnnoTo && (Anno == parseInt(this.Configs.LimiteRangeAnnoTo))) {
			if (this.AnnoField) {
				this.AnnoField.innerHTML = "<div class='"+this.Configs.calendarAnnoUnselected+"'>"+(((Anno-1) < 100 ? '20' : '') + (Anno+-1))+"</div>";
			}
			if (this.NextAnnoField) {
				this.NextAnnoField.innerHTML = "<div class='"+this.Configs.calendarAnnoSelected+"'>"+((Anno < 100 ? '20' : '') + Anno)+"</div>";
			}		
		} else {
			if (this.AnnoField) {
				this.AnnoField.innerHTML = "<div class='"+this.Configs.calendarAnnoSelected+"'>"+((Anno < 100 ? '20' : '') + Anno)+"</div>";
			}
			if (this.NextAnnoField) {
				this.NextAnnoField.innerHTML = "<div class='"+this.Configs.calendarAnnoUnselected+"'>"+(((Anno+1) < 100 ? '20' : '') + (Anno+1))+"</div>";
			}	
		}
	} 
	else
	{
		if (this.AnnoField) this.AnnoField.innerHTML = (Anno < 100 ? '20' : '') + Anno;
		if (this.NextAnnoField) this.NextAnnoField.innerHTML = ((Anno+1) < 100 ? '20' : '') + (Anno+1);
	}
	
	if (this.MeseField) this.MeseField.innerHTML = this.Configs.mesi[Mese-1];
	
	if (this.calendarToolBoxLongNavTable) {
		for(var i=1;i<=12;i++) {
			if (i>6) {
				if (i == Mese) this.calendarToolBoxLongNavTable.rows[1].cells[i-7].firstChild.className = this.Configs.calendarToolBoxLongNavTableSelected;
				else           this.calendarToolBoxLongNavTable.rows[1].cells[i-7].firstChild.className = this.Configs.calendarToolBoxLongNavTableUnselected;
			} else {
				if (i == Mese) this.calendarToolBoxLongNavTable.rows[0].cells[i].firstChild.className = this.Configs.calendarToolBoxLongNavTableSelected;
				else           this.calendarToolBoxLongNavTable.rows[0].cells[i].firstChild.className = this.Configs.calendarToolBoxLongNavTableUnselected;
			}
		}
	}
	
	var IlPrimoGiorno = new Date(Anno,Mese-1,1,1,1,1);
	var IlGiornoB = IlPrimoGiorno.getDay();
	
	//var deb = "IlGiornoB=["+IlGiornoB+"]; IlPrimoDelMese=["+IlPrimoGiorno.toString()+"];\n";
	
	if (IlGiornoB == 0) { // Do
		IlPrimoGiorno.setTime(IlPrimoGiorno.getTime()-518400000); // 6*24*60*60*1000;
	} else { // Lu-Sa
		IlPrimoGiorno.setTime(IlPrimoGiorno.getTime()-(IlGiornoB-1)*86400000); // 24*60*60*1000;
	}

	//deb += "IlPrimoGiorno=["+IlPrimoGiorno.toString()+"];\n";
	
	LUltimoGiorno = new Date(Anno,Mese,1,1,1,1);
	LUltimoGiorno.setTime(LUltimoGiorno.getTime()-86400000); // 24*60*60*1000;
	
	var IlGiornoE = LUltimoGiorno.getDay();

	//deb += "IlGiornoE=["+IlGiornoE+"]; LUltimoDelMese=["+LUltimoGiorno.toString()+"];\n";
	
	if (IlGiornoE != 0) { // Lu-Sa
		LUltimoGiorno.setTime(LUltimoGiorno.getTime()+(7-IlGiornoE)*86400000); // 24*60*60*1000;
	} else { // Do
	}

	//deb += "LUltimoGiorno=["+LUltimoGiorno.toString()+"];\n";
	
	//alert(deb);
	
	if (this.Configs.ShowNavigationGiorno)
	{
		while (this.TableCalendarBody.childNodes.length >= 1) {
			this.TableCalendarBody.removeChild(this.TableCalendarBody.firstChild);
		}
		
		var CurDate = IlPrimoGiorno;
		var CurRow = null;
		var CurCell = null;
		var Today = new Date();
		var oSelf = this;
		while(CurDate <= LUltimoGiorno) 
		{
			CurRow = this.TableCalendarBody.insertRow(-1);
			for (var gi = 1; gi <= 7; gi++) {
				CurCell = CurRow.insertCell(-1);
				
				CurCellDiv = document.createElement("div");
				CurCellDiv.innerHTML = ""+CurDate.getDate()+"";
				CurCell.appendChild(CurCellDiv);
				
				CurCell.giorno = CurDate.getDate();
				CurCell.mese  = CurDate.getMonth()+1;
				CurCell.anno  = CurDate.getFullYear();
				
				if (((CurDate.getMonth()+1) == Mese) || (!this.Configs.DisableEventOnOtherMonths)) {
					CurCell.onclick = function(event){ oSelf.setNewDate(event, this); }
				}

				addClass(CurCellDiv, this.Configs.calendarEveryDay);
					
				if ((CurDate.getMonth()+1) != Mese)
					addClass(CurCellDiv, this.Configs.calendarOthermonth);
					
				if (CurDate.getDay() == 0 || CurDate.getDay() == 6)
					addClass(CurCellDiv, this.Configs.calendarWeekend);
					
				if (in_array(""+(CurDate.getDate() < 10 ? '0' : '') + CurDate.getDate() + "." + 
								((CurDate.getMonth()+1) < 10 ? '0' : '') + (CurDate.getMonth()+1) + "." + 
								(""+CurDate.getFullYear()+"").substr(2,2)+"", this.Configs.HighLightDates)) 
					addClass(CurCellDiv, this.Configs.calendarBusyDay);
				
				if ((CurDate.getDate() == Today.getDate()) && 
					(CurDate.getMonth() == Today.getMonth()) && 
					(CurDate.getFullYear() == Today.getFullYear()) )
					addClass(CurCellDiv, this.Configs.calendarToday);
				
				if ((CurDate.getDate() == this.giorno) && 
					((CurDate.getMonth()+1) == this.mese) && 
					(CurDate.getFullYear() == this.anno) )
					addClass(CurCellDiv, this.Configs.calendarSelected);
					
				CurDate.setTime(CurDate.getTime()+86400000); // 24*60*60*1000;
			}		
		}
	}

	this.CurrentMese = Mese;
	this.CurrentAnno = Anno;
}

AssoloCalendar.prototype.setPosAndShow = function(event)
{
    this.DivCalendar.style.left = "-1000px";
    this.DivCalendar.style.top  = "-1000px";
    this.DivCalendar.style.display = 'inline';

    if (this.Configs.CalendarSottoInput) {
		var pos = GetXYWH(this.theInput);
		this.DivCalendar.style.left = pos[0]+"px";
		this.DivCalendar.style.top = (pos[1]+pos[3])+"px";
    } else {
		var pos = GetXY(this.theInput);
		this.DivCalendar.style.left = pos[0]+"px";
		this.DivCalendar.style.top = pos[1]+"px";
    }
}

AssoloCalendar.prototype.showCalendar = function(event) 
{
    if (!this.DivCalendar) {
        this.makeDivCalendar();
        this.setDate(this.theInput.value);
    }
    this.setPosAndShow(event);    
}

AssoloCalendar.prototype.Annulla = function(event) 
{
	if (!this.Configs.OpenedMode) {
		this.DivCalendar.style.display = "none";
	}
}
AssoloCalendar.prototype.Salva = function(event) 
{
	if ((this.giorno == 0) && (this.mese == 0) && (this.anno == 0)) {
		this.theInput.value = this.Configs.NessunaValue;
	} else {
		this.theInput.value = (this.giorno < 10 ? '0' : '') + this.giorno + "." + (this.mese < 10 ? '0' : '') + this.mese + "." + (this.anno < 100 ? '20' : '') + this.anno;
	}
	if (this.Configs.OpenedMode) {
		if (this.Configs.afterDateSelectEventHandler) 
			this.Configs.afterDateSelectEventHandler(this, this.giorno, this.mese, this.anno);
	} else {
        if (!this.AnnullaEventHide) {
            this.DivCalendar.style.display = "none";
        }
	}
    if (this.Configs.afterSaveEventHandler) {
        this.Configs.afterSaveEventHandler(this, this.giorno, this.mese, this.anno);
    }
}
AssoloCalendar.prototype.Nessuna = function(event) 
{
	this.theInput.value = this.Configs.NessunaValue;
	if (this.Configs.OpenedMode) {
		if (this.Configs.afterDateSelectEventHandler) 
			this.Configs.afterDateSelectEventHandler(this, 0, 0, 0);
	} else {
		this.DivCalendar.style.display = "none";
	}
}

AssoloCalendar.prototype.setHighLightDates = function(myDates)
{
	if (isdefined(myDates)) this.Configs.HighLightDates = myDates;
}

