function HTMLNavigationForm(sys, formID, posX, posY) {
  this.create(sys, formID, posX, posY, 34, 34);
}

HTMLNavigationForm.inherits(HTMLNavigation);

HTMLNavigationForm.prototype.name = 'HTMLNavigationForm';

HTMLNavigationForm.prototype.setMainImages = function(imgInclude, imgEdit, imgFirst, imgPrevious, imgNext, imgLast, imgDelete, imgRefresh, imgLog, imgDefaultValues, imgPrint, imgHelp, imgExit) {
  var fixedWidth = 34;

  var imgIncludeWidth       = fixedWidth;
  var imgEditWidth          = fixedWidth;
  var imgFirstWidth         = fixedWidth;
  var imgPreviousWidth      = fixedWidth;
  var imgNextWidth          = fixedWidth;
  var imgLastWidth          = fixedWidth;
  var imgDeleteWidth        = fixedWidth;
  var imgRefreshWidth       = fixedWidth;
  var imgPrintWidth         = fixedWidth;
  var imgLogWidth           = fixedWidth;
  var imgDefaultValuesWidth = fixedWidth;
  var imgHelpWidth          = fixedWidth;
  var imgExitWidth          = fixedWidth;
  var imgDesignWidth        = fixedWidth;
  var imgCancelWidth        = 80;
  var imgSaveWidth          = 80;

  if (imgInclude != -1) {
    this.btInclude = this.addMainButton(skin+'mainnav_include.gif', getLocaleMessage('LABEL.INCLUDE') + ' (Ctrl+Ins/Ctrl+I)', this.getAction('actInclude'), imgIncludeWidth);
    this.canInclude = true;
  } else {
    this.canInclude = false;
  }
  if (imgEdit != -1) {
    this.btEdit = this.addMainButton(skin+'mainnav_edit.gif', getLocaleMessage('LABEL.RECORD_EDIT') + ' (Ctrl+E)', this.getAction('actEdit'), imgEditWidth);
    this.canEdit = true;
  } else {
    this.canEdit = false;
  }

  if (imgFirst != -1) this.btFirst = this.addMainButton(skin+'mainnav_first.gif', getLocaleMessage('LABEL.FIRST_RECORD') + ' (Ctrl+Home)', this.getAction('actFirst'), imgFirstWidth);
  if (imgPrevious != -1) this.btPrevious = this.addMainButton(skin+'mainnav_previous.gif', getLocaleMessage('LABEL.PREVIOUS_RECORD') + ' (PgDown)', this.getAction('actPrevious'), imgPreviousWidth);
  if (imgNext != -1) this.btNext = this.addMainButton(skin+'mainnav_next.gif', getLocaleMessage('LABEL.NEXT_RECORD') + ' (PgUp)', this.getAction('actNext'), imgNextWidth);
  if (imgLast != -1) this.btLast = this.addMainButton(skin+'mainnav_last.gif', getLocaleMessage('LABEL.LAST_RECORD') + ' (Ctrl+End)', this.getAction('actLast'), imgLastWidth);
  if (imgDelete != -1) this.btDelete = this.addMainButton(skin+'mainnav_delete.gif', getLocaleMessage('LABEL.REMOVE_RECORD') + ' (Ctrl+Del/Ctrl+D)', this.getAction('actDelete'), imgDeleteWidth);
  if (imgRefresh != -1) this.btRefresh = this.addMainButton(skin+'mainnav_refresh.gif', getLocaleMessage('LABEL.REFRESH') + ' (Alt+A)', this.getAction('actRefresh'), imgRefreshWidth);
  if (imgPrint != -1) this.btPrint = this.addMainButton(skin+'mainnav_print.gif', getLocaleMessage('LABEL.PRINT') + ' (Ctrl+P)', this.getAction('actPrint'), imgPrintWidth);
  if (imgLog != -1) this.btLog = this.addMainButton(skin+'mainnav_log.gif', getLocaleMessage('LABEL.LOG_LABEL'), this.getAction('actLog'), imgLogWidth);
  if (imgDefaultValues != -1) this.btDefaultValues = this.addMainButton(skin+'mainnav_default_values.gif', getLocaleMessage('LABEL.DEFAULT_VALUES') + ' (Ctrl+Shift+C)', this.getAction('actDefaultValues'), imgDefaultValuesWidth);
  if (imgHelp != -1) this.btHelp = this.addMainButton(skin+'mainnav_help.gif', getLocaleMessage('LABEL.HELP')+' (F12)', this.getAction('actHelp'), imgHelpWidth);
  if (this.isEditable) {
    this.btDesign = this.addMainButton(skin+'mainnav_design.gif', getLocaleMessage('INFO.FORM_EDIT'), this.getAction('actDesign'), imgDesignWidth);
    this.btDesignCancel = this.addDesignButton(skin+'mainnav_cancel.gif', '', getLocaleMessage('LABEL.CANCEL') + ' (Esc)', this.getAction('actDesignCancel'), true, imgCancelWidth);
    this.btDesignSave = this.addDesignButton(skin+'mainnav_save.gif', '', getLocaleMessage('LABEL.SAVE_RECORD') + ' (Ctrl+G)', this.getAction('actDesignSave'), true, imgSaveWidth);
  }
  if (imgExit != -1) this.btExit = this.addMainButton(skin+'mainnav_exit.gif', getLocaleMessage('LABEL.EXIT') + ' (Alt+F4)', this.getAction('actExit'), imgExitWidth);

}

