// Funzioni per la gestione dei form
var errormsg = null;

function isNumeric(value){
	objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;
	return objRegExp.test(value);
 }


function checkSelect(obj){

	if(obj.options[obj.selectedIndex].value == 'select'){
			return false;
	}else return true;
}

function checkRadio(obj){
	n = obj.length;
	checked = false;
	for(i=0;i<n;i++){
		if(obj[i].checked){
			checked = true;
			break;
		}
	}
	return checked;	
}

function enable(obj){
	if(obj==null)
		obj= this.id;
	document.getElementById(obj).disabled = false;
}
function disable(obj){
	if(obj==null)
		obj= this.id;
	document.getElementById(obj).disabled = true;
}

function isEmpty(obj){
	if(obj.value != '')	return false;
	else return true;
}

function checkMail(obj){
	email = obj.value;
	var caratteriNonValidi = " /:,;"				
	for (var i=0; i<caratteriNonValidi.length; i++) {
		var noCar = caratteriNonValidi.charAt(i)
		if (email.indexOf(noCar,0) > -1){
			return false;			
		} 
	}
	//cerchiamo @
	atPos = email.indexOf("@",1)			
	if (atPos == -1){ 
		return false;
	}
//ci deve essere solo un simbolo @	
	if (email.indexOf("@",atPos+1) != -1) { 
			return false;
	}

//cerchiamo il .		
	dotPos = email.indexOf(".",atPos) 
	if (dotPos == -1){
		return false;
	}

//ci devono essere da 2 a 4 caratteri dopo l'ultimo .
	if (email.length - dotPos>5 || email.length - dotPos<3) {
		return false;
	}
	return true;
}


function error(obj,where,msg){
	alert(msg);
	obj.focus();
	return false;
}
