function getCalendar(dest, index, formCallback, calDescription){
	
	document.cal_formCallback = formCallback;
	document.cal_calDescription = calDescription;

	if (!index){
		index = 1;
	}
	memDay = 1;
	searchType = 'F';
    memorizzaGiorno=memDay;
    destinatario=dest;
		cal = document.getElementById('cal1');
    cal.style.display = 'block';
		dt = document.getElementById(dest);
		pos = getPositions(dt);
		switch (dest){
		//sys step 1
		case "date1":
			cal.style.left = (pos[0] + 85) + "px";
			cal.style.top = (pos[1] - 112) + "px";
			break;
		case "date2":
			cal.style.left = (pos[0] + 85) + "px";
			cal.style.top = (pos[1] - 233) + "px";
			break;
		//sys quick
		case "date1a":
			cal.style.left = (pos[0] + 190) + "px";
			cal.style.top = (pos[1] - 88) + "px";
			break;
		case "date2a":
			cal.style.left = (pos[0] + 85) + "px";
			cal.style.top = (pos[1] - 88) + "px";
			break;
		//web quick
		case "date1b":
			cal.style.left = "10px";
			cal.style.top = "30px";
			break;
		case "date2b":
			cal.style.left = "10px";
			cal.style.top = "30px";
			break;
		//web step 1
		case "date1c":
			cal.style.left = (pos[0] - 20) + "px";
			cal.style.top = (pos[1] - 112) + "px";
			break;
		case "date2c":
			cal.style.left = (pos[0] - 20) + "px";
			cal.style.top = (pos[1] - 233) + "px";
			break;
		case "tblAirTicket_timeLimitDate_date":
			cal.style.left = (pos[0]) + "px";
			cal.style.top = (pos[1]) + "px";
			break;
		default :
			cal.style.left = (pos[0]) + "px";
			cal.style.top  = (pos[1] + pos[3]) + "px";
			break
		//sys quick
			
	}
    ridisegnaCalendari(index, searchType);
}

function getTime() {
	// initialize time-related variables with current time settings
	var now = new Date()
	var hour = now.getHours()
	var minute = now.getMinutes()
	now = null
	var ampm = "" 

	// validate hour values	and set value of ampm
	if (hour >= 12) {
		hour -= 12
		ampm = "PM"
	} else
		ampm = "AM"
	hour = (hour == 0) ? 12 : hour

	// add zero digit to a one digit minute
	if (minute < 10)
		minute = "0" + minute // do not parse this number!

	// return time string
	return hour + ":" + minute + " " + ampm
}

function leapYear(year) {
	if (year % 4 == 0) // basic rule
		return true // is leap year
	/* else */ // else not needed when statement is "return"
		return false // is not leap year
}

function getDays(month, year) {
	// create array to hold number of days in each month
	var ar = new Array(12)
	ar[0] = 31 // January
	ar[1] = (leapYear(year)) ? 29 : 28 // February
	ar[2] = 31 // March
	ar[3] = 30 // April
	ar[4] = 31 // May
	ar[5] = 30 // June
	ar[6] = 31 // July
	ar[7] = 31 // August
	ar[8] = 30 // September
	ar[9] = 31 // October
	ar[10] = 30 // November
	ar[11] = 31 // December

	// return number of days in the specified month (parameter)
	return ar[month]
}

function getMonthName(month) {
	
	// return name of specified month (parameter)
	//window.alert(month);
	if(month==12){ //revert to january
	
		return months[0];
	}else{
		return months[month];
	}
}

function setCal(tg) {
	// standard time attributes
	var now = new Date()
	var year = now.getFullYear()
	var month = now.getMonth()
	var monthName = getMonthName(month)
	var date = now.getDate()
	now = null

	// create instance of first day of month, and extract the day on which it occurs
	var firstDayInstance = new Date(year, month, 1)
	var firstDay = firstDayInstance.getDay()
	firstDayInstance = null

	// number of days in current month
	var days = getDays(month, year)
	// call function to draw calendar
	drawCal(firstDay + 1, days, date, monthName, year,tg)
}


