var mandatory_message_IT= new Array("Informazioni obbligatorie",
									"Titolo",
									"Cognome",
									"Nome",
									"Societa",
									"Funzione",
									"Settore",
									"Dimensione azienda",
									"Indirizzo",
									"Città",
									"CPA",
									"Nazione",
									"Indirizzo Email",
									"Conferma Indirizzo Email",
									"Password",
									"Conferma Password",
									"Fax",
									"Telefono",
									"Cellulare"
									);
var mandatory_message_FR= new Array("Veuillez saisir le champ",
									"Civilit&eacute;",
									"Pr&eacute;nom",
									"Nom",
									"Soci&eacute;t&eacute;",
									"Fonction",
									"Secteur d'activit&eacute;",
									"Taille de l'entreprise",
									"Adresse",
									"Ville",
									"Code postal",
									"Pays",
									"E-mail",
									"Confirmation de l'email",
									"Mot de passe",
									"Confirmation du mot de passe",
									"T&eacute;l&eacute;copie",
									"T&eacute;l&eacute;phone",
									"Mobile"
									);
var mandatory_message_ES= new Array("Por favor, coja el campo",
									"Tratamiento",
									"Apellidos",
									"Nombre",
									"Compa&ntilde;&iacute;a",
									"Cargo",
									"Actividad",
									"Tama&ntilde;o de la empresa",
									"Direcci&oacute;n",
									"Ciudad",
									"C&oacute;digo postal",
									"Pa&iacute;s",
									"Correo electr&oacute;nico",
									"Confirmaci&oacute;n Correo electr&oacute;nico",
									"Contrase&ntilde;a",
									"Confirmaci&oacute;n Contrase&ntilde;a",
									"Fax",
									"Teléfono",
									"Mobile"
									);

var message ="";



function sendForm(tracker, langue) 
{
	if(valid(langue))
	{
		document.emvform.action=tracker+"save";
		document.emvform.submit();
		
		
	}	
	else
	{
		erreur();
		
	}
}


function valid(langue)
{		
	var test=true;
	var objMessage = eval("mandatory_message_"+langue);
	message ="<fieldset class='choice'><font color='#FF0000' ><h3><font color='#FF0000' >"+objMessage[0]+"</font></h3><ul>";
		
	// profil
	if(!mandatoryText(document.getElementById('TITLE_FIELD'), objMessage[1]))test=false;
	if(!mandatoryText(document.getElementById('FIRSTNAME_FIELD'), objMessage[2]))test=false;
	if(!mandatoryText(document.getElementById('LASTNAME_FIELD'), objMessage[3])) test=false;
	if(!mandatoryText(document.getElementById('COMPANY_NAME_FIELD'), objMessage[4])) test=false;
	if(!mandatoryText(document.getElementById('JOB_POSITION_FIELD'), objMessage[5])) test=false;
	if(!mandatoryText(document.getElementById('SECTOR_FIELD'), objMessage[6])) test=false;
	if(!mandatoryText(document.getElementById('COMPANY_SIZE_FIELD'), objMessage[7]))test=false;

	// coordonnees
	
	if(!mandatoryText(document.getElementById('ADDRESS_FIELD'), objMessage[8]))test=false;
	if(!mandatoryText(document.getElementById('CITY_FIELD'), objMessage[9]))test=false;
	if(!mandatoryText(document.getElementById('POSTCODE_FIELD'), objMessage[10]))test=false;
	if(!mandatoryText(document.getElementById('COUNTRY_FIELD'), objMessage[11]))test=false;
	if(document.getElementById('FAX_FIELD').value!="")
	{ 		
		if(!mandatoryNumField(document.getElementById('FAX_FIELD'), objMessage[16]))test=false;
	}
	if(document.getElementById('TELEPHONE_FIELD').value!="")
	{ 		
		if(!mandatoryNumField(document.getElementById('TELEPHONE_FIELD'), objMessage[17]))test=false;
	}
	if(document.getElementById('MOBILE_FIELD').value!="")
	{ 		
		if(!mandatoryNumField(document.getElementById('MOBILE_FIELD'), objMessage[18]))test=false;
	}
	// inscription
	if(!mandatoryText(document.getElementById('EMAIL_FIELD'), objMessage[12]))test=false;	
	if(!mandatoryText(document.getElementById('confirmRegMail'), objMessage[13]))test=false;
	if(!mandatoryComf(document.getElementById('confirmRegMail'), document.getElementById('EMAIL_FIELD'),objMessage[13]))test=false;
	
	if(!mandatoryText(document.getElementById('PASSWORD_FIELD'), objMessage[14]))test=false;	
	if(!mandatoryText(document.getElementById('confirmUserPass'), objMessage[15]))test=false;
	
	if(!mandatoryComf(document.getElementById('confirmUserPass'), document.getElementById('PASSWORD_FIELD'),objMessage[15]))test=false;
		
		
	message += "</ul></font></fieldset>";
	//test=false;	
	return test;	
}


