///////////////////////////////////////////////////////////////////////////////////////
//                                   AS_Scripts                                      //
//   © Copyright 1999-2002 ACTIVE STUDIO eBusiness Solutions - All rights reserved!  //
//              http://www.activestudio.com - info@activestudio.com                  //
///////////////////////////////////////////////////////////////////////////////////////


//Menu
var blnLoadCheck = false;
var intItems = 5;

function preloadImages()
{
        if (document.images) {

                for (var i=0; i<intItems; i++ )
                {
                	eval('im'+i+'=new Image()');
                        eval('im'+i+'.src="images/menu/item'+i+'over.gif"');
                }
                blnLoadCheck = true;
                changeImages(intSelectedItem, 1);
        }
}

function changeImages(aintItem, blnState)
{
        if (document.images && (blnLoadCheck == true))
        {
                if (blnState)
                {
                        document.images['menu'+aintItem].src = 'images/menu/item'+aintItem+'over.gif';
                }
                else
                {
                  if (intSelectedItem != aintItem)
                  {
                        document.images['menu'+aintItem].src = 'images/menu/item'+aintItem+'.gif';
                  }
                }
        }
}
//End Menu


function isValidEmail(s) {
	rex=true;
	if (window.RegExp) {
		st="a";
		ex=new RegExp(st);
		if (st.match(ex)) {
			r1=new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
			r2=new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
			b=(!r1.test(s)&&r2.test(s));
		} 
		else {
			rex=false;
		}
	} else {
		rex=false;
	  }
	if(!rex) 
		b=(s.indexOf("@")>0&&s.indexOf(".")>0&&s!="");
	return (b);
}

