/**
 * Método construtor do HTMLAlert.
 **/
function HTMLAlert() {
  this.visible = true;
  this.locked = false;
  this.activeFilter = false;
  this.waiting = false;
  this.includeMode = false;
  this.alterMode = false;
  this.hideImages = false;
  this.status = new Array();
}

/**
 * Herança do objeto.
 **/
HTMLAlert.inherits(HTMLElementBase);

/**
 * Exibe no formulário a imagem de filtro ativo.
 * @param v  
 **/
HTMLAlert.prototype.showFilter = function(v) {
	if (!this.hideImages) {
    if(v && this.locked) v = !v;
  
    if (!this.filterDiv && v) this.filterDiv = this.createAlert(skin+'form_filtermode.gif', null, 1, 100, getLocaleMessage("LABEL.ACTIVE_FILTER"));
    if (this.filterDiv) {
   	  visibleDiv(this.filterDiv, v&&this.visible);
      this.resizeAlert(this.filterDiv, 1);
    }	
  
    this.setStatus("filter",v);
	}
}

/**
 * Exibe no formulário a imagem de Inserção.
 * @param v 
 **/
HTMLAlert.prototype.showInclude = function(v) {
	if (!this.hideImages) {
    if (!this.includeDiv) this.includeDiv = this.createAlert(skin+'form_includemode.gif', null, 1, 200, getLocaleMessage("LABEL.INCLUSION"));
    visibleDiv(this.includeDiv, v&&this.visible);
    this.resizeAlert(this.includeDiv, 1);
  
    if(v) this.lock();
    this.setStatus('include', v);
	}
}

/**
 * Exibe no formulário a imagem de Alteração.
 * @param v 
 **/
HTMLAlert.prototype.showEdit = function(v) {
	if (!this.hideImages) {
    if (!this.editDiv) this.editDiv = this.createAlert(skin+'form_altermode.gif', null, 1, 200, getLocaleMessage("LABEL.ALTERATION"));
    visibleDiv(this.editDiv, v&&this.visible);
    this.resizeAlert(this.editDiv, 1);
  
    if(v) this.lock();
    this.setStatus('edit', v);
	}
}

/**
 * Exibe no formulário a imagem de sinalizando Aguardando.
 * @param v 
 **/
HTMLAlert.prototype.showProcessing = function(v) {
	if (!this.hideImages) {
	  if(v) {
	    if(this.filterDiv)  visibleDiv(this.filterDiv, false);
	    if(this.includeDiv) visibleDiv(this.includeDiv, false);
	    if(this.editDiv)    visibleDiv(this.editDiv, false);
	    if(this.errorDiv)   visibleDiv(this.errorDiv, false);
	  }
	  
	  if (!this.processDiv) this.processDiv = this.createAlert(skin+'wait.gif', null, 1, 300, getLocaleMessage("LABEL.WAIT"));
	  visibleDiv(this.processDiv, v&&this.visible);
	  this.resizeAlert(this.processDiv, 1);
	
	  if(!v) this.recall();
	  this.setStatus('waiting', v);
	}
}

/**
 * Exibe no formulário a imagem de Erro.
 * @param v 
 **/
HTMLAlert.prototype.showError = function(v) {
  if (!this.hideImages) {
    if(v && this.locked) v = !v;
  
    if (!this.errorDiv) this.errorDiv = this.createAlert(skin+'form_errors.gif', null, 1, 301, getLocaleMessage("LABEL.ERROR"));
    visibleDiv(this.errorDiv, v);
    this.resizeAlert(this.errorDiv, 1);
    this.errorDiv.onclick = showErrors;
    this.errorDiv.style.cursor = 'pointer';
    this.setStatus('error', v);
  }
}

/**
 * Seta o Status/Ação atual do formulário. 
 * @param status - Indica o indice do status no array.
 * @param v - Indica o status atual. 
 **/
HTMLAlert.prototype.setStatus = function(status,v) {
  this.status[status] = v;
}

/**
 * Bloqueia.
 **/
HTMLAlert.prototype.lock = function() {
  this.locked = true;
}

/**
 * Desbloqueia.
 **/
HTMLAlert.prototype.unLock  = function() {
  this.locked = false;
}

HTMLAlert.prototype.recall = function() {
  this.showFilter(this.status["filter"]);
  this.showInclude(this.status["include"]);
  this.showEdit(this.status["edit"])
  this.showError(this.status["error"]);
}

HTMLAlert.prototype.design = function(doc) {
  this.doc = doc;
  this.attachEvent(window, 'resize', this.resize);
}

HTMLAlert.prototype.resize = function() {
  this.resizeAlert(this.filterDiv, 1);
  this.resizeAlert(this.includeDiv, 1);
  this.resizeAlert(this.processDiv, 1);
  this.resizeAlert(this.errorDiv, 1);
}

HTMLAlert.prototype.resizeAlert = function(div, place) {
  if (div) {	
    var w = document.body.clientWidth;
    div.style.left = (w-(58*place)-2)+'px';
  }  
}

/**
 * @param src - Endereço da Imagem.
 * @param oc
 * @param zindex
 * @param descricao - Descrição da imagem. 
 **/
HTMLAlert.prototype.createAlert = function(src, oc, place, zindex, description) {
	var w = document.body.clientWidth;
  var definedDescription = ((description != null) && (typeof description != "undefined"));
  var div = getDiv("", w-(58*place)-2, 0, 58, 53, zindex, 'hide');
  var tab = '<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">';
  tab += '<tr><td background="'+skin+'nav_degrade.gif" id="imageContainer" align="center" valign="middle"></td></tr>';
  tab += (definedDescription ? ('<tr><td align="center">' + description + '</td></tr>') : '');
  tab += '</table>';
  div.innerHTML = tab;

  var img = new ImageObject().getImage(src, '', oc);
  findNode(div,"imageContainer").appendChild(img);

  this.doc.appendChild(div);
  return div;
}

HTMLAlert.prototype.flush = function() {
  this.filterDiv = null;
  this.includeDiv = null;
  this.editDiv = null;
  if (this.errorDiv) {
    if (this.errorDiv.onclick) this.errorDiv.onclick = null;
    this.errorDiv = null;
  }
  this.processDiv = null;
  this.status = null;
	this.callMethod(HTMLElementBase, "flush");
}