//render the top month in the calendar
function drawCal(firstDay, lastDate, date, monthName, year, target, dep_or_ret, searchType)
{
	firstDay = firstDay - 1;
	if (firstDay == 0){firstDay = 7};
	// constant table settings
	//var headerHeight = 50 // height of the table's header cell
    //var border = 2 // 3D height of table's border
	//var cellspacing = 4 // width of table's border
	//var headerColor = "midnightblue" // color of table's header
	//var headerSize = "+3" // size of tables header font
	//var colWidth = 60 // width of columns in table
	//var dayCellHeight = 25 // height of cells containing days of the week
	//var dayColor = "darkblue" // color of font representing week days
	//var cellHeight = 40 // height of cells representing dates in the calendar
	//var todayColor = "red" // color specifying today's date in the calendar
	//var timeColor = "purple" // color of font representing current time
	//window.alert(firstDay, lastDate, date, monthName, year, target, dep_or_ret, searchType);
	searchProductType = searchType;
	//window.alert(searchType);
	//used to re-display hidden elements of hotel search page - but in Java!!!
	//var displayBlock = '';
	//if(searchType == 'hotel'){
	//	displayBlock = 	"document.getElementById(\'city\').style.display=\'block\';";
	//}
	//else if(searchType == 'air'){
	//	displayBlock = 	"document.getElementById(\'departAirport\').style.display=\'inline\';document.getElementById(\'numberChild\').style.display=\'inline\';document.getElementById(\'numberInfant\').style.display=\'inline\';";
	//}
	
	// create basic table structure
	
	if (document.cal_calDescription){
		document.getElementById('calendarName').style.display = 'inline';
		document.getElementById('calendarName').innerHTML = document.cal_calDescription;
		document.getElementById('calTop').style.height = '50px';
	} else {
		document.getElementById('calendarName').style.display = 'none';
		document.getElementById('calTop').style.height = '28px';
	}
	
	var text = "" // initialize accumulative variable to empty string	
	text += '<TABLE class=\'tabCalendario\' CELLSPACING=0 cellpadding=0>' // table settings
	
	document.getElementById('nomeMese').innerHTML = monthName + ' ' + year;
	
	//window.alert(text);

	// variables to hold constant settings
	var openCol = ''
	var closeCol = '</TH>'
	

	// create first row of table to set column width and specify week day
	text += '<TR ALIGN="center" VALIGN="center">'
	for (var dayNum = 0; dayNum < 7; ++dayNum) {
		switch(dayNum)
		{
		 case 5:
		 {
		 openCol='<TH class="sab" >'
		 break
		 }
		 case 6:
		 {
		 openCol='<TH class="dom" >'
		  break
		 }
		 default:
		 {
		 openCol='<TH>'
		 }
		}
		 text += openCol + weekDay[dayNum] + closeCol 
		
	}
	text += '</TR>'
	
	// declaration and initialization of two variables to help with tables
	var digit = 1
	var curCell = 1
					//	alert ("g" +memGiorno + " m" +memMese+ " a" +memAnno)

	for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {
		text += '<TR ALIGN="right" VALIGN="top">'
		for (var col = 1; col <= 7; ++col) {
		switch(col)
		{
		 case 6:
		 {
		 openCol='class="sab"'
		 break
		 }
		 case 7:
		 {
		 openCol='class="dom"'
		  break
		 }
		 default:
		 {
		 openCol='class="oldays"'
		 }
		}		
			if (digit > lastDate)
				break
			if (curCell < firstDay) {
				text += '<TD></TD>';
				curCell++
			} else {
				
			var DATAnow = new Date()
			var annoN = DATAnow.getFullYear()
			var meseN = DATAnow.getMonth()
			meseN++
			var giornoN = DATAnow.getDate()

			if ((anno>annoN)||((anno==annoN) && (mese>meseN))||((anno==annoN) && (mese==meseN) && (giornoN<=digit)) || isAdmin == 1){
				/*if (DE[0]==digit && DE[1]=mese && DE[2]=anno)
					text += '<TD '+openCol+'><a href="seleziona il giorno" onclick="injData(this,\'destinatario\');document.getElementById(\'calendar\').style.display=\'none\';return false;"><strong>' + digit + '</strong></a></TD>'
				else			*/	
				/*alert(date)
				alert(monthName )
				alert(year)*/
                
                if(dep_or_ret == 1){ //if they clicked the depart calendar
                    if ((memAnno1 == anno) && (memMese1 == mese) && (memGiorno1==digit)){  //backround colors below set the color of the selected day. 'memGiorno' is the selected dep day
                        text += '<TD '+openCol+' style="text-align:center;border:1px solid #ED3E13!important"><a style="font-size:11px;">' + digit + '</a></TD>'
                    } else if ((memAnno2 == anno) && (memMese2 == mese) && (memGiorno2==digit)){    //
                        if(searchType == 'F'){
                        	text += '<TD '+openCol+' style="text-align:center;border:1px solid #ED3E13!important"><a style="font-size:11px;" href="#" onclick="injData(this,\'destinatario\', 1);document.getElementById(\'cal1\').style.display=\'none\'; mostraControlli(); return false;">' + digit + '</a></TD>'
                        } else {
                        	text += '<TD '+openCol+' style="text-align:center;border:1px solid #ED3E13!important"><a style="font-size:11px;">' + digit + '</a></TD>'
                        }
                    } else {
                        text += '<TD '+openCol+' style="text-align:center;"	><a href="#" onclick="injData(this,\'destinatario\', 1);document.getElementById(\'cal1\').style.display=\'none\'; mostraControlli(); return false;">' + digit + '</a></TD>'
                    }
                } else  if(dep_or_ret==2){   //if they clicked the return calendar
                
                    if ((memAnno2 == anno) && (memMese2 == mese) && (memGiorno2==digit)){   //backround colors below set the color of the selected day. 'memGiorno' is the selected dep day
                    
                        text += '<TD '+openCol+' style="text-align:center;border:1px solid #ED3E13!important"><a style="font-size:11px;">' + digit + '</a></TD>'
                    } else if ((memAnno1 == anno) && (memMese1 == mese) && (memGiorno1==digit)){   //backround colors below set the color of the selected day. 'memGiorno' is the selected dep day
                    //added this 'else if' to show the depart date on the return calendar.
                    
                        if(searchType == 'F') {
                        	text += '<TD '+openCol+' style="text-align:center;border:1px solid #ED3E13!important"><a style="font-size:11px;" href="#" onclick="injData(this,\'destinatario\', 2);document.getElementById(\'cal1\').style.display=\'none\'; mostraControlli(); return false;">' + digit + '</a></TD>'
                        } else {
                            text += '<TD '+openCol+' style="text-align:center;border:1px solid #ED3E13!important"><a style="font-size:11px;">' + digit + '</a></TD>'
                      	}
                    } else {
                        text += '<TD '+openCol+' style="text-align:center;"	><a href="#" onclick="injData(this,\'destinatario\', 2);document.getElementById(\'cal1\').style.display=\'none\'; mostraControlli(); return false;">' + digit + '</a></TD>'
                    }
                }
				} else {
					text += '<TD style="cursor:default!important" '+openCol+'>' + digit + '</TD>'
				}
			digit++
			}
		}
		text += '</TR>'
	}
	
	text += '</TABLE>'
	//window.alert(text);
	document.getElementById(target).innerHTML=text	
	
	
}


