function isEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Inserisci fra " +min+ " e " +max+ " caratteri");
		elem.focus();
		return false;
	}
}

function lengthMaxRestriction(elem, max, helperMsg){
	var uInput = elem.value;
	if(uInput.length == max){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;	
	}
}

function madeSelection(elem, helperMsg){
	if(elem.selectedIndex == ""){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function radioValidator(elem,helperMsg) {
    var cnt = -1;
    for (var i=elem.length-1; i > -1; i--) {
        if (elem[i].checked) {cnt = i; i = -1;}
    }

    if (cnt > -1){
		return true;
	}else{
		alert(helperMsg);
		elem[0].focus();
		return false;
	}
}
                  
function checkValidator(elem,helperMsg) {
    var cnt = -1;
    for (var i=elem.length-1; i > -1; i--) {
        if (elem[i].checked) {cnt = i; i = -1;}
    }

    if (cnt > -1){
		return true;
	}else{
		alert(helperMsg);
		elem[0].focus();
		return false;
	}
}