HTMLNavigationForm.prototype.design = function(doc, tabControl) {
  this.doc = doc;
  this.div = this.getDiv('WFRComponent'+this.code, this.posX, this.posY, this.width, this.height, this.zindex, this.visible);
  this.context = this.div;
  this.designComponent(doc, tabControl);
  doc.appendChild(this.div);
  this.init(tabControl);
}

HTMLNavigationForm.prototype.freeButtons = function() {
  this.btInclude = null;
  this.btEdit = null;
  if (this.btFirst) this.btFirst = null;
  if (this.btPrevious) this.btPrevious = null;
  if (this.btNext) this.btNext = null;
  if (this.btLast) this.btLast = null;
  if (this.btDelete) this.btDelete = null;
  if (this.btRefresh) this.btRefresh = null;
  if (this.btPrint) this.btPrint = null;
  if (this.btLog) this.btLog = null;
  if (this.btDefaultValues) this.btDefaultValues = null;
  if (this.btHelp) this.btHelp = null;
  if (this.btDesign) this.btDesign = null;
  if (this.btDesignCancel) this.btDesignCancel = null;
  if (this.btDesignSave)this.btDesignSave = null;
  if (this.btExit) this.btExit = null;
  this.btEditSave = null;
  this.btEditCancel = null;
  this.btIncludeSaveMore = null;
  this.btIncludeSave = null;
  this.btIncludeCancel = null;
}

HTMLNavigationForm.prototype.setEditImages = function(imgSave, imgCancel) {
  var imgSaveWidth = 80;
  var imgCancelWidth = 80;

  if (imgSave != -1) this.btEditSave = this.addEditButton(skin+'mainnav_save.gif', '', getLocaleMessage("LABEL.SAVE_RECORD")+' (Ctrl+S)', this.getAction('actEditSave'), true, imgSaveWidth);
  if (imgCancel != -1) this.btEditCancel = this.addEditButton(skin+'mainnav_cancel.gif', '', getLocaleMessage("LABEL.CANCEL")+' (Esc)', this.getAction('actEditCancel'), true, imgCancelWidth);
}

HTMLNavigationForm.prototype.setIncludeImages = function(imgSave, imgCancel) {
  var imgSaveWidth = 80;
  var imgSaveMoreWidth = 80;
  var imgCancelWidth = 80;

  if (imgSave != -1) this.btIncludeSaveMore = this.addIncludeButton(skin+'mainnav_save_more.gif', getLocaleMessage("LABEL.SAVE_RECORD")+' +', getLocaleMessage("LABEL.SAVE_RECORD")+' (Ctrl+G)', this.getAction('actIncludeSaveMore'), true, imgSaveMoreWidth);
  if (imgSave != -1) this.btIncludeSave = this.addIncludeButton(skin+'mainnav_save.gif', getLocaleMessage("LABEL.SAVE_RECORD"), getLocaleMessage("LABEL.SAVE_RECORD")+' (Ctrl+S)', this.getAction('actIncludeSave'), true, imgSaveWidth);
  if (imgCancel != -1) this.btIncludeCancel = this.addIncludeButton(skin+'mainnav_cancel.gif', getLocaleMessage("LABEL.CANCEL"), getLocaleMessage("LABEL.CANCEL")+' (Esc)', this.getAction('actIncludeCancel'), true, imgCancelWidth);
}

HTMLNavigationForm.prototype.execAjaxEval = function(param) {
  var url = 'form.do?sys=' + this.sys + '&formID=' + this.formID + '&param=' + param + '&align=0&filter=&goto='+formrow;

  var paramsName = arguments[1];
  var paramsValue = arguments[2];

  if (paramsName != null && paramsName.length != 0) {
    for (var i = 0; i < paramsName.length; i++) {
      var param = paramsName[i];

      if (param != "") url += ('&' + param + '=' + paramsValue[i]);
    }
  }
 
  if (document.t) {
	  var dep = document.t.dependences;
	  for (var componentUpdateCode in dep) {
	    if (typeof componentUpdateCode == "function") {
	      continue;
	    }
	    
	    for (var index in dep[componentUpdateCode]) {
	      if (typeof index == "function") {
	        continue;
	      }
	    
	      var componentCode = dep[componentUpdateCode][index];
	      if (isNumeric(componentCode)) {
	        var component = eval("$mainform().d.c_" + componentCode);
	
	        if ((component == null) || (typeof component == "undefined")) {
	          continue;
	        }
	      
	        url += ("&WFRInput" + component.getCode() + "=" + URLEncode(component.getValue()));
	      }  
	    }
	  }
  }

  getAndEval(url);
}

HTMLNavigationForm.prototype.execAjaxEvalSync = function(param) {
  var url = 'sys=' + this.sys + '&formID=' + this.formID + '&param=' + param + '&align=0&filter=&goto='+formrow;

  var paramsName = arguments[1];
  var paramsValue = arguments[2];

  if (paramsName != null && paramsName.length != 0) {
    for (var i = 0; i < paramsName.length; i++) {
      var param = paramsName[i];

      if (param != "") url += ('&' + param + '=' + paramsValue[i]);
    }
  }
  url += "&forceGetResponse=true";
  
  if (document.t) {
    var dep = document.t.dependences;
    for (var componentUpdateCode in dep) {
      if (typeof componentUpdateCode == "function") {
        continue;
      }
      
      for (var index in dep[componentUpdateCode]) {
        if (typeof index == "function") {
          continue;
        }
      
        var componentCode = dep[componentUpdateCode][index];
        if (isNumeric(componentCode)) {
          var component = eval("$mainform().d.c_" + componentCode);
  
          if ((component == null) || (typeof component == "undefined")) {
            continue;
          }
        
          url += ("&WFRInput" + component.getCode() + "=" + URLEncode(component.getValue()));
        }
      }
    }
  }
  
  eval(postURL("form.do", url));
}

HTMLNavigationForm.prototype.actInclude = function() {
  if (this.btInclude != null && this.btInclude.enabled) {
    if (!this.queryMode) {
      this.execAjaxEval('include');
    } else {
      interactionInfo(this.querymsg);
    }
  }
}

HTMLNavigationForm.prototype.actIncludeSync = function() {
  if (this.btInclude != null && this.btInclude.enabled) {
    if (!this.queryMode) {
      this.execAjaxEvalSync('include');
    } else {
      interactionInfo(this.querymsg);
    }
  }
}

HTMLNavigationForm.prototype.actEdit = function() { 
  if (this.btEdit != null && this.btEdit.enabled) {
    if (hasdata) {
      if (!this.queryMode)
        this.execAjaxEval('edit');
      else
        interactionInfo(this.querymsg);
    } else {
    	if (this.btInclude != null && this.btInclude.enabled)
          this.actInclude();
        else
      	  interactionInfo(getLocaleMessage("INFO.CANNOT_INSERT_FORM"));
    }
  }
}

HTMLNavigationForm.prototype.actEditSync = function() {
  if (this.btEdit != null && this.btEdit.enabled) {
    if (hasdata) {
      if (!this.queryMode)
        this.execAjaxEvalSync('edit');
      else
        interactionInfo(this.querymsg);
    } else {
      if (this.btInclude != null && this.btInclude.enabled)
          this.actInclude(true);
        else
          interactionInfo(getLocaleMessage("INFO.CANNOT_INSERT_FORM"));
    }
  }
}

HTMLNavigationForm.prototype.actFirst = function() {
  if (this.btFirst != null && this.btFirst.enabled) {
    if (!this.queryMode)
      this.execAjaxEval('first');
    else
      interactionInfo(this.querymsg);
  }
}

HTMLNavigationForm.prototype.actFirstSync = function() {
  if (this.btFirst != null && this.btFirst.enabled) {
    if (!this.queryMode)
      this.execAjaxEvalSync('first');
    else
      interactionInfo(this.querymsg);
  }
}

HTMLNavigationForm.prototype.actPrevious = function() {
  if (this.btPrevious != null && this.btPrevious.enabled) {
    if (!this.queryMode)
      this.execAjaxEval('previous');
    else
      interactionInfo(this.querymsg);
  }
}

HTMLNavigationForm.prototype.actPreviousSync = function() {
  if (this.btPrevious != null && this.btPrevious.enabled) {
    if (!this.queryMode)
      this.execAjaxEvalSync('previous');
    else
      interactionInfo(this.querymsg);
  }
}

HTMLNavigationForm.prototype.actNext = function() {
  if (this.btNext != null && this.btNext.enabled) {
    if (!this.queryMode)
      this.execAjaxEval('next');
    else
      interactionInfo(this.querymsg);
  }
}

HTMLNavigationForm.prototype.actNextSync = function() {
  if (this.btNext != null && this.btNext.enabled) {
    if (!this.queryMode)
      this.execAjaxEvalSync('next');
    else
      interactionInfo(this.querymsg);
  }
}

HTMLNavigationForm.prototype.actLast = function() {
  if (this.btLast != null && this.btLast.enabled) {
    if (!this.queryMode)
      this.execAjaxEval('last');
    else
      interactionInfo(this.querymsg);
  }
}

HTMLNavigationForm.prototype.actLastSync = function() {
  if (this.btLast != null && this.btLast.enabled) {
    if (!this.queryMode)
      this.execAjaxEvalSync('last');
    else
      interactionInfo(this.querymsg);
  }
}

HTMLNavigationForm.prototype.actGoto = function(row) {
  if (hasdata) {
    if (!this.queryMode) {
      formrow = row;
      this.execAjaxEval('goto');
    } else {
      interactionInfo(this.querymsg);
    }
  }
}

HTMLNavigationForm.prototype.actGotoSync = function(row) {
  if (hasdata) {
    if (!this.queryMode) {
      formrow = row;
      this.execAjaxEvalSync('goto');
    } else {
      interactionInfo(this.querymsg);
    }
  }
}

HTMLNavigationForm.prototype.actDelete = function() {
  if (this.btDelete != null && this.btDelete.enabled) {
    if (hasdata) {
      if (this.queryMode) {
        interactionInfo(this.querymsg);
      } else {
        interactionConfirm(getLocaleMessage("INFO.REMOVE_CONFIRM"),
          function() {
            try {
              formBeforeDelete();
              WFRFormComands.location = 'form.do?sys=' + this.sys + '&formID=' + this.formID + '&action=form&param=delete&filter=&pType=1&goto='+formrow;
              try { d.p.loaded = false; } catch(e) { }
            } catch (ex) {
              handleException(ex);
            }
          }, null, this);
      }
    }
  }
}

HTMLNavigationForm.prototype.actRefresh = function() {
  // Mensagens de interação
  var messages = new Array();
  messages.push(getLocaleMessage("INFO.UPDATE_WANT"))
  messages.push(getLocaleMessage("INFO.UPDATE_CURRENT_RECORD"))
  messages.push(getLocaleMessage("INFO.UPDATE_ALL_FORM"));

  if (this.btRefresh != null && this.btRefresh.enabled) {
    if (!this.queryMode) {
      if (this.developmentMode) {
    	  /* Verifica o formulário é modal e avisa que
    	   o formulário deve ser fechado e aberto novamente */
    	  if(this.isModal && IE) {
    	    if(parent.formOnUnLoadAction)
    	      // Limpa o Dataset 
              parent.formOnUnLoadAction();
    	    // Avisa o usuário que ele deve fechar e abrir novamente o form
    	    alert("Você deverá fechar e abrir novamente o formulário modal para visualizar alterações.");
    	  } else {
    		parent.location = parent.location.toString();
    	  }
      } else {
    	/* Verifica o formulário é modal e remove
   	     a opção de atualizar todo o formulário */  
    	if(!this.isModal) {
          interaction(messages[0],
            [ messages[1], messages[2] ],
            [ this.execAjaxEval, function() { parent.location = parent.location.toString(); } ],
            [ ["refresh"] ],
            [ this ]
          );
    	} else {
    	  interaction(messages[0],
    	    [ messages[1] ],
    	    [ this.execAjaxEval ],
    	    [ ["refresh"] ],
    	    [ this ]
    	  );
    	}
      }
    } else {
      interactionInfo(this.querymsg);
    }
  }
}

HTMLNavigationForm.prototype.actHelp = function() {
  if (this.btHelp != null && this.btHelp.enabled) {
    showFormHelp(this.sys, this.formID);
  }
}

HTMLNavigationForm.prototype.actPrint = function() {
  if (this.btPrint != null && this.btPrint.enabled) {
    if (this.reportCode) {
      openWFRReport2(this.sys, this.reportCode, this.formID, this.reportDescription);
    }
  }
}

HTMLNavigationForm.prototype.actExit = function() {
  if (this.btExit != null && this.btExit.enabled) {
    parent.close();
  }
}

HTMLNavigationForm.prototype.actDesign = function() {
  if (this.btDesign != null && this.btDesign.enabled) {
    this.formDesign();
    makercontroller.editMode();
  }
}

HTMLNavigationForm.prototype.actDesignSave = function () {
  if (this.btDesignSave != null && this.btDesignSave.enabled) {
    makercontroller.saveToDatabase();
  }
}

HTMLNavigationForm.prototype.actDesignCancel = function () {
  if (this.btDesignCancel != null && this.btDesignCancel.enabled) {
    makercontroller.cancelChanges();
  }
}

HTMLNavigationForm.prototype.getMaker = function() {
  return makercontroller;
}

HTMLNavigationForm.prototype.actEditSave = function() {
  if (this.btEditSave != null && this.btEditSave.enabled) {
    try {
      if (controller.checkRequireds() && !httpprocessing) {
        controller.doInvisibleComponents();
        formBeforeUpdate();
        MM_findObj('goto').value = formrow;
        MM_findObj('param').value = 'postcancel';
        showWait();
        controller.beforeSubmit();
        WFRForm.submit();
        controller.afterSubmit();
        try { d.p.loaded = false; } catch(e) { }
      }
    } catch (ex) {
      handleException(ex);
    }
  }
}

HTMLNavigationForm.prototype.actEditSaveSync = function() {
  if (this.btEditSave != null && this.btEditSave.enabled) {
    try {
      if (controller.checkRequireds() && !httpprocessing) {
        controller.doInvisibleComponents();
        formBeforeUpdate();
        showWait();
        controller.beforeSubmit();
        this.postAndEvalSync("postcancel", formrow);
        controller.afterSubmit();
        hideWait();
        try { d.p.loaded = false; } catch(e) { }
      }
    } catch (ex) {
      handleException(ex);
    }
  }
}

HTMLNavigationForm.prototype.postAndEvalSync = function(param, formrow) {
  var url = 'sys=' + this.sys + '&formID=' + this.formID + '&param='+ param +'&filter=&pType=1&goto='+formrow;

  var elems = controller.getFormElements();
  for(i = 0; i < elems.length; i++) {
    url += "&WFRInput" + elems[i].getCode() + "=" + URLEncode(elems[i].getValue());
  }
  url += "&forceGetResponse=true";
  
  if (document.t) {
    var dep = document.t.dependences;
    for (var componentUpdateCode in dep) {
      if (typeof componentUpdateCode == "function") {
        continue;
      }

      for (var index in dep[componentUpdateCode]) {
        if (typeof index == "function") {
          continue;
        }

        var componentCode = dep[componentUpdateCode][index];
        if (isNumeric(componentCode)) {
          var component = eval("$mainform().d.c_" + componentCode);

          if ((component == null) || (typeof component == "undefined")) {
            continue;
          }

          url += ("&WFRInput" + component.getCode() + "=" + URLEncode(component.getValue()));
        }
      }
    }
  }

  eval(postURL("form.do", url));
}

HTMLNavigationForm.prototype.actEditCancel = function() {
  if (this.btEditCancel != null && this.btEditCancel.enabled) {
    this.editCancel = true;
    this.execAjaxEval('cancel');
    removeLookup(true);
  }
}

HTMLNavigationForm.prototype.actEditCancelSync = function() {
  if (this.btEditCancel != null && this.btEditCancel.enabled) {
    this.editCancel = true;
    this.execAjaxEvalSync('cancel');
    removeLookup(true);
  }
}

HTMLNavigationForm.prototype.actIncludeSave = function() {
  if (this.btIncludeSave != null && this.btIncludeSave.enabled) {
    try {
      if (controller.checkRequireds() && !httpprocessing) {
        controller.doInvisibleComponents();
        formBeforeInsert();
        MM_findObj('goto').value = formrow;
        MM_findObj('param').value = 'postcancel';
        showWait();
        controller.beforeSubmit();
        WFRForm.submit();
        controller.afterSubmit();
        try { d.p.loaded = false; } catch(e) { }
      }
    } catch (ex) {
      handleException(ex);
    }
  }
}

HTMLNavigationForm.prototype.actIncludeSaveSync = function() {
  if (this.btIncludeSave != null && this.btIncludeSave.enabled) {
    try {
      if (controller.checkRequireds() && !httpprocessing) {
        controller.doInvisibleComponents();
        formBeforeInsert();
        showWait();
        controller.beforeSubmit();
        this.postAndEvalSync("postcancel", formrow);
        controller.afterSubmit();
        hideWait();
        try { d.p.loaded = false; } catch(e) { }
      }
    } catch (ex) {
      handleException(ex);
    }
  }
}

HTMLNavigationForm.prototype.actIncludeSaveMore = function() {
  if (this.btIncludeSaveMore != null && this.btIncludeSaveMore.enabled) {
    try {
      if (controller.checkRequireds() && !httpprocessing) {
        controller.doInvisibleComponents();
        formBeforeInsert();
        MM_findObj('goto').value = formrow;
        MM_findObj('param').value = 'post';
        showWait();
        controller.beforeSubmit();
        WFRForm.submit();
        controller.afterSubmit();
        controller.focusFirst();
        try { d.p.loaded = false; } catch(e) { }
      }
    } catch (ex) {
      handleException(ex);
    }
  }
}

HTMLNavigationForm.prototype.actIncludeSaveMoreSync = function() {
  if (this.btIncludeSaveMore != null && this.btIncludeSaveMore.enabled) {
    try {
      if (controller.checkRequireds() && !httpprocessing) {
        controller.doInvisibleComponents();
        formBeforeInsert();
        showWait();
        controller.beforeSubmit();
        this.postAndEvalSync("post", formrow);
        controller.afterSubmit();
        controller.focusFirst();
        try { d.p.loaded = false; } catch(e) { }
      }
    } catch (ex) {
      handleException(ex);
    }
  }
}

HTMLNavigationForm.prototype.actIncludeCancel = function() {
  if (this.btIncludeCancel != null && this.btIncludeCancel.enabled) {
    this.execAjaxEval('cancel');
    removeLookup(true);
  }
}

HTMLNavigationForm.prototype.actIncludeCancelSync = function() {
  if (this.btIncludeCancel != null && this.btIncludeCancel.enabled) {
    this.execAjaxEvalSync('cancel');
    removeLookup(true);
  }
}

HTMLNavigationForm.prototype.actLog = function() {
  if (this.btLog != null && this.btLog.enabled) {
    if (!this.queryMode)
      openFormLog(this.sys, this.formID, 'Log', pkeys, '1');
    else
      interactionInfo(this.querymsg);
  }
}

HTMLNavigationForm.prototype.actDefaultValues = function() {
  if (this.btDefaultValues != null && this.btDefaultValues.enabled) {
    if (!this.queryMode)
      openDefaultValues(this.sys, this.formID);
    else
      interactionInfo(this.querymsg);
  }
}