function isNetscape()
{
  isnetscape = false;
  if(navigator.appName.substring(0,8) == "Netscape" )
  {
    isnetscape = true;
  }
  return isnetscape;
}

function myDecodeURIComponent(textURIEncoded)
{
  value = textURIEncoded;
  try
  {
    value = decodeURIComponent(textURIEncoded);
  }
  catch(error)
  {
    value = textURIEncoded;
  }
  return value;
}

function cancellaData(formDati, nomeCampoData)
{
  elementi = formDati.elements;
  if((elementi != null) && (elementi != undefined))
  {
    for(i = 0; i < elementi.length; i++)
    {
      if((elementi[i] != null) && (elementi[i] != undefined) && (!isEmpty(elementi[i].name)))
      {  
        if(elementi[i].name.indexOf(nomeCampoData) == 0)
        {
          elementi[i].value = "";
        }
      }  
    }
  }
}

function disableElements(formDati, idValue, disableValue)
{
  if(idValue)
  {
    elementi = formDati.elements;
    if((elementi != null) && (elementi != undefined))
    {
      for(i = 0; i < elementi.length; i++)
      {
        if((elementi[i] != null) && (elementi[i] != undefined) && (elementi[i].id) && (!isEmpty(elementi[i].id)))
        {  
          if(elementi[i].id.toLowerCase() == idValue.toLowerCase())
          {
            elementi[i].disabled = disableValue;
          }
        }  
      }
    }
  }
}

function setNavigation(theForm, navigatorName, valore)
{
  var elementi = theForm.elements;
  elementName = navigatorName + ".thisPage"
  for(i = 0; i < elementi.length; i++)
  {
    if(elementi[i].name.indexOf(elementName) == 0)
    {
      elementi[i].value = myDecodeURIComponent(valore);
      break;
    }      
  }
  theForm.submit();
}

function setNavigatorPage(theForm, navigatorName, valore)
{
  elementName = navigatorName + "_currentPage";
  obj = theForm.elements.namedItem(elementName);
  if((obj != null) && (obj != undefined) && (!isEmpty(obj.name)))
  {  
    obj.value = myDecodeURIComponent(valore);
  }
  theForm.submit();
}

function removeSelectOptions(select, fromindex)
{
  if(select)
  { 
    if((select.options) && (select.options.length) && (select.options.length > 0))
    {
      i = 0;
      if(eNumero(fromindex))
      {
        i = parseInt(fromindex);
        if(i >= select.options.length)  
        {
          i = -1;
        }
        for(;((i >= 0) && (i < select.options.length));)
        {
          if(select.options.remove)
          {
            select.options.remove(i);
          }
          else if(select.remove)
          {
            select.remove(i);
          }
        }
      }
    }
  }
}

function selectOption(select, value)
{
  if((select != null) && (! isEmpty(value)))
  {    
    value = myDecodeURIComponent(value);
    elements = select.options;
    if((elements != null) && (elements.length > 0))
    {
      for(i = 0; i < elements.length; i++)
      {
        if(value == elements[i].value)
        {  
          select.selectedIndex = i;
          break;  
        }  
      }
    }
  }
}

function selectOptionNoCase(select, value)
{
  if((select != null) && (! isEmpty(value)))
  {    
    value = myDecodeURIComponent(value);
    elements = select.options;
    if((elements != null) && (elements.length > 0))
    {
      value = value.toLowerCase();
      for(i = 0; i < elements.length; i++)
      {
        if(value == elements[i].value.toLowerCase())
        {  
          select.selectedIndex = i;
          break;  
        }  
      }
    }
  }
}

function selectMultipleOption(select, values, valueseparator)
{
  if((select != null) && (! isEmpty(values)))
  {    
    select.selectedIndex = -1;
    values = myDecodeURIComponent(values);
    vals = tokenizeString(values, valueseparator, false);
    if((vals != null) && (vals != undefined) && (vals.length > 0))
    {
      elements = select.options;      
      if((elements != null) && (elements.length > 0))
      {
        for(i = 0; i < vals.length; i++)
        {
          for(j = 0; j < elements.length; j++)
          {
            if(vals[i] == elements[j].value)
            {  
              elements[j].selected = true;
              break;
            }
          }
        }
      }
    }
  }
}

