<!--

var spFolderDesktop = "";
var spFolderMyDocuments = "";
var spFolderPrograms = "";
var spFolderWinDir = "";
var spFolderSystem32 = "";
var spFolderTemp = "";
var spFolderHomePath = "";
var spPATH = "";

function setSpecialFolders () {
  spFolderDesktop = oWsh.SpecialFolders("Desktop");
  spFolderMyDocuments = oWsh.SpecialFolders("MyDocuments");
  spFolderPrograms = oWsh.SpecialFolders("Programs");
  spFolderWinDir = oWsh.ExpandEnvironmentStrings("%WinDir%");
  spFolderTemp = oWsh.ExpandEnvironmentStrings("%Temp%");
  spFolderHomeDrive = oWsh.ExpandEnvironmentStrings("%HomeDrive%");
  spFolderHomePath = oWsh.ExpandEnvironmentStrings("%HomePath%");
  spFolderHomePath = spFolderHomeDrive + spFolderHomePath;
  spPATH = oWsh.ExpandEnvironmentStrings("%PATH%");
  spFolderSystem32 = spFolderWinDir + "\\system32";
}

function showSpecialFolders () {
  alert (
    "spFolderDesktop is " + spFolderDesktop + "\n" + 
    "spFolderMyDocuments is " + spFolderMyDocuments + "\n" +
    "spFolderPrograms is " + spFolderPrograms + "\n" +
    "spFolderWinDir is " + spFolderWinDir + "\n" +
    "spFolderTemp is " + spFolderTemp + "\n" +
    "spFolderHomePath is " + spFolderHomePath + "\n" +
    "spFolderSystem32 is " + spFolderSystem32 + "\n" +
    "spPATH is " + spPATH + "\n" +
    "-- end --"
  );
}

//opts Eg: toolbar=0,location=0,status=1,scrollbars=1
//menubar=0,directories=0,resizable=1, 
function openWin (html,w,h,x,y,opts) {
  var winopts = "";
  if (opts) winopts += "," + opts;
  var wh = window.open ("","wh",winopts);
  if (x & y) wh.moveTo (x,y);
  if (w & h) wh.resizeTo (w,h);
  if (html) wh.document.write (html);
  return wh;
}

var popup = null;
var popupHdl = null;

function popMessage (msg) {
  var ht = "";
  ht += "<html><head>";
  ht += "<title>Message For You</title>";
  ht += "</head>";
  ht += "<body style='text-align:left'>";
  ht += "<h1>MESSAGE</h1>";
  ht += "<pre>" + msg + "</pre>";
  ht += "<button onclick=window.close()>Close</button>";
  ht += "<" + "script type=text/javascript>";
  ht += "window.setTimeout ('window.close()',300000);";
  //ht += "if (window.external) {";
  //ht += "  window.external.RemoveAboutMenuCommand();";
  //ht += "  window.external.AllowContextMenu (false);";
  //ht += "}";
  //ht += "else {";
  //ht += "  alert ('No window.external');";
  //ht += "}";  
  ht += "</" + "script>";
  ht += "</body>";
  var opts="toolbar=0,location=0,status=0,scrollbars=1,menubar=0,directories=0,resizable=1"; 
  popup = openWin (ht,420,200,120,100,opts);
  //window.setTimeout ("autoclose()",5000);
  //popup.location.href = "http://www.oracle.com/";
  //window.setTimeout ("getPopWindowHandle()",200);
}

function popupGo (url) {
  //alert ("popupGo()! url is " + url);
  popup.location.href = url;
}

// returns a string of hex digits corresponding to each char in string
function str2hex (str,spacer) {
  if (spacer==null) spacer="";
  var rtn = "";
  var hexlookup = "0123456789ABCDEF";
  var n1,n2,h;
  for (var i=0; i < str.length; i++) {
    var a = str.charCodeAt(i);
    n1 = Math.floor(a/16);
    n0 = a % 16;
    h = hexlookup.charAt(n1) + hexlookup.charAt(n0);
    rtn += h + spacer;
  }
  return rtn;
}

// hxs is string of paired-hex digits eg "FE062C"
// length of hxs MUST be EVEN
function hex2str (hxs) {
  var rtn = "";
  for (var i=0; i < hxs.length; i+=2) {
    var hex2d = "0x" + hxs.charAt(i) + hxs.charAt(i+1);
    rtn += String.fromCharCode (hex2d);	
  }	
  return rtn;
}

// do simple nibble shifting to encode/decode strings
// affects only the lowest order 6 bits to suppress "strange" characters
// due to MSBit
// previously called nibbleShifter() but renamed to n6s() to obfuscate
function n6s (str) {
  if (str=="") return "";
  var cph = "";
  for (var i=0; i < str.length; i++) {
    var a = str.charCodeAt (i);
    var t2 = a & 0x00C0;
    var es = a & 0x0015;
    var os = a & 0x002A;
    es = es << 1;
    os = os >> 1;
    var a = t2 | os | es;
    var c = String.fromCharCode (a);
    cph += c;  
  }
  return cph;
}


function winstatus (str) {
  window.status = str;
  return true;
}
	
// src: http://www.scottandrew.com/weblog/articles/cbs-events
function addEvent(obj, evType, fn, useCapture){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be attached");
  }
} 

// src: http://www.scottandrew.com/weblog/articles/cbs-events
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

// return singular or plural str depending on n
function plural (n,str1,str2) {
  var s = (n > 1)? str2 : str1;
  return s;
}

