AlertBox = {
  id: "generic",
  defaultOptions: {title: "[alerta]",
                   width: 0,
                   height: 0,
                   zIndex:1000,
                   isHTML:false,
                   showFilter:true,
                   msgClassName:"div_alertBoxMsg",
                   msgStyle:null,
                   frame:self,
                   keys:{
                     k27:function(o){o.closeAlert()}  //ESC key
                   }},
  options: {},
  staticH: 80,
  staticW: 40,
  maxW: 0,
  maxH: 0,
  minW: 0,
  minH: 0,
  buttonPath: "",
  cssArqName: "DefaultBlue",
  abHTML: "",
  ab: null,
  iframe: null,
  filter: null,

  configAlert: function(msg, options) {
    this.options = Object.extend(Object.clone(this.defaultOptions), options || {});
    if(!(this.ref = top.mainFrame)) {
      if(!(this.ref = this.options.frame)) return;
    }

    this.setInitHTML();
    this.loadCss();
    this.maxW = parseInt(this.ref.document.body.clientWidth * 0.6);
    this.maxH = parseInt(this.ref.document.body.clientHeight * 0.75);
    this.alert(msg);

    if(this.options.showFilter) {
      if(AlertBox.actives.indexOf(this) == -1) {
        AlertBox.actives.push(this);
      }
    }

    if(this.alertAfter) {
      this.alertAfter();
    }
  },
  
  alert: function(msg) {
    var abMsg        = top.getObj("alertBoxMsg" + this.id, this.ref);
    var abTitle      = top.getObj("alertBoxTitle" + this.id, this.ref);
    var msgW         = lines = h = w = 0;
    var body         = this.ref.document.body;
    var abStyle      = this.ab.style;
    var iframeStyle  = this.iframe.style;
    var PIXEL_WIDTH  = 7;
    var PIXEL_HEIGHT = 15;

    msg = new String(msg);
    if(!this.options.isHTML){
      msg = msg.replace(/\n/g, "<br>").replace(/\t/g, "&nbsp;&nbsp;&nbsp;&nbsp;");
    }

    if(abTitle) {
      abTitle.innerHTML = "<b>" + this.options.title + "</b>";
    }
    abMsg.innerHTML = msg;

    //Cálculo aproximado da altura e da largura do AlertBox
    var quebras = ["<tr>", "<br>", "<p>", "<br/>", "</div>"]
    //O título também deve fazer parte das frases pois deve ser levado em conta para a largura do AlertBox
    var frases = [this.options.title, msg];
    var separadas = [];
    //Primeiro separa-se as frases pelas quebras de linha
    for(var i = 0; i < quebras.length; i++) {
      separadas = [];
      for(var j = 0; j < frases.length; j++) {
        separadas = separadas.concat(frases[j].split(quebras[i]));
      }
      frases = separadas;
    }
    var linhas = 0;
    var maiorW = 0;
    var fraseW = 0;
    //Para saber a largura, verifica-se o tamanho da maior frase
    //Para saber a altura, verifica-se quantas linhas existem, de acordo com a largura máxima do AlertBox
    for(i = 0; i < frases.length; i++) {
      if((fraseW = frases[i].stripTags().trim().length * PIXEL_WIDTH) > maiorW) {
        maiorW = fraseW;
      }
      if(fraseW == 0) {
        linhas++;
      } else {
        linhas += Math.ceil((fraseW) / this.maxW);
      }
    }

    //Como o título conta para o número de linhas, diminui 1 para retirar esta contagem
    linhas--;
    //Fim do Cálculo da altura e largura
    if((h = (this.options.height || (linhas * PIXEL_HEIGHT) + this.staticH)) > this.maxH) {
      h = this.maxH;
    } else if(h + this.staticH < this.minH) {
      h = this.minH;
    }

    //A largura do alertbox é de um tamanho fornecido pelos options ou do tamanho
    //da mensagem * 7px. Não pode ser maior que a largura permitida
    if((w = this.options.width || maiorW + this.staticW) > this.maxW) {
      w = this.maxW;
    } else if (w + this.staticW < this.minW) {
      w = this.minW;
    }
        
    abMsg.className = this.options.msgClassName;
    if(this.options.msgStyle) {
      abMsg.style.cssText = this.options.msgStyle;
    }
    if(this.staticH >= h){
      abMsg.style.height = this.staticH;
    }else{
      abMsg.style.height = h - this.staticH;
    }
    abMsg.style.width  = "100%";

    abStyle.position = "absolute";
    abStyle.width    = w + "px";
    abStyle.height   = h + "px";
    var sTop = body.scrollTop;
    var cHeight = body.clientHeight;
    if(detectDoctype()) {
      sTop = document.documentElement.scrollTop;
      cHeight = document.documentElement.clientHeight;
    }
    abStyle.top      = (parseInt((cHeight - parseInt(abStyle.height)) / 2) + sTop) + "px";
    abStyle.left     = (parseInt((body.clientWidth - parseInt(abStyle.width)) / 2) + (body.scrollLeft || document.documentElement.scrollLeft)) + "px";

    iframeStyle.position = "absolute";
    iframeStyle.width    = abStyle.width;
    iframeStyle.height   = abStyle.height;
    iframeStyle.top      = abStyle.top;
    iframeStyle.left     = abStyle.left;

    iframeStyle.display = "inline";
    abStyle.display = "inline";
    if(this.options.showFilter) {
      AlertBox.filter.style.display = "inline";
    }
    if(AlertBox.keyDown) {
      Event.stopObserving(this.ref.document, "keydown", AlertBox.keyDown);
    }
    AlertBox.keyDown = this.keyDownListener.bindAsEventListener(this);
    Event.observe(this.ref.document, "keydown", AlertBox.keyDown);
  },

  loadCss: function() {
    if(this.cssArqName == "" || top.getObj(this.cssArqName, this.ref) != null) return false;

    var doc = this.ref.document;
    var head = doc.getElementsByTagName("head").item(0);
    var css = doc.createElement("link");

    if(this.cssArqName.indexOf(".css") == -1) {
      this.cssArqName += ".css";
    }

    css.setAttribute("href", "../_scripts/_alertbox/css/" + this.cssArqName);
    css.setAttribute("id", this.cssArqName);
    css.setAttribute("type", "text/css");
    css.setAttribute("rel", "stylesheet");
    head.appendChild(css);
  },

  setInitHTML: function() {
    if(top.getObj("ab" + this.id, this.ref)) return;
    var doc = this.ref.document;
    this.init();

    if(!top.getObj("abFilter", this.ref)) {
      var filter = AlertBox.filter = doc.createElement("div");
      filter.id = "abFilter";
      filter.className = "div_abFilter";
      doc.body.appendChild(filter);
    }

    this.iframe = doc.createElement("iframe");
    this.iframe.setAttribute("frameborder", "0");
    this.iframe.setAttribute("border", "0");
    this.iframe.setAttribute("src", "view/branco.htm");
    this.iframe.style.cssText = "top:0px; left:0px; position:absolute; display:none; width:0px; height:0px; z-index:" + (this.options.zIndex - 1) + "; border:0px;";
    doc.body.appendChild(this.iframe);

    this.ab = doc.createElement("div");
    this.ab.id = "ab" + this.id;
    this.ab.className = "div_alertBox";
    this.ab.style.cssText = "top:0px; left:0px; position:absolute; display:none; width:0px; height:0px; z-index:" + this.options.zIndex + ";";
    doc.body.appendChild(this.ab);
    this.ab.innerHTML = this.abHTML;

    var fc = this.ab.firstChild;
    if(fc) {
      fc.style.position = "absolute";
      fc.style.top = "0px";
      fc.style.left = "0px";
    }
    if(this.initAfter) {
      this.initAfter();
    }
  },
  
  closeAlert: function() {
    if(top.getObj("ab" + this.id, this.ref)) {
      this.ab.style.display = "none";
      this.iframe.style.display = "none";
      for(var i = 0; i < AlertBox.actives.length; i++) {
        if(AlertBox.actives[i].id == this.id || (!top.getObj("ab" + AlertBox.actives[i].id, this.ref))) {
          AlertBox.actives.moveBack(i);
          i--;
        }
      }
      if(AlertBox.actives.length == 0) {
        AlertBox.filter.style.display = "none";
        Event.stopObserving(this.ref.document, "keydown", AlertBox.keyDown);
        AlertBox.keyDown = null;
      } else {
        AlertBox.keyDown = AlertBox.actives[AlertBox.actives.length - 1].keyDownListener.bindAsEventListener(this);
        Event.observe(this.ref.document, "keydown", AlertBox.keyDown);
      }
      return true;
    }
    return false;
  },
  
  keyDownListener: function(e) {
    var charCode = "k" + ((e.charCode) ? e.charCode : ((e.keyCode) ? e.keyCode : ((e.which) ? e.which : 0)));
    var ctrlShift = "CTRL" + e.ctrlKey + "SHIFT" + e.shiftKey;
    if(ctrlShift == "CTRLfalseSHIFTfalse" && this.options.keys[charCode]) {
      this.options.keys[charCode](this);
      Event.stop(e);
    } else if(this.options.keys[ctrlShift] && this.options.keys[ctrlShift][charCode]) {
      this.options.keys[ctrlShift][charCode](this);
      Event.stop(e);
    }
  },
  
  activateAlertBox: function(e) {
    this.deltaX = e.clientX - parseInt(this.ab.style.left);
    this.deltaY = e.clientY - parseInt(this.ab.style.top);

    this.bmove = this.moveAlertBox.bindAsEventListener(this);
    this.bdeactivate = this.deactivateAlertBox.bindAsEventListener(this);

    Event.observe(this.ref.document, "mousemove", this.bmove);
    Event.observe(this.ref.document, "mouseup", this.bdeactivate);
    this.ref.document.onselectstart = function() {return false;}
    this.onMouseDown = this.ref.document.onmousedown;
    this.ref.document.onmousedown = function() {return false;}
  },

  deactivateAlertBox: function(e) {
   	try {
        if(document.all){
          this.ab.style.filter = 'alpha(opacity=100)';
          this.iframe.style.filter = 'alpha(opacity=100)';
        }else{
          this.ab.style.MozOpacity=1;
          this.iframe.style.MozOpacity=1;
        }
        Event.stopObserving(this.ref.document, "mousemove", this.bmove);
        Event.stopObserving(this.ref.document, "mouseup", this.bdeactivate);
        this.ref.document.onselectstart = null;
        this.ref.document.onmousedown = this.onMouseDown;
   	} catch(e) {
   		return false;
   	}
  },

  moveAlertBox: function(e) {
    var ableft, abtop;

      try {
        if(document.all){
          this.ab.style.filter = 'alpha(opacity=60)';
          this.iframe.style.filter = 'alpha(opacity=0)';
        }else{
          this.ab.style.MozOpacity=0.6;
          this.iframe.style.MozOpacity=0;
        }

        if((e.clientX - this.deltaX - this.ref.document.body.scrollLeft) < 0) {
          ableft = 0 + this.ref.document.body.scrollLeft + "px";
        } else {
          ableft = (e.clientX - this.deltaX) + "px";
        }

        this.ab.style.left = ableft;
        this.iframe.style.left = this.ab.style.left;
  
        if((e.clientY - this.deltaY - this.ref.document.body.scrollTop) < 0) {
          abtop = 0 + this.ref.document.body.scrollTop + "px";
        } else {
          abtop = (e.clientY - this.deltaY) + "px";
        }

        this.ab.style.top = abtop;
        this.iframe.style.top = this.ab.style.top;
      } catch(e) {
        return false;
      }
  }
}
AlertBox.actives = [];