function selectOptionByID(select, IDvalue)
{
  if((select != null) && (! isEmpty(IDvalue)))
  {    
    IDvalue = myDecodeURIComponent(IDvalue);
    elements = select.options;
    if((elements != null) && (elements.length > 0))
    {
      for(i = 0; i < elements.length; i++)
      {
        if(IDvalue == elements[i].id)
        {  
          select.selectedIndex = i;
          break;  
        }  
      }
    }
  }
}

function selectOptionByIdPart(select, IDPartvalue)
{
  if((select != null) && (! isEmpty(IDPartvalue)))
  {    
    IDvalue = myDecodeURIComponent(IDPartvalue);
    elements = select.options;
    if((elements != null) && (elements.length > 0))
    {
      for(i = 0; i < elements.length; i++)
      {
        if(elements[i].id.indexOf(IDvalue) >= 0)
        {  
          select.selectedIndex = i;
          break;  
        }  
      }
    }
  }
}

function selectOptionRounding(select, valore)
{
  if(!isEmpty(valore))
  {
    value = parseInt(valore);
    elements = select.options;
    size = elements.length;      
    idx = 0;
    for(i = 0; i < size; i++)
    {
      if(elements[i].value >= value)
      {
        idx = i;
        break;
      }
    }
    if((idx >= 0) && (idx < size))
    {
      value = elements[idx].value;
      selectOption(select, value);
    }
  }
}

function setTextValue(text, value)
{ 
  if((text != null) && (! isEmpty(value)))
  {    
    value = myDecodeURIComponent(value);
    if(text.value != null)
    {
      text.value = value;
    }
  }
}

function selectCheckBox(checkbox, value)
{
  if((checkbox != null) && (! isEmpty(value)))
  {    
    if(checkbox.value != null)
    {      
      value = Trim(value).toLowerCase();
      if((value == '1') || (value == 'true') || (value == 'yes') || (value == 'si'))
      {
        checkbox.checked = true;
      }
    }
  }
}

function isRadioSelected(radioButtons)
{
  go = false;
  selected = getSelectedRadio(radioButtons);
  if(selected)
  {
    go = true;
  }
  return go;
}

function getSelectedRadio(radioButtons)
{
  selected = null;
  if((radioButtons != null) && (radioButtons != undefined))
  {     
    if(eNumero(radioButtons.length))
    {
      for(i = 0; i < radioButtons.length; i++)
      {
        if(radioButtons[i].checked == true)
        {
          selected = radioButtons[i];
          break;
        }
      }
    }
    else if((radioButtons.value != null) && (radioButtons.value != undefined)) // E' uno solo
    {
      if(radioButtons.checked == true)
      {      
        selected = radioButtons;
      }
    }
  }
  return selected;
}

function selectRadioByValue(checkbox, value)
{
  if((checkbox != null) && (! isEmpty(value)))
  {    
    if(checkbox.value != null)
    {
      value = Trim(myDecodeURIComponent(value)).toLowerCase();
      if(Trim(checkbox.value).toLowerCase() == value)
      {
        checkbox.checked = true;
      }
    }
  }
}

function selectMultipleRadioByValue(radioarray, value)
{
  
  if((radioarray != null) && (! isEmpty(value)))
  {    
    if(!eNumero(radioarray.value))
    {
      for(i = 0; i < radioarray.length; i++)
      {
        selectRadioByValue(radioarray[i], value);
      }
    }
    else
    {
      selectRadioByValue(radioarray, value);
    }
  }
}

function selectRadioByAlt(checkbox, value)
{
  if((checkbox != null) && (! isEmpty(value)))
  {    
    if(checkbox.alt != null)
    {
      value = Trim(myDecodeURIComponent(value)).toLowerCase();
      if(Trim(checkbox.alt).toLowerCase() == value)
      {
        checkbox.checked = true;
      }
    }
  }
}

