//=======================================================================
//  Unit:  HTML Application (HTA) support
//=======================================================================
// [Purpose]
//  --  simplify HTA usage
// [Units]
// [Objects]
//  --  DOM\window
//  --  DOM\document
// [Files]
// [Notes]
//  --  assumes main HTA function is named "htaMain"
//  --  designed to load base document first before any operations
//      to allow title to be updated on window/taskbar
//=======================================================================

//=======================================================================
//======  Constants  ====================================================
//=======================================================================
var htamainfunc    = 'htaMain';
var htaid          = 'oHTA';

var SINGLEINSTANCE = true;

//=======================================================================
function htaCommandLineParameters() {
//=======================================================================
  var s = oHTA.commandLine;
  var p = 0;
  if (s.charAt(0) == '\"') p = s.indexOf('\"', 1);
  p = s.indexOf(' ', p) + 1;
  return s.substring(p);
}

//=======================================================================
function htaCommandLineParameterArray() { //{T} consider quote support
//=======================================================================
  var s = htaCommandLineParameters();
  var a = s.split(' ');
  return a;
}

//=======================================================================
function htaAppend(shtml) {
//=======================================================================
  document.body.innerHTML += shtml;
}

//=======================================================================
function htaPrep(icon, singleinstance, windowstate, lft, top, wid, hgt) {
//=======================================================================
  var s = '';

  if ((lft + '') != 'undefined') {
    window.moveTo(lft, top);
    if ((wid + '') != 'undefined') window.resizeTo(wid, hgt);
    windowstate = 'normal';
  }
                       s += '<HTA:APPLICATION';
                       s += ' id="' + htaid + '\"';
                       s += ' applicationname="' + document.title + '\"';
  if (icon)            s += ' icon="' + icon + '\"';
  if (singleinstance)  s += ' singleinstance="yes"';
  if (windowstate)     s += ' windowstate="' + windowstate + '\"';
                       s += '>';
  document.writeln(s);
}

//=======================================================================
function htaBody(icon, singleinstance, windowstate, lft, top, wid, hgt) {
//=======================================================================
  htaPrep(icon, singleinstance, windowstate, lft, top, wid, hgt);
  document.writeln('<BODY onload="' + htamainfunc + '()"></BODY>');
}

