// JavaScript Document
/*
----------
VISUALIZZAZIONE STANZE TROVATE - PREZZI GIORNALIERI ON/OFF
----------
*/
var ogg;
var cnttab;
var pos;
var finalPosition;
var myTimer;
var myVar;
var cnt;
var cntfreccia;
var speed = 15;
function dettaglioOnOff(elem, elemtab, elemfreccia) {
cnt = document.getElementById(elem);
cnttab = document.getElementById(elemtab);
cntfreccia = document.getElementById(elemfreccia);
cntfreccia.src = "img/_po_freccia-det-stop.gif";
if (parseInt(cnt.style.height)>100) { //riduco
move(0);
} else { //espando
move(130);
}
}
function move(finalSize){
pos = cnt.clientHeight;
myVar = cnt.clientHeight;
finalPosition = finalSize;
clearInterval(myTimer);
resize_element(finalPosition);
}
function resize_element(size) {
if (myVar < size){
myTimer=setInterval("increaseBorder()",100);
} else if (myVar > size) {
myTimer=setInterval("decreaseBorder()",100);
} else if (myVar == size) {
} else {
alert('error from: ' + myVar + ' to: ' + size);
}
}
function increaseBorder(){
pos += speed;
if( pos <= finalPosition ){
cnt.style.height = pos + 'px';
} else if(pos > finalPosition){
clearInterval(myTimer);
cnttab.style.display = "block";
cntfreccia.src = "img/_po_freccia-det-up.gif";
cnt.style.height = "130px";
} else {
clearInterval(myTimer);
alert('error increase');
}
}
function decreaseBorder(){
cnttab.style.display = "none";
pos -= speed;
if( pos >= finalPosition ){
cnt.style.height = pos + 'px';
} else if(pos < finalPosition){
clearInterval(myTimer);
cntfreccia.src = "img/_po_freccia-det-down.gif";
cnt.style.height = "0px";
} else {
clearInterval(myTimer);
alert('error decrease');
}
}
/*
----------
GENERICHE
----------
*/
function controllaPIVA(pi)
{
if( pi == '' ) return '';
if( pi.length != 11 )
return false;
validi = "0123456789";
for( i = 0; i < 11; i++ ){
if( validi.indexOf( pi.charAt(i) ) == -1 )
return false;
}
s = 0;
for( i = 0; i <= 9; i += 2 )
s += pi.charCodeAt(i) - '0'.charCodeAt(0);
for( i = 1; i <= 9; i += 2 ){
c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
if( c > 9 ) c = c - 9;
s += c;
}
if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )
return false;
return true;
}
function bisestile(anno) {
return new Date(anno,2-1,29).getDate()==29;
}
function checkMail(email){
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/;
if (filter.test(email)) return true;
else return false;
}
function diffGiorni(anno1, mese1, giorno1, anno2, mese2, giorno2) {
var primo = new Date(anno1, mese1-1, giorno1); //Mesi javascript da 0 a 11
var secondo = new Date(anno2, mese2-1, giorno2);
var giornoMs=1000*60*60*24; //1 giorno in millisecondi
return((primo.getTime()-secondo.getTime())/(giornoMs));
}
/*
----------
FORM INSERIMENTO DATI ANAGRAFICI - CHECK GENERICO
----------
*/
function frmPrenoDatiValid(_CF) {
var oggi = new Date();
var annoCorr = oggi.getFullYear();
var ultFeb;
var pattern = /^[a-zA-Z]{1}[a-zA-Z0-9]{5,19}$/;
var pattern2 = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
var pattern3 = /^[a-zA-Z]{6}[0-9]{2}[a-zA-Z][0-9]{2}[a-zA-Z][0-9]{3}[a-zA-Z]$/;
if (_CF.uid_cliente.value.search(pattern)==-1) {
alert("Username non valido.");
_CF.uid_cliente.focus();
return false;
}
if (!(_CF.ris_cliente.checked)) {
alert("Per procedere nella prenotazione bisogna accettare\n le condizioni sulla riservatezza dei dati personali.");
_CF.ris_cliente.focus();
return false;
}
if (_CF.pass_cliente.value.search(pattern)==-1) {
alert("Password non valida.");
_CF.pass_cliente.focus();
return false;
}
if (_CF.pass2_cliente.value.search(pattern)==-1) {
alert("Verifica password non valida.");
_CF.pass2_cliente.focus();
return false;
}
if (_CF.pass_cliente.value!=_CF.pass2_cliente.value) {
alert("Password e verifica non corrispondono.");
_CF.pass_cliente.focus();
return false;
}
if (_CF.nome_cliente.value=='') {
alert("il campo NOME dev'essere compilato.");
_CF.nome_cliente.focus();
return false;
}
if (_CF.cogn_cliente.value=='') {
alert("il campo COGNOME dev'essere compilato.");
_CF.cogn_cliente.focus();
return false;
}
if (_CF.ind_cliente.value=='') {
alert("il campo INDIRIZZO dev'essere compilato.");
_CF.ind_cliente.focus();
return false;
}
if (_CF.cap_cliente.value=='') {
alert("il campo C.A.P. dev'essere compilato.");
_CF.cap_cliente.focus();
return false;
}
/*if (_CF.loc_cliente.value=='') {
alert("il campo LOCALITA' dev'essere compilato.");
_CF.loc_cliente.focus();
return false;
}*/
if (_CF.captcha_code.value=='') {
alert("Inserire il passcode antispam.");
_CF.passcode.focus();
return false;
}
if (_CF.naz_cliente.value=='') {
alert("il campo NAZIONE dev'essere compilato.");
_CF.naz_cliente.focus();
return false;
}
/*if ((_CF.naz_cliente.value=='Italia') && ((_CF.prov_cliente.value==''))) {
alert("il campo PROVINCIA dev'essere compilato.");
_CF.prov_cliente.focus();
return false;
}*/
if (_CF.tel_cliente.value=='') {
alert("il campo TELEFONO dev'essere compilato.");
_CF.tel_cliente.focus();
return false;
}
if (_CF.email_cliente.value.search(pattern2)==-1) {
alert("EMAIL non valida.");
_CF.email_cliente.focus();
return false;
}
/*
if ((_CF.azienda_cliente.value=='') && (_CF.codfis_cliente.value.search(pattern3)==-1)) {
alert("Codice Fiscale non valido.");
_CF.email_cliente.focus();
return false;
}
*/
/*
if ((_CF.azienda_cliente.value!='') && (!controllaPIVA(_CF.piva_cliente.value))) {
alert("Partita IVA non valida.");
_CF.email_cliente.focus();
return false;
}
*/
/*
if (_CF.g_nasc_cliente.value=="G") {
alert("Selezionare un giorno per la data di nascita.");
_CF.g_nasc_cliente.focus();
return false;
}
if (_CF.m_nasc_cliente.value=="M") {
alert("Selezionare un nese per la data di nascita.");
_CF.m_nasc_cliente.focus();
return false;
}
if (_CF.a_nasc_cliente.value=="A") {
alert("Selezionare un anno per la data di nascita.");
_CF.a_nasc_cliente.focus();
return false;
}
if (annoCorr-parseInt(_CF.a_nasc_cliente.value)<18) {
alert("Per prenotare occorre essere maggiorenni.");
_CF.a_nasc_cliente.focus();
return false;
}
if (((_CF.m_nasc_cliente.value=="04") || (_CF.m_nasc_cliente.value=="06") || (_CF.m_nasc_cliente.value=="09") || (_CF.m_nasc_cliente.value=="11")) && (_CF.m_nasc_cliente.value=="31")) {
alert("La data di nascita risulta inesistente.");
_CF.g_nasc_cliente.focus();
return false;
}
if (bisestile(parseInt(_CF.a_nasc_cliente.value))) ultFeb = 29;
else ultFeb = 28;
if ((_CF.m_nasc_cliente.value=="02") && (parseInt(_CF.g_nasc_cliente.value)>ultFeb)) {
alert("La data di nascita risulta inesistente.");
_CF.g_nasc_cliente.focus();
return false;
}*/
/*if (!(checkMail(_CF.email_cliente.value))) {
alert("il campo EMAIL contiene un indirizzo email non corretto.");
_CF.email_cliente.focus();
return false;
}*/
}
function pivaStar(tdPiva,inputAz) {
oggTd = document.getElementById(tdPiva);
oggIn = document.getElementById(inputAz);
if (oggIn.value=='') oggTd.innerHTML = ' Partita IVA ';
else oggTd.innerHTML = ' Partita IVA * ';
}
/*
----------
FORM INSERIMENTO DATI ANAGRAFICI - UPDATE DATI
----------
*/
function frmPrenoUpdDatiValid(_CF) {
var pattern = /^[a-zA-Z]{1}[a-zA-Z0-9]{5,19}$/;
var pattern2 = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
/*
if (_CF.pass_cliente.value.search(pattern)==-1) {
alert("Password non valida.");
_CF.pass_cliente.focus();
return false;
}
if (_CF.pass2_cliente.value.search(pattern)==-1) {
alert("Verifica password non valida.");
_CF.pass2_cliente.focus();
return false;
}
if (_CF.pass_cliente.value!=_CF.pass2_cliente.value) {
alert("Password e verifica non corrispondono.");
_CF.pass_cliente.focus();
return false;
}
*/
if (_CF.ind_cliente.value=='') {
alert("il campo INDIRIZZO dev'essere compilato.");
_CF.ind_cliente.focus();
return false;
}
if (_CF.cap_cliente.value=='') {
alert("il campo C.A.P. dev'essere compilato.'");
_CF.cap_cliente.focus();
return false;
}
if (_CF.loc_cliente.value=='') {
alert("il campo LOCALITA' dev'essere compilato.");
_CF.loc_cliente.focus();
return false;
}
if (_CF.naz_cliente.value=='') {
alert("il campo NAZIONE dev'essere compilato.");
_CF.naz_cliente.focus();
return false;
}
if ((_CF.naz_cliente.value=='Italia') && ((_CF.prov_cliente.value==''))) {
alert("il campo PROVINCIA dev'essere compilato.");
_CF.prov_cliente.focus();
return false;
}
if (_CF.tel_cliente.value=='') {
alert("il campo TELEFONO dev'essere compilato.");
_CF.tel_cliente.focus();
return false;
}
if (_CF.email_cliente.value.search(pattern2)==-1) {
alert("EMAIL non valida.");
_CF.email_cliente.focus();
return false;
}
/*
if (!(checkMail(_CF.email_cliente.value))) {
alert("il campo EMAIL contiene un indirizzo email non corretto.");
_CF.email_cliente.focus();
return false;
}
*/
if (!(_CF.ris_cliente.checked)) {
alert("Per procedere nella prenotazione bisogna accettare\n le condizioni sulla riservatezza dei dati personali.");
_CF.ris_cliente.focus();
return false;
}
}
/*
----------
FORM PRELIMINARE - CHECK GENERICO
----------
*/
function frmPrenoValid(_CF) {
var pattern = /^\d{1,2}\-\d{1,2}\-\d{4}$/;
if (_CF.d_arr.value.search(pattern)==-1) {
alert("La data di arrivo dev'essere inserita nel formato GG-MM-AAAA.");
return false;
}
if (_CF.d_par.value.search(pattern)==-1) {
alert("La data di partenza dev'essere inserita nel formato GG-MM-AAAA.");
return false;
}
var d_arr = _CF.d_arr.value.split("-");
var d_par = _CF.d_par.value.split("-");
a_arr = d_arr[2];
m_arr = d_arr[1]-1;
g_arr = d_arr[0];
a_par = d_par[2];
m_par = d_par[1]-1;
g_par = d_par[0];
var oggi = new Date();
var arr = new Date();
arr.setFullYear(a_arr,m_arr,g_arr);
var ultFeb;
var part = new Date();
part.setFullYear(a_par, m_par, g_par);
if (part<=arr) {
alert("La data di partenza dev'essere successiva a quella di arrivo.");
return false;
}
if (arr=21) ) {
alert("Si accettano prenotazioni solo fino alle ore 21 del giorno di arrivo.");
return false;
}
if ((diffGiorni(a_par, m_par, g_par, a_arr, m_arr, g_arr)<3) && (_CF.tratt.value!=3)) {
msg = "Soggiorni inferiori a tre giorni prevedono\n";
msg += "il solo trattamento di bed and breakfast.\n";
msg += "e si desidera usufruire del ristorante durante\n";
msg += "soggiorni inferiori ai tre giorni, rivolgersi\n";
msg += "al personale una volta giunti in albergo.\n";
alert(msg);
return false;
}
}
/*
----------
FORM PRELIMINARE - SELECT DEGLI ALBERGHI E LOCALITA' CON OPTION DINAMICHE
----------
*/
var nomiAlb = new Array();
var idAlb = new Array();
var locIdAlb = new Array();
var i = 1;
nomiAlb[0] = "Tutti";
idAlb[0] = 0;
locIdAlb[0] = 0;
function aggAlbergo(id, nome, idLuogo) {
nomiAlb[i] = nome;
idAlb[i] = id;
locIdAlb[i] = idLuogo;
i++;
}
function scriviAlberghi(nSel) {
var oggSel = document.getElementById("albergo");
var oggLoc = document.getElementById("localita");
var idLoc;
if (oggLoc!=null) idLoc = oggLoc.selectedIndex;
else idLoc = 0;
oggSel.length = 0;
k = 1;
oggSel.options[0]=new Option(nomiAlb[0], idAlb[0], true, false); // Albergo fittizzio "tutti"
for (j = 1; j