function selectMultipleRadioByAlt(radioarray, value)
{
  if((radioarray != null) && (! isEmpty(value)))
  {    
    if(!eNumero(radioarray.value))
    {
      for(i = 0; i < radioarray.length; i++)
      {
        selectRadioByAlt(radioarray[i], value);
      }
    }
    else
    {
      selectRadioByAlt(radioarray, value);
    }
  }
}

function LTrim(text)
{
  if(text == null || text.length == 0)
  {
    return "";      
  }      
  idx = 0;
  text = myDecodeURIComponent(text);
  while(text.charAt(idx) == ' ')
  {
    ++idx;
    if(idx >= text.length)
      break; 
  }
  if(idx < text.length)
  {
    return text.substring(idx);
  }
  else  
    return "";
}

function RTrim(text)
{
  if(text == null || text.length == 0)
  {
    return "";      
  }
  text = myDecodeURIComponent(text);
  idx = text.length - 1;
  while(text.charAt(idx) == ' ')
  {
    --idx;
    if(idx < 0)
      break;
  }
  if(idx >= 0)
  {
    return text.substring(0, (idx + 1));
  }    
  else  
    return "";
}

function Trim(text)
{
  testo = LTrim(text);
  testo = RTrim(testo);
  return testo;
}

function isEmpty(text)
{
  if(text == null)
  {
    return true;  
  }
  else
  {
    testo = Trim(text);
    if(testo.length == 0)
    {
      return true;
    }
    else
      return false;
  }
}

function rendiNumero(text)
{
  text = Trim(myDecodeURIComponent(text));
  if(text.indexOf(",") >= 0)
  {
    text = text.replace(".", "");
    text = text.replace(",", ".");
  }
  while((text.indexOf("0") == 0) && (text.length > 1) && ((text.indexOf(".") < 0) || (text.indexOf(".") > 1)))
  {
    text = text.substring(1);
  }
  return Trim(text);
}

function eNumero(text)
{
  text = myDecodeURIComponent(text);
  if(isEmpty(text))
  {
    return false;  
  }
  else
  {        
    testo = rendiNumero(text);
    ok = (!isNaN(testo));
    ok = (ok && isFinite(testo));  
    return ok;
  }
}

function openPopupAtPosition(iTop, iLeft, width, height, redirect) 
{
  innerITop = iTop;
  innerILeft = iLeft;  
  windowOuterHeight = window.outerHeight;
  windowOuterWidth = window.outerWidth;
  if(isEmpty(innerITop) || (!eNumero(innerITop)) || (parseInt('' + innerITop) < 0))
  {
    if(isEmpty(windowOuterHeight) || (!eNumero(windowOuterHeight)))
    {    
      windowOuterHeight = window.screen.height;
      if(isEmpty(windowOuterHeight) || (!eNumero(windowOuterHeight)))
      {      
        windowOuterHeight = height;
      }      
    }
    innerITop = Math.round((windowOuterHeight / 2) - (height / 2));
  }
  if(isEmpty(innerILeft) || (!eNumero(innerILeft)) || (parseInt('' + innerILeft) < 0))
  {
    if(isEmpty(windowOuterWidth) || (!eNumero(windowOuterWidth)))
    {      
      windowOuterWidth = window.screen.width;
      if(isEmpty(windowOuterWidth) || (!eNumero(windowOuterWidth)))
      {      
        windowOuterWidth = width;
      }
    }
    innerILeft = Math.round((windowOuterWidth / 2) - (width / 2));
  }

  var OpenWindow = myDecodeURIComponent(redirect);
  var params = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',top='+innerITop+',left='+innerILeft
  popup = window.open(OpenWindow, "Popup", params);
}

