/**
 * iosAppDialogs.js - extends iosDialogBox.js with 3 specific types of dialog boxes,
 * based on JavaScript equivalents: 'iosAppAlert', 'iosAppConfirm' and 'iosAppPrompt'
 *
 * @version 9 Apr 2005
 * @author  Joseph Oster, wingo.com, Copyright (c) 2005-2006
 * @license http://www.wingo.com/dialogbox/license.html
 */

iosAppAlert = function(icon) {
  // CONSTRUCTOR for 'iosAppAlert' object - EXTENDS 'iosDialogBox'
  if (arguments.length==0) return;
  this.base = iosDialogBox;
  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);
  iosAppAlert.addButton(this, iosAppAlert.lblOK, 1);
  }

iosAppAlert.prototype = new iosDialogBox();


/************ BEGIN: 'iosAppAlert' Public Methods ************/
iosAppAlert.Warning = "icons/warning.gif"; // 'icon' param to 'iosAppAlert' constructor
iosAppAlert.Error = "icons/error.gif";     // 'icon' param to 'iosAppAlert' constructor
iosAppAlert.Info = "icons/info.gif";       // 'icon' param to 'iosAppAlert' constructor
iosAppAlert.lblOK = "OK"; // label for "OK" button (for i18N)
iosAppAlert.lblCancel = "Cancel"; // label for "Cancel" button (for i18N)

iosAppAlert.prototype.setContent = function(htmlContent) {
  this.contentCell.innerHTML = htmlContent;
  }

iosAppAlert.prototype.setIcon = function(icon) {
  this.iconImage.src = iosDialogBox.imagePath + icon;
  }
/************ END: 'iosAppAlert' Public Methods ************/



iosAppConfirm = function(icon, callOK, callCancel) {
  // CONSTRUCTOR for 'iosAppConfirm' object - EXTENDS 'iosAppAlert'
  if (arguments.length==0) return;
  this.base = iosAppAlert;
  this.base(icon);
  this.callOK = callOK;
  this.callCancel = callCancel;
  iosAppAlert.addButton(this, iosAppAlert.lblCancel, 2);
  }

iosAppConfirm.prototype = new iosAppAlert();


/************ BEGIN: 'iosAppConfirm' Public Methods ************/
iosAppConfirm.prototype.askUser = function(htmlContent) {
  this.setContent(htmlContent);
  this.show();
  }
/************ END: 'iosAppConfirm' Public Methods ************/



iosAppPrompt = function(icon, callOK, callCancel, cssClass) {
  // CONSTRUCTOR for 'iosAppPrompt' object - EXTENDS 'iosAppConfirm'
  if (arguments.length==0) return;
  this.base = iosAppConfirm;
  this.base(icon, callOK, callCancel);
  this.returnData = new Object();
  this.fInput = document.createElement('input');
  this.fInput.type = "text";
  if (cssClass) this.fInput.className = cssClass;
  this.fInput.appDialog = this;
  this.fInput.onkeypress = iosAppPrompt.keyPress;
  }

iosAppPrompt.prototype = new iosAppConfirm();
iosAppPrompt.superClass = iosAppConfirm.prototype;


/************ BEGIN: 'iosAppPrompt' Public Methods ************/
iosAppPrompt.prototype.askUser = function(htmlContent, stDefault) {
  this.setContent(htmlContent);
  this.fInput.value = stDefault;
  this.contentCell.appendChild(this.fInput);
  this.show();
  this.fInput.focus();
  }

iosAppPrompt.prototype.focus = function() {
  this.fInput.focus();
  }

iosAppPrompt.prototype.hide = function(ok) {
  if (ok) this.returnData.value = this.fInput.value;
  iosAppPrompt.superClass.hide.call(this, ok);
  }
/************ END: 'iosAppPrompt' Public Methods ************/



/************ BEGIN: 'iosAppAlert' Private Methods ************/
iosAppAlert.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 = iosAppAlert.clickLink;
  parent.buttonDIV.appendChild(button);
  }

iosAppAlert.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 < iosDialogBox.maxDepth)) {
    if (node.appDialog) {
      switch (linkNum) {
        case 1: {
          node.appDialog.hide(true);
          break;
          }
        case 2: {
          node.appDialog.hide();
          break;
          }
        }
      return false;
      }
    node = node.parentNode;
    count++;
    }
  return false;
  }

iosAppPrompt.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(true);
  if (key == 27) node.appDialog.hide();
  }

iosAppAlert.prototype.trace = function() {
  alert(objToString(this.contentArea));
  }