/* <![CDATA[ */ 
// SCRIPT SITO WEB CAMERA MINORILE IN CAMMINO
// Settembre 2009
function Pieno(campo, LabelCampo, check){
	var cosa=true
	if (campo.value=="") {
		if (check) alert("Il campo " + LabelCampo + " è obbligatorio.\nE' necessario inserire dei dati per proseguire");
		cosa=false;
	}
	return cosa;
}

function Stringa(check, obbl,campo, LabelCampo, minvalue, maxvalue){
	var cosa=true;
	if ((obbl==false)&&(campo.value!=""))obbl=true;
	if (obbl==true){
		var cosa=Pieno(campo,LabelCampo,check);
		if((minvalue!=null) &&(maxvalue!=null)) {
			if(campo.value.length < minvalue) {
				if(check) alert("Il campo " + LabelCampo + " deve avere almeno " + minvalue + " caratteri.");
				cosa=false;
			} else if(campo.value.length > maxvalue) {
				if(check) alert("Il campo " + LabelCampo + " deve avere al massimo " + maxvalue + ".");
				cosa=false;
			} 
		}
	}
	if(!check) cosa=false; 
	return cosa;
}
function CheckEmail(check, obbl,campo, LabelCampo){
	var cosa=true;
	if ((obbl==false)&&(campo.value!="")){
		obbl=true;
	}
	if (obbl==true){
		cosa=Pieno(campo,LabelCampo,check);
		if (cosa) {
			var posat=campo.value.indexOf("@");
			if(posat==-1) {
				if(check) {
					alert("I dati inseriti nel campo " + LabelCampo + " non sono corretti.");
				}
				cosa=false;
			} else {
				var dominio = campo.value.substr(posat+1);
				if (dominio=="") {
					if(check) {
						alert("I dati inseriti nel campo " + LabelCampo + " non sono corretti.");
					}
					cosa=false;
				} else {
					var ext=dominio.lastIndexOf(".");
					if (ext==-1) {
						if(check) {
							alert("I dati inseriti nel campo " + LabelCampo + " non sono corretti.");
						}						
						cosa=false;
					} else {
						if(ext<2){
							if(check) {
								alert("I dati inseriti nel campo " + LabelCampo + " non sono corretti.");
							}
							cosa=false;
						} else{
							var extdom=dominio.substr(ext+1);
							if ((extdom=="")||(extdom.length < 2)) {
								if(check) {
									alert("I dati inseriti nel campo " + LabelCampo + " non sono corretti.");
								}
								cosa=false;
							} 
						}
					}
				}
			}
		}
	}
	if(!check) cosa=false; 
	return cosa;
}

function Numero(check, obbl,campo,LabelCampo, minvalue, maxvalue){
	var cosa=true;
	if ((obbl==false)&&(campo.value!="")){
		obbl=true;
	}
	if (obbl==true){
		cosa=Pieno(campo,LabelCampo,check);
		if (cosa==true) {
			if((campo.value.length < minvalue) && (minvalue!=null)) {
				if(check) alert("Il campo " + LabelCampo + " deve avere almeno " + minvalue + " cifre.");
				cosa=false;
			} else if((campo.value.length > maxvalue) && (maxvalue!=null)){
				if(check) alert("Il campo " + LabelCampo + " deve avere al massimo " + maxvalue + " cifre.");
				cosa=false;
			} else {
				if (isNaN(campo.value)){
					if(check) alert("Per il campo " + LabelCampo + " sono ammesse solo cifre da 0 a 9.");
					cosa=false;
				}
			}
		}
	}
	if(!check) cosa=false; 
	return cosa;
}

function IsDate(txtDate)
{
    try
    {
        if (txtDate.length != 10)
        {
            return null;
        }
        else if
             (
                 isNaN(txtDate.substring(0, 2))       ||
                       txtDate.substring(2, 3) != "/" ||
                 isNaN(txtDate.substring(3, 5))       ||
                       txtDate.substring(5, 6) != "/" ||
                 isNaN(txtDate.substring(6, 15))
             )
        {
            return false;
        }
        else
        {
            return true;
        }
    }
    catch (e)
    {
        return null;
    }
}


function CheckData(check, obbl,gg,Labelgg,mm,Labelmm,aa,Labelaa){	
	var cosa=true;
	if ((obbl==false)&&((gg.value!="")||(mm.value!="")||(aa.value!=""))){
		obbl=true;
	}
	if (obbl==true){
		
		cosa=Numero(check,obbl,gg,Labelgg,1,2);
		cosa=Numero(check,obbl,mm,Labelmm,1,2);
		cosa=Numero(check,obbl,aa,Labelaa,4,4);
		if (cosa==true) {
			var data=gg.value + "/" + mm.value + "/" + aa.value;	
			if ((IsDate(data) == false) || (IsDate(data) == null))
			{
				ret=false;
				alert("La data inserita non è corretta.");
			}
		}
	}
	return cosa;
}


function Autorizzato(obbl, nomeform) {
	var cosa=false;
	if (obbl==true){
		if(nomeform.autorizzo.checked==false) {
			alert("Per proseguire è necessario autorizzare il trattamento dei dati.");
		} else {
			cosa=true;
		}
	}
	return cosa;
}
/* ]]> */ 