function openPopupAtPositionWithStatus(iTop, iLeft, width, height, redirect) 
{
  innerITop = iTop;
  innerILeft = iLeft;  
  windowOuterHeight = window.outerHeight;
  windowOuterWidth = window.outerWidth;
  if(isEmpty(innerITop) || (!eNumero(innerITop)) || (parseInt('' + innerITop) < 0))
  {
    if(isEmpty(windowOuterHeight) || (!eNumero(windowOuterHeight)))
    {    
      windowOuterHeight = window.screen.height;
      if(isEmpty(windowOuterHeight) || (!eNumero(windowOuterHeight)))
      {      
        windowOuterHeight = height;
      }      
    }
    innerITop = Math.round((windowOuterHeight / 2) - (height / 2));
  }
  if(isEmpty(innerILeft) || (!eNumero(innerILeft)) || (parseInt('' + innerILeft) < 0))
  {
    if(isEmpty(windowOuterWidth) || (!eNumero(windowOuterWidth)))
    {      
      windowOuterWidth = window.screen.width;
      if(isEmpty(windowOuterWidth) || (!eNumero(windowOuterWidth)))
      {      
        windowOuterWidth = width;
      }
    }
    innerILeft = Math.round((windowOuterWidth / 2) - (width / 2));
  }

  var OpenWindow = myDecodeURIComponent(redirect);
  var params = 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',top='+innerITop+',left='+innerILeft
  popup = window.open(OpenWindow, "Popup", params);
}

function openPopupAtPositionNoScrollbar(iTop, iLeft, width, height, redirect) 
{
  innerITop = iTop;
  innerILeft = iLeft;  
  windowOuterHeight = window.outerHeight;
  windowOuterWidth = window.outerWidth;
  if(isEmpty(innerITop) || (!eNumero(innerITop)) || (parseInt('' + innerITop) < 0))
  {
    if(isEmpty(windowOuterHeight) || (!eNumero(windowOuterHeight)))
    {    
      windowOuterHeight = window.screen.height;
      if(isEmpty(windowOuterHeight) || (!eNumero(windowOuterHeight)))
      {      
        windowOuterHeight = height;
      }      
    }
    innerITop = Math.round((windowOuterHeight / 2) - (height / 2));
  }
  if(isEmpty(innerILeft) || (!eNumero(innerILeft)) || (parseInt('' + innerILeft) < 0))
  {
    if(isEmpty(windowOuterWidth) || (!eNumero(windowOuterWidth)))
    {      
      windowOuterWidth = window.screen.width;
      if(isEmpty(windowOuterWidth) || (!eNumero(windowOuterWidth)))
      {      
        windowOuterWidth = width;
      }
    }
    innerILeft = Math.round((windowOuterWidth / 2) - (width / 2));
  }

  var OpenWindow = myDecodeURIComponent(redirect);
  var params = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + width + ',height=' + height + ',left=' + innerILeft + ',top=' + innerITop;
  popup = window.open(OpenWindow, "Popup", params);
}

function openPopupAtPositionNoScrollbarResizable(iTop, iLeft, width, height, redirect) 
{
  innerITop = iTop;
  innerILeft = iLeft;  
  windowOuterHeight = window.outerHeight;
  windowOuterWidth = window.outerWidth;
  if(isEmpty(innerITop) || (!eNumero(innerITop)) || (parseInt('' + innerITop) < 0))
  {
    if(isEmpty(windowOuterHeight) || (!eNumero(windowOuterHeight)))
    {    
      windowOuterHeight = window.screen.height;
      if(isEmpty(windowOuterHeight) || (!eNumero(windowOuterHeight)))
      {      
        windowOuterHeight = height;
      }      
    }
    innerITop = Math.round((windowOuterHeight / 2) - (height / 2));
  }
  if(isEmpty(innerILeft) || (!eNumero(innerILeft)) || (parseInt('' + innerILeft) < 0))
  {
    if(isEmpty(windowOuterWidth) || (!eNumero(windowOuterWidth)))
    {      
      windowOuterWidth = window.screen.width;
      if(isEmpty(windowOuterWidth) || (!eNumero(windowOuterWidth)))
      {      
        windowOuterWidth = width;
      }
    }
    innerILeft = Math.round((windowOuterWidth / 2) - (width / 2));
  }

  var OpenWindow = myDecodeURIComponent(redirect);
  var params = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=' + width + ',height=' + height + ',top='+innerITop+',left='+innerILeft
  popup = window.open(OpenWindow, "Popup", params);
}