AlertBox.Alert = {};
Object.extend(Object.extend(AlertBox.Alert, AlertBox), {
  id: "alert",
  cssArqName: "DefaultBlue",
  defaultOptions: Object.extend(Object.clone(AlertBox.defaultOptions), {
    keys: {
      k13: function(o) {o.closeAlert();}, //Enter/Return key
      k27: function(o) {o.closeAlert();}  //ESC key
    }
  }),
  init: function() {
    this.abHTML = "<table cellpadding='0' cellspacing='0' class='table_alertBox'>"+
                  "<tr>"+
                  "<td class='td_alertBoxTopEsq'>&nbsp;</td><td class='td_alertBoxTitle' onmousedown='top.AlertBox.Alert.activateAlertBox(event);'><div id='alertBoxTitle" + this.id + "'>&nbsp;</div><div class='div_closeX' onclick='top.closealertbox()'></div></td><td class='td_alertBoxTopDir'>&nbsp;</td>"+
                  "</tr>"+
                  "<tr>"+
                  "<td class='td_alertBoxEsq'>&nbsp;</td><td class='td_alertBox'>"+
                  "<table cellpadding='0' cellspacing='0' class='table_alertBoxMsg'>"+
                  "<tr>"+
                  "<td class='td_alertBoxMsg'>"+
                  "<div id='alertBoxMsg" + this.id + "' class='div_alertBoxMsg'>&nbsp;</div>"+
                  "</td>"+
                  "</tr>"+
                  "<tr>"+
                  "<td class='td_alertBoxButton'>"+
                  "<input id='alertBoxButton" + this.id + "' type='button' name='alertBoxButton' value='&nbsp;&nbsp;&nbsp;OK&nbsp;&nbsp;&nbsp;' onclick='top.closealertbox();' class='input_alertBoxButton'>"+
                  "</td>"+
                  "</tr>"+
                  "</table>"+
                  "</td><td class='td_alertBoxDir'>&nbsp;</td>"+
                  "</tr>"+
                  "<tr><td class='td_alertBoxBaseEsq'>&nbsp;</td><td class='td_alertBoxBase'>&nbsp;</td><td class='td_alertBoxBaseDir'>&nbsp;</td></tr>"+
                  "</table>";
  }
});
function alertbox(msg, options) {
  AlertBox.Alert.configAlert(msg, options);
}
function closealertbox() {
  AlertBox.Alert.closeAlert();
}

