top.importt("js.alertbox.AlertBox");

top.PromptBox = function PromptBox() {

  this.id = "prompt";
  this.buttonPath  = "";
  this.cssArqName  = "DefaultMetroRio";
  this.txtRet = null;
  this.fn = function(){};

  this.alertBoxHTML = "";
  this.alertBoxHTML += "<table cellpadding='0' cellspacing='0' class='table_alertBox'>";
  this.alertBoxHTML += "<tr>";
  this.alertBoxHTML += "<td id='alertBoxTitle" + this.id + "' class='td_alertBoxTitle' onmousedown='top.activatePromptBox(event);'>&nbsp;</td>";
  this.alertBoxHTML += "</tr>";
  this.alertBoxHTML += "<tr>";
  this.alertBoxHTML += "<td class='td_alertBox'>";
  this.alertBoxHTML += "<table cellpadding='0' cellspacing='0' class='table_alertBoxMsg'>";
  this.alertBoxHTML += "<tr>";
  this.alertBoxHTML += "<td class='td_alertBoxMsg'>";
  this.alertBoxHTML += "<div id='alertBoxMsg" + this.id + "' class='div_alertBoxMsg'>&nbsp;</div>";
  this.alertBoxHTML += "</td>";
  this.alertBoxHTML += "</tr>";
  this.alertBoxHTML += "<tr>";
  this.alertBoxHTML += "<td class='td_promptBoxTxt'>";
  this.alertBoxHTML += "<input type='text' id='promptTxt' class='input_promptBoxTxt' size='40'>";
  this.alertBoxHTML += "</td>";
  this.alertBoxHTML += "</tr>";
  this.alertBoxHTML += "<tr>";
  this.alertBoxHTML += "<td class='td_alertBoxButton'>";
  if(this.buttonPath == "") {
    this.alertBoxHTML += "<input id='alertBoxButton' type='button' name='alertBoxButton' value='&nbsp;&nbsp;&nbsp;OK&nbsp;&nbsp;&nbsp;' onclick='top.closePromptBox();' class='input_alertBoxButton'>"
  } else {
    this.alertBoxHTML += "<img id='alertBoxButton' src='" + this.buttonPath + "' onclick='top.closePromptBox();'>"
  }
  this.alertBoxHTML += "</td>";
  this.alertBoxHTML += "</tr>";
  this.alertBoxHTML += "</table>";
  this.alertBoxHTML += "</td>";
  this.alertBoxHTML += "</tr>";
  this.alertBoxHTML += "</table>";

  this.prompt = function(msg, title, fn) {
    if(!title) return;
    if(!fn) {
      this.fn = title;
      this.alert(msg);
    } else {
      this.fn = fn;
      this.alert(msg, title);
    }
  }

  this.closePrompt = function() {
    this.closeAlert();
    this.fn(top.getObj("promptTxt", this.ref).value);
  }
}
top.PromptBox.prototype.extendss("AlertBox");
top.PromptBox.instance = null;
top.PromptBox.getInstance = function() {
  if(this.instance == null) {
    this.instance = new top.PromptBox();
  }
  return this.instance;
}

top.promptbox = function promptbox(msg, title, retVar, fn) {
  top.PromptBox.getInstance().prompt(msg, title, retVar, fn);
}
top.activatePromptBox = function (e) {
  top.PromptBox.getInstance().activateAlertBox(e);
}
top.closePromptBox = function() {
  top.PromptBox.getInstance().closePrompt();
}
