// JavaScript Document

function frameOpen(menu,page,topMenu){
	parent.left.location.href = menu;
	parent.main.location.href = page;
	if(topMenu) location.href = topMenu;
	}



function goProduct(url) {
var x = url.options[url.selectedIndex].value;
if (x == "-") {
url.selectedIndex = 0;
}
else {
location = x;
url.selectedIndex = 0;
}
}


function openPopUp(pageref) {
var popupref =
window.open("","site","scrollbars=yes,width=750,height=330,resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no");
popupref.location=pageref;
}

function invia(action)
{
	var cognome=window.document.form1.cognome.value;
	var nome=window.document.form1.nome.value;
	
	var gg_arrivo=window.document.form1.gg_arrivo.value;
	var mm_arrivo=window.document.form1.mm_arrivo.value;
	var aa_arrivo=window.document.form1.aa_arrivo.value;
	
	var gg_partenza=window.document.form1.gg_partenza.value;
	var mm_partenza=window.document.form1.mm_partenza.value;
	var aa_partenza=window.document.form1.aa_partenza.value;
	
	var email=window.document.form1.email.value;
	var camera=window.document.form1.camera.value;
	var notti=window.document.form1.notti.value;
	

	window.document.form1.action = action;
	
	if(cognome.length==0) {
		alert('Inserire il \'Cognome\'');
		return false;		
	}
	if(nome.length==0) {
		alert('Inserire il \'Nome\'');
		return false;
	}
	
	if(!IsNumeric(gg_arrivo) || !IsNumeric(mm_arrivo) || !IsNumeric(aa_arrivo) )
	{
		alert('Il campo \'Data arrivo\' deve avere il formato GG-MM-AAAAA');
		return false;
	}
	if(!IsNumeric(gg_partenza) || !IsNumeric(mm_partenza) || !IsNumeric(aa_partenza) )
	{
		alert('Il campo \'Data partenza\' deve avere il formato GG-MM-AAAAA');
		return false;
	}
	
	if(notti.length==0) {
		alert('Inserire il campo \'Numero notti\'');
		return false;
	}
	
	if(camera.length==0) {
		alert('Inserire il campo \'Quantità di camere e tipologia\'');
		return false;
	}

	
	if(!isValidEmail(email))
	{
		alert('Il campo E-mail non è valido');
		return false;		
	}

	window.document.form1.submit();
//	return true;
}


 function isValidEmail(strEmail){
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
    if (strEmail.search(validRegExp) == -1) 
      return false;
    return true; 
	}

 function isValidData(strData){
  validRegExp = /^[\d]{1,2}-[\d]{1,2}-[\d]{4,4}$/i;
    if (strData.search(validRegExp) == -1) 
      return false;
    return true; 
}

function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 	if (sText=="") return false;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }