
 <form name="form_ajax_redir_1" method="post" style="display: none">
  <input type="hidden" name="nmgp_parms">
  <input type="hidden" name="nmgp_outra_jan">
  <input type="hidden" name="script_case_session" value="<?php echo session_id() ?>">
 </form>
 <form name="form_ajax_redir_2" method="post" style="display: none">
  <input type="hidden" name="nmgp_parms">
  <input type="hidden" name="nmgp_url_saida">
  <input type="hidden" name="script_case_init">
  <input type="hidden" name="script_case_session" value="<?php echo session_id() ?>">
 </form>

 <SCRIPT>
<?php
sajax_show_javascript();
?>

  function scCenterElement(oElem)
  {
    var $oElem    = $(oElem),
        $oWindow  = $(this),
        iElemTop  = Math.round(($oWindow.height() - $oElem.height()) / 2),
        iElemLeft = Math.round(($oWindow.width()  - $oElem.width())  / 2);

    $oElem.offset({top: iElemTop, left: iElemLeft});
  } // scCenterElement

  function scAjaxHideAutocomp(sFrameId)
  {
    if (document.getElementById("id_ac_frame_" + sFrameId))
    {
      document.getElementById("id_ac_frame_" + sFrameId).style.display = "none";
    }
  } // scAjaxHideAutocomp

  function scAjaxShowAutocomp(sFrameId)
  {
    if (document.getElementById("id_ac_frame_" + sFrameId))
    {
      document.getElementById("id_ac_frame_" + sFrameId).style.display = "";
      document.getElementById("id_ac_" + sFrameId).focus();
    }
  } // scAjaxShowAutocomp

  function scAjaxHideDebug()
  {
    if (document.getElementById("id_debug_window"))
    {
      document.getElementById("id_debug_window").style.display = "none";
      document.getElementById("id_debug_text").innerHTML = "";
    }
  } // scAjaxHideDebug

  function scAjaxShowDebug(oTemp)
  {
    if (!document.getElementById("id_debug_window"))
    {
      return;
    }
    if (oTemp && oTemp != null)
    {
        oResp = oTemp;
    }
    if (oResp["htmOutput"] && "" != oResp["htmOutput"])
    {
      document.getElementById("id_debug_window").style.display = "";
      document.getElementById("id_debug_text").innerHTML = scAjaxFormatDebug(oResp["htmOutput"]) + document.getElementById("id_debug_text").innerHTML;
      scCenterElement(document.getElementById("id_debug_window"));
    }
  } // scAjaxShowDebug

  function scAjaxFormatDebug(sDebugMsg)
  {
    return "<table class=\"scFormMessageTable\" style=\"margin: 1px; width: 100%\"><tr><td class=\"scFormMessageMessage\">" + scAjaxSpecCharParser(sDebugMsg) + "</td></tr></table>";
  } // scAjaxFormatDebug

  function scAjaxHideErrorDisplay(sErrorId, bForce)
  {
    if (document.getElementById("id_error_display_" + sErrorId + "_frame"))
    {
      document.getElementById("id_error_display_" + sErrorId + "_frame").style.display = "none";
      document.getElementById("id_error_display_" + sErrorId + "_text").innerHTML = "";
      if (null == bForce)
      {
          bForce = true;
      }
      if (bForce)
      {
          var $oField = $('#id_sc_field_' + sErrorId);
          if (0 < $oField.length)
          {
              $oField.removeClass(sc_css_status);
          }
      }
    }
    if (document.getElementById("id_error_display_fixed"))
    {
      document.getElementById("id_error_display_fixed").style.display = "none";
    }
  } // scAjaxHideErrorDisplay

  function scAjaxShowErrorDisplay(sErrorId, sErrorMsg)
  {
    if (oResp && oResp['redirExitInfo'])
    {
      sErrorMsg += "<br /><input type=\"button\" onClick=\"window.location='" + oResp['redirExitInfo']['action'] + "'\" value=\"Ok\">";
    }
    sErrorMsg = scAjaxErrorSql(sErrorMsg);
    if (document.getElementById("id_error_display_" + sErrorId + "_frame"))
    {
      document.getElementById("id_error_display_" + sErrorId + "_frame").style.display = "";
      document.getElementById("id_error_display_" + sErrorId + "_text").innerHTML = sErrorMsg;
      if ("table" == sErrorId)
      {
        scCenterElement(document.getElementById("id_error_display_" + sErrorId + "_frame"));
      }
      var $oField = $('#id_sc_field_' + sErrorId);
      if (0 < $oField.length)
      {
        $oField.addClass(sc_css_status);
      }
    }
    if (ajax_error_list && ajax_error_list[sErrorId] && ajax_error_list[sErrorId]["timeout"] && 0 < ajax_error_list[sErrorId]["timeout"])
    {
      setTimeout("scAjaxHideErrorDisplay('" + sErrorId + "', false)", ajax_error_list[sErrorId]["timeout"] * 1000);
    }
    /*else if ("table" == sErrorId)
    {
      document.getElementById("id_error_display_" + sErrorId + "_frame").style.left = posDispLeft + "px";
      document.getElementById("id_error_display_" + sErrorId + "_frame").style.top = posDispTop + "px";
    }*/
  } // scAjaxShowErrorDisplay

  var iErrorSqlId = 1;

  function scAjaxErrorSql(sErrorMsg)
  {
    var iTmpPos = sErrorMsg.indexOf("{SC_DB_ERROR_INI}"),
        sTmpId;
    while (-1 < iTmpPos)
    {
      sTmpId    = "sc_id_error_sql_" + iErrorSqlId;
      sErrorMsg = sErrorMsg.substr(0, iTmpPos) + "<br /><span style=\"text-decoration: underline\" onClick=\"$('#" + sTmpId + "').show(); scCenterElement(document.getElementById('" + sTmpId + "'))\">" + sErrorMsg.substr(iTmpPos + 17);
      iTmpPos   = sErrorMsg.indexOf("{SC_DB_ERROR_MID}");
      sErrorMsg = sErrorMsg.substr(0, iTmpPos) + "</span><table class=\"scFormErrorTable\" id=\"" + sTmpId + "\" style=\"display: none; position: absolute\"><tr><td>" + sErrorMsg.substr(iTmpPos + 17);
      iTmpPos   = sErrorMsg.indexOf("{SC_DB_ERROR_CLS}");
      sErrorMsg = sErrorMsg.substr(0, iTmpPos) + "<br /><br /><span onClick=\"$('#" + sTmpId + "').hide()\">" + sErrorMsg.substr(iTmpPos + 17);
      iTmpPos   = sErrorMsg.indexOf("{SC_DB_ERROR_END}");
      sErrorMsg = sErrorMsg.substr(0, iTmpPos) + "</span></td></tr></table>" + sErrorMsg.substr(iTmpPos + 17);
      iTmpPos   = sErrorMsg.indexOf("{SC_DB_ERROR_INI}");
      iErrorSqlId++;
    }
    return sErrorMsg;
  } // scAjaxErrorSql

  function scAjaxHideMessage()
  {
    if (document.getElementById("id_message_display_frame"))
    {
      document.getElementById("id_message_display_frame").style.display = "none";
      document.getElementById("id_message_display_text").innerHTML = "";
    }
  } // scAjaxHideMessage

  function scAjaxShowMessage()
  {
    if (!oResp["msgDisplay"] || !oResp["msgDisplay"]["msgText"])
    {
      return;
    }
    _scAjaxShowMessage(scMsgDefTitle, oResp["msgDisplay"]["msgText"], false, sc_ajaxMsgTime, false, "Ok", 0, 0, 0, 0, "", "", "", false, true);
  } // scAjaxShowMessage

  var scMsgDefClose = "";

  function _scAjaxShowMessage(sTitle, sMessage, bModal, iTimeout, bButton, sButton, iTop, iLeft, iWidth, iHeight, sRedir, sTarget, sParam, bClose, bBodyIcon) {
    if ("" == sMessage) {
      if (bModal) {
        scMsgDefClick = "close_modal";
      }
      else {
        scMsgDefClick = "close";
      }
      _scAjaxMessageBtnClick();
      document.getElementById("id_message_display_title").innerHTML = scMsgDefTitle;
      document.getElementById("id_message_display_text").innerHTML = "";
      document.getElementById("id_message_display_buttone").value = scMsgDefButton;
      document.getElementById("id_message_display_buttond").style.display = "none";
    }
    else {
      document.getElementById("id_message_display_title").innerHTML = scAjaxSpecCharParser(sTitle);
      document.getElementById("id_message_display_text").innerHTML = scAjaxSpecCharParser(sMessage);
      document.getElementById("id_message_display_buttone").value = sButton;
      document.getElementById("id_message_display_buttond").style.display = bButton ? "" : "none";
      document.getElementById("id_message_display_buttond").style.display = bButton ? "" : "none";
      document.getElementById("id_message_display_title_line").style.display = (bClose || "" != sTitle) ? "" : "none";
      document.getElementById("id_message_display_close_icon").style.display = bClose ? "" : "none";
      if (document.getElementById("id_message_display_body_icon")) {
        document.getElementById("id_message_display_body_icon").style.display = bBodyIcon ? "" : "none";
      }
      $("#id_message_display_content").css('width', (0 < iWidth ? iWidth + 'px' : ''));
      $("#id_message_display_content").css('height', (0 < iHeight ? iHeight + 'px' : ''));
      if (bModal) {
        iWidth = iWidth || 250;
        iHeight = iHeight || 200;
        scMsgDefClose = "close_modal";
        tb_show('', '#TB_inline?height=' + (iHeight + 6) + '&width=' + (iWidth + 4) + '&inlineId=id_message_display_frame&modal=true', '');
        if (bButton) {
          if ("" != sRedir && "" != sTarget) {
            scMsgDefClick = "redir2_modal";
            document.form_ajax_redir_2.action = sRedir;
            document.form_ajax_redir_2.target = sTarget;
            document.form_ajax_redir_2.nmgp_parms.value = sParam;
            document.form_ajax_redir_2.script_case_init.value = scMsgDefScInit;
          }
          else if ("" != sRedir && "" == sTarget) {
            scMsgDefClick = "redir1";
            document.form_ajax_redir_1.action = sRedir;
            document.form_ajax_redir_1.nmgp_parms.value = sParam;
          }
          else {
            scMsgDefClick = "close_modal";
          }
        }
        else if (null != iTimeout && 0 < iTimeout) {
          scMsgDefClick = "close_modal";
          setTimeout("_scAjaxMessageBtnClick()", iTimeout * 1000);
        }
      }
      else
      {
        scMsgDefClose = "close";
        $("#id_message_display_frame").css('top', (0 < iTop ? iTop + 'px' : ''));
        $("#id_message_display_frame").css('left', (0 < iLeft ? iLeft + 'px' : ''));
        document.getElementById("id_message_display_frame").style.display = "";
        if (0 == iTop && 0 == iLeft) {
          scCenterElement(document.getElementById("id_message_display_frame"));
        }
        if (bButton) {
          if ("" != sRedir && "" != sTarget) {
            scMsgDefClick = "redir2";
            document.form_ajax_redir_2.action = sRedir;
            document.form_ajax_redir_2.target = sTarget;
            document.form_ajax_redir_2.nmgp_parms.value = sParam;
            document.form_ajax_redir_2.script_case_init.value = scMsgDefScInit;
          }
          else if ("" != sRedir && "" == sTarget) {
            scMsgDefClick = "redir1";
            document.form_ajax_redir_1.action = sRedir;
            document.form_ajax_redir_1.nmgp_parms.value = sParam;
          }
          else {
            scMsgDefClick = "close";
          }
        }
        else if (null != iTimeout && 0 < iTimeout) {
          scMsgDefClick = "close";
          setTimeout("_scAjaxMessageBtnClick()", iTimeout * 1000);
        }
      }
    }
  } // _scAjaxShowMessage

  function _scAjaxMessageBtnClose() {
    switch (scMsgDefClose) {
      case "close":
        document.getElementById("id_message_display_frame").style.display = "none";
        break;
      case "close_modal":
        tb_remove();
        break;
    }
  } // _scAjaxMessageBtnClick

  function _scAjaxMessageBtnClick() {
    switch (scMsgDefClick) {
      case "close":
        document.getElementById("id_message_display_frame").style.display = "none";
        break;
      case "close_modal":
        tb_remove();
        break;
      case "redir1":
        document.form_ajax_redir_1.submit();
        break;
      case "redir2":
        document.form_ajax_redir_2.submit();
        document.getElementById("id_message_display_frame").style.display = "none";
        break;
      case "redir2_modal":
        document.form_ajax_redir_2.submit();
        tb_remove();
        break;
    }
  } // _scAjaxMessageBtnClick

  function scAjaxHasError()
  {
    if (!oResp["result"])
    {
      return false;
    }
    return "ERROR" == oResp["result"];
  } // scAjaxHasError

  function scAjaxIsOk()
  {
    if (!oResp["result"])
    {
      return false;
    }
    return "OK" == oResp["result"] || "SET" == oResp["result"];
  } // scAjaxIsOk

  function scAjaxIsSet()
  {
    if (!oResp["result"])
    {
      return false;
    }
    return "SET" == oResp["result"];
  } // scAjaxIsSet

  function scAjaxCalendarReload()
  {
    if (oResp["calendarReload"] && "OK" == oResp["calendarReload"])
    {
      self.parent.calendar_reload();
      self.parent.tb_remove();
    }
  } // scCalendarReload

  function scAjaxUpdateErrors(sType)
  {
    ajax_error_geral = "";
    oFieldErrors     = {};
    if (oResp["errList"])
    {
      for (iFieldErrors = 0; iFieldErrors < oResp["errList"].length; iFieldErrors++)
      {
        sTestField = oResp["errList"][iFieldErrors]["fldName"];
        if ("geral_billing_item_edit_grid" == sTestField)
        {
          if (ajax_error_geral != '') { ajax_error_geral += '<br>';}
          ajax_error_geral += scAjaxSpecCharParser(oResp["errList"][iFieldErrors]["msgText"]);
        }
        else
        {
          if (scFocusFirstErrorField && '' == scFocusFirstErrorName)
          {
            scFocusFirstErrorName = sTestField;
          }
          if (oResp["errList"][iFieldErrors]["numLinha"])
          {
            sTestField += oResp["errList"][iFieldErrors]["numLinha"];
          }
          if (!oFieldErrors[sTestField])
          {
            oFieldErrors[sTestField] = new Array();
          }
          oFieldErrors[sTestField][oFieldErrors[sTestField].length] = scAjaxSpecCharParser(oResp["errList"][iFieldErrors]["msgText"]);
        }
      }
    }
    for (iUpdateErrors = 0; iUpdateErrors < ajax_field_list.length; iUpdateErrors++)
    {
      sTestField = ajax_field_list[iUpdateErrors];
      if (oFieldErrors[sTestField])
      {
        ajax_error_list[sTestField][sType] = oFieldErrors[sTestField];
      }
    }
  } // scAjaxUpdateErrors

  function scAjaxUpdateFieldErrors(sField, sType)
  {
    aFieldErrors = new Array();
    if (oResp["errList"])
    {
      iErrorPos  = 0;
      for (iFieldErrors = 0; iFieldErrors < oResp["errList"].length; iFieldErrors++)
      {
        sTestField = oResp["errList"][iFieldErrors]["fldName"];
        if (oResp["errList"][iFieldErrors]["numLinha"])
        {
          sTestField += oResp["errList"][iFieldErrors]["numLinha"];
        }
        if (sField == sTestField)
        {
          aFieldErrors[iErrorPos] = scAjaxSpecCharParser(oResp["errList"][iFieldErrors]["msgText"]);
          iErrorPos++;
        }
      }
    }
    ajax_error_list[sField][sType] = aFieldErrors;
  } // scAjaxUpdateFieldErrors

  function scAjaxListErrors(bLabel)
  {
    bFirst        = false;
    sAppErrorText = "";
    if ("" != ajax_error_geral)
    {
      bFirst         = true;
      sAppErrorText += ajax_error_geral;
    }
    for (iFieldList = 0; iFieldList < ajax_field_list.length; iFieldList++)
    {
      sFieldError = scAjaxListFieldErrors(ajax_field_list[iFieldList], bLabel);
      if ("" != sFieldError)
      {
        if (bFirst)
        {
          bFirst         = false
          sAppErrorText += "<hr size=\"1\" width=\"80%\" />";
        }
        sAppErrorText += sFieldError;
      }
    }
    return sAppErrorText;
  } // scAjaxListErrors

  function scAjaxListFieldErrors(sField, bLabel)
  {
    sErrorText = "";
    for (iErrorType = 0; iErrorType < ajax_error_type.length; iErrorType++)
    {
      if (ajax_error_list[sField])
      {
        for (iListErrors = 0; iListErrors < ajax_error_list[sField][ajax_error_type[iErrorType]].length; iListErrors++)
        {
          if (bLabel)
          {
            sErrorText += ajax_error_list[sField]["label"] + ": ";
          }
          sErrorText += ajax_error_list[sField][ajax_error_type[iErrorType]][iListErrors] + "<br />";
        }
      }
    }
    return sErrorText;
  } // scAjaxListFieldErrors

  function scAjaxSetFields()
  {
    if (!oResp["fldList"])
    {
      return true;
    }
    for (iSetFields = 0; iSetFields < oResp["fldList"].length; iSetFields++)
    {
      var sFieldName = oResp["fldList"][iSetFields]["fldName"];
      var sFieldType = oResp["fldList"][iSetFields]["fldType"];
      if ("selectdd" == sFieldType)
      {
        var bSelectDD = true;
        sFieldType = "select";
      }
      else
      {
        var bSelectDD = false;
      }
      if (oResp["fldList"][iSetFields]["valList"])
      {
        var oFieldValues = oResp["fldList"][iSetFields]["valList"];
        if (0 == oFieldValues.length)
        {
          oFieldValues = null;
        }
      }
      else
      {
        var oFieldValues = null;
      }
      if (oResp["fldList"][iSetFields]["optList"])
      {
        var oFieldOptions = oResp["fldList"][iSetFields]["optList"];
      }
      else
      {
        var oFieldOptions = null;
      }
/*
      if ("_autocomp" == sFieldName.substr(sFieldName.length - 9) &&
          iSetFields > 0 &&
          sFieldName.substr(0, sFieldName.length - 9) == oResp["fldList"][iSetFields - 1]["fldName"] &&
          document.getElementById("div_ac_lab_" + sFieldName.substr(0, sFieldName.length - 9)) &&
          oFieldValues[0]['value'])
      {
          document.getElementById("div_ac_lab_" + sFieldName.substr(0, sFieldName.length - 9)).innerHTML = oFieldValues[0]['value'];
      }
*/
      if ("_autocomp" == sFieldName.substr(sFieldName.length - 9) &&
          iSetFields > 0 &&
          sFieldName.substr(0, sFieldName.length - 9) == oResp["fldList"][iSetFields - 1]["fldName"] &&
          document.getElementById("div_ac_lab_" + sFieldName.substr(0, sFieldName.length - 9)))
      {
          sLabel_auto_Comp = (oFieldValues[0]['value']) ? oFieldValues[0]['value'] : "";
          document.getElementById("div_ac_lab_" + sFieldName.substr(0, sFieldName.length - 9)).innerHTML = sLabel_auto_Comp;
      }


      if (oResp["fldList"][iSetFields]["colNum"])
      {
        var iColNum = oResp["fldList"][iSetFields]["colNum"];
      }
      else
      {
        var iColNum = 1;
      }
      if (oResp["fldList"][iSetFields]["row"])
      {
        var iRow = oResp["fldList"][iSetFields]["row"];
      }
      else
      {
        var iRow = 1;
      }
      if (oResp["fldList"][iSetFields]["htmComp"])
      {
        var sHtmComp = oResp["fldList"][iSetFields]["htmComp"];
        sHtmComp     = sHtmComp.replace(/__AD__/gi, '"');
        sHtmComp     = sHtmComp.replace(/__AS__/gi, "'");
      }
      else
      {
        var sHtmComp = null;
      }
      if (oResp["fldList"][iSetFields]["imgFile"])
      {
        var sImgFile = oResp["fldList"][iSetFields]["imgFile"];
      }
      else
      {
        var sImgFile = "";
      }
      if (oResp["fldList"][iSetFields]["imgOrig"])
      {
        var sImgOrig = oResp["fldList"][iSetFields]["imgOrig"];
      }
      else
      {
        var sImgOrig = "";
      }
      if (oResp["fldList"][iSetFields]["keepImg"])
      {
        var sKeepImg = oResp["fldList"][iSetFields]["keepImg"];
      }
      else
      {
        var sKeepImg = "N";
      }
      if (oResp["fldList"][iSetFields]["imgLink"])
      {
        var sImgLink = oResp["fldList"][iSetFields]["imgLink"];
      }
      else
      {
        var sImgLink = null;
      }
      if (oResp["fldList"][iSetFields]["docLink"])
      {
        var sDocLink = oResp["fldList"][iSetFields]["docLink"];
      }
      else
      {
        var sDocLink = "";
      }
      if (oResp["fldList"][iSetFields]["docIcon"])
      {
        var sDocIcon = oResp["fldList"][iSetFields]["docIcon"];
      }
      else
      {
        var sDocIcon = "";
      }
      if (oResp["fldList"][iSetFields]["optComp"])
      {
        var sOptComp = oResp["fldList"][iSetFields]["optComp"];
      }
      else
      {
        var sOptComp = "";
      }
      if (oResp["fldList"][iSetFields]["optClass"])
      {
        var sOptClass = oResp["fldList"][iSetFields]["optClass"];
      }
      else
      {
        var sOptClass = "";
      }
      if (oResp["fldList"][iSetFields]["optMulti"])
      {
        var sOptMulti = oResp["fldList"][iSetFields]["optMulti"];
      }
      else
      {
        var sOptMulti = "";
      }
      if (oResp["fldList"][iSetFields]["imgHtml"])
      {
        var sImgHtml = oResp["fldList"][iSetFields]["imgHtml"];
      }
      else
      {
        var sImgHtml = "";
      }
      if (oResp["fldList"][iSetFields]["mulHtml"])
      {
        var sMULHtml = oResp["fldList"][iSetFields]["mulHtml"];
      }
      else
      {
        var sMULHtml = "";
      }
      if (oResp["fldList"][iSetFields]["updInnerHtml"])
      {
        var sInnerHtml = scAjaxSpecCharParser(oResp["fldList"][iSetFields]["updInnerHtml"]);
      }
      else
      {
        var sInnerHtml = null;
      }
      if (oResp["fldList"][iSetFields]["lookupCons"])
      {
        var sLookupCons = scAjaxSpecCharParser(oResp["fldList"][iSetFields]["lookupCons"]);
      }
      else
      {
        var sLookupCons = "";
      }
      if (oResp["clearUpload"])
      {
        var sClearUpload = scAjaxSpecCharParser(oResp["clearUpload"]);
      }
      else
      {
        var sClearUpload = "N";
      }
      if ("checkbox" == sFieldType)
      {
        scAjaxSetFieldCheckbox(sFieldName, oFieldValues, oFieldOptions, iColNum, sHtmComp, sInnerHtml, sOptComp, sOptClass, sOptMulti);
      }
      else if ("duplosel" == sFieldType)
      {
        scAjaxSetFieldDuplosel(sFieldName, oFieldValues, oFieldOptions);
      }
      else if ("imagem" == sFieldType)
      {
        scAjaxSetFieldImage(sFieldName, oFieldValues, sImgFile, sImgOrig, sImgLink, sKeepImg);
      }
      else if ("documento" == sFieldType)
      {
        scAjaxSetFieldDocument(sFieldName, oFieldValues, sDocLink, sDocIcon, sClearUpload);
      }
      else if ("label" == sFieldType)
      {
        scAjaxSetFieldLabel(sFieldName, oFieldValues, oFieldOptions, sLookupCons);
      }
      else if ("radio" == sFieldType)
      {
        scAjaxSetFieldRadio(sFieldName, oFieldValues, oFieldOptions, iColNum, sHtmComp, sOptComp);
      }
      else if ("select" == sFieldType)
      {
        scAjaxSetFieldSelect(sFieldName, oFieldValues, oFieldOptions, bSelectDD, iRow);
      }
      else if ("text" == sFieldType)
      {
        scAjaxSetFieldText(sFieldName, oFieldValues, sLookupCons);
      }
      else if ("editor_html" == sFieldType)
      {
        scAjaxSetFieldEditorHtml(sFieldName, oFieldValues);
      }
      else if ("imagehtml" == sFieldType)
      {
        scAjaxSetFieldImageHtml(sFieldName, oFieldValues, sImgHtml);
      }
      else if ("innerhtml" == sFieldType)
      {
        scAjaxSetFieldInnerHtml(sFieldName, oFieldValues);
      }
      else if ("multi_upload" == sFieldType)
      {
        scAjaxSetFieldMultiUpload(sFieldName, sMULHtml);
      }
      scAjaxUpdateHeaderFooter(sFieldName, oFieldValues);
    }
  } // scAjaxSetFields

  function scAjaxUpdateHeaderFooter(sFieldName, oFieldValues)
  {
    if (self.updateHeaderFooter)
    {
      if (null == oFieldValues)
      {
        sNewValue = '';
      }
      else if (oFieldValues[0]["label"])
      {
        sNewValue = oFieldValues[0]["label"];
      }
      else
      {
        sNewValue = oFieldValues[0]["value"];
      }
      updateHeaderFooter(sFieldName, scAjaxSpecCharParser(sNewValue));
    }
  } // scAjaxUpdateHeaderFooter

  function scAjaxSetFieldText(sFieldName, oFieldValues, sLookupCons)
  {
    if (document.F1.elements[sFieldName])
    {
//      document.F1.elements[sFieldName].value = scAjaxSpecCharParser(oFieldValues[0]['value']);
        Temp_text = scAjaxProtectBreakLine(oFieldValues[0]['value']);
        Temp_text = scAjaxSpecCharParser(Temp_text);
        document.F1.elements[sFieldName].value = scAjaxReturnBreakLine(Temp_text);
    }
    if (document.getElementById("id_lookup_" + sFieldName))
    {
      document.getElementById("id_lookup_" + sFieldName).innerHTML = sLookupCons;
    }
    if (oFieldValues[0]['label'])
    {
      scAjaxSetReadonlyArrayValue(sFieldName, oFieldValues);
    }
    else
    {
      oFieldValues[0]['value'] = scAjaxBreakLine(oFieldValues[0]['value']);
      scAjaxSetReadonlyValue(sFieldName, scAjaxSpecCharParser(oFieldValues[0]['value']));
    }
  } // scAjaxSetFieldText

  function scAjaxSetFieldSelect(sFieldName, oFieldValues, oFieldOptions, bSelectDD, iRow)
  {
    sFieldNameHtml = sFieldName;
    if (!document.F1.elements[sFieldName] && !document.F1.elements[sFieldName + "[]"])
    {
      return;
    }
    if (bSelectDD)
    {
        $("#id_sc_field_" + sFieldName).dropdownchecklist("destroy");
    }
    if (!document.F1.elements[sFieldName] && document.F1.elements[sFieldName + "[]"])
    {
      sFieldNameHtml += "[]";
    }
    if ("hidden" == document.F1.elements[sFieldNameHtml].type)
    {
      scAjaxSetFieldText(sFieldNameHtml, oFieldValues);
      return;
    }
    if (null != oFieldOptions)
    {
      if ("<select" != oFieldOptions.substr(0, 7))
      {
        var $oField = $("#id_sc_field_" + sFieldName);
        if (0 < $oField.length)
        {
          $oField.html(oFieldOptions);
        }
        else
        {
          document.getElementById("idAjaxSelect_" + sFieldName).innerHTML = oFieldOptions;
        }
      }
      else
      {
        document.getElementById("idAjaxSelect_" + sFieldName).innerHTML = oFieldOptions;
      }
    }
    var aValues = new Array();
    if (null != oFieldValues)
    {
      for (iFieldSelect = 0; iFieldSelect < oFieldValues.length; iFieldSelect++)
      {
        aValues[iFieldSelect] = scAjaxSpecCharParser(oFieldValues[iFieldSelect]["value"]);
      }
    }
    var oFormField = document.F1.elements[sFieldNameHtml];
    for (iFieldSelect = 0; iFieldSelect < oFormField.length; iFieldSelect++)
    {
      if (scAjaxInArray(oFormField.options[iFieldSelect].value, aValues))
      {
        oFormField.options[iFieldSelect].selected = true;
      }
      else
      {
        oFormField.options[iFieldSelect].selected = false;
      }
    }
    scAjaxSetReadonlyArrayValue(sFieldName, oFieldValues, "<br />");
    if (bSelectDD)
    {
        scJQDDCheckBoxAdd(iRow);
    }
  } // scAjaxSetFieldSelect

  function scAjaxSetFieldDuplosel(sFieldName, oFieldValues, oFieldOptions)
  {
    var sFieldNameOrig = sFieldName + "_orig";
    var sFieldNameDest = sFieldName + "_dest";
    var oFormFieldOrig = document.F1.elements[sFieldNameOrig];
    var oFormFieldDest = document.F1.elements[sFieldNameDest];
    if (null != oFieldOptions)
    {
      scAjaxClearSelect(sFieldNameOrig);
      for (iFieldSelect = 0; iFieldSelect < oFieldOptions.length; iFieldSelect++)
      {
        oFormFieldOrig.options[iFieldSelect] = new Option(scAjaxSpecCharParser(oFieldOptions[iFieldSelect]["label"]), scAjaxSpecCharParser(oFieldOptions[iFieldSelect]["value"]));
      }
    }
    while (oFormFieldDest.length > 0)
    {
      oFormFieldDest.options[0] = null;
    }
    var aValues = new Array();
    if (null != oFieldValues)
    {
      for (iFieldSelect = 0; iFieldSelect < oFieldValues.length; iFieldSelect++)
      {
        sNewOptionLabel = oFieldValues[iFieldSelect]["label"] ? scAjaxSpecCharParser(oFieldValues[iFieldSelect]["label"]) : scAjaxSpecCharParser(oFieldValues[iFieldSelect]["value"]);
        sNewOptionValue = scAjaxSpecCharParser(oFieldValues[iFieldSelect]["value"]);
        if (sNewOptionValue.substr(0, 8) == "@NMorder")
        {
           sNewOptionValue                      = sNewOptionValue.substr(8);
           oFormFieldDest.options[iFieldSelect] = new Option(scAjaxSpecCharParser(sNewOptionLabel), sNewOptionValue);
           sNewOptionValue                      = sNewOptionValue.substr(1);
           aValues[iFieldSelect]                = sNewOptionValue;
        }
        else
        {
           aValues[iFieldSelect]                = sNewOptionValue;
           oFormFieldDest.options[iFieldSelect] = new Option(scAjaxSpecCharParser(sNewOptionLabel), sNewOptionValue);
        }
      }
    }
    for (iFieldSelect = 0; iFieldSelect < oFormFieldOrig.length; iFieldSelect++)
    {
      oFormFieldOrig.options[iFieldSelect].selected = false;
      if (scAjaxInArray(oFormFieldOrig.options[iFieldSelect].value, aValues))
      {
        oFormFieldOrig.options[iFieldSelect].disabled    = true;
        oFormFieldOrig.options[iFieldSelect].style.color = "#A0A0A0";
      }
      else
      {
        oFormFieldOrig.options[iFieldSelect].disabled = false;
      }
    }
    scAjaxSetReadonlyArrayValue(sFieldName, oFieldValues, "<br />");
  } // scAjaxSetFieldDuplosel

  function scAjaxSetFieldCheckbox(sFieldName, oFieldValues, oFieldOptions, iColNum, sHtmComp, sInnerHtml, sOptComp, sOptClass, sOptMulti)
  {
    if (document.getElementById("idAjaxCheckbox_" + sFieldName) && null != sInnerHtml)
    {
      document.getElementById("idAjaxCheckbox_" + sFieldName).innerHTML = sInnerHtml;
      return;
    }
    if (document.F1.elements[sFieldName] && "hidden" == document.F1.elements[sFieldName].type)
    {
      scAjaxSetFieldText(sFieldName, oFieldValues);
      return;
    }
    if (null != oFieldOptions && "" != oFieldOptions)
    {
      scAjaxClearCheckbox(sFieldName);
      scAjaxRecreateOptions("Checkbox", "checkbox", sFieldName, oFieldValues, oFieldOptions, iColNum, sHtmComp, sOptComp, sOptClass, sOptMulti);
    }
    else
    {
      scAjaxSetCheckboxOptions(sFieldName, oFieldValues);
    }
    scAjaxSetReadonlyArrayValue(sFieldName, oFieldValues, "<br />");
  } // scAjaxSetFieldCheckbox

  function scAjaxSetFieldRadio(sFieldName, oFieldValues, oFieldOptions, iColNum, sHtmComp, sOptComp)
  {
    if (document.F1.elements[sFieldName] && "hidden" == document.F1.elements[sFieldName].type)
    {
      scAjaxSetFieldText(sFieldName, oFieldValues);
      return;
    }
    if (null != oFieldOptions && "" != oFieldOptions)
    {
      scAjaxClearRadio(sFieldName);
      scAjaxRecreateOptions("Radio", "radio", sFieldName, oFieldValues, oFieldOptions, iColNum, sHtmComp, sOptComp, "", "");
    }
    else
    {
      scAjaxSetRadioOptions(sFieldName, oFieldValues);
    }
    scAjaxSetReadonlyArrayValue(sFieldName, oFieldValues, "<br />");
  } // scAjaxSetFieldRadio

  function scAjaxSetFieldLabel(sFieldName, oFieldValues, oFieldOptions, sLookupCons)
  {
    sFieldValue = oFieldValues[0]["value"];
    sFieldLabel = oFieldValues[0]["value"];
    sFieldLabel = scAjaxBreakLine(sFieldLabel);
    if (null != oFieldOptions)
    {
      for (iRecreate = 0; iRecreate < oFieldOptions.length; iRecreate++)
      {
        sOptText  = scAjaxSpecCharParser(oFieldOptions[iRecreate]["value"]);
        sOptValue = scAjaxSpecCharParser(oFieldOptions[iRecreate]["label"]);
        if (sFieldValue == sOptText)
        {
          sFieldLabel = sOptValue;
        }
      }
    }
    if (document.getElementById("id_ajax_label_" + sFieldName))
    {
      document.getElementById("id_ajax_label_" + sFieldName).innerHTML = scAjaxSpecCharParser(sFieldLabel);
    }
    if (document.F1.elements[sFieldName])
    {
//      document.F1.elements[sFieldName].value = scAjaxSpecCharParser(sFieldValue);
        Temp_text = scAjaxProtectBreakLine(sFieldValue);
        Temp_text = scAjaxSpecCharParser(Temp_text);
        document.F1.elements[sFieldName].value = scAjaxReturnBreakLine(Temp_text);

    }
    if (document.getElementById("id_lookup_" + sFieldName))
    {
      document.getElementById("id_lookup_" + sFieldName).innerHTML = sLookupCons;
    }
    scAjaxSetReadonlyValue(sFieldName, scAjaxSpecCharParser(sFieldLabel));
  } // scAjaxSetFieldLabel

  function scAjaxSetFieldImage(sFieldName, oFieldValues, sImgFile, sImgOrig, sImgLink, sKeepImg)
  {
    if (!document.F1.elements[sFieldName] && !document.F1.elements[sFieldName + "[]"])
    {
      return;
    }
    if ("N" == sKeepImg && document.getElementById("id_ajax_img_"  + sFieldName))
    {
      document.getElementById("id_ajax_img_"  + sFieldName).src           = scAjaxSpecCharParser(sImgFile);
      document.getElementById("id_ajax_img_"  + sFieldName).style.display = ("" == sImgFile) ? "none" : "";
    }
    if (document.getElementById("id_ajax_link_" + sFieldName) && null != sImgLink)
    {
      document.getElementById("id_ajax_link_" + sFieldName).innerHTML = oFieldValues[0]["value"];
      document.getElementById("id_ajax_link_" + sFieldName).href      = scAjaxSpecCharParser(sImgLink);
    }
    if (document.getElementById("chk_ajax_img_" + sFieldName))
    {
      document.getElementById("chk_ajax_img_" + sFieldName).style.display = ("" == oFieldValues[0]["value"]) ? "none" : "";
    }
    if ("" == oFieldValues[0]["value"] && document.F1.elements[sFieldName + "_limpa"])
    {
      document.F1.elements[sFieldName + "_limpa"].checked = false;
    }
    if ("N" == sKeepImg && document.getElementById("txt_ajax_img_" + sFieldName))
    {
      document.getElementById("txt_ajax_img_" + sFieldName).innerHTML     = oFieldValues[0]["value"];
      document.getElementById("txt_ajax_img_" + sFieldName).style.display = ("" == oFieldValues[0]["value"]) ? "none" : "";
    }
    if ("" != sImgOrig)
    {
      eval("if (var_ajax_img_" + sFieldName + ") var_ajax_img_" + sFieldName + " = '" + sImgOrig + "';");
      if (document.F1.elements["temp_out1_" + sFieldName])
      {
        document.F1.elements["temp_out_" + sFieldName].value = sImgFile;
        document.F1.elements["temp_out1_" + sFieldName].value = sImgOrig;
      }
      else if (document.F1.elements["temp_out_" + sFieldName])
      {
        document.F1.elements["temp_out_" + sFieldName].value = sImgOrig;
      }
    }
    if ("" != oFieldValues[0]["value"])
    {
      if (document.F1.elements[sFieldName + "_salva"]) document.F1.elements[sFieldName + "_salva"].value = oFieldValues[0]["value"];
    }
    else if (oResp && oResp["ajaxRequest"] && "navigate_form" == oResp["ajaxRequest"])
    {
      if (document.F1.elements[sFieldName + "_salva"]) document.F1.elements[sFieldName + "_salva"].value = "";
    }
    scAjaxSetReadonlyValue(sFieldName, scAjaxSpecCharParser(oFieldValues[0]["value"]));
  } // scAjaxSetFieldImage

  function scAjaxSetFieldDocument(sFieldName, oFieldValues, sDocLink, sDocIcon, sClearUpload)
  {
    if (!document.F1.elements[sFieldName] && !document.F1.elements[sFieldName + "[]"])
    {
      return;
    }
    document.getElementById("id_ajax_doc_"  + sFieldName).innerHTML = scAjaxSpecCharParser(sDocLink);
    if (document.getElementById("id_ajax_doc_icon_"  + sFieldName))
    {
      document.getElementById("id_ajax_doc_icon_"  + sFieldName).src = scAjaxSpecCharParser(sDocIcon);
    }
    if ("" == oFieldValues[0]["value"])
    {
      document.getElementById("chk_ajax_img_" + sFieldName).style.display = "none";
      document.getElementById("id_ajax_doc_" + sFieldName).style.display = "none";
    }
    else
    {
      document.getElementById("chk_ajax_img_" + sFieldName).style.display = "";
      document.getElementById("id_ajax_doc_" + sFieldName).style.display = "";
    }
    if ("" == oFieldValues[0]["value"] && document.F1.elements[sFieldName + "_limpa"])
    {
      document.F1.elements[sFieldName + "_limpa"].checked = false;
    }
    if ("S" == sClearUpload && document.F1.elements[sFieldName + "_ul_name"])
    {
      document.F1.elements[sFieldName + "_ul_name"].value = "";
    }
    scAjaxSetReadonlyValue(sFieldName, scAjaxSpecCharParser(oFieldValues[0]["value"]));
  } // scAjaxSetFieldDocument

  function scAjaxSetFieldInnerHtml(sFieldName, oFieldValues)
  {
    if (document.getElementById(sFieldName))
    {
      document.getElementById(sFieldName).innerHTML = scAjaxSpecCharParser(oFieldValues[0]["value"]);
    }
  } // scAjaxSetFieldInnerHtml

  function scAjaxSetFieldMultiUpload(sFieldName, sMULHtml)
  {
    if (!document.F1.elements[sFieldName] && !document.F1.elements[sFieldName + "[]"])
    {
      return;
    }
    $("#id_sc_loaded_" + sFieldName).html(scAjaxSpecCharParser(sMULHtml));
  } // scAjaxSetFieldMultiUpload

  function scAjaxSetFieldEditorHtml(sFieldName, oFieldValues)
  {
    if (!document.F1.elements[sFieldName])
    {
      return;
    }
    var oFormField = tinyMCE.getInstanceById(sFieldName);
    oFormField.setContent(scAjaxSpecCharParser(oFieldValues[0]["value"]));
    scAjaxSetReadonlyValue(sFieldName, scAjaxSpecCharParser(oFieldValues[0]["value"]));
  } // scAjaxSetFieldEditorHtml

  function scAjaxSetFieldImageHtml(sFieldName, oFieldValues, sImgHtml)
  {
    if (document.getElementById("id_imghtml_" + sFieldName))
    {
      document.getElementById("id_imghtml_" + sFieldName).innerHTML = scAjaxSpecCharParser(sImgHtml);
    }
  } // scAjaxSetFieldEditorHtml

  function scAjaxSetCheckboxOptions(sFieldName, oFieldValues)
  {
    if (!document.F1.elements[sFieldName] && !document.F1.elements[sFieldName + "[]"] && !document.F1.elements[sFieldName + "[0]"])
    {
      return;
    }
    var aValues    = new Array();
    if (null != oFieldValues)
    {
      for (iFieldSelect = 0; iFieldSelect < oFieldValues.length; iFieldSelect++)
      {
        aValues[iFieldSelect] = scAjaxSpecCharParser(oFieldValues[iFieldSelect]["value"]);
      }
    }
    if (document.F1.elements[sFieldName + "[]"])
    {
      var oFormField = document.F1.elements[sFieldName + "[]"];
      if (oFormField.length)
      {
        for (iFieldCheckbox = 0; iFieldCheckbox < oFormField.length; iFieldCheckbox++)
        {
          if (scAjaxInArray(oFormField[iFieldCheckbox].value, aValues))
          {
            oFormField[iFieldCheckbox].checked = true;
          }
          else
          {
            oFormField[iFieldCheckbox].checked = false;
          }
        }
      }
      else
      {
        if (scAjaxInArray(oFormField.value, aValues))
        {
          oFormField.checked = true;
        }
        else
        {
          oFormField.checked = false;
        }
      }
    }
    else if (document.F1.elements[sFieldName + "[0]"])
    {
      for (iFieldCheckbox = 0; iFieldCheckbox < document.F1.elements.length; iFieldCheckbox++)
      {
        oFormElement = document.F1.elements[iFieldCheckbox];
        if (sFieldName + "[" == oFormElement.name.substr(0, sFieldName.length + 1) && scAjaxInArray(oFormElement.value, aValues))
        {
          oFormElement.checked = true;
        }
        else if (sFieldName + "[" == oFormElement.name.substr(0, sFieldName.length + 1))
        {
          oFormElement.checked = false;
        }
      }
    }
    else
    {
      oFormElement = document.F1.elements[sFieldName];
      if (scAjaxInArray(oFormElement.value, aValues))
      {
        oFormElement.checked = true;
      }
      else
      {
        oFormElement.checked = false;
      }
    }
  } // scAjaxSetCheckboxOptions

  function scAjaxSetRadioOptions(sFieldName, oFieldValues)
  {
    if (!document.F1.elements[sFieldName])
    {
      return;
    }
    var oFormField = document.F1.elements[sFieldName];
    var aValues    = new Array();
    if (null != oFieldValues)
    {
      for (iFieldSelect = 0; iFieldSelect < oFieldValues.length; iFieldSelect++)
      {
        aValues[iFieldSelect] = scAjaxSpecCharParser(oFieldValues[iFieldSelect]["value"]);
      }
    }
    for (iFieldRadio = 0; iFieldRadio < oFormField.length; iFieldRadio++)
    {
      if (scAjaxInArray(oFormField[iFieldRadio].value, aValues))
      {
        oFormField[iFieldRadio].checked = true;
      }
    }
  } // scAjaxSetRadioOptions

  function scAjaxSetReadonlyValue(sFieldName, sFieldValue)
  {
    if (document.getElementById("id_read_on_" + sFieldName))
    {
      document.getElementById("id_read_on_" + sFieldName).innerHTML = sFieldValue;
    }
  } // scAjaxSetReadonlyValue

  function scAjaxSetReadonlyArrayValue(sFieldName, oFieldValues, sDelim)
  {
    if (null == oFieldValues)
    {
      return;
    }
    if (null == sDelim)
    {
      sDelim = " ";
    }
    sReadLabel = "";
    for (iReadArray = 0; iReadArray < oFieldValues.length; iReadArray++)
    {
      if (oFieldValues[iReadArray]["label"])
      {
        if ("" != sReadLabel)
        {
          sReadLabel += sDelim;
        }
        sReadLabel += oFieldValues[iReadArray]["label"];
      }
      else if (oFieldValues[iReadArray]["value"])
      {
        if ("" != sReadLabel)
        {
          sReadLabel += sDelim;
        }
        sReadLabel += oFieldValues[iReadArray]["value"];
      }
    }
    scAjaxSetReadonlyValue(sFieldName, scAjaxSpecCharParser(sReadLabel));
  } // scAjaxSetReadonlyArrayValue

  function scAjaxGetFieldValue(sFieldGet)
  {
    sValue = "";
    if (!oResp["fldList"])
    {
      return sValue;
    }
    for (iFieldValue = 0; iFieldValue < oResp["fldList"].length; iFieldValue++)
    {
      var sFieldName  = oResp["fldList"][iFieldValue]["fldName"];
      if (oResp["fldList"][iFieldValue]["valList"])
      {
        var oFieldValues = oResp["fldList"][iFieldValue]["valList"];
        if (0 == oFieldValues.length)
        {
          oFieldValues = null;
        }
      }
      else
      {
        var oFieldValues = null;
      }
      if (sFieldGet == sFieldName && null != oFieldValues)
      {
        if (1 == oFieldValues.length)
        {
          sValue = scAjaxSpecCharParser(oFieldValues[0]["value"]);
        }
        else
        {
          sValue = new Array();
          for (jFieldValue = 0; jFieldValue < oFieldValues.length; jFieldValue++)
          {
            sValue[jFieldValue] = scAjaxSpecCharParser(oFieldValues[jFieldValue]["value"]);
          }
        }
      }
    }
    return sValue;
  } // scAjaxGetFieldValue

  function scAjaxGetKeyValue(sFieldGet)
  {
    sValue = "";
    if (!oResp["fldList"])
    {
      return sValue;
    }
    for (iKeyValue = 0; iKeyValue < oResp["fldList"].length; iKeyValue++)
    {
      var sFieldName = oResp["fldList"][iKeyValue]["fldName"];
      if (sFieldGet == sFieldName)
      {
        if (oResp["fldList"][iKeyValue]["keyVal"])
        {
          return scAjaxSpecCharParser(oResp["fldList"][iKeyValue]["keyVal"]);
        }
        else
        {
          return scAjaxGetFieldValue(sFieldGet);
        }
      }
    }
    return sValue;
  } // scAjaxGetKeyValue

  function scAjaxGetLineNumber()
  {
    sLineNumber = "";
    if (oResp["errList"])
    {
      for (iLineNumber = 0; iLineNumber < oResp["errList"].length; iLineNumber++)
      {
        if (oResp["errList"][iLineNumber]["numLinha"])
        {
          sLineNumber = oResp["errList"][iLineNumber]["numLinha"];
        }
      }
      return sLineNumber;
    }
    if (oResp["fldList"])
    {
      return oResp["fldList"][0]["numLinha"];
    }
    if (oResp["msgDisplay"])
    {
      return oResp["msgDisplay"]["numLinha"];
    }
    return sLineNumber;
  } // scAjaxGetLineNumber

  function scAjaxFieldExists(sFieldGet)
  {
    bExists = false;
    if (!oResp["fldList"])
    {
      return bExists;
    }
    for (iFieldValue = 0; iFieldValue < oResp["fldList"].length; iFieldValue++)
    {
      var sFieldName  = oResp["fldList"][iFieldValue]["fldName"];
      if (oResp["fldList"][iFieldValue]["valList"])
      {
        var oFieldValues = oResp["fldList"][iFieldValue]["valList"];
        if (0 == oFieldValues.length)
        {
          oFieldValues = null;
        }
      }
      else
      {
        var oFieldValues = null;
      }
      if (sFieldGet == sFieldName && null != oFieldValues)
      {
        bExists = true;
      }
    }
    return bExists;
  } // scAjaxFieldExists

  function scAjaxGetFieldText(sFieldName)
  {
    $oHidden = $("input[name=" + sFieldName + "]");
    if ($oHidden.length)
    {
      for (var i = 0; i < $oHidden.length; i++)
      {
        if ("hidden" == $oHidden[i].type && $oHidden[i].form && $oHidden[i].form.name && "F1" == $oHidden[i].form.name)
        {
          return $oHidden[i].value.replace(/[+]/g, "__NM_PLUS__");
        }
      }
    }
    $oField = $("#id_sc_field_" + sFieldName);
    if ($oField.length && "select" != $oField[0].type.substr(0, 6))
    {
      return $oField.val().replace(/[+]/g, "__NM_PLUS__");
    }
    else if (document.F1.elements[sFieldName])
    {
      return document.F1.elements[sFieldName].value.replace(/[+]/g, "__NM_PLUS__");
    }
    else
    {
      return '';
    }
  } // scAjaxGetFieldText

  function scAjaxGetFieldHidden(sFieldName)
  {
    for( i= 0; i < document.F1.elements.length; i++)
    {
       if (document.F1.elements[i].name == sFieldName)
       {
          return document.F1.elements[i].value.replace(/[+]/g, "__NM_PLUS__");
       }
    }
//    return document.F1.elements[sFieldName].value.replace(/[+]/g, "__NM_PLUS__");
  } // scAjaxGetFieldHidden

  function scAjaxGetFieldSelect(sFieldName)
  {
    sFieldNameHtml = sFieldName;
    if (!document.F1.elements[sFieldName] && !document.F1.elements[sFieldName + "[]"])
    {
      return "";
    }
    if (!document.F1.elements[sFieldName] && document.F1.elements[sFieldName + "[]"])
    {
      sFieldNameHtml += "[]";
    }
    if ("hidden" == document.F1.elements[sFieldNameHtml].type)
    {
      return scAjaxGetFieldHidden(sFieldNameHtml);
    }
    var oFormField = document.F1.elements[sFieldNameHtml];
    var iSelected  = oFormField.selectedIndex;
    if (-1 < iSelected)
    {
      return oFormField.options[iSelected].value.replace(/[+]/g, "__NM_PLUS__");
    }
    else
    {
      return "";
    }
  } // scAjaxGetFieldSelect

  function scAjaxGetFieldSelectMult(sFieldName, sFieldDelim)
  {
    sFieldNameHtml = sFieldName;
    if (!document.F1.elements[sFieldName] && document.F1.elements[sFieldName + "[]"])
    {
      sFieldNameHtml += "[]";
    }
    if ("hidden" == document.F1.elements[sFieldNameHtml].type)
    {
      return scAjaxGetFieldHidden(sFieldNameHtml);
    }
    var oFormField = document.F1.elements[sFieldNameHtml];
    var sFieldVals = "";
    for (iFieldSelect = 0; iFieldSelect < oFormField.length; iFieldSelect++)
    {
      if (oFormField[iFieldSelect].selected)
      {
        if ("" != sFieldVals)
        {
          sFieldVals += sFieldDelim;
        }
        sFieldVals += oFormField[iFieldSelect].value.replace(/[+]/g, "__NM_PLUS__");
      }
    }
    return sFieldVals;
  } // scAjaxGetFieldSelectMult

  function scAjaxGetFieldCheckbox(sFieldName, sDelim)
  {
    var aValues = new Array();
    var sValue  = "";
    if (!document.F1.elements[sFieldName] && !document.F1.elements[sFieldName + "[]"] && !document.F1.elements[sFieldName + "[0]"])
    {
      return sValue;
    }
    if (document.F1.elements[sFieldName + "[]"] && "hidden" == document.F1.elements[sFieldName + "[]"].type)
    {
      return scAjaxGetFieldHidden(sFieldName + "[]");
    }
    if (document.F1.elements[sFieldName] && "hidden" == document.F1.elements[sFieldName].type)
    {
      return scAjaxGetFieldHidden(sFieldName);
    }
    if (document.F1.elements[sFieldName + "[]"])
    {
      var oFormField = document.F1.elements[sFieldName + "[]"];
      if (oFormField.length)
      {
        for (iFieldCheck = 0; iFieldCheck < oFormField.length; iFieldCheck++)
        {
          if (oFormField[iFieldCheck].checked)
          {
            aValues[aValues.length] = oFormField[iFieldCheck].value;
          }
        }
      }
      else
      {
        if (oFormField.checked)
        {
          aValues[aValues.length] = oFormField.value;
        }
      }
    }
    else
    {
      for (iFieldCheck = 0; iFieldCheck < document.F1.elements.length; iFieldCheck++)
      {
        oFormElement = document.F1.elements[iFieldCheck];
        if (sFieldName + "[" == oFormElement.name.substr(0, sFieldName.length + 1) && oFormElement.checked)
        {
          aValues[aValues.length] = oFormElement.value;
        }
        else if (sFieldName == oFormElement.name && oFormElement.checked)
        {
          aValues[aValues.length] = oFormElement.value;
        }
      }
    }
    for (iFieldCheck = 0; iFieldCheck < aValues.length; iFieldCheck++)
    {
      sValue += aValues[iFieldCheck].replace(/[+]/g, "__NM_PLUS__");
      if (iFieldCheck + 1 != aValues.length)
      {
        sValue += sDelim;
      }
    }
    return sValue;
  } // scAjaxGetFieldCheckbox

  function scAjaxGetFieldRadio(sFieldName)
  {
    if ("hidden" == document.F1.elements[sFieldName].type)
    {
      return scAjaxGetFieldHidden(sFieldName);
    }
    var sValue = "";
    if (!document.F1.elements[sFieldName])
    {
      return sValue;
    }
    var oFormField = document.F1.elements[sFieldName];
    if (!oFormField.length)
    {
        var sc_cmp_radio = eval("document.F1." + sFieldName);
        if (sc_cmp_radio.checked)
        {
           sValue = sc_cmp_radio.value.replace(/[+]/g, "__NM_PLUS__");
        }
    }
    else
    {
      for (iFieldRadio = 0; iFieldRadio < oFormField.length; iFieldRadio++)
      {
        if (oFormField[iFieldRadio].checked)
        {
          sValue = oFormField[iFieldRadio].value.replace(/[+]/g, "__NM_PLUS__");
        }
      }
    }
    return sValue;
  } // scAjaxGetFieldRadio

  function scAjaxGetFieldEditorHtml(sFieldName)
  {
    if ("hidden" == document.F1.elements[sFieldName].type)
    {
      return scAjaxGetFieldHidden(sFieldName);
    }
    var sValue = "";
    if (!document.F1.elements[sFieldName])
    {
      return sValue;
    }
    var oFormField = tinyMCE.getInstanceById(sFieldName);
    return scAjaxSpecCharParser(oFormField.getContent().replace(/[+]/g, "__NM_PLUS__"));
  } // scAjaxGetFieldEditorHtml

  function scAjaxDoNothing(e)
  {
  } // scAjaxDoNothing

  function scAjaxInArray(mVal, aList)
  {
    for (iInArray = 0; iInArray < aList.length; iInArray++)
    {
      if (aList[iInArray] == mVal)
      {
        return true;
      }
    }
    return false;
  } // scAjaxInArray

  function scAjaxSpecCharParser(sParseString)
  {
    var ta = document.createElement("textarea");
    ta.innerHTML = sParseString.replace(/</g, "&lt;").replace(/>/g, "&gt;");
    return ta.value;
    var div = document.createElement('div');
    div.innerHTML = sParseString;
    return div.childNodes[0] ? div.childNodes[0].nodeValue : '';
  } // scAjaxSpecCharParser

  function scAjaxRecreateOptions(sFieldType, sHtmlType, sFieldName, oFieldValues, oFieldOptions, iColNum, sHtmComp, sOptComp, sOptClass, sOptMulti)
  {
    var sSuffix  = ("checkbox" == sHtmlType) ? "[]" : "";
    var sDivName = "idAjax" + sFieldType + "_" + sFieldName;
    var sDivText = "";
    var iCntLine = 0;
    var aValues  = new Array();
    var sClass;
    if (null != oFieldValues)
    {
      for (iRecreate = 0; iRecreate < oFieldValues.length; iRecreate++)
      {
        aValues[iRecreate] = scAjaxSpecCharParser(oFieldValues[iRecreate]["value"]);
      }
    }
    sDivText += "<table border=0>";
    for (iRecreate = 0; iRecreate < oFieldOptions.length; iRecreate++)
    {
        sOptText  = scAjaxSpecCharParser(oFieldOptions[iRecreate]["label"]);
        sOptValue = scAjaxSpecCharParser(oFieldOptions[iRecreate]["value"]);
        if (0 == iCntLine)
        {
            sDivText += "<tr>";
        }
        iCntLine++;
        if ("" != sOptClass)
        {
            sClass = " class=\"" + sOptClass;
            if ("" != sOptMulti)
            {
                sClass += " " + sOptClass + sOptMulti;
            }
            sClass += "\"";
        }
        if (sHtmComp == null)
        {
            sHtmComp = "";
        }
        sChecked  = (scAjaxInArray(sOptValue, aValues)) ? " checked" : "";
        sDivText += "<td class=\"scFormDataFontOdd\">";
        sDivText += "<input type=\"" + sHtmlType + "\" name=\"" + sFieldName + sSuffix + "\" value=\"" + sOptValue + "\"" + sChecked + " " + sHtmComp + " " + sOptComp + sClass + ">";
        sDivText += sOptText;
        sDivText += "</td>";
        if (iColNum == iCntLine)
        {
            sDivText += "</tr>";
            iCntLine  = 0;
        }
    }
    sDivText += "</table>";
    document.getElementById(sDivName).innerHTML = sDivText;
  } // scAjaxRecreateOptions

  function scAjaxProcOn(bForce)
  {
    if (null == bForce)
    {
      bForce = false;
    }
    if (document.getElementById("id_div_process"))
    {
      if ($ && $.blockUI && !bForce)
      {
        $.blockUI({
          message: $("#id_div_process_block"),
          overlayCSS: { backgroundColor: sc_ajaxBg },
          css: {
            borderColor: sc_ajaxBordC,
            borderStyle: sc_ajaxBordS,
            borderWidth: sc_ajaxBordW
          }
        });
      }
      else
      {
        document.getElementById("id_div_process").style.display = "";
        document.getElementById("id_fatal_error").style.display = "none";
      }
    }
  } // scAjaxProcOn

  function scAjaxProcOff(bForce)
  {
    if (null == bForce)
    {
      bForce = false;
    }
    if (document.getElementById("id_div_process"))
    {
      if ($ && $.unblockUI && !bForce)
      {
        $.unblockUI();
      }
      else
      {
        document.getElementById("id_div_process").style.display = "none";
      }
    }
  } // scAjaxProcOff

  function scAjaxSetMaster()
  {
    if (!oResp["masterValue"])
    {
      return;
    }
    if (!parent || !parent.scAjaxDetailValue)
    {
      return;
    }
    for (iMaster = 0; iMaster < oResp["masterValue"].length; iMaster++)
    {
      parent.scAjaxDetailValue(oResp["masterValue"][iMaster]["index"], oResp["masterValue"][iMaster]["value"]);
    }
  } // scAjaxSetMaster

  function scAjaxSetFocus()
  {
    if (!oResp["setFocus"] && '' == scFocusFirstErrorName)
    {
      return;
    }
    sFieldName = oResp["setFocus"];
    if (document.F1.elements[sFieldName])
    {
        scFocusField(sFieldName);
    }
    scAjaxFocusError();
  } // scAjaxSetFocus

  function scAjaxFocusError()
  {
    if ('' != scFocusFirstErrorName)
    {
      scFocusField(scFocusFirstErrorName);
      scFocusFirstErrorName = '';
    }
  } // scAjaxFocusError

  function scAjaxSetNavStatus(sBarPos)
  {
    if (!oResp["navStatus"])
    {
      return;
    }
    sNavRet = "S";
    sNavAva = "S";
    if (oResp["navStatus"]["ret"])
    {
      sNavRet = oResp["navStatus"]["ret"];
    }
    if (oResp["navStatus"]["ava"])
    {
      sNavAva = oResp["navStatus"]["ava"];
    }
    if ("S" != sNavRet && "N" != sNavRet)
    {
      sNavRet = "S";
    }
    if ("S" != sNavAva && "N" != sNavAva)
    {
      sNavAva = "S";
    }
    Nav_permite_ret = sNavRet;
    Nav_permite_ava = sNavAva;
    nav_atualiza(Nav_permite_ret, Nav_permite_ava, sBarPos);
  } // scAjaxSetNavStatus

  function scAjaxSetSummary()
  {
    if (!oResp["navSummary"])
    {
      return;
    }
    sreg_ini = oResp["navSummary"].reg_ini;
    sreg_qtd = oResp["navSummary"].reg_qtd;
    sreg_tot = oResp["navSummary"].reg_tot;
    summary_atualiza(sreg_ini, sreg_qtd, sreg_tot);
  } // scAjaxSetSummary

  function scAjaxSetNavpage()
  {
    navpage_atualiza(oResp["navPage"]);
  } // scAjaxSetNavpage


  function scAjaxRedir(oTemp)
  {
    if (oTemp && oTemp != null)
    {
        oResp = oTemp;
    }
    if (!oResp["redirInfo"])
    {
      return;
    }
    sMetodo = oResp["redirInfo"]["metodo"];
    sAction = oResp["redirInfo"]["action"];
    if ("location" == sMetodo)
    {
      if ("parent.parent" == oResp["redirInfo"]["target"])
      {
        parent.parent.location = sAction;
      }
      else if ("parent" == oResp["redirInfo"]["target"])
      {
        parent.location = sAction;
      }
      else if ("_blank" == oResp["redirInfo"]["target"])
      {
        window.open(sAction, "_blank");
      }
      else
      {
        document.location = sAction;
      }
    }
    else if ("html" == sMetodo)
    {
        document.write(scAjaxSpecCharParser(oResp["redirInfo"]["action"]));
    }
    else
    {
      if (oResp["redirInfo"]["target"] == "modal")
      {
          tb_show('', sAction + '?script_case_init=' +  oResp["redirInfo"]["script_case_init"] + '&script_case_session=<?php echo session_id() ?>&nmgp_parms=' + oResp["redirInfo"]["nmgp_parms"] + '&nmgp_outra_jan=true&nmgp_url_saida=modal&NMSC_modal=ok&TB_iframe=true&modal=true&height=' +  oResp["redirInfo"]["h_modal"] + '&width=' + oResp["redirInfo"]["w_modal"], '');
          return;
      }
      sFormRedir = (oResp["redirInfo"]["nmgp_outra_jan"]) ? "form_ajax_redir_1" : "form_ajax_redir_2";
      document.forms[sFormRedir].action           = sAction;
      document.forms[sFormRedir].target           = oResp["redirInfo"]["target"];
      document.forms[sFormRedir].nmgp_parms.value = oResp["redirInfo"]["nmgp_parms"];
      if ("form_ajax_redir_1" == sFormRedir)
      {
        document.forms[sFormRedir].nmgp_outra_jan.value = oResp["redirInfo"]["nmgp_outra_jan"];
      }
      else
      {
        document.forms[sFormRedir].nmgp_url_saida.value   = oResp["redirInfo"]["nmgp_url_saida"];
        document.forms[sFormRedir].script_case_init.value = oResp["redirInfo"]["script_case_init"];
      }
      document.forms[sFormRedir].submit();
    }
  } // scAjaxRedir

  function scAjaxSetDisplay(bReset)
  {
    if (null == bReset)
    {
      bReset = false;
    }
    var aDispData = new Array();
    var aDispCont = {};
    if (bReset)
    {
      for (iDisplay = 0; iDisplay < ajax_block_list.length; iDisplay++)
      {
        aDispCont[ajax_block_list[iDisplay]] = aDispData.length;
        aDispData[aDispData.length] = new Array(ajax_block_id[ajax_block_list[iDisplay]], "on");
      }
      for (iDisplay = 0; iDisplay < ajax_field_list.length; iDisplay++)
      {
        if (ajax_field_id[ajax_field_list[iDisplay]])
        {
          aFieldIds = ajax_field_id[ajax_field_list[iDisplay]];
          for (iDisplay2 = 0; iDisplay2 < aFieldIds.length; iDisplay2++)
          {
            aDispCont[aFieldIds[iDisplay2]] = aDispData.length;
            aDispData[aDispData.length] = new Array(aFieldIds[iDisplay2], "on");
          }
        }
      }
    }
    if (oResp["blockDisplay"])
    {
      for (iDisplay = 0; iDisplay < oResp["blockDisplay"].length; iDisplay++)
      {
        if (bReset)
        {
          aDispData[ aDispCont[ oResp["blockDisplay"][iDisplay][0] ] ][1] = oResp["blockDisplay"][iDisplay][1];
        }
        else
        {
          aDispData[aDispData.length] = new Array(ajax_block_id[ oResp["blockDisplay"][iDisplay][0] ], oResp["blockDisplay"][iDisplay][1]);
        }
      }
    }
    if (oResp["fieldDisplay"])
    {
      for (iDisplay = 0; iDisplay < oResp["fieldDisplay"].length; iDisplay++)
      {
        for (iDisplay2 = 1; iDisplay2 < ajax_field_mult[ oResp["fieldDisplay"][iDisplay][0] ].length; iDisplay2++)
        {
          aFieldIds = ajax_field_id[ ajax_field_mult[ oResp["fieldDisplay"][iDisplay][0] ][iDisplay2] ];
          for (iDisplay3 = 0; iDisplay3 < aFieldIds.length; iDisplay3++)
          {
            if (bReset)
            {
              aDispData[ aDispCont[ aFieldIds[iDisplay3] ] ][1] = oResp["fieldDisplay"][iDisplay][1];
            }
            else
            {
              aDispData[aDispData.length] = new Array(aFieldIds[iDisplay3], oResp["fieldDisplay"][iDisplay][1]);
            }
          }
        }
      }
    }
    if (oResp["buttonDisplay"])
    {
      for (iDisplay = 0; iDisplay < oResp["buttonDisplay"].length; iDisplay++)
      {
        var sBtnName2 = "";
        switch (oResp["buttonDisplay"][iDisplay][0])
        {
          case "first": var sBtnName = "sc_b_ini"; break;
          case "back": var sBtnName = "sc_b_ret"; break;
          case "forward": var sBtnName = "sc_b_avc"; break;
          case "last": var sBtnName = "sc_b_fim"; break;
          case "insert": var sBtnName = "sc_b_ins"; break;
          case "update": var sBtnName = "sc_b_upd"; break;
          case "delete": var sBtnName = "sc_b_del"; break;
          default: var sBtnName = "sc_b_" + oResp["buttonDisplay"][iDisplay][0]; sBtnName2 = "sc_" + oResp["buttonDisplay"][iDisplay][0]; break;
        }
        aDispData[aDispData.length] = new Array(sBtnName, oResp["buttonDisplay"][iDisplay][1]);
        aDispData[aDispData.length] = new Array(sBtnName + "_t", oResp["buttonDisplay"][iDisplay][1]);
        aDispData[aDispData.length] = new Array(sBtnName + "_b", oResp["buttonDisplay"][iDisplay][1]);
        if ("" != sBtnName2)
        {
          aDispData[aDispData.length] = new Array(sBtnName2, oResp["buttonDisplay"][iDisplay][1]);
          aDispData[aDispData.length] = new Array(sBtnName2 + "_top", oResp["buttonDisplay"][iDisplay][1]);
          aDispData[aDispData.length] = new Array(sBtnName2 + "_bot", oResp["buttonDisplay"][iDisplay][1]);
        }
      }
    }
    for (iDisplay = 0; iDisplay < aDispData.length; iDisplay++)
    {
      scAjaxElementDisplay(aDispData[iDisplay][0], aDispData[iDisplay][1]);
    }
  } // scAjaxSetDisplay

  function scAjaxElementDisplay(sElement, sAction)
  {
    sStyle = ("off" == sAction) ? "none" : "";
    if (ajax_block_tab && ajax_block_tab[sElement] && "" != ajax_block_tab[sElement])
    {
      scAjaxElementDisplay(ajax_block_tab[sElement], sAction);
    }
    if (document.getElementById(sElement))
    {
      document.getElementById(sElement).style.display = sStyle;
      if (document.getElementById(sElement + "_dumb"))
      {
        document.getElementById(sElement + "_dumb").style.display = ("off" == sAction) ? "" : "none";
      }
    }
  } // scAjaxElementDisplay

  function scAjaxSetLabel(bReset)
  {
    if (null == bReset)
    {
      bReset = false;
    }
    if (bReset)
    {
      for (iLabel = 0; iLabel < ajax_field_list.length; iLabel++)
      {
        if (ajax_field_list[iLabel] && ajax_error_list[ajax_field_list[iLabel]])
        {
          scAjaxFieldLabel(ajax_field_list[iLabel], ajax_error_list[ajax_field_list[iLabel]]["label"]);
        }
      }
    }
    if (oResp["fieldLabel"])
    {
      for (iLabel = 0; iLabel < oResp["fieldLabel"].length; iLabel++)
      {
        scAjaxFieldLabel(oResp["fieldLabel"][iLabel][0], scAjaxSpecCharParser(oResp["fieldLabel"][iLabel][1]));
      }
    }
  } // scAjaxSetLabel

  function scAjaxFieldLabel(sField, sLabel)
  {
    if (document.getElementById("id_label_" + sField) && document.getElementById("id_label_" + sField).innerHTML != sLabel)
    {
      document.getElementById("id_label_" + sField).innerHTML = sLabel;
    }
  } // scAjaxFieldLabel

  function scAjaxSetReadonly(bReset)
  {
    if (null == bReset)
    {
      bReset = false;
    }
    if (bReset)
    {
      for (iRead = 0; iRead < ajax_field_list.length; iRead++)
      {
        scAjaxFieldRead(ajax_field_list[iRead], ajax_read_only[ajax_field_list[iRead]]);
      }
      for (iRead = 0; iRead < ajax_field_Dt_Hr.length; iRead++)
      {
        scAjaxFieldRead(ajax_field_Dt_Hr[iRead], ajax_read_only[ajax_field_Dt_Hr[iRead]]);
      }
    }
    if (oResp["readOnly"])
    {
      for (iRead = 0; iRead < oResp["readOnly"].length; iRead++)
      {
        if (ajax_read_only[ oResp["readOnly"][iRead][0] ])
        {
          scAjaxFieldRead(oResp["readOnly"][iRead][0], oResp["readOnly"][iRead][1]);
        }
        else if (oResp["rsSize"])
        {
          for (var i = 0; i <= oResp["rsSize"]; i++)
          {
            if (ajax_read_only[ oResp["readOnly"][iRead][0] + i ])
            {
              scAjaxFieldRead(oResp["readOnly"][iRead][0] + i, oResp["readOnly"][iRead][1]);
            }
          }
        }
      }
    }
  } // scAjaxSetReadonly

  function scAjaxFieldRead(sField, sStatus)
  {
    if ("on" == sStatus)
    {
      var sDisplayOff = "none";
      var sDisplayOn  = "";
    }
    else
    {
      var sDisplayOff = "";
      var sDisplayOn  = "none";
    }
    if (document.getElementById("id_read_off_" + sField))
    {
      document.getElementById("id_read_off_" + sField).style.display = sDisplayOff;
    }
    if (document.getElementById("id_read_on_" + sField))
    {
      document.getElementById("id_read_on_" + sField).style.display = sDisplayOn;
    }
  } // scAjaxFieldRead

  function scAjaxSetBtnVars()
  {
    if (oResp["btnVars"])
    {
      for (iBtn = 0; iBtn < oResp["btnVars"].length; iBtn++)
      {
        eval(oResp["btnVars"][iBtn][0] + " = '" + oResp["btnVars"][iBtn][1] + "';");
      }
    }
  } // scAjaxSetBtnVars

  function scAjaxClearText(sFormField)
  {
    document.F1.elements[sFormField].value = "";
  } // scAjaxClearText

  function scAjaxClearLabel(sFormField)
  {
    document.getElementById("id_ajax_label_" + sFormField).innerHTML = "";
  } // scAjaxClearLabel

  function scAjaxClearSelect(sFormField)
  {
    document.F1.elements[sFormField].length = 0;
  } // scAjaxClearSelect

  function scAjaxClearCheckbox(sFormField)
  {
    document.getElementById("idAjaxCheckbox_" + sFormField).innerHTML = "";
  } // scAjaxClearCheckbox

  function scAjaxClearRadio(sFormField)
  {
    document.getElementById("idAjaxRadio_" + sFormField).innerHTML = "";
  } // scAjaxClearRadio

  function scAjaxClearEditorHtml(sFormField)
  {
    var oFormField = tinyMCE.getInstanceById(sFormField);
    oFormField.setContent("");
  } // scAjaxClearEditorHtml

  function scAjaxJavascript()
  {
    if (oResp["ajaxJavascript"])
    {
      var sJsFunc = "";
      for (var i = 0; i < oResp["ajaxJavascript"].length; i++)
      {
        sJsFunc = scAjaxSpecCharParser(oResp["ajaxJavascript"][i][0]);
        if ("" != sJsFunc)
        {
          var aParam = new Array();
          if (oResp["ajaxJavascript"][i][1] && 0 < oResp["ajaxJavascript"][i][1].length)
          {
            for (var j = 0; j < oResp["ajaxJavascript"][i][1].length; j++)
            {
              aParam.push("'" + oResp["ajaxJavascript"][i][1][j] + "'");
            }
          }
          eval("if (" + sJsFunc + ") { " + sJsFunc + "(" + aParam.join(", ") + ") }");
        }
      }
    }
  } // scAjaxJavascript

  function scAjaxAlert()
  {
    if (oResp["ajaxAlert"] && oResp["ajaxAlert"]["message"] && "" != oResp["ajaxAlert"]["message"])
    {
      alert(oResp["ajaxAlert"]["message"]);
    }
  } // scAjaxAlert

  function scAjaxMessage(oTemp)
  {
    if (oTemp && oTemp != null)
    {
        oResp = oTemp;
    }
    if (oResp["ajaxMessage"] && oResp["ajaxMessage"]["message"] && "" != oResp["ajaxMessage"]["message"])
    {
      var sTitle    = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["title"])        ? oResp["ajaxMessage"]["title"]               : scMsgDefTitle,
          bModal    = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["modal"])        ? ("Y" == oResp["ajaxMessage"]["modal"])      : false,
          iTimeout  = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["timeout"])      ? parseInt(oResp["ajaxMessage"]["timeout"])   : 0,
          bButton   = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["button"])       ? ("Y" == oResp["ajaxMessage"]["button"])     : false,
          sButton   = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["button_label"]) ? oResp["ajaxMessage"]["button_label"]        : "Ok",
          iTop      = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["top"])          ? parseInt(oResp["ajaxMessage"]["top"])       : 0,
          iLeft     = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["left"])         ? parseInt(oResp["ajaxMessage"]["left"])      : 0,
          iWidth    = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["width"])        ? parseInt(oResp["ajaxMessage"]["width"])     : 0,
          iHeight   = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["height"])       ? parseInt(oResp["ajaxMessage"]["height"])    : 0,
          bClose    = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["show_close"])   ? ("Y" == oResp["ajaxMessage"]["show_close"]) : true,
          bBodyIcon = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["body_icon"])    ? ("Y" == oResp["ajaxMessage"]["body_icon"])  : true,
          sRedir    = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["redir"])        ? oResp["ajaxMessage"]["redir"]               : "",
          sTarget   = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["redir_target"]) ? oResp["ajaxMessage"]["redir_target"]        : "",
          sParam    = (oResp["ajaxMessage"] && oResp["ajaxMessage"]["redir_par"])    ? oResp["ajaxMessage"]["redir_par"]           : "";
      _scAjaxShowMessage(sTitle, oResp["ajaxMessage"]["message"], bModal, iTimeout, bButton, sButton, iTop, iLeft, iWidth, iHeight, sRedir, sTarget, sParam, bClose, bBodyIcon);
    }
  } // scAjaxAlert

  function scAjaxResponse(sResp)
  {
    eval("var oResp = " + sResp);
    return oResp;
  } // scAjaxResponse

  function scAjaxBreakLine(input)
  {
      if (null == input)
      {
          return "";
      }
      input += "";
      while (input.lastIndexOf(String.fromCharCode(10)) > -1)
      {
         input = input.replace(String.fromCharCode(10), '<br>');
      }
      return input;
  } // scAjaxBreakLine

  function scAjaxProtectBreakLine(input)
  {
      if (null == input)
      {
          return "";
      }
      var input1 = input + "";
      while (input1.lastIndexOf(String.fromCharCode(10)) > -1)
      {
         input1 = input1.replace(String.fromCharCode(10), '#@NM#@');
      }
      return input1;
  } // scAjaxProtectBreakLine

  function scAjaxReturnBreakLine(input)
  {
      if (null == input)
      {
          return "";
      }
      while (input.lastIndexOf('#@NM#@') > -1)
      {
         input = input.replace('#@NM#@', String.fromCharCode(10));
      }
      return input;
  } // scAjaxReturnBreakLine


  // ---------- Validate invoice_
  function do_ajax_billing_item_edit_grid_validate_invoice_(iNumLinha)
  {
    var nomeCampo_invoice_ = "invoice_" + iNumLinha;
    var var_invoice_ = scAjaxGetFieldText(nomeCampo_invoice_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_invoice_(var_invoice_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_invoice__cb);
  } // do_ajax_billing_item_edit_grid_validate_invoice_

  function do_ajax_billing_item_edit_grid_validate_invoice__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "invoice_" + iLineNumber;
    }
    else
    {
      sFieldValid = "invoice_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "invoice_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "invoice_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_invoice__cb

  // ---------- Validate item_
  function do_ajax_billing_item_edit_grid_validate_item_(iNumLinha)
  {
    var nomeCampo_item_ = "item_" + iNumLinha;
    var var_item_ = scAjaxGetFieldText(nomeCampo_item_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_item_(var_item_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_item__cb);
  } // do_ajax_billing_item_edit_grid_validate_item_

  function do_ajax_billing_item_edit_grid_validate_item__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "item_" + iLineNumber;
    }
    else
    {
      sFieldValid = "item_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "item_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "item_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_item__cb

  // ---------- Validate date_
  function do_ajax_billing_item_edit_grid_validate_date_(iNumLinha)
  {
    var nomeCampo_date_ = "date_" + iNumLinha;
    var var_date_ = scAjaxGetFieldText(nomeCampo_date_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_date_(var_date_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_date__cb);
  } // do_ajax_billing_item_edit_grid_validate_date_

  function do_ajax_billing_item_edit_grid_validate_date__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "date_" + iLineNumber;
    }
    else
    {
      sFieldValid = "date_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "date_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "date_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_date__cb

  // ---------- Validate bcode_
  function do_ajax_billing_item_edit_grid_validate_bcode_(iNumLinha)
  {
    var nomeCampo_bcode_ = "bcode_" + iNumLinha;
    var var_bcode_ = scAjaxGetFieldText(nomeCampo_bcode_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_bcode_(var_bcode_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_bcode__cb);
  } // do_ajax_billing_item_edit_grid_validate_bcode_

  function do_ajax_billing_item_edit_grid_validate_bcode__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "bcode_" + iLineNumber;
    }
    else
    {
      sFieldValid = "bcode_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "bcode_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "bcode_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_bcode__cb

  // ---------- Validate lin_
  function do_ajax_billing_item_edit_grid_validate_lin_(iNumLinha)
  {
    var nomeCampo_lin_ = "lin_" + iNumLinha;
    var var_lin_ = scAjaxGetFieldText(nomeCampo_lin_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_lin_(var_lin_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_lin__cb);
  } // do_ajax_billing_item_edit_grid_validate_lin_

  function do_ajax_billing_item_edit_grid_validate_lin__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "lin_" + iLineNumber;
    }
    else
    {
      sFieldValid = "lin_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "lin_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "lin_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_lin__cb

  // ---------- Validate sq_
  function do_ajax_billing_item_edit_grid_validate_sq_(iNumLinha)
  {
    var nomeCampo_sq_ = "sq_" + iNumLinha;
    var var_sq_ = scAjaxGetFieldText(nomeCampo_sq_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_sq_(var_sq_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_sq__cb);
  } // do_ajax_billing_item_edit_grid_validate_sq_

  function do_ajax_billing_item_edit_grid_validate_sq__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "sq_" + iLineNumber;
    }
    else
    {
      sFieldValid = "sq_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "sq_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "sq_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_sq__cb

  // ---------- Validate style_
  function do_ajax_billing_item_edit_grid_validate_style_(iNumLinha)
  {
    var nomeCampo_style_ = "style_" + iNumLinha;
    var var_style_ = scAjaxGetFieldText(nomeCampo_style_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_style_(var_style_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_style__cb);
  } // do_ajax_billing_item_edit_grid_validate_style_

  function do_ajax_billing_item_edit_grid_validate_style__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "style_" + iLineNumber;
    }
    else
    {
      sFieldValid = "style_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "style_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "style_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_style__cb

  // ---------- Validate width_
  function do_ajax_billing_item_edit_grid_validate_width_(iNumLinha)
  {
    var nomeCampo_width_ = "width_" + iNumLinha;
    var var_width_ = scAjaxGetFieldText(nomeCampo_width_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_width_(var_width_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_width__cb);
  } // do_ajax_billing_item_edit_grid_validate_width_

  function do_ajax_billing_item_edit_grid_validate_width__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "width_" + iLineNumber;
    }
    else
    {
      sFieldValid = "width_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "width_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "width_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_width__cb

  // ---------- Validate color_
  function do_ajax_billing_item_edit_grid_validate_color_(iNumLinha)
  {
    var nomeCampo_color_ = "color_" + iNumLinha;
    var var_color_ = scAjaxGetFieldText(nomeCampo_color_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_color_(var_color_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_color__cb);
  } // do_ajax_billing_item_edit_grid_validate_color_

  function do_ajax_billing_item_edit_grid_validate_color__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "color_" + iLineNumber;
    }
    else
    {
      sFieldValid = "color_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "color_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "color_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_color__cb

  // ---------- Validate cust_order_
  function do_ajax_billing_item_edit_grid_validate_cust_order_(iNumLinha)
  {
    var nomeCampo_cust_order_ = "cust_order_" + iNumLinha;
    var var_cust_order_ = scAjaxGetFieldText(nomeCampo_cust_order_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_cust_order_(var_cust_order_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_cust_order__cb);
  } // do_ajax_billing_item_edit_grid_validate_cust_order_

  function do_ajax_billing_item_edit_grid_validate_cust_order__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "cust_order_" + iLineNumber;
    }
    else
    {
      sFieldValid = "cust_order_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "cust_order_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "cust_order_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_cust_order__cb

  // ---------- Validate our_order_
  function do_ajax_billing_item_edit_grid_validate_our_order_(iNumLinha)
  {
    var nomeCampo_our_order_ = "our_order_" + iNumLinha;
    var var_our_order_ = scAjaxGetFieldText(nomeCampo_our_order_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_our_order_(var_our_order_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_our_order__cb);
  } // do_ajax_billing_item_edit_grid_validate_our_order_

  function do_ajax_billing_item_edit_grid_validate_our_order__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "our_order_" + iLineNumber;
    }
    else
    {
      sFieldValid = "our_order_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "our_order_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "our_order_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_our_order__cb

  // ---------- Validate price_
  function do_ajax_billing_item_edit_grid_validate_price_(iNumLinha)
  {
    var nomeCampo_price_ = "price_" + iNumLinha;
    var var_price_ = scAjaxGetFieldText(nomeCampo_price_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_price_(var_price_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_price__cb);
  } // do_ajax_billing_item_edit_grid_validate_price_

  function do_ajax_billing_item_edit_grid_validate_price__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "price_" + iLineNumber;
    }
    else
    {
      sFieldValid = "price_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "price_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "price_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_price__cb

  // ---------- Validate unit_
  function do_ajax_billing_item_edit_grid_validate_unit_(iNumLinha)
  {
    var nomeCampo_unit_ = "unit_" + iNumLinha;
    var var_unit_ = scAjaxGetFieldText(nomeCampo_unit_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_unit_(var_unit_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_unit__cb);
  } // do_ajax_billing_item_edit_grid_validate_unit_

  function do_ajax_billing_item_edit_grid_validate_unit__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "unit_" + iLineNumber;
    }
    else
    {
      sFieldValid = "unit_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "unit_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "unit_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_unit__cb

  // ---------- Validate amount_
  function do_ajax_billing_item_edit_grid_validate_amount_(iNumLinha)
  {
    var nomeCampo_amount_ = "amount_" + iNumLinha;
    var var_amount_ = scAjaxGetFieldText(nomeCampo_amount_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_amount_(var_amount_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_amount__cb);
  } // do_ajax_billing_item_edit_grid_validate_amount_

  function do_ajax_billing_item_edit_grid_validate_amount__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "amount_" + iLineNumber;
    }
    else
    {
      sFieldValid = "amount_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "amount_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "amount_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_amount__cb

  // ---------- Validate descrip_
  function do_ajax_billing_item_edit_grid_validate_descrip_(iNumLinha)
  {
    var nomeCampo_descrip_ = "descrip_" + iNumLinha;
    var var_descrip_ = scAjaxGetFieldText(nomeCampo_descrip_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_descrip_(var_descrip_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_descrip__cb);
  } // do_ajax_billing_item_edit_grid_validate_descrip_

  function do_ajax_billing_item_edit_grid_validate_descrip__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "descrip_" + iLineNumber;
    }
    else
    {
      sFieldValid = "descrip_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "descrip_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "descrip_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_descrip__cb

  // ---------- Validate dye_order_
  function do_ajax_billing_item_edit_grid_validate_dye_order_(iNumLinha)
  {
    var nomeCampo_dye_order_ = "dye_order_" + iNumLinha;
    var var_dye_order_ = scAjaxGetFieldText(nomeCampo_dye_order_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_dye_order_(var_dye_order_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_dye_order__cb);
  } // do_ajax_billing_item_edit_grid_validate_dye_order_

  function do_ajax_billing_item_edit_grid_validate_dye_order__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "dye_order_" + iLineNumber;
    }
    else
    {
      sFieldValid = "dye_order_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "dye_order_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "dye_order_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_dye_order__cb

  // ---------- Validate dye_lot_
  function do_ajax_billing_item_edit_grid_validate_dye_lot_(iNumLinha)
  {
    var nomeCampo_dye_lot_ = "dye_lot_" + iNumLinha;
    var var_dye_lot_ = scAjaxGetFieldText(nomeCampo_dye_lot_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_dye_lot_(var_dye_lot_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_dye_lot__cb);
  } // do_ajax_billing_item_edit_grid_validate_dye_lot_

  function do_ajax_billing_item_edit_grid_validate_dye_lot__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "dye_lot_" + iLineNumber;
    }
    else
    {
      sFieldValid = "dye_lot_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "dye_lot_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "dye_lot_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_dye_lot__cb

  // ---------- Validate cases_
  function do_ajax_billing_item_edit_grid_validate_cases_(iNumLinha)
  {
    var nomeCampo_cases_ = "cases_" + iNumLinha;
    var var_cases_ = scAjaxGetFieldText(nomeCampo_cases_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_cases_(var_cases_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_cases__cb);
  } // do_ajax_billing_item_edit_grid_validate_cases_

  function do_ajax_billing_item_edit_grid_validate_cases__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "cases_" + iLineNumber;
    }
    else
    {
      sFieldValid = "cases_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "cases_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "cases_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_cases__cb

  // ---------- Validate cost_
  function do_ajax_billing_item_edit_grid_validate_cost_(iNumLinha)
  {
    var nomeCampo_cost_ = "cost_" + iNumLinha;
    var var_cost_ = scAjaxGetFieldText(nomeCampo_cost_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_cost_(var_cost_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_cost__cb);
  } // do_ajax_billing_item_edit_grid_validate_cost_

  function do_ajax_billing_item_edit_grid_validate_cost__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "cost_" + iLineNumber;
    }
    else
    {
      sFieldValid = "cost_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "cost_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "cost_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_cost__cb

  // ---------- Validate cost_yd_
  function do_ajax_billing_item_edit_grid_validate_cost_yd_(iNumLinha)
  {
    var nomeCampo_cost_yd_ = "cost_yd_" + iNumLinha;
    var var_cost_yd_ = scAjaxGetFieldText(nomeCampo_cost_yd_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_cost_yd_(var_cost_yd_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_cost_yd__cb);
  } // do_ajax_billing_item_edit_grid_validate_cost_yd_

  function do_ajax_billing_item_edit_grid_validate_cost_yd__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "cost_yd_" + iLineNumber;
    }
    else
    {
      sFieldValid = "cost_yd_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "cost_yd_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "cost_yd_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_cost_yd__cb

  // ---------- Validate gp_
  function do_ajax_billing_item_edit_grid_validate_gp_(iNumLinha)
  {
    var nomeCampo_gp_ = "gp_" + iNumLinha;
    var var_gp_ = scAjaxGetFieldText(nomeCampo_gp_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_gp_(var_gp_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_gp__cb);
  } // do_ajax_billing_item_edit_grid_validate_gp_

  function do_ajax_billing_item_edit_grid_validate_gp__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "gp_" + iLineNumber;
    }
    else
    {
      sFieldValid = "gp_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "gp_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "gp_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_gp__cb

  // ---------- Validate gp_yd_
  function do_ajax_billing_item_edit_grid_validate_gp_yd_(iNumLinha)
  {
    var nomeCampo_gp_yd_ = "gp_yd_" + iNumLinha;
    var var_gp_yd_ = scAjaxGetFieldText(nomeCampo_gp_yd_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_gp_yd_(var_gp_yd_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_gp_yd__cb);
  } // do_ajax_billing_item_edit_grid_validate_gp_yd_

  function do_ajax_billing_item_edit_grid_validate_gp_yd__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "gp_yd_" + iLineNumber;
    }
    else
    {
      sFieldValid = "gp_yd_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "gp_yd_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "gp_yd_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_gp_yd__cb

  // ---------- Validate pc_
  function do_ajax_billing_item_edit_grid_validate_pc_(iNumLinha)
  {
    var nomeCampo_pc_ = "pc_" + iNumLinha;
    var var_pc_ = scAjaxGetFieldText(nomeCampo_pc_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_pc_(var_pc_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_pc__cb);
  } // do_ajax_billing_item_edit_grid_validate_pc_

  function do_ajax_billing_item_edit_grid_validate_pc__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "pc_" + iLineNumber;
    }
    else
    {
      sFieldValid = "pc_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "pc_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "pc_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_pc__cb

  // ---------- Validate adate_
  function do_ajax_billing_item_edit_grid_validate_adate_(iNumLinha)
  {
    var nomeCampo_adate_ = "adate_" + iNumLinha;
    var var_adate_ = scAjaxGetFieldText(nomeCampo_adate_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_adate_(var_adate_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_adate__cb);
  } // do_ajax_billing_item_edit_grid_validate_adate_

  function do_ajax_billing_item_edit_grid_validate_adate__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "adate_" + iLineNumber;
    }
    else
    {
      sFieldValid = "adate_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "adate_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "adate_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_adate__cb

  // ---------- Validate edate_
  function do_ajax_billing_item_edit_grid_validate_edate_(iNumLinha)
  {
    var nomeCampo_edate_ = "edate_" + iNumLinha;
    var var_edate_ = scAjaxGetFieldText(nomeCampo_edate_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_edate_(var_edate_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_edate__cb);
  } // do_ajax_billing_item_edit_grid_validate_edate_

  function do_ajax_billing_item_edit_grid_validate_edate__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "edate_" + iLineNumber;
    }
    else
    {
      sFieldValid = "edate_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "edate_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "edate_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_edate__cb

  // ---------- Validate smit_
  function do_ajax_billing_item_edit_grid_validate_smit_(iNumLinha)
  {
    var nomeCampo_smit_ = "smit_" + iNumLinha;
    var var_smit_ = scAjaxGetFieldText(nomeCampo_smit_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_smit_(var_smit_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_smit__cb);
  } // do_ajax_billing_item_edit_grid_validate_smit_

  function do_ajax_billing_item_edit_grid_validate_smit__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "smit_" + iLineNumber;
    }
    else
    {
      sFieldValid = "smit_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "smit_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "smit_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_smit__cb

  // ---------- Validate memo_
  function do_ajax_billing_item_edit_grid_validate_memo_(iNumLinha)
  {
    var nomeCampo_memo_ = "memo_" + iNumLinha;
    var var_memo_ = scAjaxGetFieldText(nomeCampo_memo_);
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_validate_memo_(var_memo_, iNumLinha, var_script_case_init, do_ajax_billing_item_edit_grid_validate_memo__cb);
  } // do_ajax_billing_item_edit_grid_validate_memo_

  function do_ajax_billing_item_edit_grid_validate_memo__cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    iLineNumber = scAjaxGetLineNumber();
    if ("" != iLineNumber)
    {
      sFieldValid = "memo_" + iLineNumber;
    }
    else
    {
      sFieldValid = "memo_";
    }
    scAjaxUpdateFieldErrors(sFieldValid, "valid");
    sFieldErrors = scAjaxListFieldErrors(sFieldValid, false);
    if ("" == sFieldErrors)
    {
      var sImgStatus = sc_img_status_ok;
      scAjaxHideErrorDisplay(sFieldValid);
      scErrorLineOff(iLineNumber, "memo_");
    }
    else
    {
      var sImgStatus = sc_img_status_err;
      scAjaxShowErrorDisplay(sFieldValid, sFieldErrors);
      scErrorLineOn(iLineNumber, "memo_");
    }
    var $oImg = $('#id_sc_status_' + sFieldValid);
    if (0 < $oImg.length)
    {
      $oImg.attr('src', sImgStatus).css('display', '');
    }
    scAjaxShowDebug();
    scAjaxSetMaster();
    scAjaxSetFocus();
  } // do_ajax_billing_item_edit_grid_validate_memo__cb

  var sc_num_ult_line = "";
  var sc_insert_open  = false;

  // ---------- add_new_line
  function do_ajax_billing_item_edit_grid_add_new_line(sc_clone, sc_seq_clone)
  {
    if (sc_insert_open)
    {
        if (sc_clone == 'S' && sc_seq_clone != iAjaxNewLine)
        {
          do_ajax_billing_item_edit_grid_cancel_insert(iAjaxNewLine);
        }
        else
        {
          return;
        }
    }
    sc_insert_open = true;
    scDisableNavigation();
    sc_num_ult_line = iAjaxNewLine + 1;
    if (sc_clone == 'S')
    {
      var var_sc_clone     = sc_clone;
      var var_sc_seq_clone = sc_seq_clone;
    }
    else
    {
      var var_sc_clone     = 'N';
      var var_sc_seq_clone = '';
    }
    var var_sc_seq_vert = document.F1.sc_contr_vert.value;
    var var_script_case_init = document.F1.script_case_init.value;
    scAjaxProcOn(true);
    x_ajax_billing_item_edit_grid_add_new_line(var_sc_clone, var_sc_seq_clone, var_sc_seq_vert, var_script_case_init, do_ajax_billing_item_edit_grid_add_new_line_cb);
  } // do_ajax_billing_item_edit_grid_add_new_line

  function do_ajax_billing_item_edit_grid_add_new_line_cb(sResp)
  {
    scAjaxProcOff(true);
    document.getElementById("new_line_dummy").innerHTML = "<table id=\"new_line_table\">" + scAjaxSpecCharParser(sResp) + "</table>";
    var oTBodyOld = document.getElementById("hidden_bloco_0").tBodies[0];
    var oTBodyNew = document.getElementById("new_line_table").tBodies[0];
    var oTRNewLine = oTBodyNew.rows[0];
    oTBodyOld.appendChild(oTRNewLine);
    ajax_create_tables(document.F1.sc_contr_vert.value);
    iAjaxNewLine = document.F1.sc_contr_vert.value;
    document.F1.sc_contr_vert.value++;
    scJQElementsAdd(iAjaxNewLine);
    if (document.getElementById("sc_clone_line_" + iAjaxNewLine))
        document.getElementById("sc_clone_line_" + iAjaxNewLine).style.display = "none";
    $('#idVertRow' + iAjaxNewLine + ' input:text.sc-js-input').listen();
    $('#idVertRow' + iAjaxNewLine + ' input:password.sc-js-input').listen();
    $('#idVertRow' + iAjaxNewLine + ' textarea.sc-js-input').listen();
  } // do_ajax_billing_item_edit_grid_add_new_line_cb

  // ---------- backup_line
  function do_ajax_billing_item_edit_grid_backup_line(iNumLinha)
  {
    var var_smit_ = scAjaxGetFieldText("smit_" + iNumLinha);
    var var_nmgp_refresh_row = iNumLinha;
    var var_nm_form_submit = document.F1.nm_form_submit.value;
    var var_script_case_init = document.F1.script_case_init.value;
    x_ajax_billing_item_edit_grid_backup_line(var_smit_, var_nmgp_refresh_row, var_nm_form_submit, var_script_case_init, do_ajax_billing_item_edit_grid_backup_line_cb);
  } // do_ajax_billing_item_edit_grid_backup_line

  function do_ajax_billing_item_edit_grid_backup_line_cb(sResp)
  {
    oResp = scAjaxResponse(sResp);
    if (!scAjaxHasError())
    {
      scAjaxSetFields();
    }
  } // do_ajax_billing_item_edit_grid_backup_line_cb

  function do_ajax_billing_item_edit_grid_cancel_insert(iSeqVert)
  {
    var oTBodyOld = document.getElementById("hidden_bloco_0").tBodies[0];
    var oTROldLine = oTBodyOld.rows[oTBodyOld.rows.length - 1];
    oTBodyOld.removeChild(oTROldLine);
    ajax_destroy_tables(iSeqVert);
    scEnableNavigation();
    sc_insert_open = false;
    scAjaxHideErrorDisplay("table");
  } // do_ajax_billing_item_edit_grid_cancel_insert

  function do_ajax_billing_item_edit_grid_cancel_update(iSeqVert)
  {
    do_ajax_billing_item_edit_grid_backup_line(iSeqVert);
    scErrorLineOff(iSeqVert, "__sc_all__");
    scAjaxHideErrorDisplay("table");
<?php
    if ($this->Embutida_ronly)
    {
?>
    mdCloseObjects(iSeqVert);
    if (document.getElementById("sc_exc_line_" + iSeqVert))
      document.getElementById("sc_exc_line_" + iSeqVert).style.display = "";
    if (document.getElementById("sc_open_line_" + iSeqVert))
      document.getElementById("sc_open_line_" + iSeqVert).style.display = "";
    if (document.getElementById("sc_upd_line_" + iSeqVert))
      document.getElementById("sc_upd_line_" + iSeqVert).style.display = "none";
    if (document.getElementById("sc_cancelu_line_" + iSeqVert))
      document.getElementById("sc_cancelu_line_" + iSeqVert).style.display = "none";
<?php
    }
?>
  } // do_ajax_billing_item_edit_grid_cancel_update

  function do_ajax_billing_item_edit_grid_restore_buttons()
  {
<?php
    if (isset($this->Embutida_ronly) && $this->Embutida_ronly)
    {
?>
    for (iSeqVert = 1; iSeqVert <= <?php echo $this->sc_max_reg; ?>; iSeqVert++)
    {
<?php
    if ($this->nmgp_botoes['delete'] == 'on')
    {
?>
      if (document.getElementById("sc_exc_line_" + iSeqVert))
        document.getElementById("sc_exc_line_" + iSeqVert).style.display = "";
<?php
    }
?>
      if (document.getElementById("sc_open_line_" + iSeqVert))
        document.getElementById("sc_open_line_" + iSeqVert).style.display = "";
      if (document.getElementById("sc_ins_line_" + iSeqVert))
        document.getElementById("sc_ins_line_" + iSeqVert).style.display = "none";
      if (document.getElementById("sc_upd_line_" + iSeqVert))
        document.getElementById("sc_upd_line_" + iSeqVert).style.display = "none";
      if (document.getElementById("sc_new_line_" + iSeqVert))
        document.getElementById("sc_new_line_" + iSeqVert).style.display = "none";
      if (document.getElementById("sc_canceli_line_" + iSeqVert))
        document.getElementById("sc_canceli_line_" + iSeqVert).style.display = "none";
      if (document.getElementById("sc_cancelu_line_" + iSeqVert))
        document.getElementById("sc_cancelu_line_" + iSeqVert).style.display = "none";
    }
<?php
    }
?>
  } // do_ajax_billing_item_edit_grid_restore_buttons

  // ---------- table_refresh
  function do_ajax_billing_item_edit_grid_table_refresh()
  {
    var var_smit_ = document.F2.smit_.value;
    var var_nm_form_submit = document.F2.nm_form_submit.value;
    var var_nmgp_opcao = document.F2.nmgp_opcao.value;
    var var_nmgp_ordem = document.F2.nmgp_ordem.value;
    var var_nmgp_fast_search = document.F2.nmgp_fast_search.value;
    var var_nmgp_cond_fast_search = document.F2.nmgp_cond_fast_search.value;
    var var_nmgp_arg_fast_search = document.F2.nmgp_arg_fast_search.value;
    var var_script_case_init = document.F2.script_case_init.value;
    scAjaxProcOn();
    x_ajax_billing_item_edit_grid_table_refresh(var_smit_, var_nm_form_submit, var_nmgp_opcao, var_nmgp_ordem, var_nmgp_fast_search, var_nmgp_cond_fast_search, var_nmgp_arg_fast_search, var_script_case_init, do_ajax_billing_item_edit_grid_table_refresh_cb);
  } //  do_ajax_billing_item_edit_grid_table_refresh

  function do_ajax_billing_item_edit_grid_table_refresh_cb(sResp)
  {
    scAjaxProcOff();
    oResp = scAjaxResponse(sResp);
    if ("ERROR" == oResp.result)
    {
        scAjaxShowErrorDisplay("table", oResp.errList[0].msgText);
        scAjaxProcOff();
        return;
    }
    if (oResp["rsSize"] < <?php echo $this->sc_max_reg; ?>)
    {
       bRefreshTable = true;
    }
    if (oResp["navSummary"].reg_tot == 0)
    {
       $("#sc-ui-empty-form").show();
    }
    else
    {
       $("#sc-ui-empty-form").hide();
    }
    document.F2.smit_.value = scAjaxGetKeyValue("smit_");
    for (i = 1; i < <?php echo $this->sc_max_reg + 1; ?> ; i++)
    {
    }
    document.getElementById("SC_tab_mult_reg").innerHTML = scAjaxSpecCharParser(oResp["tableRefresh"]);
    for (i = 1; i < <?php echo $this->sc_max_reg + 1; ?> ; i++)
    {
    }
    document.F1.sc_contr_vert.value = <?php echo $this->sc_max_reg + 1; ?>;
    iAjaxNewLine = oResp["rsSize"];
    var iAjaxNewLine = <?php echo $this->sc_max_reg + 1; ?>;
    for (var iLine = 1; iLine <= iAjaxNewLine; iLine++) {
         scJQElementsAdd(iLine);
    }
    scJQGeneralAdd();
    scAjaxSetSummary();
    scAjaxSetNavpage();
    scQSInit = true;
    scQSInitVal = $("#SC_fast_search_t").val();
    scQuickSearchKeyUp('t', null);
    $('#SC_fast_search_t').blur();
    scQuickSearchInit(true, '');
    scQSInit = false;
    scAjaxAlert();
    scAjaxMessage();
    scAjaxJavascript();
    scAjaxSetFocus();
    scAjaxSetNavStatus("t");
    scAjaxSetNavStatus("b");
    sc_insert_open = false;
  } // do_ajax_billing_item_edit_grid_table_refresh_cb

  // ---------- Form
  var sc_num_ult_line = "";
  var sc_num_ult_opc  = "";
  var sc_num_ult_tr   = "";
  function do_ajax_billing_item_edit_grid_submit_form(iNumLinha, indexTR)
  {
    sc_num_ult_line = iNumLinha;
    sc_num_ult_tr   = indexTR;
    scAjaxHideMessage();
    var var_invoice_ = scAjaxGetFieldText("invoice_" + iNumLinha);
    var var_item_ = scAjaxGetFieldText("item_" + iNumLinha);
    var var_date_ = scAjaxGetFieldText("date_" + iNumLinha);
    var var_bcode_ = scAjaxGetFieldText("bcode_" + iNumLinha);
    var var_lin_ = scAjaxGetFieldText("lin_" + iNumLinha);
    var var_sq_ = scAjaxGetFieldText("sq_" + iNumLinha);
    var var_style_ = scAjaxGetFieldText("style_" + iNumLinha);
    var var_width_ = scAjaxGetFieldText("width_" + iNumLinha);
    var var_color_ = scAjaxGetFieldText("color_" + iNumLinha);
    var var_cust_order_ = scAjaxGetFieldText("cust_order_" + iNumLinha);
    var var_our_order_ = scAjaxGetFieldText("our_order_" + iNumLinha);
    var var_price_ = scAjaxGetFieldText("price_" + iNumLinha);
    var var_unit_ = scAjaxGetFieldText("unit_" + iNumLinha);
    var var_amount_ = scAjaxGetFieldText("amount_" + iNumLinha);
    var var_descrip_ = scAjaxGetFieldText("descrip_" + iNumLinha);
    var var_dye_order_ = scAjaxGetFieldText("dye_order_" + iNumLinha);
    var var_dye_lot_ = scAjaxGetFieldText("dye_lot_" + iNumLinha);
    var var_cases_ = scAjaxGetFieldText("cases_" + iNumLinha);
    var var_cost_ = scAjaxGetFieldText("cost_" + iNumLinha);
    var var_cost_yd_ = scAjaxGetFieldText("cost_yd_" + iNumLinha);
    var var_gp_ = scAjaxGetFieldText("gp_" + iNumLinha);
    var var_gp_yd_ = scAjaxGetFieldText("gp_yd_" + iNumLinha);
    var var_pc_ = scAjaxGetFieldText("pc_" + iNumLinha);
    var var_adate_ = scAjaxGetFieldText("adate_" + iNumLinha);
    var var_edate_ = scAjaxGetFieldText("edate_" + iNumLinha);
    var var_smit_ = scAjaxGetFieldText("smit_" + iNumLinha);
    var var_memo_ = scAjaxGetFieldText("memo_" + iNumLinha);
    var var_nm_form_submit = document.F1.nm_form_submit.value;
    var var_nmgp_url_saida = document.F1.nmgp_url_saida.value;
    var var_nmgp_opcao = document.F1.nmgp_opcao.value;
    var var_nmgp_ancora = document.F1.nmgp_ancora.value;
    var var_nmgp_num_form = document.F1.nmgp_num_form.value;
    var var_nmgp_parms = "Sc_num_lin_alt?#?" + iNumLinha + "?@?" +  document.F1.nmgp_parms.value;
    var var_script_case_init = document.F1.script_case_init.value;
<?php
    if (isset($this->Embutida_form) && $this->Embutida_form)
    {
?>
    var var_nmgp_refresh_row = iNumLinha;
<?php
    }
    else
    {
?>
    var var_nmgp_refresh_row = "";
<?php
    }
?>
    sc_num_ult_opc = var_nmgp_opcao;
    scAjaxProcOn();
<?php
    if (isset($this->Embutida_form) && $this->Embutida_form)
    {
?>
    scRemoveErrors();
<?php
    }
?>
    x_ajax_billing_item_edit_grid_submit_form(var_invoice_, var_item_, var_date_, var_bcode_, var_lin_, var_sq_, var_style_, var_width_, var_color_, var_cust_order_, var_our_order_, var_price_, var_unit_, var_amount_, var_descrip_, var_dye_order_, var_dye_lot_, var_cases_, var_cost_, var_cost_yd_, var_gp_, var_gp_yd_, var_pc_, var_adate_, var_edate_, var_smit_, var_memo_, var_nmgp_refresh_row, var_nm_form_submit, var_nmgp_url_saida, var_nmgp_opcao, var_nmgp_ancora, var_nmgp_num_form, var_nmgp_parms, var_script_case_init, do_ajax_billing_item_edit_grid_submit_form_cb);
  } // do_ajax_billing_item_edit_grid_submit_form

  function do_ajax_billing_item_edit_grid_submit_form_cb(sResp)
  {
    scAjaxProcOff();
    oResp = scAjaxResponse(sResp);
    scAjaxCalendarReload();
    scAjaxUpdateErrors("valid");
    sAppErrors = scAjaxListErrors(true);
    if ("" == sAppErrors)
    {
      $('.sc-js-ui-statusimg').css('display', 'none');
      scAjaxHideErrorDisplay("table");
      scErrorLineOff(sc_num_ult_line, "__sc_all__");
    }
    else
    {
      scAjaxShowErrorDisplay("table", sAppErrors);
      scErrorLineOn(sc_num_ult_line, "__sc_all__");
    }
    if (!scAjaxHasError())
    {
      if (sc_num_ult_opc == 'incluir')
      {
         bRefreshTable = true;
         if (document.getElementById("sc_ins_line_" + sc_num_ult_line))
           document.getElementById("sc_ins_line_" + sc_num_ult_line).style.display = "none";
         if (document.getElementById("sc_upd_line_" + sc_num_ult_line))
           document.getElementById("sc_upd_line_" + sc_num_ult_line).style.display = "";
         if (document.getElementById("sc_clone_line_" + sc_num_ult_line))
           document.getElementById("sc_clone_line_" + sc_num_ult_line).style.display = "";
<?php
    if ($this->nmgp_botoes['delete'] == 'on')
    {
?>
         if (document.getElementById("sc_exc_line_" + sc_num_ult_line))
           document.getElementById("sc_exc_line_" + sc_num_ult_line).style.display = "";
<?php
    }
?>
         if (document.getElementById("sc_new_line_" + sc_num_ult_line))
           document.getElementById("sc_new_line_" + sc_num_ult_line).style.display = "none";
<?php
    if (isset($this->Embutida_form) && $this->Embutida_form)
    {
?>
         if (document.getElementById("sc_canceli_line_" + sc_num_ult_line))
           document.getElementById("sc_canceli_line_" + sc_num_ult_line).style.display = "none";
<?php
    }
?>
         sc_insert_open = false;
         scEnableNavigation();
         do_ajax_billing_item_edit_grid_add_new_line();
         $("#sc-ui-empty-form").hide();
      }
      if (sc_num_ult_opc == 'alterar')
      {
<?php
    if (isset($this->Embutida_ronly) && $this->Embutida_ronly)
    {
       if ($this->nmgp_botoes['delete'] == 'on')
       {
?>
         if (document.getElementById("sc_exc_line_" + sc_num_ult_line))
           document.getElementById("sc_exc_line_" + sc_num_ult_line).style.display = "";
<?php
       }
?>
         if (document.getElementById("sc_cancelu_line_" + sc_num_ult_line))
           document.getElementById("sc_cancelu_line_" + sc_num_ult_line).style.display = "none";
<?php
    }
?>
      }
      if (sc_num_ult_opc == 'excluir')
      {
         bRefreshTable = true;
         sc_name_table = document.getElementById("hidden_bloco_0");
         sc_name_table.deleteRow(sc_num_ult_tr);
         sc_num_ult_line = sc_name_table.rows.length - 1;
         if (0 == sc_num_ult_line || (1 == sc_num_ult_line && sc_insert_open))
         {
            $("#sc-ui-empty-form").show();
         }
      }
      scAjaxShowMessage();
      scAjaxHideErrorDisplay("table");
      scAjaxHideErrorDisplay("invoice_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("item_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("date_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("bcode_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("lin_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("sq_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("style_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("width_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("color_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("cust_order_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("our_order_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("price_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("unit_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("amount_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("descrip_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("dye_order_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("dye_lot_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("cases_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("cost_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("cost_yd_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("gp_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("gp_yd_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("pc_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("adate_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("edate_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("smit_" + sc_num_ult_line);
      scAjaxHideErrorDisplay("memo_" + sc_num_ult_line);
<?php
if (isset($this->Embutida_form) && $this->Embutida_form) {
?>
      scAjaxSetFields();
      scAjaxSetReadonly();
<?php
    if (isset($this->Embutida_ronly) && $this->Embutida_ronly) {
?>
      mdCloseLine();
<?php
    }
} else {
?>
      scAjaxSetReadonly(true);
<?php
}
?>
      scLigEditLookupCall();
    }
    Nm_Proc_Atualiz = false;
    if (!scAjaxHasError())
    {
      if (sc_closeChange && self.parent && self.parent.tb_remove)
      {
        self.parent.tb_remove();
      }
      scAjaxSetFields();
      if (sc_num_ult_opc == 'alterar' || sc_num_ult_opc == 'incluir')
      {
<?php
        if (isset($this->Embutida_form) && $this->Embutida_form)
        {
?>
<?php
        }
?>
      }
    }
    scAjaxSetSummary();
    scAjaxSetNavpage();
    scAjaxShowDebug();
    scAjaxSetDisplay(true);
    scAjaxSetLabel(true);
    scAjaxSetMaster();
    scAjaxAlert();
    scAjaxMessage();
    scAjaxJavascript();
    scAjaxSetFocus();
    scAjaxRedir();
    if (hasJsFormOnload)
    {
      sc_form_onload();
    }
  } // do_ajax_billing_item_edit_grid_submit_form_cb

  var scStatusDetail = {};

  function do_ajax_billing_item_edit_grid_navigate_form()
  {
    if (scRefreshTable())
    {
      return;
    }
    if (sc_insert_open)
    {
        do_ajax_billing_item_edit_grid_cancel_insert(sc_num_ult_line);
    }
    nm_uncheck_delete();
    scAjaxHideMessage();
    scAjaxHideErrorDisplay("table");
    for (iNavForm = 1; iNavForm < <?php echo $this->sc_max_reg; ?> + 1; iNavForm++)
    {
      scAjaxHideErrorDisplay("invoice_" + iNavForm);
      scAjaxHideErrorDisplay("item_" + iNavForm);
      scAjaxHideErrorDisplay("date_" + iNavForm);
      scAjaxHideErrorDisplay("bcode_" + iNavForm);
      scAjaxHideErrorDisplay("lin_" + iNavForm);
      scAjaxHideErrorDisplay("sq_" + iNavForm);
      scAjaxHideErrorDisplay("style_" + iNavForm);
      scAjaxHideErrorDisplay("width_" + iNavForm);
      scAjaxHideErrorDisplay("color_" + iNavForm);
      scAjaxHideErrorDisplay("cust_order_" + iNavForm);
      scAjaxHideErrorDisplay("our_order_" + iNavForm);
      scAjaxHideErrorDisplay("price_" + iNavForm);
      scAjaxHideErrorDisplay("unit_" + iNavForm);
      scAjaxHideErrorDisplay("amount_" + iNavForm);
      scAjaxHideErrorDisplay("descrip_" + iNavForm);
      scAjaxHideErrorDisplay("dye_order_" + iNavForm);
      scAjaxHideErrorDisplay("dye_lot_" + iNavForm);
      scAjaxHideErrorDisplay("cases_" + iNavForm);
      scAjaxHideErrorDisplay("cost_" + iNavForm);
      scAjaxHideErrorDisplay("cost_yd_" + iNavForm);
      scAjaxHideErrorDisplay("gp_" + iNavForm);
      scAjaxHideErrorDisplay("gp_yd_" + iNavForm);
      scAjaxHideErrorDisplay("pc_" + iNavForm);
      scAjaxHideErrorDisplay("adate_" + iNavForm);
      scAjaxHideErrorDisplay("edate_" + iNavForm);
      scAjaxHideErrorDisplay("smit_" + iNavForm);
      scAjaxHideErrorDisplay("memo_" + iNavForm);
    }
    var var_smit_ = document.F2.smit_.value;
    var var_nm_form_submit = document.F2.nm_form_submit.value;
    var var_nmgp_opcao = document.F2.nmgp_opcao.value;
    var var_nmgp_ordem = document.F2.nmgp_ordem.value;
    var var_script_case_init = document.F2.script_case_init.value;
    scAjaxProcOn();
    x_ajax_billing_item_edit_grid_navigate_form(var_smit_, var_nm_form_submit, var_nmgp_opcao, var_nmgp_ordem, var_script_case_init, do_ajax_billing_item_edit_grid_navigate_form_cb);
  } // do_ajax_billing_item_edit_grid_navigate_form

  function do_ajax_billing_item_edit_grid_navigate_form_cb(sResp)
  {
    scAjaxProcOff();
    oResp = scAjaxResponse(sResp);
    var var_last_index = oResp["rsSize"];
    sc_mupload_ok = true;
    scAjaxSetFields();
    document.F2.smit_.value = scAjaxGetKeyValue("smit_" + var_last_index);
    var_last_index = parseInt(var_last_index) + 1;
    for (iNavigateForm = 1; iNavigateForm < var_last_index; iNavigateForm++)
    {
      if (document.getElementById("idVertRow" + iNavigateForm))
      {
        document.getElementById("idVertRow" + iNavigateForm).style.display = "";
      }
    }
    var oTBodyOld = document.getElementById("hidden_bloco_0").tBodies[0];
    for (iNavigatedel = <?php echo $this->sc_max_reg; ?>; iNavigatedel >= iNavigateForm; iNavigatedel--)
    {
        oTBodyOld.deleteRow(iNavigatedel);
        bRefreshTable = true;
    }
    document.F1.sc_contr_vert.value = var_last_index;
    scAjaxSetSummary();
    scAjaxSetNavpage();
    scAjaxShowDebug();
    scAjaxSetDisplay(true);
    scAjaxSetLabel(true);
    scAjaxSetReadonly(true);
    scAjaxSetMaster();
    scAjaxSetNavStatus("t");
    scAjaxSetNavStatus("b");
    for (var iImg = 0; iImg < var_last_index; iImg++)
    {
    }
    scAjaxSetBtnVars();
    scErrorLineReset();
    $('.sc-js-ui-statusimg').css('display', 'none');
    scAjaxAlert();
    scAjaxMessage();
    scAjaxJavascript();
    scAjaxSetFocus();
<?php
if ($this->Embutida_form)
{
?>
    do_ajax_billing_item_edit_grid_restore_buttons();
<?php
}
?>
    if (hasJsFormOnload)
    {
      sc_form_onload();
    }
  } // do_ajax_billing_item_edit_grid_navigate_form_cb

  function scAjaxDetailProc()
  {
    return true;
  } // scAjaxDetailProc

<?php
$sLineInfo = $this->Embutida_form ? '' : ' (linha " + iNumLinha + ")';
?>
  function ajax_create_tables(iNumLinha)
  {
    ajax_field_list[iTotCampos] = "invoice_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "item_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "date_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "bcode_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "lin_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "sq_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "style_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "width_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "color_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "cust_order_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "our_order_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "price_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "unit_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "amount_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "descrip_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "dye_order_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "dye_lot_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "cases_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "cost_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "cost_yd_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "gp_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "gp_yd_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "pc_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "adate_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "edate_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "smit_" + iNumLinha;
    iTotCampos++;
    ajax_field_list[iTotCampos] = "memo_" + iNumLinha;
    iTotCampos++;
    ajax_error_list["invoice_" + iNumLinha] = {"label": "INVOICE<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["item_" + iNumLinha] = {"label": "ITEM<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["date_" + iNumLinha] = {"label": "DATE<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["bcode_" + iNumLinha] = {"label": "BCODE<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["lin_" + iNumLinha] = {"label": "LIN<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["sq_" + iNumLinha] = {"label": "SQ<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["style_" + iNumLinha] = {"label": "STYLE<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["width_" + iNumLinha] = {"label": "WIDTH<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["color_" + iNumLinha] = {"label": "COLOR<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["cust_order_" + iNumLinha] = {"label": "CUST ORDER<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["our_order_" + iNumLinha] = {"label": "OUR ORDER<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["price_" + iNumLinha] = {"label": "PRICE<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["unit_" + iNumLinha] = {"label": "UNIT<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["amount_" + iNumLinha] = {"label": "AMOUNT<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["descrip_" + iNumLinha] = {"label": "DESCRIP<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["dye_order_" + iNumLinha] = {"label": "DYE ORDER<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["dye_lot_" + iNumLinha] = {"label": "DYE LOT<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["cases_" + iNumLinha] = {"label": "CASES<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["cost_" + iNumLinha] = {"label": "COST<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["cost_yd_" + iNumLinha] = {"label": "COST YD<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["gp_" + iNumLinha] = {"label": "GP<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["gp_yd_" + iNumLinha] = {"label": "GP YD<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["pc_" + iNumLinha] = {"label": "PC<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["adate_" + iNumLinha] = {"label": "ADATE<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["edate_" + iNumLinha] = {"label": "EDATE<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["smit_" + iNumLinha] = {"label": "SMIT<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_error_list["memo_" + iNumLinha] = {"label": "MEMO<?php echo $sLineInfo; ?>", "valid": new Array(), "onblur": new Array(), "onchange": new Array(), "onclick": new Array(), "onfocus": new Array(), "timeout": 5};
    ajax_field_mult["invoice_"][iNumLinha] = "invoice_" + iNumLinha;
    ajax_field_mult["item_"][iNumLinha] = "item_" + iNumLinha;
    ajax_field_mult["date_"][iNumLinha] = "date_" + iNumLinha;
    ajax_field_mult["bcode_"][iNumLinha] = "bcode_" + iNumLinha;
    ajax_field_mult["lin_"][iNumLinha] = "lin_" + iNumLinha;
    ajax_field_mult["sq_"][iNumLinha] = "sq_" + iNumLinha;
    ajax_field_mult["style_"][iNumLinha] = "style_" + iNumLinha;
    ajax_field_mult["width_"][iNumLinha] = "width_" + iNumLinha;
    ajax_field_mult["color_"][iNumLinha] = "color_" + iNumLinha;
    ajax_field_mult["cust_order_"][iNumLinha] = "cust_order_" + iNumLinha;
    ajax_field_mult["our_order_"][iNumLinha] = "our_order_" + iNumLinha;
    ajax_field_mult["price_"][iNumLinha] = "price_" + iNumLinha;
    ajax_field_mult["unit_"][iNumLinha] = "unit_" + iNumLinha;
    ajax_field_mult["amount_"][iNumLinha] = "amount_" + iNumLinha;
    ajax_field_mult["descrip_"][iNumLinha] = "descrip_" + iNumLinha;
    ajax_field_mult["dye_order_"][iNumLinha] = "dye_order_" + iNumLinha;
    ajax_field_mult["dye_lot_"][iNumLinha] = "dye_lot_" + iNumLinha;
    ajax_field_mult["cases_"][iNumLinha] = "cases_" + iNumLinha;
    ajax_field_mult["cost_"][iNumLinha] = "cost_" + iNumLinha;
    ajax_field_mult["cost_yd_"][iNumLinha] = "cost_yd_" + iNumLinha;
    ajax_field_mult["gp_"][iNumLinha] = "gp_" + iNumLinha;
    ajax_field_mult["gp_yd_"][iNumLinha] = "gp_yd_" + iNumLinha;
    ajax_field_mult["pc_"][iNumLinha] = "pc_" + iNumLinha;
    ajax_field_mult["adate_"][iNumLinha] = "adate_" + iNumLinha;
    ajax_field_mult["edate_"][iNumLinha] = "edate_" + iNumLinha;
    ajax_field_mult["smit_"][iNumLinha] = "smit_" + iNumLinha;
    ajax_field_mult["memo_"][iNumLinha] = "memo_" + iNumLinha;
    ajax_field_id["invoice_" + iNumLinha] = new Array("hidden_field_label_invoice_", "hidden_field_data_invoice_" + iNumLinha);
    ajax_field_id["item_" + iNumLinha] = new Array("hidden_field_label_item_", "hidden_field_data_item_" + iNumLinha);
    ajax_field_id["date_" + iNumLinha] = new Array("hidden_field_label_date_", "hidden_field_data_date_" + iNumLinha);
    ajax_field_id["bcode_" + iNumLinha] = new Array("hidden_field_label_bcode_", "hidden_field_data_bcode_" + iNumLinha);
    ajax_field_id["lin_" + iNumLinha] = new Array("hidden_field_label_lin_", "hidden_field_data_lin_" + iNumLinha);
    ajax_field_id["sq_" + iNumLinha] = new Array("hidden_field_label_sq_", "hidden_field_data_sq_" + iNumLinha);
    ajax_field_id["style_" + iNumLinha] = new Array("hidden_field_label_style_", "hidden_field_data_style_" + iNumLinha);
    ajax_field_id["width_" + iNumLinha] = new Array("hidden_field_label_width_", "hidden_field_data_width_" + iNumLinha);
    ajax_field_id["color_" + iNumLinha] = new Array("hidden_field_label_color_", "hidden_field_data_color_" + iNumLinha);
    ajax_field_id["cust_order_" + iNumLinha] = new Array("hidden_field_label_cust_order_", "hidden_field_data_cust_order_" + iNumLinha);
    ajax_field_id["our_order_" + iNumLinha] = new Array("hidden_field_label_our_order_", "hidden_field_data_our_order_" + iNumLinha);
    ajax_field_id["price_" + iNumLinha] = new Array("hidden_field_label_price_", "hidden_field_data_price_" + iNumLinha);
    ajax_field_id["unit_" + iNumLinha] = new Array("hidden_field_label_unit_", "hidden_field_data_unit_" + iNumLinha);
    ajax_field_id["amount_" + iNumLinha] = new Array("hidden_field_label_amount_", "hidden_field_data_amount_" + iNumLinha);
    ajax_field_id["descrip_" + iNumLinha] = new Array("hidden_field_label_descrip_", "hidden_field_data_descrip_" + iNumLinha);
    ajax_field_id["dye_order_" + iNumLinha] = new Array("hidden_field_label_dye_order_", "hidden_field_data_dye_order_" + iNumLinha);
    ajax_field_id["dye_lot_" + iNumLinha] = new Array("hidden_field_label_dye_lot_", "hidden_field_data_dye_lot_" + iNumLinha);
    ajax_field_id["cases_" + iNumLinha] = new Array("hidden_field_label_cases_", "hidden_field_data_cases_" + iNumLinha);
    ajax_field_id["cost_" + iNumLinha] = new Array("hidden_field_label_cost_", "hidden_field_data_cost_" + iNumLinha);
    ajax_field_id["cost_yd_" + iNumLinha] = new Array("hidden_field_label_cost_yd_", "hidden_field_data_cost_yd_" + iNumLinha);
    ajax_field_id["gp_" + iNumLinha] = new Array("hidden_field_label_gp_", "hidden_field_data_gp_" + iNumLinha);
    ajax_field_id["gp_yd_" + iNumLinha] = new Array("hidden_field_label_gp_yd_", "hidden_field_data_gp_yd_" + iNumLinha);
    ajax_field_id["pc_" + iNumLinha] = new Array("hidden_field_label_pc_", "hidden_field_data_pc_" + iNumLinha);
    ajax_field_id["adate_" + iNumLinha] = new Array("hidden_field_label_adate_", "hidden_field_data_adate_" + iNumLinha);
    ajax_field_id["edate_" + iNumLinha] = new Array("hidden_field_label_edate_", "hidden_field_data_edate_" + iNumLinha);
    ajax_field_id["smit_" + iNumLinha] = new Array("hidden_field_label_smit_", "hidden_field_data_smit_" + iNumLinha);
    ajax_field_id["memo_" + iNumLinha] = new Array("hidden_field_label_memo_", "hidden_field_data_memo_" + iNumLinha);
    ajax_error_count["invoice_" + iNumLinha] = "off";
    ajax_error_count["item_" + iNumLinha] = "off";
    ajax_error_count["date_" + iNumLinha] = "off";
    ajax_error_count["bcode_" + iNumLinha] = "off";
    ajax_error_count["lin_" + iNumLinha] = "off";
    ajax_error_count["sq_" + iNumLinha] = "off";
    ajax_error_count["style_" + iNumLinha] = "off";
    ajax_error_count["width_" + iNumLinha] = "off";
    ajax_error_count["color_" + iNumLinha] = "off";
    ajax_error_count["cust_order_" + iNumLinha] = "off";
    ajax_error_count["our_order_" + iNumLinha] = "off";
    ajax_error_count["price_" + iNumLinha] = "off";
    ajax_error_count["unit_" + iNumLinha] = "off";
    ajax_error_count["amount_" + iNumLinha] = "off";
    ajax_error_count["descrip_" + iNumLinha] = "off";
    ajax_error_count["dye_order_" + iNumLinha] = "off";
    ajax_error_count["dye_lot_" + iNumLinha] = "off";
    ajax_error_count["cases_" + iNumLinha] = "off";
    ajax_error_count["cost_" + iNumLinha] = "off";
    ajax_error_count["cost_yd_" + iNumLinha] = "off";
    ajax_error_count["gp_" + iNumLinha] = "off";
    ajax_error_count["gp_yd_" + iNumLinha] = "off";
    ajax_error_count["pc_" + iNumLinha] = "off";
    ajax_error_count["adate_" + iNumLinha] = "off";
    ajax_error_count["edate_" + iNumLinha] = "off";
    ajax_error_count["smit_" + iNumLinha] = "off";
    ajax_error_count["memo_" + iNumLinha] = "off";
<?php
if (!$this->Grid_editavel)
{
?>
    ajax_read_only["invoice_" + iNumLinha] = "off";
    ajax_read_only["item_" + iNumLinha] = "off";
    ajax_read_only["date_" + iNumLinha] = "off";
    ajax_read_only["bcode_" + iNumLinha] = "off";
    ajax_read_only["lin_" + iNumLinha] = "off";
    ajax_read_only["sq_" + iNumLinha] = "off";
    ajax_read_only["style_" + iNumLinha] = "off";
    ajax_read_only["width_" + iNumLinha] = "off";
    ajax_read_only["color_" + iNumLinha] = "off";
    ajax_read_only["cust_order_" + iNumLinha] = "off";
    ajax_read_only["our_order_" + iNumLinha] = "off";
    ajax_read_only["price_" + iNumLinha] = "off";
    ajax_read_only["unit_" + iNumLinha] = "off";
    ajax_read_only["amount_" + iNumLinha] = "off";
    ajax_read_only["descrip_" + iNumLinha] = "off";
    ajax_read_only["dye_order_" + iNumLinha] = "off";
    ajax_read_only["dye_lot_" + iNumLinha] = "off";
    ajax_read_only["cases_" + iNumLinha] = "off";
    ajax_read_only["cost_" + iNumLinha] = "off";
    ajax_read_only["cost_yd_" + iNumLinha] = "off";
    ajax_read_only["gp_" + iNumLinha] = "off";
    ajax_read_only["gp_yd_" + iNumLinha] = "off";
    ajax_read_only["pc_" + iNumLinha] = "off";
    ajax_read_only["adate_" + iNumLinha] = "off";
    ajax_read_only["edate_" + iNumLinha] = "off";
    ajax_read_only["smit_" + iNumLinha] = "off";
    ajax_read_only["memo_" + iNumLinha] = "off";
<?php
}
else
{
?>
    ajax_read_only["invoice_" + iNumLinha] = "on";
    ajax_read_only["item_" + iNumLinha] = "on";
    ajax_read_only["date_" + iNumLinha] = "on";
    ajax_read_only["bcode_" + iNumLinha] = "on";
    ajax_read_only["lin_" + iNumLinha] = "on";
    ajax_read_only["sq_" + iNumLinha] = "on";
    ajax_read_only["style_" + iNumLinha] = "on";
    ajax_read_only["width_" + iNumLinha] = "on";
    ajax_read_only["color_" + iNumLinha] = "on";
    ajax_read_only["cust_order_" + iNumLinha] = "on";
    ajax_read_only["our_order_" + iNumLinha] = "on";
    ajax_read_only["price_" + iNumLinha] = "on";
    ajax_read_only["unit_" + iNumLinha] = "on";
    ajax_read_only["amount_" + iNumLinha] = "on";
    ajax_read_only["descrip_" + iNumLinha] = "on";
    ajax_read_only["dye_order_" + iNumLinha] = "on";
    ajax_read_only["dye_lot_" + iNumLinha] = "on";
    ajax_read_only["cases_" + iNumLinha] = "on";
    ajax_read_only["cost_" + iNumLinha] = "on";
    ajax_read_only["cost_yd_" + iNumLinha] = "on";
    ajax_read_only["gp_" + iNumLinha] = "on";
    ajax_read_only["gp_yd_" + iNumLinha] = "on";
    ajax_read_only["pc_" + iNumLinha] = "on";
    ajax_read_only["adate_" + iNumLinha] = "on";
    ajax_read_only["edate_" + iNumLinha] = "on";
    ajax_read_only["smit_" + iNumLinha] = "on";
    ajax_read_only["memo_" + iNumLinha] = "on";
<?php
}
?>
  }
  function ajax_destroy_tables(iNumLinha)
  {
    ajax_error_list["invoice_" + iNumLinha] = null;
    ajax_error_list["item_" + iNumLinha] = null;
    ajax_error_list["date_" + iNumLinha] = null;
    ajax_error_list["bcode_" + iNumLinha] = null;
    ajax_error_list["lin_" + iNumLinha] = null;
    ajax_error_list["sq_" + iNumLinha] = null;
    ajax_error_list["style_" + iNumLinha] = null;
    ajax_error_list["width_" + iNumLinha] = null;
    ajax_error_list["color_" + iNumLinha] = null;
    ajax_error_list["cust_order_" + iNumLinha] = null;
    ajax_error_list["our_order_" + iNumLinha] = null;
    ajax_error_list["price_" + iNumLinha] = null;
    ajax_error_list["unit_" + iNumLinha] = null;
    ajax_error_list["amount_" + iNumLinha] = null;
    ajax_error_list["descrip_" + iNumLinha] = null;
    ajax_error_list["dye_order_" + iNumLinha] = null;
    ajax_error_list["dye_lot_" + iNumLinha] = null;
    ajax_error_list["cases_" + iNumLinha] = null;
    ajax_error_list["cost_" + iNumLinha] = null;
    ajax_error_list["cost_yd_" + iNumLinha] = null;
    ajax_error_list["gp_" + iNumLinha] = null;
    ajax_error_list["gp_yd_" + iNumLinha] = null;
    ajax_error_list["pc_" + iNumLinha] = null;
    ajax_error_list["adate_" + iNumLinha] = null;
    ajax_error_list["edate_" + iNumLinha] = null;
    ajax_error_list["smit_" + iNumLinha] = null;
    ajax_error_list["memo_" + iNumLinha] = null;
  }

  var ajax_error_geral = "";

  var ajax_error_type = new Array("valid", "onblur", "onchange", "onclick", "onfocus");

  var ajax_field_list = new Array();
  var ajax_field_Dt_Hr = new Array();
  iTotCampos = 0;
  iTotDt_Hr  = 0;

  var ajax_block_list = new Array();
  ajax_block_list[0] = "0";

  var ajax_error_list = {};
  var ajax_error_timeout = 5;

  var ajax_block_id = {
    "0": "hidden_bloco_0"
  };

  var ajax_block_tab = {
    "hidden_bloco_0": ""
  };

  var ajax_field_mult = {
    "invoice_": new Array(),
    "item_": new Array(),
    "date_": new Array(),
    "bcode_": new Array(),
    "lin_": new Array(),
    "sq_": new Array(),
    "style_": new Array(),
    "width_": new Array(),
    "color_": new Array(),
    "cust_order_": new Array(),
    "our_order_": new Array(),
    "price_": new Array(),
    "unit_": new Array(),
    "amount_": new Array(),
    "descrip_": new Array(),
    "dye_order_": new Array(),
    "dye_lot_": new Array(),
    "cases_": new Array(),
    "cost_": new Array(),
    "cost_yd_": new Array(),
    "gp_": new Array(),
    "gp_yd_": new Array(),
    "pc_": new Array(),
    "adate_": new Array(),
    "edate_": new Array(),
    "smit_": new Array(),
    "memo_": new Array()
  };

  var ajax_field_id = {};

  var ajax_read_only = {};

  var ajax_error_count = {};

  var Lim_linhas = <?php echo $sc_seq_vert ?>;
  for (iNumLinha = 1; iNumLinha < Lim_linhas; iNumLinha++)
  {
     ajax_create_tables(iNumLinha);
  }

  function scRemoveErrors()
  {
    for (iNumLinha = 1; iNumLinha < Lim_linhas; iNumLinha++)
    {
      ajax_error_list["invoice_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["invoice_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["invoice_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["invoice_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["invoice_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["item_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["item_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["item_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["item_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["item_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["date_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["date_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["date_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["date_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["date_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["bcode_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["bcode_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["bcode_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["bcode_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["bcode_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["lin_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["lin_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["lin_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["lin_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["lin_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["sq_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["sq_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["sq_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["sq_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["sq_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["style_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["style_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["style_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["style_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["style_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["width_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["width_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["width_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["width_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["width_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["color_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["color_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["color_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["color_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["color_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["cust_order_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["cust_order_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["cust_order_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["cust_order_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["cust_order_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["our_order_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["our_order_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["our_order_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["our_order_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["our_order_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["price_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["price_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["price_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["price_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["price_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["unit_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["unit_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["unit_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["unit_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["unit_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["amount_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["amount_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["amount_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["amount_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["amount_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["descrip_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["descrip_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["descrip_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["descrip_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["descrip_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["dye_order_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["dye_order_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["dye_order_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["dye_order_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["dye_order_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["dye_lot_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["dye_lot_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["dye_lot_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["dye_lot_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["dye_lot_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["cases_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["cases_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["cases_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["cases_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["cases_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["cost_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["cost_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["cost_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["cost_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["cost_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["cost_yd_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["cost_yd_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["cost_yd_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["cost_yd_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["cost_yd_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["gp_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["gp_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["gp_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["gp_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["gp_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["gp_yd_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["gp_yd_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["gp_yd_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["gp_yd_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["gp_yd_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["pc_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["pc_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["pc_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["pc_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["pc_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["adate_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["adate_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["adate_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["adate_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["adate_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["edate_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["edate_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["edate_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["edate_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["edate_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["smit_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["smit_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["smit_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["smit_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["smit_" + iNumLinha]["onfocus"] = new Array();
      ajax_error_list["memo_" + iNumLinha]["valid"] = new Array();
      ajax_error_list["memo_" + iNumLinha]["onblur"] = new Array();
      ajax_error_list["memo_" + iNumLinha]["onchange"] = new Array();
      ajax_error_list["memo_" + iNumLinha]["onclick"] = new Array();
      ajax_error_list["memo_" + iNumLinha]["onfocus"] = new Array();
    }
  }

  function mdOpenLine(iSeq)
  {
    if (document.getElementById("sc_open_line_" + iSeq))
    {
      document.getElementById("sc_open_line_" + iSeq).style.display = "none";
    }
<?php
    if ($this->nmgp_botoes['delete'] == 'on')
    {
?>
    if (document.getElementById("sc_exc_line_" + iSeq))
    {
      document.getElementById("sc_exc_line_" + iSeq).style.display = "none";
    }
<?php
    }
?>
    if (document.getElementById("sc_upd_line_" + iSeq))
    {
      document.getElementById("sc_upd_line_" + iSeq).style.display = "";
    }
    if (document.getElementById("sc_cancelu_line_" + iSeq))
    {
      document.getElementById("sc_cancelu_line_" + iSeq).style.display = "";
    }
    mdOpenObjects(iSeq);
  }

  function mdOpenObjects(iSeq)
  {
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['invoice_'])) ? $this->nmgp_cmp_readonly['invoice_'] : 'off';
?>
    scAjaxFieldRead("invoice_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['item_'])) ? $this->nmgp_cmp_readonly['item_'] : 'off';
?>
    scAjaxFieldRead("item_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['date_'])) ? $this->nmgp_cmp_readonly['date_'] : 'off';
?>
    scAjaxFieldRead("date_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['bcode_'])) ? $this->nmgp_cmp_readonly['bcode_'] : 'off';
?>
    scAjaxFieldRead("bcode_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['lin_'])) ? $this->nmgp_cmp_readonly['lin_'] : 'off';
?>
    scAjaxFieldRead("lin_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['sq_'])) ? $this->nmgp_cmp_readonly['sq_'] : 'off';
?>
    scAjaxFieldRead("sq_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['style_'])) ? $this->nmgp_cmp_readonly['style_'] : 'off';
?>
    scAjaxFieldRead("style_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['width_'])) ? $this->nmgp_cmp_readonly['width_'] : 'off';
?>
    scAjaxFieldRead("width_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['color_'])) ? $this->nmgp_cmp_readonly['color_'] : 'off';
?>
    scAjaxFieldRead("color_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['cust_order_'])) ? $this->nmgp_cmp_readonly['cust_order_'] : 'off';
?>
    scAjaxFieldRead("cust_order_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['our_order_'])) ? $this->nmgp_cmp_readonly['our_order_'] : 'off';
?>
    scAjaxFieldRead("our_order_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['price_'])) ? $this->nmgp_cmp_readonly['price_'] : 'off';
?>
    scAjaxFieldRead("price_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['unit_'])) ? $this->nmgp_cmp_readonly['unit_'] : 'off';
?>
    scAjaxFieldRead("unit_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['amount_'])) ? $this->nmgp_cmp_readonly['amount_'] : 'off';
?>
    scAjaxFieldRead("amount_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['descrip_'])) ? $this->nmgp_cmp_readonly['descrip_'] : 'off';
?>
    scAjaxFieldRead("descrip_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['dye_order_'])) ? $this->nmgp_cmp_readonly['dye_order_'] : 'off';
?>
    scAjaxFieldRead("dye_order_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['dye_lot_'])) ? $this->nmgp_cmp_readonly['dye_lot_'] : 'off';
?>
    scAjaxFieldRead("dye_lot_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['cases_'])) ? $this->nmgp_cmp_readonly['cases_'] : 'off';
?>
    scAjaxFieldRead("cases_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['cost_'])) ? $this->nmgp_cmp_readonly['cost_'] : 'off';
?>
    scAjaxFieldRead("cost_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['cost_yd_'])) ? $this->nmgp_cmp_readonly['cost_yd_'] : 'off';
?>
    scAjaxFieldRead("cost_yd_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['gp_'])) ? $this->nmgp_cmp_readonly['gp_'] : 'off';
?>
    scAjaxFieldRead("gp_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['gp_yd_'])) ? $this->nmgp_cmp_readonly['gp_yd_'] : 'off';
?>
    scAjaxFieldRead("gp_yd_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['pc_'])) ? $this->nmgp_cmp_readonly['pc_'] : 'off';
?>
    scAjaxFieldRead("pc_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['adate_'])) ? $this->nmgp_cmp_readonly['adate_'] : 'off';
?>
    scAjaxFieldRead("adate_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['edate_'])) ? $this->nmgp_cmp_readonly['edate_'] : 'off';
?>
    scAjaxFieldRead("edate_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['smit_'])) ? $this->nmgp_cmp_readonly['smit_'] : 'off';
?>
    scAjaxFieldRead("smit_" + iSeq, "<?php echo $NM_contr_readonly ?>");
<?php
  $NM_contr_readonly = (isset($this->nmgp_cmp_readonly['memo_'])) ? $this->nmgp_cmp_readonly['memo_'] : 'off';
?>
    scAjaxFieldRead("memo_" + iSeq, "<?php echo $NM_contr_readonly ?>");
  }

  function mdCloseObjects(iSeq)
  {
    scAjaxFieldRead("invoice_" + iSeq, "on");
    scAjaxFieldRead("item_" + iSeq, "on");
    scAjaxFieldRead("date_" + iSeq, "on");
    scAjaxFieldRead("bcode_" + iSeq, "on");
    scAjaxFieldRead("lin_" + iSeq, "on");
    scAjaxFieldRead("sq_" + iSeq, "on");
    scAjaxFieldRead("style_" + iSeq, "on");
    scAjaxFieldRead("width_" + iSeq, "on");
    scAjaxFieldRead("color_" + iSeq, "on");
    scAjaxFieldRead("cust_order_" + iSeq, "on");
    scAjaxFieldRead("our_order_" + iSeq, "on");
    scAjaxFieldRead("price_" + iSeq, "on");
    scAjaxFieldRead("unit_" + iSeq, "on");
    scAjaxFieldRead("amount_" + iSeq, "on");
    scAjaxFieldRead("descrip_" + iSeq, "on");
    scAjaxFieldRead("dye_order_" + iSeq, "on");
    scAjaxFieldRead("dye_lot_" + iSeq, "on");
    scAjaxFieldRead("cases_" + iSeq, "on");
    scAjaxFieldRead("cost_" + iSeq, "on");
    scAjaxFieldRead("cost_yd_" + iSeq, "on");
    scAjaxFieldRead("gp_" + iSeq, "on");
    scAjaxFieldRead("gp_yd_" + iSeq, "on");
    scAjaxFieldRead("pc_" + iSeq, "on");
    scAjaxFieldRead("adate_" + iSeq, "on");
    scAjaxFieldRead("edate_" + iSeq, "on");
    scAjaxFieldRead("smit_" + iSeq, "on");
    scAjaxFieldRead("memo_" + iSeq, "on");
  }

  function mdCloseLine()
  {
    if (!oResp["closeLine"] || "" == oResp["closeLine"])
    {
      return;
    }
<?php
    if ($this->nmgp_botoes['update'] == 'on')
    {
?>
    if (document.getElementById("sc_open_line_" + oResp["closeLine"]))
    {
      document.getElementById("sc_open_line_" + oResp["closeLine"]).style.display = "";
    }
<?php
    }
?>
    if (document.getElementById("sc_upd_line_" + oResp["closeLine"]))
    {
      document.getElementById("sc_upd_line_" + oResp["closeLine"]).style.display = "none";
    }
  }

  var sc_open_lines = 0;
  var orig_Nav_permite_ret = "";
  var orig_Nav_permite_ava = "";
  function scDisableNavigation()
  {
    if (0 == sc_open_lines)
    {
      orig_Nav_permite_ret = Nav_permite_ret;
      orig_Nav_permite_ava = Nav_permite_ava;
      Nav_permite_ret = "N";
      Nav_permite_ava = "N";
      nav_atualiza(Nav_permite_ret, Nav_permite_ava, 't');
      nav_atualiza(Nav_permite_ret, Nav_permite_ava, 'b');
    }
    sc_open_lines++;
  }

  function scEnableNavigation()
  {
    sc_open_lines--;
    if (0 == sc_open_lines)
    {
      Nav_permite_ret = orig_Nav_permite_ret;
      Nav_permite_ava = orig_Nav_permite_ava;
      nav_atualiza(Nav_permite_ret, Nav_permite_ava, 't');
      nav_atualiza(Nav_permite_ret, Nav_permite_ava, 'b');
    }
  }

  function scErrorLineOn(iRow, sIdError)
  {
    var bErrorRow = false;
    if ("__sc_all__" == sIdError)
    {
      bErrorRow = true;
    }
    else if (ajax_error_count[sIdError + iRow])
    {
      ajax_error_count[sIdError + iRow] = "on";
    }
    if (bErrorRow || ("on" == ajax_error_count["invoice_" + iRow] || "on" == ajax_error_count["item_" + iRow] || "on" == ajax_error_count["date_" + iRow] || "on" == ajax_error_count["bcode_" + iRow] || "on" == ajax_error_count["lin_" + iRow] || "on" == ajax_error_count["sq_" + iRow] || "on" == ajax_error_count["style_" + iRow] || "on" == ajax_error_count["width_" + iRow] || "on" == ajax_error_count["color_" + iRow] || "on" == ajax_error_count["cust_order_" + iRow] || "on" == ajax_error_count["our_order_" + iRow] || "on" == ajax_error_count["price_" + iRow] || "on" == ajax_error_count["unit_" + iRow] || "on" == ajax_error_count["amount_" + iRow] || "on" == ajax_error_count["descrip_" + iRow] || "on" == ajax_error_count["dye_order_" + iRow] || "on" == ajax_error_count["dye_lot_" + iRow] || "on" == ajax_error_count["cases_" + iRow] || "on" == ajax_error_count["cost_" + iRow] || "on" == ajax_error_count["cost_yd_" + iRow] || "on" == ajax_error_count["gp_" + iRow] || "on" == ajax_error_count["gp_yd_" + iRow] || "on" == ajax_error_count["pc_" + iRow] || "on" == ajax_error_count["adate_" + iRow] || "on" == ajax_error_count["edate_" + iRow] || "on" == ajax_error_count["smit_" + iRow] || "on" == ajax_error_count["memo_" + iRow]))
    {
      if (document.getElementById("hidden_field_data_sc_seq" + iRow))
        document.getElementById("hidden_field_data_sc_seq" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_sc_actions" + iRow))
        document.getElementById("hidden_field_data_sc_actions" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_invoice_" + iRow))
        document.getElementById("hidden_field_data_invoice_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_item_" + iRow))
        document.getElementById("hidden_field_data_item_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_date_" + iRow))
        document.getElementById("hidden_field_data_date_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_bcode_" + iRow))
        document.getElementById("hidden_field_data_bcode_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_lin_" + iRow))
        document.getElementById("hidden_field_data_lin_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_sq_" + iRow))
        document.getElementById("hidden_field_data_sq_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_style_" + iRow))
        document.getElementById("hidden_field_data_style_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_width_" + iRow))
        document.getElementById("hidden_field_data_width_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_color_" + iRow))
        document.getElementById("hidden_field_data_color_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_cust_order_" + iRow))
        document.getElementById("hidden_field_data_cust_order_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_our_order_" + iRow))
        document.getElementById("hidden_field_data_our_order_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_price_" + iRow))
        document.getElementById("hidden_field_data_price_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_unit_" + iRow))
        document.getElementById("hidden_field_data_unit_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_amount_" + iRow))
        document.getElementById("hidden_field_data_amount_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_descrip_" + iRow))
        document.getElementById("hidden_field_data_descrip_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_dye_order_" + iRow))
        document.getElementById("hidden_field_data_dye_order_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_dye_lot_" + iRow))
        document.getElementById("hidden_field_data_dye_lot_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_cases_" + iRow))
        document.getElementById("hidden_field_data_cases_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_cost_" + iRow))
        document.getElementById("hidden_field_data_cost_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_cost_yd_" + iRow))
        document.getElementById("hidden_field_data_cost_yd_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_gp_" + iRow))
        document.getElementById("hidden_field_data_gp_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_gp_yd_" + iRow))
        document.getElementById("hidden_field_data_gp_yd_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_pc_" + iRow))
        document.getElementById("hidden_field_data_pc_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_adate_" + iRow))
        document.getElementById("hidden_field_data_adate_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_edate_" + iRow))
        document.getElementById("hidden_field_data_edate_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_smit_" + iRow))
        document.getElementById("hidden_field_data_smit_" + iRow).className = "scFormErrorLine";
      if (document.getElementById("hidden_field_data_memo_" + iRow))
        document.getElementById("hidden_field_data_memo_" + iRow).className = "scFormErrorLine";
    }
  }

  function scErrorLineOff(iRow, sIdError)
  {
    var bErrorRow = false;
    if ("__sc_all__" == sIdError)
    {
      bErrorRow = true;
    }
    else if (ajax_error_count[sIdError + iRow])
    {
      ajax_error_count[sIdError + iRow] = "off";
    }
    if (bErrorRow || ("off" == ajax_error_count["invoice_" + iRow] && "off" == ajax_error_count["item_" + iRow] && "off" == ajax_error_count["date_" + iRow] && "off" == ajax_error_count["bcode_" + iRow] && "off" == ajax_error_count["lin_" + iRow] && "off" == ajax_error_count["sq_" + iRow] && "off" == ajax_error_count["style_" + iRow] && "off" == ajax_error_count["width_" + iRow] && "off" == ajax_error_count["color_" + iRow] && "off" == ajax_error_count["cust_order_" + iRow] && "off" == ajax_error_count["our_order_" + iRow] && "off" == ajax_error_count["price_" + iRow] && "off" == ajax_error_count["unit_" + iRow] && "off" == ajax_error_count["amount_" + iRow] && "off" == ajax_error_count["descrip_" + iRow] && "off" == ajax_error_count["dye_order_" + iRow] && "off" == ajax_error_count["dye_lot_" + iRow] && "off" == ajax_error_count["cases_" + iRow] && "off" == ajax_error_count["cost_" + iRow] && "off" == ajax_error_count["cost_yd_" + iRow] && "off" == ajax_error_count["gp_" + iRow] && "off" == ajax_error_count["gp_yd_" + iRow] && "off" == ajax_error_count["pc_" + iRow] && "off" == ajax_error_count["adate_" + iRow] && "off" == ajax_error_count["edate_" + iRow] && "off" == ajax_error_count["smit_" + iRow] && "off" == ajax_error_count["memo_" + iRow]))
    {
      if (bErrorRow)
      {
        ajax_error_count["invoice_" + iRow] = "off";
        ajax_error_count["item_" + iRow] = "off";
        ajax_error_count["date_" + iRow] = "off";
        ajax_error_count["bcode_" + iRow] = "off";
        ajax_error_count["lin_" + iRow] = "off";
        ajax_error_count["sq_" + iRow] = "off";
        ajax_error_count["style_" + iRow] = "off";
        ajax_error_count["width_" + iRow] = "off";
        ajax_error_count["color_" + iRow] = "off";
        ajax_error_count["cust_order_" + iRow] = "off";
        ajax_error_count["our_order_" + iRow] = "off";
        ajax_error_count["price_" + iRow] = "off";
        ajax_error_count["unit_" + iRow] = "off";
        ajax_error_count["amount_" + iRow] = "off";
        ajax_error_count["descrip_" + iRow] = "off";
        ajax_error_count["dye_order_" + iRow] = "off";
        ajax_error_count["dye_lot_" + iRow] = "off";
        ajax_error_count["cases_" + iRow] = "off";
        ajax_error_count["cost_" + iRow] = "off";
        ajax_error_count["cost_yd_" + iRow] = "off";
        ajax_error_count["gp_" + iRow] = "off";
        ajax_error_count["gp_yd_" + iRow] = "off";
        ajax_error_count["pc_" + iRow] = "off";
        ajax_error_count["adate_" + iRow] = "off";
        ajax_error_count["edate_" + iRow] = "off";
        ajax_error_count["smit_" + iRow] = "off";
        ajax_error_count["memo_" + iRow] = "off";
      }
      var sCssLine = scErrorLineCss(iRow);
      if (document.getElementById("hidden_field_data_sc_seq" + iRow))
        document.getElementById("hidden_field_data_sc_seq" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_sc_actions" + iRow))
        document.getElementById("hidden_field_data_sc_actions" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_invoice_" + iRow))
        document.getElementById("hidden_field_data_invoice_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_item_" + iRow))
        document.getElementById("hidden_field_data_item_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_date_" + iRow))
        document.getElementById("hidden_field_data_date_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_bcode_" + iRow))
        document.getElementById("hidden_field_data_bcode_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_lin_" + iRow))
        document.getElementById("hidden_field_data_lin_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_sq_" + iRow))
        document.getElementById("hidden_field_data_sq_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_style_" + iRow))
        document.getElementById("hidden_field_data_style_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_width_" + iRow))
        document.getElementById("hidden_field_data_width_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_color_" + iRow))
        document.getElementById("hidden_field_data_color_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_cust_order_" + iRow))
        document.getElementById("hidden_field_data_cust_order_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_our_order_" + iRow))
        document.getElementById("hidden_field_data_our_order_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_price_" + iRow))
        document.getElementById("hidden_field_data_price_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_unit_" + iRow))
        document.getElementById("hidden_field_data_unit_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_amount_" + iRow))
        document.getElementById("hidden_field_data_amount_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_descrip_" + iRow))
        document.getElementById("hidden_field_data_descrip_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_dye_order_" + iRow))
        document.getElementById("hidden_field_data_dye_order_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_dye_lot_" + iRow))
        document.getElementById("hidden_field_data_dye_lot_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_cases_" + iRow))
        document.getElementById("hidden_field_data_cases_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_cost_" + iRow))
        document.getElementById("hidden_field_data_cost_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_cost_yd_" + iRow))
        document.getElementById("hidden_field_data_cost_yd_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_gp_" + iRow))
        document.getElementById("hidden_field_data_gp_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_gp_yd_" + iRow))
        document.getElementById("hidden_field_data_gp_yd_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_pc_" + iRow))
        document.getElementById("hidden_field_data_pc_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_adate_" + iRow))
        document.getElementById("hidden_field_data_adate_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_edate_" + iRow))
        document.getElementById("hidden_field_data_edate_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_smit_" + iRow))
        document.getElementById("hidden_field_data_smit_" + iRow).className = sCssLine;
      if (document.getElementById("hidden_field_data_memo_" + iRow))
        document.getElementById("hidden_field_data_memo_" + iRow).className = sCssLine;
    }
  }

  function scErrorLineReset()
  {
    for (iLineReset = 0; iLineReset < iAjaxNewLine; iLineReset++)
    {
      scErrorLineOff(iLineReset, "__sc_all__");
    }
  }

  function scErrorLineCss(iRow)
  {
    return "scFormDataOddMult";
  }
  var bRefreshTable = false;
  function scRefreshTable()
  {
    if (bRefreshTable || document.F2.nmgp_opcao.value == "fast_search")
    {
      do_ajax_billing_item_edit_grid_table_refresh();
      bRefreshTable = false;
      return true;
    }
    return false;
  }

  function scAjaxDetailValue(sIndex, sValue)
  {
    var aValue = new Array();
    aValue[0] = {"value" : sValue};
    if ("invoice_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("item_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("date_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("bcode_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("lin_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("sq_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("style_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("width_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("color_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("cust_order_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("our_order_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("price_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("unit_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("amount_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("descrip_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("dye_order_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("dye_lot_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("cases_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("cost_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("cost_yd_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("gp_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("gp_yd_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("pc_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("adate_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("edate_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("smit_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    if ("memo_" == sIndex)
    {
      scAjaxSetFieldText(sIndex, aValue);
      updateHeaderFooter(sIndex, aValue);
      return;
    }
    scAjaxSetFieldInnerHtml(sIndex, aValue);
  }
 </SCRIPT>