function openPopupAtPositionScrollbarNoResizable(iTop, iLeft, width, height, redirect) 
{
  innerITop = iTop;
  innerILeft = iLeft;  
  windowOuterHeight = window.outerHeight;
  windowOuterWidth = window.outerWidth;
  if(isEmpty(innerITop) || (!eNumero(innerITop)) || (parseInt('' + innerITop) < 0))
  {
    if(isEmpty(windowOuterHeight) || (!eNumero(windowOuterHeight)))
    {    
      windowOuterHeight = window.screen.height;
      if(isEmpty(windowOuterHeight) || (!eNumero(windowOuterHeight)))
      {      
        windowOuterHeight = height;
      }      
    }
    innerITop = Math.round((windowOuterHeight / 2) - (height / 2));
  }
  if(isEmpty(innerILeft) || (!eNumero(innerILeft)) || (parseInt('' + innerILeft) < 0))
  {
    if(isEmpty(windowOuterWidth) || (!eNumero(windowOuterWidth)))
    {      
      windowOuterWidth = window.screen.width;
      if(isEmpty(windowOuterWidth) || (!eNumero(windowOuterWidth)))
      {      
        windowOuterWidth = width;
      }
    }
    innerILeft = Math.round((windowOuterWidth / 2) - (width / 2));
  }

  var OpenWindow = redirect;
  var params = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=' + width + ',height=' + height + ',top='+innerITop+',left='+innerILeft
  popup = window.open(OpenWindow, "Popup", params);
}

function changeImageSRC(imageObj, src)
{
  if((imageObj != null) && (imageObj != undefined) && (!isEmpty(src)))  
  {
    imageObj.src = src;
  }
}

function isValidEmailAddress(indirizzo) 
{
  if(isEmpty(indirizzo))
  {
    return false;
  }
  else
  {
    indirizzo = myDecodeURIComponent(indirizzo);
    var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
    var regnv = new RegExp(nonvalido);
    var regv = new RegExp(valido);
    if (!regnv.test(indirizzo) && regv.test(indirizzo))
    {
      return true;
    }
    else
    {
      return false;
    }
  }
}

function isValidItalianTaxNumber(cf) 
{
  if(isEmpty(cf))
  {
    return false;
  }
  else
  {
    cf = myDecodeURIComponent(cf);
    var valido = "";
    var regv = null;

    if (cf.length == 16) // codice fiscale
    {
      regv = new RegExp(/[A-Za-z]{6}\d{2}[A-Za-z]\d{2}[A-Za-z]\d{3}[A-Za-z]$/);
    }
    else if (cf.length == 11)// partita iva
    {
      regv = new RegExp(/\d{11}/);
    }
    else
    {
      return false;
    }
    if (regv.test(cf))
    {
      return true;
    }
    else
    {
      return false;
    }
  }
}

function getDataToString(formDati, prefissocampodata)
{
  valore = "";  
  elementi = formDati.elements;
  if(elementi && (elementi.length > 0))
  {
    dateseparator = "-";
    timeseparator = ":";
    elemento = elementi.namedItem(prefissocampodata + "$day");
    if(elemento && elemento.value)
    {
      if(elemento.value.length == 1)
      {
        elemento.value = ("0" + elemento.value)
      }
      valore += elemento.value;
      elemento = elementi.namedItem(prefissocampodata + "$month");
      if(elemento && elemento.value)
      {
        if(elemento.value.length == 1)
        {
          elemento.value = ("0" + elemento.value)
        }
        valore += (dateseparator + elemento.value);
        elemento = elementi.namedItem(prefissocampodata + "$year");
        if(elemento && elemento.value)
        {
          valore += (dateseparator + elemento.value);
          elemento = elementi.namedItem(prefissocampodata + "$hour");
          if(elemento && elemento.value)
          {
            if(elemento.value.length == 1)
            {              
              valore += (" 0" + elemento.value);
            }
            else
            {
              valore += (" " + elemento.value);
            }
            elemento = elementi.namedItem(prefissocampodata + "$minute");
            if(elemento && elemento.value)
            {
              if(elemento.value.length == 1)
              {              
                valore += (timeseparator + "0" + elemento.value);
              }
              else
              {
                valore += (timeseparator + elemento.value);
              }
              elemento = elementi.namedItem(prefissocampodata + "$second");
              timeseparator = ".";
              if(elemento && elemento.value)
              {                
                if(elemento.value.length == 1)
                {
                  valore += (timeseparator + "0" + elemento.value);
                }
                else
                {
                  valore += (timeseparator + elemento.value);
                }
                elemento = elementi.namedItem(prefissocampodata + "$millisecond");
                timeseparator = ",";
                if(elemento && elemento.value)
                {   
                  if(elemento.value.length == 1)
                  {
                    valore += (timeseparator + "00" + elemento.value);
                  }
                  else if(elemento.value.length == 2)
                  {
                    valore += (timeseparator + "0" + elemento.value);
                  }
                  else
                  {
                    valore += (timeseparator + elemento.value);
                  }                  
                }
                else
                {
                  valore += (timeseparator + "000");
                }
              }
              else
              {
                valore += (timeseparator + "00");
              }  
            }
            else
            {
              valore += (timeseparator + "00");
            }
          }
          else
          {
            valore += "";
          }
        }
        else
        {
          valore = "";
        }
      }
      else
      {
        valore = "";
      }
    }
    else
    {
      valore = "";
    }
  }
  return valore;
}

