
  function ValidaForm (form, formElAryDsc, formElAryCod){
    for (i=0; i<formElAryCod.length; i++){
      for (j=0;j<formElAryCod.length; j++){
        if (form.elements[i].value.length==0){
          if (form.elements[i].name==formElAryCod[j]){
            alert("O campo '"+formElAryDsc[j]+"' não deverá estar vazio.");
            form.elements[i].focus();
            return false;
            break;
          }
        }  
      }
    }
    return true
  }
 

  function validaUmCampoForm(form, formElAryDsc, formElAryCod){
    formCampos="";
    for (i=0; i<formElAryCod.length; i++){
      if (i>0) formCampos+=", ";
      formCampos+=formElAryDsc[i];  
      if (form.elements[i].value.length>0){
        return true;
        break;
      }
    }
    alert("Um dos campos '"+formCampos+"' deverá estar preenchido.");    
    return false;
  }


  function validaFormNumber(objecto){
    var numeroStr=objecto.value;
    for (i=0; i<numeroStr.length; i++){
      numero=false;
      for (j=0; j<10; j++){
        if (numeroStr.charAt(i)==j) numero=true;
      }
      if (!numero){
        alert("Número inválido");
        objecto.value="";
        objecto.focus();
        return false;
      }
    }
  }


  function validaFormDecimal(objecto){
    var numVFDStr=objecto.value;
    var decDotCnt=0;
    for (i=0; i<numVFDStr.length; i++){
      numVFD=false;
      for (j=0; j<10; j++){
        if (numVFDStr.charAt(i)==j) numVFD=true;
      }
      if (numVFDStr.charAt(i)==".") decDotCnt++;
      if (decDotCnt>0 && decDotCnt<2) numVFD=true;
      if (!numVFD){
        alert("Número inválido - deverá ter o seguinte formato : 1234.56");
        objecto.value="";
        objecto.focus();
        return false;
      }
    }
  }

  var tim=0;
  var _menuDiv;
  var _tdTable;
  var _id;
  var _newBgColor;
  var _newFontColor;
  var _tdId;  
  
  function changeBgColor(newBgColor, newFontColor, tdId){
    _newBgColor=newBgColor;
    _newFontColor=newFontColor;
    _tdId=tdId;
    eval(tdId).bgColor=newBgColor;
    eval(tdId+"f").style.color=newFontColor;
  }
  
  function showHideSubMenu(showHide, menuDiv, tdTable, id){
    clearTimeout(tim);
    _menuDiv=menuDiv;
    _tdTable=tdTable;
    _id=id;
    if (showHide=="show") {
      menuDiv.style.visibility="visible";
      //menuDiv.style.top=table_01.offsetTop+table_03.offsetTop+table_02.offsetHeight+tdTable.offsetTop;
      menuDiv.style.top=tdTable.offsetTop+210;
      menuDiv.style.left=table_01.offsetLeft+110;
      idMenu=id;
      actualizaSubMenu();
    }else{
      tim=setTimeout("hideSubMenu()",500);
    }
  }  

  function hideSubMenu(){
    _menuDiv.style.visibility="hidden";
  }
  
  function showHideMenu02(showHide){
    clearTimeout(tim);
    if (showHide=="show"){
      _menuDiv.style.visibility="visible";
      changeBgColor('', '#9191EB', _tdId);
    }else{
      changeBgColor('', '#00017F', _tdId);
      tim=setTimeout("hideSubMenu()",500);
    }  
  }  

  function actualizaSubMenu(){
    var divMenu="<table id='table_n2_02' width='150' align='left' border='0' cellspacing='0' cellpadding='0'>";
    subMenuTemp=eval("subMenuAry"+idMenu);
    for (i=0; i<subMenuTemp.length; i++){
      idMenuVal=i+1;
      if (idMenuVal<10) idMenuVal="0"+idMenuVal;
      divMenu+="<tr><td id='td_01' colspan='4' height='1' background='images/dot_blue.gif'></td></tr>";
      (subMenuTemp[i].split("|")[2]=="1") ? 
        aHref="<a href=\""+subMenuTemp[i].split("|")[3]+"&id="+subMenuTemp[i].split("|")[1]+"\" target=\"_blank\" onMouseOver=showHideMenu02(\"show\"); onMouseOut=showHideMenu02(\"hide\"); class='menu_02'>" :
        aHref="<a href=\""+subMenuTemp[i].split("|")[3]+"&id="+subMenuTemp[i].split("|")[1]+"\" onMouseOver=showHideMenu02(\"show\"); onMouseOut=showHideMenu02(\"hide\"); class='menu_02'>";
      divMenu+="<tr>";
      divMenu+="<td width='1' background='images/dot_blue.gif'></td>";
      divMenu+="<td width='5'onMouseOver=showHideMenu02(\"show\"); onMouseOut=showHideMenu02(\"hide\"); bgcolor='#fff1d7'>&nbsp;</td>";
      divMenu+="<td height='18'onMouseOver=showHideMenu02(\"show\"); onMouseOut=showHideMenu02(\"hide\"); width='150' bgcolor='#fff1d7'>"+aHref+""+subMenuTemp[i].split("|")[0].split(":")[0]+"</a></td>";
      divMenu+="<td width='1' background='images/dot_blue.gif'></td>";
      divMenu+="</tr>";
      divMenu+="<tr><td colspan='4' height='1' background='images/dot_blue.gif'></td></tr>";
      divMenu+="<tr><td height='2'><img src='images/transparent_dot.gif'></td></tr>";
    }
    divMenu+="</table>";
    document.getElementById("menu_nivel_02").innerHTML=divMenu;
  }
  
  function novaJanela(theUrl, winName, features){
  window.open(theUrl, winName, features);
}
 
  function validaPesquisa(form){
  var pesqVal;
  if (form.pesquisa.value.length<4){
    alert("Inserir a pesquisa com mais de 3 caracteres.")
    form.pesquisa.focus();
    return false;
  }
  return true;
}

 function replaceSubstring(inputString, fromString, toString) {
 	 var temp = inputString.value;
 	 
 	 alert(inputString);
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function


