var oldLink = null;

function selected(cal, date) {
  cal.sel.value = date;
  if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel2" || cal.sel.id == "sel3" || cal.sel.id == "sel4"))
    cal.callCloseHandler();
}

function closeHandler(cal) {
  cal.hide();                        // hide the calendar
  _dynarch_popupCalendar = null;
}

function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (_dynarch_popupCalendar != null) {
    _dynarch_popupCalendar.hide();                 
  } else {
    
    var cal = new Calendar(1, null, selected, closeHandler);
    if (typeof showsTime == "string") {
      cal.showsTime = true;
      cal.time24 = (showsTime == "24");
    }
    if (showsOtherMonths) {
      cal.showsOtherMonths = true;
    }
    _dynarch_popupCalendar = cal;                  
    cal.setRange(1900, 2070);        
    cal.create();
  }
  _dynarch_popupCalendar.setDateFormat(format);    
  _dynarch_popupCalendar.parseDate(el.value);      
  _dynarch_popupCalendar.sel = el;                 

  _dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");

  return false;
}

var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
var WEEK = 7 * DAY;

function isDisabled(date) {
  var today = new Date();
  return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
}

function flatSelected(cal, date) {
  var el = document.getElementById("preview");
  el.innerHTML = date;
}

function showFlatCalendar() {
  var parent = document.getElementById("display");

  var cal = new Calendar(0, null, flatSelected);

  cal.weekNumbers = false;

  cal.setDisabledHandler(isDisabled);
  cal.setDateFormat("%A, %B %e");

  cal.create(parent);

  cal.show();
}

function trim(stringa){
while (stringa.substring(0,1) == ' '){
stringa = stringa.substring(1, stringa.length);}
while (stringa.substring(stringa.length-1, stringa.length) == ' '){
stringa = stringa.substring(0,stringa.length-1);}
return stringa;}

function check_mod(){
   today = new Date(); 
   giorno = today.getDate() >= 10 ? today.getDate() : '0'+today.getDate();
   mese = (today.getMonth() + 1) >= 10 ? (today.getMonth() + 1) : '0'+ (today.getMonth() + 1); 
   oggisc = giorno + "/" + mese + "/" + today.getFullYear();
   var oggi = (oggisc.slice(6,10)) + (oggisc.slice(3,5)) + (oggisc.slice(0,2));

   var nome = trim(document.prn_mod.prn_n.value);
   var cognome = trim(document.prn_mod.prn_c.value);
   var telefono = trim(document.prn_mod.prn_tel.value);
   var mail = document.prn_mod.prn_ml.value;
   var emailtest = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   var typis = document.prn_mod.type_prn.value;
   var testo = trim(document.prn_mod.prn_mx.value);


  // var arrival = (arrivo.slice(6,10)) + (arrivo.slice(3,5)) + (arrivo.slice(0,2));
  // var partval = (partenza.slice(6,10)) + (partenza.slice(3,5)) + (partenza.slice(0,2));
   //var checkdt = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;

if (nome == '' || nome == 'undefined')
   {
   alert ("Inserire il nome!")
   document.prn_mod.prn_n.focus();
   return false;
   }
else if (cognome == '' || cognome == 'undefined')
   {
   alert ("Inserire il cognome!");
   document.prn_mod.prn_c.focus();
   return false;
   }
else if (telefono == '' || telefono == 'undefined')
   {
   alert ("Inserire un recapito telefonico!");
   document.prn_mod.prn_tel.focus();
   return false;
   }
else if(mail == "" || mail =="undefined")
   {
   alert ("Inserire indirizzo e-mail!");
   document.prn_mod.prn_ml.focus();
   return false;
   }
else if (!emailtest.test(mail)){
   alert ("Inserire un indirizzo e-mail valido!");
   document.prn_mod.prn_ml.focus();
   return false;
   }
   else if (typis == "0" || typis =="undefined"){
   alert ("Selezionare il tipo di prenotazione:\nHotel | Ristorante | Ricevimento");
   document.prn_mod.type_prn.focus();
   return false;
   }
else
   {document.prn_mod.action = "js/send_prn.php";
    document.prn_mod.submit();
}
}