AlertBox.Message = {};
Object.extend(Object.extend(AlertBox.Message, AlertBox), {
  id: "message",
  cssArqName: "DefaultBlue",
  defaultOptions: Object.extend(Object.clone(AlertBox.defaultOptions), {zIndex: 2000, msgClassName:"td_messageBoxMsg"}),
  init: function() {
    this.abHTML = "<table cellpadding='0' cellspacing='0' class='table_messageBox'>"+
                  "<tr>"+
                  "<td class='td_messageBox'>"+
                  "<table cellpadding='0' cellspacing='0' class='table_messageBoxMsg'>"+
                  "<tr>"+
                  "<td id='alertBoxMsg" + this.id + "' class='td_messageBoxMsg'>&nbsp;</td>"+
                  "</tr>"+
                  "</table>"+
                  "</td>"+
                  "</tr>"+
                  "</table>";
  }
});

function messagebox(msg, options) {
  AlertBox.Message.configAlert(msg, options);
}
function closemessagebox() {
  AlertBox.Message.closeAlert();
}

AlertBox.Prompt = {};
Object.extend(Object.extend(AlertBox.Prompt, AlertBox), {
  id: "prompt",
  cssArqName: "DefaultBlue",
  defaultOptions: Object.extend(Object.clone(AlertBox.defaultOptions), {
    func: function(s){return s;},
    keys: {
      k13: function(o) {o.closeOk();}, //Enter/Return key
      k27: function(o) {o.closeAlert();} //ESC key
    }
  }),
  minW: 170,
  init: function() {
    this.abHTML = "<table cellpadding='0' cellspacing='0' class='table_alertBox'>"+
                  "<tr>"+
                  "<td class='td_alertBoxTopEsq'>&nbsp;</td><td class='td_alertBoxTitle' onmousedown='top.AlertBox.Prompt.activateAlertBox(event);'><div id='alertBoxTitle" + this.id + "'>&nbsp;</div><div class='div_closeX' onclick='top.closepromptbox()'></div></td><td class='td_alertBoxTopDir'>&nbsp;</td>"+
                  "</tr>"+
                  "<tr>"+
                  "<td class='td_alertBoxEsq'>&nbsp;</td><td class='td_alertBox'>"+
                  "<table cellpadding='0' cellspacing='0' class='table_alertBoxMsg'>"+
                  "<tr>"+
                  "<td class='td_alertBoxMsg'>"+
                  "<div id='alertBoxMsg" + this.id + "' class='div_alertBoxMsg'>&nbsp;</div>"+
                  "</td>"+
                  "</tr>"+
                  "<tr>"+
                  "<td class='td_promptBoxTxt' id='td_promptTxt'>"+
                  "<input type='text' id='promptTxt' class='input_promptBoxTxt' size='20' maxlength='5'>"+
                  "</td>"+
                  "</tr>"+
                  "<tr>"+
                  "<td class='td_alertBoxButton'>"+
                  "<input id='alertBoxButton' type='button' name='alertBoxButtonOk' value='&nbsp;&nbsp;&nbsp;OK&nbsp;&nbsp;&nbsp;' onclick='top.AlertBox.Prompt.closeOk();' class='input_alertBoxButton'>"+
                  "<input id='alertBoxButton' type='button' name='alertBoxButtonCancel' value='&nbsp;&nbsp;&nbsp;CANCEL&nbsp;&nbsp;&nbsp;' onclick='top.AlertBox.Prompt.closeAlert();' class='input_alertBoxButton'>"+
                  "</td>"+
                  "</tr>"+
                  "</table>"+
                  "</td><td class='td_alertBoxDir'>&nbsp;</td>"+
                  "</tr>"+
                  "<tr><td class='td_alertBoxBaseEsq'>&nbsp;</td><td class='td_alertBoxBase'>&nbsp;</td><td class='td_alertBoxBaseDir'>&nbsp;</td></tr>"+
                  "</table>";
  },
  
  alertAfter: function(msg) {
    var campo = $(top.getObj("promptTxt", this.ref));

    while(campo.nextSibling) {
      campo.parentNode.removeChild(campo.nextSibling);
    }

    campo.value = "";
    campo.removeAttribute("maxLength");
    if(this.options.maxlength) {
      campo.setAttribute("maxLength", this.options.maxlength);
      $(campo).insert({after: "<br>máximo de " + this.options.maxlength  + " caracteres"})
    }
  },

  closeOk: function() {
    if(this.closeAlert()) {
      var value = top.getObj("promptTxt", this.ref).value;
      if(this.options.maxlength && value.length > this.options.maxlength) {
        alertbox("Por favor, preencha com no máximo " + this.options.maxlength + "caracteres.");
      } else {
        this.options.func(value);
      }
    }
  }
});

