function checkRental()
{
	if (document.rental.r_modello.value.replace(/^ +/, "") == "")
	{
		alert("ATTENZIONE: il campo 'Modello' è obbligatorio.");
		document.rental.r_modello.focus();
		return false;
	}
	
	if (document.rental.r_1day.value.replace(/^ +/, "") == "")
	{
		alert("ATTENZIONE: il campo 'Prezzo per 1 giorno' è obbligatorio.");
		document.rental.r_1day.focus();
		return false;
	}
	
	if (document.rental.r_we.value.replace(/^ +/, "") == "")
	{
		alert("ATTENZIONE: il campo 'Prezzo per il week-end' è obbligatorio.");
		document.rental.r_we.focus();
		return false;
	}
	
	if (document.rental.r_week.value.replace(/^ +/, "") == "")
	{
		alert("ATTENZIONE: il campo 'Prezzo per 1 settimana' è obbligatorio.");
		document.rental.r_week.focus();
		return false;
	}
	
	if (document.rental.r_3days.value.replace(/^ +/, "") == "")
	{
		alert("ATTENZIONE: il campo 'Prezzo per 3 giorni' è obbligatorio.");
		document.rental.r_3days.focus();
		return false;
	}
	
	if (CheckEstensione(document.rental.r_foto.value) == false)
	{
		alert("ATTENZIONE: il formato del file caricato non è corretto. Inserire solo file .GIF o .JPG");
		document.rental.r_foto.focus();
		return false;
	}
	
	//if ((document.rental.r_foto.value.replace(/^ +/, "") == "") && ((document.rental.r_descImgIta.value.replace(/^ +/, "") != "") || (document.rental.r_descImgEng.value.replace(/^ +/, "") != "")))
	//{
	//	alert("ATTENZIONE: inserie la descrizione solo in presenza di una foto.");
	//	return false;
	//}
}

function checkNotes()
{
	if (document.notes.n_titolo_ita.value.replace(/^ +/, "") == "")
	{
		alert("ATTENZIONE: il campo 'Titolo (ita)' è obbligatorio.");
		document.notes.n_titolo_ita.focus();
		return false;
	}
	
	if (document.notes.n_testo_ita.value.replace(/^ +/, "") == "")
	{
		alert("ATTENZIONE: il campo 'Testo (ita)' è obbligatorio.");
		document.notes.n_testo_ita.focus();
		return false;
	}
	
}

function conferma(id)
{
	if (!confirm("Sei sicuro di voler eliminare questa moto?"))
	{	
		return;
	}	
	nomeform="elimina" + id;
	
	document.forms[nomeform].submit();
}

function confermaNote(id)
{
	if (!confirm("Sei sicuro di voler eliminare queste note?"))
	{	
		return;
	}	
	nomeform="elimina" + id;
	
	document.forms[nomeform].submit();
}

function OpenDetails(id, lang)
{
	target = "/ITA/Dinamic/rental_detail.asp?id=" + id + "&lang=" + lang;
	newWin = window.open(target, 'new_fin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=500,height=350');

	newWin.focus()
}

function CheckInfo()
{
	if (document.conta.nome.value.replace(/^ +/, "") == "")
	{
		alert("ATTENZIONE: Inserire il nome");
		document.conta.nome.focus();
		return(false);
	}

	if (document.conta.cognome.value.replace(/^ +/, "") == "")
	{
		alert("ATTENZIONE: Inserire il cognome");
		document.conta.cognome.focus();
		return(false);
	}

	if (document.conta.telefono.value.replace(/^ +/, "") == "")
	{
		alert("ATTENZIONE: Inserire il Telefono");
		document.conta.telefono.focus();
		return(false);
	}

	if (ValidaTelefono(document.conta.telefono.value) == false)
	{
		alert("ATTENZIONE: Il numero di Telefono è non corretto, provarlo a reinserirlo.");
		document.conta.telefono.focus();
		return(false);
	}
				
	if (document.conta.telefono.value.replace(/^ +/, "") == "")
	{
		alert("ATTENZIONE: Inserire il numero di telefono");
		document.conta.telefono.focus();
		return(false);
	}


	if (ValidaEmail(document.conta.email.value) == false)
	{
		alert("ATTENZIONE: L'indirizzo di Email è non corretto, provare a reinserirlo.");
		document.conta.email.focus();
		return(false);
	}

	if (document.conta.email.value.replace(/^ +/, "") == "")
	{
		alert("ATTENZIONE: Inserire l'indirizzo E-mail");
		document.conta.email.focus();
		return(false);
	}				
	
	return(true);
}

/* Funzioni generiche                       
   ----------------------------------------------------------------------------------------------------------------------------------------*/
function ValidaEmail(stringa)
{ 
  if (stringa=="")
	return(true)
  var carrattere=""
  var testo =0
  var vannobene = "abcdefghijklmnopqrstuvwxyz_@.ABCDEFGHIJKLMNOPQRSTUVWXYZƒŠŒšœŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþ0123456789";
  var checkStr = stringa;
  var aposto = true;
  var chiocciola = 0
  var punto = 0
  for (i = 0;  i < checkStr.length;  i++)
  {
	 carattere = checkStr.charAt(i);
	 for (j = 0;  j < vannobene.length;  j++)
	 {
		if (carattere == vannobene.charAt(j))
		{
		  if (carattere=="@")
		  {
			 if (testo==0)
				aposto=false;
			 chiocciola = chiocciola +1;
			 testo = -1;
		  }
		  if (carattere==".")
		  {
			 if (testo==0)
				aposto=false;
			 punto= punto +1
			 testo = -1;
		  }
		  testo = testo + 1;
		  break;
		}

		if (j == vannobene.length)
		{
		  aposto = false;
		  break;
		}
	 }
   }
	if (!aposto || chiocciola !=1 || punto ==0 || testo < 2 || testo >3 )
   {
		return (false);
   }
return (true);
}

function ValidaTelefono(checkStr)
{ 
  if (checkStr=="")
	return(true)

  var carrattere="";
  var vannobene = "0123456789/";
  var bolAposto = true;
  var bolTrovato = false;

  for (i = 0;  i < checkStr.length;  i++)
  {
		carattere = checkStr.charAt(i);
		bolTrovato = false;

	    for (j = 0;  j < vannobene.length;  j++)
		{
			if (carattere == vannobene.charAt(j))
			{		
				bolTrovato = true;
				break;
			}		
		}
		
		if (!bolTrovato ) 
		{
			bolAposto = false;
			break;
		}
  }		

  if (!bolAposto )
  {
    return (false);
  }
return (true);
}


function CheckEstensione(nome)
{
	if (nome == "")
		return(true);
	nome = nome.toLowerCase();
	lunghezza = nome.length;
	estensione = nome.substring(lunghezza-4,lunghezza);
	if ((estensione == ".jpg") || (estensione == ".gif"))
		return(true);
	return(false);
}
