
function miostatus() { //v2.0
  status=" ";
  }


function checkMail(myForm) {
	var ok = false;
	var mess = 'Attenzione!\n ';
	if (myForm.email.value=='') {
		ok = false;
		mess = mess + 'Bisogna inserire l\'e-mail!\n';
	} else {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.email.value)) {
			ok = true;
		} else {
			ok = false;
			mess = mess + 'Email non corretta!\n';
		}
	}
	if (!ok) {
		alert(mess);
		return false;
	} else {
		return true;
	}
}

function checkMailValue(emailValue) {
	var ok = false;
	var mess = 'Attenzione!\n ';
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailValue)) {
		ok = true;
	} else {
		ok = false;
		mess = mess + 'Email non corretta!\n';
	}
	if (!ok) {
		return false;
	} else {
		return true;
	}
}

function chkEmptyTxt(txt){
	var myRegExp;
	
	myRegExp = /^(\s*)$/;
	if (myRegExp.test(txt)) { 
		//alert("NO");
		return false
		}
	else {
		//alert("SI");
		return true
	}
}

function chkNumericFields(myForm){
	var myRegExp;
	var i;
	var ok = true;
	myRegExp = /^(\d*)$/;
	for (i=0; i < myForm.elements.length ; i++) {
		if (myForm.elements[i].type == 'text') {
			if (!myRegExp.test(myForm.elements[i].value)) { 
				ok = false;
			}
		}
	}
	if (ok) {
		return true;
	} else {
		//	alert('I campi quantità devono essere numerici!');
		return false;
	}
}


function chkNumericTxt(txt){
	var myRegExp;
	
	myRegExp = /^(\d*)$/;
	if (myRegExp.test(txt)) { 
		//alert("NO");
		return false
		}
	else {
		//alert("SI");
		return true
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function controllaModulo(laform){
	var ret;
	ret=true;
	mess='Attenzione!\n';
	
	if (laform.Nome.value==''){
		ret=false;
		mess += "Bisogna inserire il nome!\n";
	}
	if (laform.Cognome.value==''){
		ret=false;
		mess += "Bisogna inserire il cognome!\n";
	}
	if (laform.mymail.value==''){
		ret=false;
		mess += "Bisogna inserire l\'indirizzo e-mail!\n";
	} else {
		if (!checkMailValue(laform.mymail.value)) {
			ret=false;
			mess += "Indirizzo e-mail non corretto!\n";
		}
	}
	if (laform.Oggetto.value==''){
		ret=false;
		mess += "Bisogna inserire l\'oggetto della richiesta!\n";
	}
	if (laform.messaggio.value==''){
		ret=false;
		mess += "Bisogna inserire il messaggio!\n";
	}
	
	if (!controllapriv(laform)) {
		ret=false;
		mess += "Manca il consenso al trattamento dei dati personali!\n";
	}
	
	if (ret == true) {
		return true;
	} else{
		alert(mess);
		return false;
	}
}


function controllapriv(laform){
	var ret;
	ret=true;
	if (laform.accetto[1].checked==true){
		return false;
	}
	else{
		return true;
	}
}

//JavaScript per il controllo dei caratteri non unicode
function controllaCaratteri(str,nomecampo){
	var n,m;
	var i;
	var ok;
	var c,val;
	var riga,pos;
	var ret;
	var messaggio;
	
	messaggio='';
	ret=true;
	n=str.length;
	i=0;
	riga=1;
	pos=1;
	ok=1;					
	while ((i<n) && (ok==1)){
		c=str.charAt(i);
		c=escape(c);
		//alert(c);		
		if (c.indexOf("%")==0){
	  		val=c.substring(1,c.length);
			m=parseInt(val,16);

			if ( (m<1) || (m>255) || isNaN(m) ){
				
				
				ok=0;
			}
		} 
		if (str.charAt(i)==String.fromCharCode(10)) {
			riga=riga+1;
			pos=1;
		} else {
			pos=pos+1;
		}		
		i=i+1;
	}

	if (ok==0){
		//var messaggio;
		var min,max;
		//COmpongo il messaggio di avviso
		messaggio= nomecampo + ": inserito carattere non valido!\r";	
		if ((i-10) < 0)
			min = 0;
		else
			min = i-10;
		if ((i+10) > (str.length-1))
			max = (str.length-1);
		else
			max = i+10;			
		messaggio=messaggio + "Riga:" + riga + " Pos: " + pos + "\r";
		for(n=min;n<=max;n++) {
			if ( (str.charAt(n)==String.fromCharCode(10)) 
			||	(str.charAt(n)==String.fromCharCode(13)) 
			){
				messaggio = messaggio + ' ';				
			} else {
				if (n==(i-1))
					messaggio = messaggio + ' >' + str.charAt(n) + '< ';
				else
					messaggio = messaggio + str.charAt(n);
			}
			
		}		
		messaggio=messaggio + "\r";				
		/*
		for(n=min;n<=max;n++) {
			if (n==i)
				messaggio = messaggio + "^";
			else
				messaggio = messaggio + " ";
		}
		*/		
		ret=false;
	}

	return(messaggio);
}

function isNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}