function erreur()
{
	document.getElementById("error").innerHTML=message;
	document.regForm.EMAIL.focus();
}




function isEmail(emailAddress){
emailAddressValue=emailAddress.value.toLowerCase();
var countryTLDs=/^(ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$/;
var gTLDs=/^(aero|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org)$/;
var basicAddress=/^(.+)@(.+)$/;
var specialChars='\\(\\)><@,;:\\\\\\\"\\.\\[\\]';
var validChars='\[^\\s'+specialChars+'\]';
var validCharset='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\'-_.';
var quotedUser='(\"[^\"]*\")';
var atom=validChars+'+';
var word='('+atom+'|'+quotedUser+')';
var validUser=new RegExp('^'+word+'(\.'+word+')*$');
var symDomain=new RegExp('^'+atom+'(\.'+atom+')*$');
var matchArray=emailAddressValue.match(basicAddress);

if(matchArray==null){
//alert('L\'adresse Email semble incorrecte,\nveuillez vérifier la syntaxe.');
return  false;
}else{
var user=matchArray[1];
var domain=matchArray[2];
for(i=0;i<user.length;i++){
if(validCharset.indexOf(user.charAt(i))==-1){
//alert('L\'adresse Email contient des caractères invalides,\nveuillez vérifier la partie avant l\'arobase.');
return false;
}
}
for(i=0;i<domain.length;i++){
if(validCharset.indexOf(domain.charAt(i))==-1){
//alert('L\'adresse Email contient des caractères invalides,\nveuillez vérifier la partie après l\'arobase.');

return false;
}
}
if(user.match(validUser)==null){
//alert('L\'adresse Email semble incorrecte,\nveuillez vérifier la partie avant l\'arobase.');

return false;
}
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){
//alert('L\'adresse Email semble incorrecte,\nveuillez vérifier la partie après l\'arobase.');

return false;
}
}
if((domArr[domArr.length-1].length==2)&&(domArr[domArr.length-1].search(countryTLDs)==-1)){
//alert('L\'adresse Email semble incorrecte,\nveuillez vérifier le suffixe du domaine.');

return  false;
}
if((domArr[domArr.length-1].length>2)&&(domArr[domArr.length-1].search(gTLDs)==-1)){
alert('L\'adresse Email semble incorrecte,\nveuillez vérifier le suffixe du domaine.');

return  false;
}
if((domArr[domArr.length-1].length<2)||(domArr[domArr.length-1].length>6)){
//alert('L\'adresse Email semble incorrecte,\nveuillez vérifier le suffixe du domaine.');

return  false;
}
if(len<2){
//alert('L\'adresse Email semble incorrecte.');

return false;
}
}
return true;
}





// champs check boxe
function mandatoryCheckBox(checkBox,fieldName){
var nbcheck=0;
if(checkBox.length==undefined){
if(checkBox.checked){ nbcheck++; }
}else{
for (counter=0;counter<checkBox.length;counter++){
if(checkBox[counter].checked){ nbcheck++; }
}
}
if(nbcheck==0){
message +="<li>"+fieldName+"</li>";
return false;
}
return true;
}

// champs radio
function mandatoryRadio(radio,fieldName){
var radioValue=null;
for(var i=0;i<radio.length;i++){
if(radio[i].checked){
radioValue=radio[i].value;
break;
}
}
if(radioValue==null){
message +="<li>"+fieldName+"</li>";
//radio[0].focus();
return false;
} else {
return true;
}
}
String.prototype.trim = function() { return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");	}

// champ texte 
function mandatoryText(input,fieldName){
if(input.value.trim()==''){
message +="<li>"+fieldName+"</li>";
//input.focus();
return false;
} else {
return true;
}
}


function mandatoryComf(input1, input2,fieldName)
{
	if ((input1.value.trim()!='') && (input2.value.trim()!='') )
	{
		if ((input1.value==input2.value)==false)
		{	
			message +="<li>"+fieldName+"</li>";
			return false;
		}
	}
	return true;

}

function mandatoryNumField(input,fieldName)
{
	expression =/^\d*$/;	
	if (!expression.test(input.value))
	{
			message +="<li>"+fieldName+"</li>";
			return false;		
	}
	return true;
}