/***********************************************
* Required field(s) validation v1.10- By NavSurf
* Visit Nav Surf at http://navsurf.com
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function formCheck(formobj,lang){
	// Enter name of mandatory fields
	var fieldRequired = Array("Nome", "Cognome","updval[cognome]","updval[nome]","E-mail","Tipo di corso","Dal1","Al1","Pagamento","Prenotazione","Costo_totale");
	// Enter field description to appear in the dialog box
	var fieldDescriptionit = Array("Nome", "Cognome","cognome","nome","E-mail","Tipo di corso","Data inizio corso","Data fine corso","Metodo di pagamento","Alloggio","Costo complessivo");
	var fieldDescriptionen = Array("Name", "Surname","surname","name","E-mail","Kind of course","Starting date","Ending date","Way of payment","Place","Global cost");
	var fieldDescriptiones = Array("Nombre", "Apellidos","nombre","apellidos","E-mail","Tipo de curso","Fecha de inicio curso","Fecha de fin de curso","Forma de pago","Alojamiento","Coste total");
	var fieldDescriptionde = Array("Name", "Vorname","name","vorname","E-mail","Sprachkurse","Startdatum","Enddatum","Zahlungsbedingungen","Unterkunft","Gesamtkosten");
	var fieldDescriptionru = Array("Name", "Surname","surname","name","E-mail","Kind of course","Starting date","Ending date","Way of payment","Place","Global cost");
	var fieldDescriptionjp = Array("Name", "Surname","surname","name","E-mail","Kind of course","Starting date","Ending date","Way of payment","Place","Global cost");
	var fieldDescriptionfr = Array("Prénom", "Nom", "prénom", "nom", "E-mail","Type de cours","Date de début","Date de fin","Mode de paiement","Hébergement","Coût total");
	switch(lang)
	{
	case "it":
		// dialog message
		var alertMsg = "Compila i seguenti campi:\n";
		var fieldDescription=fieldDescriptionit;
	break;
	case "en":
		// dialog message
		var alertMsg = "Fill the following fields:\n";
		var fieldDescription=fieldDescriptionen;
	break;
	case "es":
		// dialog message
		var alertMsg = "Rellena las siguientes campos:\n";
		var fieldDescription=fieldDescriptiones;
	break;
	case "de":
		// dialog message
		var alertMsg = "Fill the following fields:\n";
		var fieldDescription=fieldDescriptionde;
	break;
	case "ru":
		// dialog message
		var alertMsg = "Fill the following fields:\n";
		var fieldDescription=fieldDescriptionen;
	break;
	case "jp":
		// dialog message
		var alertMsg = "Fill the following fields:\n";
		var fieldDescription=fieldDescriptionen;
	break;
	case "fr":
		// dialog message
		var alertMsg = "Remplir les champs suivants:\n";
		var fieldDescription=fieldDescriptionfr;
	break;
	default:
	}

	var l_Msg = alertMsg.length;
	
	for (var i = 0; i < fieldRequired.length; i++){
		var obj = formobj.elements[fieldRequired[i]];
		if (obj){
			switch(obj.type){
			case "select-one":
				if (obj.selectedIndex == -1 || obj.selectedIndex == 0 || obj.options[obj.selectedIndex].text == ""){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "select-multiple":
				if (obj.selectedIndex == -1){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
				break;
			case "text":
			case "textarea":
				if (obj.value == "" || obj.value == null){
					if (fieldRequired[i]!="Costo_totale" || formobj.elements["Pagamento"].value == "Carta")
					{
						alertMsg += " - " + fieldDescription[i] + "\n";			
					}	
				}
				break;
			default:
			}
			if (obj.type == undefined){
				var blnchecked = false;
				for (var j = 0; j < obj.length; j++){
					if (obj[j].checked){
						blnchecked = true;
					}
				}
				if (!blnchecked){
					alertMsg += " - " + fieldDescription[i] + "\n";
				}
			}
		}
	}

	if (alertMsg.length == l_Msg){
		return true;
	}else{
		alert(alertMsg);
		return false;
	}
}

/*
Script  tratto dal libro "JavaScript and DHTML Cookbook" - Capitolo 8-11
     Pubblicato da O'Reilly & Associates
     Copyright 2003 Danny Goodman
	  Riprodurre questa nota per qualunque riutilizzo del codice.
	*/
	function numeralsOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : 
        ((evt.which) ? evt.which : 0));
    if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
        alert("Puoi inserire solo numeri oppure il punto"); 
        return false;
    }
    return true;
}

