<!--

//CONTROLLO TEXT OBBLIGATORIA
function checkText(mytext, name){
    trim(mytext)
	if (mytext.value==""){
		alert("Insert "+name+" in the corresponding field");
		mytext.focus();
		return false;
		}
	else
    return true;
}

//CONTROLLA CAMPO NUMERICO  
function checkNumber(mytext, name)
{
   if (mytext.value.match(/\D/)) {
         alert("The field "+name+"  must be numeric")   //non è un numero
  	  mytext.focus();
      return false
	  }
   else
    return true
}

//CONTROLLA euro
function checkEuro(mytext, name)  
 {
  trim(mytext)
  var ch,vir
  vir=0
  if (mytext.value=="") return true
  for (var i = 0; i < mytext.value.length; i++)
    {
     ch = mytext.value.substring(i, i + 1)
 	 if (ch==',') vir+=1
     if ((ch < "0" || ch > "9") && (ch != ","))
     {
     alert("The field "+name+" must be numeric")
	    mytext.focus();
	    return false
		}
    }
if ((vir!=1)||((mytext.value.substring(mytext.value.length-3, mytext.value.length-2)!=',')))
	  {
	    alert("The field "+name+" is not written correctly (es. 100,00)")
	    mytext.focus();
	    return false
		}
  return true
}

//CONTROLLO LISTA O SELECT A DISCESA OBBLIGATORIA
function checkSelect(myselect, checkInd, name){
	if (myselect.selectedIndex==checkInd){
		if (name==''){
			alert("Select un item from the list");
			myselect.focus();
			}
		else{
			alert("Select un item from the list: "+name);
			myselect.focus();
		}
		return false;
		}
	else
	 	return true;
}

//CONTROLLO SE UN DETERMINATO RADIO BUTTON E' STATO PREMUTO
function whatRadio(mytext, num, name, msg){
 if (mytext[num].checked)
  {
   if (msg==1) alert(name)
   return false
  }
  return true
}


function check_mail(mymail)
{
   Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   if (Filtro.test(mymail.value))
      return true;
   else
      {
      alert("please check the email spelling");
      mymail.focus();
      return false;
      }
}

//CONTROLLA LUNGHEZZA DI UNA TEXTAREA
function checkTextAreaLenght(mytext, name, dim){
  if (mytext.value.length>dim) {
       alert("The field "+name+" cannot contain more than "+dim+" characters");
	   mytext.value=mytext.value.substring(0,dim)
   	   mytext.focus();	   
	   return false;
	   }
  else 
   return true	     
}

//Va alla pagina indicata, con submit di un form.
function GoToPage(form, DestPage){
	form.method ='Post';
	form.action = DestPage;
	form.submit();
}

//TORNA INDIETRO DI 1 PAG.
function TornaIndietro(){
	window.history.back(-1);
}

//TRIM
function trim(mytext)
{
//mytext.value=mytext.value.match(/^ *([^ ].*[^ ]|[^ ]|$) *$/)[1].replace(/^$/,''); 
mytext.value=mytext.value.replace(/ *\n */g,'\n').replace(/ *\r */g,'\r').replace(/^ */g,'').replace(/ *$/g,'').replace(/(\r\n)*$/g,"")
//mytext.value=mytext.value.replace(/ *\n */g,'\n').replace(/ *\r */g,'\r').replace(/^ */g,'').replace(/ *$/g,'').replace(/(\r\n)*$/g,"").replace(/'/g,"''");
}

//SCRIVE SU UN HIDDEN IL TESTO SELEZIONATO IN LISTA
function scriviDescr_lista(lista, campoDescr) {
	if(lista.selectedIndex>0){
		campoDescr.value=lista[lista.selectedIndex].text
	}
	else {campoDescr.value=""}
	//alert('Campo descr = '+campoDescr.value)
}

//AGGIUNGE UN ELEMENTO A UNA LISTA
function Add_lista(lista, pos, testo) {
	var optElem;
	//alert(pos);
	//alert(testo);
	
	optElem = new Option;
	optElem.text = testo;
	optElem.value = testo;
//	alert (optElem.value);
	lista[pos] = optElem;
}

//RIMUOVE UN ELEMENTO DA UNA LISTA
function Remove_lista(lista, indice, campoCount) {
	//alert(indice);
	lista[indice] = null;
	//aggiorna_stanze.lista_count.value=parseInt(aggiorna_stanze.lista_count.value)-1;
	campoCount.value=parseInt(campoCount.value)-1;
	lista.focus();
}

//RIMUOVE TUTTI GLI ELEMENTI DA UNA LISTA
function Svuota_lista(lista, campoCount) {
	for (var i=0;i<campoCount;i++)
	{
		lista[i] = null;
	}
	campoCount.value=0;
	//alert (campoCount.value);
}


//CONTROLLO RADIO BUTTON OBBLIGATORIO
function checkRadio(myradio, num, name){
//num = numero delle scelte
 if (num>1)
  {
  for (var i=0;i<num;i++)
  	if (myradio[i].checked) return true;
  alert("Select "+name)
  return false;	   
  }
 else
  if (myradio.checked) return true
  else
   {
    alert("Select "+name)
	return false;	   
   }
}

function checkExt(myfile, name){
	trim(myfile)
    
    //(.*\.(([wW][mM][aA])|([mM][pP][3]))$)
	
	//RegExp=/\.(doc|xls|txt|rtf|pdf) *$/i
	//RegExp=(.*\.(([jJ][pP][gG])|([jJ][pP][eE][gG])|([jJ][pP][eE]))$)
	RegExp=/\.([jJ][pP][gG]|[jJ][pP][eE][gG]|[jJ][pP][eE]) *$/i
	if (!RegExp.test(myfile.value))
	//if (!myfile.value.match(RegExp))
	{
		alert ("The File "+name+" is not supported (.jpg, .jpeg, .jpe).");
		return false;
    } 
	return true;
}


//CONTROLLO RADIO BUTTON OBBLIGATORIO QUANDO NON CI SONO ALTRI CONTROLLI NELLA PAGINA
//function checkRadio(form, name){
//  for (var i=0;i<form.elements.length;i++)
//    {
//    var e = form.elements[i];
//    if (e.checked) return true;
//    }
//    alert("Selezionare un elemento dalla lista: "+name)
//  	return false;	
//}

//FINE CONTROLLI FORM
//-->