// JavaScript Document


function PrintMessagge(msg){

			 if(document.getElementById("MessaggeForm")){
			 var box = document.getElementById("MessaggeForm");
			 box.innerHTML = "";
			 box.style.visibility = "visible";
			 box.innerHTML = msg;
			 } else {
				 alert(msg);
			 }
			 
         }



///// CONTROLLO CHE ESISTA E SIA VALIDO UN VALORE PER I CAMPI OBBLIGATORI ////////////////////

function VerifyForm(arr, lang) {
	if(arr.length>0){
	for(var i=0; i<arr.length; i++){
        //// CONTROLLO SE RADIO BUTTON

		var name = arr[i][0].toString();
		var name_arr = name.split("|");
		var nm = new Array();
		 
		nm["it"] = name_arr[0];
		nm["en"] = name_arr[1];
		nm["de"] = name_arr[2];
		var input = arr[i][1];
		var type = arr[i][2];
		
		var nome = nm[lang];

		
		if(type=="radiobutton"){
			   var radio = false;
			   if((document.forms[0][input].length) && (document.forms[0][input].length>1)){
			   for (counter = 0; counter < document.forms[0][input].length; counter++){
				   if (document.forms[0][input][counter].checked){
				   radio = true;
				   }
			   }
			   if(radio==false){
			   if(lang=="it") PrintMessagge("Assegnare un valore per il campo '" + nome + "'.");
			   if(lang=="en") PrintMessagge("Choose a value for the field '" + nome + "'.");
			   return (false);
			   }
			   }else{
			   if (!document.forms[0][input].checked){
				   if(lang=="it") PrintMessagge("E' necessario selezionare il campo '" + nome + "' ai fini della richiesta.");
				   if(lang=="en") PrintMessagge("It is necessary to select a field '" + nome + "' in order to send the request.");
				   return(false);
			       }
			   
			   }
			   
	   } else if(type=="checkbox"){
		////// CONTROLLO SE DI TIPO CHECKBOX ///////////
			   var check = false;
			   var checklength = document.forms[0][input].length;

			   if((checklength<="0") || (checklength=="undefined") || (!checklength)){
				   check = document.forms[0][input].checked;
			   } else {
			   for (counter = 0; counter<checklength; counter++){
				   if (document.forms[0][input][counter].checked){
				   check = true;
				   }
			   }
			   }
			   
			   if(check==false){
			   if(lang=="it") PrintMessagge("Assegnare un valore per il campo '" + nome + "'.");
			   if(lang=="en") PrintMessagge("Choose a value for the field '" + nome + "'.");
			   return (false);
			   }
			   
		} else if(type=="text"){
		////// CONTROLLO SE DI TIPO TEXT ///////////
			if (document.forms[0][input].value==""){
				if(lang=="it") PrintMessagge("Inserire un valore per il campo '" + nome + "'.");
				if(lang=="en") PrintMessagge("Please fill the field '" + nome + "'.");
				document.forms[0][input].focus();
				return (false); 
			}
		} else if(type=="number"){
		////// CONTROLLO SE DI TIPO NUMBER ///////////
		if (isNaN(document.forms[0][input].value)) {
		if(lang=="it") PrintMessagge("Inserire un valore di tipo numerico per il campo '" + nome + "'.");
		if(lang=="en") PrintMessagge("Please insert a numeric value in the field '" + nome + "'.");
		return false;
		}
			
		} else if(type=="email"){
		////// CONTROLLO SE DI TIPO EMAIL ///////////
			  var goodEmail = document.forms[0][input].value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.biz)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
			  if (!goodEmail || document.forms[0][input].value==""){
				if(lang=="it") PrintMessagge("Inserire un indirizzo esatto per il campo '" + nome + "'.");
				if(lang=="en") PrintMessagge("Please insert a correct email address in the field '" + nome + "'.");
				document.forms[0][input].focus();
				return (false);
			  }

		} else if(type=="select-one"){
		////// CONTROLLO SE DI TIPO TEXT ///////////
			if ((document.forms[0][input].value=="") || (document.forms[0][input].value=="0")){
				if(lang=="it") PrintMessagge("Selezionare un valore per il campo '" + nome + "'.");
				if(lang=="en") PrintMessagge("Select an option in the field '" + nome + "'.");
				document.forms[0][input].focus();
				return (false); 
			}
		}

	}
	}

return (true); 
}