function promptbox(msg, options) {
  AlertBox.Prompt.configAlert(msg, options);
}
function closepromptbox() {
  AlertBox.Prompt.closeAlert();
}

AlertBox.Confirm = {};
Object.extend(Object.extend(AlertBox.Confirm, AlertBox), {
  id: "confirm",
  cssArqName: "DefaultBlue",
  defaultOptions: Object.extend(Object.clone(AlertBox.defaultOptions), {
    func: function(s){return s;},
    keys: {
      k13: function(o) {o.closeConfirm(true);}, //Enter/Return key
      k27: function(o) {o.closeConfirm(false);} //ESC key
    }
  }),
  minW: 170,
  init: function() {
    this.abHTML = "<table cellpadding='0' cellspacing='0' class='table_alertBox'>"+
                  "<tr>"+
                  "<td class='td_alertBoxTopEsq'>&nbsp;</td><td class='td_alertBoxTitle' onmousedown='top.AlertBox.Confirm.activateAlertBox(event);'><div id='alertBoxTitle" + this.id + "'>&nbsp;</div><div class='div_closeX' onclick='top.closeconfirmbox()'></div></td><td class='td_alertBoxTopDir'>&nbsp;</td>"+
                  "</tr>"+
                  "<tr>"+
                  "<td class='td_alertBoxEsq'>&nbsp;</td><td class='td_alertBox'>"+
                  "<table cellpadding='0' cellspacing='0' class='table_alertBoxMsg'>"+
                  "<tr>"+
                  "<td class='td_alertBoxMsg'>"+
                  "<div id='alertBoxMsg" + this.id + "' class='div_alertBoxMsg'>&nbsp;</div>"+
                  "</td>"+
                  "</tr>"+
                  "<tr>"+
                  "<td class='td_alertBoxButton'>"+
                  "<input id='alertBoxButton' type='button' name='alertBoxButtonOk' value='&nbsp;&nbsp;&nbsp;OK&nbsp;&nbsp;&nbsp;' onclick='top.closeconfirmbox(true);' class='input_alertBoxButton'>"+
                  "<input id='alertBoxButton' type='button' name='alertBoxButtonCancel' value='&nbsp;&nbsp;&nbsp;CANCEL&nbsp;&nbsp;&nbsp;' onclick='top.closeconfirmbox(false);' class='input_alertBoxButton'>"+
                  "</td>"+
                  "</tr>"+
                  "</table>"+
                  "</td><td class='td_alertBoxDir'>&nbsp;</td>"+
                  "</tr>"+
                  "<tr><td class='td_alertBoxBaseEsq'>&nbsp;</td><td class='td_alertBoxBase'>&nbsp;</td><td class='td_alertBoxBaseDir'>&nbsp;</td></tr>"+
                  "</table>";
  },
  
  closeConfirm: function(resp) {
    if(this.closeAlert() && resp != undefined) {
      this.options.func(resp);
    }
  }
});
function confirmbox(msg, options) {
  AlertBox.Confirm.configAlert(msg, options);
}
function closeconfirmbox(resp) {
  AlertBox.Confirm.closeConfirm(resp);
}

