// JavaScript Document

browser_version= parseInt(navigator.appVersion);
browser_type = navigator.appName;

if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 4)) {

}

else if (browser_type == "Netscape" && (browser_version >= 4)) {

} 

////////////////////////////////////////////////////////////////////

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


////////////////////////////////////////////////////////////////////
function stampa_avviso_form(testo){
	     document.getElementById("responso_form").innerHTML = testo;
		 document.getElementById("responso_form").style.display="";
		  }

function Controllo_campi(formname, campi, valori, input, lang) {
	
	if((!lang) || (lang=="")) lang="ita";
	
	if(document.getElementById("responso_form")){
	document.getElementById("responso_form").style.display="none";
	}
	
	var localform = document.getElementById(formname);
	if((campi.length>0) && (document.getElementById || document.all)){
	for(var i=0; i<campi.length; i++){
        //// CONTROLLO SE RADIO BUTTON
		if(input[i]=="radiobutton"){
			   var radio = false;
			   if((localform[campi[i]].length) && (localform[campi[i]].length>1)){
			   for (counter = 0; counter < localform[campi[i]].length; counter++){
				   if (localform[campi[i]][counter].checked){
				   radio = true;
				   }
			   }
			   if(radio==false){
			   if((lang=="") || (lang=="ita")){
				   
				   stampa_avviso_form("Assegnare un valore per il campo '" + valori[i] + "'.");
				   
			   }else if(lang=="eng"){
				   
			       stampa_avviso_form("Please fill the field '" + valori[i] + "'.");
				   
			   }
			   return (false);
			   }
			   }else{
			   if (!localform[campi[i]].checked){
				   if((lang=="") || (lang=="ita")){
				   alert("E' necessario selezionare il campo '" + valori[i] + "' ai fini della richiesta.");
				   }else if(lang=="eng"){
				   alert("It is required to select the field '" + valori[i] + "' to complete the request.");     
				   }

				   return(false);
			       }
			   
			   }
			   
	   } else if(input[i]=="checkbox"){
		////// CONTROLLO SE DI TIPO CHECKBOX ///////////
			   var check = false;
			   
               if((localform[campi[i]].length) && (localform[campi[i]].length>1)){
			   for (var counter = 0; counter<localform[campi[i]].length; counter++){
				   if (localform[campi[i]][counter].checked){
				   check = true;
				   break;
				   }
			   }
			   }else{
				   if (localform[campi[i]].checked){
				   check = true;
				   }
			   }
			   
			   
			   if(check==false){
			   if((lang=="") || (lang=="ita")){
			   stampa_avviso_form("Assegnare un valore per il campo '" + valori[i] + "'.");
			   }else if(lang=="eng"){
			   stampa_avviso_form("Please fill the field '" + valori[i] + "'.");     
			   }
			   return (false);
			   }
			   
		} else if(input[i]=="text"){
		////// CONTROLLO SE DI TIPO TEXT ///////////
			if (localform[campi[i]].value==""){
			   if((lang=="") || (lang=="ita")){
			   stampa_avviso_form("Assegnare un valore per il campo '" + valori[i] + "'.");
			   }else if(lang=="eng"){
			   stampa_avviso_form("Please insert a value into the field '" + valori[i] + "'.");     
			   }
			   localform[campi[i]].focus();
			   return (false); 
			}
		
		} else if(input[i]=="password"){
		////// CONTROLLO SE IL VALORE DI INPUT E' DI LUNGHEZZA 8 LETTERE ///////////
			if (localform[campi[i]].value.length<8){
			   if((lang=="") || (lang=="ita")){
			   stampa_avviso_form("Assegnare un valore di minimo 8 lettere/numeri per il campo '" + valori[i] + "'.");
			   }else if(lang=="eng"){
			   stampa_avviso_form("Please insert a value into the field '" + valori[i] + "'.");     
			   }
			   localform[campi[i]].focus();
			   return (false); 
			}
			
			
		} else if(input[i]=="number"){
		////// CONTROLLO SE DI TIPO NUMERICO ///////////
		 
		   var strValidChars = "0123456789.";
		   var strChar = "";
		   var blnResult = true;

		   if (localform[campi[i]].value.length==0){ blnResult = false };
		
		   //  test strString consists of valid characters listed above

		   
		   if(blnResult == true){
			   for (var k = 0; k<localform[campi[i]].value.length; k++){
				  strChar = localform[campi[i]].value.charAt(k);
				  if (strValidChars.indexOf(strChar) == -1){
					 blnResult = false;
					 break;
					 }
			   }
		   }
		   
		   if(blnResult == false){
			   if((lang=="") || (lang=="ita")){
				   stampa_avviso_form("Inserire un valore di tipo numerico per il campo '" + valori[i] + "'.");
				   }else if(lang=="eng"){
				   stampa_avviso_form("Please insert a numeric value into the field '" + valori[i] + "'.");     
			   }
		  localform[campi[i]].focus();
		  return false;
		  }

			
		} else if(input[i]=="email"){
		////// CONTROLLO SE DI TIPO EMAIL ///////////
			  var goodEmail = localform[campi[i]].value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.biz)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
			  if (!goodEmail || localform[campi[i]].value==""){
				   if((lang=="") || (lang=="ita")){
				   stampa_avviso_form("Inserire un indirizzo esatto per il campo '" + valori[i] + "'.");
				   }else if(lang=="eng"){
				   stampa_avviso_form("Please insert a valid address into the field '" + valori[i] + "'.");     
				   }
				
				localform[campi[i]].focus();
				return (false);
			  }
  
		} else if(input[i]=="select-one"){
		////// CONTROLLO SE DI TIPO TEXT ///////////
			if (localform[campi[i]].value==""){
				
				   if((lang=="") || (lang=="ita")){
				   stampa_avviso_form("Selezionare un valore per il campo '" + valori[i] + "'.");
				   }else if(lang=="eng"){
				   stampa_avviso_form("Please select an option from the list '" + valori[i] + "'.");     
				   }
				
				localform[campi[i]].focus();
				return (false); 
			}
		}

	}
	}

return (true); 
}

