function redirectLingua()
{
  var lingua=navigator.systemLanguage;
  if (typeof(lingua) == 'undefined')
    lingua = window.navigator.language;
  var pagina=document.URL;
  if(lingua=="it") 
  {
  	if(pagina.indexOf("ita")<0) this.document.location='/home.html';
  }
  else 
  {
  	if(pagina.indexOf("eng")<0) this.document.location='/home_EN.html';
  }
}

function pressEnter(index, e) 
{	
	// Recupero informazioni sull'evento
	if (!e) var e = window.event;
	if (e && e.keyCode == 13) {eval("submitLogin(" + index + ")")}; 	   
}
  	
function submitLogin(index) 
{
  if (!index)
    index = "";
  var form = eval("document.LoginForm" + index);
  if (form.username.value == '' || form.username.value == 'Username' || form.username.value == 'INSERISCI IL TUO USERNAME' || form.username.value == 'USERNAME') 
  {
		alert("E' necessario indicare il nome utente");
		form.username.focus()
	} 
	else 
	{
	  if (form.password.value == '' || form.password.value == 'Password' || form.username.value == 'INSERISCI LA TUA PASSWORD' || form.username.value == 'PASSWORD')
	  {
		  alert("E' necessario indicare la password");
			form.password.focus()
	  } 
	  else 
	  {
		  if (form.agency_code.value == '' || form.agency_code.value == 'Cod. Agenzia' || form.username.value == 'CODICE AGENZIA' || form.username.value == 'AGENCY CODE')  
		  {
			  alert("E' necessario indicare il codice agenzia");
				form.agency_code.focus()
			} 
			else 
			{
		    form.OK.style.display="none"
				form.submit();
			}
		}
	}
}

//funzioni personalizzate per la versione inglese
function submitLoginEng() 
{
  if (document.LoginForm.username.value == '' || document.LoginForm.username.value == 'Username') 
  {
		alert("Username field cannot be left blank");
		document.LoginForm.username.focus()
	} 
	else 
	{
	  if (document.LoginForm.password.value == '' || document.LoginForm.password.value == 'Password') 
	  {
		  alert("Password field cannot be left blank");
			document.LoginForm.password.focus()
	  } 
	  else 
	  {
		  if (document.LoginForm.agency_code.value == '' || document.LoginForm.agency_code.value == 'Agency code') 
		  {
			  alert("Agency code field cannot be left blank");
				document.LoginForm.agency_code.focus()
			} 
			else 
			{
		    document.LoginForm.OK.style.display="none"
				document.LoginForm.submit();
			}
		}
	}	       
}	

function submitLoginEng2() 
{
  if (document.LoginForm2.username.value == '' || document.LoginForm2.username.value == 'Username') 
  {
		alert("Username field cannot be left blank");
		document.LoginForm2.username.focus()
	} 
	else 
	{
	  if (document.LoginForm2.password.value == '' || document.LoginForm2.password.value == 'Password') 
	  {
		  alert("Password field cannot be left blank");
			document.LoginForm2.password.focus()
	  } 
	  else 
	  {
		  if (document.LoginForm2.agency_code.value == '' || document.LoginForm2.agency_code.value == 'Agency code') 
		  {
			  alert("Agency code field cannot be left blank");
				document.LoginForm2.agency_code.focus()
			} 
			else 
			{
		    document.LoginForm2.OK.style.display="none"
				document.LoginForm2.submit();
			}
		}
	}
}		
	
function inviaFormIta()
{
			
	var obbligatori="";
	
	if(document.forms['RichiestaForm'].cli_nome.value=="") obbligatori += "Nome dell'agenzia\n";	
	if(document.forms['RichiestaForm'].cli_nazione.value=="") obbligatori += "Nazione\n";	
	if(document.forms['RichiestaForm'].cli_telefono.value=="") obbligatori += "Telefono\n";	
	if(document.forms['RichiestaForm'].COGNOME.value=="") obbligatori += "Cognome\n";	
	if(document.forms['RichiestaForm'].NOME.value=="") obbligatori += "Nome\n";	
	if(document.forms['RichiestaForm'].DIRET_TEL.value=="") obbligatori += "Telefono\n";	
	if(document.forms['RichiestaForm'].DIRET_FAX.value=="") obbligatori += "Fax\n";	
	if(document.forms['RichiestaForm'].DIRET_EMAIL.value=="") obbligatori += "E-mail\n";
	
	if(obbligatori=="")
	{
	  document.forms['RichiestaForm'].submit();
	}
  else
  {
  	alert("I seguenti campi sono obbligatori:\n\n" + obbligatori);
  }	
}	


function inviaFormEng()
{
	alert("inviaFormEng()");
	document.forms['LoginForm'].submit();
}	

$(document).ready( function() {
  $('input:text[name="passwordfake"]').each(
    function(index, element) {
      $(element).focus(function() {      
        $(element).next('input:password').show();
        $(element).next('input:password').focus();
        $(element).remove();
      });
    }
  );   
});
