

function update_date(obj)

{

	var str_datetime = document.form_prenotazione.arrivo_giorno.value+"-"+obj.value;

	//alert(str_datetime);

	var dt_datetime = (str_datetime == null || str_datetime =="" ?  new Date() : str2dt(str_datetime));

	var dt_new = new Date(dt_datetime);

	dt_new.setDate(dt_datetime.getDate()+1);

	var a;

	if(dt_new.getDate() < 10) a = "0"+dt_new.getDate(); else a = dt_new.getDate();

	var c;

	var d = dt_new.getMonth()+1;

	if(dt_new.getMonth() < 9) c = "0"+d; else c = d;

	var b = c+"-"+dt_new.getFullYear();

	document.form_prenotazione.partenza_giorno.value = a;

	document.form_prenotazione.partenza_mese_anno.value = b;



}



function update_date1(obj_form)

{

	var str_datetime = obj_form.arrivo_giorno.value+"-"+obj_form.arrivo_mese_anno.value;

	//alert(str_datetime);

	var dt_datetime = (str_datetime == null || str_datetime =="" ?  new Date() : str2dt(str_datetime));

	var dt_new = new Date(dt_datetime);

	dt_new.setDate(dt_datetime.getDate()+1);

	var a;

	if(dt_new.getDate() < 10) a = "0"+dt_new.getDate(); else a = dt_new.getDate();

	var c;

	//alert(dt_new.getMonth());

	var d = dt_new.getMonth()+1;

	if(dt_new.getMonth() < 9) c = "0"+d; else c = d;	var b = c+"-"+dt_new.getFullYear();



	obj_form.partenza_giorno.value = a;

	obj_form.partenza_mese_anno.value = b;



}








function show_calendar2(lng, str_target, str_datetime)