function getValidDate(dd, mm, yyyy, hh, mi, ss, ms)
{
  var date = null;
  try
  {
    if(isEmpty(hh))
    {
      hh = "0";
    }
    if(isEmpty(mi))
    {
      mi = "0";
    }
    if(isEmpty(ss))
    {
      ss = "0";
    }
    if(isEmpty(ms))
    {
      ms = "0";
    }
    if(
      eNumero(dd) && eNumero(mm) && eNumero(yyyy) && 
      eNumero(hh) && eNumero(mi) && eNumero(ss) && eNumero(ms)
    )
    {
      if(isValidDate(dd, mm, yyyy))
      {
        date = new Date(parseInt(rendiNumero(yyyy)), (parseInt(rendiNumero(mm)) - 1), parseInt(rendiNumero(dd)), parseInt(rendiNumero(hh)), parseInt(rendiNumero(mi)), parseInt(rendiNumero(ss)), parseInt(rendiNumero(ms)));
      }
    }
  }
  catch(exception)
  {    
    date = null;
  }
  return date;
}

function addDaysToDate(dateObj, adding)
{
  returning = dateObj;
  addingvalue = 0;
  if(eNumero(adding))
  {
    addingvalue = adding * 24 * 60 * 60 * 1000;         
  }
  if(addingvalue > 0)
  {
    returning = new Date();
    returning.setTime(dateObj.getTime() + addingvalue);
  }
  return returning;
}

function inizioMese(dateObj)
{
  returning = new Date(dateObj.getTime());
  returning.setDate(1);
  return returning;
}

function fineMese(dateObj)
{
  returning = inizioMese(dateObj);
  returning.setDate(giorniMese(returning.getMonth() + 1, returning.getFullYear()));
  return returning;
}

function inizioGiornata(dateObj)
{
  returning = new Date(dateObj.getTime());
  returning.setHours(0);
  returning.setMinutes(0);
  returning.setSeconds(0);
  returning.setMilliseconds(0);
  return returning;
}

function fineGiornata(dateObj)
{
  returning = new Date(dateObj.getTime());
  returning.setHours(23);
  returning.setMinutes(59);
  returning.setSeconds(59);
  returning.setMilliseconds(999);
  return returning;
}

function giorniMese(mese, anno)
{
  giorni = 31;
  if(meseBisestile(mese, anno))
  {
    giorni = 29;
  }
  else if((mese == 9) || (mese == 4) || (mese == 6) || (mese == 11))
  {    
    giorni = 30
  }
  return giorni;
}

function giorniAnno(anno)
{
  giorni = 365;
  if(meseBisestile(2, anno))
  {
    giorni = 366;
  }  
  return giorni;
}

