function nomCheck ()
{

	if (document.getElementById('nom').value!='')
	{
		document.getElementById('img-nom').src='../img/aff_tick.gif';
		document.getElementById('nom').style.borderColor='green';
	}
	else 
	{
                document.getElementById('nom').style.borderColor='';
                document.getElementById('img-nom').src='../img/vide.gif';
	}
	return;
	
}

function emailCheck (type)
{
var isValid = 0;
var nbMailValid = 0;
var nbMailInvalid = 0;
var NomValid = 0;

var id=["email","mail1","mail2","mail3","mail4","mail5"]; 
var img=["img-email","img-mail1","img-mail2","img-mail3","img-mail4","img-mail5"];

var mail=[document.getElementById('email').value, document.getElementById('mail1').value,
	  document.getElementById('mail2').value, document.getElementById('mail3').value, 
          document.getElementById('mail4').value, document.getElementById('mail5').value];

if (document.getElementById('nom').value.length!=0)
{
++NomValid;
}
else if (type == 'nom') 
{
	document.getElementById('nom').style.borderColor='red';
	document.getElementById('img-nom').src='../img/aff_cross.gif';
}

for (j=0; j<6; ++j)
{
if (mail[j].length==0)
{
	document.getElementById(id[j]).style.borderColor='';
	document.getElementById(img[j]).src='../img/vide.gif';
	continue;
}

var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=mail[j].match(emailPat);


if (matchArray==null) 
{
	if (type != 'a')
	{
		document.getElementById(id[j]).style.borderColor='red';
		document.getElementById(img[j]).src='../img/aff_cross.gif';
	}
	else 
	{
		document.getElementById(id[j]).style.borderColor='';
		document.getElementById(img[j]).src='../img/vide.gif';

	}
	if (id[i]!="email") ++nbMailInvalid;
	continue;
}

var user=matchArray[1];
var domain=matchArray[2];


for (i=0; i<user.length; i++) 
{
	if (user.charCodeAt(i)>127) 
	{
		if (type != 'a')
		{
			document.getElementById(id[j]).style.borderColor='red';
			document.getElementById(img[j]).src='../img/aff_cross.gif';
		}
	        else
        	{
                	document.getElementById(id[j]).style.borderColor='';
                	document.getElementById(img[j]).src='../img/vide.gif';

        	}

		if (id[i]!="email") ++nbMailInvalid;
		continue;
   	}
}

for (i=0; i<domain.length; i++) 
{
	if (domain.charCodeAt(i)>127) 
	{
		if (type != 'a')
		{
			document.getElementById(id[j]).style.borderColor='red';
			document.getElementById(img[j]).src='../img/aff_cross.gif';
		}
	        else
        	{
                	document.getElementById(id[j]).style.borderColor='';
                	document.getElementById(img[j]).src='../img/vide.gif';

        	}

		if (id[i]!="email") ++nbMailInvalid;
		continue;
        }
}


if (user.match(userPat)==null) 
{
	if (type != 'a')
	{
		document.getElementById(id[j]).style.borderColor='red';
		document.getElementById(img[j]).src='../img/aff_cross.gif';
	}
        else
        {
                document.getElementById(id[j]).style.borderColor='';
                document.getElementById(img[j]).src='../img/vide.gif';

        }

	if (id[i]!="email") ++nbMailInvalid;
	continue;
}


var IPArray=domain.match(ipDomainPat);

if (IPArray!=null) 
{
	for (var i=1;i<=4;i++) 
	{
		if (IPArray[i]>255) 
		{
			if (type != 'a')
			{
				document.getElementById(id[j]).style.borderColor='red';
			    document.getElementById(img[j]).src='../img/aff_cross.gif';
			}
		        else
        		{
                		document.getElementById(id[j]).style.borderColor='';
                		document.getElementById(img[j]).src='../img/vide.gif';

        		}

			if (id[i]!="email") ++nbMailInvalid;
			continue;
   		}
	}

	if (id[j]=="email") ++isValid;
	else ++nbMailValid;
	document.getElementById(id[j]).style.borderColor='green';
	document.getElementById(img[j]).src='../img/aff_tick.gif';
	continue;
}

var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;

for (i=0;i<len;i++) 
{
	if (domArr[i].search(atomPat)==-1) 
	{
		if (type != 'a')
		{
			document.getElementById(id[j]).style.borderColor='red';
			document.getElementById(img[j]).src='../img/aff_cross.gif';
		}
	        else
        	{
                	document.getElementById(id[j]).style.borderColor='';
                	document.getElementById(img[j]).src='../img/vide.gif';

        	}

		if (id[i]!="email") ++nbMailInvalid;
		continue;
	}
}


if (checkTLD && domArr[domArr.length-1].length!=2 &&
    domArr[domArr.length-1].search(knownDomsPat)==-1) 
{
	if (type != 'a')
	{
		document.getElementById(id[j]).style.borderColor='red';
		document.getElementById(img[j]).src='../img/aff_cross.gif';
	}
        else
        {
                document.getElementById(id[j]).style.borderColor='';
                document.getElementById(img[j]).src='../img/vide.gif';

        }

	if (id[i]!="email") ++nbMailInvalid;
	continue;
}

if (len<2) 
{
	if (type != 'a')
	{
		document.getElementById(id[j]).style.borderColor='red';
		document.getElementById(img[j]).src='../img/aff_cross.gif';
	}
        else
        {
                document.getElementById(id[j]).style.borderColor='';
                document.getElementById(img[j]).src='../img/vide.gif';

        }

	if (id[i]!="email") ++nbMailInvalid;
	continue;
}

if (id[j]=="email") ++isValid;
else ++nbMailValid;

document.getElementById(id[j]).style.borderColor='green';
document.getElementById(img[j]).src='../img/aff_tick.gif';
continue;
}

if (NomValid && isValid && nbMailValid && !nbMailInvalid) document.getElementById('Submit').disabled='';
else document.getElementById('Submit').disabled='disabled';
return;
}