{

	if(lng == 'it')

	{

		var arr_months = ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno",

		"Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"];

		var week_days = ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"];

	}

	else if(lng == 'en')

	{

		var arr_months = ["January", "February", "March", "April", "May", "June",

		"July", "August", "September", "October", "November", "December"];

		var week_days = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];

	}

	else if(lng == 'de')

	{

		var arr_months = ["Januar", "Februar", "Marz", "April", "Mai", "Juni",

		"Juli", "August", "September", "Oktober", "November", "Dezember"];

		var week_days = ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"];

	}

	else

	{

		var arr_months = ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno",

		"Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"];

		var week_days = ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"];

	}

	

	var n_weekstart = 1; // day week starts from (normally 0 or 1)



	var dt_datetime = (str_datetime == null || str_datetime =="" ?  new Date() : str2dt(str_datetime));

	var dt_prev_month = new Date(dt_datetime);

	dt_prev_month.setMonth(dt_datetime.getMonth()-1);

	var dt_next_month = new Date(dt_datetime);

	dt_next_month.setMonth(dt_datetime.getMonth()+1);

	var dt_firstday = new Date(dt_datetime);

	dt_firstday.setDate(1);

	dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7);

	var dt_lastday = new Date(dt_next_month);

	dt_lastday.setDate(0);



	var dt_dataselect = new Date(dt_datetime);

	

	// html generation (feel free to tune it for your particular application)

	// print calendar header

	

	var stringa = new String ();

	

	for(k=0;k<12;k++)

	{

		if(k == dt_datetime.getMonth())

		stringa += "\n<option value=\""+dt_datetime.getDate()+"-"+(k+1)+"-"+dt_datetime.getFullYear()+"\" selected>"+arr_months[k]+" "+dt_datetime.getFullYear()+"</option>";	

		else

		stringa += "\n<option value=\""+dt_datetime.getDate()+"-"+(k+1)+"-"+dt_datetime.getFullYear()+"\">"+arr_months[k]+" "+dt_datetime.getFullYear()+"</option>";	

	}



	for(k=0;k<12;k++)

	{

		stringa += "\n<option value=\""+dt_datetime.getDate()+"-"+(k+1)+"-"+(dt_datetime.getFullYear()+1)+"\">"+arr_months[k]+" "+(dt_datetime.getFullYear()+1)+"</option>";	

	}

	

	var str_buffer = new String (

		"<html>\n"+

		"<head>\n"+

		"	<title>Calendar</title>\n"+

		"</head>\n"+

		"<body bgcolor=\"#cccccc\">\n"+

		"<table class=\"clsOTable\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"+

		"<tr><td bgcolor=\"#f6a704\">\n"+

		"<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"100%\">\n"+

		"<tr>\n	<td bgcolor=\"#f6a704\"><a style=\"text-decoration:none\" href=\"javascript:window.opener.show_calendar2('"+lng+"', '"+

		str_target+"', '"+dt2dtstr(dt_prev_month)+"');\">"+

		"<div style=\"color:white;font-size:17px;font-family:Arial;\">&laquo;</div></a></td>\n"+

		"	<td bgcolor=\"#f6a704\" colspan=\"5\" align=\"center\">"+

		"<font color=\"white\" face=\"arial, verdana\" size=\"2\">"+

		"<select class=\"modulo\" id=\"select_mese\" name=\"mese\""+

		"onchange=\"javascript:window.opener.show_calendar2('"+lng+"', '"+

		str_target+"', this.value);\""+

		">"+stringa+"</select> "+

		"</td>\n"+

		"<td bgcolor=\"#f6a704\" align=\"center\"><a style=\"text-decoration:none\" href=\"javascript:window.opener.show_calendar2('"+lng+"','"

		+str_target+"', '"+dt2dtstr(dt_next_month)+"');\">"+

		"<div style=\"color:white;font-size:17px;font-family:Arial;\">&raquo;</div></a></td>\n</tr>\n"

	);



	var dt_current_day = new Date(dt_firstday);

	// print weekdays titles

	str_buffer += "<tr>\n";

	for (var n=0; n<7; n++)

		str_buffer += "	<td bgcolor=\"#c5dd80\">"+

		"<div style=\"color:white;font-size:11px;font-family:Arial;\">"+

		week_days[(n_weekstart+n)%7]+"</div></td>\n";

	// print calendar table

	str_buffer += "</tr>\n";

	while (dt_current_day.getMonth() == dt_datetime.getMonth() ||

		dt_current_day.getMonth() == dt_firstday.getMonth()) {

		// print row heder

		str_buffer += "<tr>\n";

		for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {

				current=false;

				if (dt_current_day.getDate() == dt_datetime.getDate() &&

					dt_current_day.getMonth() == dt_datetime.getMonth())

					// print current date

					{str_buffer += "	<td bgcolor=\"#c42562\" align=\"center\">"; current=true;}

				else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)

					// weekend days

					str_buffer += "	<td bgcolor=\"#F7F8F9\" align=\"center\">";

				else

					// print working days of current month

					str_buffer += "	<td bgcolor=\"FFFFFF\" align=\"center\">";



				if(dt_current_day.getMonth() < 9) mese_normalizzato = '0'+(dt_current_day.getMonth()+1);

				else mese_normalizzato = dt_current_day.getMonth()+1;

				

				if(dt_current_day.getDate() < 10) giorno_normalizzato = '0'+dt_current_day.getDate();

				else giorno_normalizzato = dt_current_day.getDate();



				if (dt_current_day.getMonth() == dt_datetime.getMonth())

				{	

					if(current == true) color='white'; else color='#555555';

					// print days of current month

					

						str_buffer += "<a style=\"text-decoration:none\" href=\"javascript:window.opener."+str_target+

						".value='"+giorno_normalizzato+"-"+mese_normalizzato+"-"+dt_current_day.getFullYear()+"';"+

						" window.close();\">"+

						"<div style=\"color:"+color+";font-size:11px;font-family:Arial;\">";



				}

				else 

				{

					

						str_buffer += "<a style=\"text-decoration:none\" href=\"javascript:window.opener."+str_target+

						".value='"+giorno_normalizzato+"-"+mese_normalizzato+"-"+dt_current_day.getFullYear()+"';"+

						" window.close();\">"+

						"<div style=\"color:#cccccc;font-size:11px;font-family:Arial;\">";



				}

				str_buffer += dt_current_day.getDate()+"</div></a></td>\n";

				dt_current_day.setDate(dt_current_day.getDate()+1);

		}

		// print row footer

		str_buffer += "</tr>\n";

	}

	// print calendar footer

	str_buffer +=

		"<form name=\"cal\">\n<tr><td colspan=\"7\" bgcolor=\"#c5dd80\">"+

		"<font color=\"White\" face=\"arial, verdana\" size=\"2\">"+

		"<input type=\"hidden\" name=\"time\" value=\"\" size=\"8\" maxlength=\"8\"></font></td></tr>\n</form>\n" +

		"</table>\n" +

		"</tr>\n</td>\n</table>\n" +

		"</body>\n" +

		"</html>\n";



	var vWinCal = window.open("", "Calendar", 

		"width=200,height=200,status=no,resizable=yes,top=200,left=200");

	vWinCal.opener = self;

	var calc_doc = vWinCal.document;

	calc_doc.write (str_buffer);

	calc_doc.close();

}





function show_calendar(lng, str_target, str_datetime)

