function conferma(messaggio, url){
        if(confirm(messaggio))
                window.location.href = url;
}

function chk_txt(oggetto, messaggio, min, max){
	// Toglie spazi iniziali e finali
	oggetto.value = oggetto.value.replace(/^\s*/, ''); 
	oggetto.value = oggetto.value.replace(/\s*$/, ''); 
	switch(arguments.length){
		case 2:
			if(oggetto.value.length <= 0){
				alert(messaggio);
				oggetto.focus();
				return false;
			}
			break;
		case 3:
			if(min == 0 && oggetto.value.length == 0)
				return true;
			else{
				if(oggetto.value.length < min){ 
					alert(messaggio);
					oggetto.focus();
					return false;
				}
			}
			break;
		case 4:
			if(min == 0 && oggetto.value.length == 0) return true;
			else{
				if(oggetto.value.length < min || oggetto.value.length > max){
					alert(messaggio);
					oggetto.focus();
					return false;
				}
			}
			break;
		default:
			return false;
			break;
	}
	return true;
}

function chk_float(o,d){
	if(o.value.search('^[0-9]{1,}(\.[0-9]{0,3})?$') == -1){
		alert(d);
		o.focus();
		return false;
	}
	return true;
}

function chk_int(o,d){
	if(!o.value || o.value.search('[^0-9]') != -1){
		alert(d);
		o.focus();
		return false;
	}
	return true;
}

function chk_url(o,d){
	if(o.value.search('[a-z]+://[a-zA-Z0-9]+\.[a-zA-Z0-9]+') == -1){
		alert(d);
		o.focus();
		return false;
	}
	return true;
}

function chk_email(o,d){
	if(o.value.search("^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-.]?[0-9a-zA-Z])*\\.[a-zA-Z]{2,4}$") == -1){
		alert(d);
		o.focus();
		return false;
	}
	return true;
}

function chk_select(o,d){
	if(o.selectedIndex == -1 || !o[o.selectedIndex].value){
		alert(d);
		o.focus();
		return false;
	}
	return true;
}

function chk_radio(o, m, v){
	var index = 0;
	if(arguments.length == 3){
		for(var i=0; i<o.length; i++)
			if(o[i].value == v){
				if(o[i].checked) return true;
				index = i;
				break;
			}
	}else{
		for(var i=0; i<o.length; i++)
			if(o[i].checked) return true;
	}
	alert(m);
	o[index].focus();
	return false;
}

function chk_checkbox(o,m){
	for(var i=0; i<o.length; i++)
		if(o[i].checked) return true;
	alert(m);
	o.focus();
	return false;
}

/*
	Copyright 2001-2003 B2S di Stenio Brunetta.
	Vietata la riproduzione, l'uso o la modifica senza autorizzazione.
	Per informazioni: info@b2s.it
*/
function chk_date(obj_g, obj_m, obj_a, msg, mandatory){
    if(!mandatory && obj_g.selectedIndex == 0 && obj_m.selectedIndex == 0 && obj_a.selectedIndex == 0) return true;

    g = obj_g.options[obj_g.selectedIndex].value;
    m = obj_m.options[obj_m.selectedIndex].value;
    a = obj_a.options[obj_a.selectedIndex].value;
    

    
	var giorni = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)[m-1];
	if ((m == 2) && (a % 4 == 0 && a % 100 != 0 || a % 400 == 0)) giorni++;
	if (g > giorni || g <= 0 || m <= 0 || a <= 0){
		alert(msg);
		obj_g.focus();
        return false;
    }
    else return true;
}

/*
	Copyright 2001-2003 B2S di Stenio Brunetta.
	Vietata la riproduzione, l'uso o la modifica senza autorizzazione.
	Per informazioni: info@b2s.it

    obj = input type file
    exts = stringa separata da spazi con estensioni senza punto
    mandatory = true se il file � obbligatorio
    msg = messaggio nell'alert
*/
function chk_file(obj, exts, mandatory, msg){
    if(!mandatory && (!obj || !obj.value || obj.value.length == 0)) return true;
    if(obj && obj.value && obj.value.length > 0){
        var vexts = exts.split(" "); 
        for(var i=0; i<vexts.length; i++)
            if(obj.value.search(new RegExp("\." + vexts[i] + "$", "i")) != -1) return true;
    }
    alert(msg);
    obj.focus();
    return false;
}
/* Fine Copyright */

function chk_money(o,d){
	if(o.value.search('^[0-9]{1,}(,[0-9]{0,2})?$') == -1){
		alert(d);
		o.focus();
		return false;
	}
	return true;
}
function chk_tel(o, msg){
	if(o.value.search('^\\+?[0-9]{5,}$') == -1){
		alert(msg);
		o.focus();
		return false;
	}
	return true;
}