//render the bottom month in the calendar
function drawCal2(firstDay, lastDate, date, monthName, year, target, dep_or_ret, searchType) 
{
	firstDay = firstDay - 1;
	if (firstDay == 0){firstDay = 7};
	// constant table settings
	//var headerHeight = 50 // height of the table's header cell
    //var border = 2 // 3D height of table's border
	//var cellspacing = 4 // width of table's border
	//var headerColor = "midnightblue" // color of table's header
	//var headerSize = "+3" // size of tables header font
	//var colWidth = 60 // width of columns in table
	//var dayCellHeight = 25 // height of cells containing days of the week
	//var dayColor = "darkblue" // color of font representing week days
	//var cellHeight = 40 // height of cells representing dates in the calendar
	//var todayColor = "red" // color specifying today's date in the calendar
	//var timeColor = "purple" // color of font representing current time
	
	searchProductType = searchType;
	
	//used to re-display hidden elements of hotel search page - but in Java!!!
	//var displayBlock = '';
	//if(searchType == 'hotel'){
	//	displayBlock = 	"document.getElementById(\'city\').style.display=\'block\';";
	//}

	//else if(searchType == 'air'){
	//		displayBlock = 	"document.getElementById(\'departAirport\').style.display=\'inline\';document.getElementById(\'numberChild\').style.display=\'inline\';document.getElementById(\'numberInfant\').style.display=\'inline\';";
	//}
	
	// create basic table structure
	var text = "" // initialize accumulative variable to empty string
	text += '<TABLE class=\'tabCalendario\' CELLSPACING=0 cellpadding=0>' // table settings
		
	text += 	"<tr><td colspan='7' id='nomeMese2'>" + monthName + ' ' + year + "</td></tr>";
	

	// variables to hold constant settings
	var openCol = ''
	var closeCol = '</TH>'
	

	// create first row of table to set column width and specify week day
	text += '<TR ALIGN="center" VALIGN="center">'
	for (var dayNum = 0; dayNum < 7; ++dayNum) {
		switch(dayNum)
		{
		 case 5:
		 {
		 openCol='<TH class="sab" >'
		 break
		 }
		 case 6:
		 {
		 openCol='<TH class="dom" >'
		  break
		 }
		 default:
		 {
		 openCol='<TH>'
		 }
		}
		 text += openCol + weekDay[dayNum] + closeCol 
		
	}
	text += '</TR>'
	
	// declaration and initialization of two variables to help with tables
	var digit = 1
	var curCell = 1
	
	for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) {
		text += '<TR ALIGN="right" VALIGN="top">'
		for (var col = 1; col <= 7; ++col) {
		switch(col)
		{
		 case 6:
		 {
		 openCol='class="sab"'
		 break
		 }
		 case 7:
		 {
		 openCol='class="dom"'
		  break
		 }
		 default:
		 {
		 openCol='class="oldays"'
		 }
		}		
			if (digit > lastDate)
				break
			if (curCell < firstDay) {
				text += '<TD></TD>';
				curCell++
			} else {
				
			var DATAnow = new Date()
			var annoN = DATAnow.getFullYear()
			var meseN = DATAnow.getMonth()
			meseN++
			var giornoN = DATAnow.getDate()
	
			if ((anno>annoN)||((anno==annoN) && (mese>meseN))||((anno==annoN) && (mese==meseN)) || 1)//remove  || 1 to disable past second month
			{
				//alert ("g" +digit +" XG" +memGiorno +" m" +mese + " XM" +memMese+" a" +anno +" XA" +memAnno)
                
                if(dep_or_ret == 1) //if they clicked the depart calendar
                {
                    if ((memAnno1 == anno) && (memMese1 == mese+1) && (memGiorno1==digit))
                    {
                        text += '<TD '+openCol+' style="text-align:center;border:1px solid #ED3E13!important"><a style="font-size:12px;">' + digit + '</a></TD>'
                        //alert("evidenzio il "+digit)
                    }
                    else if ((memAnno2 == anno) && (memMese2 == mese+1) && (memGiorno2==digit))
                    {
                        if(searchType == 'F') {
	                        text += '<TD '+openCol+' style="text-align:center;border:1px solid #ED3E13!important"><a style="font-size:10px; color:#000!important" href="#" onclick="injData2(this,\'destinatario\', 1);document.getElementById(\'cal1\').style.display=\'none\'; mostraControlli(); return false;">' + digit + '</a></TD>'
                        }
                        else {
  	                      text += '<TD '+openCol+' style="text-align:center;border:1px solid #ED3E13!important"><a style="font-size:10px; color:#000!important">' + digit + '</a></TD>'
                        //alert("evidenzio il "+digit)
                      	}
                    }
                    else
                    {
                        text += '<TD '+openCol+' style="text-align:center;"	><a href="#" onclick="injData2(this,\'destinatario\', 1);document.getElementById(\'cal1\').style.display=\'none\'; mostraControlli(); return false;">' + digit + '</a></TD>'
                    }
                }
                else if(dep_or_ret==2)
                {
                    if ((memAnno2 == anno) && (memMese2 == mese+1) && (memGiorno2==digit))
                    {
                        text += '<TD '+openCol+' style="text-align:center;border:1px solid #ED3E13!important"><a>' + digit + '</a></TD>'
                        //alert("evidenzio il "+digit)
                    }
                    //added this 'else if' to show the depart date on the return calendar.
                    else if ((memAnno1 == anno) && (memMese1 == mese+1) && (memGiorno1==digit))   //backround colors below set the color of the selected day. 'memGiorno' is the selected dep day
                    {
                        if(searchType == 'F') {
                        	text += '<TD '+openCol+' style="text-align:center;border:1px solid #ED3E13!important"><a href="#" onclick="injData2(this,\'destinatario\', 2);document.getElementById(\'cal1\').style.display=\'none\'; mostraControlli(); return false;">' + digit + '</a></TD>'
                        }
                        else {
                            text += '<TD '+openCol+' style="text-align:center;border:1px solid #ED3E13!important"><a style="font-size:10px; >' + digit + '</a></TD>'
                      	}
                    }
                    else
                    {
                        text += '<TD '+openCol+' style="text-align:center;"	><a href="#" onclick="injData2(this,\'destinatario\', 2);document.getElementById(\'cal1\').style.display=\'none\'; mostraControlli(); return false;">' + digit + '</a></TD>'
                    }
                }
            }
			else
				text += '<TD style="cursor:default!important" '+openCol+'> ' + digit + '</TD>'
			digit++
			}
		}
		text += '</TR>'
	}
	
	text += '</TABLE>'
	if(dep_or_ret == 1) {
		textNextPrev = "<div><a class='sx' href='javascript:previousMonth(2, 1)'>" + previousLabel + "</a><a class='dx' href='javascript:nextMonth(2, 1)'>" + nextLabel + "</a></div>"
	} else if(dep_or_ret == 2) {
		textNextPrev = "<div><a class='sx' href='javascript:previousMonth(2, 2)'>" + previousLabel + "</a><a class='dx' href='javascript:nextMonth(2, 2)'>" + nextLabel + "</a></div>"
	}
	document.getElementById('nextPrev').innerHTML=textNextPrev;
	document.getElementById(target).innerHTML=text
}