function meseBisestile(mese, anno)
{
  bisestile = false;
  if((mese == 2) && ((((anno % 4) == 0) && ((anno % 100) != 0)) ||  ((anno % 400) == 0)))
  {
    bisestile = true;
  }
  return bisestile;
}

function isValidDate(dd, mm, yyyy)
{
  valid = eNumero(dd);  
  valid = valid && eNumero(mm);
  valid = valid && eNumero(yyyy);
  if(valid)
  {
    day = parseInt(rendiNumero(dd));
    month = parseInt(rendiNumero(mm)) - 1;
    year = parseInt(rendiNumero(yyyy));
    valid = valid && (day >= 1) && (day <= 31);
    valid = valid && (month >= 0) && (month <= 11);
    valid = valid && (year > 1900);  
    if(valid)
    {
      var date = new Date(year, month, day, 0, 0, 1);
      valid = valid && (date.getDate() == day);
      valid = valid && (date.getMonth() == month);
      valid = valid && (date.getFullYear() == year);  
    }
  }
  return valid;
}

function tokenizeString(value, separator, returnseparator)
{
  tokens = new Array();
  if(!isEmpty(value))
  {
    i = 0;
    if(!isEmpty(separator))
    {
      idxStart = 0;
      idxEnd = value.indexOf(separator);
      token = "";
      while((idxStart >= 0) && (idxEnd >= 0) && (idxStart < value.length) && (idxEnd < value.length))
      {        
        tokens[i++] = Trim(value.substring(idxStart, idxEnd));
        if(returnseparator)
        {
          tokens[i++] = separator;
        }
        idxStart = idxEnd + 1;
        idxEnd = value.indexOf(separator, idxStart);
      }
      if((idxEnd < idxStart) && (idxStart < value.length))
      {
        tokens[i++] = Trim(value.substring(idxStart));        
      }
    }
    else
    {
      tokens[i++] = value;
    }
  }
  return tokens;
}

function setOpenerTextObjectFireEventAndCloseWindow(windowObj, close, openerFormName, openerFieldName, value, event)
{
  if((!isEmpty(close)) && (!isEmpty(openerFormName)) && (!isEmpty(openerFieldName)) && (!isEmpty(value)))
  {    
    obj = eval("opener.document." + openerFormName + "." + openerFieldName);        
    if((obj != null) && (obj != undefined))
    {            
      obj.value = unescape(value);      
      if(!isEmpty(event))
      {
        fireElementEvent(obj, event);               
      }      
      if(close)
      {   
        windowObj.close();
      }       
    }
  }
}

function fireElementEvent(element, eventname)
{
  //alert("fireElementEvent");
  //alert("fireElementEvent::element = " + element);
  //alert("fireElementEvent::eventname = " + eventname);
  if((element != null) && (element != undefined))
  {            
    //alert("fireElementEvent::element.fireEvent = " + element.fireEvent);
    if(element.fireEvent)
    {
      element.fireEvent(eventname);
    }
    else
    {
      e = document.createEvent('HTMLEvents');
      //alert("fireElementEvent::e = " + e);
      if(eventname.indexOf("on") == 0)
      {
        eventname = eventname.substring(2);
      }
      //alert("fireElementEvent::eventname = " + eventname);
      e.initEvent(eventname, false, false);
      element.dispatchEvent(e);
    }
  }
  //alert("fireElementEvent ENDS");
}

function isLocalResource(resource)
{  
  isRemote = true;
  if(!isEmpty(resource))  
  {
    var regexp = new RegExp(); 
    regexp.compile("^(http|https)://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
    isRemote =  regexp.test(resource);
  }
  return !isRemote;
}

function getRemoteResource(resource)
{
  resourceExtracted = "";
  if(!isEmpty(resource))  
  {
    idxStart = resource.indexOf("://");
    if(idxStart > 0)
    {
      idxStart += 3;
      if(idxStart < resource.length)
      {
        idxEnd = resource.indexOf("/", idxStart);
        if(idxEnd > idxStart)  
        {
          resourceExtracted = resource.substring(idxStart, idxEnd);
        }
        else
        {
          resourceExtracted = resource.substring(idxStart);
        }
      }
    }
  }
  return resourceExtracted;
}

