function swap(img,over)
{
	var source=document.getElementById(img).src
	var sourcenew=""
	if(over && source.substr(source.length-6,2)!="_o")
	{
		sourcenew=source.substr(0,source.length-4)+"_o"+source.substr(source.length-4,4)
		document.getElementById(img).src=sourcenew;	
	}
	else if (!over && source.substr(source.length-6,2)=="_o")
	{
		sourcenew=source.substr(0,source.length-6)+source.substr(source.length-4,4)
		document.getElementById(img).src=sourcenew;
	}
	
	//alert(sourcenew)
}

function Validchars(stringaemail)
{
	var retval=true;
	for(i=0;i<stringaemail.length;i++)
	{
		p=stringaemail.charCodeAt(i);
		if(p==45 || p==46 || (p>=64 && p<=90) || p==95 || (p>=97 && p<=122) || (p>=48 && p<=57))
		{
			o=2;	
		}
		else
		{
			retval=false;
			break;
		}
	}
	return retval;
}

function Doppiachiocciola(stringa)
{
	var retval=false;
	var contachiocciole=0;
	for(i=0;i<stringa.length;i++)
	{
		p=stringa.charCodeAt(i);
		if(p==64)
		{
			contachiocciole++;	
		}
	}
	if(contachiocciole>1)
	{
		retval=true;
	}
	return retval;
}

function Checkmail(nomeelemento)
{
	var mail=document.getElementById(nomeelemento).value;
	if(mail.indexOf("..")!=-1 || mail.indexOf("@@")!=-1 || mail.indexOf("@")==-1 || mail.indexOf(".")==-1 || mail.substr(0,1)=="." || mail.substr(mail.length-1,1)=="." || mail.substr(0,1)=="@" || mail.substr(mail.length,-1)=="@" || mail.substr(0,1)=="-" || mail.substr(mail.length-1,1)=="-" || mail.substr(0,1)=="_" || mail.substr(mail.length-1,1)=="_" || !Validchars(nomeelemento) || Doppiachiocciola(mail))
	{
		alert("Inserire un indirizzo E-mail corretto.");
		document.getElementById(nomeelemento).focus();
		return false;
	}
	else
	{
		return true;	
	}
}

//lunghezza, se non importa mettere 0
function Checknumeric(strnumero,lunghezza)
{
	var retval=true
	if(lunghezza!=0 && strnumero.length<lunghezza)
	{
		retval=false;
	}
	else
	{
		for(i=0;i<strnumero.length;i++)
		{
			p=strnumero.charCodeAt(i);
			if(p<48 || p>57)
			{
				retval=false;	
				break;
			}
		}
	}
	return retval;
}

function Checkphone(numero)
{
	var retval=true;
	for(i=0;i<numero.length;i++)
	{
		p=numero.charCodeAt(i);
		if((p>=47 && p<=57) || p==32)
		{
			o=2;	
		}
		else
		{
			retval=false;
			break;
		}
	}
	return retval;
}