AlertBox.Action = {};
Object.extend(Object.extend(AlertBox.Action, AlertBox), {
  id: "action",
  cssArqName: "DefaultBlue",
  defaultOptions: Object.extend(Object.clone(AlertBox.defaultOptions), {
    buttons: [{value: "FECHAR", name: "alertBoxButton", onclick: function() {top.closeactionbox();}, className:"input_alertBoxButton"}]
  }),
  init: function() {
    this.abHTML = "<table cellpadding='0' cellspacing='0' class='table_alertBox'>"+
                  "<tr>"+
                  "<td class='td_alertBoxTopEsq'>&nbsp;</td><td class='td_alertBoxTitle' onmousedown='top.AlertBox.Action.activateAlertBox(event);'><div id='alertBoxTitle" + this.id + "'>&nbsp;</div><div class='div_closeX' onclick='top.closeactionbox()'></div></td><td class='td_alertBoxTopDir'>&nbsp;</td>"+
                  "</tr>"+
                  "<tr>"+
                  "<td class='td_alertBoxEsq'>&nbsp;</td><td class='td_alertBox'>"+
                  "<table cellpadding='0' cellspacing='0' class='table_alertBoxMsg'>"+
                  "<tr>"+
                  "<td class='td_alertBoxMsg'>"+
                  "<div id='alertBoxMsg" + this.id + "' class='div_alertBoxMsg'>&nbsp;</div>"+
                  "</td>"+
                  "</tr>"+
                  "<tr>"+
                  "<td class='td_alertBoxButton' id='alertBoxButtons" + this.id + "'>"+
                  "</td>"+
                  "</tr>"+
                  "</table>"+
                  "</td><td class='td_alertBoxDir'>&nbsp;</td>"+
                  "</tr>"+
                  "<tr><td class='td_alertBoxBaseEsq'>&nbsp;</td><td class='td_alertBoxBase'>&nbsp;</td><td class='td_alertBoxBaseDir'>&nbsp;</td></tr>"+
                  "</table>";
  },

  alertAfter: function(msg) {
    var ret = "";
    var bts = this.options.buttons;
    var bt;
    var abBts = top.getObj("alertBoxButtons" + this.id, this.ref);

    abBts.innerHTML = "";
    for(var i = 0; i < bts.length; i++) {
      bt = this.ref.document.createElement("input");
      bt.type = (bts[i].src) ? "image" : "button";
      bt.style.cssText += "; margin: 0px 2px; border:0px;";
      for(var attr in bts[i]) {
        bt[attr] = bts[i][attr];
      }
      abBts.appendChild(bt);
    }
  }
});
function actionbox(msg, options) {
  AlertBox.Action.configAlert(msg, options);
}
function closeactionbox() {
  AlertBox.Action.closeAlert();
}

