function check_login()
{
	if( check_user() && check_dati() )
	{
		document.forms['accesso'].submit();
	}
}

function check_login2()
{
	if( check_user2() && check_dati2() )
	{
		document.forms['accesso2'].submit();
	}
}


function check_user()
{
	username=document.getElementById("username").value;
	password=document.getElementById("password").value;
	if ( is_alphanumeric(username) == is_alphanumeric(password) && is_alphanumeric(username) == true)
	{
		return is_alphanumeric(username);
	}
	else
	{
		window.alert("USERNAME E PASSWORD NON VALIDI");
		return false;
	}
}

function check_user2()
{
	username=document.getElementById("username2").value;
	password=document.getElementById("password2").value;
	if ( is_alphanumeric(username) == is_alphanumeric(password) && is_alphanumeric(username) == true)
	{
		return is_alphanumeric(username);
	}
	else
	{
		window.alert("USERNAME E PASSWORD NON VALIDI");
		return false;
	}
}

function check_dati()
{
	username=document.getElementById("username").value;
	password=document.getElementById("password").value;
	if (username == "username" || password == "password") 
	{
		window.alert("INSERISCI USERNAME E PASSWORD");
		return false;
	}
	else 
	{ 
		return true;
	}
}

function check_dati2()
{
	username=document.getElementById("username2").value;
	password=document.getElementById("password2").value;
	if (username == "" || password == "") 
	{
		window.alert("INSERISCI USERNAME E PASSWORD");
		return false;
	}
	else 
	{ 
		return true;
	}
}

	
function is_alphanumeric(string)
{
	not_alphanumeric = 0;
	for(i=0; i < string.length; i++)
		if(!(	string.charCodeAt(i) >= 48 && string.charCodeAt(i) <= 57 ||								//numeri
				string.charCodeAt(i) >= 65 && string.charCodeAt(i) <= 90 ||								//maiuscole
				string.charCodeAt(i) >= 97 && string.charCodeAt(i) <= 122 )) not_alphanumeric = 1;		//minuscole
		return (!not_alphanumeric);
}

function check_email()
{
	if( email1() )
	{
		document.forms['recupera'].submit();
	}
}

	function email1()
	{

		var email = document.forms["recupera"].elements["email"].value;

		if (email == "")
		{
			alert("INSERISCI LA TUA E-MAIL")
			document.forms["recupera"].elements["email"].focus();
			return false;
		}
		else
		{
			if (email.indexOf ('@',0) == -1 || email.indexOf ('.',0) == -1)
			{

			alert("FORMATO E-MAIL ERRATO")
			document.forms["recupera"].elements["email"].focus();


			return false;

			}
			else

			{
				
				return true;
			}
		}

	}


function checkmail()
{
	if( email2() )
	{
		document.forms['mailinglist'].submit();
	}
}

	function email2()
	{

		var email = document.forms["mailinglist"].elements["email"].value;

		if (email == "" || email =="inserisci la tua mail")
		{
			alert("INSERISCI LA TUA E-MAIL")
			document.forms["mailinglist"].elements["email"].focus();
			return false;
		}
		else
		{
			if (email.indexOf ('@',0) == -1 || email.indexOf ('.',0) == -1)
			{

			alert("FORMATO E-MAIL ERRATO")
			document.forms["mailinglist"].elements["email"].focus();


			return false;

			}
			else

			{
				
				return true;
			}
		}

	}



var clicked = 0;


function tab(id) {

if (id != clicked)
{
	clicked = id;

	if (clicked == 1) { id2=id-(-1); } else { id2=id-1;}

	document.getElementById("ling1"+id).style.visibility = 'visible';
	document.getElementById("ling1"+id).style.display = 'block';
	document.getElementById("formcontatti"+id).style.visibility = 'visible';
	document.getElementById("formcontatti"+id).style.display = 'block';
	document.getElementById("ling1"+id2).style.visibility = 'hidden';
	document.getElementById("ling1"+id2).style.display = 'none';
	document.getElementById("formcontatti"+id2).style.visibility = 'hidden';
	document.getElementById("formcontatti"+id2).style.display = 'none';

	document.getElementById("ling2"+id).style.visibility = 'visible';
	document.getElementById("ling2"+id).style.display = 'block';
	document.getElementById("ling2"+id2).style.visibility = 'hidden';
	document.getElementById("ling2"+id2).style.display = 'none';

	if (id==1)
	{
		document.getElementById("formcontattidx").style.visibility = 'visible';
		document.getElementById("formcontattidx").style.display = 'block';
	}
	else
	{
		document.getElementById("formcontattidx").style.visibility = 'hidden';
		document.getElementById("formcontattidx").style.display = 'none';
	}

}

}
