/**
 * jt_AppDialogs.js - extends jt_DialogBox.js with 3 specific types of dialog boxes,
 * based on JavaScript equivalents: 'jt_AppAlert', 'jt_AppConfirm' and 'jt_AppPrompt'
 *
 * @version 9 Apr 2005
 * @author  Joseph Oster, wingo.com, Copyright (c) 2005-2006
 */

jt_AppAlert = function(icon) {
  // CONSTRUCTOR for 'jt_AppAlert' object - EXTENDS 'jt_DialogBox'
  if (arguments.length==0) return;
  this.base = jt_DialogBox;
  this.base(true);

  var dialogTable = document.createElement('table');
  dialogTable.setAttribute('cellSpacing', '0');
  dialogTable.setAttribute('cellPadding', '0');
  dialogTable.setAttribute('border', '0');

  var tBody = document.createElement('tbody');
  var row = document.createElement('tr');
  var cell = document.createElement('td');
  cell.setAttribute("vAlign", "top");

  this.iconImage = document.createElement('img');
  this.iconImage.style.margin = "0px 10px 0px 0px";
  this.setIcon(icon);
  cell.appendChild(this.iconImage);
  row.appendChild(cell);

  this.contentCell = document.createElement('td');
  this.contentCell.className = "ContentArea";
  row.appendChild(this.contentCell);
  tBody.appendChild(row);
  dialogTable.appendChild(tBody);
  this.contentArea.appendChild(dialogTable);

  this.buttonDIV = document.createElement('div');
  this.buttonDIV.setAttribute("align", "center");
  this.buttonDIV.style.margin = "10px 0px 0px 0px";
  this.contentArea.appendChild(this.buttonDIV);
  
  //jt_AppAlert.addButton(this, jt_AppAlert.lblOK, 1);
}

jt_AppAlert.prototype = new jt_DialogBox();


/************ BEGIN: 'jt_AppAlert' Public Methods ************/
jt_AppAlert.Warning = "ico_warning.gif"; // 'icon' param to 'jt_AppAlert' constructor
jt_AppAlert.Error = "ico_error.gif";     // 'icon' param to 'jt_AppAlert' constructor
jt_AppAlert.Info = "ico_info.gif";       // 'icon' param to 'jt_AppAlert' constructor
jt_AppAlert.Question = "ico_question.gif";       // 'icon' param to 'jt_AppAlert' constructor

jt_AppAlert.btnYes = 1;
jt_AppAlert.btnNo = 2;
jt_AppAlert.btnCancel = 3;


jt_AppAlert.prototype.setContent = function(htmlContent) {
  this.contentCell.innerHTML = htmlContent;
}

jt_AppAlert.prototype.setIcon = function(icon) {
  this.iconImage.src = jt_DialogBox.imagePath + icon;
}
/************ END: 'jt_AppAlert' Public Methods ************/


jt_AppYesNoCancel = function(icon, callYes, callNo, callCancel) {
  // CONSTRUCTOR for 'jt_AppYesNoCancel' object - EXTENDS 'jt_AppAlert'
  if (arguments.length==0) return;
  this.base = jt_AppAlert;
  this.base(icon);
  this.callYes = callYes;
  this.callNo = callNo;
  this.callCancel = callCancel;
  
  jt_AppAlert.addButton(this, jt_AppAlert.lblYes, 1);
  jt_AppAlert.addButton(this, jt_AppAlert.lblNo, 2);
  jt_AppAlert.addButton(this, jt_AppAlert.lblCancel, 3);
}

jt_AppYesNoCancel.prototype = new jt_AppAlert();

/************ BEGIN: 'jt_AppYesNoCancel' Public Methods ************/
jt_AppYesNoCancel.prototype.askUser = function(htmlContent) {
  this.setContent(htmlContent);
  this.show();
}
/************ END: 'jt_AppYesNoCancel' Public Methods ************/





/************ BEGIN: 'jt_AppAlert' Private Methods ************/
jt_AppAlert.addButton = function(parent, buttonText, buttonNum) {
  var button = document.createElement("button");
  button.style.fontSize = "10pt";
  button.style.width = "60px";
  button.style.margin = "0px 5px";
  button.innerHTML = buttonText;
  button.linkNum = buttonNum;
  button.appDialog = parent;
  button.onclick = jt_AppAlert.clickLink;
  parent.buttonDIV.appendChild(button);
}

jt_AppAlert.clickLink = function(e) {
  if (!e) e = window.event;
  var node = e.target ? e.target : e.srcElement;
  var linkNum = node.linkNum;
  var count = 0;
  while ((node != null) && (count < jt_DialogBox.maxDepth)) {
    if (node.appDialog) {
      node.appDialog.hide(linkNum);
      return false;
    }
    node = node.parentNode;
    count++;
  }
  return false;
}

jt_AppAlert.keyPress = function(e) {
  if (!e) e = window.event;
  var node = e.target ? e.target : e.srcElement;
  var key = e.keyCode ? e.keyCode : e.which;
  if (key == 13) node.appDialog.hide(1); // Yes Button
  if (key == 27) node.appDialog.hide(3); // Cancel Button
}

jt_AppAlert.prototype.trace = function() {
  alert(objToString(this.contentArea));
}