AlertBox.Notify = {};
Object.extend(Object.extend(AlertBox.Notify, AlertBox), {
  id: "notify",
  cssArqName: "DefaultBlue",
  defaultOptions: Object.extend(Object.clone(AlertBox.defaultOptions), {timeout: 5000, className: "", style: "", showFilter:false}),
  msgCount: 0,
  init: function() {
    this.abHTML = "";
  },
  
  initAfter: function() {
    this.ab.className = "div_notifyBox";

    this.ab.style.cssText = "right:0px; bottom:0px; position:absolute; display:none; z-index:" + this.options.zIndex + "; border:0px;";
    this.ab.style.display = "inline";
    this.iframe.style.display = "none";
  },

  alert: function(msg) {
    var style = timeoutMsg = className = "";

    //Recupera as opções já herdadas do default mescladas com as opções passadas por parâmetro

    this.msgCount++;
    timeoutMsg = this.TIMEOUT_MSG;

    if(this.options.icon) {
      msg = "<img src='" + this.options.icon + "' border='0' align='left'> " + msg;
    }

    var div = this.ref.document.createElement("div");
    div.id = "ab" + this.id + this.msgCount;
    div.className = this.options.className;
    div.style.cssTex = this.options.style;
    div.innerHTML = msg;
    if(this.ab.firstChild) {
      this.ab.insertBefore(div, this.ab.firstChild);
    } else {
      this.ab.appendChild(div);
    }

    setTimeout("AlertBox.Notify.closeAlert(" + this.msgCount + ")", this.options.timeout);
  },

  closeAlert: function(msgCount) {
    var notifyMsg;
    if(!msgCount) {
      notifyMsg = top.getObj("ab" + this.id, this.ref).firstChild;
    } else {
      notifyMsg = top.getObj("ab" + this.id + msgCount, this.ref);
    }
    if(notifyMsg) {
      this.ab.removeChild(notifyMsg);
    }
  }
});

