function show_calendar(str_target, lang, str_datetime){
var lang = lang;
if (lang=="en"){
var arr_months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var week_days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
}
else if (lang=="fr"){
var arr_months = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"];
var week_days = ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"];
}
else if (lang=="de"){
var arr_months = ["Januar", "Februar", "M&auml;rz", "April", "Mai", "Juni", "Juli", "August", "September", "Okctober", "November", "Dezember"];
var week_days = ["Son", "Mon", "Die", "Mit", "Don", "Fre", "Sam"];
}
else if (lang=="es"){
var arr_months = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];
var week_days = ["Dom", "Lun", "Mar", "Mié", "Jue", "Vie", "S&aacute;b"];
}
else{
var arr_months = ["Gennaio", "Febbario", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"];
var week_days = ["Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"];
}

var n_weekstart = 0; // 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);
 
  // html generation (feel free to tune it for your particular application)
  // print calendar header
  var str_buffer = new String("<html>\n" +
                              "<head>\n" +
                              "<title>Calendar</title>\n" +
					"<LINK rel=\"stylesheet\" href=\"font.css\" type=\"text/css\">\n" +
                              "</head>\n" +
                              "<body>\n" +
                              "<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\">\n<Tbody>\n" +
                              "<tr><td bgcolor=\"#000000\">\n" +
                              "<table cellspacing=\"1\" cellpadding=\"2\" border=\"0\" width=\"100%\">\n" +
                              "<tr>\n <td bgcolor=\"#ff0000\"><a href=\"javascript:window.opener.show_calendar('" +
                              str_target +
					"', '"+ lang +"', '" +
                              dt2dtstr(dt_prev_month) +
                              " ' + document.cal.time.value);\">" +
                              "<img src=\"images/freccia_sx2.gif\" width=\"10\" height=\"9\" border=\"0\"" +
                              " alt=\"" +
                              arr_months[dt_datetime.getMonth()-1] +
                              "\"></a></td>\n" +
                              " <td bgcolor=\"#ff0000\" colspan=\"5\" align=\"center\" valign=\"middle\">" +
                              "<font color=\"#FFFF80\" class=\"corpo\">" +
                              arr_months[dt_datetime.getMonth()] +
                              " " +
                              dt_datetime.getFullYear() +
                              "</font></td>\n" +
                              " <td bgcolor=\"#ff0000\" align=\"right\"><a href=\"javascript:window.opener.show_calendar('" +
                              str_target +
					"', '"+ lang +"', '" +
                              dt2dtstr(dt_next_month) +
                              " ' + document.cal.time.value);\">" +
                              "<img src=\"images/freccia_dx2.gif\" width=\"10\" height=\"9\" border=\"0\"" +
                              " alt=\"" +
                              arr_months[dt_datetime.getMonth()+1] +
                              "\"></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=\"#CCCCCC\" align=\"center\">" +
    "<font color=\"white\" class=\"corpo\">" +
    week_days[(n_weekstart + n) % 7] +
    "</font></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++)
        {
          if (dt_current_day.getDate() == dt_datetime.getDate() &&
              dt_current_day.getMonth() == dt_datetime.getMonth())
              // print current date
              str_buffer += " <td bgcolor=\"#FF0000\" align=\"right\">";
          else if (dt_current_day.getDay() == 0 || dt_current_day.getDay() == 6)
                   // weekend days
                   str_buffer += " <td bgcolor=\"#E0ECE8\" align=\"right\">";
          else // print working days of current month
               str_buffer += " <td bgcolor=\"white\" align=\"right\">";

          if (dt_current_day.getMonth() == dt_datetime.getMonth())
              // print days of current month

              str_buffer += "<a href=\"javascript:window.opener." +
                            str_target +
                            ".value='" + dt2dtstr(dt_current_day) + "'; window.close();\">" +
                            "<font color=\"black\" class=\"corpo\">";
          else // print days of other months
               str_buffer += "<a href=\"javascript:window.opener." +
                             str_target +
                             ".value='" + dt2dtstr(dt_current_day) + "'; window.close();\">" +
                             "<font color=\"gray\" class=\"corpo\">";
 
          str_buffer += dt_current_day.getDate() + "</font></a></td>\n";
          dt_current_day.setDate(dt_current_day.getDate() + 1);
        }
 
      // print row footer
      str_buffer += "</tr>\n";
    }

  // print calendar footer
  str_buffer += "<tr bgcolor=\"#000000\" ><td colspan=\"7\" height=\"15\" class=\"corpo2\" align=\"center\" valign=\"middle\" bgcolor=\"#ff0000\">\n<form name=\"cal\" style=\"margin:0px;\">" +
                "<input type=\"hidden\" name=\"time\" value=\""+dt2tmstr(dt_datetime) +
                "\"><a href=\"javascript:window.close();\"><font color=\"#FFFF80\">Close Window</font></a>\n" +
		    "</form>\n</td></tr>\n" +
                "</Tbody>\n</table>\n" +
                "</td>\n</tr>\n</Tbody>\n</table>\n" +
                "</body>\n" +
                "</html>\n";

 
  var vWinCal = window.open("", "Calendario", "width=250,height=190,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{1,2})\/(\d{1,2})\/(\d{4})\s+(\d{1,2})\:(\d{1,2})\:(\d{1,2})$/;
 
  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){
//var dt = dt_datetime.getDate() + "-";

var day = dt_datetime.getDate();
var month = dt_datetime.getMonth() + 1;
var dt = ((day < 10) ? "0" + day : day) + "/";
dt += ((month < 10) ? "0" + month : month);
dt += "/" + dt_datetime.getFullYear();
return(dt);
}
 
function dt2tmstr(dt_datetime){
var dt = dt_datetime.getHours() + ":";
dt += ((dt_datetime.getMinutes() < 10) ? "0" + dt_datetime.getMinutes() : dt_datetime.getMinutes()) + ":";
dt += ((dt_datetime.getSeconds() < 10) ? "0" + dt_datetime.getSeconds() : dt_datetime.getSeconds());
return(dt);
}


function people(lng){
var colore_normale = "#FFFFFF";
var colore_avviso = "#FFFFC0";
//--Applico il colore base alle text--
document.theform.nome.style.backgroundColor = colore_normale;
document.theform.cognome.style.backgroundColor = colore_normale;
document.theform.indirizzo.style.backgroundColor = colore_normale;
document.theform.citta.style.backgroundColor = colore_normale;
document.theform.telefono.style.backgroundColor = colore_normale;
document.theform.email.style.backgroundColor = colore_normale;
document.theform.arrivo.style.backgroundColor = colore_normale;
document.theform.partenza.style.backgroundColor = colore_normale;
document.theform.ora_arrivo.style.backgroundColor = colore_normale;
document.theform.n_persone.style.backgroundColor = colore_normale;
document.theform.camera1.style.backgroundColor = colore_normale;
document.theform.camera2.style.backgroundColor = colore_normale;
document.theform.camera3.style.backgroundColor = colore_normale;
document.theform.camera4.style.backgroundColor = colore_normale;

var camera1 = document.theform.camera1.options.selectedIndex;
var camera2 = document.theform.camera2.options.selectedIndex;
var camera3 = document.theform.camera3.options.selectedIndex;
var camera4 = document.theform.camera4.options.selectedIndex;

var persone = document.theform.n_persone.options.selectedIndex;
var tot_1 = 0;
var tot_2 = 0;
var tot_3 = 0;
var tot_4 = 0;

var somma = 0;

tot_1 = parseInt(camera1) * 1;
tot_2 = parseInt(camera2) * 2;
tot_3 = parseInt(camera3) * 2;
tot_4 = parseInt(camera4) * 3;

somma = tot_1 + tot_2 + tot_3 + tot_4;

if (lng=="en"){
var err_1 = "Please insert the Surname."
var err_2 = "Please insert the Name."
var err_3 = "Please insert the Town."
var err_4 = "Please insert the Phone Number or Mobile Phone."
var err_5 = "Please insert the Email."
var err_6 = "Attention ! Email wrong."
var err_7 = "Please insert the Arrival Date."
var err_8 = "Please insert the Departure Date."
var err_9 = "Please insert the Arrival Time."
var err_10 = "Attention ! The number of people is greater to the number of selected beds."
var err_11 = "Attention ! The number of people is lower to the number of selected beds."
var err_12 = "Attention ! Choose a typology of lodging."
var err_13 = "Please insert the N. of People."
var err_14 = "Attention ! Our property can entertain maximum 17 people."
}
else if (lng=="es"){
var err_1 = "¡Atención! Insertar el Apellido."
var err_2 = "¡Atención! Insertar el Nombre."
var err_3 = "¡Atención! Insertar la Ciudad."
var err_4 = "¡Atención! Insertar el Teléfono o Cell."
var err_5 = "¡Atención! Insertar el Email."
var err_6 = "Atención! Insertar el Email corregido."
var err_7 = "¡Atención! Insertar el Día de Llegada."
var err_8 = "¡Atención! Insertar el Día de Salida."
var err_9 = "¡Atención! Insertar el horario de Llegada."
var err_10 = "¡Atención! El número max de personas integradas es superior a los sitios cama seleccionada."
var err_11 = "¡Atención! El número max de personas integradas es inferior a los sitios cama seleccionada."
var err_12 = "¡Atención! Eliges una tipología de habitación."
var err_13 = "¡Atención! Insertar el número de las personas."
var err_14 = "¡Atención! Nuestra estructura puede hospedar un máximo de 17 personas."
}
else {
var err_1 = "Attenzione ! Inserire il Cognome."
var err_2 = "Attenzione ! Inserire il Nome."
var err_3 = "Attenzione ! Inserire la Città."
var err_4 = "Attenzione ! Inserire il Telefono o Cell."
var err_5 = "Attenzione ! Inserire l\'Email."
var err_6 = "Attenzione! Inserire l\'E-mail corretta."
var err_7 = "Attenzione ! Inserire il Giorno di Arrivo."
var err_8 = "Attenzione ! Inserire il Giorno di Partenza."
var err_9 = "Attenzione ! Inserire l\'Orario di Arrivo."
var err_10 = "Attenzione ! Il numero max di persone inserite è superiore ai posti letto selezionati."
var err_11 = "Attenzione ! Il numero max di persone inserite è inferiore ai posti letto selezionati."
var err_12 = "Attenzione ! Scegli una tipologia di stanza."
var err_13 = "Attenzione ! Inserire il numero delle persone."
var err_14 = "Attenzione ! La nostra struttura può ospitare un massimo di 17 persone."
}

if (document.theform.cognome.value==""){
alert(err_1);
document.theform.cognome.focus();
document.theform.cognome.style.backgroundColor = colore_avviso;
return false;
}
if (document.theform.nome.value==""){
alert(err_2);
document.theform.nome.focus();
document.theform.nome.style.backgroundColor = colore_avviso;
return false;
}
if (document.theform.citta.value==""){
alert(err_3);
document.theform.citta.focus();
document.theform.citta.style.backgroundColor = colore_avviso;
return false;
}
if (document.theform.telefono.value==""){
alert(err_4);
document.theform.telefono.focus();
document.theform.telefono.style.backgroundColor = colore_avviso;
return false;
}
if (document.theform.email.value==""){
alert(err_5);
document.theform.email.focus();
document.theform.email.style.backgroundColor = colore_avviso;
return false;
}
var x = document.theform.email.value;
var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!(filter.test(x))){
alert (err_6);
document.theform.email.focus();
document.theform.email.style.backgroundColor = colore_avviso;
return false;
}
if (document.theform.arrivo.value==""){
alert(err_7);
document.theform.arrivo.focus();
document.theform.arrivo.style.backgroundColor = colore_avviso;
return false;
}
if (document.theform.partenza.value==""){
alert(err_8);
document.theform.partenza.focus();
document.theform.partenza.style.backgroundColor = colore_avviso;
return false;
}
if (document.theform.ora_arrivo.value=="0"){
alert(err_9);
document.theform.ora_arrivo.focus();
document.theform.ora_arrivo.style.backgroundColor = colore_avviso;
return false;
}
if (somma < persone){
alert(err_10);
document.theform.n_persone.focus();
document.theform.n_persone.style.backgroundColor = colore_avviso;
return false;
}
if (somma > persone){
alert(err_11);
document.theform.n_persone.focus();
document.theform.n_persone.style.backgroundColor = colore_avviso;
return false;
}
if (somma==0){
alert(err_12);
document.theform.camera1.style.backgroundColor = colore_avviso;
document.theform.camera2.style.backgroundColor = colore_avviso;
document.theform.camera3.style.backgroundColor = colore_avviso;
document.theform.camera4.style.backgroundColor = colore_avviso;
return false;
}

if (persone==0){
alert(err_13);
document.theform.n_persone.focus();
document.theform.n_persone.style.backgroundColor = colore_avviso;
return false;
}

//if (somma > 17){
//alert(err_14);
//document.theform.camera1.style.backgroundColor = colore_avviso;
//document.theform.camera2.style.backgroundColor = colore_avviso;
//document.theform.camera3.style.backgroundColor = colore_avviso;
//document.theform.camera4.style.backgroundColor = colore_avviso;
//return false;
//}
}

// funzione per far comparire il pop-up della privacy
function apriFinestra(page){
var winOpenSquadra;
winOpened = window.open(page,"Squadra","directories=no,status=no,statusbar=no,resizable=no,menubar=no,scrollbars=yes,toolbar=no,width=770,height=530,left=10,top=10");
}



//funzione che mi permette di centrare la popup
function resizeWin(Altezza,Larghezza){
var sizeH= Altezza;
var sizeW= Larghezza;
var posH=0;
var posW=0;

if (sizeH<=screen.height)
sizeH=30+sizeH;
if (sizeW<=screen.width)
sizeW=30+sizeW
self.resizeTo(sizeW,sizeH);
if (((screen.height-sizeH)/2)>0)
posW=((screen.height-sizeH)/2);
if (((screen.width-sizeW)/2)>0)
posH=((screen.width-sizeW)/2);
self.moveTo(posW,posH);
}