function previousMonth(perc, dep_ret) //move to previous month
{
    mese=mese-perc;

    if(mese == -1) //it was Jan when they hit back, display Nov & Dec
    {   
        mese=11;
        anno--;
    }
    else if(mese == 0)//it was Feb when they hit back, display Dec & Jan
    {
        mese=12;
        anno--;
    }

    show_date = new Date(mese+"/6"+"/"+anno);
    now = new Date(mese+"/6"+"/"+anno);

    year = now.getFullYear();
    month = now.getMonth();
    monthName = getMonthName(month);
    date = now.getDate();
    now = null;
    firstDayInstance = new Date(year, month, 1);
    firstDay = firstDayInstance.getDay();
    firstDayInstance = null;
    days = getDays(month, year);
    
    monthName2 = getMonthName(month+1);
    firstDayInstance2 = new Date(year, month+1, 1);
    firstDay2 = firstDayInstance2.getDay();
    days2 = getDays(month+1, year);

    drawCal(firstDay + 1, days, date, monthName, year,'calNEW', dep_ret, searchProductType);
    document.getElementById('nomeMese').innerText= (months[mese-1] + " " + anno); //change contents of month title

    var year2 = year;
    var anno2 = anno;
    
    if(mese == 12)
    {
        monthName2 = getMonthName(0);   //set to january
        firstDayInstance2 = new Date(year+1, 0, 1); //increment year
        firstDay2 = firstDayInstance2.getDay();
        days2 = getDays(0, year+1);   //get days for january
        
        year2 += 1;
        anno2 += 1;
    }
    
    drawCal2(firstDay2 + 1, days2, date, monthName2, year2,'calNEW2', dep_ret, searchProductType);
    document.getElementById('nomeMese2').innerText= (getMonthName(mese) + " " + anno2); //change contents of month title
    
    year2 = year;
    anno2 = anno;
}

