function controllaSeNumero(id,obbligatorio,msg){
      obj=document.getElementById(id);
      if (trim(obj.value)=="" && obbligatorio){
            if (msg==null)
                  alert("Inserire un valore numerico nel campo!!");
            else
                  alert(''+ msg);
            obj.select(); 
            obj.focus();
            return false; 
      }
      if (isNaN(obj.value)){
            if(msg==null)
                  alert("Inserire un valore numerico nel campo!!");
            else
                  alert('' + msg);
            obj.select(); 
            obj.focus(); 
            //event.preventDefault();
            return false;
      }
      else
            return true;
}

function campoNonVuoto(id,msg){
       obj=document.getElementById(id);
       if (obj.value==""){
            if (msg==null)
                  alert("Inserire un valore nel campo!!");
            else
                  alert(msg);
            obj.select(); 
            obj.focus(); 
            //event.preventDefault() ;
            return false;
      }
      else
            return true;          
}

function sostituisciVirgola(obj){
      //alert(event.keyCode)  
      //obj=document.getElementById(id);        
      if(event.keyCode==188)
            obj.value=(obj.value).replace(",",".");
}

function  eseguiOp(op,indice,form){
      var conf=true;
      if (op=='cancella')
            if (!confirm('Eliminare la riga selezionata?'))
                  conf=false;
                  
      if (conf){
            document.getElementById("txtOperazione").value=op;
            document.getElementById("txtCodice").value=indice;
            document.forms[form].submit();      
      }
}

function eseguiOpSalva(op,codice,form){ 
      var conf=true;
      if (op=='annullaSalva')
            if (!confirm('Annullare l\'operazione?'))
                  conf=false;
                  
      if (conf){
            document.getElementById("txtSalva").value=op;
            document.getElementById("txtCodice").value=codice;
            document.forms[form].submit();      
      }
}

function scegliMenu(menu){
      document.getElementById("txtMenuScelto").value=menu; 
      document.formMenu.submit();     
}

function  confermaAnnulla(op){
      var conf=true;
      if (op=='annulla')
            if (!confirm('Annullare tutte le modifiche eseguite fino ad ora?'))
                  conf=false;
                  
      if (conf){
            document.getElementById("txtConfAnn").value=op;
            document.formConfAnnModifiche.submit();      
      }
}

function trim(inputString) {
	// Removes leading and trailing spaces from the passed string. Also removes
	// consecutive spaces and replaces it with one space. If something besides
	// a string is passed in (null, custom object, etc.) then return the input.
	if (typeof inputString != "string") { return inputString; }
	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") { // Check for spaces at the beginning of the string
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") { // Check for spaces at the end of the string
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}
	return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function ControllaMail(MailToCheck)
{
	Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if ((Filtro.test(MailToCheck))||(MailToCheck=="")){
		return true;
	}
	else{
		return false;
	}
}

/*function ControllaMail(MailToCheck)
{
	Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if ((Filtro.test(MailToCheck))||(MailToCheck=="")){
		return true;
	}
	else{
		return false;
	}
}*/

//Richiamata dal filmato Flash delle News
function RedirToNews(id){
  window.location="http://www.bsdsoftware.it/bsd_site/bsd_site_news/news.php?idNews=" + id;
}

function RedirToPromo(){
  window.location="http://www.bsdsoftware.it/bsd_site/bsd_site_demo/demo.php";
}

function RedirTo(){
  window.location="http://www.bsdsoftware.it/bsd_site/bsd_site_demo/demo.php";
}

function RedirToStaff(par){
  switch(par){
    case 'B':
      visualizza('Brighi');
      break;
    case 'S':
      visualizza('Sabbattini');
      break;
    case 'D':
      visualizza('DellaChiesa');
      break;
  }
}

