<?php
//
class custbill_form_apl
{
   var $NM_is_redirected = false;
   var $NM_non_ajax_info = false;
   var $NM_ajax_flag    = false;
   var $NM_ajax_opcao   = '';
   var $NM_ajax_retorno = '';
   var $NM_ajax_info    = array('result'         => '',
                                'param'          => array(),
                                'autoComp'       => '',
                                'rsSize'         => '',
                                'msgDisplay'     => '',
                                'errList'        => array(),
                                'fldList'        => array(),
                                'focus'          => '',
                                'navStatus'      => array(),
                                'navSummary'     => array(),
                                'navPage'        => array(),
                                'redir'          => array(),
                                'blockDisplay'   => array(),
                                'fieldDisplay'   => array(),
                                'fieldLabel'     => array(),
                                'readOnly'       => array(),
                                'btnVars'        => array(),
                                'ajaxAlert'      => '',
                                'ajaxMessage'    => '',
                                'ajaxJavascript' => array(),
                                'buttonDisplay'  => array(),
                                'calendarReload' => false,
                                'quickSearchRes' => false,
                                'displayMsg'     => false,
                                'displayMsgTxt'  => '',
                               );
   var $Nav_permite_ava = true;
   var $Nav_permite_ret = true;
   var $Apl_com_erro    = false;
   var $Ini;
   var $Erro;
   var $Db;
   var $bcode;
   var $status;
   var $name;
   var $number;
   var $prefix;
   var $address1;
   var $address2;
   var $city;
   var $state;
   var $country;
   var $zip_code;
   var $salesman;
   var $email;
   var $cat1;
   var $cat2;
   var $cat3;
   var $cat4;
   var $cat5;
   var $cat6;
   var $cat7;
   var $terms;
   var $phone;
   var $added;
   var $contact;
   var $tdate;
   var $memo;
   var $att;
   var $cphone1;
   var $cphone2;
   var $contact2;
   var $cemail1;
   var $cemail2;
   var $fax;
   var $cfax1;
   var $cfax2;
   var $mtd;
   var $ytd;
   var $qtd;
   var $jan;
   var $feb;
   var $mar;
   var $apr;
   var $may;
   var $jun;
   var $jul;
   var $aug;
   var $sep;
   var $oct;
   var $nov;
   var $dec;
   var $lyear;
   var $llyear;
   var $q1;
   var $q2;
   var $q3;
   var $q4;
   var $updated;
   var $s365;
   var $temp;
   var $custship;
   var $billing;
   var $orders;
   var $quotes;
   var $nm_data;
   var $nmgp_opcao;
   var $nmgp_opc_ant;
   var $sc_evento;
   var $sc_insert_on;
   var $nmgp_clone;
   var $nmgp_return_img = array();
   var $nmgp_dados_form = array();
   var $nmgp_dados_select = array();
   var $nm_location;
   var $nm_flag_iframe;
   var $nm_flag_saida_novo;
   var $nmgp_botoes = array();
   var $nmgp_url_saida;
   var $nmgp_form_show;
   var $nmgp_form_empty;
   var $nmgp_cmp_readonly = array();
   var $nmgp_cmp_hidden = array();
   var $form_paginacao = 'parcial';
   var $lig_edit_lookup      = false;
   var $lig_edit_lookup_call = false;
   var $lig_edit_lookup_cb   = '';
   var $lig_edit_lookup_row  = '';
   var $is_calendar_app = false;
   var $Embutida_call  = false;
   var $Embutida_ronly = false;
   var $Embutida_proc  = false;
   var $Embutida_form  = false;
   var $Grid_editavel  = false;
   var $url_webhelp = '';
   var $nm_todas_criticas;
   var $Campos_Mens_erro;
   var $nm_new_label = array();
//
//----- 
   function ini_controle()
   {
        global $nm_url_saida, $teste_validade, $script_case_init, 
               $glo_senha_protect, $nm_apl_dependente, $nm_form_submit, $sc_check_excl, $nm_opc_form_php, $nm_call_php, $nm_opc_lookup;


      if ($this->NM_ajax_flag)
      {
          if (isset($this->NM_ajax_info['param']['address1']))
          {
              $this->address1 = $this->NM_ajax_info['param']['address1'];
          }
          if (isset($this->NM_ajax_info['param']['address2']))
          {
              $this->address2 = $this->NM_ajax_info['param']['address2'];
          }
          if (isset($this->NM_ajax_info['param']['apr']))
          {
              $this->apr = $this->NM_ajax_info['param']['apr'];
          }
          if (isset($this->NM_ajax_info['param']['att']))
          {
              $this->att = $this->NM_ajax_info['param']['att'];
          }
          if (isset($this->NM_ajax_info['param']['aug']))
          {
              $this->aug = $this->NM_ajax_info['param']['aug'];
          }
          if (isset($this->NM_ajax_info['param']['bcode']))
          {
              $this->bcode = $this->NM_ajax_info['param']['bcode'];
          }
          if (isset($this->NM_ajax_info['param']['billing']))
          {
              $this->billing = $this->NM_ajax_info['param']['billing'];
          }
          if (isset($this->NM_ajax_info['param']['cat1']))
          {
              $this->cat1 = $this->NM_ajax_info['param']['cat1'];
          }
          if (isset($this->NM_ajax_info['param']['cat2']))
          {
              $this->cat2 = $this->NM_ajax_info['param']['cat2'];
          }
          if (isset($this->NM_ajax_info['param']['cat3']))
          {
              $this->cat3 = $this->NM_ajax_info['param']['cat3'];
          }
          if (isset($this->NM_ajax_info['param']['cat4']))
          {
              $this->cat4 = $this->NM_ajax_info['param']['cat4'];
          }
          if (isset($this->NM_ajax_info['param']['cat5']))
          {
              $this->cat5 = $this->NM_ajax_info['param']['cat5'];
          }
          if (isset($this->NM_ajax_info['param']['cat6']))
          {
              $this->cat6 = $this->NM_ajax_info['param']['cat6'];
          }
          if (isset($this->NM_ajax_info['param']['cat7']))
          {
              $this->cat7 = $this->NM_ajax_info['param']['cat7'];
          }
          if (isset($this->NM_ajax_info['param']['cemail1']))
          {
              $this->cemail1 = $this->NM_ajax_info['param']['cemail1'];
          }
          if (isset($this->NM_ajax_info['param']['cemail2']))
          {
              $this->cemail2 = $this->NM_ajax_info['param']['cemail2'];
          }
          if (isset($this->NM_ajax_info['param']['cfax1']))
          {
              $this->cfax1 = $this->NM_ajax_info['param']['cfax1'];
          }
          if (isset($this->NM_ajax_info['param']['cfax2']))
          {
              $this->cfax2 = $this->NM_ajax_info['param']['cfax2'];
          }
          if (isset($this->NM_ajax_info['param']['city']))
          {
              $this->city = $this->NM_ajax_info['param']['city'];
          }
          if (isset($this->NM_ajax_info['param']['contact']))
          {
              $this->contact = $this->NM_ajax_info['param']['contact'];
          }
          if (isset($this->NM_ajax_info['param']['contact2']))
          {
              $this->contact2 = $this->NM_ajax_info['param']['contact2'];
          }
          if (isset($this->NM_ajax_info['param']['country']))
          {
              $this->country = $this->NM_ajax_info['param']['country'];
          }
          if (isset($this->NM_ajax_info['param']['cphone1']))
          {
              $this->cphone1 = $this->NM_ajax_info['param']['cphone1'];
          }
          if (isset($this->NM_ajax_info['param']['cphone2']))
          {
              $this->cphone2 = $this->NM_ajax_info['param']['cphone2'];
          }
          if (isset($this->NM_ajax_info['param']['custship']))
          {
              $this->custship = $this->NM_ajax_info['param']['custship'];
          }
          if (isset($this->NM_ajax_info['param']['dec']))
          {
              $this->dec = $this->NM_ajax_info['param']['dec'];
          }
          if (isset($this->NM_ajax_info['param']['email']))
          {
              $this->email = $this->NM_ajax_info['param']['email'];
          }
          if (isset($this->NM_ajax_info['param']['fax']))
          {
              $this->fax = $this->NM_ajax_info['param']['fax'];
          }
          if (isset($this->NM_ajax_info['param']['feb']))
          {
              $this->feb = $this->NM_ajax_info['param']['feb'];
          }
          if (isset($this->NM_ajax_info['param']['jan']))
          {
              $this->jan = $this->NM_ajax_info['param']['jan'];
          }
          if (isset($this->NM_ajax_info['param']['jul']))
          {
              $this->jul = $this->NM_ajax_info['param']['jul'];
          }
          if (isset($this->NM_ajax_info['param']['jun']))
          {
              $this->jun = $this->NM_ajax_info['param']['jun'];
          }
          if (isset($this->NM_ajax_info['param']['llyear']))
          {
              $this->llyear = $this->NM_ajax_info['param']['llyear'];
          }
          if (isset($this->NM_ajax_info['param']['lyear']))
          {
              $this->lyear = $this->NM_ajax_info['param']['lyear'];
          }
          if (isset($this->NM_ajax_info['param']['mar']))
          {
              $this->mar = $this->NM_ajax_info['param']['mar'];
          }
          if (isset($this->NM_ajax_info['param']['may']))
          {
              $this->may = $this->NM_ajax_info['param']['may'];
          }
          if (isset($this->NM_ajax_info['param']['memo']))
          {
              $this->memo = $this->NM_ajax_info['param']['memo'];
          }
          if (isset($this->NM_ajax_info['param']['mtd']))
          {
              $this->mtd = $this->NM_ajax_info['param']['mtd'];
          }
          if (isset($this->NM_ajax_info['param']['name']))
          {
              $this->name = $this->NM_ajax_info['param']['name'];
          }
          if (isset($this->NM_ajax_info['param']['nm_form_submit']))
          {
              $this->nm_form_submit = $this->NM_ajax_info['param']['nm_form_submit'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_ancora']))
          {
              $this->nmgp_ancora = $this->NM_ajax_info['param']['nmgp_ancora'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_arg_fast_search']))
          {
              $this->nmgp_arg_fast_search = $this->NM_ajax_info['param']['nmgp_arg_fast_search'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_cond_fast_search']))
          {
              $this->nmgp_cond_fast_search = $this->NM_ajax_info['param']['nmgp_cond_fast_search'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_fast_search']))
          {
              $this->nmgp_fast_search = $this->NM_ajax_info['param']['nmgp_fast_search'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_num_form']))
          {
              $this->nmgp_num_form = $this->NM_ajax_info['param']['nmgp_num_form'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_opcao']))
          {
              $this->nmgp_opcao = $this->NM_ajax_info['param']['nmgp_opcao'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_ordem']))
          {
              $this->nmgp_ordem = $this->NM_ajax_info['param']['nmgp_ordem'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_parms']))
          {
              $this->nmgp_parms = $this->NM_ajax_info['param']['nmgp_parms'];
          }
          if (isset($this->NM_ajax_info['param']['nmgp_url_saida']))
          {
              $this->nmgp_url_saida = $this->NM_ajax_info['param']['nmgp_url_saida'];
          }
          if (isset($this->NM_ajax_info['param']['nov']))
          {
              $this->nov = $this->NM_ajax_info['param']['nov'];
          }
          if (isset($this->NM_ajax_info['param']['number']))
          {
              $this->number = $this->NM_ajax_info['param']['number'];
          }
          if (isset($this->NM_ajax_info['param']['oct']))
          {
              $this->oct = $this->NM_ajax_info['param']['oct'];
          }
          if (isset($this->NM_ajax_info['param']['orders']))
          {
              $this->orders = $this->NM_ajax_info['param']['orders'];
          }
          if (isset($this->NM_ajax_info['param']['phone']))
          {
              $this->phone = $this->NM_ajax_info['param']['phone'];
          }
          if (isset($this->NM_ajax_info['param']['prefix']))
          {
              $this->prefix = $this->NM_ajax_info['param']['prefix'];
          }
          if (isset($this->NM_ajax_info['param']['q1']))
          {
              $this->q1 = $this->NM_ajax_info['param']['q1'];
          }
          if (isset($this->NM_ajax_info['param']['q2']))
          {
              $this->q2 = $this->NM_ajax_info['param']['q2'];
          }
          if (isset($this->NM_ajax_info['param']['q3']))
          {
              $this->q3 = $this->NM_ajax_info['param']['q3'];
          }
          if (isset($this->NM_ajax_info['param']['q4']))
          {
              $this->q4 = $this->NM_ajax_info['param']['q4'];
          }
          if (isset($this->NM_ajax_info['param']['qtd']))
          {
              $this->qtd = $this->NM_ajax_info['param']['qtd'];
          }
          if (isset($this->NM_ajax_info['param']['quotes']))
          {
              $this->quotes = $this->NM_ajax_info['param']['quotes'];
          }
          if (isset($this->NM_ajax_info['param']['salesman']))
          {
              $this->salesman = $this->NM_ajax_info['param']['salesman'];
          }
          if (isset($this->NM_ajax_info['param']['script_case_init']))
          {
              $this->script_case_init = $this->NM_ajax_info['param']['script_case_init'];
          }
          if (isset($this->NM_ajax_info['param']['sep']))
          {
              $this->sep = $this->NM_ajax_info['param']['sep'];
          }
          if (isset($this->NM_ajax_info['param']['state']))
          {
              $this->state = $this->NM_ajax_info['param']['state'];
          }
          if (isset($this->NM_ajax_info['param']['status']))
          {
              $this->status = $this->NM_ajax_info['param']['status'];
          }
          if (isset($this->NM_ajax_info['param']['tdate']))
          {
              $this->tdate = $this->NM_ajax_info['param']['tdate'];
          }
          if (isset($this->NM_ajax_info['param']['terms']))
          {
              $this->terms = $this->NM_ajax_info['param']['terms'];
          }
          if (isset($this->NM_ajax_info['param']['updated']))
          {
              $this->updated = $this->NM_ajax_info['param']['updated'];
          }
          if (isset($this->NM_ajax_info['param']['ytd']))
          {
              $this->ytd = $this->NM_ajax_info['param']['ytd'];
          }
          if (isset($this->NM_ajax_info['param']['zip_code']))
          {
              $this->zip_code = $this->NM_ajax_info['param']['zip_code'];
          }
          if (isset($this->nmgp_refresh_fields))
          {
              $this->nmgp_refresh_fields = explode('_#fld#_', $this->nmgp_refresh_fields);
              $this->nmgp_opcao          = 'recarga';
          }
          if (!isset($this->nmgp_refresh_row))
          {
              $this->nmgp_refresh_row = '';
          }
      }

      $this->sc_conv_var = array();
      if (!empty($_FILES))
      {
          foreach ($_FILES as $nmgp_campo => $nmgp_valores)
          {
               if (isset($this->sc_conv_var[$nmgp_campo]))
               {
                   $nmgp_campo = $this->sc_conv_var[$nmgp_campo];
               }
               elseif (isset($this->sc_conv_var[strtolower($nmgp_campo)]))
               {
                   $nmgp_campo = $this->sc_conv_var[strtolower($nmgp_campo)];
               }
               $tmp_scfile_name     = $nmgp_campo . "_scfile_name";
               $tmp_scfile_type     = $nmgp_campo . "_scfile_type";
               $this->$nmgp_campo = is_array($nmgp_valores['tmp_name']) ? $nmgp_valores['tmp_name'][0] : $nmgp_valores['tmp_name'];
               $this->$tmp_scfile_type   = is_array($nmgp_valores['type'])     ? $nmgp_valores['type'][0]     : $nmgp_valores['type'];
               $this->$tmp_scfile_name   = is_array($nmgp_valores['name'])     ? $nmgp_valores['name'][0]     : $nmgp_valores['name'];
          }
      }
      if (!empty($_POST))
      {
          foreach ($_POST as $nmgp_var => $nmgp_val)
          {
               if (isset($this->sc_conv_var[$nmgp_var]))
               {
                   $nmgp_var = $this->sc_conv_var[$nmgp_var];
               }
               elseif (isset($this->sc_conv_var[strtolower($nmgp_var)]))
               {
                   $nmgp_var = $this->sc_conv_var[strtolower($nmgp_var)];
               }
               $this->$nmgp_var = $nmgp_val;
          }
      }
      if (!empty($_GET))
      {
          foreach ($_GET as $nmgp_var => $nmgp_val)
          {
               if (isset($this->sc_conv_var[$nmgp_var]))
               {
                   $nmgp_var = $this->sc_conv_var[$nmgp_var];
               }
               elseif (isset($this->sc_conv_var[strtolower($nmgp_var)]))
               {
                   $nmgp_var = $this->sc_conv_var[strtolower($nmgp_var)];
               }
               $this->$nmgp_var = $nmgp_val;
          }
      }
      if (isset($this->var_bcode) && isset($this->NM_contr_var_session) && $this->NM_contr_var_session == "Yes") 
      {
          $_SESSION['var_bcode'] = $this->var_bcode;
      }
      if (isset($_POST["var_bcode"])) 
      {
          $_SESSION['var_bcode'] = $this->var_bcode;
      }
      if (isset($_GET["var_bcode"])) 
      {
          $_SESSION['var_bcode'] = $this->var_bcode;
      }
      if (isset($_SESSION['sc_session'][$script_case_init]['custbill_form']['embutida_parms']))
      { 
          $this->nmgp_parms = $_SESSION['sc_session'][$script_case_init]['custbill_form']['embutida_parms'];
          unset($_SESSION['sc_session'][$script_case_init]['custbill_form']['embutida_parms']);
      } 
      if (isset($this->nmgp_parms) && !empty($this->nmgp_parms)) 
      { 
          if (isset($_SESSION['nm_aba_bg_color'])) 
          { 
              unset($_SESSION['nm_aba_bg_color']);
          }   
          $nmgp_parms = NM_decode_input($nmgp_parms);
          $nmgp_parms = str_replace("@aspass@", "'", $this->nmgp_parms);
          $nmgp_parms = str_replace("*scout", "?@?", $nmgp_parms);
          $nmgp_parms = str_replace("*scin", "?#?", $nmgp_parms);
          $todo = explode("?@?", $nmgp_parms);
          $ix = 0;
          while (!empty($todo[$ix]))
          {
             $cadapar = explode("?#?", $todo[$ix]);
             if (1 < sizeof($cadapar))
             {
                 if (isset($this->sc_conv_var[$cadapar[0]]))
                 {
                     $cadapar[0] = $this->sc_conv_var[$cadapar[0]];
                 }
                 elseif (isset($this->sc_conv_var[strtolower($cadapar[0])]))
                 {
                     $cadapar[0] = $this->sc_conv_var[strtolower($cadapar[0])];
                 }
                 nm_limpa_str_custbill_form($cadapar[1]);
                 $this->$cadapar[0] = $cadapar[1];
             }
             $ix++;
          }
          if (isset($this->NM_where_filter_form))
          {
              $_SESSION['sc_session'][$script_case_init]['custbill_form']['where_filter_form'] = $this->NM_where_filter_form;
             unset($_SESSION['sc_session'][$script_case_init]['custbill_form']['total']);
          }
          if (isset($this->sc_redir_atualiz))
          {
              $_SESSION['sc_session'][$script_case_init]['custbill_form']['sc_redir_atualiz'] = $this->sc_redir_atualiz;
          }
          if (isset($this->sc_redir_insert))
          {
              $_SESSION['sc_session'][$script_case_init]['custbill_form']['sc_redir_insert'] = $this->sc_redir_insert;
          }
          if (isset($this->var_bcode)) 
          {
              $_SESSION['var_bcode'] = $this->var_bcode;
          }
      } 
      elseif (isset($script_case_init) && !empty($script_case_init) && isset($_SESSION['sc_session'][$script_case_init]['custbill_form']['parms']))
      {
          if ((!isset($this->nmgp_opcao) || ($this->nmgp_opcao != "incluir" && $this->nmgp_opcao != "alterar" && $this->nmgp_opcao != "excluir" && $this->nmgp_opcao != "novo" && $this->nmgp_opcao != "recarga" && $this->nmgp_opcao != "muda_form")) && (!isset($this->NM_ajax_opcao) || $this->NM_ajax_opcao == ""))
          {
              $todo = explode("?@?", $_SESSION['sc_session'][$script_case_init]['custbill_form']['parms']);
              $ix = 0;
              while (!empty($todo[$ix]))
              {
                 $cadapar = explode("?#?", $todo[$ix]);
                 $this->$cadapar[0] = $cadapar[1];
                 $ix++;
              }
          }
      } 

      if (!$this->NM_ajax_flag && 'autocomp_' == substr($this->NM_ajax_opcao, 0, 9))
      {
          $this->NM_ajax_flag = true;
      }

      $dir_raiz          = strrpos($_SERVER['PHP_SELF'],"/") ;  
      $dir_raiz          = substr($_SERVER['PHP_SELF'], 0, $dir_raiz + 1) ;  
      if (isset($this->nm_evt_ret_edit) && '' != $this->nm_evt_ret_edit)
      {
          $_SESSION['sc_session'][$script_case_init]['custbill_form']['lig_edit_lookup']     = true;
          $_SESSION['sc_session'][$script_case_init]['custbill_form']['lig_edit_lookup_cb']  = $this->nm_evt_ret_edit;
          $_SESSION['sc_session'][$script_case_init]['custbill_form']['lig_edit_lookup_row'] = isset($this->nm_evt_ret_row) ? $this->nm_evt_ret_row : '';
      }
      if (isset($_SESSION['sc_session'][$script_case_init]['custbill_form']['lig_edit_lookup']) && $_SESSION['sc_session'][$script_case_init]['custbill_form']['lig_edit_lookup'])
      {
          $this->lig_edit_lookup     = true;
          $this->lig_edit_lookup_cb  = $_SESSION['sc_session'][$script_case_init]['custbill_form']['lig_edit_lookup_cb'];
          $this->lig_edit_lookup_row = $_SESSION['sc_session'][$script_case_init]['custbill_form']['lig_edit_lookup_row'];
      }
      if (!$this->Ini)
      { 
          $this->Ini = new custbill_form_ini(); 
          $this->Ini->init();
      } 
      if (!function_exists("nmButtonOutput"))
      {
          include_once($this->Ini->path_lib_php . "nm_gp_config_btn.php");
      }
      include("../_lib/css/" . $this->Ini->str_schema_all . "_form.php");
      $this->Ini->Str_btn_form    = trim($str_button);
      include($this->Ini->path_btn . $this->Ini->Str_btn_form . '/' . $this->Ini->Str_btn_form . '.php');
      $this->Db = $this->Ini->Db; 
      $this->Ini->Img_sep_form    = "/" . trim($str_toolbar_separator);
      $this->Ini->Color_bg_ajax   = "" == trim($str_ajax_bg)         ? "#000" : $str_ajax_bg;
      $this->Ini->Border_c_ajax   = "" == trim($str_ajax_border_c)   ? ""     : $str_ajax_border_c;
      $this->Ini->Border_s_ajax   = "" == trim($str_ajax_border_s)   ? ""     : $str_ajax_border_s;
      $this->Ini->Border_w_ajax   = "" == trim($str_ajax_border_w)   ? ""     : $str_ajax_border_w;
      $this->Ini->Block_img_exp   = "" == trim($str_block_exp)       ? ""     : $str_block_exp;
      $this->Ini->Block_img_col   = "" == trim($str_block_col)       ? ""     : $str_block_col;
      $this->Ini->Msg_ico_title   = "" == trim($str_msg_ico_title)   ? ""     : $str_msg_ico_title;
      $this->Ini->Msg_ico_body    = "" == trim($str_msg_ico_body)    ? ""     : $str_msg_ico_body;
      $this->Ini->Err_ico_title   = "" == trim($str_err_ico_title)   ? ""     : $str_err_ico_title;
      $this->Ini->Err_ico_body    = "" == trim($str_err_ico_body)    ? ""     : $str_err_ico_body;
      $this->Ini->Cal_ico_back    = "" == trim($str_cal_ico_back)    ? ""     : $str_cal_ico_back;
      $this->Ini->Cal_ico_for     = "" == trim($str_cal_ico_for)     ? ""     : $str_cal_ico_for;
      $this->Ini->Cal_ico_close   = "" == trim($str_cal_ico_close)   ? ""     : $str_cal_ico_close;
      $this->Ini->Tab_space       = "" == trim($str_tab_space)       ? ""     : $str_tab_space;
      $this->Ini->Bubble_tail     = "" == trim($str_bubble_tail)     ? ""     : $str_bubble_tail;
      $this->Ini->Label_sort_pos  = "" == trim($str_label_sort_pos)  ? ""     : $str_label_sort_pos;
      $this->Ini->Label_sort      = "" == trim($str_label_sort)      ? ""     : $str_label_sort;
      $this->Ini->Label_sort_asc  = "" == trim($str_label_sort_asc)  ? ""     : $str_label_sort_asc;
      $this->Ini->Label_sort_desc = "" == trim($str_label_sort_desc) ? ""     : $str_label_sort_desc;
      $this->Ini->Img_status_ok   = "" == trim($str_img_status_ok)   ? ""     : $str_img_status_ok;
      $this->Ini->Img_status_err  = "" == trim($str_img_status_err)  ? ""     : $str_img_status_err;
      $this->Ini->Css_status      = "scFormInputError";
      $this->Ini->Error_icon_span = "" == trim($str_error_icon_span) ? false  : "message" == $str_error_icon_span;
      $this->Ini->Img_qs_search        = "" == trim($img_qs_search)        ? "scriptcase__NM__qs_lupa.png"  : $img_qs_search;
      $this->Ini->Img_qs_clean         = "" == trim($img_qs_clean)         ? "scriptcase__NM__qs_close.png" : $img_qs_clean;
      $this->Ini->Str_qs_image_padding = "" == trim($str_qs_image_padding) ? "0"                            : $str_qs_image_padding;


      $this->arr_buttons['fixdb']['hint']             = "";
      $this->arr_buttons['fixdb']['type']             = "button";
      $this->arr_buttons['fixdb']['value']            = "FixDB";
      $this->arr_buttons['fixdb']['display']          = "only_text";
      $this->arr_buttons['fixdb']['display_position'] = "text_right";
      $this->arr_buttons['fixdb']['style']            = "default";
      $this->arr_buttons['fixdb']['image']            = "";


      $_SESSION['scriptcase']['error_icon']['custbill_form']  = "<img src=\"" . $this->Ini->path_icones . "/scriptcase__NM__icnMensagemAlerta.png\" style=\"border-width: 0px\" align=\"top\">&nbsp;";
      $_SESSION['scriptcase']['error_close']['custbill_form'] = "<td>" . nmButtonOutput($this->arr_buttons, "berrm_clse", "document.getElementById('id_error_display_fixed').style.display = 'none'; document.getElementById('id_error_message_fixed').innerHTML = ''; return false", "document.getElementById('id_error_display_fixed').style.display = 'none'; document.getElementById('id_error_message_fixed').innerHTML = ''; return false", "", "", "", "", "", "", "", $this->Ini->path_botoes, "", "", "", "") . "</td>";

      $this->Embutida_proc = isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_proc']) ? $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_proc'] : $this->Embutida_proc;
      $this->Embutida_form = isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_form']) ? $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_form'] : $this->Embutida_form;
      $this->Embutida_call = isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_call']) ? $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_call'] : $this->Embutida_call;

      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_grid_edit']) && '' != $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_grid_edit'])
      {
          $this->Grid_editavel = ('on' == $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_grid_edit']) ? true : false;
      }
      if (isset($this->Grid_editavel) && $this->Grid_editavel)
      {
          $this->Embutida_form  = true;
          $this->Embutida_ronly = true;
      }
      $this->Embutida_multi = false;
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_multi']) && $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_multi'])
      {
          $this->Grid_editavel  = false;
          $this->Embutida_form  = false;
          $this->Embutida_ronly = false;
          $this->Embutida_multi = true;
      }
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_tp_pag']) && '' != $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_tp_pag'])
      {
          $this->form_paginacao = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_tp_pag'];
      }

      if (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_form']) || '' == $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_form'])
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_form'] = $this->Embutida_form;
      }
      if (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_grid_edit']) || '' == $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_grid_edit'])
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_grid_edit'] = $this->Grid_editavel ? 'on' : 'off';
      }
      if (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_grid_edit']) || '' == $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_grid_edit'])
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_grid_edit'] = $this->Embutida_call;
      }

      $this->Ini->cor_grid_par = $this->Ini->cor_grid_impar;
      $this->nm_location = $this->Ini->sc_protocolo . $this->Ini->server . $dir_raiz; 
      $this->nmgp_url_saida  = $nm_url_saida;
      $this->nmgp_form_show  = "on";
      $this->nmgp_form_empty = false;
      $this->Ini->sc_Include($this->Ini->path_lib_php . "/nm_valida.php", "C", "NM_Valida") ; 
      $teste_validade = new NM_Valida ;

      $this->loadFieldConfig();

      if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['first_time'])
      {
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['insert']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['new']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['update']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['delete']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['first']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['back']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['forward']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['last']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['qsearch']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['summary']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['navpage']);
          unset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['goto']);
      }
      if (isset($this->NM_btn_insert) && '' != $this->NM_btn_insert && (!isset($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['insert']) || '' == $_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['insert']))
      {
          if ('N' == $this->NM_btn_insert)
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['insert'] = 'off';
          }
          else
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['insert'] = 'on';
          }
      }
      if (isset($this->NM_btn_new) && 'N' == $this->NM_btn_new)
      {
          $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['new'] = 'off';
      }
      if (isset($this->NM_btn_update) && '' != $this->NM_btn_update && (!isset($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['update']) || '' == $_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['update']))
      {
          if ('N' == $this->NM_btn_update)
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['update'] = 'off';
          }
          else
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['update'] = 'on';
          }
      }
      if (isset($this->NM_btn_delete) && '' != $this->NM_btn_delete && (!isset($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['delete']) || '' == $_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['delete']))
      {
          if ('N' == $this->NM_btn_delete)
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['delete'] = 'off';
          }
          else
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['delete'] = 'on';
          }
      }
      if (isset($this->NM_btn_navega) && '' != $this->NM_btn_navega)
      {
          if ('N' == $this->NM_btn_navega)
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['first']   = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['back']    = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['forward'] = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['last']    = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['qsearch'] = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['summary'] = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['navpage'] = 'off';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['goto']    = 'off';
          }
          else
          {
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['first']   = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['back']    = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['forward'] = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['last']    = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['qsearch'] = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['summary'] = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['navpage'] = 'on';
              $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['goto']    = 'on';
          }
      }

      $this->nmgp_botoes['exit'] = "on";
      $this->nmgp_botoes['qsearch'] = "on";
      $this->nmgp_botoes['new'] = "on";
      $this->nmgp_botoes['insert'] = "on";
      $this->nmgp_botoes['copy'] = "off";
      $this->nmgp_botoes['update'] = "on";
      $this->nmgp_botoes['delete'] = "on";
      $this->nmgp_botoes['first'] = "on";
      $this->nmgp_botoes['back'] = "on";
      $this->nmgp_botoes['forward'] = "on";
      $this->nmgp_botoes['last'] = "on";
      $this->nmgp_botoes['summary'] = "on";
      $this->nmgp_botoes['navpage'] = "on";
      $this->nmgp_botoes['goto'] = "on";
      $this->nmgp_botoes['qtline'] = "off";
      $this->nmgp_botoes['FixDB'] = "on";
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['iframe_filtro']) && $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['iframe_filtro'] == "S")
      {
          $this->nmgp_botoes['exit'] = "off";
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['btn_display']) && !empty($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['btn_display']))
      {
          foreach ($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['btn_display'] as $NM_cada_btn => $NM_cada_opc)
          {
              $this->nmgp_botoes[$NM_cada_btn] = $NM_cada_opc;
          }
      }

      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['insert']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['insert'] != '')
      {
          $this->nmgp_botoes['new']    = $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['insert'];
          $this->nmgp_botoes['insert'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['insert'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['new']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['new'] != '')
      {
          $this->nmgp_botoes['new']    = $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['new'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['update']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['update'] != '')
      {
          $this->nmgp_botoes['update'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['update'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['delete']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['delete'] != '')
      {
          $this->nmgp_botoes['delete'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['delete'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['first']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['first'] != '')
      {
          $this->nmgp_botoes['first'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['first'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['back']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['back'] != '')
      {
          $this->nmgp_botoes['back'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['back'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['forward']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['forward'] != '')
      {
          $this->nmgp_botoes['forward'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['forward'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['last']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['last'] != '')
      {
          $this->nmgp_botoes['last'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['last'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['qsearch']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['qsearch'] != '')
      {
          $this->nmgp_botoes['qsearch'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['qsearch'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['summary']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['summary'] != '')
      {
          $this->nmgp_botoes['summary'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['summary'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['navpage']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['navpage'] != '')
      {
          $this->nmgp_botoes['navpage'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['navpage'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['goto']) && $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['goto'] != '')
      {
          $this->nmgp_botoes['goto'] = $_SESSION['scriptcase']['sc_apl_conf_lig']['custbill_form']['goto'];
      }

      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_insert']) && $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_insert'] != '')
      {
          $this->nmgp_botoes['new']    = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_insert'];
          $this->nmgp_botoes['insert'] = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_insert'];
      }
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_update']) && $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_update'] != '')
      {
          $this->nmgp_botoes['update'] = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_update'];
      }
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_delete']) && $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_delete'] != '')
      {
          $this->nmgp_botoes['delete'] = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_delete'];
      }
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_btn_nav']) && $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_btn_nav'] != '')
      {
          $this->nmgp_botoes['first']   = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_btn_nav'];
          $this->nmgp_botoes['back']    = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_btn_nav'];
          $this->nmgp_botoes['forward'] = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_btn_nav'];
          $this->nmgp_botoes['last']    = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['embutida_liga_form_btn_nav'];
      }

      if (isset($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['insert']) && $_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['insert'] != '')
      {
          $this->nmgp_botoes['new']    = $_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['insert'];
          $this->nmgp_botoes['insert'] = $_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['insert'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['update']) && $_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['update'] != '')
      {
          $this->nmgp_botoes['update'] = $_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['update'];
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['delete']) && $_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['delete'] != '')
      {
          $this->nmgp_botoes['delete'] = $_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['delete'];
      }

      if (isset($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['field_display']) && !empty($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['field_display']))
      {
          foreach ($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['field_display'] as $NM_cada_field => $NM_cada_opc)
          {
              $this->nmgp_cmp_hidden[$NM_cada_field] = $NM_cada_opc;
              $this->NM_ajax_info['fieldDisplay'][$NM_cada_field] = $NM_cada_opc;
          }
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['field_readonly']) && !empty($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['field_readonly']))
      {
          foreach ($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['field_readonly'] as $NM_cada_field => $NM_cada_opc)
          {
              $this->nmgp_cmp_readonly[$NM_cada_field] = "on";
              $this->NM_ajax_info['readOnly'][$NM_cada_field] = $NM_cada_opc;
          }
      }
      if (isset($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['exit']) && $_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['exit'] != '')
      {
          $_SESSION['scriptcase']['sc_url_saida'][$this->Ini->sc_page] = $_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['exit'];
      }
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['dados_form']))
      {
          $this->nmgp_dados_form = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['dados_form'];
          if (!isset($this->added)){$this->added = $this->nmgp_dados_form['added'];} 
          if (!isset($this->s365)){$this->s365 = $this->nmgp_dados_form['s365'];} 
          if (!isset($this->temp)){$this->temp = $this->nmgp_dados_form['temp'];} 
      }
      $glo_senha_protect = (isset($_SESSION['scriptcase']['glo_senha_protect'])) ? $_SESSION['scriptcase']['glo_senha_protect'] : "S";
      $this->aba_iframe = false;
      if (isset($_SESSION['scriptcase']['sc_aba_iframe']))
      {
          foreach ($_SESSION['scriptcase']['sc_aba_iframe'] as $aba => $apls_aba)
          {
              if (in_array("custbill_form", $apls_aba))
              {
                  $this->aba_iframe = true;
                  break;
              }
          }
      }
      if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['iframe_menu'] && (!isset($_SESSION['scriptcase']['menu_mobile']) || empty($_SESSION['scriptcase']['menu_mobile'])))
      {
          $this->aba_iframe = true;
      }
      $this->Ini->sc_Include($this->Ini->path_lib_php . "/nm_gp_limpa.php", "F", "nm_limpa_valor") ; 
      $this->Ini->sc_Include($this->Ini->path_libs . "/nm_gc.php", "F", "nm_gc") ; 
      $_SESSION['scriptcase']['sc_tab_meses']['int'] = array(
                                      $this->Ini->Nm_lang['lang_mnth_janu'],
                                      $this->Ini->Nm_lang['lang_mnth_febr'],
                                      $this->Ini->Nm_lang['lang_mnth_marc'],
                                      $this->Ini->Nm_lang['lang_mnth_apri'],
                                      $this->Ini->Nm_lang['lang_mnth_mayy'],
                                      $this->Ini->Nm_lang['lang_mnth_june'],
                                      $this->Ini->Nm_lang['lang_mnth_july'],
                                      $this->Ini->Nm_lang['lang_mnth_augu'],
                                      $this->Ini->Nm_lang['lang_mnth_sept'],
                                      $this->Ini->Nm_lang['lang_mnth_octo'],
                                      $this->Ini->Nm_lang['lang_mnth_nove'],
                                      $this->Ini->Nm_lang['lang_mnth_dece']);
      $_SESSION['scriptcase']['sc_tab_meses']['abr'] = array(
                                      $this->Ini->Nm_lang['lang_shrt_mnth_janu'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_febr'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_marc'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_apri'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_mayy'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_june'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_july'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_augu'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_sept'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_octo'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_nove'],
                                      $this->Ini->Nm_lang['lang_shrt_mnth_dece']);
      $_SESSION['scriptcase']['sc_tab_dias']['int'] = array(
                                      $this->Ini->Nm_lang['lang_days_sund'],
                                      $this->Ini->Nm_lang['lang_days_mond'],
                                      $this->Ini->Nm_lang['lang_days_tued'],
                                      $this->Ini->Nm_lang['lang_days_wend'],
                                      $this->Ini->Nm_lang['lang_days_thud'],
                                      $this->Ini->Nm_lang['lang_days_frid'],
                                      $this->Ini->Nm_lang['lang_days_satd']);
      $_SESSION['scriptcase']['sc_tab_dias']['abr'] = array(
                                      $this->Ini->Nm_lang['lang_shrt_days_sund'],
                                      $this->Ini->Nm_lang['lang_shrt_days_mond'],
                                      $this->Ini->Nm_lang['lang_shrt_days_tued'],
                                      $this->Ini->Nm_lang['lang_shrt_days_wend'],
                                      $this->Ini->Nm_lang['lang_shrt_days_thud'],
                                      $this->Ini->Nm_lang['lang_shrt_days_frid'],
                                      $this->Ini->Nm_lang['lang_shrt_days_satd']);
      nm_gc($this->Ini->path_libs);
      $this->Ini->Gd_missing  = true;
      if(function_exists("getProdVersion"))
      {
         $_SESSION['scriptcase']['sc_prod_Version'] = str_replace(".", "", getProdVersion($this->Ini->path_libs));
         if(function_exists("gd_info"))
         {
            $this->Ini->Gd_missing = false;
         }
      }
      $this->Ini->sc_Include($this->Ini->path_lib_php . "/nm_trata_img.php", "C", "nm_trata_img") ; 
      $this->nm_data = new nm_data("en_us");
      if (isset($_GET['nm_cal_display']))
      {
          if ($this->Embutida_proc)
          { 
              include_once($this->Ini->path_embutida . 'custbill_form/custbill_form_calendar.php');
          }
          else
          { 
              include_once($this->Ini->path_aplicacao . 'custbill_form_calendar.php');
          }
          exit;
      }

      if (is_file($this->Ini->path_aplicacao . 'custbill_form_help.txt'))
      {
          $arr_link_webhelp = file($this->Ini->path_aplicacao . 'custbill_form_help.txt');
          if ($arr_link_webhelp)
          {
              foreach ($arr_link_webhelp as $str_link_webhelp)
              {
                  $str_link_webhelp = trim($str_link_webhelp);
                  if ('form:' == substr($str_link_webhelp, 0, 5))
                  {
                      $arr_link_parts = explode(':', $str_link_webhelp);
                      if ('' != $arr_link_parts[1] && is_file($this->Ini->root . $this->Ini->path_help . $arr_link_parts[1]))
                      {
                          $this->url_webhelp = $this->Ini->path_help . $arr_link_parts[1];
                      }
                  }
              }
          }
      }

      if (is_dir($this->Ini->path_aplicacao . 'img'))
      {
          $Res_dir_img = @opendir($this->Ini->path_aplicacao . 'img');
          if ($Res_dir_img)
          {
              while (FALSE !== ($Str_arquivo = @readdir($Res_dir_img))) 
              {
                 if (@is_file($this->Ini->path_aplicacao . 'img/' . $Str_arquivo) && '.' != $Str_arquivo && '..' != $this->Ini->path_aplicacao . 'img/' . $Str_arquivo)
                 {
                     @unlink($this->Ini->path_aplicacao . 'img/' . $Str_arquivo);
                 }
              }
          }
          @closedir($Res_dir_img);
          rmdir($this->Ini->path_aplicacao . 'img');
      }

      if ($this->Embutida_proc)
      { 
          require_once($this->Ini->path_embutida . 'custbill_form/custbill_form_erro.class.php');
      }
      else
      { 
          require_once($this->Ini->path_aplicacao . "custbill_form_erro.class.php"); 
      }
      $this->Erro      = new custbill_form_erro();
      $this->Erro->Ini = $this->Ini;
      $this->proc_fast_search = false;
      if ($this->nmgp_opcao == "fast_search")  
      {
          $this->SC_fast_search($this->nmgp_fast_search, $this->nmgp_cond_fast_search, $this->nmgp_arg_fast_search);
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opcao'] = "inicio";
          $this->nmgp_opcao = "inicio";
          $this->proc_fast_search = true;
      } 
      if ($nm_opc_lookup != "lookup" && $nm_opc_php != "formphp")
      { 
         if (empty($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opcao']))
         { 
             if ($this->bcode != "")   
             { 
                 $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opcao'] = "igual" ;  
             }   
         }   
      } 
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opcao']) && !empty($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opcao']) && empty($this->nmgp_refresh_fields))
      {
          $this->nmgp_opcao = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opcao'];  
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opcao'] = "" ;  
          if ($this->nmgp_opcao == "edit_novo")  
          {
             $this->nmgp_opcao = "novo";
             $this->nm_flag_saida_novo = "S";
          }
      } 
      $this->nm_Start_new = false;
      if (isset($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['start']) && $_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['start'] == 'new')
      {
          $this->nmgp_opcao = "novo";
          $this->nm_Start_new = true;
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opcao'] = "novo";
          unset($_SESSION['scriptcase']['sc_apl_conf']['custbill_form']['start']);
      }
      if ($this->nmgp_opcao == "igual")  
      {
          $this->nmgp_opc_ant = $this->nmgp_opcao;
      } 
      else
      {
          $this->nmgp_opc_ant = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opc_ant'];
      } 
      if ($this->nmgp_opcao == "novo")  
      {
          $this->nmgp_botoes['FixDB'] = "off";
      }
      elseif ($this->nmgp_opcao == "incluir")  
      {
          $this->nmgp_botoes['FixDB'] = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['botoes']['FixDB'];
      }
      if ($this->nmgp_opcao == "recarga" || $this->nmgp_opcao == "muda_form")  
      {
          $this->nmgp_botoes = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['botoes'];
          $this->Nav_permite_ret = 0 != $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['inicio'];
          $this->Nav_permite_ava = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total'] != $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['final'];
      }
      else
      {
      }
      $this->nm_flag_iframe = false;
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['dados_form'])) 
      {
         $this->nmgp_dados_form = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['dados_form'];
      }
      if ($this->nmgp_opcao == "edit_novo")  
      {
          $this->nmgp_opcao = "novo";
          $this->nm_flag_saida_novo = "S";
      }
//
      if ($this->nmgp_opcao == "excluir")
      {
          $GLOBALS['script_case_init'] = $this->Ini->sc_page;
          $_SESSION['sc_session'][$this->Ini->sc_page]['custship_form']['embutida_form'] = false;
          $_SESSION['sc_session'][$this->Ini->sc_page]['custship_form']['embutida_proc'] = true;
          $_SESSION['sc_session'][$this->Ini->sc_page]['custship_form']['reg_start'] = "";
          unset($_SESSION['sc_session'][$this->Ini->sc_page]['custship_form']['total']);
          require_once($this->Ini->root . $this->Ini->path_link  . SC_dir_app_name('custship_form') . "/index.php");
          require_once($this->Ini->root . $this->Ini->path_link  . SC_dir_app_name('custship_form') . "/custship_form_apl.php");
          $this->custship_form = new custship_form_apl;
      }
      $this->sc_evento = $this->nmgp_opcao;
      $this->sc_insert_on = false;
      if (isset($this->bcode)) { $this->nm_limpa_alfa($this->bcode); }
      if (isset($this->status)) { $this->nm_limpa_alfa($this->status); }
      if (isset($this->name)) { $this->nm_limpa_alfa($this->name); }
      if (isset($this->number)) { $this->nm_limpa_alfa($this->number); }
      if (isset($this->prefix)) { $this->nm_limpa_alfa($this->prefix); }
      if (isset($this->address1)) { $this->nm_limpa_alfa($this->address1); }
      if (isset($this->address2)) { $this->nm_limpa_alfa($this->address2); }
      if (isset($this->city)) { $this->nm_limpa_alfa($this->city); }
      if (isset($this->state)) { $this->nm_limpa_alfa($this->state); }
      if (isset($this->country)) { $this->nm_limpa_alfa($this->country); }
      if (isset($this->zip_code)) { $this->nm_limpa_alfa($this->zip_code); }
      if (isset($this->salesman)) { $this->nm_limpa_alfa($this->salesman); }
      if (isset($this->email)) { $this->nm_limpa_alfa($this->email); }
      if (isset($this->cat1)) { $this->nm_limpa_alfa($this->cat1); }
      if (isset($this->cat2)) { $this->nm_limpa_alfa($this->cat2); }
      if (isset($this->cat3)) { $this->nm_limpa_alfa($this->cat3); }
      if (isset($this->cat4)) { $this->nm_limpa_alfa($this->cat4); }
      if (isset($this->cat5)) { $this->nm_limpa_alfa($this->cat5); }
      if (isset($this->cat6)) { $this->nm_limpa_alfa($this->cat6); }
      if (isset($this->cat7)) { $this->nm_limpa_alfa($this->cat7); }
      if (isset($this->terms)) { $this->nm_limpa_alfa($this->terms); }
      if (isset($this->phone)) { $this->nm_limpa_alfa($this->phone); }
      if (isset($this->contact)) { $this->nm_limpa_alfa($this->contact); }
      if (isset($this->memo)) { $this->nm_limpa_alfa($this->memo); }
      if (isset($this->att)) { $this->nm_limpa_alfa($this->att); }
      if (isset($this->cphone1)) { $this->nm_limpa_alfa($this->cphone1); }
      if (isset($this->cphone2)) { $this->nm_limpa_alfa($this->cphone2); }
      if (isset($this->contact2)) { $this->nm_limpa_alfa($this->contact2); }
      if (isset($this->cemail1)) { $this->nm_limpa_alfa($this->cemail1); }
      if (isset($this->cemail2)) { $this->nm_limpa_alfa($this->cemail2); }
      if (isset($this->fax)) { $this->nm_limpa_alfa($this->fax); }
      if (isset($this->cfax1)) { $this->nm_limpa_alfa($this->cfax1); }
      if (isset($this->cfax2)) { $this->nm_limpa_alfa($this->cfax2); }
      if (isset($this->mtd)) { $this->nm_limpa_alfa($this->mtd); }
      if (isset($this->ytd)) { $this->nm_limpa_alfa($this->ytd); }
      if (isset($this->qtd)) { $this->nm_limpa_alfa($this->qtd); }
      if (isset($this->jan)) { $this->nm_limpa_alfa($this->jan); }
      if (isset($this->feb)) { $this->nm_limpa_alfa($this->feb); }
      if (isset($this->mar)) { $this->nm_limpa_alfa($this->mar); }
      if (isset($this->apr)) { $this->nm_limpa_alfa($this->apr); }
      if (isset($this->may)) { $this->nm_limpa_alfa($this->may); }
      if (isset($this->jun)) { $this->nm_limpa_alfa($this->jun); }
      if (isset($this->jul)) { $this->nm_limpa_alfa($this->jul); }
      if (isset($this->aug)) { $this->nm_limpa_alfa($this->aug); }
      if (isset($this->sep)) { $this->nm_limpa_alfa($this->sep); }
      if (isset($this->oct)) { $this->nm_limpa_alfa($this->oct); }
      if (isset($this->nov)) { $this->nm_limpa_alfa($this->nov); }
      if (isset($this->dec)) { $this->nm_limpa_alfa($this->dec); }
      if (isset($this->lyear)) { $this->nm_limpa_alfa($this->lyear); }
      if (isset($this->llyear)) { $this->nm_limpa_alfa($this->llyear); }
      if (isset($this->q1)) { $this->nm_limpa_alfa($this->q1); }
      if (isset($this->q2)) { $this->nm_limpa_alfa($this->q2); }
      if (isset($this->q3)) { $this->nm_limpa_alfa($this->q3); }
      if (isset($this->q4)) { $this->nm_limpa_alfa($this->q4); }
      if (isset($this->custship)) { $this->nm_limpa_alfa($this->custship); }
      if (isset($this->billing)) { $this->nm_limpa_alfa($this->billing); }
      if (isset($this->orders)) { $this->nm_limpa_alfa($this->orders); }
      if (isset($this->quotes)) { $this->nm_limpa_alfa($this->quotes); }
      if ($nm_opc_form_php == "formphp")
      { 
          if ($nm_call_php == "FixDB")
          { 
              $this->sc_btn_FixDB();
          } 
          $this->NM_close_db(); 
          exit;
      } 
      $Campos_Crit       = "";
      $Campos_erro       = "";
      $Campos_Falta      = array();
      $Campos_Erros      = array();
      $dir_raiz          = strrpos($_SERVER['PHP_SELF'],"/") ;  
      $dir_raiz          =  substr($_SERVER['PHP_SELF'], 0, $dir_raiz + 1) ;  
      $this->nm_location = $this->Ini->sc_protocolo . $this->Ini->server . $dir_raiz; 
      $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opc_edit'] = true;  
     if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['dados_select'])) 
     {
        $this->nmgp_dados_select = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['dados_select'];
     }
   }

   function loadFieldConfig()
   {
      $this->field_config = array();
      //-- updated
      $this->field_config['updated']                 = array();
      $this->field_config['updated']['date_format']  = $_SESSION['scriptcase']['reg_conf']['date_format'];
      $this->field_config['updated']['date_sep']     = $_SESSION['scriptcase']['reg_conf']['date_sep'];
      $this->field_config['updated']['date_display'] = "ddmmaaaa";
      $this->new_date_format('DT', 'updated');
      //-- number
      $this->field_config['number']               = array();
      $this->field_config['number']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_num'];
      $this->field_config['number']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['num_group_digit'];
      $this->field_config['number']['symbol_dec'] = '';
      $this->field_config['number']['symbol_neg'] = $_SESSION['scriptcase']['reg_conf']['simb_neg'];
      $this->field_config['number']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['neg_num'];
      //-- tdate
      $this->field_config['tdate']                 = array();
      $this->field_config['tdate']['date_format']  = $_SESSION['scriptcase']['reg_conf']['date_format'];
      $this->field_config['tdate']['date_sep']     = $_SESSION['scriptcase']['reg_conf']['date_sep'];
      $this->field_config['tdate']['date_display'] = "ddmmaaaa";
      $this->new_date_format('DT', 'tdate');
      //-- mtd
      $this->field_config['mtd']               = array();
      $this->field_config['mtd']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['mtd']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['mtd']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['mtd']['symbol_mon'] = '';
      $this->field_config['mtd']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['mtd']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- qtd
      $this->field_config['qtd']               = array();
      $this->field_config['qtd']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['qtd']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['qtd']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['qtd']['symbol_mon'] = '';
      $this->field_config['qtd']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['qtd']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- ytd
      $this->field_config['ytd']               = array();
      $this->field_config['ytd']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['ytd']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['ytd']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['ytd']['symbol_mon'] = '';
      $this->field_config['ytd']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['ytd']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- jan
      $this->field_config['jan']               = array();
      $this->field_config['jan']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['jan']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['jan']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['jan']['symbol_mon'] = '';
      $this->field_config['jan']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['jan']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- feb
      $this->field_config['feb']               = array();
      $this->field_config['feb']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['feb']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['feb']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['feb']['symbol_mon'] = '';
      $this->field_config['feb']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['feb']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- mar
      $this->field_config['mar']               = array();
      $this->field_config['mar']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['mar']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['mar']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['mar']['symbol_mon'] = '';
      $this->field_config['mar']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['mar']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- apr
      $this->field_config['apr']               = array();
      $this->field_config['apr']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['apr']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['apr']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['apr']['symbol_mon'] = '';
      $this->field_config['apr']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['apr']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- may
      $this->field_config['may']               = array();
      $this->field_config['may']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['may']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['may']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['may']['symbol_mon'] = '';
      $this->field_config['may']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['may']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- jun
      $this->field_config['jun']               = array();
      $this->field_config['jun']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['jun']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['jun']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['jun']['symbol_mon'] = '';
      $this->field_config['jun']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['jun']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- jul
      $this->field_config['jul']               = array();
      $this->field_config['jul']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['jul']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['jul']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['jul']['symbol_mon'] = '';
      $this->field_config['jul']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['jul']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- aug
      $this->field_config['aug']               = array();
      $this->field_config['aug']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['aug']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['aug']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['aug']['symbol_mon'] = '';
      $this->field_config['aug']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['aug']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- sep
      $this->field_config['sep']               = array();
      $this->field_config['sep']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['sep']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['sep']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['sep']['symbol_mon'] = '';
      $this->field_config['sep']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['sep']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- oct
      $this->field_config['oct']               = array();
      $this->field_config['oct']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['oct']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['oct']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['oct']['symbol_mon'] = '';
      $this->field_config['oct']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['oct']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- nov
      $this->field_config['nov']               = array();
      $this->field_config['nov']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['nov']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['nov']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['nov']['symbol_mon'] = '';
      $this->field_config['nov']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['nov']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- dec
      $this->field_config['dec']               = array();
      $this->field_config['dec']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['dec']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['dec']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['dec']['symbol_mon'] = '';
      $this->field_config['dec']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['dec']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- lyear
      $this->field_config['lyear']               = array();
      $this->field_config['lyear']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['lyear']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['lyear']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['lyear']['symbol_mon'] = '';
      $this->field_config['lyear']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['lyear']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- llyear
      $this->field_config['llyear']               = array();
      $this->field_config['llyear']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['llyear']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['llyear']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['llyear']['symbol_mon'] = '';
      $this->field_config['llyear']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['llyear']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- q1
      $this->field_config['q1']               = array();
      $this->field_config['q1']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['q1']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['q1']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['q1']['symbol_mon'] = '';
      $this->field_config['q1']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['q1']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- q2
      $this->field_config['q2']               = array();
      $this->field_config['q2']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['q2']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['q2']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['q2']['symbol_mon'] = '';
      $this->field_config['q2']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['q2']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- q4
      $this->field_config['q4']               = array();
      $this->field_config['q4']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['q4']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['q4']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['q4']['symbol_mon'] = '';
      $this->field_config['q4']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['q4']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- q3
      $this->field_config['q3']               = array();
      $this->field_config['q3']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['q3']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['q3']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['q3']['symbol_mon'] = '';
      $this->field_config['q3']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['q3']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
      //-- s365
      $this->field_config['s365']               = array();
      $this->field_config['s365']['symbol_grp'] = $_SESSION['scriptcase']['reg_conf']['grup_val'];
      $this->field_config['s365']['symbol_fmt'] = $_SESSION['scriptcase']['reg_conf']['unid_mont_group_digit'];
      $this->field_config['s365']['symbol_dec'] = $_SESSION['scriptcase']['reg_conf']['dec_val'];
      $this->field_config['s365']['symbol_mon'] = '';
      $this->field_config['s365']['format_pos'] = $_SESSION['scriptcase']['reg_conf']['monet_f_pos'];
      $this->field_config['s365']['format_neg'] = $_SESSION['scriptcase']['reg_conf']['monet_f_neg'];
   }

   function controle()
   {
        global $nm_url_saida, $teste_validade, 
               $glo_senha_protect, $nm_apl_dependente, $nm_form_submit, $sc_check_excl, $nm_opc_form_php, $nm_call_php, $nm_opc_lookup;


      $this->ini_controle();

      if ('' != $_SESSION['scriptcase']['change_regional_old'])
      {
          $_SESSION['scriptcase']['str_conf_reg'] = $_SESSION['scriptcase']['change_regional_old'];
          $this->Ini->regionalDefault($_SESSION['scriptcase']['str_conf_reg']);
          $this->loadFieldConfig();
          $this->nm_tira_formatacao();
          $this->nm_converte_datas();

          $_SESSION['scriptcase']['str_conf_reg'] = $_SESSION['scriptcase']['change_regional_new'];
          $this->Ini->regionalDefault($_SESSION['scriptcase']['str_conf_reg']);
          $this->loadFieldConfig();
          $guarda_formatado = $this->formatado;
          $this->nm_formatar_campos();
          $this->formatado = $guarda_formatado;

          $_SESSION['scriptcase']['change_regional_old'] = '';
          $_SESSION['scriptcase']['change_regional_new'] = '';
      }

//
//-----> 
//
      if ($this->NM_ajax_flag && 'validate_' == substr($this->NM_ajax_opcao, 0, 9))
      {
          if ('validate_bcode' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'bcode');
          }
          if ('validate_status' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'status');
          }
          if ('validate_updated' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'updated');
          }
          if ('validate_number' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'number');
          }
          if ('validate_terms' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'terms');
          }
          if ('validate_salesman' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'salesman');
          }
          if ('validate_tdate' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'tdate');
          }
          if ('validate_att' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'att');
          }
          if ('validate_prefix' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'prefix');
          }
          if ('validate_name' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'name');
          }
          if ('validate_address1' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'address1');
          }
          if ('validate_address2' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'address2');
          }
          if ('validate_city' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'city');
          }
          if ('validate_state' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'state');
          }
          if ('validate_zip_code' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'zip_code');
          }
          if ('validate_country' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'country');
          }
          if ('validate_email' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'email');
          }
          if ('validate_phone' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'phone');
          }
          if ('validate_contact' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'contact');
          }
          if ('validate_fax' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'fax');
          }
          if ('validate_cphone1' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'cphone1');
          }
          if ('validate_cemail1' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'cemail1');
          }
          if ('validate_cfax1' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'cfax1');
          }
          if ('validate_contact2' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'contact2');
          }
          if ('validate_cphone2' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'cphone2');
          }
          if ('validate_cemail2' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'cemail2');
          }
          if ('validate_cfax2' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'cfax2');
          }
          if ('validate_cat1' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'cat1');
          }
          if ('validate_cat2' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'cat2');
          }
          if ('validate_cat3' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'cat3');
          }
          if ('validate_cat4' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'cat4');
          }
          if ('validate_cat5' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'cat5');
          }
          if ('validate_cat6' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'cat6');
          }
          if ('validate_cat7' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'cat7');
          }
          if ('validate_mtd' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'mtd');
          }
          if ('validate_qtd' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'qtd');
          }
          if ('validate_ytd' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'ytd');
          }
          if ('validate_jan' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'jan');
          }
          if ('validate_feb' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'feb');
          }
          if ('validate_mar' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'mar');
          }
          if ('validate_apr' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'apr');
          }
          if ('validate_may' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'may');
          }
          if ('validate_jun' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'jun');
          }
          if ('validate_jul' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'jul');
          }
          if ('validate_aug' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'aug');
          }
          if ('validate_sep' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'sep');
          }
          if ('validate_oct' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'oct');
          }
          if ('validate_nov' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'nov');
          }
          if ('validate_dec' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'dec');
          }
          if ('validate_lyear' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'lyear');
          }
          if ('validate_llyear' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'llyear');
          }
          if ('validate_q1' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'q1');
          }
          if ('validate_q2' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'q2');
          }
          if ('validate_q4' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'q4');
          }
          if ('validate_q3' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'q3');
          }
          if ('validate_memo' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'memo');
          }
          if ('validate_custship' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'custship');
          }
          if ('validate_orders' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'orders');
          }
          if ('validate_billing' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'billing');
          }
          if ('validate_quotes' == $this->NM_ajax_opcao)
          {
              $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros, 'quotes');
          }
          custbill_form_pack_ajax_response();
          exit;
      }
      if (isset($this->sc_inline_call) && 'Y' == $this->sc_inline_call)
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['inline_form_seq'] = $this->sc_seq_row;
          $this->nm_tira_formatacao();
          $this->nm_converte_datas();
      }
      if ($this->nmgp_opcao == "recarga" || $this->nmgp_opcao == "muda_form") 
      {
          $this->nm_tira_formatacao();
          $this->nm_converte_datas();
          $nm_sc_sv_opcao = $this->nmgp_opcao; 
          $this->nmgp_opcao = "nada"; 
          $this->nm_acessa_banco();
          if ($this->NM_ajax_flag)
          {
              $this->ajax_return_values();
              custbill_form_pack_ajax_response();
              exit;
          }
          $this->nm_formatar_campos();
          $this->nmgp_opcao = $nm_sc_sv_opcao; 
          $this->nm_gera_html();
          $this->NM_close_db(); 
          $this->nmgp_opcao = ""; 
          exit; 
      }
      if ($this->nmgp_opcao == "incluir" || $this->nmgp_opcao == "alterar" || $this->nmgp_opcao == "excluir") 
      {
          $this->Valida_campos($Campos_Crit, $Campos_Falta, $Campos_Erros) ; 
          $_SESSION['scriptcase']['custbill_form']['contr_erro'] = 'off';
          if ($Campos_Crit != "") 
          {
              $Campos_Crit = $this->Ini->Nm_lang['lang_errm_flds'] . ' ' . $Campos_Crit ; 
          }
          if ($Campos_Crit != "" || !empty($Campos_Falta) || $this->Campos_Mens_erro != "")
          {
              if ($this->NM_ajax_flag)
              {
                  custbill_form_pack_ajax_response();
                  exit;
              }
              $campos_erro = $this->Formata_Erros($Campos_Crit, $Campos_Falta, $Campos_Erros);
              $this->Campos_Mens_erro = ""; 
              $this->Erro->mensagem(__FILE__, __LINE__, "critica", $campos_erro); 
              $this->nmgp_opc_ant = $this->nmgp_opcao ; 
              if ($this->nmgp_opcao == "incluir" && $nm_apl_dependente == 1) 
              { 
                  $this->nm_flag_saida_novo = "S";; 
              }
              if ($this->nmgp_opcao == "incluir") 
              { 
                  $GLOBALS["erro_incl"] = 1; 
              }
              $this->nmgp_opcao = "nada" ; 
          }
      }
      elseif (isset($nm_form_submit) && $this->nmgp_opcao != "menu_link")
      {
      }
//
      if ($this->nmgp_opcao != "nada")
      {
          $this->nm_acessa_banco();
      }
      else
      {
           if ($this->nmgp_opc_ant == "incluir") 
           { 
               $this->nm_proc_onload(false);
           }
           else
           { 
              $this->nm_guardar_campos();
           }
      }
      if ($this->nmgp_opcao != "recarga" && $this->nmgp_opcao != "muda_form" && !$this->Apl_com_erro)
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['recarga'] = $this->nmgp_opcao;
          if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['sc_redir_insert']) && $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['sc_redir_insert'] == "ok")
          {
              if ($this->sc_evento == "insert" || ($this->nmgp_opc_ant == "novo" && $this->nmgp_opcao == "novo" && $this->sc_evento == "novo"))
              {
                  $this->NM_close_db(); 
                  $this->nmgp_redireciona(2); 
              }
          }
          if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['sc_redir_atualiz']) && $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['sc_redir_atualiz'] == "ok")
          {
              if ($this->sc_evento == "update")
              {
                  $this->NM_close_db(); 
                  $this->nmgp_redireciona(2); 
              }
              if ($this->sc_evento == "delete")
              {
                  $this->NM_close_db(); 
                  $this->nmgp_redireciona(2); 
              }
          }
      }
      if ($this->NM_ajax_flag && 'navigate_form' == $this->NM_ajax_opcao)
      {
          $this->ajax_return_values();
          $this->ajax_add_parameters();
          custbill_form_pack_ajax_response();
          exit;
      }
      $this->nm_formatar_campos();
      if ($this->NM_ajax_flag)
      {
          $this->NM_ajax_info['result'] = 'OK';
          if ('alterar' == $this->NM_ajax_info['param']['nmgp_opcao'])
          {
              $this->NM_ajax_info['msgDisplay'] = NM_charset_to_utf8($this->Ini->Nm_lang['lang_othr_ajax_frmu']);
          }
          custbill_form_pack_ajax_response();
          exit;
      }
      $this->nm_gera_html();
      $this->NM_close_db(); 
      $this->nmgp_opcao = ""; 
   }
//
//--------------------------------------------------------------------------------------
   function NM_has_trans()
   {
       return !in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access);
   }
//
//--------------------------------------------------------------------------------------
   function NM_commit_db()
   {
       if ($this->Ini->sc_tem_trans_banco && !$this->Embutida_proc)
       { 
           $this->Db->CommitTrans(); 
           $this->Ini->sc_tem_trans_banco = false;
       } 
   }
//
//--------------------------------------------------------------------------------------
   function NM_rollback_db()
   {
       if ($this->Ini->sc_tem_trans_banco && !$this->Embutida_proc)
       { 
           $this->Db->RollbackTrans(); 
           $this->Ini->sc_tem_trans_banco = false;
       } 
   }
//
//--------------------------------------------------------------------------------------
   function NM_close_db()
   {
       if ($this->Db && !$this->Embutida_proc)
       { 
           $this->Db->Close(); 
       } 
   }
   function sc_btn_FixDB() 
   {
        global $nm_url_saida, $teste_validade, 
               $glo_senha_protect, $nm_apl_dependente, $nm_form_submit, $sc_check_excl, $nm_opc_form_php, $nm_call_php, $nm_opc_lookup;
 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">

<html<?php echo $_SESSION['scriptcase']['reg_conf']['html_dir'] ?>>
 <head>
    <META http-equiv="Content-Type" content="text/html; charset=<?php echo $_SESSION['scriptcase']['charset_html'] ?>" />
    <SCRIPT type="text/javascript">
      var sc_pathToTB = '<?php echo $this->Ini->path_prod ?>/third/jquery_plugin/thickbox/';
    </SCRIPT>
    <SCRIPT type="text/javascript" src="<?php echo $this->Ini->path_prod; ?>/third/jquery/js/jquery.js"></SCRIPT>
    <SCRIPT type="text/javascript" src="<?php echo $this->Ini->path_prod; ?>/third/jquery_plugin/malsup-blockui/jquery.blockUI.js"></SCRIPT>
    <SCRIPT type="text/javascript" src="<?php echo $this->Ini->path_prod; ?>/third/jquery_plugin/thickbox/thickbox-compressed.js"></SCRIPT>
    <link rel="stylesheet" href="<?php echo $this->Ini->path_prod ?>/third/jquery_plugin/thickbox/thickbox.css" type="text/css" media="screen" />
    <link rel="stylesheet" type="text/css" href="../_lib/css/<?php echo $this->Ini->str_schema_all ?>_form.css" />
 </head>
  <body class="scFormPage">
      <table class="scFormTabela" align="center"><tr><td>
<?php
      $nmgp_opcao_saida_php = "igual";
      $nmgp_opc_ant_saida_php = "";
      if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opc_ant'] == "novo" || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opc_ant'] == "incluir")
      {
          $nmgp_opc_ant_saida_php = "novo";
          $nmgp_opcao_saida_php   = "recarga";
      }
      $nm_f_saida = "./";
      nm_limpa_data($this->updated, $this->field_config['updated']['date_sep']) ; 
      nm_limpa_numero($this->number, $this->field_config['number']['symbol_grp']) ; 
      nm_limpa_data($this->tdate, $this->field_config['tdate']['date_sep']) ; 
      if (!empty($this->field_config['mtd']['symbol_dec']))
      {
          $this->sc_remove_currency($this->mtd, $this->field_config['mtd']['symbol_dec'], $this->field_config['mtd']['symbol_grp'], $this->field_config['mtd']['symbol_mon']); 
          nm_limpa_valor($this->mtd, $this->field_config['mtd']['symbol_dec'], $this->field_config['mtd']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['qtd']['symbol_dec']))
      {
          $this->sc_remove_currency($this->qtd, $this->field_config['qtd']['symbol_dec'], $this->field_config['qtd']['symbol_grp'], $this->field_config['qtd']['symbol_mon']); 
          nm_limpa_valor($this->qtd, $this->field_config['qtd']['symbol_dec'], $this->field_config['qtd']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['ytd']['symbol_dec']))
      {
          $this->sc_remove_currency($this->ytd, $this->field_config['ytd']['symbol_dec'], $this->field_config['ytd']['symbol_grp'], $this->field_config['ytd']['symbol_mon']); 
          nm_limpa_valor($this->ytd, $this->field_config['ytd']['symbol_dec'], $this->field_config['ytd']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['jan']['symbol_dec']))
      {
          $this->sc_remove_currency($this->jan, $this->field_config['jan']['symbol_dec'], $this->field_config['jan']['symbol_grp'], $this->field_config['jan']['symbol_mon']); 
          nm_limpa_valor($this->jan, $this->field_config['jan']['symbol_dec'], $this->field_config['jan']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['feb']['symbol_dec']))
      {
          $this->sc_remove_currency($this->feb, $this->field_config['feb']['symbol_dec'], $this->field_config['feb']['symbol_grp'], $this->field_config['feb']['symbol_mon']); 
          nm_limpa_valor($this->feb, $this->field_config['feb']['symbol_dec'], $this->field_config['feb']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['mar']['symbol_dec']))
      {
          $this->sc_remove_currency($this->mar, $this->field_config['mar']['symbol_dec'], $this->field_config['mar']['symbol_grp'], $this->field_config['mar']['symbol_mon']); 
          nm_limpa_valor($this->mar, $this->field_config['mar']['symbol_dec'], $this->field_config['mar']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['apr']['symbol_dec']))
      {
          $this->sc_remove_currency($this->apr, $this->field_config['apr']['symbol_dec'], $this->field_config['apr']['symbol_grp'], $this->field_config['apr']['symbol_mon']); 
          nm_limpa_valor($this->apr, $this->field_config['apr']['symbol_dec'], $this->field_config['apr']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['may']['symbol_dec']))
      {
          $this->sc_remove_currency($this->may, $this->field_config['may']['symbol_dec'], $this->field_config['may']['symbol_grp'], $this->field_config['may']['symbol_mon']); 
          nm_limpa_valor($this->may, $this->field_config['may']['symbol_dec'], $this->field_config['may']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['jun']['symbol_dec']))
      {
          $this->sc_remove_currency($this->jun, $this->field_config['jun']['symbol_dec'], $this->field_config['jun']['symbol_grp'], $this->field_config['jun']['symbol_mon']); 
          nm_limpa_valor($this->jun, $this->field_config['jun']['symbol_dec'], $this->field_config['jun']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['jul']['symbol_dec']))
      {
          $this->sc_remove_currency($this->jul, $this->field_config['jul']['symbol_dec'], $this->field_config['jul']['symbol_grp'], $this->field_config['jul']['symbol_mon']); 
          nm_limpa_valor($this->jul, $this->field_config['jul']['symbol_dec'], $this->field_config['jul']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['aug']['symbol_dec']))
      {
          $this->sc_remove_currency($this->aug, $this->field_config['aug']['symbol_dec'], $this->field_config['aug']['symbol_grp'], $this->field_config['aug']['symbol_mon']); 
          nm_limpa_valor($this->aug, $this->field_config['aug']['symbol_dec'], $this->field_config['aug']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['sep']['symbol_dec']))
      {
          $this->sc_remove_currency($this->sep, $this->field_config['sep']['symbol_dec'], $this->field_config['sep']['symbol_grp'], $this->field_config['sep']['symbol_mon']); 
          nm_limpa_valor($this->sep, $this->field_config['sep']['symbol_dec'], $this->field_config['sep']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['oct']['symbol_dec']))
      {
          $this->sc_remove_currency($this->oct, $this->field_config['oct']['symbol_dec'], $this->field_config['oct']['symbol_grp'], $this->field_config['oct']['symbol_mon']); 
          nm_limpa_valor($this->oct, $this->field_config['oct']['symbol_dec'], $this->field_config['oct']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['nov']['symbol_dec']))
      {
          $this->sc_remove_currency($this->nov, $this->field_config['nov']['symbol_dec'], $this->field_config['nov']['symbol_grp'], $this->field_config['nov']['symbol_mon']); 
          nm_limpa_valor($this->nov, $this->field_config['nov']['symbol_dec'], $this->field_config['nov']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['dec']['symbol_dec']))
      {
          $this->sc_remove_currency($this->dec, $this->field_config['dec']['symbol_dec'], $this->field_config['dec']['symbol_grp'], $this->field_config['dec']['symbol_mon']); 
          nm_limpa_valor($this->dec, $this->field_config['dec']['symbol_dec'], $this->field_config['dec']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['lyear']['symbol_dec']))
      {
          $this->sc_remove_currency($this->lyear, $this->field_config['lyear']['symbol_dec'], $this->field_config['lyear']['symbol_grp'], $this->field_config['lyear']['symbol_mon']); 
          nm_limpa_valor($this->lyear, $this->field_config['lyear']['symbol_dec'], $this->field_config['lyear']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['llyear']['symbol_dec']))
      {
          $this->sc_remove_currency($this->llyear, $this->field_config['llyear']['symbol_dec'], $this->field_config['llyear']['symbol_grp'], $this->field_config['llyear']['symbol_mon']); 
          nm_limpa_valor($this->llyear, $this->field_config['llyear']['symbol_dec'], $this->field_config['llyear']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['q1']['symbol_dec']))
      {
          $this->sc_remove_currency($this->q1, $this->field_config['q1']['symbol_dec'], $this->field_config['q1']['symbol_grp'], $this->field_config['q1']['symbol_mon']); 
          nm_limpa_valor($this->q1, $this->field_config['q1']['symbol_dec'], $this->field_config['q1']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['q2']['symbol_dec']))
      {
          $this->sc_remove_currency($this->q2, $this->field_config['q2']['symbol_dec'], $this->field_config['q2']['symbol_grp'], $this->field_config['q2']['symbol_mon']); 
          nm_limpa_valor($this->q2, $this->field_config['q2']['symbol_dec'], $this->field_config['q2']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['q4']['symbol_dec']))
      {
          $this->sc_remove_currency($this->q4, $this->field_config['q4']['symbol_dec'], $this->field_config['q4']['symbol_grp'], $this->field_config['q4']['symbol_mon']); 
          nm_limpa_valor($this->q4, $this->field_config['q4']['symbol_dec'], $this->field_config['q4']['symbol_grp']) ; 
      }
      if (!empty($this->field_config['q3']['symbol_dec']))
      {
          $this->sc_remove_currency($this->q3, $this->field_config['q3']['symbol_dec'], $this->field_config['q3']['symbol_grp'], $this->field_config['q3']['symbol_mon']); 
          nm_limpa_valor($this->q3, $this->field_config['q3']['symbol_dec'], $this->field_config['q3']['symbol_grp']) ; 
      }
      $this->nm_converte_datas();
      $_SESSION['scriptcase']['custbill_form']['contr_erro'] = 'on';
 $update_sql = "ALTER TABLE custbill ADD ID2 INT PRIMARY KEY AUTO_INCREMENT";

     $nm_select = $update_sql; 
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select;
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
         $rf = $this->Db->Execute($nm_select);
         if ($rf === false)
         {
             $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg());
             $this->NM_rollback_db(); 
             if ($this->NM_ajax_flag)
             {
                custbill_form_pack_ajax_response();
             }
             exit;
         }
         $rf->Close();
      ;
$_SESSION['scriptcase']['custbill_form']['contr_erro'] = 'off'; 
?>
      </td></tr><tr><td align="center">
      <form name="FPHP" method="post" 
                        action="<?php echo $nm_f_saida ?>" 
                        target="_self">
      <input type=hidden name="nmgp_opcao" value=""/>
      <input type=hidden name="script_case_init" value="<?php  echo NM_encode_input($this->Ini->sc_page); ?>"/>
      <input type=hidden name="script_case_session" value="<?php  echo NM_encode_input(session_id()); ?>"/>
      <input type=hidden name="bcode" value="<?php echo NM_encode_input($this->bcode) ?>"/>
      <input type=hidden name="nmgp_opcao" value="<?php echo NM_encode_input($nmgp_opcao_saida_php); ?>"/>
      <input type=hidden name="nmgp_opc_ant" value="<?php echo NM_encode_input($nmgp_opc_ant_saida_php); ?>"/>
      <input type=submit name="nmgp_bok" value="<?php echo $this->Ini->Nm_lang['lang_btns_cfrm'] ?>"/>
      </form>
      </td></tr></table>
      </body>
      </html>
<?php
   }
//
//--------------------------------------------------------------------------------------
   function Formata_Erros($Campos_Crit, $Campos_Falta, $Campos_Erros, $mode = 3) 
   {
       switch ($mode)
       {
           case 1:
               $campos_erro = array();
               if (!empty($Campos_Crit))
               {
                   $campos_erro[] = $Campos_Crit;
               }
               if (!empty($Campos_Falta))
               {
                   $campos_erro[] = $this->Formata_Campos_Falta($Campos_Falta);
               }
               if (!empty($this->Campos_Mens_erro))
               {
                   $campos_erro[] = $this->Campos_Mens_erro;
               }
               return implode('<br />', $campos_erro);
               break;

           case 2:
               $campos_erro = array();
               if (!empty($Campos_Crit))
               {
                   $campos_erro[] = $Campos_Crit;
               }
               if (!empty($Campos_Falta))
               {
                   $campos_erro[] = $this->Formata_Campos_Falta($Campos_Falta, true);
               }
               if (!empty($this->Campos_Mens_erro))
               {
                   $campos_erro[] = $this->Campos_Mens_erro;
               }
               return implode('<br />', $campos_erro);
               break;

           case 3:
               $campos_erro = array();
               if (!empty($Campos_Erros))
               {
                   $campos_erro[] = $this->Formata_Campos_Erros($Campos_Erros);
               }
               if (!empty($this->Campos_Mens_erro))
               {
                   $campos_mens_erro = str_replace(array('<br />', '<br>', '<BR />'), array('<BR>', '<BR>', '<BR>'), $this->Campos_Mens_erro);
                   $campos_mens_erro = explode('<BR>', $campos_mens_erro);
                   foreach ($campos_mens_erro as $msg_erro)
                   {
                       if ('' != $msg_erro && !in_array($msg_erro, $campos_erro))
                       {
                           $campos_erro[] = $msg_erro;
                       }
                   }
               }
               return implode('<br />', $campos_erro);
               break;
       }
   }

   function Formata_Campos_Falta($Campos_Falta, $table = false) 
   {
       $Campos_Falta = array_unique($Campos_Falta);

       if (!$table)
       {
           return $this->Ini->Nm_lang['lang_errm_reqd'] . ' ' . implode('; ', $Campos_Falta);
       }

       $aCols  = array();
       $iTotal = sizeof($Campos_Falta);
       $iCols  = 6 > $iTotal ? 1 : (11 > $iTotal ? 2 : (16 > $iTotal ? 3 : 4));
       $iItems = ceil($iTotal / $iCols);
       $iNowC  = 0;
       $iNowI  = 0;

       foreach ($Campos_Falta as $campo)
       {
           $aCols[$iNowC][] = $campo;
           if ($iItems == ++$iNowI)
           {
               $iNowC++;
               $iNowI = 0;
           }
       }

       $sError  = '<table style="border-collapse: collapse; border-width: 0px">';
       $sError .= '<tr>';
       $sError .= '<td class="scFormErrorMessageFont" style="padding: 0; vertical-align: top; white-space: nowrap">' . $this->Ini->Nm_lang['lang_errm_reqd'] . '</td>';
       foreach ($aCols as $aCol)
       {
           $sError .= '<td class="scFormErrorMessageFont" style="padding: 0 6px; vertical-align: top; white-space: nowrap">' . implode('<br />', $aCol) . '</td>';
       }
       $sError .= '</tr>';
       $sError .= '</table>';

       return $sError;
   }

   function Formata_Campos_Crit($Campos_Crit, $table = false) 
   {
       $Campos_Crit = array_unique($Campos_Crit);

       if (!$table)
       {
           return $this->Ini->Nm_lang['lang_errm_flds'] . ' ' . implode('; ', $Campos_Crit);
       }

       $aCols  = array();
       $iTotal = sizeof($Campos_Crit);
       $iCols  = 6 > $iTotal ? 1 : (11 > $iTotal ? 2 : (16 > $iTotal ? 3 : 4));
       $iItems = ceil($iTotal / $iCols);
       $iNowC  = 0;
       $iNowI  = 0;

       foreach ($Campos_Crit as $campo)
       {
           $aCols[$iNowC][] = $campo;
           if ($iItems == ++$iNowI)
           {
               $iNowC++;
               $iNowI = 0;
           }
       }

       $sError  = '<table style="border-collapse: collapse; border-width: 0px">';
       $sError .= '<tr>';
       $sError .= '<td class="scFormErrorMessageFont" style="padding: 0; vertical-align: top; white-space: nowrap">' . $this->Ini->Nm_lang['lang_errm_flds'] . '</td>';
       foreach ($aCols as $aCol)
       {
           $sError .= '<td class="scFormErrorMessageFont" style="padding: 0 6px; vertical-align: top; white-space: nowrap">' . implode('<br />', $aCol) . '</td>';
       }
       $sError .= '</tr>';
       $sError .= '</table>';

       return $sError;
   }

   function Formata_Campos_Erros($Campos_Erros) 
   {
       $sError  = '<table style="border-collapse: collapse; border-width: 0px">';

       foreach ($Campos_Erros as $campo => $erros)
       {
           $sError .= '<tr>';
           $sError .= '<td class="scFormErrorMessageFont" style="padding: 0; vertical-align: top; white-space: nowrap">' . $this->Recupera_Nome_Campo($campo) . ':</td>';
           $sError .= '<td class="scFormErrorMessageFont" style="padding: 0 6px; vertical-align: top; white-space: nowrap">' . implode('<br />', array_unique($erros)) . '</td>';
           $sError .= '</tr>';
       }

       $sError .= '</table>';

       return $sError;
   }

   function Recupera_Nome_Campo($campo) 
   {
       switch($campo)
       {
           case 'bcode':
               return "BCODE";
               break;
           case 'status':
               return "STATUS";
               break;
           case 'updated':
               return "UPDATED";
               break;
           case 'number':
               return "NUMBER";
               break;
           case 'terms':
               return "TERMS";
               break;
           case 'salesman':
               return "SALESMAN";
               break;
           case 'tdate':
               return "TDATE";
               break;
           case 'att':
               return "ATT";
               break;
           case 'prefix':
               return "PREFIX";
               break;
           case 'name':
               return "NAME";
               break;
           case 'address1':
               return "ADDRESS1";
               break;
           case 'address2':
               return "ADDRESS2";
               break;
           case 'city':
               return "CITY";
               break;
           case 'state':
               return "STATE";
               break;
           case 'zip_code':
               return "ZIP CODE";
               break;
           case 'country':
               return "COUNTRY";
               break;
           case 'email':
               return "EMAIL";
               break;
           case 'phone':
               return "PHONE";
               break;
           case 'contact':
               return "CONTACT";
               break;
           case 'fax':
               return "FAX";
               break;
           case 'cphone1':
               return "CPHONE1";
               break;
           case 'cemail1':
               return "CEMAIL1";
               break;
           case 'cfax1':
               return "CFAX1";
               break;
           case 'contact2':
               return "CONTACT2";
               break;
           case 'cphone2':
               return "CPHONE2";
               break;
           case 'cemail2':
               return "CEMAIL2";
               break;
           case 'cfax2':
               return "CFAX2";
               break;
           case 'cat1':
               return "CAT1";
               break;
           case 'cat2':
               return "CAT2";
               break;
           case 'cat3':
               return "CAT3";
               break;
           case 'cat4':
               return "CAT4";
               break;
           case 'cat5':
               return "CAT5";
               break;
           case 'cat6':
               return "CAT6";
               break;
           case 'cat7':
               return "CAT7";
               break;
           case 'mtd':
               return "MTD";
               break;
           case 'qtd':
               return "QTD";
               break;
           case 'ytd':
               return "YTD";
               break;
           case 'jan':
               return "JAN";
               break;
           case 'feb':
               return "FEB";
               break;
           case 'mar':
               return "MAR";
               break;
           case 'apr':
               return "APR";
               break;
           case 'may':
               return "MAY";
               break;
           case 'jun':
               return "JUN";
               break;
           case 'jul':
               return "JUL";
               break;
           case 'aug':
               return "AUG";
               break;
           case 'sep':
               return "SEP";
               break;
           case 'oct':
               return "OCT";
               break;
           case 'nov':
               return "NOV";
               break;
           case 'dec':
               return "DEC";
               break;
           case 'lyear':
               return "LYEAR";
               break;
           case 'llyear':
               return "LLYEAR";
               break;
           case 'q1':
               return "Q1";
               break;
           case 'q2':
               return "Q2";
               break;
           case 'q4':
               return "Q4";
               break;
           case 'q3':
               return "Q3";
               break;
           case 'memo':
               return "MEMO";
               break;
           case 'custship':
               return "Ship To";
               break;
           case 'orders':
               return "Orders";
               break;
           case 'billing':
               return "Billing";
               break;
           case 'quotes':
               return "Quotes";
               break;
           case 'added':
               return "ADDED";
               break;
           case 's365':
               return "S365";
               break;
           case 'temp':
               return "TEMP";
               break;
       }

       return $campo;
   }

   function dateDefaultFormat()
   {
       if (isset($this->Ini->Nm_conf_reg[$this->Ini->str_conf_reg]['data_format']))
       {
           $sDate = str_replace('yyyy', 'Y', $this->Ini->Nm_conf_reg[$this->Ini->str_conf_reg]['data_format']);
           $sDate = str_replace('mm',   'm', $sDate);
           $sDate = str_replace('dd',   'd', $sDate);
           return substr(chunk_split($sDate, 1, $this->Ini->Nm_conf_reg[$this->Ini->str_conf_reg]['data_sep']), 0, -1);
       }
       elseif ('en_us' == $this->Ini->str_lang)
       {
           return 'm/d/Y';
       }
       else
       {
           return 'd/m/Y';
       }
   } // dateDefaultFormat

//
//--------------------------------------------------------------------------------------
   function Valida_campos(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros, $filtro = '') 
   {
     global $nm_browser, $teste_validade;
//---------------------------------------------------------
     $this->sc_force_zero = array();
      if ('' == $filtro || 'bcode' == $filtro)
        $this->ValidateField_bcode($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'status' == $filtro)
        $this->ValidateField_status($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'updated' == $filtro)
        $this->ValidateField_updated($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'number' == $filtro)
        $this->ValidateField_number($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'terms' == $filtro)
        $this->ValidateField_terms($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'salesman' == $filtro)
        $this->ValidateField_salesman($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'tdate' == $filtro)
        $this->ValidateField_tdate($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'att' == $filtro)
        $this->ValidateField_att($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'prefix' == $filtro)
        $this->ValidateField_prefix($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'name' == $filtro)
        $this->ValidateField_name($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'address1' == $filtro)
        $this->ValidateField_address1($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'address2' == $filtro)
        $this->ValidateField_address2($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'city' == $filtro)
        $this->ValidateField_city($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'state' == $filtro)
        $this->ValidateField_state($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'zip_code' == $filtro)
        $this->ValidateField_zip_code($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'country' == $filtro)
        $this->ValidateField_country($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'email' == $filtro)
        $this->ValidateField_email($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'phone' == $filtro)
        $this->ValidateField_phone($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'contact' == $filtro)
        $this->ValidateField_contact($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'fax' == $filtro)
        $this->ValidateField_fax($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'cphone1' == $filtro)
        $this->ValidateField_cphone1($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'cemail1' == $filtro)
        $this->ValidateField_cemail1($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'cfax1' == $filtro)
        $this->ValidateField_cfax1($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'contact2' == $filtro)
        $this->ValidateField_contact2($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'cphone2' == $filtro)
        $this->ValidateField_cphone2($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'cemail2' == $filtro)
        $this->ValidateField_cemail2($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'cfax2' == $filtro)
        $this->ValidateField_cfax2($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'cat1' == $filtro)
        $this->ValidateField_cat1($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'cat2' == $filtro)
        $this->ValidateField_cat2($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'cat3' == $filtro)
        $this->ValidateField_cat3($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'cat4' == $filtro)
        $this->ValidateField_cat4($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'cat5' == $filtro)
        $this->ValidateField_cat5($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'cat6' == $filtro)
        $this->ValidateField_cat6($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'cat7' == $filtro)
        $this->ValidateField_cat7($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'mtd' == $filtro)
        $this->ValidateField_mtd($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'qtd' == $filtro)
        $this->ValidateField_qtd($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'ytd' == $filtro)
        $this->ValidateField_ytd($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'jan' == $filtro)
        $this->ValidateField_jan($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'feb' == $filtro)
        $this->ValidateField_feb($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'mar' == $filtro)
        $this->ValidateField_mar($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'apr' == $filtro)
        $this->ValidateField_apr($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'may' == $filtro)
        $this->ValidateField_may($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'jun' == $filtro)
        $this->ValidateField_jun($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'jul' == $filtro)
        $this->ValidateField_jul($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'aug' == $filtro)
        $this->ValidateField_aug($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'sep' == $filtro)
        $this->ValidateField_sep($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'oct' == $filtro)
        $this->ValidateField_oct($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'nov' == $filtro)
        $this->ValidateField_nov($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'dec' == $filtro)
        $this->ValidateField_dec($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'lyear' == $filtro)
        $this->ValidateField_lyear($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'llyear' == $filtro)
        $this->ValidateField_llyear($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'q1' == $filtro)
        $this->ValidateField_q1($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'q2' == $filtro)
        $this->ValidateField_q2($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'q4' == $filtro)
        $this->ValidateField_q4($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'q3' == $filtro)
        $this->ValidateField_q3($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'memo' == $filtro)
        $this->ValidateField_memo($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'custship' == $filtro)
        $this->ValidateField_custship($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'orders' == $filtro)
        $this->ValidateField_orders($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'billing' == $filtro)
        $this->ValidateField_billing($Campos_Crit, $Campos_Falta, $Campos_Erros);
      if ('' == $filtro || 'quotes' == $filtro)
        $this->ValidateField_quotes($Campos_Crit, $Campos_Falta, $Campos_Erros);
//-- converter datas   
      $this->nm_converte_datas();
//---
      if (!empty($Campos_Crit) || !empty($Campos_Falta) || !empty($this->Campos_Mens_erro))
      {
          if (!empty($this->sc_force_zero))
          {
              foreach ($this->sc_force_zero as $i_force_zero => $sc_force_zero_field)
              {
                  eval('$this->' . $sc_force_zero_field . ' = "";');
                  unset($this->sc_force_zero[$i_force_zero]);
              }
          }
      }
   }

    function ValidateField_bcode(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir" && (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['bcode']) || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['bcode'] == "on")) 
      { 
          if ($this->bcode == "")  
          { 
              $Campos_Falta[] =  "BCODE" ; 
              if (!isset($Campos_Erros['bcode']))
              {
                  $Campos_Erros['bcode'] = array();
              }
              $Campos_Erros['bcode'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
                  if (!isset($this->NM_ajax_info['errList']['bcode']) || !is_array($this->NM_ajax_info['errList']['bcode']))
                  {
                      $this->NM_ajax_info['errList']['bcode'] = array();
                  }
                  $this->NM_ajax_info['errList']['bcode'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
          } 
      } 
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->bcode) > 4) 
          { 
              $Campos_Crit .= "BCODE " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['bcode']))
              {
                  $Campos_Erros['bcode'] = array();
              }
              $Campos_Erros['bcode'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['bcode']) || !is_array($this->NM_ajax_info['errList']['bcode']))
              {
                  $this->NM_ajax_info['errList']['bcode'] = array();
              }
              $this->NM_ajax_info['errList']['bcode'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_bcode

    function ValidateField_status(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->status) > 1) 
          { 
              $Campos_Crit .= "STATUS " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 1 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['status']))
              {
                  $Campos_Erros['status'] = array();
              }
              $Campos_Erros['status'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 1 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['status']) || !is_array($this->NM_ajax_info['errList']['status']))
              {
                  $this->NM_ajax_info['errList']['status'] = array();
              }
              $this->NM_ajax_info['errList']['status'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 1 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_status

    function ValidateField_updated(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      nm_limpa_data($this->updated, $this->field_config['updated']['date_sep']) ; 
      $trab_dt_min = ""; 
      $trab_dt_max = ""; 
      if ($this->nmgp_opcao == "incluir")
      { 
          $guarda_datahora = $this->field_config['updated']['date_format']; 
          if (false !== strpos($guarda_datahora, ';')) $this->field_config['updated']['date_format'] = substr($guarda_datahora, 0, strpos($guarda_datahora, ';'));
          $Format_Data = $this->field_config['updated']['date_format']; 
          nm_limpa_data($Format_Data, $this->field_config['updated']['date_sep']) ; 
          if (trim($this->updated) != "")  
          { 
              if ($teste_validade->Data($this->updated, $Format_Data, $trab_dt_min, $trab_dt_max) == false)  
              { 
                  $Campos_Crit .= "UPDATED; " ; 
                  if (!isset($Campos_Erros['updated']))
                  {
                      $Campos_Erros['updated'] = array();
                  }
                  $Campos_Erros['updated'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['updated']) || !is_array($this->NM_ajax_info['errList']['updated']))
                  {
                      $this->NM_ajax_info['errList']['updated'] = array();
                  }
                  $this->NM_ajax_info['errList']['updated'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
          $this->field_config['updated']['date_format'] = $guarda_datahora; 
       } 
    } // ValidateField_updated

    function ValidateField_number(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->number == "")  
      { 
          $this->number = 0;
          $this->sc_force_zero[] = 'number';
      } 
      nm_limpa_numero($this->number, $this->field_config['number']['symbol_grp']) ; 
      if ($this->nmgp_opcao != "excluir") 
      { 
          if ($this->number != '')  
          { 
              $iTestSize = 11;
              if (strlen($this->number) > $iTestSize)  
              { 
                  $Campos_Crit .= "NUMBER: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['number']))
                  {
                      $Campos_Erros['number'] = array();
                  }
                  $Campos_Erros['number'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['number']) || !is_array($this->NM_ajax_info['errList']['number']))
                  {
                      $this->NM_ajax_info['errList']['number'] = array();
                  }
                  $this->NM_ajax_info['errList']['number'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->number, 11, 0, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "NUMBER; " ; 
                  if (!isset($Campos_Erros['number']))
                  {
                      $Campos_Erros['number'] = array();
                  }
                  $Campos_Erros['number'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['number']) || !is_array($this->NM_ajax_info['errList']['number']))
                  {
                      $this->NM_ajax_info['errList']['number'] = array();
                  }
                  $this->NM_ajax_info['errList']['number'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_number

    function ValidateField_terms(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir" && (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['terms']) || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['terms'] == "on")) 
      { 
          if ($this->terms == "")  
          { 
              $Campos_Falta[] =  "TERMS" ; 
              if (!isset($Campos_Erros['terms']))
              {
                  $Campos_Erros['terms'] = array();
              }
              $Campos_Erros['terms'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
                  if (!isset($this->NM_ajax_info['errList']['terms']) || !is_array($this->NM_ajax_info['errList']['terms']))
                  {
                      $this->NM_ajax_info['errList']['terms'] = array();
                  }
                  $this->NM_ajax_info['errList']['terms'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
          } 
      } 
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->terms) > 15) 
          { 
              $Campos_Crit .= "TERMS " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 15 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['terms']))
              {
                  $Campos_Erros['terms'] = array();
              }
              $Campos_Erros['terms'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 15 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['terms']) || !is_array($this->NM_ajax_info['errList']['terms']))
              {
                  $this->NM_ajax_info['errList']['terms'] = array();
              }
              $this->NM_ajax_info['errList']['terms'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 15 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_terms

    function ValidateField_salesman(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir" && (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['salesman']) || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['salesman'] == "on")) 
      { 
          if ($this->salesman == "")  
          { 
              $Campos_Falta[] =  "SALESMAN" ; 
              if (!isset($Campos_Erros['salesman']))
              {
                  $Campos_Erros['salesman'] = array();
              }
              $Campos_Erros['salesman'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
                  if (!isset($this->NM_ajax_info['errList']['salesman']) || !is_array($this->NM_ajax_info['errList']['salesman']))
                  {
                      $this->NM_ajax_info['errList']['salesman'] = array();
                  }
                  $this->NM_ajax_info['errList']['salesman'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
          } 
      } 
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->salesman) > 3) 
          { 
              $Campos_Crit .= "SALESMAN " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 3 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['salesman']))
              {
                  $Campos_Erros['salesman'] = array();
              }
              $Campos_Erros['salesman'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 3 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['salesman']) || !is_array($this->NM_ajax_info['errList']['salesman']))
              {
                  $this->NM_ajax_info['errList']['salesman'] = array();
              }
              $this->NM_ajax_info['errList']['salesman'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 3 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_salesman

    function ValidateField_tdate(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      nm_limpa_data($this->tdate, $this->field_config['tdate']['date_sep']) ; 
      $trab_dt_min = ""; 
      $trab_dt_max = ""; 
      if ($this->nmgp_opcao == "incluir")
      { 
          $guarda_datahora = $this->field_config['tdate']['date_format']; 
          if (false !== strpos($guarda_datahora, ';')) $this->field_config['tdate']['date_format'] = substr($guarda_datahora, 0, strpos($guarda_datahora, ';'));
          $Format_Data = $this->field_config['tdate']['date_format']; 
          nm_limpa_data($Format_Data, $this->field_config['tdate']['date_sep']) ; 
          if (trim($this->tdate) != "")  
          { 
              if ($teste_validade->Data($this->tdate, $Format_Data, $trab_dt_min, $trab_dt_max) == false)  
              { 
                  $Campos_Crit .= "TDATE; " ; 
                  if (!isset($Campos_Erros['tdate']))
                  {
                      $Campos_Erros['tdate'] = array();
                  }
                  $Campos_Erros['tdate'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['tdate']) || !is_array($this->NM_ajax_info['errList']['tdate']))
                  {
                      $this->NM_ajax_info['errList']['tdate'] = array();
                  }
                  $this->NM_ajax_info['errList']['tdate'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
          $this->field_config['tdate']['date_format'] = $guarda_datahora; 
       } 
    } // ValidateField_tdate

    function ValidateField_att(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->att) > 25) 
          { 
              $Campos_Crit .= "ATT " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['att']))
              {
                  $Campos_Erros['att'] = array();
              }
              $Campos_Erros['att'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['att']) || !is_array($this->NM_ajax_info['errList']['att']))
              {
                  $this->NM_ajax_info['errList']['att'] = array();
              }
              $this->NM_ajax_info['errList']['att'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_att

    function ValidateField_prefix(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->prefix) > 5) 
          { 
              $Campos_Crit .= "PREFIX " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 5 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['prefix']))
              {
                  $Campos_Erros['prefix'] = array();
              }
              $Campos_Erros['prefix'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 5 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['prefix']) || !is_array($this->NM_ajax_info['errList']['prefix']))
              {
                  $this->NM_ajax_info['errList']['prefix'] = array();
              }
              $this->NM_ajax_info['errList']['prefix'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 5 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_prefix

    function ValidateField_name(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir" && (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['name']) || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['name'] == "on")) 
      { 
          if ($this->name == "")  
          { 
              $Campos_Falta[] =  "NAME" ; 
              if (!isset($Campos_Erros['name']))
              {
                  $Campos_Erros['name'] = array();
              }
              $Campos_Erros['name'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
                  if (!isset($this->NM_ajax_info['errList']['name']) || !is_array($this->NM_ajax_info['errList']['name']))
                  {
                      $this->NM_ajax_info['errList']['name'] = array();
                  }
                  $this->NM_ajax_info['errList']['name'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
          } 
      } 
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->name) > 30) 
          { 
              $Campos_Crit .= "NAME " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 30 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['name']))
              {
                  $Campos_Erros['name'] = array();
              }
              $Campos_Erros['name'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 30 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['name']) || !is_array($this->NM_ajax_info['errList']['name']))
              {
                  $this->NM_ajax_info['errList']['name'] = array();
              }
              $this->NM_ajax_info['errList']['name'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 30 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_name

    function ValidateField_address1(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir" && (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['address1']) || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['address1'] == "on")) 
      { 
          if ($this->address1 == "")  
          { 
              $Campos_Falta[] =  "ADDRESS1" ; 
              if (!isset($Campos_Erros['address1']))
              {
                  $Campos_Erros['address1'] = array();
              }
              $Campos_Erros['address1'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
                  if (!isset($this->NM_ajax_info['errList']['address1']) || !is_array($this->NM_ajax_info['errList']['address1']))
                  {
                      $this->NM_ajax_info['errList']['address1'] = array();
                  }
                  $this->NM_ajax_info['errList']['address1'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
          } 
      } 
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->address1) > 25) 
          { 
              $Campos_Crit .= "ADDRESS1 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['address1']))
              {
                  $Campos_Erros['address1'] = array();
              }
              $Campos_Erros['address1'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['address1']) || !is_array($this->NM_ajax_info['errList']['address1']))
              {
                  $this->NM_ajax_info['errList']['address1'] = array();
              }
              $this->NM_ajax_info['errList']['address1'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_address1

    function ValidateField_address2(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->address2) > 25) 
          { 
              $Campos_Crit .= "ADDRESS2 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['address2']))
              {
                  $Campos_Erros['address2'] = array();
              }
              $Campos_Erros['address2'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['address2']) || !is_array($this->NM_ajax_info['errList']['address2']))
              {
                  $this->NM_ajax_info['errList']['address2'] = array();
              }
              $this->NM_ajax_info['errList']['address2'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_address2

    function ValidateField_city(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir" && (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['city']) || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['city'] == "on")) 
      { 
          if ($this->city == "")  
          { 
              $Campos_Falta[] =  "CITY" ; 
              if (!isset($Campos_Erros['city']))
              {
                  $Campos_Erros['city'] = array();
              }
              $Campos_Erros['city'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
                  if (!isset($this->NM_ajax_info['errList']['city']) || !is_array($this->NM_ajax_info['errList']['city']))
                  {
                      $this->NM_ajax_info['errList']['city'] = array();
                  }
                  $this->NM_ajax_info['errList']['city'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
          } 
      } 
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->city) > 17) 
          { 
              $Campos_Crit .= "CITY " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 17 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['city']))
              {
                  $Campos_Erros['city'] = array();
              }
              $Campos_Erros['city'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 17 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['city']) || !is_array($this->NM_ajax_info['errList']['city']))
              {
                  $this->NM_ajax_info['errList']['city'] = array();
              }
              $this->NM_ajax_info['errList']['city'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 17 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_city

    function ValidateField_state(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir" && (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['state']) || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['state'] == "on")) 
      { 
          if ($this->state == "")  
          { 
              $Campos_Falta[] =  "STATE" ; 
              if (!isset($Campos_Erros['state']))
              {
                  $Campos_Erros['state'] = array();
              }
              $Campos_Erros['state'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
                  if (!isset($this->NM_ajax_info['errList']['state']) || !is_array($this->NM_ajax_info['errList']['state']))
                  {
                      $this->NM_ajax_info['errList']['state'] = array();
                  }
                  $this->NM_ajax_info['errList']['state'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
          } 
      } 
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->state) > 2) 
          { 
              $Campos_Crit .= "STATE " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 2 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['state']))
              {
                  $Campos_Erros['state'] = array();
              }
              $Campos_Erros['state'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 2 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['state']) || !is_array($this->NM_ajax_info['errList']['state']))
              {
                  $this->NM_ajax_info['errList']['state'] = array();
              }
              $this->NM_ajax_info['errList']['state'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 2 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_state

    function ValidateField_zip_code(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir" && (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['zip_code']) || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['zip_code'] == "on")) 
      { 
          if ($this->zip_code == "")  
          { 
              $Campos_Falta[] =  "ZIP CODE" ; 
              if (!isset($Campos_Erros['zip_code']))
              {
                  $Campos_Erros['zip_code'] = array();
              }
              $Campos_Erros['zip_code'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
                  if (!isset($this->NM_ajax_info['errList']['zip_code']) || !is_array($this->NM_ajax_info['errList']['zip_code']))
                  {
                      $this->NM_ajax_info['errList']['zip_code'] = array();
                  }
                  $this->NM_ajax_info['errList']['zip_code'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
          } 
      } 
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->zip_code) > 5) 
          { 
              $Campos_Crit .= "ZIP CODE " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 5 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['zip_code']))
              {
                  $Campos_Erros['zip_code'] = array();
              }
              $Campos_Erros['zip_code'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 5 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['zip_code']) || !is_array($this->NM_ajax_info['errList']['zip_code']))
              {
                  $this->NM_ajax_info['errList']['zip_code'] = array();
              }
              $this->NM_ajax_info['errList']['zip_code'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 5 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_zip_code

    function ValidateField_country(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->country) > 15) 
          { 
              $Campos_Crit .= "COUNTRY " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 15 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['country']))
              {
                  $Campos_Erros['country'] = array();
              }
              $Campos_Erros['country'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 15 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['country']) || !is_array($this->NM_ajax_info['errList']['country']))
              {
                  $this->NM_ajax_info['errList']['country'] = array();
              }
              $this->NM_ajax_info['errList']['country'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 15 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_country

    function ValidateField_email(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->email) > 30) 
          { 
              $Campos_Crit .= "EMAIL " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 30 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['email']))
              {
                  $Campos_Erros['email'] = array();
              }
              $Campos_Erros['email'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 30 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['email']) || !is_array($this->NM_ajax_info['errList']['email']))
              {
                  $this->NM_ajax_info['errList']['email'] = array();
              }
              $this->NM_ajax_info['errList']['email'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 30 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_email

    function ValidateField_phone(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->phone) > 10) 
          { 
              $Campos_Crit .= "PHONE " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['phone']))
              {
                  $Campos_Erros['phone'] = array();
              }
              $Campos_Erros['phone'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['phone']) || !is_array($this->NM_ajax_info['errList']['phone']))
              {
                  $this->NM_ajax_info['errList']['phone'] = array();
              }
              $this->NM_ajax_info['errList']['phone'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_phone

    function ValidateField_contact(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->contact) > 25) 
          { 
              $Campos_Crit .= "CONTACT " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['contact']))
              {
                  $Campos_Erros['contact'] = array();
              }
              $Campos_Erros['contact'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['contact']) || !is_array($this->NM_ajax_info['errList']['contact']))
              {
                  $this->NM_ajax_info['errList']['contact'] = array();
              }
              $this->NM_ajax_info['errList']['contact'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_contact

    function ValidateField_fax(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->fax) > 10) 
          { 
              $Campos_Crit .= "FAX " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['fax']))
              {
                  $Campos_Erros['fax'] = array();
              }
              $Campos_Erros['fax'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['fax']) || !is_array($this->NM_ajax_info['errList']['fax']))
              {
                  $this->NM_ajax_info['errList']['fax'] = array();
              }
              $this->NM_ajax_info['errList']['fax'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_fax

    function ValidateField_cphone1(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->cphone1) > 10) 
          { 
              $Campos_Crit .= "CPHONE1 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['cphone1']))
              {
                  $Campos_Erros['cphone1'] = array();
              }
              $Campos_Erros['cphone1'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['cphone1']) || !is_array($this->NM_ajax_info['errList']['cphone1']))
              {
                  $this->NM_ajax_info['errList']['cphone1'] = array();
              }
              $this->NM_ajax_info['errList']['cphone1'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_cphone1

    function ValidateField_cemail1(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->cemail1) > 30) 
          { 
              $Campos_Crit .= "CEMAIL1 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 30 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['cemail1']))
              {
                  $Campos_Erros['cemail1'] = array();
              }
              $Campos_Erros['cemail1'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 30 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['cemail1']) || !is_array($this->NM_ajax_info['errList']['cemail1']))
              {
                  $this->NM_ajax_info['errList']['cemail1'] = array();
              }
              $this->NM_ajax_info['errList']['cemail1'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 30 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_cemail1

    function ValidateField_cfax1(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->cfax1) > 10) 
          { 
              $Campos_Crit .= "CFAX1 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['cfax1']))
              {
                  $Campos_Erros['cfax1'] = array();
              }
              $Campos_Erros['cfax1'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['cfax1']) || !is_array($this->NM_ajax_info['errList']['cfax1']))
              {
                  $this->NM_ajax_info['errList']['cfax1'] = array();
              }
              $this->NM_ajax_info['errList']['cfax1'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_cfax1

    function ValidateField_contact2(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->contact2) > 25) 
          { 
              $Campos_Crit .= "CONTACT2 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['contact2']))
              {
                  $Campos_Erros['contact2'] = array();
              }
              $Campos_Erros['contact2'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['contact2']) || !is_array($this->NM_ajax_info['errList']['contact2']))
              {
                  $this->NM_ajax_info['errList']['contact2'] = array();
              }
              $this->NM_ajax_info['errList']['contact2'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 25 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_contact2

    function ValidateField_cphone2(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->cphone2) > 10) 
          { 
              $Campos_Crit .= "CPHONE2 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['cphone2']))
              {
                  $Campos_Erros['cphone2'] = array();
              }
              $Campos_Erros['cphone2'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['cphone2']) || !is_array($this->NM_ajax_info['errList']['cphone2']))
              {
                  $this->NM_ajax_info['errList']['cphone2'] = array();
              }
              $this->NM_ajax_info['errList']['cphone2'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_cphone2

    function ValidateField_cemail2(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->cemail2) > 30) 
          { 
              $Campos_Crit .= "CEMAIL2 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 30 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['cemail2']))
              {
                  $Campos_Erros['cemail2'] = array();
              }
              $Campos_Erros['cemail2'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 30 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['cemail2']) || !is_array($this->NM_ajax_info['errList']['cemail2']))
              {
                  $this->NM_ajax_info['errList']['cemail2'] = array();
              }
              $this->NM_ajax_info['errList']['cemail2'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 30 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_cemail2

    function ValidateField_cfax2(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->cfax2) > 10) 
          { 
              $Campos_Crit .= "CFAX2 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['cfax2']))
              {
                  $Campos_Erros['cfax2'] = array();
              }
              $Campos_Erros['cfax2'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['cfax2']) || !is_array($this->NM_ajax_info['errList']['cfax2']))
              {
                  $this->NM_ajax_info['errList']['cfax2'] = array();
              }
              $this->NM_ajax_info['errList']['cfax2'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 10 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_cfax2

    function ValidateField_cat1(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir" && (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['cat1']) || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['php_cmp_required']['cat1'] == "on")) 
      { 
          if ($this->cat1 == "")  
          { 
              $Campos_Falta[] =  "CAT1" ; 
              if (!isset($Campos_Erros['cat1']))
              {
                  $Campos_Erros['cat1'] = array();
              }
              $Campos_Erros['cat1'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
                  if (!isset($this->NM_ajax_info['errList']['cat1']) || !is_array($this->NM_ajax_info['errList']['cat1']))
                  {
                      $this->NM_ajax_info['errList']['cat1'] = array();
                  }
                  $this->NM_ajax_info['errList']['cat1'][] = $this->Ini->Nm_lang['lang_errm_ajax_rqrd'];
          } 
      } 
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->cat1) > 4) 
          { 
              $Campos_Crit .= "CAT1 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['cat1']))
              {
                  $Campos_Erros['cat1'] = array();
              }
              $Campos_Erros['cat1'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['cat1']) || !is_array($this->NM_ajax_info['errList']['cat1']))
              {
                  $this->NM_ajax_info['errList']['cat1'] = array();
              }
              $this->NM_ajax_info['errList']['cat1'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_cat1

    function ValidateField_cat2(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->cat2) > 4) 
          { 
              $Campos_Crit .= "CAT2 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['cat2']))
              {
                  $Campos_Erros['cat2'] = array();
              }
              $Campos_Erros['cat2'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['cat2']) || !is_array($this->NM_ajax_info['errList']['cat2']))
              {
                  $this->NM_ajax_info['errList']['cat2'] = array();
              }
              $this->NM_ajax_info['errList']['cat2'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_cat2

    function ValidateField_cat3(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->cat3) > 4) 
          { 
              $Campos_Crit .= "CAT3 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['cat3']))
              {
                  $Campos_Erros['cat3'] = array();
              }
              $Campos_Erros['cat3'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['cat3']) || !is_array($this->NM_ajax_info['errList']['cat3']))
              {
                  $this->NM_ajax_info['errList']['cat3'] = array();
              }
              $this->NM_ajax_info['errList']['cat3'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_cat3

    function ValidateField_cat4(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->cat4) > 4) 
          { 
              $Campos_Crit .= "CAT4 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['cat4']))
              {
                  $Campos_Erros['cat4'] = array();
              }
              $Campos_Erros['cat4'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['cat4']) || !is_array($this->NM_ajax_info['errList']['cat4']))
              {
                  $this->NM_ajax_info['errList']['cat4'] = array();
              }
              $this->NM_ajax_info['errList']['cat4'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_cat4

    function ValidateField_cat5(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->cat5) > 4) 
          { 
              $Campos_Crit .= "CAT5 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['cat5']))
              {
                  $Campos_Erros['cat5'] = array();
              }
              $Campos_Erros['cat5'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['cat5']) || !is_array($this->NM_ajax_info['errList']['cat5']))
              {
                  $this->NM_ajax_info['errList']['cat5'] = array();
              }
              $this->NM_ajax_info['errList']['cat5'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_cat5

    function ValidateField_cat6(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->cat6) > 4) 
          { 
              $Campos_Crit .= "CAT6 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['cat6']))
              {
                  $Campos_Erros['cat6'] = array();
              }
              $Campos_Erros['cat6'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['cat6']) || !is_array($this->NM_ajax_info['errList']['cat6']))
              {
                  $this->NM_ajax_info['errList']['cat6'] = array();
              }
              $this->NM_ajax_info['errList']['cat6'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_cat6

    function ValidateField_cat7(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->cat7) > 4) 
          { 
              $Campos_Crit .= "CAT7 " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['cat7']))
              {
                  $Campos_Erros['cat7'] = array();
              }
              $Campos_Erros['cat7'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['cat7']) || !is_array($this->NM_ajax_info['errList']['cat7']))
              {
                  $this->NM_ajax_info['errList']['cat7'] = array();
              }
              $this->NM_ajax_info['errList']['cat7'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 4 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_cat7

    function ValidateField_mtd(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->mtd == "")  
      { 
          $this->mtd = 0;
          $this->sc_force_zero[] = 'mtd';
      } 
      if (!empty($this->field_config['mtd']['symbol_dec']))
      {
          $this->sc_remove_currency($this->mtd, $this->field_config['mtd']['symbol_dec'], $this->field_config['mtd']['symbol_grp'], $this->field_config['mtd']['symbol_mon']); 
          nm_limpa_valor($this->mtd, $this->field_config['mtd']['symbol_dec'], $this->field_config['mtd']['symbol_grp']) ; 
          if ('.' == substr($this->mtd, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->mtd, 1)))
              {
                  $this->mtd = '';
              }
              else
              {
                  $this->mtd = '0' . $this->mtd;
              }
          }
      }
      if ($this->nmgp_opcao == "incluir")
      { 
          if ($this->mtd != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->mtd) > $iTestSize)  
              { 
                  $Campos_Crit .= "MTD: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['mtd']))
                  {
                      $Campos_Erros['mtd'] = array();
                  }
                  $Campos_Erros['mtd'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['mtd']) || !is_array($this->NM_ajax_info['errList']['mtd']))
                  {
                      $this->NM_ajax_info['errList']['mtd'] = array();
                  }
                  $this->NM_ajax_info['errList']['mtd'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->mtd, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "MTD; " ; 
                  if (!isset($Campos_Erros['mtd']))
                  {
                      $Campos_Erros['mtd'] = array();
                  }
                  $Campos_Erros['mtd'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['mtd']) || !is_array($this->NM_ajax_info['errList']['mtd']))
                  {
                      $this->NM_ajax_info['errList']['mtd'] = array();
                  }
                  $this->NM_ajax_info['errList']['mtd'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_mtd

    function ValidateField_qtd(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->qtd == "")  
      { 
          $this->qtd = 0;
          $this->sc_force_zero[] = 'qtd';
      } 
      if (!empty($this->field_config['qtd']['symbol_dec']))
      {
          $this->sc_remove_currency($this->qtd, $this->field_config['qtd']['symbol_dec'], $this->field_config['qtd']['symbol_grp'], $this->field_config['qtd']['symbol_mon']); 
          nm_limpa_valor($this->qtd, $this->field_config['qtd']['symbol_dec'], $this->field_config['qtd']['symbol_grp']) ; 
          if ('.' == substr($this->qtd, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->qtd, 1)))
              {
                  $this->qtd = '';
              }
              else
              {
                  $this->qtd = '0' . $this->qtd;
              }
          }
      }
      if ($this->nmgp_opcao == "incluir")
      { 
          if ($this->qtd != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->qtd) > $iTestSize)  
              { 
                  $Campos_Crit .= "QTD: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['qtd']))
                  {
                      $Campos_Erros['qtd'] = array();
                  }
                  $Campos_Erros['qtd'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['qtd']) || !is_array($this->NM_ajax_info['errList']['qtd']))
                  {
                      $this->NM_ajax_info['errList']['qtd'] = array();
                  }
                  $this->NM_ajax_info['errList']['qtd'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->qtd, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "QTD; " ; 
                  if (!isset($Campos_Erros['qtd']))
                  {
                      $Campos_Erros['qtd'] = array();
                  }
                  $Campos_Erros['qtd'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['qtd']) || !is_array($this->NM_ajax_info['errList']['qtd']))
                  {
                      $this->NM_ajax_info['errList']['qtd'] = array();
                  }
                  $this->NM_ajax_info['errList']['qtd'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_qtd

    function ValidateField_ytd(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->ytd == "")  
      { 
          $this->ytd = 0;
          $this->sc_force_zero[] = 'ytd';
      } 
      if (!empty($this->field_config['ytd']['symbol_dec']))
      {
          $this->sc_remove_currency($this->ytd, $this->field_config['ytd']['symbol_dec'], $this->field_config['ytd']['symbol_grp'], $this->field_config['ytd']['symbol_mon']); 
          nm_limpa_valor($this->ytd, $this->field_config['ytd']['symbol_dec'], $this->field_config['ytd']['symbol_grp']) ; 
          if ('.' == substr($this->ytd, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->ytd, 1)))
              {
                  $this->ytd = '';
              }
              else
              {
                  $this->ytd = '0' . $this->ytd;
              }
          }
      }
      if ($this->nmgp_opcao == "incluir")
      { 
          if ($this->ytd != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->ytd) > $iTestSize)  
              { 
                  $Campos_Crit .= "YTD: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['ytd']))
                  {
                      $Campos_Erros['ytd'] = array();
                  }
                  $Campos_Erros['ytd'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['ytd']) || !is_array($this->NM_ajax_info['errList']['ytd']))
                  {
                      $this->NM_ajax_info['errList']['ytd'] = array();
                  }
                  $this->NM_ajax_info['errList']['ytd'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->ytd, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "YTD; " ; 
                  if (!isset($Campos_Erros['ytd']))
                  {
                      $Campos_Erros['ytd'] = array();
                  }
                  $Campos_Erros['ytd'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['ytd']) || !is_array($this->NM_ajax_info['errList']['ytd']))
                  {
                      $this->NM_ajax_info['errList']['ytd'] = array();
                  }
                  $this->NM_ajax_info['errList']['ytd'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_ytd

    function ValidateField_jan(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->jan == "")  
      { 
          $this->jan = 0;
          $this->sc_force_zero[] = 'jan';
      } 
      if (!empty($this->field_config['jan']['symbol_dec']))
      {
          $this->sc_remove_currency($this->jan, $this->field_config['jan']['symbol_dec'], $this->field_config['jan']['symbol_grp'], $this->field_config['jan']['symbol_mon']); 
          nm_limpa_valor($this->jan, $this->field_config['jan']['symbol_dec'], $this->field_config['jan']['symbol_grp']) ; 
          if ('.' == substr($this->jan, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->jan, 1)))
              {
                  $this->jan = '';
              }
              else
              {
                  $this->jan = '0' . $this->jan;
              }
          }
      }
      if ($this->nmgp_opcao == "incluir")
      { 
          if ($this->jan != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->jan) > $iTestSize)  
              { 
                  $Campos_Crit .= "JAN: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['jan']))
                  {
                      $Campos_Erros['jan'] = array();
                  }
                  $Campos_Erros['jan'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['jan']) || !is_array($this->NM_ajax_info['errList']['jan']))
                  {
                      $this->NM_ajax_info['errList']['jan'] = array();
                  }
                  $this->NM_ajax_info['errList']['jan'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->jan, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "JAN; " ; 
                  if (!isset($Campos_Erros['jan']))
                  {
                      $Campos_Erros['jan'] = array();
                  }
                  $Campos_Erros['jan'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['jan']) || !is_array($this->NM_ajax_info['errList']['jan']))
                  {
                      $this->NM_ajax_info['errList']['jan'] = array();
                  }
                  $this->NM_ajax_info['errList']['jan'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_jan

    function ValidateField_feb(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->feb == "")  
      { 
          $this->feb = 0;
          $this->sc_force_zero[] = 'feb';
      } 
      if (!empty($this->field_config['feb']['symbol_dec']))
      {
          $this->sc_remove_currency($this->feb, $this->field_config['feb']['symbol_dec'], $this->field_config['feb']['symbol_grp'], $this->field_config['feb']['symbol_mon']); 
          nm_limpa_valor($this->feb, $this->field_config['feb']['symbol_dec'], $this->field_config['feb']['symbol_grp']) ; 
          if ('.' == substr($this->feb, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->feb, 1)))
              {
                  $this->feb = '';
              }
              else
              {
                  $this->feb = '0' . $this->feb;
              }
          }
      }
      if ($this->nmgp_opcao == "incluir")
      { 
          if ($this->feb != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->feb) > $iTestSize)  
              { 
                  $Campos_Crit .= "FEB: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['feb']))
                  {
                      $Campos_Erros['feb'] = array();
                  }
                  $Campos_Erros['feb'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['feb']) || !is_array($this->NM_ajax_info['errList']['feb']))
                  {
                      $this->NM_ajax_info['errList']['feb'] = array();
                  }
                  $this->NM_ajax_info['errList']['feb'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->feb, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "FEB; " ; 
                  if (!isset($Campos_Erros['feb']))
                  {
                      $Campos_Erros['feb'] = array();
                  }
                  $Campos_Erros['feb'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['feb']) || !is_array($this->NM_ajax_info['errList']['feb']))
                  {
                      $this->NM_ajax_info['errList']['feb'] = array();
                  }
                  $this->NM_ajax_info['errList']['feb'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_feb

    function ValidateField_mar(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->mar == "")  
      { 
          $this->mar = 0;
          $this->sc_force_zero[] = 'mar';
      } 
      if (!empty($this->field_config['mar']['symbol_dec']))
      {
          $this->sc_remove_currency($this->mar, $this->field_config['mar']['symbol_dec'], $this->field_config['mar']['symbol_grp'], $this->field_config['mar']['symbol_mon']); 
          nm_limpa_valor($this->mar, $this->field_config['mar']['symbol_dec'], $this->field_config['mar']['symbol_grp']) ; 
          if ('.' == substr($this->mar, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->mar, 1)))
              {
                  $this->mar = '';
              }
              else
              {
                  $this->mar = '0' . $this->mar;
              }
          }
      }
      if ($this->nmgp_opcao == "incluir")
      { 
          if ($this->mar != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->mar) > $iTestSize)  
              { 
                  $Campos_Crit .= "MAR: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['mar']))
                  {
                      $Campos_Erros['mar'] = array();
                  }
                  $Campos_Erros['mar'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['mar']) || !is_array($this->NM_ajax_info['errList']['mar']))
                  {
                      $this->NM_ajax_info['errList']['mar'] = array();
                  }
                  $this->NM_ajax_info['errList']['mar'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->mar, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "MAR; " ; 
                  if (!isset($Campos_Erros['mar']))
                  {
                      $Campos_Erros['mar'] = array();
                  }
                  $Campos_Erros['mar'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['mar']) || !is_array($this->NM_ajax_info['errList']['mar']))
                  {
                      $this->NM_ajax_info['errList']['mar'] = array();
                  }
                  $this->NM_ajax_info['errList']['mar'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_mar

    function ValidateField_apr(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->apr == "")  
      { 
          $this->apr = 0;
          $this->sc_force_zero[] = 'apr';
      } 
      if (!empty($this->field_config['apr']['symbol_dec']))
      {
          $this->sc_remove_currency($this->apr, $this->field_config['apr']['symbol_dec'], $this->field_config['apr']['symbol_grp'], $this->field_config['apr']['symbol_mon']); 
          nm_limpa_valor($this->apr, $this->field_config['apr']['symbol_dec'], $this->field_config['apr']['symbol_grp']) ; 
          if ('.' == substr($this->apr, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->apr, 1)))
              {
                  $this->apr = '';
              }
              else
              {
                  $this->apr = '0' . $this->apr;
              }
          }
      }
      if ($this->nmgp_opcao == "incluir")
      { 
          if ($this->apr != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->apr) > $iTestSize)  
              { 
                  $Campos_Crit .= "APR: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['apr']))
                  {
                      $Campos_Erros['apr'] = array();
                  }
                  $Campos_Erros['apr'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['apr']) || !is_array($this->NM_ajax_info['errList']['apr']))
                  {
                      $this->NM_ajax_info['errList']['apr'] = array();
                  }
                  $this->NM_ajax_info['errList']['apr'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->apr, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "APR; " ; 
                  if (!isset($Campos_Erros['apr']))
                  {
                      $Campos_Erros['apr'] = array();
                  }
                  $Campos_Erros['apr'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['apr']) || !is_array($this->NM_ajax_info['errList']['apr']))
                  {
                      $this->NM_ajax_info['errList']['apr'] = array();
                  }
                  $this->NM_ajax_info['errList']['apr'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_apr

    function ValidateField_may(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->may == "")  
      { 
          $this->may = 0;
          $this->sc_force_zero[] = 'may';
      } 
      if (!empty($this->field_config['may']['symbol_dec']))
      {
          $this->sc_remove_currency($this->may, $this->field_config['may']['symbol_dec'], $this->field_config['may']['symbol_grp'], $this->field_config['may']['symbol_mon']); 
          nm_limpa_valor($this->may, $this->field_config['may']['symbol_dec'], $this->field_config['may']['symbol_grp']) ; 
          if ('.' == substr($this->may, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->may, 1)))
              {
                  $this->may = '';
              }
              else
              {
                  $this->may = '0' . $this->may;
              }
          }
      }
      if ($this->nmgp_opcao == "incluir")
      { 
          if ($this->may != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->may) > $iTestSize)  
              { 
                  $Campos_Crit .= "MAY: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['may']))
                  {
                      $Campos_Erros['may'] = array();
                  }
                  $Campos_Erros['may'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['may']) || !is_array($this->NM_ajax_info['errList']['may']))
                  {
                      $this->NM_ajax_info['errList']['may'] = array();
                  }
                  $this->NM_ajax_info['errList']['may'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->may, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "MAY; " ; 
                  if (!isset($Campos_Erros['may']))
                  {
                      $Campos_Erros['may'] = array();
                  }
                  $Campos_Erros['may'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['may']) || !is_array($this->NM_ajax_info['errList']['may']))
                  {
                      $this->NM_ajax_info['errList']['may'] = array();
                  }
                  $this->NM_ajax_info['errList']['may'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_may

    function ValidateField_jun(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->jun == "")  
      { 
          $this->jun = 0;
          $this->sc_force_zero[] = 'jun';
      } 
      if (!empty($this->field_config['jun']['symbol_dec']))
      {
          $this->sc_remove_currency($this->jun, $this->field_config['jun']['symbol_dec'], $this->field_config['jun']['symbol_grp'], $this->field_config['jun']['symbol_mon']); 
          nm_limpa_valor($this->jun, $this->field_config['jun']['symbol_dec'], $this->field_config['jun']['symbol_grp']) ; 
          if ('.' == substr($this->jun, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->jun, 1)))
              {
                  $this->jun = '';
              }
              else
              {
                  $this->jun = '0' . $this->jun;
              }
          }
      }
      if ($this->nmgp_opcao == "incluir")
      { 
          if ($this->jun != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->jun) > $iTestSize)  
              { 
                  $Campos_Crit .= "JUN: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['jun']))
                  {
                      $Campos_Erros['jun'] = array();
                  }
                  $Campos_Erros['jun'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['jun']) || !is_array($this->NM_ajax_info['errList']['jun']))
                  {
                      $this->NM_ajax_info['errList']['jun'] = array();
                  }
                  $this->NM_ajax_info['errList']['jun'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->jun, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "JUN; " ; 
                  if (!isset($Campos_Erros['jun']))
                  {
                      $Campos_Erros['jun'] = array();
                  }
                  $Campos_Erros['jun'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['jun']) || !is_array($this->NM_ajax_info['errList']['jun']))
                  {
                      $this->NM_ajax_info['errList']['jun'] = array();
                  }
                  $this->NM_ajax_info['errList']['jun'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_jun

    function ValidateField_jul(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->jul == "")  
      { 
          $this->jul = 0;
          $this->sc_force_zero[] = 'jul';
      } 
      if (!empty($this->field_config['jul']['symbol_dec']))
      {
          $this->sc_remove_currency($this->jul, $this->field_config['jul']['symbol_dec'], $this->field_config['jul']['symbol_grp'], $this->field_config['jul']['symbol_mon']); 
          nm_limpa_valor($this->jul, $this->field_config['jul']['symbol_dec'], $this->field_config['jul']['symbol_grp']) ; 
          if ('.' == substr($this->jul, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->jul, 1)))
              {
                  $this->jul = '';
              }
              else
              {
                  $this->jul = '0' . $this->jul;
              }
          }
      }
      if ($this->nmgp_opcao == "incluir")
      { 
          if ($this->jul != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->jul) > $iTestSize)  
              { 
                  $Campos_Crit .= "JUL: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['jul']))
                  {
                      $Campos_Erros['jul'] = array();
                  }
                  $Campos_Erros['jul'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['jul']) || !is_array($this->NM_ajax_info['errList']['jul']))
                  {
                      $this->NM_ajax_info['errList']['jul'] = array();
                  }
                  $this->NM_ajax_info['errList']['jul'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->jul, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "JUL; " ; 
                  if (!isset($Campos_Erros['jul']))
                  {
                      $Campos_Erros['jul'] = array();
                  }
                  $Campos_Erros['jul'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['jul']) || !is_array($this->NM_ajax_info['errList']['jul']))
                  {
                      $this->NM_ajax_info['errList']['jul'] = array();
                  }
                  $this->NM_ajax_info['errList']['jul'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_jul

    function ValidateField_aug(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->aug == "")  
      { 
          $this->aug = 0;
          $this->sc_force_zero[] = 'aug';
      } 
      if (!empty($this->field_config['aug']['symbol_dec']))
      {
          $this->sc_remove_currency($this->aug, $this->field_config['aug']['symbol_dec'], $this->field_config['aug']['symbol_grp'], $this->field_config['aug']['symbol_mon']); 
          nm_limpa_valor($this->aug, $this->field_config['aug']['symbol_dec'], $this->field_config['aug']['symbol_grp']) ; 
          if ('.' == substr($this->aug, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->aug, 1)))
              {
                  $this->aug = '';
              }
              else
              {
                  $this->aug = '0' . $this->aug;
              }
          }
      }
      if ($this->nmgp_opcao == "incluir")
      { 
          if ($this->aug != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->aug) > $iTestSize)  
              { 
                  $Campos_Crit .= "AUG: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['aug']))
                  {
                      $Campos_Erros['aug'] = array();
                  }
                  $Campos_Erros['aug'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['aug']) || !is_array($this->NM_ajax_info['errList']['aug']))
                  {
                      $this->NM_ajax_info['errList']['aug'] = array();
                  }
                  $this->NM_ajax_info['errList']['aug'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->aug, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "AUG; " ; 
                  if (!isset($Campos_Erros['aug']))
                  {
                      $Campos_Erros['aug'] = array();
                  }
                  $Campos_Erros['aug'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['aug']) || !is_array($this->NM_ajax_info['errList']['aug']))
                  {
                      $this->NM_ajax_info['errList']['aug'] = array();
                  }
                  $this->NM_ajax_info['errList']['aug'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_aug

    function ValidateField_sep(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->sep == "")  
      { 
          $this->sep = 0;
          $this->sc_force_zero[] = 'sep';
      } 
      if (!empty($this->field_config['sep']['symbol_dec']))
      {
          $this->sc_remove_currency($this->sep, $this->field_config['sep']['symbol_dec'], $this->field_config['sep']['symbol_grp'], $this->field_config['sep']['symbol_mon']); 
          nm_limpa_valor($this->sep, $this->field_config['sep']['symbol_dec'], $this->field_config['sep']['symbol_grp']) ; 
          if ('.' == substr($this->sep, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->sep, 1)))
              {
                  $this->sep = '';
              }
              else
              {
                  $this->sep = '0' . $this->sep;
              }
          }
      }
      if ($this->nmgp_opcao != "excluir") 
      { 
          if ($this->sep != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->sep) > $iTestSize)  
              { 
                  $Campos_Crit .= "SEP: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['sep']))
                  {
                      $Campos_Erros['sep'] = array();
                  }
                  $Campos_Erros['sep'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['sep']) || !is_array($this->NM_ajax_info['errList']['sep']))
                  {
                      $this->NM_ajax_info['errList']['sep'] = array();
                  }
                  $this->NM_ajax_info['errList']['sep'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->sep, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "SEP; " ; 
                  if (!isset($Campos_Erros['sep']))
                  {
                      $Campos_Erros['sep'] = array();
                  }
                  $Campos_Erros['sep'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['sep']) || !is_array($this->NM_ajax_info['errList']['sep']))
                  {
                      $this->NM_ajax_info['errList']['sep'] = array();
                  }
                  $this->NM_ajax_info['errList']['sep'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_sep

    function ValidateField_oct(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->oct == "")  
      { 
          $this->oct = 0;
          $this->sc_force_zero[] = 'oct';
      } 
      if (!empty($this->field_config['oct']['symbol_dec']))
      {
          $this->sc_remove_currency($this->oct, $this->field_config['oct']['symbol_dec'], $this->field_config['oct']['symbol_grp'], $this->field_config['oct']['symbol_mon']); 
          nm_limpa_valor($this->oct, $this->field_config['oct']['symbol_dec'], $this->field_config['oct']['symbol_grp']) ; 
          if ('.' == substr($this->oct, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->oct, 1)))
              {
                  $this->oct = '';
              }
              else
              {
                  $this->oct = '0' . $this->oct;
              }
          }
      }
      if ($this->nmgp_opcao != "excluir") 
      { 
          if ($this->oct != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->oct) > $iTestSize)  
              { 
                  $Campos_Crit .= "OCT: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['oct']))
                  {
                      $Campos_Erros['oct'] = array();
                  }
                  $Campos_Erros['oct'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['oct']) || !is_array($this->NM_ajax_info['errList']['oct']))
                  {
                      $this->NM_ajax_info['errList']['oct'] = array();
                  }
                  $this->NM_ajax_info['errList']['oct'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->oct, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "OCT; " ; 
                  if (!isset($Campos_Erros['oct']))
                  {
                      $Campos_Erros['oct'] = array();
                  }
                  $Campos_Erros['oct'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['oct']) || !is_array($this->NM_ajax_info['errList']['oct']))
                  {
                      $this->NM_ajax_info['errList']['oct'] = array();
                  }
                  $this->NM_ajax_info['errList']['oct'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_oct

    function ValidateField_nov(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nov == "")  
      { 
          $this->nov = 0;
          $this->sc_force_zero[] = 'nov';
      } 
      if (!empty($this->field_config['nov']['symbol_dec']))
      {
          $this->sc_remove_currency($this->nov, $this->field_config['nov']['symbol_dec'], $this->field_config['nov']['symbol_grp'], $this->field_config['nov']['symbol_mon']); 
          nm_limpa_valor($this->nov, $this->field_config['nov']['symbol_dec'], $this->field_config['nov']['symbol_grp']) ; 
          if ('.' == substr($this->nov, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->nov, 1)))
              {
                  $this->nov = '';
              }
              else
              {
                  $this->nov = '0' . $this->nov;
              }
          }
      }
      if ($this->nmgp_opcao != "excluir") 
      { 
          if ($this->nov != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->nov) > $iTestSize)  
              { 
                  $Campos_Crit .= "NOV: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['nov']))
                  {
                      $Campos_Erros['nov'] = array();
                  }
                  $Campos_Erros['nov'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['nov']) || !is_array($this->NM_ajax_info['errList']['nov']))
                  {
                      $this->NM_ajax_info['errList']['nov'] = array();
                  }
                  $this->NM_ajax_info['errList']['nov'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->nov, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "NOV; " ; 
                  if (!isset($Campos_Erros['nov']))
                  {
                      $Campos_Erros['nov'] = array();
                  }
                  $Campos_Erros['nov'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['nov']) || !is_array($this->NM_ajax_info['errList']['nov']))
                  {
                      $this->NM_ajax_info['errList']['nov'] = array();
                  }
                  $this->NM_ajax_info['errList']['nov'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_nov

    function ValidateField_dec(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->dec == "")  
      { 
          $this->dec = 0;
          $this->sc_force_zero[] = 'dec';
      } 
      if (!empty($this->field_config['dec']['symbol_dec']))
      {
          $this->sc_remove_currency($this->dec, $this->field_config['dec']['symbol_dec'], $this->field_config['dec']['symbol_grp'], $this->field_config['dec']['symbol_mon']); 
          nm_limpa_valor($this->dec, $this->field_config['dec']['symbol_dec'], $this->field_config['dec']['symbol_grp']) ; 
          if ('.' == substr($this->dec, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->dec, 1)))
              {
                  $this->dec = '';
              }
              else
              {
                  $this->dec = '0' . $this->dec;
              }
          }
      }
      if ($this->nmgp_opcao != "excluir") 
      { 
          if ($this->dec != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->dec) > $iTestSize)  
              { 
                  $Campos_Crit .= "DEC: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['dec']))
                  {
                      $Campos_Erros['dec'] = array();
                  }
                  $Campos_Erros['dec'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['dec']) || !is_array($this->NM_ajax_info['errList']['dec']))
                  {
                      $this->NM_ajax_info['errList']['dec'] = array();
                  }
                  $this->NM_ajax_info['errList']['dec'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->dec, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "DEC; " ; 
                  if (!isset($Campos_Erros['dec']))
                  {
                      $Campos_Erros['dec'] = array();
                  }
                  $Campos_Erros['dec'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['dec']) || !is_array($this->NM_ajax_info['errList']['dec']))
                  {
                      $this->NM_ajax_info['errList']['dec'] = array();
                  }
                  $this->NM_ajax_info['errList']['dec'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_dec

    function ValidateField_lyear(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->lyear == "")  
      { 
          $this->lyear = 0;
          $this->sc_force_zero[] = 'lyear';
      } 
      if (!empty($this->field_config['lyear']['symbol_dec']))
      {
          $this->sc_remove_currency($this->lyear, $this->field_config['lyear']['symbol_dec'], $this->field_config['lyear']['symbol_grp'], $this->field_config['lyear']['symbol_mon']); 
          nm_limpa_valor($this->lyear, $this->field_config['lyear']['symbol_dec'], $this->field_config['lyear']['symbol_grp']) ; 
          if ('.' == substr($this->lyear, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->lyear, 1)))
              {
                  $this->lyear = '';
              }
              else
              {
                  $this->lyear = '0' . $this->lyear;
              }
          }
      }
      if ($this->nmgp_opcao != "excluir") 
      { 
          if ($this->lyear != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->lyear) > $iTestSize)  
              { 
                  $Campos_Crit .= "LYEAR: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['lyear']))
                  {
                      $Campos_Erros['lyear'] = array();
                  }
                  $Campos_Erros['lyear'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['lyear']) || !is_array($this->NM_ajax_info['errList']['lyear']))
                  {
                      $this->NM_ajax_info['errList']['lyear'] = array();
                  }
                  $this->NM_ajax_info['errList']['lyear'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->lyear, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "LYEAR; " ; 
                  if (!isset($Campos_Erros['lyear']))
                  {
                      $Campos_Erros['lyear'] = array();
                  }
                  $Campos_Erros['lyear'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['lyear']) || !is_array($this->NM_ajax_info['errList']['lyear']))
                  {
                      $this->NM_ajax_info['errList']['lyear'] = array();
                  }
                  $this->NM_ajax_info['errList']['lyear'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_lyear

    function ValidateField_llyear(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->llyear == "")  
      { 
          $this->llyear = 0;
          $this->sc_force_zero[] = 'llyear';
      } 
      if (!empty($this->field_config['llyear']['symbol_dec']))
      {
          $this->sc_remove_currency($this->llyear, $this->field_config['llyear']['symbol_dec'], $this->field_config['llyear']['symbol_grp'], $this->field_config['llyear']['symbol_mon']); 
          nm_limpa_valor($this->llyear, $this->field_config['llyear']['symbol_dec'], $this->field_config['llyear']['symbol_grp']) ; 
          if ('.' == substr($this->llyear, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->llyear, 1)))
              {
                  $this->llyear = '';
              }
              else
              {
                  $this->llyear = '0' . $this->llyear;
              }
          }
      }
      if ($this->nmgp_opcao != "excluir") 
      { 
          if ($this->llyear != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->llyear) > $iTestSize)  
              { 
                  $Campos_Crit .= "LLYEAR: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['llyear']))
                  {
                      $Campos_Erros['llyear'] = array();
                  }
                  $Campos_Erros['llyear'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['llyear']) || !is_array($this->NM_ajax_info['errList']['llyear']))
                  {
                      $this->NM_ajax_info['errList']['llyear'] = array();
                  }
                  $this->NM_ajax_info['errList']['llyear'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->llyear, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "LLYEAR; " ; 
                  if (!isset($Campos_Erros['llyear']))
                  {
                      $Campos_Erros['llyear'] = array();
                  }
                  $Campos_Erros['llyear'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['llyear']) || !is_array($this->NM_ajax_info['errList']['llyear']))
                  {
                      $this->NM_ajax_info['errList']['llyear'] = array();
                  }
                  $this->NM_ajax_info['errList']['llyear'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_llyear

    function ValidateField_q1(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->q1 == "")  
      { 
          $this->q1 = 0;
          $this->sc_force_zero[] = 'q1';
      } 
      if (!empty($this->field_config['q1']['symbol_dec']))
      {
          $this->sc_remove_currency($this->q1, $this->field_config['q1']['symbol_dec'], $this->field_config['q1']['symbol_grp'], $this->field_config['q1']['symbol_mon']); 
          nm_limpa_valor($this->q1, $this->field_config['q1']['symbol_dec'], $this->field_config['q1']['symbol_grp']) ; 
          if ('.' == substr($this->q1, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->q1, 1)))
              {
                  $this->q1 = '';
              }
              else
              {
                  $this->q1 = '0' . $this->q1;
              }
          }
      }
      if ($this->nmgp_opcao != "excluir") 
      { 
          if ($this->q1 != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->q1) > $iTestSize)  
              { 
                  $Campos_Crit .= "Q1: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['q1']))
                  {
                      $Campos_Erros['q1'] = array();
                  }
                  $Campos_Erros['q1'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['q1']) || !is_array($this->NM_ajax_info['errList']['q1']))
                  {
                      $this->NM_ajax_info['errList']['q1'] = array();
                  }
                  $this->NM_ajax_info['errList']['q1'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->q1, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "Q1; " ; 
                  if (!isset($Campos_Erros['q1']))
                  {
                      $Campos_Erros['q1'] = array();
                  }
                  $Campos_Erros['q1'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['q1']) || !is_array($this->NM_ajax_info['errList']['q1']))
                  {
                      $this->NM_ajax_info['errList']['q1'] = array();
                  }
                  $this->NM_ajax_info['errList']['q1'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_q1

    function ValidateField_q2(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->q2 == "")  
      { 
          $this->q2 = 0;
          $this->sc_force_zero[] = 'q2';
      } 
      if (!empty($this->field_config['q2']['symbol_dec']))
      {
          $this->sc_remove_currency($this->q2, $this->field_config['q2']['symbol_dec'], $this->field_config['q2']['symbol_grp'], $this->field_config['q2']['symbol_mon']); 
          nm_limpa_valor($this->q2, $this->field_config['q2']['symbol_dec'], $this->field_config['q2']['symbol_grp']) ; 
          if ('.' == substr($this->q2, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->q2, 1)))
              {
                  $this->q2 = '';
              }
              else
              {
                  $this->q2 = '0' . $this->q2;
              }
          }
      }
      if ($this->nmgp_opcao != "excluir") 
      { 
          if ($this->q2 != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->q2) > $iTestSize)  
              { 
                  $Campos_Crit .= "Q2: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['q2']))
                  {
                      $Campos_Erros['q2'] = array();
                  }
                  $Campos_Erros['q2'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['q2']) || !is_array($this->NM_ajax_info['errList']['q2']))
                  {
                      $this->NM_ajax_info['errList']['q2'] = array();
                  }
                  $this->NM_ajax_info['errList']['q2'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->q2, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "Q2; " ; 
                  if (!isset($Campos_Erros['q2']))
                  {
                      $Campos_Erros['q2'] = array();
                  }
                  $Campos_Erros['q2'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['q2']) || !is_array($this->NM_ajax_info['errList']['q2']))
                  {
                      $this->NM_ajax_info['errList']['q2'] = array();
                  }
                  $this->NM_ajax_info['errList']['q2'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_q2

    function ValidateField_q4(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->q4 == "")  
      { 
          $this->q4 = 0;
          $this->sc_force_zero[] = 'q4';
      } 
      if (!empty($this->field_config['q4']['symbol_dec']))
      {
          $this->sc_remove_currency($this->q4, $this->field_config['q4']['symbol_dec'], $this->field_config['q4']['symbol_grp'], $this->field_config['q4']['symbol_mon']); 
          nm_limpa_valor($this->q4, $this->field_config['q4']['symbol_dec'], $this->field_config['q4']['symbol_grp']) ; 
          if ('.' == substr($this->q4, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->q4, 1)))
              {
                  $this->q4 = '';
              }
              else
              {
                  $this->q4 = '0' . $this->q4;
              }
          }
      }
      if ($this->nmgp_opcao != "excluir") 
      { 
          if ($this->q4 != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->q4) > $iTestSize)  
              { 
                  $Campos_Crit .= "Q4: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['q4']))
                  {
                      $Campos_Erros['q4'] = array();
                  }
                  $Campos_Erros['q4'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['q4']) || !is_array($this->NM_ajax_info['errList']['q4']))
                  {
                      $this->NM_ajax_info['errList']['q4'] = array();
                  }
                  $this->NM_ajax_info['errList']['q4'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->q4, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "Q4; " ; 
                  if (!isset($Campos_Erros['q4']))
                  {
                      $Campos_Erros['q4'] = array();
                  }
                  $Campos_Erros['q4'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['q4']) || !is_array($this->NM_ajax_info['errList']['q4']))
                  {
                      $this->NM_ajax_info['errList']['q4'] = array();
                  }
                  $this->NM_ajax_info['errList']['q4'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_q4

    function ValidateField_q3(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->q3 == "")  
      { 
          $this->q3 = 0;
          $this->sc_force_zero[] = 'q3';
      } 
      if (!empty($this->field_config['q3']['symbol_dec']))
      {
          $this->sc_remove_currency($this->q3, $this->field_config['q3']['symbol_dec'], $this->field_config['q3']['symbol_grp'], $this->field_config['q3']['symbol_mon']); 
          nm_limpa_valor($this->q3, $this->field_config['q3']['symbol_dec'], $this->field_config['q3']['symbol_grp']) ; 
          if ('.' == substr($this->q3, 0, 1))
          {
              if ('' == str_replace('0', '', substr($this->q3, 1)))
              {
                  $this->q3 = '';
              }
              else
              {
                  $this->q3 = '0' . $this->q3;
              }
          }
      }
      if ($this->nmgp_opcao != "excluir") 
      { 
          if ($this->q3 != '')  
          { 
              $iTestSize = 12;
              if (strlen($this->q3) > $iTestSize)  
              { 
                  $Campos_Crit .= "Q3: " . $this->Ini->Nm_lang['lang_errm_size']; 
                  if (!isset($Campos_Erros['q3']))
                  {
                      $Campos_Erros['q3'] = array();
                  }
                  $Campos_Erros['q3'][] = $this->Ini->Nm_lang['lang_errm_size'];
                  if (!isset($this->NM_ajax_info['errList']['q3']) || !is_array($this->NM_ajax_info['errList']['q3']))
                  {
                      $this->NM_ajax_info['errList']['q3'] = array();
                  }
                  $this->NM_ajax_info['errList']['q3'][] = $this->Ini->Nm_lang['lang_errm_size'];
              } 
              if ($teste_validade->Valor($this->q3, 9, 2, 0, 0, "N") == false)  
              { 
                  $Campos_Crit .= "Q3; " ; 
                  if (!isset($Campos_Erros['q3']))
                  {
                      $Campos_Erros['q3'] = array();
                  }
                  $Campos_Erros['q3'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
                  if (!isset($this->NM_ajax_info['errList']['q3']) || !is_array($this->NM_ajax_info['errList']['q3']))
                  {
                      $this->NM_ajax_info['errList']['q3'] = array();
                  }
                  $this->NM_ajax_info['errList']['q3'][] = "" . $this->Ini->Nm_lang['lang_errm_ajax_data'] . "";
              } 
          } 
      } 
    } // ValidateField_q3

    function ValidateField_memo(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (NM_utf8_strlen($this->memo) > 32767) 
          { 
              $Campos_Crit .= "MEMO " . $this->Ini->Nm_lang['lang_errm_mxch'] . " 32767 " . $this->Ini->Nm_lang['lang_errm_nchr']; 
              if (!isset($Campos_Erros['memo']))
              {
                  $Campos_Erros['memo'] = array();
              }
              $Campos_Erros['memo'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 32767 " . $this->Ini->Nm_lang['lang_errm_nchr'];
              if (!isset($this->NM_ajax_info['errList']['memo']) || !is_array($this->NM_ajax_info['errList']['memo']))
              {
                  $this->NM_ajax_info['errList']['memo'] = array();
              }
              $this->NM_ajax_info['errList']['memo'][] = $this->Ini->Nm_lang['lang_errm_mxch'] . " 32767 " . $this->Ini->Nm_lang['lang_errm_nchr'];
          } 
      } 
    } // ValidateField_memo

    function ValidateField_custship(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (trim($this->custship) != "")  
          { 
          } 
      } 
    } // ValidateField_custship

    function ValidateField_orders(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (trim($this->orders) != "")  
          { 
          } 
      } 
    } // ValidateField_orders

    function ValidateField_billing(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (trim($this->billing) != "")  
          { 
          } 
      } 
    } // ValidateField_billing

    function ValidateField_quotes(&$Campos_Crit, &$Campos_Falta, &$Campos_Erros)
    {
        global $teste_validade;
      if ($this->nmgp_opcao != "excluir") 
      { 
          if (trim($this->quotes) != "")  
          { 
          } 
      } 
    } // ValidateField_quotes

    function removeDuplicateDttmError($aErrDate, &$aErrTime)
    {
        if (empty($aErrDate) || empty($aErrTime))
        {
            return;
        }

        foreach ($aErrDate as $sErrDate)
        {
            foreach ($aErrTime as $iErrTime => $sErrTime)
            {
                if ($sErrDate == $sErrTime)
                {
                    unset($aErrTime[$iErrTime]);
                }
            }
        }
    } // removeDuplicateDttmError

   function nm_guardar_campos()
   {
    global
           $sc_seq_vert;
    $this->nmgp_dados_form['bcode'] = $this->bcode;
    $this->nmgp_dados_form['status'] = $this->status;
    $this->nmgp_dados_form['updated'] = $this->updated;
    $this->nmgp_dados_form['number'] = $this->number;
    $this->nmgp_dados_form['terms'] = $this->terms;
    $this->nmgp_dados_form['salesman'] = $this->salesman;
    $this->nmgp_dados_form['tdate'] = $this->tdate;
    $this->nmgp_dados_form['att'] = $this->att;
    $this->nmgp_dados_form['prefix'] = $this->prefix;
    $this->nmgp_dados_form['name'] = $this->name;
    $this->nmgp_dados_form['address1'] = $this->address1;
    $this->nmgp_dados_form['address2'] = $this->address2;
    $this->nmgp_dados_form['city'] = $this->city;
    $this->nmgp_dados_form['state'] = $this->state;
    $this->nmgp_dados_form['zip_code'] = $this->zip_code;
    $this->nmgp_dados_form['country'] = $this->country;
    $this->nmgp_dados_form['email'] = $this->email;
    $this->nmgp_dados_form['phone'] = $this->phone;
    $this->nmgp_dados_form['contact'] = $this->contact;
    $this->nmgp_dados_form['fax'] = $this->fax;
    $this->nmgp_dados_form['cphone1'] = $this->cphone1;
    $this->nmgp_dados_form['cemail1'] = $this->cemail1;
    $this->nmgp_dados_form['cfax1'] = $this->cfax1;
    $this->nmgp_dados_form['contact2'] = $this->contact2;
    $this->nmgp_dados_form['cphone2'] = $this->cphone2;
    $this->nmgp_dados_form['cemail2'] = $this->cemail2;
    $this->nmgp_dados_form['cfax2'] = $this->cfax2;
    $this->nmgp_dados_form['cat1'] = $this->cat1;
    $this->nmgp_dados_form['cat2'] = $this->cat2;
    $this->nmgp_dados_form['cat3'] = $this->cat3;
    $this->nmgp_dados_form['cat4'] = $this->cat4;
    $this->nmgp_dados_form['cat5'] = $this->cat5;
    $this->nmgp_dados_form['cat6'] = $this->cat6;
    $this->nmgp_dados_form['cat7'] = $this->cat7;
    $this->nmgp_dados_form['mtd'] = $this->mtd;
    $this->nmgp_dados_form['qtd'] = $this->qtd;
    $this->nmgp_dados_form['ytd'] = $this->ytd;
    $this->nmgp_dados_form['jan'] = $this->jan;
    $this->nmgp_dados_form['feb'] = $this->feb;
    $this->nmgp_dados_form['mar'] = $this->mar;
    $this->nmgp_dados_form['apr'] = $this->apr;
    $this->nmgp_dados_form['may'] = $this->may;
    $this->nmgp_dados_form['jun'] = $this->jun;
    $this->nmgp_dados_form['jul'] = $this->jul;
    $this->nmgp_dados_form['aug'] = $this->aug;
    $this->nmgp_dados_form['sep'] = $this->sep;
    $this->nmgp_dados_form['oct'] = $this->oct;
    $this->nmgp_dados_form['nov'] = $this->nov;
    $this->nmgp_dados_form['dec'] = $this->dec;
    $this->nmgp_dados_form['lyear'] = $this->lyear;
    $this->nmgp_dados_form['llyear'] = $this->llyear;
    $this->nmgp_dados_form['q1'] = $this->q1;
    $this->nmgp_dados_form['q2'] = $this->q2;
    $this->nmgp_dados_form['q4'] = $this->q4;
    $this->nmgp_dados_form['q3'] = $this->q3;
    $this->nmgp_dados_form['memo'] = $this->memo;
    $this->nmgp_dados_form['custship'] = $this->custship;
    $this->nmgp_dados_form['orders'] = $this->orders;
    $this->nmgp_dados_form['billing'] = $this->billing;
    $this->nmgp_dados_form['quotes'] = $this->quotes;
    $this->nmgp_dados_form['added'] = $this->added;
    $this->nmgp_dados_form['s365'] = $this->s365;
    $this->nmgp_dados_form['temp'] = $this->temp;
    $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['dados_form'] = $this->nmgp_dados_form;
   }
   function nm_tira_formatacao()
   {
      global $nm_form_submit;
         $this->formatado = false;
      nm_limpa_data($this->updated, $this->field_config['updated']['date_sep']) ; 
      nm_limpa_numero($this->number, $this->field_config['number']['symbol_grp']) ; 
      nm_limpa_data($this->tdate, $this->field_config['tdate']['date_sep']) ; 
      if (!empty($this->field_config['mtd']['symbol_dec']))
      {
         $this->sc_remove_currency($this->mtd, $this->field_config['mtd']['symbol_dec'], $this->field_config['mtd']['symbol_grp'], $this->field_config['mtd']['symbol_mon']);
         nm_limpa_valor($this->mtd, $this->field_config['mtd']['symbol_dec'], $this->field_config['mtd']['symbol_grp']);
      }
      if (!empty($this->field_config['qtd']['symbol_dec']))
      {
         $this->sc_remove_currency($this->qtd, $this->field_config['qtd']['symbol_dec'], $this->field_config['qtd']['symbol_grp'], $this->field_config['qtd']['symbol_mon']);
         nm_limpa_valor($this->qtd, $this->field_config['qtd']['symbol_dec'], $this->field_config['qtd']['symbol_grp']);
      }
      if (!empty($this->field_config['ytd']['symbol_dec']))
      {
         $this->sc_remove_currency($this->ytd, $this->field_config['ytd']['symbol_dec'], $this->field_config['ytd']['symbol_grp'], $this->field_config['ytd']['symbol_mon']);
         nm_limpa_valor($this->ytd, $this->field_config['ytd']['symbol_dec'], $this->field_config['ytd']['symbol_grp']);
      }
      if (!empty($this->field_config['jan']['symbol_dec']))
      {
         $this->sc_remove_currency($this->jan, $this->field_config['jan']['symbol_dec'], $this->field_config['jan']['symbol_grp'], $this->field_config['jan']['symbol_mon']);
         nm_limpa_valor($this->jan, $this->field_config['jan']['symbol_dec'], $this->field_config['jan']['symbol_grp']);
      }
      if (!empty($this->field_config['feb']['symbol_dec']))
      {
         $this->sc_remove_currency($this->feb, $this->field_config['feb']['symbol_dec'], $this->field_config['feb']['symbol_grp'], $this->field_config['feb']['symbol_mon']);
         nm_limpa_valor($this->feb, $this->field_config['feb']['symbol_dec'], $this->field_config['feb']['symbol_grp']);
      }
      if (!empty($this->field_config['mar']['symbol_dec']))
      {
         $this->sc_remove_currency($this->mar, $this->field_config['mar']['symbol_dec'], $this->field_config['mar']['symbol_grp'], $this->field_config['mar']['symbol_mon']);
         nm_limpa_valor($this->mar, $this->field_config['mar']['symbol_dec'], $this->field_config['mar']['symbol_grp']);
      }
      if (!empty($this->field_config['apr']['symbol_dec']))
      {
         $this->sc_remove_currency($this->apr, $this->field_config['apr']['symbol_dec'], $this->field_config['apr']['symbol_grp'], $this->field_config['apr']['symbol_mon']);
         nm_limpa_valor($this->apr, $this->field_config['apr']['symbol_dec'], $this->field_config['apr']['symbol_grp']);
      }
      if (!empty($this->field_config['may']['symbol_dec']))
      {
         $this->sc_remove_currency($this->may, $this->field_config['may']['symbol_dec'], $this->field_config['may']['symbol_grp'], $this->field_config['may']['symbol_mon']);
         nm_limpa_valor($this->may, $this->field_config['may']['symbol_dec'], $this->field_config['may']['symbol_grp']);
      }
      if (!empty($this->field_config['jun']['symbol_dec']))
      {
         $this->sc_remove_currency($this->jun, $this->field_config['jun']['symbol_dec'], $this->field_config['jun']['symbol_grp'], $this->field_config['jun']['symbol_mon']);
         nm_limpa_valor($this->jun, $this->field_config['jun']['symbol_dec'], $this->field_config['jun']['symbol_grp']);
      }
      if (!empty($this->field_config['jul']['symbol_dec']))
      {
         $this->sc_remove_currency($this->jul, $this->field_config['jul']['symbol_dec'], $this->field_config['jul']['symbol_grp'], $this->field_config['jul']['symbol_mon']);
         nm_limpa_valor($this->jul, $this->field_config['jul']['symbol_dec'], $this->field_config['jul']['symbol_grp']);
      }
      if (!empty($this->field_config['aug']['symbol_dec']))
      {
         $this->sc_remove_currency($this->aug, $this->field_config['aug']['symbol_dec'], $this->field_config['aug']['symbol_grp'], $this->field_config['aug']['symbol_mon']);
         nm_limpa_valor($this->aug, $this->field_config['aug']['symbol_dec'], $this->field_config['aug']['symbol_grp']);
      }
      if (!empty($this->field_config['sep']['symbol_dec']))
      {
         $this->sc_remove_currency($this->sep, $this->field_config['sep']['symbol_dec'], $this->field_config['sep']['symbol_grp'], $this->field_config['sep']['symbol_mon']);
         nm_limpa_valor($this->sep, $this->field_config['sep']['symbol_dec'], $this->field_config['sep']['symbol_grp']);
      }
      if (!empty($this->field_config['oct']['symbol_dec']))
      {
         $this->sc_remove_currency($this->oct, $this->field_config['oct']['symbol_dec'], $this->field_config['oct']['symbol_grp'], $this->field_config['oct']['symbol_mon']);
         nm_limpa_valor($this->oct, $this->field_config['oct']['symbol_dec'], $this->field_config['oct']['symbol_grp']);
      }
      if (!empty($this->field_config['nov']['symbol_dec']))
      {
         $this->sc_remove_currency($this->nov, $this->field_config['nov']['symbol_dec'], $this->field_config['nov']['symbol_grp'], $this->field_config['nov']['symbol_mon']);
         nm_limpa_valor($this->nov, $this->field_config['nov']['symbol_dec'], $this->field_config['nov']['symbol_grp']);
      }
      if (!empty($this->field_config['dec']['symbol_dec']))
      {
         $this->sc_remove_currency($this->dec, $this->field_config['dec']['symbol_dec'], $this->field_config['dec']['symbol_grp'], $this->field_config['dec']['symbol_mon']);
         nm_limpa_valor($this->dec, $this->field_config['dec']['symbol_dec'], $this->field_config['dec']['symbol_grp']);
      }
      if (!empty($this->field_config['lyear']['symbol_dec']))
      {
         $this->sc_remove_currency($this->lyear, $this->field_config['lyear']['symbol_dec'], $this->field_config['lyear']['symbol_grp'], $this->field_config['lyear']['symbol_mon']);
         nm_limpa_valor($this->lyear, $this->field_config['lyear']['symbol_dec'], $this->field_config['lyear']['symbol_grp']);
      }
      if (!empty($this->field_config['llyear']['symbol_dec']))
      {
         $this->sc_remove_currency($this->llyear, $this->field_config['llyear']['symbol_dec'], $this->field_config['llyear']['symbol_grp'], $this->field_config['llyear']['symbol_mon']);
         nm_limpa_valor($this->llyear, $this->field_config['llyear']['symbol_dec'], $this->field_config['llyear']['symbol_grp']);
      }
      if (!empty($this->field_config['q1']['symbol_dec']))
      {
         $this->sc_remove_currency($this->q1, $this->field_config['q1']['symbol_dec'], $this->field_config['q1']['symbol_grp'], $this->field_config['q1']['symbol_mon']);
         nm_limpa_valor($this->q1, $this->field_config['q1']['symbol_dec'], $this->field_config['q1']['symbol_grp']);
      }
      if (!empty($this->field_config['q2']['symbol_dec']))
      {
         $this->sc_remove_currency($this->q2, $this->field_config['q2']['symbol_dec'], $this->field_config['q2']['symbol_grp'], $this->field_config['q2']['symbol_mon']);
         nm_limpa_valor($this->q2, $this->field_config['q2']['symbol_dec'], $this->field_config['q2']['symbol_grp']);
      }
      if (!empty($this->field_config['q4']['symbol_dec']))
      {
         $this->sc_remove_currency($this->q4, $this->field_config['q4']['symbol_dec'], $this->field_config['q4']['symbol_grp'], $this->field_config['q4']['symbol_mon']);
         nm_limpa_valor($this->q4, $this->field_config['q4']['symbol_dec'], $this->field_config['q4']['symbol_grp']);
      }
      if (!empty($this->field_config['q3']['symbol_dec']))
      {
         $this->sc_remove_currency($this->q3, $this->field_config['q3']['symbol_dec'], $this->field_config['q3']['symbol_grp'], $this->field_config['q3']['symbol_mon']);
         nm_limpa_valor($this->q3, $this->field_config['q3']['symbol_dec'], $this->field_config['q3']['symbol_grp']);
      }
      if (!empty($this->field_config['s365']['symbol_dec']))
      {
         $this->sc_remove_currency($this->s365, $this->field_config['s365']['symbol_dec'], $this->field_config['s365']['symbol_grp'], $this->field_config['s365']['symbol_mon']);
         nm_limpa_valor($this->s365, $this->field_config['s365']['symbol_dec'], $this->field_config['s365']['symbol_grp']);
      }
   }
   function sc_add_currency(&$value, $symbol, $pos)
   {
       if ('' == $value)
       {
           return;
       }
       $value = (1 == $pos || 3 == $pos) ? $symbol . ' ' . $value : $value . ' ' . $symbol;
   }
   function sc_remove_currency(&$value, $symbol_dec, $symbol_tho, $symbol_mon)
   {
       $value = preg_replace('~&#x0*([0-9a-f]+);~ei', '', $value);
       $sNew  = str_replace($symbol_mon, '', $value);
       if ($sNew != $value)
       {
           $value = str_replace(' ', '', $sNew);
           return;
       }
       $aTest = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', $symbol_dec, $symbol_tho);
       $sNew  = '';
       for ($i = 0; $i < strlen($value); $i++)
       {
           if ($this->sc_test_currency_char($value[$i], $aTest))
           {
               $sNew .= $value[$i];
           }
       }
       $value = $sNew;
   }
   function sc_test_currency_char($char, $test)
   {
       $found = false;
       foreach ($test as $test_char)
       {
           if ($char === $test_char)
           {
               $found = true;
           }
       }
       return $found;
   }
   function nm_clear_val($Nome_Campo)
   {
      if ($Nome_Campo == "number")
      {
          nm_limpa_numero($this->number, $this->field_config['number']['symbol_grp']) ; 
      }
      if ($Nome_Campo == "mtd")
      {
          if (!empty($this->field_config['mtd']['symbol_dec']))
          {
             $this->sc_remove_currency($this->mtd, $this->field_config['mtd']['symbol_dec'], $this->field_config['mtd']['symbol_grp'], $this->field_config['mtd']['symbol_mon']);
             nm_limpa_valor($this->mtd, $this->field_config['mtd']['symbol_dec'], $this->field_config['mtd']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "qtd")
      {
          if (!empty($this->field_config['qtd']['symbol_dec']))
          {
             $this->sc_remove_currency($this->qtd, $this->field_config['qtd']['symbol_dec'], $this->field_config['qtd']['symbol_grp'], $this->field_config['qtd']['symbol_mon']);
             nm_limpa_valor($this->qtd, $this->field_config['qtd']['symbol_dec'], $this->field_config['qtd']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "ytd")
      {
          if (!empty($this->field_config['ytd']['symbol_dec']))
          {
             $this->sc_remove_currency($this->ytd, $this->field_config['ytd']['symbol_dec'], $this->field_config['ytd']['symbol_grp'], $this->field_config['ytd']['symbol_mon']);
             nm_limpa_valor($this->ytd, $this->field_config['ytd']['symbol_dec'], $this->field_config['ytd']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "jan")
      {
          if (!empty($this->field_config['jan']['symbol_dec']))
          {
             $this->sc_remove_currency($this->jan, $this->field_config['jan']['symbol_dec'], $this->field_config['jan']['symbol_grp'], $this->field_config['jan']['symbol_mon']);
             nm_limpa_valor($this->jan, $this->field_config['jan']['symbol_dec'], $this->field_config['jan']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "feb")
      {
          if (!empty($this->field_config['feb']['symbol_dec']))
          {
             $this->sc_remove_currency($this->feb, $this->field_config['feb']['symbol_dec'], $this->field_config['feb']['symbol_grp'], $this->field_config['feb']['symbol_mon']);
             nm_limpa_valor($this->feb, $this->field_config['feb']['symbol_dec'], $this->field_config['feb']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "mar")
      {
          if (!empty($this->field_config['mar']['symbol_dec']))
          {
             $this->sc_remove_currency($this->mar, $this->field_config['mar']['symbol_dec'], $this->field_config['mar']['symbol_grp'], $this->field_config['mar']['symbol_mon']);
             nm_limpa_valor($this->mar, $this->field_config['mar']['symbol_dec'], $this->field_config['mar']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "apr")
      {
          if (!empty($this->field_config['apr']['symbol_dec']))
          {
             $this->sc_remove_currency($this->apr, $this->field_config['apr']['symbol_dec'], $this->field_config['apr']['symbol_grp'], $this->field_config['apr']['symbol_mon']);
             nm_limpa_valor($this->apr, $this->field_config['apr']['symbol_dec'], $this->field_config['apr']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "may")
      {
          if (!empty($this->field_config['may']['symbol_dec']))
          {
             $this->sc_remove_currency($this->may, $this->field_config['may']['symbol_dec'], $this->field_config['may']['symbol_grp'], $this->field_config['may']['symbol_mon']);
             nm_limpa_valor($this->may, $this->field_config['may']['symbol_dec'], $this->field_config['may']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "jun")
      {
          if (!empty($this->field_config['jun']['symbol_dec']))
          {
             $this->sc_remove_currency($this->jun, $this->field_config['jun']['symbol_dec'], $this->field_config['jun']['symbol_grp'], $this->field_config['jun']['symbol_mon']);
             nm_limpa_valor($this->jun, $this->field_config['jun']['symbol_dec'], $this->field_config['jun']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "jul")
      {
          if (!empty($this->field_config['jul']['symbol_dec']))
          {
             $this->sc_remove_currency($this->jul, $this->field_config['jul']['symbol_dec'], $this->field_config['jul']['symbol_grp'], $this->field_config['jul']['symbol_mon']);
             nm_limpa_valor($this->jul, $this->field_config['jul']['symbol_dec'], $this->field_config['jul']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "aug")
      {
          if (!empty($this->field_config['aug']['symbol_dec']))
          {
             $this->sc_remove_currency($this->aug, $this->field_config['aug']['symbol_dec'], $this->field_config['aug']['symbol_grp'], $this->field_config['aug']['symbol_mon']);
             nm_limpa_valor($this->aug, $this->field_config['aug']['symbol_dec'], $this->field_config['aug']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "sep")
      {
          if (!empty($this->field_config['sep']['symbol_dec']))
          {
             $this->sc_remove_currency($this->sep, $this->field_config['sep']['symbol_dec'], $this->field_config['sep']['symbol_grp'], $this->field_config['sep']['symbol_mon']);
             nm_limpa_valor($this->sep, $this->field_config['sep']['symbol_dec'], $this->field_config['sep']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "oct")
      {
          if (!empty($this->field_config['oct']['symbol_dec']))
          {
             $this->sc_remove_currency($this->oct, $this->field_config['oct']['symbol_dec'], $this->field_config['oct']['symbol_grp'], $this->field_config['oct']['symbol_mon']);
             nm_limpa_valor($this->oct, $this->field_config['oct']['symbol_dec'], $this->field_config['oct']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "nov")
      {
          if (!empty($this->field_config['nov']['symbol_dec']))
          {
             $this->sc_remove_currency($this->nov, $this->field_config['nov']['symbol_dec'], $this->field_config['nov']['symbol_grp'], $this->field_config['nov']['symbol_mon']);
             nm_limpa_valor($this->nov, $this->field_config['nov']['symbol_dec'], $this->field_config['nov']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "dec")
      {
          if (!empty($this->field_config['dec']['symbol_dec']))
          {
             $this->sc_remove_currency($this->dec, $this->field_config['dec']['symbol_dec'], $this->field_config['dec']['symbol_grp'], $this->field_config['dec']['symbol_mon']);
             nm_limpa_valor($this->dec, $this->field_config['dec']['symbol_dec'], $this->field_config['dec']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "lyear")
      {
          if (!empty($this->field_config['lyear']['symbol_dec']))
          {
             $this->sc_remove_currency($this->lyear, $this->field_config['lyear']['symbol_dec'], $this->field_config['lyear']['symbol_grp'], $this->field_config['lyear']['symbol_mon']);
             nm_limpa_valor($this->lyear, $this->field_config['lyear']['symbol_dec'], $this->field_config['lyear']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "llyear")
      {
          if (!empty($this->field_config['llyear']['symbol_dec']))
          {
             $this->sc_remove_currency($this->llyear, $this->field_config['llyear']['symbol_dec'], $this->field_config['llyear']['symbol_grp'], $this->field_config['llyear']['symbol_mon']);
             nm_limpa_valor($this->llyear, $this->field_config['llyear']['symbol_dec'], $this->field_config['llyear']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "q1")
      {
          if (!empty($this->field_config['q1']['symbol_dec']))
          {
             $this->sc_remove_currency($this->q1, $this->field_config['q1']['symbol_dec'], $this->field_config['q1']['symbol_grp'], $this->field_config['q1']['symbol_mon']);
             nm_limpa_valor($this->q1, $this->field_config['q1']['symbol_dec'], $this->field_config['q1']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "q2")
      {
          if (!empty($this->field_config['q2']['symbol_dec']))
          {
             $this->sc_remove_currency($this->q2, $this->field_config['q2']['symbol_dec'], $this->field_config['q2']['symbol_grp'], $this->field_config['q2']['symbol_mon']);
             nm_limpa_valor($this->q2, $this->field_config['q2']['symbol_dec'], $this->field_config['q2']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "q4")
      {
          if (!empty($this->field_config['q4']['symbol_dec']))
          {
             $this->sc_remove_currency($this->q4, $this->field_config['q4']['symbol_dec'], $this->field_config['q4']['symbol_grp'], $this->field_config['q4']['symbol_mon']);
             nm_limpa_valor($this->q4, $this->field_config['q4']['symbol_dec'], $this->field_config['q4']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "q3")
      {
          if (!empty($this->field_config['q3']['symbol_dec']))
          {
             $this->sc_remove_currency($this->q3, $this->field_config['q3']['symbol_dec'], $this->field_config['q3']['symbol_grp'], $this->field_config['q3']['symbol_mon']);
             nm_limpa_valor($this->q3, $this->field_config['q3']['symbol_dec'], $this->field_config['q3']['symbol_grp']);
          }
      }
      if ($Nome_Campo == "s365")
      {
          if (!empty($this->field_config['s365']['symbol_dec']))
          {
             $this->sc_remove_currency($this->s365, $this->field_config['s365']['symbol_dec'], $this->field_config['s365']['symbol_grp'], $this->field_config['s365']['symbol_mon']);
             nm_limpa_valor($this->s365, $this->field_config['s365']['symbol_dec'], $this->field_config['s365']['symbol_grp']);
          }
      }
   }
   function nm_formatar_campos($format_fields = array())
   {
      global $nm_form_submit;
     if (isset($this->formatado) && $this->formatado)
     {
         return;
     }
     $this->formatado = true;
      if ((!empty($this->updated) && 'null' != $this->updated) || (!empty($format_fields) && isset($format_fields['updated'])))
      {
          nm_volta_data($this->updated, $this->field_config['updated']['date_format']) ; 
          nmgp_Form_Datas($this->updated, $this->field_config['updated']['date_format'], $this->field_config['updated']['date_sep']) ;  
      }
      elseif ('null' == $this->updated || '' == $this->updated)
      {
          $this->updated = '';
      }
      if (!empty($this->number) || (!empty($format_fields) && isset($format_fields['number'])))
      {
          nmgp_Form_Num_Val($this->number, $this->field_config['number']['symbol_grp'], $this->field_config['number']['symbol_dec'], "0", "S", "", "", "", "-", $this->field_config['number']['symbol_fmt']) ; 
      }
      if ((!empty($this->tdate) && 'null' != $this->tdate) || (!empty($format_fields) && isset($format_fields['tdate'])))
      {
          nm_volta_data($this->tdate, $this->field_config['tdate']['date_format']) ; 
          nmgp_Form_Datas($this->tdate, $this->field_config['tdate']['date_format'], $this->field_config['tdate']['date_sep']) ;  
      }
      elseif ('null' == $this->tdate || '' == $this->tdate)
      {
          $this->tdate = '';
      }
      if (!empty($this->mtd) || (!empty($format_fields) && isset($format_fields['mtd'])))
      {
          nmgp_Form_Num_Val($this->mtd, $this->field_config['mtd']['symbol_grp'], $this->field_config['mtd']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['mtd']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['mtd']['symbol_mon'];
          $this->sc_add_currency($this->mtd, $sMonSymb, $this->field_config['mtd']['format_pos']); 
      }
      if (!empty($this->qtd) || (!empty($format_fields) && isset($format_fields['qtd'])))
      {
          nmgp_Form_Num_Val($this->qtd, $this->field_config['qtd']['symbol_grp'], $this->field_config['qtd']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['qtd']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['qtd']['symbol_mon'];
          $this->sc_add_currency($this->qtd, $sMonSymb, $this->field_config['qtd']['format_pos']); 
      }
      if (!empty($this->ytd) || (!empty($format_fields) && isset($format_fields['ytd'])))
      {
          nmgp_Form_Num_Val($this->ytd, $this->field_config['ytd']['symbol_grp'], $this->field_config['ytd']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['ytd']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['ytd']['symbol_mon'];
          $this->sc_add_currency($this->ytd, $sMonSymb, $this->field_config['ytd']['format_pos']); 
      }
      if (!empty($this->jan) || (!empty($format_fields) && isset($format_fields['jan'])))
      {
          nmgp_Form_Num_Val($this->jan, $this->field_config['jan']['symbol_grp'], $this->field_config['jan']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['jan']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['jan']['symbol_mon'];
          $this->sc_add_currency($this->jan, $sMonSymb, $this->field_config['jan']['format_pos']); 
      }
      if (!empty($this->feb) || (!empty($format_fields) && isset($format_fields['feb'])))
      {
          nmgp_Form_Num_Val($this->feb, $this->field_config['feb']['symbol_grp'], $this->field_config['feb']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['feb']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['feb']['symbol_mon'];
          $this->sc_add_currency($this->feb, $sMonSymb, $this->field_config['feb']['format_pos']); 
      }
      if (!empty($this->mar) || (!empty($format_fields) && isset($format_fields['mar'])))
      {
          nmgp_Form_Num_Val($this->mar, $this->field_config['mar']['symbol_grp'], $this->field_config['mar']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['mar']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['mar']['symbol_mon'];
          $this->sc_add_currency($this->mar, $sMonSymb, $this->field_config['mar']['format_pos']); 
      }
      if (!empty($this->apr) || (!empty($format_fields) && isset($format_fields['apr'])))
      {
          nmgp_Form_Num_Val($this->apr, $this->field_config['apr']['symbol_grp'], $this->field_config['apr']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['apr']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['apr']['symbol_mon'];
          $this->sc_add_currency($this->apr, $sMonSymb, $this->field_config['apr']['format_pos']); 
      }
      if (!empty($this->may) || (!empty($format_fields) && isset($format_fields['may'])))
      {
          nmgp_Form_Num_Val($this->may, $this->field_config['may']['symbol_grp'], $this->field_config['may']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['may']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['may']['symbol_mon'];
          $this->sc_add_currency($this->may, $sMonSymb, $this->field_config['may']['format_pos']); 
      }
      if (!empty($this->jun) || (!empty($format_fields) && isset($format_fields['jun'])))
      {
          nmgp_Form_Num_Val($this->jun, $this->field_config['jun']['symbol_grp'], $this->field_config['jun']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['jun']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['jun']['symbol_mon'];
          $this->sc_add_currency($this->jun, $sMonSymb, $this->field_config['jun']['format_pos']); 
      }
      if (!empty($this->jul) || (!empty($format_fields) && isset($format_fields['jul'])))
      {
          nmgp_Form_Num_Val($this->jul, $this->field_config['jul']['symbol_grp'], $this->field_config['jul']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['jul']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['jul']['symbol_mon'];
          $this->sc_add_currency($this->jul, $sMonSymb, $this->field_config['jul']['format_pos']); 
      }
      if (!empty($this->aug) || (!empty($format_fields) && isset($format_fields['aug'])))
      {
          nmgp_Form_Num_Val($this->aug, $this->field_config['aug']['symbol_grp'], $this->field_config['aug']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['aug']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['aug']['symbol_mon'];
          $this->sc_add_currency($this->aug, $sMonSymb, $this->field_config['aug']['format_pos']); 
      }
      if (!empty($this->sep) || (!empty($format_fields) && isset($format_fields['sep'])))
      {
          nmgp_Form_Num_Val($this->sep, $this->field_config['sep']['symbol_grp'], $this->field_config['sep']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['sep']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['sep']['symbol_mon'];
          $this->sc_add_currency($this->sep, $sMonSymb, $this->field_config['sep']['format_pos']); 
      }
      if (!empty($this->oct) || (!empty($format_fields) && isset($format_fields['oct'])))
      {
          nmgp_Form_Num_Val($this->oct, $this->field_config['oct']['symbol_grp'], $this->field_config['oct']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['oct']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['oct']['symbol_mon'];
          $this->sc_add_currency($this->oct, $sMonSymb, $this->field_config['oct']['format_pos']); 
      }
      if (!empty($this->nov) || (!empty($format_fields) && isset($format_fields['nov'])))
      {
          nmgp_Form_Num_Val($this->nov, $this->field_config['nov']['symbol_grp'], $this->field_config['nov']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['nov']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['nov']['symbol_mon'];
          $this->sc_add_currency($this->nov, $sMonSymb, $this->field_config['nov']['format_pos']); 
      }
      if (!empty($this->dec) || (!empty($format_fields) && isset($format_fields['dec'])))
      {
          nmgp_Form_Num_Val($this->dec, $this->field_config['dec']['symbol_grp'], $this->field_config['dec']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['dec']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['dec']['symbol_mon'];
          $this->sc_add_currency($this->dec, $sMonSymb, $this->field_config['dec']['format_pos']); 
      }
      if (!empty($this->lyear) || (!empty($format_fields) && isset($format_fields['lyear'])))
      {
          nmgp_Form_Num_Val($this->lyear, $this->field_config['lyear']['symbol_grp'], $this->field_config['lyear']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['lyear']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['lyear']['symbol_mon'];
          $this->sc_add_currency($this->lyear, $sMonSymb, $this->field_config['lyear']['format_pos']); 
      }
      if (!empty($this->llyear) || (!empty($format_fields) && isset($format_fields['llyear'])))
      {
          nmgp_Form_Num_Val($this->llyear, $this->field_config['llyear']['symbol_grp'], $this->field_config['llyear']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['llyear']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['llyear']['symbol_mon'];
          $this->sc_add_currency($this->llyear, $sMonSymb, $this->field_config['llyear']['format_pos']); 
      }
      if (!empty($this->q1) || (!empty($format_fields) && isset($format_fields['q1'])))
      {
          nmgp_Form_Num_Val($this->q1, $this->field_config['q1']['symbol_grp'], $this->field_config['q1']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['q1']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['q1']['symbol_mon'];
          $this->sc_add_currency($this->q1, $sMonSymb, $this->field_config['q1']['format_pos']); 
      }
      if (!empty($this->q2) || (!empty($format_fields) && isset($format_fields['q2'])))
      {
          nmgp_Form_Num_Val($this->q2, $this->field_config['q2']['symbol_grp'], $this->field_config['q2']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['q2']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['q2']['symbol_mon'];
          $this->sc_add_currency($this->q2, $sMonSymb, $this->field_config['q2']['format_pos']); 
      }
      if (!empty($this->q4) || (!empty($format_fields) && isset($format_fields['q4'])))
      {
          nmgp_Form_Num_Val($this->q4, $this->field_config['q4']['symbol_grp'], $this->field_config['q4']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['q4']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['q4']['symbol_mon'];
          $this->sc_add_currency($this->q4, $sMonSymb, $this->field_config['q4']['format_pos']); 
      }
      if (!empty($this->q3) || (!empty($format_fields) && isset($format_fields['q3'])))
      {
          nmgp_Form_Num_Val($this->q3, $this->field_config['q3']['symbol_grp'], $this->field_config['q3']['symbol_dec'], "2", "S", "", "", "", "-", $this->field_config['q3']['symbol_fmt']) ; 
          $sMonSymb = $this->field_config['q3']['symbol_mon'];
          $this->sc_add_currency($this->q3, $sMonSymb, $this->field_config['q3']['format_pos']); 
      }
   }
   function nm_gera_mask(&$nm_campo, $nm_mask)
   { 
      $trab_campo = $nm_campo;
      $trab_mask  = $nm_mask;
      $tam_campo  = strlen($nm_campo);
      $trab_saida = "";

      if (false !== strpos($nm_mask, '9') || false !== strpos($nm_mask, 'a') || false !== strpos($nm_mask, '*'))
      {
          $new_campo = '';
          $a_mask_ord  = array();
          $i_mask_size = -1;

          foreach (explode(';', $nm_mask) as $str_mask)
          {
              $a_mask_ord[ $this->nm_conta_mask_chars($str_mask) ] = $str_mask;
          }
          ksort($a_mask_ord);

          foreach ($a_mask_ord as $i_size => $s_mask)
          {
              if (-1 == $i_mask_size)
              {
                  $i_mask_size = $i_size;
              }
              elseif (strlen($nm_campo) >= $i_size && strlen($nm_campo) > $i_mask_size)
              {
                  $i_mask_size = $i_size;
              }
          }
          $nm_mask = $a_mask_ord[$i_mask_size];

          for ($i = 0; $i < strlen($nm_mask); $i++)
          {
              $test_mask = substr($nm_mask, $i, 1);
              
              if ('9' == $test_mask || 'a' == $test_mask || '*' == $test_mask)
              {
                  $new_campo .= substr($nm_campo, 0, 1);
                  $nm_campo   = substr($nm_campo, 1);
              }
              else
              {
                  $new_campo .= $test_mask;
              }
          }

                  $nm_campo = $new_campo;

          return;
      }

      $mask_num = false;
      for ($x=0; $x < strlen($trab_mask); $x++)
      {
          if (substr($trab_mask, $x, 1) == "#")
          {
              $mask_num = true;
              break;
          }
      }
      if ($mask_num )
      {
          $ver_duas = explode(";", $trab_mask);
          if (isset($ver_duas[1]) && !empty($ver_duas[1]))
          {
              $cont1 = count(explode("#", $ver_duas[0])) - 1;
              $cont2 = count(explode("#", $ver_duas[1])) - 1;
              if ($cont1 < $cont2 && $tam_campo <= $cont2 && $tam_campo > $cont1)
              {
                  $trab_mask = $ver_duas[1];
              }
              elseif ($cont1 > $cont2 && $tam_campo <= $cont2)
              {
                  $trab_mask = $ver_duas[1];
              }
              else
              {
                  $trab_mask = $ver_duas[0];
              }
          }
          $tam_mask = strlen($trab_mask);
          $xdados = 0;
          for ($x=0; $x < $tam_mask; $x++)
          {
              if (substr($trab_mask, $x, 1) == "#" && $xdados < $tam_campo)
              {
                  $trab_saida .= substr($trab_campo, $xdados, 1);
                  $xdados++;
              }
              elseif ($xdados < $tam_campo)
              {
                  $trab_saida .= substr($trab_mask, $x, 1);
              }
          }
          if ($xdados < $tam_campo)
          {
              $trab_saida .= substr($trab_campo, $xdados);
          }
          $nm_campo = $trab_saida;
          return;
      }
      for ($ix = strlen($trab_mask); $ix > 0; $ix--)
      {
           $char_mask = substr($trab_mask, $ix - 1, 1);
           if ($char_mask != "x" && $char_mask != "z")
           {
               $trab_saida = $char_mask . $trab_saida;
           }
           else
           {
               if ($tam_campo != 0)
               {
                   $trab_saida = substr($trab_campo, $tam_campo - 1, 1) . $trab_saida;
                   $tam_campo--;
               }
               else
               {
                   $trab_saida = "0" . $trab_saida;
               }
           }
      }
      if ($tam_campo != 0)
      {
          $trab_saida = substr($trab_campo, 0, $tam_campo) . $trab_saida;
          $trab_mask  = str_repeat("z", $tam_campo) . $trab_mask;
      }
   
      $iz = 0; 
      for ($ix = 0; $ix < strlen($trab_mask); $ix++)
      {
           $char_mask = substr($trab_mask, $ix, 1);
           if ($char_mask != "x" && $char_mask != "z")
           {
               if ($char_mask == "." || $char_mask == ",")
               {
                   $trab_saida = substr($trab_saida, 0, $iz) . substr($trab_saida, $iz + 1);
               }
               else
               {
                   $iz++;
               }
           }
           elseif ($char_mask == "x" || substr($trab_saida, $iz, 1) != "0")
           {
               $ix = strlen($trab_mask) + 1;
           }
           else
           {
               $trab_saida = substr($trab_saida, 0, $iz) . substr($trab_saida, $iz + 1);
           }
      }
      $nm_campo = $trab_saida;
   } 
   function nm_conta_mask_chars($sMask)
   {
       $iLength = 0;

       for ($i = 0; $i < strlen($sMask); $i++)
       {
           if (in_array($sMask[$i], array('9', 'a', '*')))
           {
               $iLength++;
           }
       }

       return $iLength;
   }
   function nm_tira_mask(&$nm_campo, $nm_mask, $nm_chars = '')
   { 
      $mask_dados = $nm_campo;
      $trab_mask  = $nm_mask;
      $tam_campo  = strlen($nm_campo);
      $tam_mask   = strlen($nm_mask);
      $trab_saida = "";

      if (false !== strpos($nm_mask, '9') || false !== strpos($nm_mask, 'a') || false !== strpos($nm_mask, '*'))
      {
          $raw_campo = $this->sc_clear_mask($nm_campo, $nm_chars);
          $raw_mask  = $this->sc_clear_mask($nm_mask, $nm_chars);
          $new_campo = '';

          $test_mask = substr($raw_mask, 0, 1);
          $raw_mask  = substr($raw_mask, 1);

          while ('' != $raw_campo)
          {
              $test_val  = substr($raw_campo, 0, 1);
              $raw_campo = substr($raw_campo, 1);
              $ord       = ord($test_val);
              $found     = false;

              switch ($test_mask)
              {
                  case '9':
                      if (48 <= $ord && 57 >= $ord)
                      {
                          $new_campo .= $test_val;
                          $found      = true;
                      }
                      break;

                  case 'a':
                      if ((65 <= $ord && 90 >= $ord) || (97 <= $ord && 122 >= $ord))
                      {
                          $new_campo .= $test_val;
                          $found      = true;
                      }
                      break;

                  case '*':
                      if ((48 <= $ord && 57 >= $ord) || (65 <= $ord && 90 >= $ord) || (97 <= $ord && 122 >= $ord))
                      {
                          $new_campo .= $test_val;
                          $found      = true;
                      }
                      break;
              }

              if ($found)
              {
                  $test_mask = substr($raw_mask, 0, 1);
                  $raw_mask  = substr($raw_mask, 1);
              }
          }

          $nm_campo = $new_campo;

          return;
      }

      $mask_num = false;
      for ($x=0; $x < strlen($trab_mask); $x++)
      {
          if (substr($trab_mask, $x, 1) == "#")
          {
              $mask_num = true;
              break;
          }
      }
      if ($mask_num )
      {
          for ($x=0; $x < strlen($mask_dados); $x++)
          {
              if (is_numeric(substr($mask_dados, $x, 1)))
              {
                  $trab_saida .= substr($mask_dados, $x, 1);
              }
          }
          $nm_campo = $trab_saida;
          return;
      }
      if ($tam_mask > $tam_campo)
      {
         $mask_desfaz = "";
         for ($mask_ind = 0; $tam_mask > $tam_campo; $mask_ind++)
         {
              $mask_char = substr($trab_mask, $mask_ind, 1);
              if ($mask_char == "z")
              {
                  $tam_mask--;
              }
              else
              {
                  $mask_desfaz .= $mask_char;
              }
              if ($mask_ind == $tam_campo)
              {
                  $tam_mask = $tam_campo;
              }
         }
         $trab_mask = $mask_desfaz . substr($trab_mask, $mask_ind);
      }
      $mask_saida = "";
      for ($mask_ind = strlen($trab_mask); $mask_ind > 0; $mask_ind--)
      {
          $mask_char = substr($trab_mask, $mask_ind - 1, 1);
          if ($mask_char == "x" || $mask_char == "z")
          {
              if ($tam_campo > 0)
              {
                  $mask_saida = substr($mask_dados, $tam_campo - 1, 1) . $mask_saida;
              }
          }
          else
          {
              if ($mask_char != substr($mask_dados, $tam_campo - 1, 1) && $tam_campo > 0)
              {
                  $mask_saida = substr($mask_dados, $tam_campo - 1, 1) . $mask_saida;
                  $mask_ind--;
              }
          }
          $tam_campo--;
      }
      if ($tam_campo > 0)
      {
         $mask_saida = substr($mask_dados, 0, $tam_campo) . $mask_saida;
      }
      $nm_campo = $mask_saida;
   }

   function sc_clear_mask($value, $chars)
   {
       $new = '';

       for ($i = 0; $i < strlen($value); $i++)
       {
           if (false === strpos($chars, $value[$i]))
           {
               $new .= $value[$i];
           }
       }

       return $new;
   }
//
   function nm_limpa_alfa(&$str)
   {
       if (get_magic_quotes_gpc())
       {
           if (is_array($str))
           {
               $x = 0;
               foreach ($str as $cada_str)
               {
                   $str[$x] = stripslashes($str[$x]);
                   $x++;
               }
           }
           else
           {
               $str = stripslashes($str);
           }
       }
   }
//
//-- 
   function nm_converte_datas($use_null = true)
   {
       $guarda_format_hora = $this->field_config['updated']['date_format'];
      if ($this->updated != "")  
      { 
          nm_conv_data($this->updated, $this->field_config['updated']['date_format']) ; 
          $this->updated_hora = "00:00:00:000" ; 
          if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_postgres))
          {
              $this->updated_hora = substr($this->updated_hora, 0, -4);
          }
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mysql))
          {
              $this->updated_hora = substr($this->updated_hora, 0, -4);
          }
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
          {
              $this->updated_hora = substr($this->updated_hora, 0, -4);
          }
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
          {
              $this->updated_hora = substr($this->updated_hora, 0, -4);
          }
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_db2))
          {
              $this->updated_hora = substr($this->updated_hora, 0, -4);
          }
      } 
      if ($this->updated == "" && $use_null)  
      { 
          $this->updated = "null" ; 
      } 
       $this->field_config['updated']['date_format'] = $guarda_format_hora;
       $guarda_format_hora = $this->field_config['tdate']['date_format'];
      if ($this->tdate != "")  
      { 
          nm_conv_data($this->tdate, $this->field_config['tdate']['date_format']) ; 
          $this->tdate_hora = "00:00:00:000" ; 
          if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_postgres))
          {
              $this->tdate_hora = substr($this->tdate_hora, 0, -4);
          }
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mysql))
          {
              $this->tdate_hora = substr($this->tdate_hora, 0, -4);
          }
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
          {
              $this->tdate_hora = substr($this->tdate_hora, 0, -4);
          }
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
          {
              $this->tdate_hora = substr($this->tdate_hora, 0, -4);
          }
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_db2))
          {
              $this->tdate_hora = substr($this->tdate_hora, 0, -4);
          }
      } 
      if ($this->tdate == "" && $use_null)  
      { 
          $this->tdate = "null" ; 
      } 
       $this->field_config['tdate']['date_format'] = $guarda_format_hora;
   }
   function nm_conv_data_db($dt_in, $form_in, $form_out, $replaces = array())
   {
       $dt_out = $dt_in;
       if (strtoupper($form_in) == "DB_FORMAT")
       {
           if ($dt_out == "null" || $dt_out == "")
           {
               $dt_out = "";
               return $dt_out;
           }
           $form_in = "AAAA-MM-DD";
       }
       if (strtoupper($form_out) == "DB_FORMAT")
       {
           if (empty($dt_out))
           {
               $dt_out = "null";
               return $dt_out;
           }
           $form_out = "AAAA-MM-DD";
       }
       nm_conv_form_data($dt_out, $form_in, $form_out, $replaces);
       return $dt_out;
   }

   function returnWhere($aCond, $sOp = 'AND')
   {
       $aWhere = array();
       foreach ($aCond as $sCond)
       {
           $this->handleWhereCond($sCond);
           if ('' != $sCond)
           {
               $aWhere[] = $sCond;
           }
       }
       if (empty($aWhere))
       {
           return '';
       }
       else
       {
           return ' WHERE (' . implode(') ' . $sOp . ' (', $aWhere) . ')';
       }
   } // returnWhere

   function handleWhereCond(&$sCond)
   {
       $sCond = trim($sCond);
       if ('where' == strtolower(substr($sCond, 0, 5)))
       {
           $sCond = trim(substr($sCond, 5));
       }
   } // handleWhereCond

   function ajax_return_values()
   {
          $this->ajax_return_values_bcode();
          $this->ajax_return_values_status();
          $this->ajax_return_values_updated();
          $this->ajax_return_values_number();
          $this->ajax_return_values_terms();
          $this->ajax_return_values_salesman();
          $this->ajax_return_values_tdate();
          $this->ajax_return_values_att();
          $this->ajax_return_values_prefix();
          $this->ajax_return_values_name();
          $this->ajax_return_values_address1();
          $this->ajax_return_values_address2();
          $this->ajax_return_values_city();
          $this->ajax_return_values_state();
          $this->ajax_return_values_zip_code();
          $this->ajax_return_values_country();
          $this->ajax_return_values_email();
          $this->ajax_return_values_phone();
          $this->ajax_return_values_contact();
          $this->ajax_return_values_fax();
          $this->ajax_return_values_cphone1();
          $this->ajax_return_values_cemail1();
          $this->ajax_return_values_cfax1();
          $this->ajax_return_values_contact2();
          $this->ajax_return_values_cphone2();
          $this->ajax_return_values_cemail2();
          $this->ajax_return_values_cfax2();
          $this->ajax_return_values_cat1();
          $this->ajax_return_values_cat2();
          $this->ajax_return_values_cat3();
          $this->ajax_return_values_cat4();
          $this->ajax_return_values_cat5();
          $this->ajax_return_values_cat6();
          $this->ajax_return_values_cat7();
          $this->ajax_return_values_mtd();
          $this->ajax_return_values_qtd();
          $this->ajax_return_values_ytd();
          $this->ajax_return_values_jan();
          $this->ajax_return_values_feb();
          $this->ajax_return_values_mar();
          $this->ajax_return_values_apr();
          $this->ajax_return_values_may();
          $this->ajax_return_values_jun();
          $this->ajax_return_values_jul();
          $this->ajax_return_values_aug();
          $this->ajax_return_values_sep();
          $this->ajax_return_values_oct();
          $this->ajax_return_values_nov();
          $this->ajax_return_values_dec();
          $this->ajax_return_values_lyear();
          $this->ajax_return_values_llyear();
          $this->ajax_return_values_q1();
          $this->ajax_return_values_q2();
          $this->ajax_return_values_q4();
          $this->ajax_return_values_q3();
          $this->ajax_return_values_memo();
          $this->ajax_return_values_custship();
          $this->ajax_return_values_orders();
          $this->ajax_return_values_billing();
          $this->ajax_return_values_quotes();
          if ('navigate_form' == $this->NM_ajax_opcao)
          {
              $this->NM_ajax_info['clearUpload']      = 'S';
              $this->NM_ajax_info['navStatus']['ret'] = $this->Nav_permite_ret ? 'S' : 'N';
              $this->NM_ajax_info['navStatus']['ava'] = $this->Nav_permite_ava ? 'S' : 'N';
              $this->NM_ajax_info['fldList']['bcode']['keyVal'] = custbill_form_pack_protect_string($this->nmgp_dados_form['bcode']);
              $_SESSION['sc_session'][$this->Ini->sc_page]['custship_form']['foreign_key']['bcode'] = $this->nmgp_dados_form['bcode'];
              $_SESSION['sc_session'][$this->Ini->sc_page]['custship_form']['where_filter'] = "BCODE = '" . $this->nmgp_dados_form['bcode'] . "'";
              $_SESSION['sc_session'][$this->Ini->sc_page]['custship_form']['where_detal']  = "BCODE = '" . $this->nmgp_dados_form['bcode'] . "'";
              if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total'] < 0)
              {
                  $_SESSION['sc_session'][$this->Ini->sc_page]['custship_form']['where_filter'] = "1 <> 1";
              }
              $_SESSION['sc_session'][$this->Ini->sc_page]['custship_form']['reg_start'] = "";
              unset($_SESSION['sc_session'][$this->Ini->sc_page]['custship_form']['total']);
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_invoice_grid']['embutida_form']       = true;
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_invoice_grid']['embutida_form_parms'] = "var_bcode?#?" . $this->nmgp_dados_form['bcode'] . "?@?";
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_invoice_grid']['reg_start'] = "";
              unset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_invoice_grid']['total']);
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_orders_grid']['embutida_form']       = true;
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_orders_grid']['embutida_form_parms'] = "var_bcode?#?" . $this->nmgp_dados_form['bcode'] . "?@?";
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_orders_grid']['reg_start'] = "";
              unset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_orders_grid']['total']);
              $_SESSION['sc_session'][$this->Ini->sc_page]['prices_grid']['embutida_form']       = true;
              $_SESSION['sc_session'][$this->Ini->sc_page]['prices_grid']['embutida_form_parms'] = "var_bcode?#?" . $this->nmgp_dados_form['bcode'] . "?@?";
              $_SESSION['sc_session'][$this->Ini->sc_page]['prices_grid']['reg_start'] = "";
              unset($_SESSION['sc_session'][$this->Ini->sc_page]['prices_grid']['total']);
          }
   } // ajax_return_values

          //----- bcode
   function ajax_return_values_bcode($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("bcode", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->bcode);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['bcode'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- status
   function ajax_return_values_status($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("status", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->status);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['status'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- updated
   function ajax_return_values_updated($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("updated", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->updated);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['updated'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- number
   function ajax_return_values_number($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("number", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->number);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['number'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- terms
   function ajax_return_values_terms($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("terms", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->terms);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['terms'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- salesman
   function ajax_return_values_salesman($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("salesman", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->salesman);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['salesman'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- tdate
   function ajax_return_values_tdate($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("tdate", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->tdate);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['tdate'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- att
   function ajax_return_values_att($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("att", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->att);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['att'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- prefix
   function ajax_return_values_prefix($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("prefix", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->prefix);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['prefix'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- name
   function ajax_return_values_name($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("name", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->name);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['name'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- address1
   function ajax_return_values_address1($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("address1", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->address1);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['address1'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- address2
   function ajax_return_values_address2($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("address2", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->address2);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['address2'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- city
   function ajax_return_values_city($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("city", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->city);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['city'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- state
   function ajax_return_values_state($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("state", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->state);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['state'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- zip_code
   function ajax_return_values_zip_code($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("zip_code", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->zip_code);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['zip_code'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- country
   function ajax_return_values_country($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("country", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->country);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['country'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- email
   function ajax_return_values_email($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("email", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->email);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['email'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- phone
   function ajax_return_values_phone($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("phone", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->phone);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['phone'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- contact
   function ajax_return_values_contact($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("contact", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->contact);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['contact'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- fax
   function ajax_return_values_fax($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("fax", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->fax);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['fax'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- cphone1
   function ajax_return_values_cphone1($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("cphone1", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->cphone1);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['cphone1'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- cemail1
   function ajax_return_values_cemail1($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("cemail1", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->cemail1);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['cemail1'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- cfax1
   function ajax_return_values_cfax1($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("cfax1", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->cfax1);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['cfax1'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- contact2
   function ajax_return_values_contact2($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("contact2", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->contact2);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['contact2'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- cphone2
   function ajax_return_values_cphone2($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("cphone2", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->cphone2);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['cphone2'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- cemail2
   function ajax_return_values_cemail2($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("cemail2", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->cemail2);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['cemail2'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- cfax2
   function ajax_return_values_cfax2($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("cfax2", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->cfax2);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['cfax2'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- cat1
   function ajax_return_values_cat1($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("cat1", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->cat1);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['cat1'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- cat2
   function ajax_return_values_cat2($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("cat2", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->cat2);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['cat2'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- cat3
   function ajax_return_values_cat3($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("cat3", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->cat3);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['cat3'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- cat4
   function ajax_return_values_cat4($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("cat4", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->cat4);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['cat4'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- cat5
   function ajax_return_values_cat5($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("cat5", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->cat5);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['cat5'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- cat6
   function ajax_return_values_cat6($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("cat6", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->cat6);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['cat6'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- cat7
   function ajax_return_values_cat7($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("cat7", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->cat7);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['cat7'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- mtd
   function ajax_return_values_mtd($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("mtd", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->mtd);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['mtd'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- qtd
   function ajax_return_values_qtd($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("qtd", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->qtd);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['qtd'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- ytd
   function ajax_return_values_ytd($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("ytd", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->ytd);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['ytd'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- jan
   function ajax_return_values_jan($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("jan", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->jan);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['jan'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- feb
   function ajax_return_values_feb($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("feb", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->feb);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['feb'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- mar
   function ajax_return_values_mar($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("mar", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->mar);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['mar'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- apr
   function ajax_return_values_apr($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("apr", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->apr);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['apr'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- may
   function ajax_return_values_may($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("may", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->may);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['may'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- jun
   function ajax_return_values_jun($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("jun", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->jun);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['jun'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- jul
   function ajax_return_values_jul($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("jul", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->jul);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['jul'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- aug
   function ajax_return_values_aug($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("aug", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->aug);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['aug'] = array(
                       'row'    => '',
               'type'    => 'label',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- sep
   function ajax_return_values_sep($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("sep", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->sep);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['sep'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- oct
   function ajax_return_values_oct($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("oct", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->oct);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['oct'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- nov
   function ajax_return_values_nov($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("nov", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->nov);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['nov'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- dec
   function ajax_return_values_dec($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("dec", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->dec);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['dec'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- lyear
   function ajax_return_values_lyear($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("lyear", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->lyear);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['lyear'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- llyear
   function ajax_return_values_llyear($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("llyear", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->llyear);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['llyear'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- q1
   function ajax_return_values_q1($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("q1", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->q1);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['q1'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- q2
   function ajax_return_values_q2($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("q2", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->q2);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['q2'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- q4
   function ajax_return_values_q4($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("q4", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->q4);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['q4'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- q3
   function ajax_return_values_q3($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("q3", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->q3);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['q3'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- memo
   function ajax_return_values_memo($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("memo", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->memo);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['memo'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- custship
   function ajax_return_values_custship($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("custship", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->custship);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['custship'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- orders
   function ajax_return_values_orders($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("orders", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->orders);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['orders'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- billing
   function ajax_return_values_billing($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("billing", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->billing);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['billing'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

          //----- quotes
   function ajax_return_values_quotes($bForce = false)
   {
          if ('navigate_form' == $this->NM_ajax_opcao || 'backup_line' == $this->NM_ajax_opcao || (isset($this->nmgp_refresh_fields) && in_array("quotes", $this->nmgp_refresh_fields)) || $bForce)
          {
              $sTmpValue = NM_charset_to_utf8($this->quotes);
              $aLookup = array();
          $aLookupOrig = $aLookup;
          $this->NM_ajax_info['fldList']['quotes'] = array(
                       'row'    => '',
               'type'    => 'text',
               'valList' => array($sTmpValue),
              );
          }
   }

   function ajax_add_parameters()
   {
   } // ajax_add_parameters
  function nm_proc_onload($bFormat = true)
  {
      if (!$this->NM_ajax_flag || !isset($this->nmgp_refresh_fields)) {
      $_SESSION['scriptcase']['custbill_form']['contr_erro'] = 'on';
if (isset($this->NM_ajax_flag) && $this->NM_ajax_flag)
{
    $original_bcode = $this->bcode;
}
if (!isset($this->sc_temp_var_bcode)) {$this->sc_temp_var_bcode = (isset($_SESSION['var_bcode'])) ? $_SESSION['var_bcode'] : "";}
 $this->sc_temp_var_bcode = $this->bcode ;
if (isset($this->sc_temp_var_bcode)) { $_SESSION['var_bcode'] = $this->sc_temp_var_bcode;}
if (isset($this->NM_ajax_flag) && $this->NM_ajax_flag)
{
    if (($original_bcode != $this->bcode || (isset($bFlagRead_bcode) && $bFlagRead_bcode)))
    {
        $this->ajax_return_values_bcode(true);
    }
}
$_SESSION['scriptcase']['custbill_form']['contr_erro'] = 'off'; 
      }
      $this->nm_guardar_campos();
      if ($bFormat) $this->nm_formatar_campos();
  }
//
//----------------------------------------------------
//-----> 
//----------------------------------------------------
//
   function nm_troca_decimal($sc_parm1, $sc_parm2) 
   { 
      $this->mtd = str_replace($sc_parm1, $sc_parm2, $this->mtd); 
      $this->qtd = str_replace($sc_parm1, $sc_parm2, $this->qtd); 
      $this->ytd = str_replace($sc_parm1, $sc_parm2, $this->ytd); 
      $this->jan = str_replace($sc_parm1, $sc_parm2, $this->jan); 
      $this->feb = str_replace($sc_parm1, $sc_parm2, $this->feb); 
      $this->mar = str_replace($sc_parm1, $sc_parm2, $this->mar); 
      $this->apr = str_replace($sc_parm1, $sc_parm2, $this->apr); 
      $this->may = str_replace($sc_parm1, $sc_parm2, $this->may); 
      $this->jun = str_replace($sc_parm1, $sc_parm2, $this->jun); 
      $this->jul = str_replace($sc_parm1, $sc_parm2, $this->jul); 
      $this->aug = str_replace($sc_parm1, $sc_parm2, $this->aug); 
      $this->sep = str_replace($sc_parm1, $sc_parm2, $this->sep); 
      $this->oct = str_replace($sc_parm1, $sc_parm2, $this->oct); 
      $this->nov = str_replace($sc_parm1, $sc_parm2, $this->nov); 
      $this->dec = str_replace($sc_parm1, $sc_parm2, $this->dec); 
      $this->lyear = str_replace($sc_parm1, $sc_parm2, $this->lyear); 
      $this->llyear = str_replace($sc_parm1, $sc_parm2, $this->llyear); 
      $this->q1 = str_replace($sc_parm1, $sc_parm2, $this->q1); 
      $this->q2 = str_replace($sc_parm1, $sc_parm2, $this->q2); 
      $this->q4 = str_replace($sc_parm1, $sc_parm2, $this->q4); 
      $this->q3 = str_replace($sc_parm1, $sc_parm2, $this->q3); 
      $this->s365 = str_replace($sc_parm1, $sc_parm2, $this->s365); 
   } 
   function nm_poe_aspas_decimal() 
   { 
      $this->mtd = "'" . $this->mtd . "'";
      $this->qtd = "'" . $this->qtd . "'";
      $this->ytd = "'" . $this->ytd . "'";
      $this->jan = "'" . $this->jan . "'";
      $this->feb = "'" . $this->feb . "'";
      $this->mar = "'" . $this->mar . "'";
      $this->apr = "'" . $this->apr . "'";
      $this->may = "'" . $this->may . "'";
      $this->jun = "'" . $this->jun . "'";
      $this->jul = "'" . $this->jul . "'";
      $this->aug = "'" . $this->aug . "'";
      $this->sep = "'" . $this->sep . "'";
      $this->oct = "'" . $this->oct . "'";
      $this->nov = "'" . $this->nov . "'";
      $this->dec = "'" . $this->dec . "'";
      $this->lyear = "'" . $this->lyear . "'";
      $this->llyear = "'" . $this->llyear . "'";
      $this->q1 = "'" . $this->q1 . "'";
      $this->q2 = "'" . $this->q2 . "'";
      $this->q4 = "'" . $this->q4 . "'";
      $this->q3 = "'" . $this->q3 . "'";
      $this->s365 = "'" . $this->s365 . "'";
   } 
   function nm_tira_aspas_decimal() 
   { 
      $this->mtd = str_replace("'", "", $this->mtd); 
      $this->qtd = str_replace("'", "", $this->qtd); 
      $this->ytd = str_replace("'", "", $this->ytd); 
      $this->jan = str_replace("'", "", $this->jan); 
      $this->feb = str_replace("'", "", $this->feb); 
      $this->mar = str_replace("'", "", $this->mar); 
      $this->apr = str_replace("'", "", $this->apr); 
      $this->may = str_replace("'", "", $this->may); 
      $this->jun = str_replace("'", "", $this->jun); 
      $this->jul = str_replace("'", "", $this->jul); 
      $this->aug = str_replace("'", "", $this->aug); 
      $this->sep = str_replace("'", "", $this->sep); 
      $this->oct = str_replace("'", "", $this->oct); 
      $this->nov = str_replace("'", "", $this->nov); 
      $this->dec = str_replace("'", "", $this->dec); 
      $this->lyear = str_replace("'", "", $this->lyear); 
      $this->llyear = str_replace("'", "", $this->llyear); 
      $this->q1 = str_replace("'", "", $this->q1); 
      $this->q2 = str_replace("'", "", $this->q2); 
      $this->q4 = str_replace("'", "", $this->q4); 
      $this->q3 = str_replace("'", "", $this->q3); 
      $this->s365 = str_replace("'", "", $this->s365); 
   } 
//----------- 


   function temRegistros($sWhere)
   {
       if ('' == $sWhere)
       {
           return false;
       }
       $nmgp_sel_count = 'SELECT COUNT(*) FROM ' . $this->Ini->nm_tabela . ' WHERE ' . $sWhere;
       $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nmgp_sel_count; 
       $rsc = $this->Db->Execute($nmgp_sel_count); 
       if ($rsc === false && !$rsc->EOF)
       {
           $this->Erro->mensagem(__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dbas'], $this->Db->ErrorMsg());
           exit; 
       }
       $iTotal = $rsc->fields[0];
       $rsc->Close();
       return 0 < $iTotal;
   } // temRegistros

   function deletaRegistros($sWhere)
   {
       if ('' == $sWhere)
       {
           return false;
       }
       $nmgp_sel_count = 'DELETE FROM ' . $this->Ini->nm_tabela . ' WHERE ' . $sWhere;
       $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nmgp_sel_count; 
       $rsc = $this->Db->Execute($nmgp_sel_count); 
       $bResult = $rsc;
       $rsc->Close();
       return $bResult == true;
   } // deletaRegistros

   function nm_acessa_banco() 
   { 
      global  $nm_form_submit, $teste_validade, $sc_where;
 
      $NM_val_null = array();
      $NM_val_form = array();
      $this->sc_erro_insert = "";
      $this->sc_erro_update = "";
      $this->sc_erro_delete = "";
      if (!empty($this->sc_force_zero))
      {
          foreach ($this->sc_force_zero as $i_force_zero => $sc_force_zero_field)
          {
              eval('if ($this->' . $sc_force_zero_field . ' == 0) {$this->' . $sc_force_zero_field . ' = "";}');
          }
      }
      $this->sc_force_zero = array();
      $SC_tem_cmp_update = true; 
      $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
      $salva_opcao = $this->nmgp_opcao; 
      if ($this->sc_evento != "novo") 
      { 
          $this->sc_evento = ""; 
      } 
      if (!in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access) && !$this->Ini->sc_tem_trans_banco && in_array($this->nmgp_opcao, array('excluir', 'incluir', 'alterar')))
      { 
          $this->Db->BeginTrans(); 
          $this->Ini->sc_tem_trans_banco = true; 
      } 
      $NM_val_form['bcode'] = $this->bcode;
      $NM_val_form['status'] = $this->status;
      $NM_val_form['updated'] = $this->updated;
      $NM_val_form['number'] = $this->number;
      $NM_val_form['terms'] = $this->terms;
      $NM_val_form['salesman'] = $this->salesman;
      $NM_val_form['tdate'] = $this->tdate;
      $NM_val_form['att'] = $this->att;
      $NM_val_form['prefix'] = $this->prefix;
      $NM_val_form['name'] = $this->name;
      $NM_val_form['address1'] = $this->address1;
      $NM_val_form['address2'] = $this->address2;
      $NM_val_form['city'] = $this->city;
      $NM_val_form['state'] = $this->state;
      $NM_val_form['zip_code'] = $this->zip_code;
      $NM_val_form['country'] = $this->country;
      $NM_val_form['email'] = $this->email;
      $NM_val_form['phone'] = $this->phone;
      $NM_val_form['contact'] = $this->contact;
      $NM_val_form['fax'] = $this->fax;
      $NM_val_form['cphone1'] = $this->cphone1;
      $NM_val_form['cemail1'] = $this->cemail1;
      $NM_val_form['cfax1'] = $this->cfax1;
      $NM_val_form['contact2'] = $this->contact2;
      $NM_val_form['cphone2'] = $this->cphone2;
      $NM_val_form['cemail2'] = $this->cemail2;
      $NM_val_form['cfax2'] = $this->cfax2;
      $NM_val_form['cat1'] = $this->cat1;
      $NM_val_form['cat2'] = $this->cat2;
      $NM_val_form['cat3'] = $this->cat3;
      $NM_val_form['cat4'] = $this->cat4;
      $NM_val_form['cat5'] = $this->cat5;
      $NM_val_form['cat6'] = $this->cat6;
      $NM_val_form['cat7'] = $this->cat7;
      $NM_val_form['mtd'] = $this->mtd;
      $NM_val_form['qtd'] = $this->qtd;
      $NM_val_form['ytd'] = $this->ytd;
      $NM_val_form['jan'] = $this->jan;
      $NM_val_form['feb'] = $this->feb;
      $NM_val_form['mar'] = $this->mar;
      $NM_val_form['apr'] = $this->apr;
      $NM_val_form['may'] = $this->may;
      $NM_val_form['jun'] = $this->jun;
      $NM_val_form['jul'] = $this->jul;
      $NM_val_form['aug'] = $this->aug;
      $NM_val_form['sep'] = $this->sep;
      $NM_val_form['oct'] = $this->oct;
      $NM_val_form['nov'] = $this->nov;
      $NM_val_form['dec'] = $this->dec;
      $NM_val_form['lyear'] = $this->lyear;
      $NM_val_form['llyear'] = $this->llyear;
      $NM_val_form['q1'] = $this->q1;
      $NM_val_form['q2'] = $this->q2;
      $NM_val_form['q4'] = $this->q4;
      $NM_val_form['q3'] = $this->q3;
      $NM_val_form['memo'] = $this->memo;
      $NM_val_form['custship'] = $this->custship;
      $NM_val_form['orders'] = $this->orders;
      $NM_val_form['billing'] = $this->billing;
      $NM_val_form['quotes'] = $this->quotes;
      $NM_val_form['added'] = $this->added;
      $NM_val_form['s365'] = $this->s365;
      $NM_val_form['temp'] = $this->temp;
      if ($this->number == "")  
      { 
          $this->number = 0;
          $this->sc_force_zero[] = 'number';
      } 
      if ($this->mtd == "")  
      { 
          $this->mtd = 0;
          $this->sc_force_zero[] = 'mtd';
      } 
      if ($this->ytd == "")  
      { 
          $this->ytd = 0;
          $this->sc_force_zero[] = 'ytd';
      } 
      if ($this->qtd == "")  
      { 
          $this->qtd = 0;
          $this->sc_force_zero[] = 'qtd';
      } 
      if ($this->jan == "")  
      { 
          $this->jan = 0;
          $this->sc_force_zero[] = 'jan';
      } 
      if ($this->feb == "")  
      { 
          $this->feb = 0;
          $this->sc_force_zero[] = 'feb';
      } 
      if ($this->mar == "")  
      { 
          $this->mar = 0;
          $this->sc_force_zero[] = 'mar';
      } 
      if ($this->apr == "")  
      { 
          $this->apr = 0;
          $this->sc_force_zero[] = 'apr';
      } 
      if ($this->may == "")  
      { 
          $this->may = 0;
          $this->sc_force_zero[] = 'may';
      } 
      if ($this->jun == "")  
      { 
          $this->jun = 0;
          $this->sc_force_zero[] = 'jun';
      } 
      if ($this->jul == "")  
      { 
          $this->jul = 0;
          $this->sc_force_zero[] = 'jul';
      } 
      if ($this->aug == "")  
      { 
          $this->aug = 0;
          $this->sc_force_zero[] = 'aug';
      } 
      if ($this->sep == "")  
      { 
          $this->sep = 0;
          $this->sc_force_zero[] = 'sep';
      } 
      if ($this->oct == "")  
      { 
          $this->oct = 0;
          $this->sc_force_zero[] = 'oct';
      } 
      if ($this->nov == "")  
      { 
          $this->nov = 0;
          $this->sc_force_zero[] = 'nov';
      } 
      if ($this->dec == "")  
      { 
          $this->dec = 0;
          $this->sc_force_zero[] = 'dec';
      } 
      if ($this->lyear == "")  
      { 
          $this->lyear = 0;
          $this->sc_force_zero[] = 'lyear';
      } 
      if ($this->llyear == "")  
      { 
          $this->llyear = 0;
          $this->sc_force_zero[] = 'llyear';
      } 
      if ($this->q1 == "")  
      { 
          $this->q1 = 0;
          $this->sc_force_zero[] = 'q1';
      } 
      if ($this->q2 == "")  
      { 
          $this->q2 = 0;
          $this->sc_force_zero[] = 'q2';
      } 
      if ($this->q3 == "")  
      { 
          $this->q3 = 0;
          $this->sc_force_zero[] = 'q3';
      } 
      if ($this->q4 == "")  
      { 
          $this->q4 = 0;
          $this->sc_force_zero[] = 'q4';
      } 
      if ($this->s365 == "")  
      { 
          $this->s365 = 0;
          $this->sc_force_zero[] = 's365';
      } 
      $nm_bases_lob_geral = array_merge($this->Ini->nm_bases_oracle, $this->Ini->nm_bases_ibase, $this->Ini->nm_bases_informix);
      if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['decimal_db'] == ",") 
      {
          $this->nm_troca_decimal(".", ",");
      }
      if ($this->nmgp_opcao == "alterar" || $this->nmgp_opcao == "incluir") 
      {
          $this->bcode = substr($this->Db->qstr($this->bcode), 1, -1); 
          if ($this->bcode == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->bcode = "null"; 
              $NM_val_null[] = "bcode";
          } 
          $this->status = substr($this->Db->qstr($this->status), 1, -1); 
          if ($this->status == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->status = "null"; 
              $NM_val_null[] = "status";
          } 
          $this->name = substr($this->Db->qstr($this->name), 1, -1); 
          if ($this->name == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->name = "null"; 
              $NM_val_null[] = "name";
          } 
          $this->prefix = substr($this->Db->qstr($this->prefix), 1, -1); 
          if ($this->prefix == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->prefix = "null"; 
              $NM_val_null[] = "prefix";
          } 
          $this->address1 = substr($this->Db->qstr($this->address1), 1, -1); 
          if ($this->address1 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->address1 = "null"; 
              $NM_val_null[] = "address1";
          } 
          $this->address2 = substr($this->Db->qstr($this->address2), 1, -1); 
          if ($this->address2 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->address2 = "null"; 
              $NM_val_null[] = "address2";
          } 
          $this->city = substr($this->Db->qstr($this->city), 1, -1); 
          if ($this->city == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->city = "null"; 
              $NM_val_null[] = "city";
          } 
          $this->state = substr($this->Db->qstr($this->state), 1, -1); 
          if ($this->state == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->state = "null"; 
              $NM_val_null[] = "state";
          } 
          $this->country = substr($this->Db->qstr($this->country), 1, -1); 
          if ($this->country == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->country = "null"; 
              $NM_val_null[] = "country";
          } 
          $this->zip_code = substr($this->Db->qstr($this->zip_code), 1, -1); 
          if ($this->zip_code == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->zip_code = "null"; 
              $NM_val_null[] = "zip_code";
          } 
          $this->salesman = substr($this->Db->qstr($this->salesman), 1, -1); 
          if ($this->salesman == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->salesman = "null"; 
              $NM_val_null[] = "salesman";
          } 
          $this->email = substr($this->Db->qstr($this->email), 1, -1); 
          if ($this->email == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->email = "null"; 
              $NM_val_null[] = "email";
          } 
          $this->cat1 = substr($this->Db->qstr($this->cat1), 1, -1); 
          if ($this->cat1 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->cat1 = "null"; 
              $NM_val_null[] = "cat1";
          } 
          $this->cat2 = substr($this->Db->qstr($this->cat2), 1, -1); 
          if ($this->cat2 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->cat2 = "null"; 
              $NM_val_null[] = "cat2";
          } 
          $this->cat3 = substr($this->Db->qstr($this->cat3), 1, -1); 
          if ($this->cat3 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->cat3 = "null"; 
              $NM_val_null[] = "cat3";
          } 
          $this->cat4 = substr($this->Db->qstr($this->cat4), 1, -1); 
          if ($this->cat4 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->cat4 = "null"; 
              $NM_val_null[] = "cat4";
          } 
          $this->cat5 = substr($this->Db->qstr($this->cat5), 1, -1); 
          if ($this->cat5 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->cat5 = "null"; 
              $NM_val_null[] = "cat5";
          } 
          $this->cat6 = substr($this->Db->qstr($this->cat6), 1, -1); 
          if ($this->cat6 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->cat6 = "null"; 
              $NM_val_null[] = "cat6";
          } 
          $this->cat7 = substr($this->Db->qstr($this->cat7), 1, -1); 
          if ($this->cat7 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->cat7 = "null"; 
              $NM_val_null[] = "cat7";
          } 
          $this->terms = substr($this->Db->qstr($this->terms), 1, -1); 
          if ($this->terms == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->terms = "null"; 
              $NM_val_null[] = "terms";
          } 
          $this->phone = substr($this->Db->qstr($this->phone), 1, -1); 
          if ($this->phone == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->phone = "null"; 
              $NM_val_null[] = "phone";
          } 
          $this->added = substr($this->Db->qstr($this->added), 1, -1); 
          if ($this->added == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->added = "null"; 
              $NM_val_null[] = "added";
          } 
          $this->contact = substr($this->Db->qstr($this->contact), 1, -1); 
          if ($this->contact == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->contact = "null"; 
              $NM_val_null[] = "contact";
          } 
          if ($this->tdate == "")  
          { 
              $this->tdate = "null"; 
              $NM_val_null[] = "tdate";
          } 
          $this->memo = substr($this->Db->qstr($this->memo), 1, -1); 
          if ($this->memo == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->memo = "null"; 
              $NM_val_null[] = "memo";
          } 
          $this->att = substr($this->Db->qstr($this->att), 1, -1); 
          if ($this->att == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->att = "null"; 
              $NM_val_null[] = "att";
          } 
          $this->cphone1 = substr($this->Db->qstr($this->cphone1), 1, -1); 
          if ($this->cphone1 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->cphone1 = "null"; 
              $NM_val_null[] = "cphone1";
          } 
          $this->cphone2 = substr($this->Db->qstr($this->cphone2), 1, -1); 
          if ($this->cphone2 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->cphone2 = "null"; 
              $NM_val_null[] = "cphone2";
          } 
          $this->contact2 = substr($this->Db->qstr($this->contact2), 1, -1); 
          if ($this->contact2 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->contact2 = "null"; 
              $NM_val_null[] = "contact2";
          } 
          $this->cemail1 = substr($this->Db->qstr($this->cemail1), 1, -1); 
          if ($this->cemail1 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->cemail1 = "null"; 
              $NM_val_null[] = "cemail1";
          } 
          $this->cemail2 = substr($this->Db->qstr($this->cemail2), 1, -1); 
          if ($this->cemail2 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->cemail2 = "null"; 
              $NM_val_null[] = "cemail2";
          } 
          $this->fax = substr($this->Db->qstr($this->fax), 1, -1); 
          if ($this->fax == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->fax = "null"; 
              $NM_val_null[] = "fax";
          } 
          $this->cfax1 = substr($this->Db->qstr($this->cfax1), 1, -1); 
          if ($this->cfax1 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->cfax1 = "null"; 
              $NM_val_null[] = "cfax1";
          } 
          $this->cfax2 = substr($this->Db->qstr($this->cfax2), 1, -1); 
          if ($this->cfax2 == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->cfax2 = "null"; 
              $NM_val_null[] = "cfax2";
          } 
          if ($this->updated == "")  
          { 
              $this->updated = "null"; 
              $NM_val_null[] = "updated";
          } 
          $this->temp = substr($this->Db->qstr($this->temp), 1, -1); 
          if ($this->temp == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->temp = "null"; 
              $NM_val_null[] = "temp";
          } 
          $this->custship = substr($this->Db->qstr($this->custship), 1, -1); 
          if ($this->custship == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->custship = "null"; 
              $NM_val_null[] = "custship";
          } 
          $this->billing = substr($this->Db->qstr($this->billing), 1, -1); 
          if ($this->billing == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->billing = "null"; 
              $NM_val_null[] = "billing";
          } 
          $this->orders = substr($this->Db->qstr($this->orders), 1, -1); 
          if ($this->orders == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->orders = "null"; 
              $NM_val_null[] = "orders";
          } 
          $this->quotes = substr($this->Db->qstr($this->quotes), 1, -1); 
          if ($this->quotes == "" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))  
          { 
              $this->quotes = "null"; 
              $NM_val_null[] = "quotes";
          } 
      }
      if ($this->nmgp_opcao == "alterar") 
      {
          $SC_ex_update = true; 
          $SC_ex_upd_or = true; 
          if (($this->Embutida_form || $this->Embutida_multi) && isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['foreign_key']) && !empty($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['foreign_key']))
          {
              foreach ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['foreign_key'] as $sFKName => $sFKValue)
              {
                   if (isset($this->sc_conv_var[$sFKName]))
                   {
                       $sFKName = $this->sc_conv_var[$sFKName];
                   }
                  eval("\$this->" . $sFKName . " = \"" . $sFKValue . "\";");
              }
          }
          if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['decimal_db'] == ",") 
          {
              $this->nm_poe_aspas_decimal();
          }
          if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' ";
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' ";
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' ";
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' ";
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          else  
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' ";
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          if ($rs1 === false)  
          { 
              $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dbas'], $this->Db->ErrorMsg()); 
              if ($this->NM_ajax_flag)
              {
                 custbill_form_pack_ajax_response();
              }
              exit; 
          }  
          $bUpdateOk = true;
          $tmp_result = (int) $rs1->fields[0]; 
          if ($tmp_result != 1) 
          { 
              $this->Erro->mensagem (__FILE__, __LINE__, "critica", $this->Ini->Nm_lang['lang_errm_nfnd']); 
              $this->nmgp_opcao = "nada"; 
              $bUpdateOk = false;
              $this->sc_evento = 'update';
          } 
          $aUpdateOk = array();
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where (BCODE = '" . $this->bcode . "') AND (BCODE <> '$this->bcode')";
              $rsUni = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where (BCODE = '" . $this->bcode . "') AND (BCODE <> '$this->bcode')");
              if (0 < $rsUni->fields[0])
              {
                  $this->Erro->mensagem (__FILE__, __LINE__, "critica", $this->Ini->Nm_lang['lang_errm_ukey'] . " BCODE"); 
                  $this->nmgp_opcao = "nada"; 
                  $aUpdateOk[] = 'bcode';
              }
              $rsUni->Close();
          $bUpdateOk = $bUpdateOk && empty($aUpdateOk);
          if ($bUpdateOk)
          { 
              $rs1->Close(); 
              if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
              { 
                  $comando = "UPDATE " . $this->Ini->nm_tabela . " SET STATUS = '$this->status', NAME = '$this->name', NUMBER = $this->number, PREFIX = '$this->prefix', ADDRESS1 = '$this->address1', ADDRESS2 = '$this->address2', CITY = '$this->city', STATE = '$this->state', COUNTRY = '$this->country', ZIP_CODE = '$this->zip_code', SALESMAN = '$this->salesman', EMAIL = '$this->email', CAT1 = '$this->cat1', CAT2 = '$this->cat2', CAT3 = '$this->cat3', CAT4 = '$this->cat4', CAT5 = '$this->cat5', CAT6 = '$this->cat6', CAT7 = '$this->cat7', TERMS = '$this->terms', PHONE = '$this->phone', CONTACT = '$this->contact', MEMO = '$this->memo', ATT = '$this->att', CPHONE1 = '$this->cphone1', CPHONE2 = '$this->cphone2', CONTACT2 = '$this->contact2', CEMAIL1 = '$this->cemail1', CEMAIL2 = '$this->cemail2', FAX = '$this->fax', CFAX1 = '$this->cfax1', CFAX2 = '$this->cfax2', SEP = $this->sep, OCT = $this->oct, NOV = $this->nov, `DEC` = $this->dec, LYEAR = $this->lyear, LLYEAR = $this->llyear, Q1 = $this->q1, Q2 = $this->q2, Q3 = $this->q3, Q4 = $this->q4";  
              } 
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
              { 
                  $comando = "UPDATE " . $this->Ini->nm_tabela . " SET STATUS = '$this->status', NAME = '$this->name', NUMBER = $this->number, PREFIX = '$this->prefix', ADDRESS1 = '$this->address1', ADDRESS2 = '$this->address2', CITY = '$this->city', STATE = '$this->state', COUNTRY = '$this->country', ZIP_CODE = '$this->zip_code', SALESMAN = '$this->salesman', EMAIL = '$this->email', CAT1 = '$this->cat1', CAT2 = '$this->cat2', CAT3 = '$this->cat3', CAT4 = '$this->cat4', CAT5 = '$this->cat5', CAT6 = '$this->cat6', CAT7 = '$this->cat7', TERMS = '$this->terms', PHONE = '$this->phone', CONTACT = '$this->contact', MEMO = '$this->memo', ATT = '$this->att', CPHONE1 = '$this->cphone1', CPHONE2 = '$this->cphone2', CONTACT2 = '$this->contact2', CEMAIL1 = '$this->cemail1', CEMAIL2 = '$this->cemail2', FAX = '$this->fax', CFAX1 = '$this->cfax1', CFAX2 = '$this->cfax2', SEP = $this->sep, OCT = $this->oct, NOV = $this->nov, `DEC` = $this->dec, LYEAR = $this->lyear, LLYEAR = $this->llyear, Q1 = $this->q1, Q2 = $this->q2, Q3 = $this->q3, Q4 = $this->q4";  
              } 
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
              { 
                  $comando_oracle = "UPDATE " . $this->Ini->nm_tabela . " SET STATUS = '$this->status', NAME = '$this->name', NUMBER = $this->number, PREFIX = '$this->prefix', ADDRESS1 = '$this->address1', ADDRESS2 = '$this->address2', CITY = '$this->city', STATE = '$this->state', COUNTRY = '$this->country', ZIP_CODE = '$this->zip_code', SALESMAN = '$this->salesman', EMAIL = '$this->email', CAT1 = '$this->cat1', CAT2 = '$this->cat2', CAT3 = '$this->cat3', CAT4 = '$this->cat4', CAT5 = '$this->cat5', CAT6 = '$this->cat6', CAT7 = '$this->cat7', TERMS = '$this->terms', PHONE = '$this->phone', CONTACT = '$this->contact', MEMO = '$this->memo', ATT = '$this->att', CPHONE1 = '$this->cphone1', CPHONE2 = '$this->cphone2', CONTACT2 = '$this->contact2', CEMAIL1 = '$this->cemail1', CEMAIL2 = '$this->cemail2', FAX = '$this->fax', CFAX1 = '$this->cfax1', CFAX2 = '$this->cfax2', SEP = $this->sep, OCT = $this->oct, NOV = $this->nov, `DEC` = $this->dec, LYEAR = $this->lyear, LLYEAR = $this->llyear, Q1 = $this->q1, Q2 = $this->q2, Q3 = $this->q3, Q4 = $this->q4";  
              } 
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
              { 
                  $comando_oracle = "UPDATE " . $this->Ini->nm_tabela . " SET STATUS = '$this->status', NAME = '$this->name', NUMBER = $this->number, PREFIX = '$this->prefix', ADDRESS1 = '$this->address1', ADDRESS2 = '$this->address2', CITY = '$this->city', STATE = '$this->state', COUNTRY = '$this->country', ZIP_CODE = '$this->zip_code', SALESMAN = '$this->salesman', EMAIL = '$this->email', CAT1 = '$this->cat1', CAT2 = '$this->cat2', CAT3 = '$this->cat3', CAT4 = '$this->cat4', CAT5 = '$this->cat5', CAT6 = '$this->cat6', CAT7 = '$this->cat7', TERMS = '$this->terms', PHONE = '$this->phone', CONTACT = '$this->contact', MEMO = '$this->memo', ATT = '$this->att', CPHONE1 = '$this->cphone1', CPHONE2 = '$this->cphone2', CONTACT2 = '$this->contact2', CEMAIL1 = '$this->cemail1', CEMAIL2 = '$this->cemail2', FAX = '$this->fax', CFAX1 = '$this->cfax1', CFAX2 = '$this->cfax2', SEP = $this->sep, OCT = $this->oct, NOV = $this->nov, `DEC` = $this->dec, LYEAR = $this->lyear, LLYEAR = $this->llyear, Q1 = $this->q1, Q2 = $this->q2, Q3 = $this->q3, Q4 = $this->q4";  
              } 
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_ibase))
              { 
                  $comando_oracle = "UPDATE " . $this->Ini->nm_tabela . " SET STATUS = '$this->status', NAME = '$this->name', NUMBER = $this->number, PREFIX = '$this->prefix', ADDRESS1 = '$this->address1', ADDRESS2 = '$this->address2', CITY = '$this->city', STATE = '$this->state', COUNTRY = '$this->country', ZIP_CODE = '$this->zip_code', SALESMAN = '$this->salesman', EMAIL = '$this->email', CAT1 = '$this->cat1', CAT2 = '$this->cat2', CAT3 = '$this->cat3', CAT4 = '$this->cat4', CAT5 = '$this->cat5', CAT6 = '$this->cat6', CAT7 = '$this->cat7', TERMS = '$this->terms', PHONE = '$this->phone', CONTACT = '$this->contact', MEMO = '$this->memo', ATT = '$this->att', CPHONE1 = '$this->cphone1', CPHONE2 = '$this->cphone2', CONTACT2 = '$this->contact2', CEMAIL1 = '$this->cemail1', CEMAIL2 = '$this->cemail2', FAX = '$this->fax', CFAX1 = '$this->cfax1', CFAX2 = '$this->cfax2', SEP = $this->sep, OCT = $this->oct, NOV = $this->nov, `DEC` = $this->dec, LYEAR = $this->lyear, LLYEAR = $this->llyear, Q1 = $this->q1, Q2 = $this->q2, Q3 = $this->q3, Q4 = $this->q4";  
              } 
              else 
              { 
                  $comando = "UPDATE " . $this->Ini->nm_tabela . " SET STATUS = '$this->status', NAME = '$this->name', NUMBER = $this->number, PREFIX = '$this->prefix', ADDRESS1 = '$this->address1', ADDRESS2 = '$this->address2', CITY = '$this->city', STATE = '$this->state', COUNTRY = '$this->country', ZIP_CODE = '$this->zip_code', SALESMAN = '$this->salesman', EMAIL = '$this->email', CAT1 = '$this->cat1', CAT2 = '$this->cat2', CAT3 = '$this->cat3', CAT4 = '$this->cat4', CAT5 = '$this->cat5', CAT6 = '$this->cat6', CAT7 = '$this->cat7', TERMS = '$this->terms', PHONE = '$this->phone', CONTACT = '$this->contact', MEMO = '$this->memo', ATT = '$this->att', CPHONE1 = '$this->cphone1', CPHONE2 = '$this->cphone2', CONTACT2 = '$this->contact2', CEMAIL1 = '$this->cemail1', CEMAIL2 = '$this->cemail2', FAX = '$this->fax', CFAX1 = '$this->cfax1', CFAX2 = '$this->cfax2', SEP = $this->sep, OCT = $this->oct, NOV = $this->nov, `DEC` = $this->dec, LYEAR = $this->lyear, LLYEAR = $this->llyear, Q1 = $this->q1, Q2 = $this->q2, Q3 = $this->q3, Q4 = $this->q4";  
              } 
              if (isset($NM_val_form['added']) && $NM_val_form['added'] != $this->nmgp_dados_select['added']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " ADDED = '$this->added'"; 
                  $comando_oracle        .= " ADDED = '$this->added'"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['tdate']) && $NM_val_form['tdate'] != $this->nmgp_dados_select['tdate']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
                  { 
                      $comando        .= " TDATE = #$this->tdate#"; 
                  } 
                  else 
                  { 
                      $comando        .= " TDATE = '$this->tdate'"; 
                  } 
                  if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
                  { 
                      $comando_oracle        .= " TDATE = EXTEND('" . $this->tdate . "', YEAR TO DAY)"; 
                  } 
                  else
                  { 
                      $comando_oracle        .= " TDATE = '$this->tdate'"; 
                  } 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['mtd']) && $NM_val_form['mtd'] != $this->nmgp_dados_select['mtd']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " MTD = $this->mtd"; 
                  $comando_oracle        .= " MTD = $this->mtd"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['ytd']) && $NM_val_form['ytd'] != $this->nmgp_dados_select['ytd']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " YTD = $this->ytd"; 
                  $comando_oracle        .= " YTD = $this->ytd"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['qtd']) && $NM_val_form['qtd'] != $this->nmgp_dados_select['qtd']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " QTD = $this->qtd"; 
                  $comando_oracle        .= " QTD = $this->qtd"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['jan']) && $NM_val_form['jan'] != $this->nmgp_dados_select['jan']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " JAN = $this->jan"; 
                  $comando_oracle        .= " JAN = $this->jan"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['feb']) && $NM_val_form['feb'] != $this->nmgp_dados_select['feb']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " FEB = $this->feb"; 
                  $comando_oracle        .= " FEB = $this->feb"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['mar']) && $NM_val_form['mar'] != $this->nmgp_dados_select['mar']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " MAR = $this->mar"; 
                  $comando_oracle        .= " MAR = $this->mar"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['apr']) && $NM_val_form['apr'] != $this->nmgp_dados_select['apr']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " APR = $this->apr"; 
                  $comando_oracle        .= " APR = $this->apr"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['may']) && $NM_val_form['may'] != $this->nmgp_dados_select['may']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " MAY = $this->may"; 
                  $comando_oracle        .= " MAY = $this->may"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['jun']) && $NM_val_form['jun'] != $this->nmgp_dados_select['jun']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " JUN = $this->jun"; 
                  $comando_oracle        .= " JUN = $this->jun"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['jul']) && $NM_val_form['jul'] != $this->nmgp_dados_select['jul']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " JUL = $this->jul"; 
                  $comando_oracle        .= " JUL = $this->jul"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['aug']) && $NM_val_form['aug'] != $this->nmgp_dados_select['aug']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " AUG = $this->aug"; 
                  $comando_oracle        .= " AUG = $this->aug"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['updated']) && $NM_val_form['updated'] != $this->nmgp_dados_select['updated']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
                  { 
                      $comando        .= " UPDATED = #$this->updated#"; 
                  } 
                  else 
                  { 
                      $comando        .= " UPDATED = '$this->updated'"; 
                  } 
                  if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
                  { 
                      $comando_oracle        .= " UPDATED = EXTEND('" . $this->updated . "', YEAR TO DAY)"; 
                  } 
                  else
                  { 
                      $comando_oracle        .= " UPDATED = '$this->updated'"; 
                  } 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['s365']) && $NM_val_form['s365'] != $this->nmgp_dados_select['s365']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " S365 = $this->s365"; 
                  $comando_oracle        .= " S365 = $this->s365"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (isset($NM_val_form['temp']) && $NM_val_form['temp'] != $this->nmgp_dados_select['temp']) 
              { 
                  if ($SC_ex_update || $SC_tem_cmp_update) 
                  { 
                      $comando        .= ","; 
                      $comando_oracle .= ","; 
                  } 
                  $comando        .= " TEMP = '$this->temp'"; 
                  $comando_oracle        .= " TEMP = '$this->temp'"; 
                  $SC_ex_update = true; 
                  $SC_ex_upd_or = true; 
              } 
              if (in_array(strtolower($this->Ini->nm_tpbanco), $nm_bases_lob_geral))
              { 
                  $comando = $comando_oracle;  
                  $SC_ex_update = $SC_ex_upd_or;
              }   
              if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
              {
                  $comando .= " WHERE BCODE = '$this->bcode' ";  
              }  
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
              {
                  $comando .= " WHERE BCODE = '$this->bcode' ";  
              }  
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
              {
                  $comando .= " WHERE BCODE = '$this->bcode' ";  
              }  
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
              {
                  $comando .= " WHERE BCODE = '$this->bcode' ";  
              }  
              else  
              {
                  $comando .= " WHERE BCODE = '$this->bcode' ";  
              }  
              $comando = str_replace("'null'", "null", $comando) ; 
              $comando = str_replace("#null#", "null", $comando) ; 
              if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
              {
                $comando = str_replace("EXTEND('', YEAR TO FRACTION)", "null", $comando) ; 
                $comando = str_replace("EXTEND(null, YEAR TO FRACTION)", "null", $comando) ; 
                $comando = str_replace("EXTEND('', YEAR TO DAY)", "null", $comando) ; 
                $comando = str_replace("EXTEND(null, YEAR TO DAY)", "null", $comando) ; 
              }  
              if ($SC_ex_update || $SC_tem_cmp_update)
              { 
                  $_SESSION['scriptcase']['sc_sql_ult_comando'] = $comando; 
                  $rs = $this->Db->Execute($comando);  
                  if ($rs === false) 
                  { 
                      if (FALSE === strpos(strtoupper($this->Db->ErrorMsg()), "MAIL SENT") && FALSE === strpos(strtoupper($this->Db->ErrorMsg()), "WARNING"))
                      {
                          $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_updt'], $this->Db->ErrorMsg(), true); 
                          if (isset($_SESSION['scriptcase']['erro_handler']) && $_SESSION['scriptcase']['erro_handler']) 
                          { 
                              $this->sc_erro_update = $this->Db->ErrorMsg();  
                              $this->NM_rollback_db(); 
                              if ($this->NM_ajax_flag)
                              {
                                  custbill_form_pack_ajax_response();
                              }
                              exit;  
                          }   
                      }   
                  }   
              }   
              if (in_array(strtolower($this->Ini->nm_tpbanco), $nm_bases_lob_geral))
              { 
              }   
              $this->sc_evento = "update"; 
              $this->nmgp_opcao = "igual"; 
              $this->nm_flag_iframe = true;
              if ($this->lig_edit_lookup)
              {
                  $this->lig_edit_lookup_call = true;
              }

              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['db_changed'] = true;


              if     (isset($NM_val_form) && isset($NM_val_form['bcode'])) { $this->bcode = $NM_val_form['bcode']; }
              elseif (isset($this->bcode)) { $this->nm_limpa_alfa($this->bcode); }
              if     (isset($NM_val_form) && isset($NM_val_form['status'])) { $this->status = $NM_val_form['status']; }
              elseif (isset($this->status)) { $this->nm_limpa_alfa($this->status); }
              if     (isset($NM_val_form) && isset($NM_val_form['name'])) { $this->name = $NM_val_form['name']; }
              elseif (isset($this->name)) { $this->nm_limpa_alfa($this->name); }
              if     (isset($NM_val_form) && isset($NM_val_form['number'])) { $this->number = $NM_val_form['number']; }
              elseif (isset($this->number)) { $this->nm_limpa_alfa($this->number); }
              if     (isset($NM_val_form) && isset($NM_val_form['prefix'])) { $this->prefix = $NM_val_form['prefix']; }
              elseif (isset($this->prefix)) { $this->nm_limpa_alfa($this->prefix); }
              if     (isset($NM_val_form) && isset($NM_val_form['address1'])) { $this->address1 = $NM_val_form['address1']; }
              elseif (isset($this->address1)) { $this->nm_limpa_alfa($this->address1); }
              if     (isset($NM_val_form) && isset($NM_val_form['address2'])) { $this->address2 = $NM_val_form['address2']; }
              elseif (isset($this->address2)) { $this->nm_limpa_alfa($this->address2); }
              if     (isset($NM_val_form) && isset($NM_val_form['city'])) { $this->city = $NM_val_form['city']; }
              elseif (isset($this->city)) { $this->nm_limpa_alfa($this->city); }
              if     (isset($NM_val_form) && isset($NM_val_form['state'])) { $this->state = $NM_val_form['state']; }
              elseif (isset($this->state)) { $this->nm_limpa_alfa($this->state); }
              if     (isset($NM_val_form) && isset($NM_val_form['country'])) { $this->country = $NM_val_form['country']; }
              elseif (isset($this->country)) { $this->nm_limpa_alfa($this->country); }
              if     (isset($NM_val_form) && isset($NM_val_form['zip_code'])) { $this->zip_code = $NM_val_form['zip_code']; }
              elseif (isset($this->zip_code)) { $this->nm_limpa_alfa($this->zip_code); }
              if     (isset($NM_val_form) && isset($NM_val_form['salesman'])) { $this->salesman = $NM_val_form['salesman']; }
              elseif (isset($this->salesman)) { $this->nm_limpa_alfa($this->salesman); }
              if     (isset($NM_val_form) && isset($NM_val_form['email'])) { $this->email = $NM_val_form['email']; }
              elseif (isset($this->email)) { $this->nm_limpa_alfa($this->email); }
              if     (isset($NM_val_form) && isset($NM_val_form['cat1'])) { $this->cat1 = $NM_val_form['cat1']; }
              elseif (isset($this->cat1)) { $this->nm_limpa_alfa($this->cat1); }
              if     (isset($NM_val_form) && isset($NM_val_form['cat2'])) { $this->cat2 = $NM_val_form['cat2']; }
              elseif (isset($this->cat2)) { $this->nm_limpa_alfa($this->cat2); }
              if     (isset($NM_val_form) && isset($NM_val_form['cat3'])) { $this->cat3 = $NM_val_form['cat3']; }
              elseif (isset($this->cat3)) { $this->nm_limpa_alfa($this->cat3); }
              if     (isset($NM_val_form) && isset($NM_val_form['cat4'])) { $this->cat4 = $NM_val_form['cat4']; }
              elseif (isset($this->cat4)) { $this->nm_limpa_alfa($this->cat4); }
              if     (isset($NM_val_form) && isset($NM_val_form['cat5'])) { $this->cat5 = $NM_val_form['cat5']; }
              elseif (isset($this->cat5)) { $this->nm_limpa_alfa($this->cat5); }
              if     (isset($NM_val_form) && isset($NM_val_form['cat6'])) { $this->cat6 = $NM_val_form['cat6']; }
              elseif (isset($this->cat6)) { $this->nm_limpa_alfa($this->cat6); }
              if     (isset($NM_val_form) && isset($NM_val_form['cat7'])) { $this->cat7 = $NM_val_form['cat7']; }
              elseif (isset($this->cat7)) { $this->nm_limpa_alfa($this->cat7); }
              if     (isset($NM_val_form) && isset($NM_val_form['terms'])) { $this->terms = $NM_val_form['terms']; }
              elseif (isset($this->terms)) { $this->nm_limpa_alfa($this->terms); }
              if     (isset($NM_val_form) && isset($NM_val_form['phone'])) { $this->phone = $NM_val_form['phone']; }
              elseif (isset($this->phone)) { $this->nm_limpa_alfa($this->phone); }
              if     (isset($NM_val_form) && isset($NM_val_form['contact'])) { $this->contact = $NM_val_form['contact']; }
              elseif (isset($this->contact)) { $this->nm_limpa_alfa($this->contact); }
              if     (isset($NM_val_form) && isset($NM_val_form['memo'])) { $this->memo = $NM_val_form['memo']; }
              elseif (isset($this->memo)) { $this->nm_limpa_alfa($this->memo); }
              if     (isset($NM_val_form) && isset($NM_val_form['att'])) { $this->att = $NM_val_form['att']; }
              elseif (isset($this->att)) { $this->nm_limpa_alfa($this->att); }
              if     (isset($NM_val_form) && isset($NM_val_form['cphone1'])) { $this->cphone1 = $NM_val_form['cphone1']; }
              elseif (isset($this->cphone1)) { $this->nm_limpa_alfa($this->cphone1); }
              if     (isset($NM_val_form) && isset($NM_val_form['cphone2'])) { $this->cphone2 = $NM_val_form['cphone2']; }
              elseif (isset($this->cphone2)) { $this->nm_limpa_alfa($this->cphone2); }
              if     (isset($NM_val_form) && isset($NM_val_form['contact2'])) { $this->contact2 = $NM_val_form['contact2']; }
              elseif (isset($this->contact2)) { $this->nm_limpa_alfa($this->contact2); }
              if     (isset($NM_val_form) && isset($NM_val_form['cemail1'])) { $this->cemail1 = $NM_val_form['cemail1']; }
              elseif (isset($this->cemail1)) { $this->nm_limpa_alfa($this->cemail1); }
              if     (isset($NM_val_form) && isset($NM_val_form['cemail2'])) { $this->cemail2 = $NM_val_form['cemail2']; }
              elseif (isset($this->cemail2)) { $this->nm_limpa_alfa($this->cemail2); }
              if     (isset($NM_val_form) && isset($NM_val_form['fax'])) { $this->fax = $NM_val_form['fax']; }
              elseif (isset($this->fax)) { $this->nm_limpa_alfa($this->fax); }
              if     (isset($NM_val_form) && isset($NM_val_form['cfax1'])) { $this->cfax1 = $NM_val_form['cfax1']; }
              elseif (isset($this->cfax1)) { $this->nm_limpa_alfa($this->cfax1); }
              if     (isset($NM_val_form) && isset($NM_val_form['cfax2'])) { $this->cfax2 = $NM_val_form['cfax2']; }
              elseif (isset($this->cfax2)) { $this->nm_limpa_alfa($this->cfax2); }
              if     (isset($NM_val_form) && isset($NM_val_form['mtd'])) { $this->mtd = $NM_val_form['mtd']; }
              elseif (isset($this->mtd)) { $this->nm_limpa_alfa($this->mtd); }
              if     (isset($NM_val_form) && isset($NM_val_form['ytd'])) { $this->ytd = $NM_val_form['ytd']; }
              elseif (isset($this->ytd)) { $this->nm_limpa_alfa($this->ytd); }
              if     (isset($NM_val_form) && isset($NM_val_form['qtd'])) { $this->qtd = $NM_val_form['qtd']; }
              elseif (isset($this->qtd)) { $this->nm_limpa_alfa($this->qtd); }
              if     (isset($NM_val_form) && isset($NM_val_form['jan'])) { $this->jan = $NM_val_form['jan']; }
              elseif (isset($this->jan)) { $this->nm_limpa_alfa($this->jan); }
              if     (isset($NM_val_form) && isset($NM_val_form['feb'])) { $this->feb = $NM_val_form['feb']; }
              elseif (isset($this->feb)) { $this->nm_limpa_alfa($this->feb); }
              if     (isset($NM_val_form) && isset($NM_val_form['mar'])) { $this->mar = $NM_val_form['mar']; }
              elseif (isset($this->mar)) { $this->nm_limpa_alfa($this->mar); }
              if     (isset($NM_val_form) && isset($NM_val_form['apr'])) { $this->apr = $NM_val_form['apr']; }
              elseif (isset($this->apr)) { $this->nm_limpa_alfa($this->apr); }
              if     (isset($NM_val_form) && isset($NM_val_form['may'])) { $this->may = $NM_val_form['may']; }
              elseif (isset($this->may)) { $this->nm_limpa_alfa($this->may); }
              if     (isset($NM_val_form) && isset($NM_val_form['jun'])) { $this->jun = $NM_val_form['jun']; }
              elseif (isset($this->jun)) { $this->nm_limpa_alfa($this->jun); }
              if     (isset($NM_val_form) && isset($NM_val_form['jul'])) { $this->jul = $NM_val_form['jul']; }
              elseif (isset($this->jul)) { $this->nm_limpa_alfa($this->jul); }
              if     (isset($NM_val_form) && isset($NM_val_form['aug'])) { $this->aug = $NM_val_form['aug']; }
              elseif (isset($this->aug)) { $this->nm_limpa_alfa($this->aug); }
              if     (isset($NM_val_form) && isset($NM_val_form['sep'])) { $this->sep = $NM_val_form['sep']; }
              elseif (isset($this->sep)) { $this->nm_limpa_alfa($this->sep); }
              if     (isset($NM_val_form) && isset($NM_val_form['oct'])) { $this->oct = $NM_val_form['oct']; }
              elseif (isset($this->oct)) { $this->nm_limpa_alfa($this->oct); }
              if     (isset($NM_val_form) && isset($NM_val_form['nov'])) { $this->nov = $NM_val_form['nov']; }
              elseif (isset($this->nov)) { $this->nm_limpa_alfa($this->nov); }
              if     (isset($NM_val_form) && isset($NM_val_form['dec'])) { $this->dec = $NM_val_form['dec']; }
              elseif (isset($this->dec)) { $this->nm_limpa_alfa($this->dec); }
              if     (isset($NM_val_form) && isset($NM_val_form['lyear'])) { $this->lyear = $NM_val_form['lyear']; }
              elseif (isset($this->lyear)) { $this->nm_limpa_alfa($this->lyear); }
              if     (isset($NM_val_form) && isset($NM_val_form['llyear'])) { $this->llyear = $NM_val_form['llyear']; }
              elseif (isset($this->llyear)) { $this->nm_limpa_alfa($this->llyear); }
              if     (isset($NM_val_form) && isset($NM_val_form['q1'])) { $this->q1 = $NM_val_form['q1']; }
              elseif (isset($this->q1)) { $this->nm_limpa_alfa($this->q1); }
              if     (isset($NM_val_form) && isset($NM_val_form['q2'])) { $this->q2 = $NM_val_form['q2']; }
              elseif (isset($this->q2)) { $this->nm_limpa_alfa($this->q2); }
              if     (isset($NM_val_form) && isset($NM_val_form['q3'])) { $this->q3 = $NM_val_form['q3']; }
              elseif (isset($this->q3)) { $this->nm_limpa_alfa($this->q3); }
              if     (isset($NM_val_form) && isset($NM_val_form['q4'])) { $this->q4 = $NM_val_form['q4']; }
              elseif (isset($this->q4)) { $this->nm_limpa_alfa($this->q4); }
              if     (isset($NM_val_form) && isset($NM_val_form['custship'])) { $this->custship = $NM_val_form['custship']; }
              elseif (isset($this->custship)) { $this->nm_limpa_alfa($this->custship); }
              if     (isset($NM_val_form) && isset($NM_val_form['billing'])) { $this->billing = $NM_val_form['billing']; }
              elseif (isset($this->billing)) { $this->nm_limpa_alfa($this->billing); }
              if     (isset($NM_val_form) && isset($NM_val_form['orders'])) { $this->orders = $NM_val_form['orders']; }
              elseif (isset($this->orders)) { $this->nm_limpa_alfa($this->orders); }
              if     (isset($NM_val_form) && isset($NM_val_form['quotes'])) { $this->quotes = $NM_val_form['quotes']; }
              elseif (isset($this->quotes)) { $this->nm_limpa_alfa($this->quotes); }

              $this->nm_formatar_campos();
              if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
              {
              }

              $aOldRefresh               = $this->nmgp_refresh_fields;
              $this->nmgp_refresh_fields = array('bcode', 'status', 'updated', 'number', 'terms', 'salesman', 'tdate', 'att', 'prefix', 'name', 'address1', 'address2', 'city', 'state', 'zip_code', 'country', 'email', 'phone', 'contact', 'fax', 'cphone1', 'cemail1', 'cfax1', 'contact2', 'cphone2', 'cemail2', 'cfax2', 'cat1', 'cat2', 'cat3', 'cat4', 'cat5', 'cat6', 'cat7', 'mtd', 'qtd', 'ytd', 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec', 'lyear', 'llyear', 'q1', 'q2', 'q4', 'q3', 'memo', 'custship', 'orders', 'billing', 'quotes');
              $this->ajax_return_values();
              $this->nmgp_refresh_fields = $aOldRefresh;

              $this->nm_tira_formatacao();
              $this->nm_converte_datas();
          }  
      }  
      if ($this->nmgp_opcao == "incluir") 
      { 
          $NM_cmp_auto = "";
          $NM_seq_auto = "";
          if (($this->Embutida_form || $this->Embutida_multi) && isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['foreign_key']) && !empty($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['foreign_key']))
          {
              foreach ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['foreign_key'] as $sFKName => $sFKValue)
              {
                   if (isset($this->sc_conv_var[$sFKName]))
                   {
                       $sFKName = $this->sc_conv_var[$sFKName];
                   }
                  eval("\$this->" . $sFKName . " = \"" . $sFKValue . "\";");
              }
          }
          if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['decimal_db'] == ",") 
          {
              $this->nm_poe_aspas_decimal();
          }
          $bInsertOk = true;
          if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "; 
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "; 
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "; 
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "; 
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          else  
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "; 
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          if ($rs1 === false)  
          { 
              $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dbas'], $this->Db->ErrorMsg()); 
              exit; 
          }  
          $tmp_result = (int) $rs1->fields[0]; 
          if ($tmp_result != 0) 
          { 
              $this->Erro->mensagem (__FILE__, __LINE__, "critica", $this->Ini->Nm_lang['lang_errm_pkey']); 
              $this->nmgp_opcao = "nada"; 
              $GLOBALS["erro_incl"] = 1; 
              $bInsertOk = false;
              $this->sc_evento = 'insert';
          } 
          $rs1->Close(); 
          $aInsertOk = array(); 
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '" . $this->bcode . "'";
              $rsUni = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '" . $this->bcode . "'");
              if (0 < $rsUni->fields[0])
              {
                  $this->Erro->mensagem (__FILE__, __LINE__, "critica", $this->Ini->Nm_lang['lang_errm_inst_uniq'] . " BCODE"); 
                  $this->nmgp_opcao = "nada"; 
                  $GLOBALS["erro_incl"] = 1; 
                  $aInsertOk[] = 'bcode';
              }
              $rsUni->Close();
          $bInsertOk = $bInsertOk && empty($aInsertOk);
          if ($bInsertOk)
          { 
              if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
              { 
                  $comando = "INSERT INTO " . $this->Ini->nm_tabela . " (BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, TDATE, MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC`, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, UPDATED, S365, TEMP) VALUES ('$this->bcode', '$this->status', '$this->name', $this->number, '$this->prefix', '$this->address1', '$this->address2', '$this->city', '$this->state', '$this->country', '$this->zip_code', '$this->salesman', '$this->email', '$this->cat1', '$this->cat2', '$this->cat3', '$this->cat4', '$this->cat5', '$this->cat6', '$this->cat7', '$this->terms', '$this->phone', '$this->added', '$this->contact', #$this->tdate#, '$this->memo', '$this->att', '$this->cphone1', '$this->cphone2', '$this->contact2', '$this->cemail1', '$this->cemail2', '$this->fax', '$this->cfax1', '$this->cfax2', $this->mtd, $this->ytd, $this->qtd, $this->jan, $this->feb, $this->mar, $this->apr, $this->may, $this->jun, $this->jul, $this->aug, $this->sep, $this->oct, $this->nov, $this->dec, $this->lyear, $this->llyear, $this->q1, $this->q2, $this->q3, $this->q4, #$this->updated#, $this->s365, '$this->temp')"; 
              }
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
              { 
                  $comando = "INSERT INTO " . $this->Ini->nm_tabela . " (" . $NM_cmp_auto . "BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, TDATE, MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC`, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, UPDATED, S365, TEMP) VALUES (" . $NM_seq_auto . "'$this->bcode', '$this->status', '$this->name', $this->number, '$this->prefix', '$this->address1', '$this->address2', '$this->city', '$this->state', '$this->country', '$this->zip_code', '$this->salesman', '$this->email', '$this->cat1', '$this->cat2', '$this->cat3', '$this->cat4', '$this->cat5', '$this->cat6', '$this->cat7', '$this->terms', '$this->phone', '$this->added', '$this->contact', '$this->tdate', '$this->memo', '$this->att', '$this->cphone1', '$this->cphone2', '$this->contact2', '$this->cemail1', '$this->cemail2', '$this->fax', '$this->cfax1', '$this->cfax2', $this->mtd, $this->ytd, $this->qtd, $this->jan, $this->feb, $this->mar, $this->apr, $this->may, $this->jun, $this->jul, $this->aug, $this->sep, $this->oct, $this->nov, $this->dec, $this->lyear, $this->llyear, $this->q1, $this->q2, $this->q3, $this->q4, '$this->updated', $this->s365, '$this->temp')"; 
              }
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
              {
                  $comando = "INSERT INTO " . $this->Ini->nm_tabela . " (" . $NM_cmp_auto . "BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, TDATE, MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC`, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, UPDATED, S365, TEMP) VALUES (" . $NM_seq_auto . "'$this->bcode', '$this->status', '$this->name', $this->number, '$this->prefix', '$this->address1', '$this->address2', '$this->city', '$this->state', '$this->country', '$this->zip_code', '$this->salesman', '$this->email', '$this->cat1', '$this->cat2', '$this->cat3', '$this->cat4', '$this->cat5', '$this->cat6', '$this->cat7', '$this->terms', '$this->phone', '$this->added', '$this->contact', '$this->tdate', '$this->memo', '$this->att', '$this->cphone1', '$this->cphone2', '$this->contact2', '$this->cemail1', '$this->cemail2', '$this->fax', '$this->cfax1', '$this->cfax2', $this->mtd, $this->ytd, $this->qtd, $this->jan, $this->feb, $this->mar, $this->apr, $this->may, $this->jun, $this->jul, $this->aug, $this->sep, $this->oct, $this->nov, $this->dec, $this->lyear, $this->llyear, $this->q1, $this->q2, $this->q3, $this->q4, '$this->updated', $this->s365, '$this->temp')"; 
              }
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
              {
                  $comando = "INSERT INTO " . $this->Ini->nm_tabela . " (" . $NM_cmp_auto . "BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, TDATE, MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC`, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, UPDATED, S365, TEMP) VALUES (" . $NM_seq_auto . "'$this->bcode', '$this->status', '$this->name', $this->number, '$this->prefix', '$this->address1', '$this->address2', '$this->city', '$this->state', '$this->country', '$this->zip_code', '$this->salesman', '$this->email', '$this->cat1', '$this->cat2', '$this->cat3', '$this->cat4', '$this->cat5', '$this->cat6', '$this->cat7', '$this->terms', '$this->phone', '$this->added', '$this->contact', EXTEND('$this->tdate', YEAR TO DAY), '$this->memo', '$this->att', '$this->cphone1', '$this->cphone2', '$this->contact2', '$this->cemail1', '$this->cemail2', '$this->fax', '$this->cfax1', '$this->cfax2', $this->mtd, $this->ytd, $this->qtd, $this->jan, $this->feb, $this->mar, $this->apr, $this->may, $this->jun, $this->jul, $this->aug, $this->sep, $this->oct, $this->nov, $this->dec, $this->lyear, $this->llyear, $this->q1, $this->q2, $this->q3, $this->q4, EXTEND('$this->updated', YEAR TO DAY), $this->s365, '$this->temp')"; 
              }
              else
              {
                  $comando = "INSERT INTO " . $this->Ini->nm_tabela . " (" . $NM_cmp_auto . "BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, TDATE, MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC`, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, UPDATED, S365, TEMP) VALUES (" . $NM_seq_auto . "'$this->bcode', '$this->status', '$this->name', $this->number, '$this->prefix', '$this->address1', '$this->address2', '$this->city', '$this->state', '$this->country', '$this->zip_code', '$this->salesman', '$this->email', '$this->cat1', '$this->cat2', '$this->cat3', '$this->cat4', '$this->cat5', '$this->cat6', '$this->cat7', '$this->terms', '$this->phone', '$this->added', '$this->contact', '$this->tdate', '$this->memo', '$this->att', '$this->cphone1', '$this->cphone2', '$this->contact2', '$this->cemail1', '$this->cemail2', '$this->fax', '$this->cfax1', '$this->cfax2', $this->mtd, $this->ytd, $this->qtd, $this->jan, $this->feb, $this->mar, $this->apr, $this->may, $this->jun, $this->jul, $this->aug, $this->sep, $this->oct, $this->nov, $this->dec, $this->lyear, $this->llyear, $this->q1, $this->q2, $this->q3, $this->q4, '$this->updated', $this->s365, '$this->temp')"; 
              }
              $comando = str_replace("'null'", "null", $comando) ; 
              $comando = str_replace("#null#", "null", $comando) ; 
              if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
              {
                $comando = str_replace("EXTEND('', YEAR TO FRACTION)", "null", $comando) ; 
                $comando = str_replace("EXTEND(null, YEAR TO FRACTION)", "null", $comando) ; 
                $comando = str_replace("EXTEND('', YEAR TO DAY)", "null", $comando) ; 
                $comando = str_replace("EXTEND(null, YEAR TO DAY)", "null", $comando) ; 
              }  
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = $comando; 
              $rs = $this->Db->Execute($comando); 
              if ($rs === false)  
              { 
                  if (FALSE === strpos(strtoupper($this->Db->ErrorMsg()), "MAIL SENT") && FALSE === strpos(strtoupper($this->Db->ErrorMsg()), "WARNING"))
                  {
                      $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_inst'], $this->Db->ErrorMsg(), true); 
                      if (isset($_SESSION['scriptcase']['erro_handler']) && $_SESSION['scriptcase']['erro_handler']) 
                      { 
                          $this->sc_erro_insert = $this->Db->ErrorMsg();  
                          $this->nmgp_opcao     = 'refresh_insert';
                          $this->NM_rollback_db(); 
                          if ($this->NM_ajax_flag)
                          {
                              custbill_form_pack_ajax_response();
                              exit; 
                          }
                      }  
                  }  
              }  
              if ('refresh_insert' != $this->nmgp_opcao)
              {
              }

              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['db_changed'] = true;

              if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total']))
              {
                  unset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total']);
              }

              $this->sc_evento = "insert"; 
              $this->sc_insert_on = true; 
              if ('refresh_insert' != $this->nmgp_opcao && (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['sc_redir_insert']) || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['sc_redir_insert'] != "S"))
              {
              $this->nmgp_opcao   = "igual"; 
              $this->nmgp_opc_ant = "igual"; 
              $this->nmgp_botoes['FixDB'] = "on";
              }
              $this->nm_flag_iframe = true;
          } 
          if ($this->lig_edit_lookup)
          {
              $this->lig_edit_lookup_call = true;
          }
      } 
      if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['decimal_db'] == ",") 
      {
          $this->nm_tira_aspas_decimal();
      }
      if ($this->nmgp_opcao == "excluir") 
      { 
          $this->bcode = substr($this->Db->qstr($this->bcode), 1, -1); 

          $bDelecaoOk = true;
          $sMsgErro   = '';
          if ($bDelecaoOk)
          {
              $sDetailWhere = "BCODE = '" . $this->bcode . "'";
              $this->custship_form->ini_controle();
              if ($this->custship_form->temRegistros($sDetailWhere))
              {
                  $bDelecaoOk = false;
                  $sMsgErro   = $this->Ini->Nm_lang['lang_errm_fkvi'];
              }
          }

          if ($bDelecaoOk)
          {

          if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode'"; 
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode'"; 
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode'"; 
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode'"; 
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          else  
          {
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode'"; 
              $rs1 = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
          }  
          if ($rs1 === false)  
          { 
              $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dbas'], $this->Db->ErrorMsg()); 
              exit; 
          }  
          if ($rs1 === false)  
          { 
              $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dbas'], $this->Db->ErrorMsg()); 
              exit; 
          }  
          $tmp_result = (int) $rs1->fields[0]; 
          if ($tmp_result != 1) 
          { 
              $this->Erro->mensagem (__FILE__, __LINE__, "critica", $this->Ini->Nm_lang['lang_errm_dele_nfnd']); 
              $this->nmgp_opcao = "nada"; 
              $this->sc_evento = 'delete';
          } 
          else 
          { 
              $rs1->Close(); 
              if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
              {
                  $_SESSION['scriptcase']['sc_sql_ult_comando'] = "DELETE FROM " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "; 
                  $rs = $this->Db->Execute("DELETE FROM " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
              }  
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
              {
                  $_SESSION['scriptcase']['sc_sql_ult_comando'] = "DELETE FROM " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "; 
                  $rs = $this->Db->Execute("DELETE FROM " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
              }  
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
              {
                  $_SESSION['scriptcase']['sc_sql_ult_comando'] = "DELETE FROM " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "; 
                  $rs = $this->Db->Execute("DELETE FROM " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
              }  
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
              {
                  $_SESSION['scriptcase']['sc_sql_ult_comando'] = "DELETE FROM " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "; 
                  $rs = $this->Db->Execute("DELETE FROM " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
              }  
              else  
              {
                  $_SESSION['scriptcase']['sc_sql_ult_comando'] = "DELETE FROM " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "; 
                  $rs = $this->Db->Execute("DELETE FROM " . $this->Ini->nm_tabela . " where BCODE = '$this->bcode' "); 
              }  
              if ($rs === false) 
              { 
                  $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dele'], $this->Db->ErrorMsg(), true); 
                  if (isset($_SESSION['scriptcase']['erro_handler']) && $_SESSION['scriptcase']['erro_handler']) 
                  { 
                      $this->sc_erro_delete = $this->Db->ErrorMsg();  
                      $this->NM_rollback_db(); 
                      if ($this->NM_ajax_flag)
                      {
                          custbill_form_pack_ajax_response();
                          exit; 
                      }
                  } 
              } 
              $this->sc_evento = "delete"; 
              $this->nmgp_opcao = "avanca"; 
              $this->nm_flag_iframe = true;
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start']--; 
              if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] < 0)
              {
                  $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] = 0; 
              }

              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['db_changed'] = true;

              if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total']))
              {
                  unset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total']);
              }

              if ($this->lig_edit_lookup)
              {
                  $this->lig_edit_lookup_call = true;
              }
          }

          }
          else
          {
              $this->sc_evento = "delete"; 
              $this->nmgp_opcao = "igual"; 
              $this->Erro->mensagem(__FILE__, __LINE__, "critica", $sMsgErro); 
          }

      }  
      if (!empty($this->sc_force_zero))
      {
          foreach ($this->sc_force_zero as $i_force_zero => $sc_force_zero_field)
          {
              eval('if ($this->' . $sc_force_zero_field . ' == 0) {$this->' . $sc_force_zero_field . ' = "";}');
          }
      }
      $this->sc_force_zero = array();
      if (!empty($NM_val_null))
      {
          foreach ($NM_val_null as $i_val_null => $sc_val_null_field)
          {
              eval('$this->' . $sc_val_null_field . ' = "";');
          }
      }
      if ($salva_opcao == "incluir" && $GLOBALS["erro_incl"] != 1) 
      { 
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['parms'] = "bcode?#?$this->bcode?@?"; 
      }
      $this->NM_commit_db(); 
      if ($this->sc_evento != "insert" && $this->sc_evento != "update" && $this->sc_evento != "delete")
      { 
          $this->bcode = substr($this->Db->qstr($this->bcode), 1, -1); 
      } 
      if (isset($this->NM_where_filter))
      {
          $this->NM_where_filter = str_replace("@percent@", "%", $this->NM_where_filter);
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_filter'] = trim($this->NM_where_filter);
          if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total']))
          {
              unset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total']);
          }
      }
      $sc_where_filter = '';
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_filter_form']) && '' != $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_filter_form'])
      {
          $sc_where_filter = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_filter_form'];
      }
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_filter']) && '' != $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_filter'])
      {
          if (empty($sc_where_filter))
          {
              $sc_where_filter = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_filter'];
          }
          else
          {
              $sc_where_filter .= " and (" . $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_filter'] . ")";
          }
      }
//------------ 
      if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['run_iframe'] == "F" || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['run_iframe'] == "R")
      {
          if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['iframe_evento'] == "insert") 
          { 
               $this->nmgp_opcao = "novo"; 
               $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['select'] = "";
          } 
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['iframe_evento'] = $this->sc_evento; 
      } 
      if (!isset($this->nmgp_opcao) || empty($this->nmgp_opcao)) 
      { 
          if (empty($this->bcode)) 
          { 
              $this->nmgp_opcao = "inicio"; 
          } 
          else 
          { 
              $this->nmgp_opcao = "igual"; 
          } 
      } 
      if (isset($_POST['master_nav']) && 'on' == $_POST['master_nav']) 
      { 
          $this->nmgp_opcao = "inicio";
      } 
      if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_ibase))
      { 
          $GLOBALS["NM_ERRO_IBASE"] = 1;  
      } 
      if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['run_iframe'] == "F" && $this->sc_evento == "insert")
      {
          $this->nmgp_opcao = "final";
      }
      $sc_where = trim("");
      if (substr(strtolower($sc_where), 0, 5) == "where")
      {
          $sc_where  = substr($sc_where , 5);
      }
      if (!empty($sc_where))
      {
          $sc_where = " where " . $sc_where . " ";
      }
      if ('' != $sc_where_filter)
      {
          $sc_where = ('' != $sc_where) ? $sc_where . ' and (' . $sc_where_filter . ')' : ' where ' . $sc_where_filter;
      }
      if (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total']))
      { 
          $nmgp_select = "SELECT count(*) from " . $this->Ini->nm_tabela . $sc_where; 
          $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nmgp_select; 
          $rt = $this->Db->Execute($nmgp_select) ; 
          if ($rt === false && !$rt->EOF && $GLOBALS["NM_ERRO_IBASE"] != 1) 
          { 
              $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg()); 
              exit ; 
          }  
          $qt_geral_reg_custbill_form = isset($rt->fields[0]) ? $rt->fields[0] - 1 : 0; 
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total'] = $qt_geral_reg_custbill_form;
          $rt->Close(); 
          if ($this->nmgp_opcao == "igual" && isset($this->NM_btn_navega) && 'S' == $this->NM_btn_navega && !empty($this->bcode))
          {
              if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
              {
                  $Key_Where = "BCODE < '$this->bcode' "; 
              }  
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
              {
                  $Key_Where = "BCODE < '$this->bcode' "; 
              }
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
              {
                  $Key_Where = "BCODE < '$this->bcode' "; 
              }
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
              {
                  $Key_Where = "BCODE < '$this->bcode' "; 
              }
              else  
              {
                  $Key_Where = "BCODE < '$this->bcode' "; 
              }
              $Where_Start = (empty($sc_where)) ? " where " . $Key_Where :  $sc_where . " and (" . $Key_Where . ")";
              $nmgp_select = "SELECT count(*) from " . $this->Ini->nm_tabela . $Where_Start; 
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nmgp_select; 
              $rt = $this->Db->Execute($nmgp_select) ; 
              if ($rt === false && !$rt->EOF && $GLOBALS["NM_ERRO_IBASE"] != 1) 
              { 
                  $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg()); 
                  exit ; 
              }  
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] = $rt->fields[0];
              $rt->Close(); 
          }
      } 
      else 
      { 
          $qt_geral_reg_custbill_form = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total'];
      } 
      if ($this->nmgp_opcao == "inicio") 
      { 
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] = 0; 
      } 
      if ($this->nmgp_opcao == "avanca")  
      { 
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start']++; 
          if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] > $qt_geral_reg_custbill_form)
          {
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] = $qt_geral_reg_custbill_form; 
          }
      } 
      if ($this->nmgp_opcao == "retorna") 
      { 
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start']--; 
          if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] < 0)
          {
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] = 0; 
          }
      } 
      if ($this->nmgp_opcao == "final") 
      { 
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] = $qt_geral_reg_custbill_form; 
      } 
      if ($this->nmgp_opcao == "navpage" && ($this->nmgp_ordem - 1) <= $qt_geral_reg_custbill_form) 
      { 
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] = $this->nmgp_ordem - 1; 
      } 
      if (!isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start']) || empty($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start']))
      {
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] = 0;
      }
      $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_qtd'] = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] + 1;
      $this->NM_ajax_info['navSummary']['reg_ini'] = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] + 1; 
      $this->NM_ajax_info['navSummary']['reg_qtd'] = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_qtd']; 
      $this->NM_ajax_info['navSummary']['reg_tot'] = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total'] + 1; 
      $this->NM_gera_nav_page(); 
      $this->NM_ajax_info['navPage'] = $this->SC_nav_page; 
      $GLOBALS["NM_ERRO_IBASE"] = 0;  
//---------- 
      if ($this->nmgp_opcao != "novo" && $this->nmgp_opcao != "nada" && $this->nmgp_opcao != "refresh_insert") 
      { 
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['parms'] = ""; 
          if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_ibase))
          { 
              $GLOBALS["NM_ERRO_IBASE"] = 1;  
          } 
          if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_sybase))
          { 
              $nmgp_select = "SELECT BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, str_replace (convert(char(10),TDATE,102), '.', '-') + ' ' + convert(char(8),TDATE,20), MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC`, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, str_replace (convert(char(10),UPDATED,102), '.', '-') + ' ' + convert(char(8),UPDATED,20), S365, TEMP from " . $this->Ini->nm_tabela ; 
          } 
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
          { 
              $nmgp_select = "SELECT BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, convert(char(23),TDATE,121), MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC`, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, convert(char(23),UPDATED,121), S365, TEMP from " . $this->Ini->nm_tabela ; 
          } 
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
          { 
              $nmgp_select = "SELECT BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, TDATE, MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC`, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, UPDATED, S365, TEMP from " . $this->Ini->nm_tabela ; 
          } 
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
          { 
              $nmgp_select = "SELECT BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, EXTEND(TDATE, YEAR TO DAY), MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC`, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, EXTEND(UPDATED, YEAR TO DAY), S365, TEMP from " . $this->Ini->nm_tabela ; 
          } 
          else 
          { 
              $nmgp_select = "SELECT BCODE, STATUS, NAME, NUMBER, PREFIX, ADDRESS1, ADDRESS2, CITY, STATE, COUNTRY, ZIP_CODE, SALESMAN, EMAIL, CAT1, CAT2, CAT3, CAT4, CAT5, CAT6, CAT7, TERMS, PHONE, ADDED, CONTACT, TDATE, MEMO, ATT, CPHONE1, CPHONE2, CONTACT2, CEMAIL1, CEMAIL2, FAX, CFAX1, CFAX2, MTD, YTD, QTD, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, `DEC`, LYEAR, LLYEAR, Q1, Q2, Q3, Q4, UPDATED, S365, TEMP from " . $this->Ini->nm_tabela ; 
          } 
          $aWhere = array();
          $aWhere[] = $sc_where_filter;
          if ($this->nmgp_opcao == "igual" || (($_SESSION['sc_session'][$this->Ini->sc_page]['form_adm_clientes']['run_iframe'] == "F" || $_SESSION['sc_session'][$this->Ini->sc_page]['form_adm_clientes']['run_iframe'] == "R") && ($this->sc_evento == "insert" || $this->sc_evento == "update")) )
          { 
              if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
              {
                  $aWhere[] = "BCODE = '$this->bcode'"; 
              }  
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
              {
                  $aWhere[] = "BCODE = '$this->bcode'"; 
              }  
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
              {
                  $aWhere[] = "BCODE = '$this->bcode'"; 
              }  
              elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
              {
                  $aWhere[] = "BCODE = '$this->bcode'"; 
              }  
              else  
              {
                  $aWhere[] = "BCODE = '$this->bcode'"; 
              }  
              if (!empty($sc_where_filter))  
              {
                  $teste_select = $nmgp_select . $this->returnWhere($aWhere);
                  $_SESSION['scriptcase']['sc_sql_ult_comando'] = $teste_select; 
                  $rs = $this->Db->Execute($teste_select); 
                  if ($rs->EOF)
                  {
                     $aWhere = array($sc_where_filter);
                  }  
                  $rs->Close(); 
              }  
          } 
          $nmgp_select .= $this->returnWhere($aWhere) . ' ';
          $sc_order_by = "";
          $sc_order_by = "BCODE";
          $sc_order_by = str_replace("order by ", "", $sc_order_by);
          $sc_order_by = str_replace("ORDER BY ", "", trim($sc_order_by));
          if (!empty($sc_order_by))
          {
              $nmgp_select .= " order by $sc_order_by "; 
          }
          if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['run_iframe'] == "F" || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['run_iframe'] == "R")
          {
              if ($this->sc_evento == "update")
              {
                  $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['select'] = $nmgp_select;
                  $this->nm_gera_html();
              } 
              elseif (!empty($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['select']))
              { 
                  $nmgp_select = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['select'];
                  $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['select'] = ""; 
              } 
          } 
          if ($this->nmgp_opcao == "igual") 
          { 
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nmgp_select; 
              $rs = $this->Db->Execute($nmgp_select) ; 
          } 
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mysql) || in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_postgres) || in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle) || in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_ibase) || in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_db2))
          { 
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "SelectLimit($nmgp_select, 1, " . $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] . ")" ; 
              $rs = $this->Db->SelectLimit($nmgp_select, 1, $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start']) ; 
          } 
          elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
          { 
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = "SelectLimit($nmgp_select, 1, " . $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] . ")" ; 
              $rs = $this->Db->SelectLimit($nmgp_select, 1, $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start']) ; 
          } 
          else  
          { 
              $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nmgp_select; 
              $rs = $this->Db->Execute($nmgp_select) ; 
              if (!$rs === false && !$rs->EOF) 
              { 
                  $rs->Move($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start']) ;  
              } 
          } 
          if ($rs === false && !$rs->EOF && $GLOBALS["NM_ERRO_IBASE"] != 1) 
          { 
              $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg()); 
              exit ; 
          }  
          if ($rs === false && $GLOBALS["NM_ERRO_IBASE"] == 1) 
          { 
              $GLOBALS["NM_ERRO_IBASE"] = 0; 
              $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_nfnd_extr'], $this->Db->ErrorMsg()); 
              exit ; 
          }  
          if ($rs->EOF) 
          { 
              if ($this->nmgp_botoes['insert'] != "on")
              {
                  $this->nmgp_form_empty        = true;
                  $this->nmgp_botoes['first']   = "off";
                  $this->nmgp_botoes['back']    = "off";
                  $this->nmgp_botoes['forward'] = "off";
                  $this->nmgp_botoes['last']    = "off";
              }
              $this->nmgp_opcao = "novo"; 
              $this->nm_flag_saida_novo = "S"; 
              $rs->Close(); 
              $this->nmgp_botoes['FixDB'] = "off";
              if ($this->aba_iframe)
              {
                  $this->nmgp_botoes['exit'] = 'off';
              }
          } 
          if ($rs === false && $GLOBALS["NM_ERRO_IBASE"] == 1) 
          { 
              $GLOBALS["NM_ERRO_IBASE"] = 0; 
              $this->Erro->mensagem (__FILE__, __LINE__, "critica", $this->Ini->Nm_lang['lang_errm_nfnd_extr']); 
              $this->nmgp_opcao = "novo"; 
          }  
          if ($this->nmgp_opcao != "novo") 
          { 
              $this->bcode = $rs->fields[0] ; 
              $this->nmgp_dados_select['bcode'] = $this->bcode;
              $this->status = $rs->fields[1] ; 
              $this->nmgp_dados_select['status'] = $this->status;
              $this->name = $rs->fields[2] ; 
              $this->nmgp_dados_select['name'] = $this->name;
              $this->number = $rs->fields[3] ; 
              $this->nmgp_dados_select['number'] = $this->number;
              $this->prefix = $rs->fields[4] ; 
              $this->nmgp_dados_select['prefix'] = $this->prefix;
              $this->address1 = $rs->fields[5] ; 
              $this->nmgp_dados_select['address1'] = $this->address1;
              $this->address2 = $rs->fields[6] ; 
              $this->nmgp_dados_select['address2'] = $this->address2;
              $this->city = $rs->fields[7] ; 
              $this->nmgp_dados_select['city'] = $this->city;
              $this->state = $rs->fields[8] ; 
              $this->nmgp_dados_select['state'] = $this->state;
              $this->country = $rs->fields[9] ; 
              $this->nmgp_dados_select['country'] = $this->country;
              $this->zip_code = $rs->fields[10] ; 
              $this->nmgp_dados_select['zip_code'] = $this->zip_code;
              $this->salesman = $rs->fields[11] ; 
              $this->nmgp_dados_select['salesman'] = $this->salesman;
              $this->email = $rs->fields[12] ; 
              $this->nmgp_dados_select['email'] = $this->email;
              $this->cat1 = $rs->fields[13] ; 
              $this->nmgp_dados_select['cat1'] = $this->cat1;
              $this->cat2 = $rs->fields[14] ; 
              $this->nmgp_dados_select['cat2'] = $this->cat2;
              $this->cat3 = $rs->fields[15] ; 
              $this->nmgp_dados_select['cat3'] = $this->cat3;
              $this->cat4 = $rs->fields[16] ; 
              $this->nmgp_dados_select['cat4'] = $this->cat4;
              $this->cat5 = $rs->fields[17] ; 
              $this->nmgp_dados_select['cat5'] = $this->cat5;
              $this->cat6 = $rs->fields[18] ; 
              $this->nmgp_dados_select['cat6'] = $this->cat6;
              $this->cat7 = $rs->fields[19] ; 
              $this->nmgp_dados_select['cat7'] = $this->cat7;
              $this->terms = $rs->fields[20] ; 
              $this->nmgp_dados_select['terms'] = $this->terms;
              $this->phone = $rs->fields[21] ; 
              $this->nmgp_dados_select['phone'] = $this->phone;
              $this->added = $rs->fields[22] ; 
              $this->nmgp_dados_select['added'] = $this->added;
              $this->contact = $rs->fields[23] ; 
              $this->nmgp_dados_select['contact'] = $this->contact;
              $this->tdate = $rs->fields[24] ; 
              $this->nmgp_dados_select['tdate'] = $this->tdate;
              $this->memo = $rs->fields[25] ; 
              $this->nmgp_dados_select['memo'] = $this->memo;
              $this->att = $rs->fields[26] ; 
              $this->nmgp_dados_select['att'] = $this->att;
              $this->cphone1 = $rs->fields[27] ; 
              $this->nmgp_dados_select['cphone1'] = $this->cphone1;
              $this->cphone2 = $rs->fields[28] ; 
              $this->nmgp_dados_select['cphone2'] = $this->cphone2;
              $this->contact2 = $rs->fields[29] ; 
              $this->nmgp_dados_select['contact2'] = $this->contact2;
              $this->cemail1 = $rs->fields[30] ; 
              $this->nmgp_dados_select['cemail1'] = $this->cemail1;
              $this->cemail2 = $rs->fields[31] ; 
              $this->nmgp_dados_select['cemail2'] = $this->cemail2;
              $this->fax = $rs->fields[32] ; 
              $this->nmgp_dados_select['fax'] = $this->fax;
              $this->cfax1 = $rs->fields[33] ; 
              $this->nmgp_dados_select['cfax1'] = $this->cfax1;
              $this->cfax2 = $rs->fields[34] ; 
              $this->nmgp_dados_select['cfax2'] = $this->cfax2;
              $this->mtd = trim($rs->fields[35]) ; 
              $this->nmgp_dados_select['mtd'] = $this->mtd;
              $this->ytd = trim($rs->fields[36]) ; 
              $this->nmgp_dados_select['ytd'] = $this->ytd;
              $this->qtd = trim($rs->fields[37]) ; 
              $this->nmgp_dados_select['qtd'] = $this->qtd;
              $this->jan = trim($rs->fields[38]) ; 
              $this->nmgp_dados_select['jan'] = $this->jan;
              $this->feb = trim($rs->fields[39]) ; 
              $this->nmgp_dados_select['feb'] = $this->feb;
              $this->mar = trim($rs->fields[40]) ; 
              $this->nmgp_dados_select['mar'] = $this->mar;
              $this->apr = trim($rs->fields[41]) ; 
              $this->nmgp_dados_select['apr'] = $this->apr;
              $this->may = trim($rs->fields[42]) ; 
              $this->nmgp_dados_select['may'] = $this->may;
              $this->jun = trim($rs->fields[43]) ; 
              $this->nmgp_dados_select['jun'] = $this->jun;
              $this->jul = trim($rs->fields[44]) ; 
              $this->nmgp_dados_select['jul'] = $this->jul;
              $this->aug = trim($rs->fields[45]) ; 
              $this->nmgp_dados_select['aug'] = $this->aug;
              $this->sep = trim($rs->fields[46]) ; 
              $this->nmgp_dados_select['sep'] = $this->sep;
              $this->oct = trim($rs->fields[47]) ; 
              $this->nmgp_dados_select['oct'] = $this->oct;
              $this->nov = trim($rs->fields[48]) ; 
              $this->nmgp_dados_select['nov'] = $this->nov;
              $this->dec = trim($rs->fields[49]) ; 
              $this->nmgp_dados_select['dec'] = $this->dec;
              $this->lyear = trim($rs->fields[50]) ; 
              $this->nmgp_dados_select['lyear'] = $this->lyear;
              $this->llyear = trim($rs->fields[51]) ; 
              $this->nmgp_dados_select['llyear'] = $this->llyear;
              $this->q1 = trim($rs->fields[52]) ; 
              $this->nmgp_dados_select['q1'] = $this->q1;
              $this->q2 = trim($rs->fields[53]) ; 
              $this->nmgp_dados_select['q2'] = $this->q2;
              $this->q3 = trim($rs->fields[54]) ; 
              $this->nmgp_dados_select['q3'] = $this->q3;
              $this->q4 = trim($rs->fields[55]) ; 
              $this->nmgp_dados_select['q4'] = $this->q4;
              $this->updated = $rs->fields[56] ; 
              $this->nmgp_dados_select['updated'] = $this->updated;
              $this->s365 = trim($rs->fields[57]) ; 
              $this->nmgp_dados_select['s365'] = $this->s365;
              $this->temp = $rs->fields[58] ; 
              $this->nmgp_dados_select['temp'] = $this->temp;
              $this->custship = $rs->fields[59] ; 
              $this->nmgp_dados_select['custship'] = $this->custship;
              $this->billing = $rs->fields[60] ; 
              $this->nmgp_dados_select['billing'] = $this->billing;
              $this->orders = $rs->fields[61] ; 
              $this->nmgp_dados_select['orders'] = $this->orders;
              $this->quotes = $rs->fields[62] ; 
              $this->nmgp_dados_select['quotes'] = $this->quotes;
          $GLOBALS["NM_ERRO_IBASE"] = 0; 
              $this->nm_troca_decimal(",", ".");
              $this->number = (string)$this->number; 
              $this->mtd = (strpos(strtolower($this->mtd), "e")) ? (float)$this->mtd : $this->mtd; 
              $this->mtd = (string)$this->mtd; 
              $this->ytd = (strpos(strtolower($this->ytd), "e")) ? (float)$this->ytd : $this->ytd; 
              $this->ytd = (string)$this->ytd; 
              $this->qtd = (strpos(strtolower($this->qtd), "e")) ? (float)$this->qtd : $this->qtd; 
              $this->qtd = (string)$this->qtd; 
              $this->jan = (strpos(strtolower($this->jan), "e")) ? (float)$this->jan : $this->jan; 
              $this->jan = (string)$this->jan; 
              $this->feb = (strpos(strtolower($this->feb), "e")) ? (float)$this->feb : $this->feb; 
              $this->feb = (string)$this->feb; 
              $this->mar = (strpos(strtolower($this->mar), "e")) ? (float)$this->mar : $this->mar; 
              $this->mar = (string)$this->mar; 
              $this->apr = (strpos(strtolower($this->apr), "e")) ? (float)$this->apr : $this->apr; 
              $this->apr = (string)$this->apr; 
              $this->may = (strpos(strtolower($this->may), "e")) ? (float)$this->may : $this->may; 
              $this->may = (string)$this->may; 
              $this->jun = (strpos(strtolower($this->jun), "e")) ? (float)$this->jun : $this->jun; 
              $this->jun = (string)$this->jun; 
              $this->jul = (strpos(strtolower($this->jul), "e")) ? (float)$this->jul : $this->jul; 
              $this->jul = (string)$this->jul; 
              $this->aug = (strpos(strtolower($this->aug), "e")) ? (float)$this->aug : $this->aug; 
              $this->aug = (string)$this->aug; 
              $this->sep = (strpos(strtolower($this->sep), "e")) ? (float)$this->sep : $this->sep; 
              $this->sep = (string)$this->sep; 
              $this->oct = (strpos(strtolower($this->oct), "e")) ? (float)$this->oct : $this->oct; 
              $this->oct = (string)$this->oct; 
              $this->nov = (strpos(strtolower($this->nov), "e")) ? (float)$this->nov : $this->nov; 
              $this->nov = (string)$this->nov; 
              $this->dec = (strpos(strtolower($this->dec), "e")) ? (float)$this->dec : $this->dec; 
              $this->dec = (string)$this->dec; 
              $this->lyear = (strpos(strtolower($this->lyear), "e")) ? (float)$this->lyear : $this->lyear; 
              $this->lyear = (string)$this->lyear; 
              $this->llyear = (strpos(strtolower($this->llyear), "e")) ? (float)$this->llyear : $this->llyear; 
              $this->llyear = (string)$this->llyear; 
              $this->q1 = (strpos(strtolower($this->q1), "e")) ? (float)$this->q1 : $this->q1; 
              $this->q1 = (string)$this->q1; 
              $this->q2 = (strpos(strtolower($this->q2), "e")) ? (float)$this->q2 : $this->q2; 
              $this->q2 = (string)$this->q2; 
              $this->q3 = (strpos(strtolower($this->q3), "e")) ? (float)$this->q3 : $this->q3; 
              $this->q3 = (string)$this->q3; 
              $this->q4 = (strpos(strtolower($this->q4), "e")) ? (float)$this->q4 : $this->q4; 
              $this->q4 = (string)$this->q4; 
              $this->s365 = (strpos(strtolower($this->s365), "e")) ? (float)$this->s365 : $this->s365; 
              $this->s365 = (string)$this->s365; 
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['parms'] = "bcode?#?$this->bcode?@?";
          } 
          $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['dados_select'] = $this->nmgp_dados_select;
          if (!$this->NM_ajax_flag || 'backup_line' != $this->NM_ajax_opcao)
          {
              $this->Nav_permite_ret = 0 != $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'];
              $this->Nav_permite_ava = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] < $qt_geral_reg_custbill_form;
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opcao']   = '';
          }
      } 
      if ($this->nmgp_opcao == "novo" || $this->nmgp_opcao == "refresh_insert") 
      { 
          $this->sc_evento_old = $this->sc_evento;
          $this->sc_evento = "novo";
          if ('refresh_insert' == $this->nmgp_opcao)
          {
              $this->nmgp_opcao = 'novo';
          }
          else
          {
              $this->nm_formatar_campos();
              $this->bcode = "" ;  
              $this->status = "" ;  
              $this->name = "" ;  
              $this->number = "" ;  
              $this->prefix = "" ;  
              $this->address1 = "" ;  
              $this->address2 = "" ;  
              $this->city = "" ;  
              $this->state = "" ;  
              $this->country = "" ;  
              $this->zip_code = "" ;  
              $this->salesman = "" ;  
              $this->email = "" ;  
              $this->cat1 = "" ;  
              $this->cat2 = "" ;  
              $this->cat3 = "" ;  
              $this->cat4 = "" ;  
              $this->cat5 = "" ;  
              $this->cat6 = "" ;  
              $this->cat7 = "" ;  
              $this->terms = "" ;  
              $this->phone = "" ;  
              $this->added = "" ;  
              $this->contact = "" ;  
              $this->tdate = "" ;  
              $this->tdate_hora = "" ;  
              $this->memo = "" ;  
              $this->att = "" ;  
              $this->cphone1 = "" ;  
              $this->cphone2 = "" ;  
              $this->contact2 = "" ;  
              $this->cemail1 = "" ;  
              $this->cemail2 = "" ;  
              $this->fax = "" ;  
              $this->cfax1 = "" ;  
              $this->cfax2 = "" ;  
              $this->mtd = "" ;  
              $this->ytd = "" ;  
              $this->qtd = "" ;  
              $this->jan = "" ;  
              $this->feb = "" ;  
              $this->mar = "" ;  
              $this->apr = "" ;  
              $this->may = "" ;  
              $this->jun = "" ;  
              $this->jul = "" ;  
              $this->aug = "" ;  
              $this->sep = "" ;  
              $this->oct = "" ;  
              $this->nov = "" ;  
              $this->dec = "" ;  
              $this->lyear = "" ;  
              $this->llyear = "" ;  
              $this->q1 = "" ;  
              $this->q2 = "" ;  
              $this->q3 = "" ;  
              $this->q4 = "" ;  
              $this->updated = "" ;  
              $this->updated_hora = "" ;  
              $this->s365 = "" ;  
              $this->temp = "" ;  
              $this->custship = "" ;  
              $this->billing = "" ;  
              $this->orders = "" ;  
              $this->quotes = "" ;  
              $this->formatado = false;
          }
          if (($this->Embutida_form || $this->Embutida_multi) && isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['foreign_key']) && !empty($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['foreign_key']))
          {
              foreach ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['foreign_key'] as $sFKName => $sFKValue)
              {
                   if (isset($this->sc_conv_var[$sFKName]))
                   {
                       $sFKName = $this->sc_conv_var[$sFKName];
                   }
                  eval("\$this->" . $sFKName . " = \"" . $sFKValue . "\";");
              }
          }
      }  
//
//
//-- 
      if ($this->nmgp_opcao != "novo") 
      {
      }
      $this->nm_proc_onload();
      $_SESSION['sc_session'][$this->Ini->sc_page]['custship_form']['embutida_parms'] = "var_bcode?#?" . $this->nmgp_dados_form['bcode'] . "?@?NM_btn_insert?#?S?@?NM_btn_update?#?S?@?NM_btn_delete?#?S?@?NM_btn_navega?#?N?@?";
      $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_orders_grid']['embutida_parms'] = "var_bcode?#?" . $this->nmgp_dados_form['bcode'] . "?@?";
      $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_invoice_grid']['embutida_parms'] = "var_bcode?#?" . $this->nmgp_dados_form['bcode'] . "?@?";
      $_SESSION['sc_session'][$this->Ini->sc_page]['prices_grid']['embutida_parms'] = "var_bcode?#?" . $this->nmgp_dados_form['bcode'] . "?@?";
  }
// 
//-- 
   function nm_db_retorna($str_where_param = '') 
   {  
     $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
     $str_where_filter = ('' != $str_where_param) ? ' and ' . $str_where_param : '';
     if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select max(BCODE) from " . $this->Ini->nm_tabela . " where BCODE < '$this->bcode'" . $str_where_filter; 
         $rs = $this->Db->Execute("select max(BCODE) from " . $this->Ini->nm_tabela . " where BCODE < '$this->bcode'" . $str_where_filter); 
     }  
     elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select max(BCODE) from " . $this->Ini->nm_tabela . " where BCODE < '$this->bcode'" . $str_where_filter; 
         $rs = $this->Db->Execute("select max(BCODE) from " . $this->Ini->nm_tabela . " where BCODE < '$this->bcode'" . $str_where_filter); 
     }  
     elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select max(BCODE) from " . $this->Ini->nm_tabela . " where BCODE < '$this->bcode'" . $str_where_filter; 
         $rs = $this->Db->Execute("select max(BCODE) from " . $this->Ini->nm_tabela . " where BCODE < '$this->bcode'" . $str_where_filter); 
     }  
     elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select max(BCODE) from " . $this->Ini->nm_tabela . " where BCODE < '$this->bcode'" . $str_where_filter; 
         $rs = $this->Db->Execute("select max(BCODE) from " . $this->Ini->nm_tabela . " where BCODE < '$this->bcode'" . $str_where_filter); 
     }  
     else  
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select max(BCODE) from " . $this->Ini->nm_tabela . " where BCODE < '$this->bcode'" . $str_where_filter; 
         $rs = $this->Db->Execute("select max(BCODE) from " . $this->Ini->nm_tabela . " where BCODE < '$this->bcode'" . $str_where_filter); 
     }  
     if ($rs === false && !$rs->EOF && $GLOBALS["NM_ERRO_IBASE"] != 1) 
     { 
         $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg()); 
         exit ; 
     }  
     if (isset($rs->fields[0]) && $rs->fields[0] != "") 
     { 
         $this->bcode = substr($this->Db->qstr($rs->fields[0]), 1, -1); 
         $rs->Close();  
         $this->nmgp_opcao = "igual";  
         return ;  
     } 
     else 
     { 
        $this->nmgp_opcao = "inicio";  
        $rs->Close();  
        return ; 
     } 
   } 
// 
//-- 
   function nm_db_avanca($str_where_param = '') 
   {  
     $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
     $str_where_filter = ('' != $str_where_param) ? ' and ' . $str_where_param : '';
     if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select min(BCODE) from " . $this->Ini->nm_tabela . " where BCODE > '$this->bcode'" . $str_where_filter; 
         $rs = $this->Db->Execute("select min(BCODE) from " . $this->Ini->nm_tabela . " where BCODE > '$this->bcode'" . $str_where_filter); 
     }  
     elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select min(BCODE) from " . $this->Ini->nm_tabela . " where BCODE > '$this->bcode'" . $str_where_filter; 
         $rs = $this->Db->Execute("select min(BCODE) from " . $this->Ini->nm_tabela . " where BCODE > '$this->bcode'" . $str_where_filter); 
     }  
     elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select min(BCODE) from " . $this->Ini->nm_tabela . " where BCODE > '$this->bcode'" . $str_where_filter; 
         $rs = $this->Db->Execute("select min(BCODE) from " . $this->Ini->nm_tabela . " where BCODE > '$this->bcode'" . $str_where_filter); 
     }  
     elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select min(BCODE) from " . $this->Ini->nm_tabela . " where BCODE > '$this->bcode'" . $str_where_filter; 
         $rs = $this->Db->Execute("select min(BCODE) from " . $this->Ini->nm_tabela . " where BCODE > '$this->bcode'" . $str_where_filter); 
     }  
     else  
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select min(BCODE) from " . $this->Ini->nm_tabela . " where BCODE > '$this->bcode'" . $str_where_filter; 
         $rs = $this->Db->Execute("select min(BCODE) from " . $this->Ini->nm_tabela . " where BCODE > '$this->bcode'" . $str_where_filter); 
     }  
     if ($rs === false && !$rs->EOF && $GLOBALS["NM_ERRO_IBASE"] != 1) 
     { 
         $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg()); 
         exit ; 
     }  
     if (isset($rs->fields[0]) && $rs->fields[0] != "") 
     { 
         $this->bcode = substr($this->Db->qstr($rs->fields[0]), 1, -1); 
         $rs->Close();  
         $this->nmgp_opcao = "igual";  
         return ;  
     } 
     else 
     { 
        $this->nmgp_opcao = "final";  
        $rs->Close();  
        return ; 
     } 
   } 
// 
//-- 
   function nm_db_inicio($str_where_param = '') 
   {   
     $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
     $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select count(*) from " . $this->Ini->nm_tabela; 
     $rs = $this->Db->Execute("select count(*) from " . $this->Ini->nm_tabela);
     if ($rs === false && !$rs->EOF && $GLOBALS["NM_ERRO_IBASE"] != 1) 
     { 
         $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg()); 
         exit ; 
     }  
     if ($rs->fields[0] == 0) 
     { 
         $this->nmgp_opcao = "novo"; 
         $this->nm_flag_saida_novo = "S"; 
         $rs->Close(); 
         if ($this->aba_iframe)
         {
             $this->nmgp_botoes['exit'] = 'off';
         }
         return;
     }
     $str_where_filter = ('' != $str_where_param) ? ' where ' . $str_where_param : '';
     if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select min(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter; 
         $rs = $this->Db->Execute("select min(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter); 
     }  
     elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select min(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter; 
         $rs = $this->Db->Execute("select min(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter); 
     }  
     elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select min(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter; 
         $rs = $this->Db->Execute("select min(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter); 
     }  
     elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select min(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter; 
         $rs = $this->Db->Execute("select min(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter); 
     }  
     else  
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select min(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter; 
         $rs = $this->Db->Execute("select min(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter); 
     }  
     if ($rs === false && !$rs->EOF && $GLOBALS["NM_ERRO_IBASE"] != 1) 
     { 
         $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg()); 
         exit ; 
     }  
     if (!isset($rs->fields[0]) || $rs->EOF) 
     { 
         $this->nm_flag_saida_novo = "S"; 
         $this->nmgp_opcao = "novo";  
         $rs->Close();  
         if ($this->aba_iframe)
         {
             $this->nmgp_botoes['exit'] = 'off';
         }
         return ; 
     } 
     $this->bcode = substr($this->Db->qstr($rs->fields[0]), 1, -1); 
     $rs->Close();  
     $this->nmgp_opcao = "igual";  
     return ;  
   } 
// 
//-- 
   function nm_db_final($str_where_param = '') 
   { 
     $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
     $str_where_filter = ('' != $str_where_param) ? ' where ' . $str_where_param : '';
     if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select max(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter; 
         $rs = $this->Db->Execute("select max(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter); 
     }  
     elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select max(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter; 
         $rs = $this->Db->Execute("select max(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter); 
     }  
     elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select max(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter; 
         $rs = $this->Db->Execute("select max(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter); 
     }  
     elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_informix))
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select max(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter; 
         $rs = $this->Db->Execute("select max(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter); 
     }  
     else  
     {
         $_SESSION['scriptcase']['sc_sql_ult_comando'] = "select max(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter; 
         $rs = $this->Db->Execute("select max(BCODE) from " . $this->Ini->nm_tabela . " " . $str_where_filter); 
     }  
     if ($rs === false && !$rs->EOF && $GLOBALS["NM_ERRO_IBASE"] != 1) 
     { 
         $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg()); 
         exit ; 
     }  
     if (!isset($rs->fields[0]) || $rs->EOF) 
     { 
         $this->nm_flag_saida_novo = "S"; 
         $this->nmgp_opcao = "novo";  
         $rs->Close();  
         if ($this->aba_iframe)
         {
             $this->nmgp_botoes['exit'] = 'off';
         }
         return ; 
     } 
     $this->bcode = substr($this->Db->qstr($rs->fields[0]), 1, -1); 
     $rs->Close();  
     $this->nmgp_opcao = "igual";  
     return ;  
   } 
   function NM_gera_nav_page() 
   {
       $this->SC_nav_page = "";
       $Reg_Page   = 1;
       $Max_link   = 5;
       $Mid_link   = ceil($Max_link / 2);
       $Corr_link  = (($Max_link % 2) == 0) ? 0 : 1;
       $rec_tot    = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total'] + 1;
       $rec_fim    = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['reg_start'] + 1;
       $rec_fim    = ($rec_fim > $rec_tot) ? $rec_tot : $rec_fim;
       if ($rec_tot == 0)
       {
           return;
       }
       $Qtd_Pages  = ceil($rec_tot / $Reg_Page);
       $Page_Atu   = ceil($rec_fim / $Reg_Page);
       $Link_ini   = 1;
       if ($Page_Atu > $Max_link)
       {
           $Link_ini = $Page_Atu - $Mid_link + $Corr_link;
       }
       elseif ($Page_Atu > $Mid_link)
       {
           $Link_ini = $Page_Atu - $Mid_link + $Corr_link;
       }
       if (($Qtd_Pages - $Link_ini) < $Max_link)
       {
           $Link_ini = ($Qtd_Pages - $Max_link) + 1;
       }
       if ($Link_ini < 1)
       {
           $Link_ini = 1;
       }
       for ($x = 0; $x < $Max_link && $Link_ini <= $Qtd_Pages; $x++)
       {
           $rec = (($Link_ini - 1) * $Reg_Page) + 1;
           if ($Link_ini == $Page_Atu)
           {
               $this->SC_nav_page .= '<span class="scFormToolbarNavOpen" style="vertical-align: middle;">' . $Link_ini . '</span>';
           }
           else
           {
               $this->SC_nav_page .= '<a class="scFormToolbarNav" style="vertical-align: middle;" href="javascript: nm_navpage(' . $rec . ')">' . $Link_ini . '</a>';
           }
           $Link_ini++;
           if (($x + 1) < $Max_link && $Link_ini <= $Qtd_Pages && '' != $this->Ini->Str_toolbarnav_separator && @is_file($this->Ini->root . $this->Ini->path_img_global . $this->Ini->Str_toolbarnav_separator))
           {
               $this->SC_nav_page .= '<img src="' . $this->Ini->path_img_global . $this->Ini->Str_toolbarnav_separator . '" align="absmiddle" style="vertical-align: middle;">';
           }
       }
   }
//
 function nm_gera_html()
 {
    global
           $nm_url_saida, $nmgp_url_saida, $nm_saida_global, $nm_apl_dependente, $glo_subst, $sc_check_excl, $sc_check_incl, $nmgp_num_form, $NM_run_iframe;
     if ($this->Embutida_proc)
     {
         return;
     }
     if ($this->nmgp_form_show == 'off')
     {
         exit;
     }
     $HTTP_REFERER = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : ""; 
     $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''; 
     $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['botoes'] = $this->nmgp_botoes;
     if ($this->nmgp_opcao != "recarga" && $this->nmgp_opcao != "muda_form")
     {
         $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opc_ant'] = $this->nmgp_opcao;
     }
     else
     {
         $this->nmgp_opcao = $this->nmgp_opc_ant;
     }
     if (!empty($this->Campos_Mens_erro)) 
     {
         $this->Erro->mensagem(__FILE__, __LINE__, "critica", $this->Campos_Mens_erro); 
         $this->Campos_Mens_erro = "";
     }
     if (($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['run_iframe'] == "F" || $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['run_iframe'] == "R") && $this->nm_flag_iframe && empty($this->nm_todas_criticas))
     {
          if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['run_iframe_ajax']))
          {
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['retorno_edit'] = array("edit", "");
          }
          else
          {
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['retorno_edit'] .= "&nmgp_opcao=edit";
          }
          if ($this->sc_evento == "insert" && $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['run_iframe'] == "F")
          {
              if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['run_iframe_ajax']))
              {
                  $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['retorno_edit'] = array("edit", "fim");
              }
              else
              {
                  $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['retorno_edit'] .= "&rec=fim";
              }
          }
          $this->NM_close_db(); 
          $sJsParent = '';
          if ($this->NM_ajax_flag && isset($this->NM_ajax_info['param']['buffer_output']) && $this->NM_ajax_info['param']['buffer_output'])
          {
              if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['run_iframe_ajax']))
              {
                  $this->NM_ajax_info['ajaxJavascript'][] = array("parent.ajax_navigate", $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['retorno_edit']);
              }
              else
              {
                  $sJsParent .= 'parent';
                  $this->NM_ajax_info['redir']['metodo'] = 'location';
                  $this->NM_ajax_info['redir']['action'] = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['retorno_edit'];
                  $this->NM_ajax_info['redir']['target'] = $sJsParent;
              }
              custbill_form_pack_ajax_response();
              exit;
          }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">

         <html><body>
         <script type="text/javascript">
<?php
    
    if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['run_iframe_ajax']))
    {
        $opc = ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['run_iframe'] == "F" && $this->sc_evento == "insert") ? "fim" : "";
        echo "parent.ajax_navigate('edit', '" .$opc . "');";
    }
    else
    {
        echo $sJsParent . "parent.location = '" . $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['retorno_edit'] . "';";
    }
?>
         </script>
         </body></html>
<?php
         exit;
     }
        include_once("custbill_form_form0.php");
        include_once("custbill_form_form1.php");
        include_once("custbill_form_form2.php");
        include_once("custbill_form_form3.php");
        include_once("custbill_form_form4.php");
        include_once("custbill_form_form5.php");
        include_once("custbill_form_form6.php");
        include_once("custbill_form_form7.php");
        include_once("custbill_form_form8.php");
 }
   function jqueryCalendarDtFormat($sFormat, $sSep)
   {
       $sFormat = chunk_split(str_replace('yyyy', 'yy', $sFormat), 2, $sSep);

       if ($sSep == substr($sFormat, -1))
       {
           $sFormat = substr($sFormat, 0, -1);
       }

       return $sFormat;
   } // jqueryCalendarDtFormat

   function jqueryCalendarTimeStart($sFormat)
   {
       $aDateParts = explode(';', $sFormat);

       if (2 == sizeof($aDateParts))
       {
           $sTime = $aDateParts[1];
       }
       else
       {
           $sTime = 'hh:mm:ss';
       }

       return str_replace(array('h', 'm', 'i', 's'), array('0', '0', '0', '0'), $sTime);
   } // jqueryCalendarTimeStart

   function jqueryCalendarWeekInit($sDay)
   {
       switch ($sDay) {
           case 'MO': return 1; break;
           case 'TU': return 2; break;
           case 'WE': return 3; break;
           case 'TH': return 4; break;
           case 'FR': return 5; break;
           case 'SA': return 6; break;
           default  : return 7; break;
       }
   } // jqueryCalendarWeekInit

   function jqueryIconFile($sModule)
   {
       if ('calendar' == $sModule)
       {
           if (isset($this->arr_buttons['bcalendario']) && isset($this->arr_buttons['bcalendario']['type']) && 'image' == $this->arr_buttons['bcalendario']['type'])
           {
               $sImage = $this->arr_buttons['bcalendario']['image'];
           }
       }
       elseif ('calculator' == $sModule)
       {
           if (isset($this->arr_buttons['bcalculadora']) && isset($this->arr_buttons['bcalculadora']['type']) && 'image' == $this->arr_buttons['bcalculadora']['type'])
           {
               $sImage = $this->arr_buttons['bcalculadora']['image'];
           }
       }

       return $this->Ini->path_icones . '/' . $sImage;
   } // jqueryIconFile


 function new_date_format($type, $field)
 {
     $new_date_format = '';

     if ('DT' == $type)
     {
         $date_format  = $this->field_config[$field]['date_format'];
         $date_sep     = $this->field_config[$field]['date_sep'];
         $date_display = $this->field_config[$field]['date_display'];
         $time_format  = '';
         $time_sep     = '';
         $time_display = '';
     }
     elseif ('DH' == $type)
     {
         $date_format  = false !== strpos($this->field_config[$field]['date_format'] , ';') ? substr($this->field_config[$field]['date_format'] , 0, strpos($this->field_config[$field]['date_format'] , ';')) : $this->field_config[$field]['date_format'];
         $date_sep     = $this->field_config[$field]['date_sep'];
         $date_display = false !== strpos($this->field_config[$field]['date_display'], ';') ? substr($this->field_config[$field]['date_display'], 0, strpos($this->field_config[$field]['date_display'], ';')) : $this->field_config[$field]['date_display'];
         $time_format  = false !== strpos($this->field_config[$field]['date_format'] , ';') ? substr($this->field_config[$field]['date_format'] , strpos($this->field_config[$field]['date_format'] , ';') + 1) : '';
         $time_sep     = $this->field_config[$field]['time_sep'];
         $time_display = false !== strpos($this->field_config[$field]['date_display'], ';') ? substr($this->field_config[$field]['date_display'], strpos($this->field_config[$field]['date_display'], ';') + 1) : '';
     }
     elseif ('HH' == $type)
     {
         $date_format  = '';
         $date_sep     = '';
         $date_display = '';
         $time_format  = $this->field_config[$field]['date_format'];
         $time_sep     = $this->field_config[$field]['time_sep'];
         $time_display = $this->field_config[$field]['date_display'];
     }

     if ('DT' == $type || 'DH' == $type)
     {
         $date_array = array();
         $date_index = 0;
         $date_ult   = '';
         for ($i = 0; $i < strlen($date_format); $i++)
         {
             $char = strtolower(substr($date_format, $i, 1));
             if (in_array($char, array('d', 'm', 'y', 'a')))
             {
                 if ('a' == $char)
                 {
                     $char = 'y';
                 }
                 if ($char == $date_ult)
                 {
                     $date_array[$date_index] .= $char;
                 }
                 else
                 {
                     if ('' != $date_ult)
                     {
                         $date_index++;
                     }
                     $date_array[$date_index] = $char;
                 }
             }
             $date_ult = $char;
         }

         $disp_array = array();
         $date_index = 0;
         $date_ult   = '';
         for ($i = 0; $i < strlen($date_display); $i++)
         {
             $char = strtolower(substr($date_display, $i, 1));
             if (in_array($char, array('d', 'm', 'y', 'a')))
             {
                 if ('a' == $char)
                 {
                     $char = 'y';
                 }
                 if ($char == $date_ult)
                 {
                     $disp_array[$date_index] .= $char;
                 }
                 else
                 {
                     if ('' != $date_ult)
                     {
                         $date_index++;
                     }
                     $disp_array[$date_index] = $char;
                 }
             }
             $date_ult = $char;
         }

         $date_final = array();
         foreach ($date_array as $date_part)
         {
             if (in_array($date_part, $disp_array))
             {
                 $date_final[] = $date_part;
             }
         }

         $date_format = implode($date_sep, $date_final);
     }
     if ('HH' == $type || 'DH' == $type)
     {
         $time_array = array();
         $time_index = 0;
         $time_ult   = '';
         for ($i = 0; $i < strlen($time_format); $i++)
         {
             $char = strtolower(substr($time_format, $i, 1));
             if (in_array($char, array('h', 'i', 's')))
             {
                 if ($char == $time_ult)
                 {
                     $time_array[$time_index] .= $char;
                 }
                 else
                 {
                     if ('' != $time_ult)
                     {
                         $time_index++;
                     }
                     $time_array[$time_index] = $char;
                 }
             }
             $time_ult = $char;
         }

         $disp_array = array();
         $time_index = 0;
         $time_ult   = '';
         for ($i = 0; $i < strlen($time_display); $i++)
         {
             $char = strtolower(substr($time_display, $i, 1));
             if (in_array($char, array('h', 'i', 's')))
             {
                 if ($char == $time_ult)
                 {
                     $disp_array[$time_index] .= $char;
                 }
                 else
                 {
                     if ('' != $time_ult)
                     {
                         $time_index++;
                     }
                     $disp_array[$time_index] = $char;
                 }
             }
             $time_ult = $char;
         }

         $time_final = array();
         foreach ($time_array as $time_part)
         {
             if (in_array($time_part, $disp_array))
             {
                 $time_final[] = $time_part;
             }
         }

         $time_format = implode($time_sep, $time_final);
     }

     if ('DT' == $type)
     {
         $old_date_format = $date_format;
     }
     elseif ('DH' == $type)
     {
         $old_date_format = $date_format . ';' . $time_format;
     }
     elseif ('HH' == $type)
     {
         $old_date_format = $time_format;
     }

     for ($i = 0; $i < strlen($old_date_format); $i++)
     {
         $char = substr($old_date_format, $i, 1);
         if ('/' == $char)
         {
             $new_date_format .= $date_sep;
         }
         elseif (':' == $char)
         {
             $new_date_format .= $time_sep;
         }
         else
         {
             $new_date_format .= $char;
         }
     }

     $this->field_config[$field]['date_format'] = $new_date_format;
     if ('DH' == $type)
     {
         $new_date_format                                      = explode(';', $new_date_format);
         $this->field_config[$field]['date_format_js']        = $new_date_format[0];
         $this->field_config[$field . '_hora']['date_format'] = $new_date_format[1];
         $this->field_config[$field . '_hora']['time_sep']    = $this->field_config[$field]['time_sep'];
     }
 } // new_date_format

   function SC_fast_search($field, $arg_search, $data_search)
   {
      if (empty($data_search)) 
      {
          unset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_filter']);
          unset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total']);
          unset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['fast_search']);
          if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_detal']) && !empty($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_detal'])) 
          {
              $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_filter'] = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_detal'];
          }
          return;
      }
      $comando = "";
      if ($_SESSION['scriptcase']['charset'] != "UTF-8" && NM_is_utf8($data_search))
      {
          $data_search = NM_conv_charset($data_search, $_SESSION['scriptcase']['charset'], "UTF-8");
      }
      $sv_data = $data_search;
      if ($field == "bcode") 
      {
          $this->SC_monta_condicao($comando, "BCODE", $arg_search, $data_search);
      }
      if ($field == "name") 
      {
          $this->SC_monta_condicao($comando, "NAME", $arg_search, $data_search);
      }
      if ($field == "address1") 
      {
          $this->SC_monta_condicao($comando, "ADDRESS1", $arg_search, $data_search);
      }
      if ($field == "address2") 
      {
          $this->SC_monta_condicao($comando, "ADDRESS2", $arg_search, $data_search);
      }
      if ($field == "city") 
      {
          $this->SC_monta_condicao($comando, "CITY", $arg_search, $data_search);
      }
      if ($field == "state") 
      {
          $this->SC_monta_condicao($comando, "STATE", $arg_search, $data_search);
      }
      if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_detal']) && !empty($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_detal']) && !empty($comando)) 
      {
          $comando = $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_detal'] . " and (" .  $comando . ")";
      }
      if (empty($comando)) 
      {
          $comando = " 1 <> 1 "; 
      }
      $sc_where = " where " . $comando;
      $nmgp_select = "SELECT count(*) from " . $this->Ini->nm_tabela . $sc_where; 
      $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nmgp_select; 
      $rt = $this->Db->Execute($nmgp_select) ; 
      if ($rt === false && !$rt->EOF && $GLOBALS["NM_ERRO_IBASE"] != 1) 
      { 
          $this->Erro->mensagem (__FILE__, __LINE__, "banco", $this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg()); 
          exit ; 
      }  
     $qt_geral_reg_custbill_form = isset($rt->fields[0]) ? $rt->fields[0] - 1 : 0; 
     $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['total'] = $qt_geral_reg_custbill_form;
      $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['where_filter'] = $comando;
      $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['fast_search'][0] = $field;
      $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['fast_search'][1] = $arg_search;
      $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['fast_search'][2] = $sv_data;
      $rt->Close(); 
   }
   function SC_monta_condicao(&$comando, $nome, $condicao, $campo, $tp_campo="")
   {
      $nm_aspas   = "'";
      $nm_numeric = array();
      $campo_join = strtolower(str_replace(".", "_", $nome));
      $nm_ini_lower = "";
      $nm_fim_lower = "";
      $nm_numeric[] = "number";$nm_numeric[] = "mtd";$nm_numeric[] = "ytd";$nm_numeric[] = "qtd";$nm_numeric[] = "jan";$nm_numeric[] = "feb";$nm_numeric[] = "mar";$nm_numeric[] = "apr";$nm_numeric[] = "may";$nm_numeric[] = "jun";$nm_numeric[] = "jul";$nm_numeric[] = "aug";$nm_numeric[] = "sep";$nm_numeric[] = "oct";$nm_numeric[] = "nov";$nm_numeric[] = "`dec`";$nm_numeric[] = "lyear";$nm_numeric[] = "llyear";$nm_numeric[] = "q1";$nm_numeric[] = "q2";$nm_numeric[] = "q3";$nm_numeric[] = "q4";$nm_numeric[] = "s365";
      if (in_array($campo_join, $nm_numeric))
      {
         if ($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['decimal_db'] == ".")
         {
             $nm_aspas = "";
         }
         if (is_array($campo))
         {
             foreach ($campo as $Ind => $Cmp)
             {
                if (!is_numeric($Cmp))
                {
                    return;
                }
                if ($Cmp == "")
                {
                    $campo[$Ind] = 0;
                }
             }
         }
         else
         {
             if (!is_numeric($campo))
             {
                 return;
             }
             if ($campo == "")
             {
                $campo = 0;
             }
         }
      }
      $Nm_datas[] = "tdate";$Nm_datas[] = "updated";
          if (in_array($campo_join, $Nm_datas) && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_access))
          {
             $nm_aspas = "#";
          }
         if (in_array($campo_join, $nm_numeric) && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_postgres) && (strtoupper($condicao) == "II" || strtoupper($condicao) == "QP" || strtoupper($condicao) == "NP"))
         {
             $nome     = "CAST ($nome AS TEXT)";
             $nm_aspas = "'";
         }
         if (in_array($campo_join, $Nm_datas) && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_postgres))
         {
             $nome     = "to_char ($nome, 'YYYY-MM-DD')";
         }
         if (substr($tp_campo, 0, 4) == "DATE" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_sybase))
         {
             $nome     = "str_replace (convert(char(10),$nome,102), '.', '-') + ' ' + convert(char(8),$nome,20)";
         }
         if (substr($tp_campo, 0, 4) == "DATE" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_mssql))
         {
             $nome     = "convert(char(23),$nome,121)";
         }
         if (substr($tp_campo, 0, 5) == "TIMES" && in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_oracle))
         {
             $nome     = "TO_DATE(TO_CHAR($nome, 'yyyy-mm-dd hh24:mi:ss'), 'yyyy-mm-dd hh24:mi:ss')";
             $tp_campo = "DATE" . substr($tp_campo, 4);
         }
         $comando .= (!empty($comando) ? " or " : "");
         if (is_array($campo))
         {
             $prep = "";
             foreach ($campo as $Ind => $Cmp)
             {
                 $prep .= (!empty($prep)) ? "," : "";
                 $Cmp   = substr($this->Db->qstr($Cmp), 1, -1);
                 $prep .= $nm_aspas . $Cmp . $nm_aspas;
             }
             $prep .= (empty($prep)) ? $nm_aspas . $nm_aspas : "";
             $comando .= $nm_ini_lower . $nome . $nm_fim_lower . " in (" . $prep . ")";
             return;
         }
         $campo  = substr($this->Db->qstr($campo), 1, -1);
         switch (strtoupper($condicao))
         {
            case "EQ":     // 
               $comando        .= $nm_ini_lower . $nome . $nm_fim_lower . " = " . $nm_aspas . $campo . $nm_aspas;
            break;
            case "II":     // 
               $comando        .= $nm_ini_lower . $nome . $nm_fim_lower . " like '" . $campo . "%'";
            break;
            case "QP":     // 
               if (substr($tp_campo, 0, 4) == "DATE")
               {
                   $NM_cmd     = "";
                   if ($this->NM_data_qp['ano'] != "____")
                   {
                       $NM_cmd     .= (empty($NM_cmd)) ? "" : " and ";
                       if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_postgres))
                       {
                           $NM_cmd     .= "extract('year' from $nome) = " . $this->NM_data_qp['ano'];
                       }
                       elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_ibase))
                       {
                           $NM_cmd     .= "extract(year from $nome) = " . $this->NM_data_qp['ano'];
                       }
                       else
                       {
                       $NM_cmd     .= "year($nome) = " . $this->NM_data_qp['ano'];
                       }
                   }
                   if ($this->NM_data_qp['mes'] != "__")
                   {
                       $NM_cmd     .= (empty($NM_cmd)) ? "" : " and ";
                       if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_postgres))
                       {
                           $NM_cmd     .= "extract('month' from $nome) = " . $this->NM_data_qp['mes'];
                       }
                       elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_ibase))
                       {
                           $NM_cmd     .= "extract(month from $nome) = " . $this->NM_data_qp['mes'];
                       }
                       else
                       {
                       $NM_cmd     .= "month($nome) = " . $this->NM_data_qp['mes'];
                       }
                   }
                   if ($this->NM_data_qp['dia'] != "__")
                   {
                       $NM_cmd     .= (empty($NM_cmd)) ? "" : " and ";
                       if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_postgres))
                       {
                           $NM_cmd     .= "extract('day' from $nome) = " . $this->NM_data_qp['dia'];
                       }
                       elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_ibase))
                       {
                           $NM_cmd     .= "extract(day from $nome) = " . $this->NM_data_qp['dia'];
                       }
                       else
                       {
                       $NM_cmd     .= "day($nome) = " . $this->NM_data_qp['dia'];
                       }
                   }
                   if (!empty($NM_cmd))
                   {
                       $NM_cmd     = " (" . $NM_cmd . ")";
                       $comando        .= $NM_cmd;
                   }
               }
               else
               {
                   $comando        .= $nm_ini_lower . $nome . $nm_fim_lower ." like '%" . $campo . "%'";
               }
            break;
            case "NP":     // 
               if (substr($tp_campo, 0, 4) == "DATE")
               {
                   $NM_cmd     = "";
                   if ($this->NM_data_qp['ano'] != "____")
                   {
                       $NM_cmd     .= (empty($NM_cmd)) ? "" : " and ";
                       if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_postgres))
                       {
                           $NM_cmd     .= "extract('year' from $nome) <> " . $this->NM_data_qp['ano'];
                       }
                       elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_ibase))
                       {
                           $NM_cmd     .= "extract(year from $nome) <> " . $this->NM_data_qp['ano'];
                       }
                       else
                       {
                       $NM_cmd     .= "year($nome) <> " . $this->NM_data_qp['ano'];
                       }
                   }
                   if ($this->NM_data_qp['mes'] != "__")
                   {
                       $NM_cmd     .= (empty($NM_cmd)) ? "" : " and ";
                       if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_postgres))
                       {
                           $NM_cmd     .= "extract('month' from $nome) <> " . $this->NM_data_qp['mes'];
                       }
                       elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_ibase))
                       {
                           $NM_cmd     .= "extract(month from $nome) <> " . $this->NM_data_qp['mes'];
                       }
                       else
                       {
                       $NM_cmd     .= "month($nome) <> " . $this->NM_data_qp['mes'];
                       }
                   }
                   if ($this->NM_data_qp['dia'] != "__")
                   {
                       $NM_cmd     .= (empty($NM_cmd)) ? "" : " and ";
                       if (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_postgres))
                       {
                           $NM_cmd     .= "extract('day' from $nome) <> " . $this->NM_data_qp['dia'];
                       }
                       elseif (in_array(strtolower($this->Ini->nm_tpbanco), $this->Ini->nm_bases_ibase))
                       {
                           $NM_cmd     .= "extract(day from $nome) <> " . $this->NM_data_qp['dia'];
                       }
                       else
                       {
                       $NM_cmd     .= "day($nome) <> " . $this->NM_data_qp['dia'];
                       }
                   }
                   if (!empty($NM_cmd))
                   {
                       $NM_cmd     = " (" . $NM_cmd . ")";
                       $comando        .= $NM_cmd;
                   }
               }
               else
               {
                   $comando        .= $nm_ini_lower . $nome . $nm_fim_lower ." not like '%" . $campo . "%'";
               }
            break;
            case "DF":     // 
               if ($tp_campo == "DTDF" || $tp_campo == "DATEDF")
               {
                   $comando        .= $nm_ini_lower . $nome . $nm_fim_lower . " not like '%" . $campo . "%'";
               }
               else
               {
                   $comando        .= $nm_ini_lower . $nome . $nm_fim_lower . " <> " . $nm_aspas . $campo . $nm_aspas;
               }
            break;
            case "GT":     // 
               $comando        .= " $nome > " . $nm_aspas . $campo . $nm_aspas;
            break;
            case "GE":     // 
               $comando        .= " $nome >= " . $nm_aspas . $campo . $nm_aspas;
            break;
            case "LT":     // 
               $comando        .= " $nome < " . $nm_aspas . $campo . $nm_aspas;
            break;
            case "LE":     // 
               $comando        .= " $nome <= " . $nm_aspas . $campo . $nm_aspas;
            break;
         }
   }
function nmgp_redireciona($tipo=0)
{
   global $nm_apl_dependente;
   if (isset($_SESSION['scriptcase']['nm_sc_retorno']) && !empty($_SESSION['scriptcase']['nm_sc_retorno']) && $_SESSION['scriptcase']['sc_tp_saida'] != "D" && $nm_apl_dependente != 1) 
   {
       $nmgp_saida_form = $_SESSION['scriptcase']['nm_sc_retorno'];
   }
   else
   {
       $nmgp_saida_form = $_SESSION['scriptcase']['sc_url_saida'][$this->Ini->sc_page];
   }
   if ($tipo == 2 && isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['sc_outra_jan']) && $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['sc_outra_jan'])
   {
       $nmgp_saida_form = "custbill_form_fim.php";
   }
   if (isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['redir']) && $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['redir'] == 'redir')
   {
       unset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']);
   }
   unset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['opc_ant']);
   $diretorio = explode("/", $nmgp_saida_form);
   $cont = count($diretorio);
   $apl = $diretorio[$cont - 1];
   $apl = str_replace(".php", "", $apl);
   $pos = strpos($apl, "?");
   if ($pos !== false)
   {
       $apl = substr($apl, 0, $pos);
   }
   if ($tipo != 1 && $tipo != 2)
   {
       unset($_SESSION['sc_session'][$this->Ini->sc_page][$apl]['where_orig']);
   }
   if ($this->NM_ajax_flag)
   {
       $this->NM_ajax_info['redir']['metodo']              = 'post';
       $this->NM_ajax_info['redir']['action']              = $nmgp_saida_form;
       $this->NM_ajax_info['redir']['target']              = '_self';
       $this->NM_ajax_info['redir']['script_case_init']    = $this->Ini->sc_page;
       $this->NM_ajax_info['redir']['script_case_session'] = session_id();
       if (0 == $tipo)
       {
           $this->NM_ajax_info['redir']['nmgp_url_saida'] = $this->nm_location;
       }
       custbill_form_pack_ajax_response();
       exit;
   }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">

   <HTML>
   <HEAD>
    <META http-equiv="Content-Type" content="text/html; charset=<?php echo $_SESSION['scriptcase']['charset_html'] ?>" />
    <META http-equiv="Expires" content="Fri, Jan 01 1900 00:00:00 GMT"/>
    <META http-equiv="Last-Modified" content="<?php echo gmdate("D, d M Y H:i:s"); ?> GMT"/>
    <META http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate"/>
    <META http-equiv="Cache-Control" content="post-check=0, pre-check=0"/>
    <META http-equiv="Pragma" content="no-cache"/>
   </HEAD>
   <BODY>
   <FORM name="form_ok" method="POST" action="<?php echo NM_encode_input($nmgp_saida_form); ?>" target="_self">
<?php
   if ($tipo == 0)
   {
?>
     <INPUT type="hidden" name="nmgp_url_saida" value="<?php echo NM_encode_input($this->nm_location); ?>"> 
<?php
   }
?>
     <INPUT type="hidden" name="script_case_init" value="<?php echo NM_encode_input($this->Ini->sc_page); ?>"> 
     <INPUT type="hidden" name="script_case_session" value="<?php echo NM_encode_input(session_id()); ?>"> 
   </FORM>
   <SCRIPT type="text/javascript">
      bLigEditLookupCall = <?php if ($this->lig_edit_lookup_call) { ?>true<?php } else { ?>false<?php } ?>;
      function scLigEditLookupCall()
      {
<?php
   if ($this->lig_edit_lookup && isset($_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['sc_modal']) && $_SESSION['sc_session'][$this->Ini->sc_page]['custbill_form']['sc_modal'])
   {
?>
        parent.<?php echo $this->lig_edit_lookup_cb; ?>(<?php echo $this->lig_edit_lookup_row; ?>);
<?php
   }
   elseif ($this->lig_edit_lookup)
   {
?>
        opener.<?php echo $this->lig_edit_lookup_cb; ?>(<?php echo $this->lig_edit_lookup_row; ?>);
<?php
   }
?>
      }
      if (bLigEditLookupCall)
      {
        scLigEditLookupCall();
      }
      document.form_ok.submit();
   </SCRIPT>
   </BODY>
   </HTML>
<?php
  exit;
}
}
?>
