//***** funzione di reset campi di un form di tipo "text" "textarea" "select" ****//
function resetForm(form){
var formLen = form.length;
for (i=0;i<formLen;i++)
   {
   
   var formType=form[i].type;
   var formName=form[i].name;
      
   if(formType=="text" || formType=="file" || formType=="textarea" || formType=="password")      
      form[i].value="";
 
   if(formType=="select-one" || formType=="select-multiple" || formType=="select")
      {
      var selLen= form[i].options.length;
      for(j=0;j<selLen;j++)
         {
         form[i].options[j].selected=false;
         }
      form[i].options[0].selected=true;
      }
   }
}


function viewDoc(myURL)
{
  str = myURL;
  win = window.open(str, "win", "scrollbars=yes,toolbar=yes,menubar=yes,status=yes,resizable=yes");
  //top.Principale.location = str;
  //win.top.location = str;
  win.focus();
}



function viewAbout(myURL)
{
  str = myURL;
  about = window.open(str, "About", "scrollbars=no,toolbar=no,menubar=no,status=no,resizable=no,width=275,height=100");
  //top.Principale.location = str;
  //win.top.location = str;
  about.focus();
}

function viewHelp(myURL)
{
  str = myURL;
  about = window.open(str, "Help", "scrollbars=yes,toolbar=yes,menubar=yes,status=no,resizable=yes,width=500,height=300");
  //top.Principale.location = str;
  //win.top.location = str;
  about.focus();
}

function redirect(url)
{	
  //alert(url);
  top.location = url;
}

function moveItem(form, source, dest)
{
  fromSelectBox = document[form][source];
  toSelectBox = document[form][dest];
  
  var selectedIndex = null, selectedOption = null ;
	var selectedCount = toSelectBox.length ;

   while ((selectedIndex = fromSelectBox.selectedIndex) >= 0) {
      selectedOption = fromSelectBox.options[ selectedIndex ] ;
      
      var newOption = new Option(selectedOption.text, selectedOption.value, true, true) ;
      var newIndex = toSelectBox.length ;
      toSelectBox.options[newIndex] = newOption ;

      fromSelectBox.options[fromSelectBox.selectedIndex] = null ;
   }
   
   //  if this is Netscape and the selectedAttribute list was empty,
   //    force a page refresh so the select box will resize itself
   //if (isNav4 && selectedCount == 0) {
   //	window.history.go(0);
   //}

  /*
  // source box
  so_box = document[form][source];
  // destination box
  de_box = document[form][dest];
  
  // test
  so_i = so_box.options.selectedIndex;
  if ((so_i >= 0) && (so_i < so_box.length))
  {
    myOptions = so_box.options;
    for(i=0; i < myOptions.length; i++)
    {
      if (myOptions[i].selected)
      {
        // New Option
        newOption = new Option(myOptions[i].text, myOptions[i].value, false, true);
        // put it to destination SELECT
        de_box.options[de_box.options.length] = newOption;
        myOptions[i] = null;
      }
    }
  }
  */
}

function abilitaCheck(sel,form) {
var howmany= form.elements.length;
for (j=0;j<howmany;j++)
{
  var myType=form.elements[j].type;
  if (myType=="checkbox")
    {
    var theName = 'ck' + sel;
    
    if(form.elements[j].id==theName)
      {
      form.elements[j].checked=true;
      }
    else
      {
      form.elements[j].checked=false;
      }
    if(form.elements[j].disabled==false)
      {
      form.elements[j].disabled=true;
      }
    }
  }
var selectedRadio = eval('form.ck'+sel+';');
if (selectedRadio != null)
  {
  var len= selectedRadio.length;
  for (i=0;i<len;i++)
    {
    selectedRadio[i].disabled=false;
    }
  }
}


function process(form, selectionColumn)
{
  myOptions = form[selectionColumn].options;
  for(i=0; i < myOptions.length; i++)
  {
    myOptions[i].selected = true;
  }
  
// provvisorie  (test)
function disable(elem) { // elem: form element to be disabled
  elem.onfocus=elem.blur;
}

//provvisorie (test)
function enable(elem) { // elem: form element to be reenabled
  elem.onfocus=null;
}
  
  
function waiting() {
  alert("SONO QUI");
  document.getElementById("myData").innerHTML='<table><tr>'
  +'<td height="250" align="center" valign="middle" class="waiting">'
  +'attendere prego...'
  +'</td></tr></table>';
  }  
  
}


function submitEvent(ths, timeOut){
  var xxx='<input type="hidden" name="'+ ths.name +'" value="'+ ths.value +'">';
  eval(ths.name + '.innerHTML=xxx;');
  setTimeout('makeWait()', timeOut);
  ths.form.submit();
}

// apriPagina(destination link) add a new parameter at link
function apriPagina(ref) {
  //link
  var newUrl= ref;
  //var len=document.sceltaEtichette.elements.length;
  var len=document.forms[0].elements.length;
  var myVal=null;
    //loop objects present into a form 
    for (i=0;i<len;i++)
       {
       if (document.sceltaEtichette.elements[i].checked==true)
         {
           myVal=document.sceltaEtichette.elements[i].value;
         }
       }
  //add a new parameters    
  newUrl = newUrl + "/sezioneScelta/"+ myVal;
  
  viewDoc(newUrl);

}

/*** funzione che cambia il beakground color della cella 
     a cui appartiene il radio button ***/
function changeBG(ths) {
 
var thsForm = ths.form.elements;
var numEl = thsForm.length;
var ckdIndx;
for (var i=0;i<numEl;i++)
   {
   var e = thsForm[i];
   if (e.type=='radio' && e.checked)
      ckdIndx = i;
   }
for (var i=0;i<numEl;i++)
   {
   var e = thsForm[i];
   if (e.type=='radio' && i<ckdIndx)
       thsForm[i].parentElement.className="notToPrint";
      //thsForm[i].parentElement.style.backgroundColor='#C1CDD8';
   if (e.type=='radio' && i>=ckdIndx)
      thsForm[i].parentElement.className="toPrint";
      //thsForm[i].parentElement.style.backgroundColor='#ffffff';
   }
}