// variation of prompt: must enter something
function promptSticky (msg,defstr) {
  var tmp="";
  while (tmp=="") {
    tmp = prompt (msg,defstr);
    if (tmp==null) tmp = "";
    if (tmp=="") alert ("Input required. Please try again.");
  }
  return tmp;
}

// return string with object properties and values
function dumpObjectProperties (obj, obj_name, cr) {
   var result = "Properties of " + obj_name + cr;
   for (var i in obj) {
      result += obj_name + "." + i + " = " + obj[i] + "<BR>"
   }
   result += cr;
   return result;
} 

// caller: num = prefixZero (5,2); rtns 05
// caller: num = prefixZero (5,3); rtns 005
// p can be any value.
// If number n has width greater than p, than n is returned!
function prefixZero (n,p) {
  if ((""+n).length >= p) return n;
  zstr = "";
  for (var i=1; i<p; i++) zstr += "0";
  var m = zstr + n;
  return m.substr(m.length-p,p);    
}

// important to use this when using ajax.js to
// read in a file with single or double quotes!
/*
function addSlashes2Quotes(str) {
  str=str.replace(/\'/g,'\\\'');
  str=str.replace(/\"/g,'\\"');
  return str;
}
*/

// similar to php addslashes()
// WARNING: do NOT use this if the str has to parsed
// and the backslash character is used as a continuation character
// by your script!
function addslashes(str) {
  str=str.replace(/\'/g,'\\\'');
  str=str.replace(/\"/g,'\\"');
  str=str.replace(/\\/g,'\\\\');
  str=str.replace(/\0/g,'\\0');
  return str;
}

// similar to php stripslashes()
function stripslashes(str) {
  str=str.replace(/\\'/g,'\'');
  str=str.replace(/\\"/g,'"');
  str=str.replace(/\\\\/g,'\\');
  str=str.replace(/\\0/g,'\0');
  return str;
}

// for debugging only, allows JS to be
// aborted in the middle of a long loop
// with many alert() pop-ups
function guiAbort() {
  if (!window.confirm("Click Cancel to Abort")) error();
}

// return null string if no <script> blocks found
// all <script> blocks are consolidated!
function pluckJS (txt) {
  matches = txt.match (/<script(.|\r|\n)*?<\/script>/ig);
  if (matches == null) return "";
  var code = "";
  for (var i=0; i < matches.length; i++) code += matches[i];      
  code = code.replace (/<script .*?>/ig,"");
  code = code.replace (/<\/script>/ig,"");
  return code;
}

// getPassword ("Enter password", "width=400,height=100","cb_getpwd");
// cb_getPassword () is companion to getPassword()!
// cb_getpwd signature should be: function cb_getpwd(t)
function getPassword (prmpt, w_cfg, cb_func, x, y) {
    var wid = window.open('','pwdwin',w_cfg);
    if (x && y) wid.moveTo (x,y);
    if (!wid.opener) wid.opener = self;
    txt = '';
    txt += '<html><head><title>Popup</title></head><body>';
    txt += '<script>';
    txt += 'function checkEnter (e) {';
    txt += '  var asc=0;';
    txt += '  if (e.which) asc=e.which;';
    txt += '  if (e.keyCode) asc=e.keyCode;';
    txt += '  if (asc==13) return true;';
    txt += '  return false;';
    txt += '}';
    txt += 'function hitEnter2() {';
    txt += '  if (!e) e=event;';
    txt += '  if (checkEnter(e)) hitEnter();';
    txt += '}';
    txt += 'function hitEnter() {';
    txt += '   var t = document.getElementById("pwd").value;';
    txt += '   opener.cb_getPassword (t,"' + cb_func + '",self);';
    txt += '}';
    txt += '</' + 'script>';
    txt += '<br>';
    txt += '<b>' + prmpt + '</b>&nbsp;&nbsp;';
    txt += '<input type="password" id="pwd" onKeyPress=hitEnter2(event)>&nbsp;';
    txt += '<button onclick=hitEnter()> OK </button>';
    txt += '</body></html>';
    wid.document.open();
    wid.document.write(txt);
    wid.document.close();
}

// staging call-back function to hide window ID
function cb_getPassword (t,cb_func,wid) {
  wid.close ();
  var cmd = cb_func + "('" + t + "');";
  eval (cmd);
}

function getpwd() {
  alert ("getpwd()!");
  getPassword("Enter password", "width=400,height=100", "cb_getpwd");
}

function cb_getpwd(txt) {
  alert ("cb_getpwd(): Collected password as " + txt);
}

var msgwid = null;

function delayMessage (waitmsg, html, w_cfg, x, y) {
  if (msgwid) msgwid.close();
  if (!w_cfg) w_cfg = "width=400,height=120,resizable";
  msgwid = window.open('','msgwid',w_cfg);
  if (x && y) msgwid.moveTo (x,y);
  if (!msgwid.opener) msgwid.opener = self;
  txt = "";
  txt += '<html><head><title>Message</title></head><body>';
  txt += '<div id=msg>' + waitmsg + '</div>';
  txt += '<center><button onclick=self.close()>Close</button></center>';
  txt += '<script>';  
  txt += 'function dmreveal() {';
  txt += '  document.getElementById("msg").innerHTML = "' + html + '";';
  txt += '}';
  txt += 'window.setTimeout ("dmreveal()",3000);';
  txt += '</' + 'script>';
  txt += '</body></html>';
  msgwid.document.open();
  msgwid.document.write(txt);
  msgwid.document.close();
  msgwid.focus();
}

//-->