function notifybox(msg, options) {
  AlertBox.Notify.configAlert(msg, options);
}

function closenotifybox(msgCount) {
  AlertBox.Notify.closeAlert(msgCount);
}

function docTypeInfo()
{
  this.xhtml="";
  this.version="";
  this.importance="";
  this.dtd="";
}

function detectDTD(){
  //Detect DTD
  var re=/\/+(\w+\-?\w+\.dtd)/gi;
  /*********************************************
  Just check for internet explorer.
  **********************************************/

  if(typeof document.namespaces != "undefined"){
    if(document.all[0].nodeType==8 && re.test(document.all[0].text))
      re.exec(document.all[0].text);
    else
      return null;
  }else{
    if(document.doctype != null && document.doctype.systemId != "")
      re.exec(document.doctype.systemId);
    else
      return null;
  }

  return RegExp.$1;
}

function detectDoctype(){
  var re=/\s+(X?HTML)\s+([\d\.]+)\s*([^\/]+)*\//gi;
  var iDocTypeInfo=new docTypeInfo();

  if(typeof document.namespaces != "undefined"){
    if(document.all[0].nodeType==8)
      re.exec(document.all[0].nodeValue);
    else
      return null;
  }else{
    if(document.doctype != null)
      re.exec(document.doctype.publicId);
    else
      return null;
  }
  iDocTypeInfo.xhtml=RegExp.$1;
  iDocTypeInfo.version=RegExp.$2;
  iDocTypeInfo.importance=RegExp.$3;
  iDocTypeInfo.dtd=detectDTD();
  return iDocTypeInfo;
}
