// JavaScript Document
function ValidaMail(mail,id, tasto){
	     match = mail.match(/^([\w-.]+)[@]{1}([\w-.]+)\.([\w]{2,4})$/);
		 if (match == null) {document.getElementById(id).innerHTML = 'Indirizzo e-mail non valido!<br />';
		 document.getElementById(tasto).disabled = true;
		 alert('Indirizzo e-mail non valido!!');} else 
		 {document.getElementById(id).innerHTML = '';
		 document.getElementById(tasto).disabled = false;}
}

function ValidaData(data,no,elim){
        match = data.match(/^([0-9]{2})[-.\/]{1}([0-9]{2})[-.\/]{1}([0-9]{4})$/);
		
		if (match != null) {
		  dataValida = new Date(match[3],match[2]-1,match[1]);
		  valido = ((dataValida.getMonth() == match[2]-1) && (dataValida.getDate() == match[1])) 
		  if (valido != false){if (no != '') {document.getElementById(no).innerHTML = '<br/>';}
		                       document.getElementById(elim).disabled = false;
							   return(1);} 
		  else {if (no != '') {document.getElementById(no).innerHTML = 'Data non valida';}
		        document.getElementById(elim).disabled = true;
		        return false;}}
		else{if (no != '') {document.getElementById(no).innerHTML = 'Data non valida';}
		     document.getElementById(elim).disabled = true;
			 return false;}
		}

function ContrData(sorg){
	    frm = document.forms[sorg];
	    data = frm.data.value;
        match = data.match(/^([0-9]{2})[-.\/]{1}([0-9]{2})[-.\/]{1}([0-9]{4})$/);
		
		if (match != null) {
		  dataValida = new Date(match[3],match[2]-1,match[1]);
		  valido = ((dataValida.getMonth() == match[2]-1) && (dataValida.getDate() == match[1])) 
		  if (valido != false){} 
		  else if (valido == false) {alert('Data non valida');
		        return false;}}
		else{alert('Data non valida');
			 return false;}
		}

function htmlEncode(source,ida){
	    var result = '';
	     for (i=0; i < source.length; i++) {
			 if (source.charCodeAt(i) == 10){result += '<br/>'}
			 else if (source.charAt(i) == '\''){result += '&#'+source.charCodeAt(i)+';'}
			 else if (source.charCodeAt(i) < 32||source.charCodeAt(i) > 126){
				 result += '&#'+source.charCodeAt(i)+';'}
		     else {result += source.charAt(i);}
		 }
		 document.getElementById(ida).value = result;
}

function htmlEncode1(ida){
	    var source = document.getElementById(ida).value;
	    var result = '';
	     for (i=0; i < source.length; i++) {
			 if (source.charCodeAt(i) == 10){result += '<br/>'}
			 else if (source.charAt(i) == '\''){result += '&#'+source.charCodeAt(i)+';'}
			 else if (source.charCodeAt(i) < 32||source.charCodeAt(i) > 126){
				 result += '&#'+source.charCodeAt(i)+';'}
		     else {result += source.charAt(i);}
		 }
		 document.getElementById(ida).value = result;
}