function isValidPhone(s) {
  var rex = new RegExp("^[0-9]*$");
  return rex.test(s);
} 
function checkInfo(theForm) {
	switch (theForm.name) {

	  case "subscribe":

		if(!isValidEmail(theForm.email.value)) {
			alert("Prego, inserire un indirizzo email del tipo id@dominio.xxx o id@dominio.xx.xxx");
			with (theForm.email) { 
				focus();
				select();
			}
		return; 
		}
	 	theForm.submit();
		break;				

	  case "info":

		if (theForm.fullname.value == "") {
				alert("Inserire un valore per il campo \"Nome e Cognome\"");
				with (theForm.fullname) {
						focus();
						select();
				}
				return false;
		}


		if (theForm.email.value == "") {
				alert("Inserire un valore per il campo \"E-mail\"");
				with (theForm.email) {
						focus();
						select();
				}
				return false;
		}

		if(!isValidEmail(theForm.email.value)) {
				alert("Prego, inserire un indirizzo email del tipo id@dominio.xxx o id@dominio.xx.xxx");
				with (theForm.email) {
						focus();
						select();
				}
				return false;
		}

			if(!isValidPhone(theForm.phone.value)) {
                    alert("Prego, inserire solo numeri nel campo \"Telefono\"");
                    with (theForm.phone) {
                            focus();
                            select();
                    }
                    return false;
            }

		if (theForm.message.value == "") {
				alert("Inserire un valore per il campo \"Richieste\"");
				with (theForm.message) {
						focus();
						select();
				}
				return false;
		}
		theForm.submit();
		break;				

	  case "recommend":

		if (theForm.fullname.value == "") {
				alert("Inserire un valore per il campo \"Nome e Cognome\"");
				with (theForm.fullname) {
						focus();
						select();
				}
				return false;
		}

		if (theForm.senderEmail.value == "") {
			alert("Per favore, inserisci un valore per il campo \"La tua email\"");
			theForm.senderEmail.focus();
			return false; 
		}

		if (theForm.senderEmail.value != "")
			if(!isValidEmail(theForm.senderEmail.value)) {
				alert("Per favore, inserisci un indirizzo email del tipo id@domain.xxx or id@domain.xx.xxx");
				with (theForm.senderEmail) { 
					focus();
					select();
				}
			return false; 
			}

		if (theForm.destEmail0.value == "") {
			alert("Per favore, inserisci un valore per il campo \"Le email dei tuoi amici 1\"");
			theForm.destEmail0.focus();
			return false; 
		}

		if (theForm.destEmail0.value != "")
			if(!isValidEmail(theForm.destEmail0.value)) {
				alert("Per favore, inserisci un indirizzo email del tipo id@domain.xxx or id@domain.xx.xxx");
				with (theForm.destEmail0) { 
					focus();
					select();
				}
			return false; 
			}

		if (theForm.destEmail1.value != "")
			if(!isValidEmail(theForm.destEmail1.value)) {
				alert("Per favore, inserisci un indirizzo email del tipo id@domain.xxx or id@domain.xx.xxx");
				with (theForm.destEmail1) { 
					focus();
					select();
				}
			return false; 
			}

		if (theForm.destEmail2.value != "")
			if(!isValidEmail(theForm.destEmail2.value)) {
				alert("Per favore, inserisci un indirizzo email del tipo id@domain.xxx or id@domain.xx.xxx");
				with (theForm.destEmail2) { 
					focus();
					select();
				}
			return false; 
			}

		if (theForm.message.value.length > 300) {
			alert("Non è possibile inserire più di 300 caratteri per il campo \"Messaggio\"");
			theForm.Message.focus();
			return false; 
		}
        theForm.submit();
		break;				

      case "reservation":

            //if (!theForm.chkAcceptPrivacy.checked) {
            //        alert("Si prega di leggere l'informativa e dare il consenso al trattamento dei dati.\nAltrimenti non sarà possibile usufruire di questo servizio.");
            //        return false;
            //}
			
			if (theForm.fullname.value == "") {
                    alert("Inserire un valore per il campo \"Nome e Cognome\"");
                    with (theForm.fullname) {
                            focus();
                            select();
                    }
                    return false;
            }


            if (theForm.email.value == "") {
                    alert("Inserire un valore per il campo \"E-mail\"");
                    with (theForm.email) {
                            focus();
                            select();
                    }
                    return false;
            }

            if(!isValidEmail(theForm.email.value)) {
                    alert("Prego, inserire un indirizzo email del tipo id@dominio.xxx o id@dominio.xx.xxx");
                    with (theForm.email) {
                            focus();
                            select();
                    }
                    return false;
            }

            if(!isValidPhone(theForm.phone.value)) {
                    alert("Prego, inserire solo numeri nel campo \"Telefono\"");
                    with (theForm.phone) {
                            focus();
                            select();
                    }
                    return false;
            }

            if (theForm.message.value == "") {
                    alert("Inserire un valore per il campo \"Modello\"");
                    with (theForm.message) {
                            focus();
                            select();
                    }
                    return false;
            }
            theForm.submit();
		    break;				
			
      case "booking":
	  
            //if (!theForm.chkAcceptPrivacy.checked) {
            //        alert("Si prega di leggere l'informativa e dare il consenso al trattamento dei dati.\nAltrimenti non sarà possibile usufruire di questo servizio.");
            //        return false;
            //}


            if (theForm.m.value == "Nessuna autovettura disponibile") {
                    alert("Spiacente, al momento con ci sono autovetture!");
                    with (theForm.m) {
                            focus();
                            select();
                    }
                    return false;
            }


            if (theForm.fullname.value == "") {
                    alert("Inserire un valore per il campo \"Nome e Cognome\"");
                    with (theForm.fullname) {
                            focus();
                            select();
                    }
                    return false;
            }


            if (theForm.email.value == "") {
                    alert("Inserire un valore per il campo \"E-mail\"");
                    with (theForm.email) {
                            focus();
                            select();
                    }
                    return false;
            }

            if(!isValidEmail(theForm.email.value)) {
                    alert("Prego, inserire un indirizzo email del tipo id@dominio.xxx o id@dominio.xx.xxx");
                    with (theForm.email) {
                            focus();
                            select();
                    }
                    return false;
            }

            if(!isValidPhone(theForm.phone.value)) {
                    alert("Prego, inserire solo numeri nel campo \"Telefono\"");
                    with (theForm.phone) {
                            focus();
                            select();
                    }
                    return false;
            }

            theForm.submit();
		    break;				

	  case "search":

		if ((theForm.sf.value == "") && (theForm.sf.value.length < 3)) {
			alert("Prego, inserire un valore di ricerca di almeno 3 caratteri.");
			with (theForm.sf) { 
				focus();
				select();
			}
		return; 
		}
	 	theForm.submit();
	  
	}//end switch	
}

function resetForm(theForm) {
  theForm.reset();
}

function checkEmailField(aintAction) {
  if (aintAction == 0) {
    if (document.subscribe.email.value.toLowerCase() == "email" )
      document.subscribe.email.value = "";
 }
  else 
    if (document.subscribe.email.value == "" )
      document.subscribe.email.value = "email";
}

function disableControl(aRadioValue) {
  if (aRadioValue == 2) {
  	document.advsearch.startyr.disabled = true 
  	document.advsearch.endyr.disabled = true 
  }	
  else {
  	document.advsearch.startyr.disabled = false;
  	document.advsearch.endyr.disabled = false 
  }	
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'channelmode=yes,fullscreen=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,left='+left+',top='+top+',screenX='+left+',screenY='+top+'');
}

