function autoSelect(selectTarget) {
 	if(selectTarget != null && ((selectTarget.childNodes.length == 1
      && selectTarget.childNodes[0].nodeName == "#text") || (selectTarget.tagName == "INPUT"
      && selectTarget.type == "text"))) {
  		if(selectTarget.tagName == 'TEXTAREA' || (selectTarget.tagName == "INPUT" && selectTarget.type == "text")) {
  			 selectTarget.select();
  		} 
		
 	}
}
function emailvalidation(entered, alertbox){
	with (entered){
		apos=value.indexOf("@");
		dotpos=value.lastIndexOf(".");
		lastpos=value.length-1;
			if (apos<1 || dotpos-apos<2 || lastpos-dotpos>4 || lastpos-dotpos<2) 
			{
				if (alertbox) {
					alert(alertbox);
				} return false;
			}else {
				return true;
			}
	}
}
function emptyvalidation(entered, alertbox){
	with (entered){
		if (value==null || value=="" || value.search("#") != -1){
			if (alertbox!="") {
				alert(alertbox);
			} return false;
			}else {
				return true;
			}
	}
}

/* ################################# */

function validaRegistrazioneSmall(thisform){
	with (thisform){
		if (emailvalidation(email,"!!! Indirizzo email non valido !!!")==false) {
			autoSelect(email); return false;
		}
		if (emptyvalidation(nome,"!!! come ti chiami? !!!")==false) {
			autoSelect(nome); return false;
		}
	}
}
function validaMail(thisform){
	with (thisform){
		if (emailvalidation(replayto,"!!! Indirizzo email non valido !!!")==false) {
			autoSelect(replayto); return false;
		}
	}
}