{

	if(lng == 'it')

	{

		var arr_months = ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno",

		"Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"];

		var week_days = ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"];

	}

	else if(lng == 'en')

	{

		var arr_months = ["January", "February", "March", "April", "May", "June",

		"July", "August", "September", "October", "November", "December"];

		var week_days = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];

	}

	else if(lng == 'de')

	{

		var arr_months = ["Januar", "Februar", "Marz", "April", "Mai", "Juni",

		"Juli", "August", "September", "Oktober", "November", "Dezember"];

		var week_days = ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"];

	}

	else

	{

		var arr_months = ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno",

		"Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"];

		var week_days = ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"];

	}

	

	var n_weekstart = 1; // day week starts from (normally 0 or 1)



	var dt_datetime = (str_datetime == null || str_datetime =="" ?  new Date() : str2dt(str_datetime));

	var dt_prev_month = new Date(dt_datetime);

	dt_prev_month.setMonth(dt_datetime.getMonth()-1);

	var dt_next_month = new Date(dt_datetime);

	dt_next_month.setMonth(dt_datetime.getMonth()+1);

	var dt_firstday = new Date(dt_datetime);

	dt_firstday.setDate(1);

	dt_firstday.setDate(1-(7+dt_firstday.getDay()-n_weekstart)%7);

	var dt_lastday = new Date(dt_next_month);

	dt_lastday.setDate(0);



	var dt_dataselect = new Date(dt_datetime);

	

	// html generation (feel free to tune it for your particular application)

	// print calendar header

	

	var stringa = new String ();

	

	for(k=0;k<12;k++)

	{

		if(k == dt_datetime.getMonth())

		stringa += "\n<option value=\""+dt_datetime.getDate()+"-"+(k+1)+"-"+dt_datetime.getFullYear()+"\" selected>"+arr_months[k]+" "+dt_datetime.getFullYear()+"</option>";	

		else

		stringa += "\n<option value=\""+dt_datetime.getDate()+"-"+(k+1)+"-"+dt_datetime.getFullYear()+"\">"+arr_months[k]+" "+dt_datetime.getFullYear()+"</option>";	

	}



	for(k=0;k<12;k++)

	{

		stringa += "\n<option value=\""+dt_datetime.getDate()+"-"+(k+1)+"-"+(dt_datetime.getFullYear()+1)+"\">"+arr_months[k]+" "+(dt_datetime.getFullYear()+1)+"</option>";	

	}

	

	var str_buffer = new String (

		"<html>\n"+

		"<head>\n"+

		"	<title>Calendar</title>\n"+

		"</head>\n"+

		"<body bgcolor=\"#cccccc\">\n"+

		"<table class=\"clsOTable\" cellspacing=\"0\" border=\"0\" width=\"100%\">\n"+

		"<tr><td bgcolor=\"#f6a704\">\n"+

		"<table cellspacing=\"1\" cellpadding=\"3\" border=\"0\" width=\"100%\">\n"+

		"<tr>\n	<td bgcolor=\"#f6a704\"><a style=\"text-decoration:none\" href=\"javascript:window.opener.show_calendar('"+lng+"', '"+

		str_target+"', '"+dt2dtstr(dt_prev_month)+"');\">"+

		"<div style=\"color:white;font-size:17px;font-family:Arial;\">&laquo;</div></a></td>\n"+

		"	<td bgcolor=\"#f6a704\" colspan=\"5\" align=\"center\">"+

		"<font color=\"white\" face=\"arial, verdana\" size=\"2\">"+

		"<select class=\"modulo\" id=\"select_mese\" name=\"mese\""+

		"onchange=\"javascript:window.opener.show_calendar('"+lng+"', '"+

		str_target+"', this.value);\""+

		">"+stringa+"</select> "+

		"</td>\n"+

		"<td bgcolor=\"#f6a704\" align=\"center\"><a style=\"text-decoration:none\" href=\"javascript:window.opener.show_calendar('"+lng+"','"

		+str_target+"', '"+dt2dtstr(dt_next_month)+"');\">"+

		"<div style=\"color:white;font-size:17px;font-family:Arial;\">&raquo;</div></a></td>\n</tr>\n"

	);



	var dt_current_day = new Date(dt_firstday);

	// print weekdays titles

	str_buffer += "<tr>\n";

	for (var n=0; n<7; n++)

		str_buffer += "	<td bgcolor=\"#c5dd80\">"+

		"<div style=\"color:white;font-size:11px;font-family:Arial;\">"+

		week_days[(n_weekstart+n)%7]+"</div></td>\n";

	// print calendar table

	str_buffer += "</tr>\n";

	while (dt_current_day.getMonth() == dt_datetime.getMonth() ||

		dt_current_day.getMonth() == dt_firstday.getMonth()) {

		// print row heder

		str_buffer += "<tr>\n";

		for (var n_current_wday=0; n_current_wday<7; n_current_wday++) {

				var current=false;

				if (dt_current_day.getDate() == dt_datetime.getDate() &&

					dt_current_day.getMonth() == dt_datetime.getMonth())

					// print current date

					{str_buffer += "	<td bgcolor=\"#c42562\" align=\"center\">"; current=true;}

				else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)

					// weekend days

					str_buffer += "	<td bgcolor=\"#F7F8F9\" align=\"center\">";

				else

					// print working days of current month

					str_buffer += "	<td bgcolor=\"FFFFFF\" align=\"center\">";



				if(dt_current_day.getMonth() < 9) mese_normalizzato = '0'+(dt_current_day.getMonth()+1);

				else mese_normalizzato = dt_current_day.getMonth()+1;

				

				if(dt_current_day.getDate() < 10) giorno_normalizzato = '0'+dt_current_day.getDate();

				else giorno_normalizzato = dt_current_day.getDate();



				if (dt_current_day.getMonth() == dt_datetime.getMonth())

				{	

					if(current == true) color='white'; else color='#555555';

					// print days of current month

					if(str_target == "document.form_prenotazione.partenza")

					{

						str_buffer += "<a style=\"text-decoration:none\" href=\"javascript:window.opener."+str_target+

						"_giorno.value='"+giorno_normalizzato+"'; window.opener."+str_target+

						"_mese_anno.value='"+mese_normalizzato+"-"+dt_current_day.getFullYear()+"'; window.close();\">"+

						"<div style=\"color:"+color+";font-size:11px;font-family:Arial;\">";

					}

					else

					{

						str_buffer += "<a style=\"text-decoration:none\" href=\"javascript:window.opener."+str_target+

						"_giorno.value='"+giorno_normalizzato+"'; window.opener."+str_target+

						"_mese_anno.value='"+mese_normalizzato+"-"+dt_current_day.getFullYear()+"';"+

						"window.opener.update_date1(window.opener.document.form_prenotazione); window.close();\">"+

						"<div style=\"color:"+color+";font-size:11px;font-family:Arial;\">";

					}

				}

				else 

				{

					// print days of other months

					if(str_target == "document.form_prenotazione.partenza")

					{

						str_buffer += "<a style=\"text-decoration:none\" href=\"javascript:window.opener."+str_target+

						"_giorno.value='"+giorno_normalizzato+"'; window.opener."+str_target+

						"_mese_anno.value='"+mese_normalizzato+"-"+dt_current_day.getFullYear()+"'; window.close();\">"+

						"<div style=\"color:gray;font-size:11px;font-family:Arial;\">";

					}

					else

					{

						str_buffer += "<a style=\"text-decoration:none\" href=\"javascript:window.opener."+str_target+

						"_giorno.value='"+giorno_normalizzato+"'; window.opener."+str_target+

						"_mese_anno.value='"+mese_normalizzato+"-"+dt_current_day.getFullYear()+"';"+

						"window.opener.update_date1(window.opener.document.form_prenotazione); window.close();\">"+

						"<div style=\"color:#cccccc;font-size:11px;font-family:Arial;\">";

					}

				}

				str_buffer += dt_current_day.getDate()+"</div></a></td>\n";

				dt_current_day.setDate(dt_current_day.getDate()+1);

		}

		// print row footer

		str_buffer += "</tr>\n";

	}

	// print calendar footer

	str_buffer +=

		"<form name=\"cal\">\n<tr><td colspan=\"7\" bgcolor=\"#c5dd80\">"+

		"<font color=\"White\" face=\"arial, verdana\" size=\"2\">"+

		"<input type=\"hidden\" name=\"time\" value=\"\" size=\"8\" maxlength=\"8\"></font></td></tr>\n</form>\n" +

		"</table>\n" +

		"</tr>\n</td>\n</table>\n" +

		"</body>\n" +

		"</html>\n";



	var vWinCal = window.open("", "Calendar", 

		"width=200,height=200,status=no,resizable=yes,top=200,left=200");

	vWinCal.opener = self;

	var calc_doc = vWinCal.document;

	calc_doc.write (str_buffer);

	calc_doc.close();

}

// datetime parsing and formatting routimes. modify them if you wish other datetime format

function str2dt (str_datetime) {

	var re_date = /^(\d+)\-(\d+)\-(\d+)$/;

	if (!re_date.exec(str_datetime))

		return alert("Invalid Datetime format: "+ str_datetime);

	return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1, RegExp.$4, RegExp.$5, RegExp.$6));

}

function dt2dtstr (dt_datetime) {

	return (new String (

			dt_datetime.getDate()+"-"+(dt_datetime.getMonth()+1)+"-"+dt_datetime.getFullYear()));

}

function dt2tmstr (dt_datetime) {

	return (new String (

			dt_datetime.getHours()+":"+dt_datetime.getMinutes()+":"+dt_datetime.getSeconds()));

}