function nextMonth(perc, dep_ret) //move to next month
{
    mese=mese+perc;
    
    if (mese == 14) //it was december when they hit next, display Feb & Mar
    {
        mese=2;
        anno++;
    }
    else if(mese == 13) //it was november when they hit next, display Jan & Feb
    {
        mese=1;
        anno++;
    }
    
    show_date = new Date(mese+"/6"+"/"+anno);
    now = new Date(mese+"/6"+"/"+anno);
    
    year = now.getFullYear();
    month = now.getMonth();
    monthName = getMonthName(month);
    date = now.getDate();
    now = null;
    firstDayInstance = new Date(year, month, 1);
    firstDay = firstDayInstance.getDay();
    firstDayInstance = null;
    days = getDays(month, year);
    
    monthName2 = getMonthName(month+1);
    firstDayInstance2 = new Date(year, month+1, 1);
    firstDay2 = firstDayInstance2.getDay();
    days2 = getDays(month+1, year);

    drawCal(firstDay + 1, days, date, monthName, year,'calNEW', dep_ret, searchProductType);
    document.getElementById('nomeMese').innerText= (months[mese-1] + " " + anno); //change contents of month title
    //window.alert(months[mese-1]);
    var year2 = year;
    var anno2 = anno;
    var mese2 = mese;
    
    if(mese == 12)
    {
        monthName2 = getMonthName(0);   //set to january
        firstDayInstance2 = new Date(year+1, 0, 1); //increment year
        firstDay2 = firstDayInstance2.getDay();
        days2 = getDays(0, year+1);   //get days for january
        
        year2 += 1;
        anno2 += 1;
        mese2 = 0;
    }
    
    drawCal2(firstDay2 + 1, days2, date, monthName2, year2,'calNEW2', dep_ret, searchProductType);
    document.getElementById('nomeMese2').innerText= (months[mese2] + " " + anno2); //change contents of month title
    
    year2 = year;
    anno2 = anno;
    mese2 = mese;
}

function injData(who,where,dep_or_ret){
	//alert(eval(who));
	//alert ("g" + DE[0] + " m" + DE[0]+ " a" +DE[0])
	var day = who.innerHTML;    //stores the day selected in the top month
	var month = ""+eval(mese); //convert to string
	var year = anno;

	//Pad the month and day is required	
	if(day.length==1) day = '0'+day;
	if(month.length==1) month = '0'+month;
	//where='txtDepartureDateTime';
	document.getElementById(eval(where)).value=day+"/"+(month)+"/"+year
	/*DE[0]=who.innerHTML
	DE[1]=mese
	DE[2]=anno
	*/
	//alert(who.innerText+"/"+mese+"/"+anno)
		
	if(dep_or_ret==1)
	{
        memGiorno1=who.innerHTML;
        memMese1=mese;
        memAnno1=anno;
	}
    else if(dep_or_ret==2)
    {
        memGiorno2=who.innerHTML;
        memMese2=mese;
        memAnno2=anno;
    }
    if (document.cal_formCallback){
    	setTimeout(document.cal_formCallback + ";", 100);
    }
	showSelects();
	//alert ("g" +memGiorno + " m" +memMese+ " a" +memAnno)
}
function injData2(who,where, dep_or_ret)
{
		//alert(eval(who));
	
	var day = who.innerHTML;    //stores the day selected in the bottom month
	var month = ""+eval(mese+1); //convert to string
	var year = anno;
    
    //Alan: above code doesnt allow for top month being december, results in bottom month being 13 instead of 1
    if(month == 13)
    {
        month = ""+eval(01);  //set to january of next year
        year++;
    }
    
	//Pad the month and day is required	
	if(day.length==1) day = '0'+day;
	if(month.length==1) month = '0'+month;
	a = document.getElementById(eval(where));
	document.getElementById(eval(where)).value=day+"/"+(month)+"/"+year
		
	if(dep_or_ret==1){
		memGiorno1=who.innerHTML;
		memMese1=mese+1;
		memAnno1=anno;
	} else if (dep_or_ret==2) {
		memGiorno2=who.innerHTML
		memMese2=mese+1
		memAnno2=anno
	}
    if (document.cal_formCallback){
    	setTimeout(document.cal_formCallback + ";", 100);
    }
	//alert(memGiorno+"/"+memMese+"/"+memAnno)
	showSelects();

}

function getTheDay(aText){
	myDays= ["Domenica","Lunedi","Martedi","Mercoledi","Giovedi","Venerdi","Sabato","Domenica"]
	myDate=new Date(eval('"'+aText+'"'))
	document.write(myDays[myDate.getDay()]);
}



//Introdotta per compatibilità Gestione visualizzazione controlli
function mostraControlli(){}
    
    
//Introdotta per compatibilità Gestione visualizzazione controlli
function nascondiControlli(){}
    
var now = null;
var show_date = null;
var anno = null;
var mese = null;
var memorizzaGiorno=0;
        
initCalendar();
        
function initCalendar(){
    // calendario
    now = new Date();			
    show_date = new Date();		
    anno=show_date.getFullYear();
    mese=show_date.getMonth()+1;
 }        
// gestione calendario in NLS
var destinatario;

// stores the selected day/month/year for depart (1) and return (2)
var memGiorno1=0
var memMese1=0
var memAnno1=0
var memGiorno2=0
var memMese2=0
var memAnno2=0

//called when page 1st loads
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth();
//window.alert(month);
var monthName = getMonthName(month);
//window.alert("MESE:"+monthName);

var date = now.getDate();
now = null;
var firstDayInstance = new Date(year, month, 1);

var firstDay = firstDayInstance.getDay();

firstDayInstance = null;
var days = getDays(month, year);
var monthName2 = getMonthName(month+1);
var firstDayInstance2 = new Date(year, month+1, 1);
var firstDay2 = firstDayInstance2.getDay();
var days2 = getDays(month+1, year);
var days3 = getDays(0, year+1); //used when bottom panel displays january

function hideSelects(){
	objs = document.getElementsByTagName("select");
	for (i = 0; i < objs.length; i++){
		obj = objs[i];
		obj.style.visibility = 'hidden';
	}
}

function showSelects(){
	objs = document.getElementsByTagName("select");
	for (i = 0; i < objs.length; i++){
		obj = objs[i];
		obj.style.visibility = 'visible';
	}
}

function ridisegnaCalendari(dep_or_ret, searchType){   //called each time the calendar is opened. dep_or_ret is 1 (depart) or 2 (return)
	hideSelects();
	//window.alert("MESE:" +monthName2);
	//render top month
	//window.alert("MESE:"+monthName);
  drawCal(firstDay + 1, days, date, monthName, year,'calNEW', dep_or_ret, searchType);
	//render bottom month
	//if(monthName == "December" || monthName == "Dicembre")
	if(month == 11){
		drawCal2(firstDay2 + 1, days3, date, monthName2, year+1,'calNEW2', dep_or_ret, searchType);
	} else {
		drawCal2(firstDay2 + 1, days2, date, monthName2, year,'calNEW2', dep_or_ret, searchType);
	}
}

	function getPositions(obj){
		var el = obj;
		var pL = 0;
		while(el){
			pL+=el.offsetLeft;
			el=el.offsetParent;
		}
		var el = obj;
		var pT = 0;
		while(el){
			pT+=el.offsetTop;
			el=el.offsetParent;
		}
		pos = new Array(pL, pT);
		return pos;	
	}
