//copyright Tan Silliksaar 2008. All rights reserved.

var updatetimer = 0;

function XmlHttp()
{
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  try 
  {
    return new ActiveXObject("Msxml2.XMLHTTP");
  } 
  catch (e) 
  {
    try 
    {
      return new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (E)
    {
      return false;
    }
  }
  @end @*/

  if (typeof XMLHttpRequest != 'undefined') 
	try 
	{
      return new XMLHttpRequest();
	}
	catch (e) 
	{
      return false;
	}

  if (window.createRequest) 
	try 
	{
      return window.createRequest();
	}
	catch (e) 
	{
      return false;
	}
  return false;
}

function GetHttpArgs(obj, func, args)
{
  var query = "callback.htm?o=" + obj + "&f=" + func + "&rand=" + Math.random();
  if (args)
    for (var i = 0; i < args.length; i++)
      query += "&a" + (i + 1) + "=" + encodeURIComponent(args[i]);    
  
  var xmlhttp = XmlHttp();
  if (!xmlhttp)
  {
    window.alert("xmlhttp is null");
    return;
  }
  
  xmlhttp.open("GET", query, true);
  xmlhttp.onreadystatechange = function() 
  {
    if (xmlhttp.readyState == 4) 
    {
      var ret = xmlhttp.responseText;
      try
      {
        eval(ret);
      }
      catch (e)
      {
        window.alert("SCRIPT ERROR:\r\n" + e.message + ": " + ret);
      }
    }
  }
  xmlhttp.send(null);
}

function GetHttp(obj, func)
{
  var args = new Array();
  for (var i = 2; i < arguments.length; i++)
    args.push(arguments[i]);    
      
  GetHttpArgs(obj, func, args);
}

function calculateleft(sender)
{
  var l = 0;
  var p = sender;
  while (p)
  {
    l += p.offsetLeft;
    p = p.offsetParent;
  }
  return l + "px";
}

function val(id)
{
  try
  {
    return document.getElementById(id).value;
  }
  catch(e)
  {
    return null;
  }
}

function OnLoad(obj)
{
  GetHttp(obj, "OnLoad");
}

function OnClick(obj, name)
{
  if (obj && name)
    GetHttp(obj, "OnClick", name);
}

function OnValidate(obj)
{
  GetHttp(obj, "OnValidate");
}

function OnReturn(obj, fields)
{
  GetHttpArgs(obj, "OnReturn", fields);
}

function addTag(parent, tagName, className)
{
  var res;
  if (parent.tagName == "TABLE")
    res = parent.insertRow(-1);
  else if (parent.tagName == "TR")
    res = parent.insertCell(-1);
  else
    parent.appendChild(res = document.createElement(tagName));
  if (className)
    res.className = className;   
  return res;
}

function buttonClick(dianame, button)
{
  var fields = new Array();
  fields.push(button);

  var els = document.getElementsByTagName("INPUT");
  for (var i = 0; i < els.length; i++)
    if (els[i].editName)
    {
      fields.push(els[i].editName);
      if (els[i].hiddenValue)
        fields.push(els[i].hiddenValue);
      else
        fields.push(els[i].value);
    }

  OnReturn(dianame, fields);
}

function validateDialog(dianame)
{
  var fields = new Array();

  var els = document.getElementsByTagName("INPUT");
  for (var i = 0; i < els.length; i++)
    if (els[i].editName)
    {
      fields.push(els[i].editName);
      if (els[i].hiddenValue)
        fields.push(els[i].hiddenValue);
      else
        fields.push(els[i].value);
    }

  OnValidate(dianame, fields);
}

function calculateLeft(sender, parent)
{
  var v = 0;
  var p = sender;
  while (p)
  {
    v += p.offsetLeft;
    p = p.offsetParent;
    if (parent)
      if (p == parent)
        break;
  }
  return v;
}

function calculateTop(sender, parent)
{
  var v = 0;
  var p = sender;
  while (p)
  {
    v += p.offsetTop;
    p = p.offsetParent;
    if (parent)
      if (p == parent)
        break;
  }
  return v;
}

function findParent(sender, tagName)
{
  var p = sender;
  while (p)
  {
    if (p.tagName == tagName)
      return p;
    p = p.parentNode;
  }
  return null;
}

var defaultButtons = 0;
var escapeButtons = 0;
var validateElement = false;

function createDialog(dialogButtons, defaultbuttons, escapebuttons, name, title, buttons, disabled)
{
  defaultButtons = defaultbuttons;
  escapeButtons = escapebuttons;

  var dia = addTag(document.body, "DIV", "window");

  var diatable = addTag(dia, "TABLE", "window");
  diatable.cellPadding = 0;
  diatable.cellSpacing = 0;

  //title
  var titlediv = addTag(addTag(addTag(diatable), null, "windowtitle"), "DIV", "windowtitle");
  addTag(titlediv, "SPAN").innerHTML = title;

  //top right button
  var close = addTag(titlediv, "IMG", "windowtitlebutton");
  close.src = "windowtitleclose.gif.sax";
  close.dialogClass = name;
  close.style.right = 2;
  close.sourceDialog = dia;
  var cancel = 0;
  var any = 0;
  j = 1;
  for (var k = 0; k < dialogButtons.length; k++)
  {
    if ((buttons & j) == j)
    {
      any = j;
      if ((escapebuttons & j) == j) 
        cancel = j;
    }
    j *= 2;
  }
  close.buttonIndex = cancel ? cancel : any;
  close.onmouseover = function(et)
  {
    var e = et || window.event;
    var b = e.target || e.srcElement;
    b.src = "windowtitleclosehover.gif.sax";
  }
  close.onmouseout = function(et)
  {
    var e = et || window.event;
    var b = e.target || e.srcElement;
    b.src = "windowtitleclose.gif.sax";
  }
  close.onmousedown = function(et)
  {
    var e = et || window.event;
    var b = e.target || e.srcElement;
    b.src = "windowtitleclose.gif.sax";
    buttonClick(b.dialogClass, b.buttonIndex);
    b.sourceDialog.parentNode.removeChild(b.sourceDialog);
  }

  //content
  var content = addTag(addTag(diatable), null, "windowcontent");
  if (!document.all)
    content = addTag(content, "DIV");
  content.style.position = "relative";
  content.style.zIndex = 99;
  content.dialogClass = name;

  //buttons
  var buttontable = addTag(addTag(addTag(addTag(diatable)), "DIV", "windowbutton"), "TABLE", "windowbutton");
  buttontable.cellSpacing = 10;
  var buttonrow = addTag(buttontable);
  var space = addTag(addTag(addTag(diatable)), "IMG");
  space.style.width = 300;
  space.style.height = 1;
  space.src = "clear.gif.sax";

  j = 1;
  for (var i = 0; i < dialogButtons.length; i++)
  {
    if ((buttons & j) == j)
    {
      var btn = addTag(buttonrow, null, "windowbutton");
      btn.innerHTML = dialogButtons[i];
      btn.buttonIndex = j;
      btn.sourceDialog = dia;
      btn.dialogClass = name;
      if (disabled && ((defaultButtons & j) == j))
        btn.className = "windowbuttondisabled";
      btn.onmouseover = function(et)
      {
        var e = et || window.event;
        var b = e.target || e.srcElement;
        if (b.className == "windowbutton")
          b.className = "windowbuttonhover";
      }
      btn.onmouseout = function(et)
      {
        var e = et || window.event;
        var b = e.target || e.srcElement;
        if (b.className == "windowbuttonhover")
          b.className = "windowbutton";
      }
      btn.onmousedown = function(et)
      {
        var e = et || window.event;
        var b = e.target || e.srcElement;
        if (b.className != "windowbuttondisabled")
          b.className = "windowbuttondown";
      }
      btn.onmouseup = function(et)
      {
        var e = et || window.event;
        var b = e.target || e.srcElement;
        if (b.className != "windowbuttondisabled")
        {
          b.className = "windowbutton";
          buttonClick(b.dialogClass, b.buttonIndex);
          b.sourceDialog.parentNode.removeChild(b.sourceDialog);
        }
      }
    }
    j *= 2; 
  }

  return content;    
}

function enableDialog()
{
  var ok = true;
  var els = document.getElementsByTagName("INPUT");
  for (var i = 0; i < els.length; i++)
    if (els[i].style.color == "maroon")
    {
      ok = false;
      break;
    }

  els = document.getElementsByTagName("TD");
  for (var j = 0; j < els.length; j++)
    if ((els[j].buttonIndex & defaultButtons) > 0)
      if (els[j].className == (ok ? "windowbuttondisabled" : "windowbutton"))
        els[j].className = (ok ? "windowbutton" : "windowbuttondisabled");
}

function addText(dialog, text)
{
  var t = addTag(dialog, "DIV");
  t.style.width = 400;
  t.style.overflow = "visible";
  t.innerHTML = text;
  t.style.paddingBottom = 10;
  t.dialogWindow = dialog;
  return t;
}

function addPropertyEditor(dialog, name)
{
  var t = addTag(dialog, "TABLE", "propertyeditor");
  t.cellPadding = 0;
  t.cellSpacing = 1;
  t.dialogWindow = dialog;
  t.objectName = name;
  return t;
}

function addPropertyDescription(editor)
{
  var row = addTag(editor);
  var cell = addTag(row);
  cell.colSpan = 2;
  cell.id = "propertyeditordescription";
}

function addPropertyText(editor, name, displayname, description, value, chars_disabled, validate)
{
  return addPropertyTextItem("TEXT", editor, name, displayname, description, value, chars_disabled, validate)
}

function addPropertyPassword(editor, name, displayname, description, value, chars_disabled, validate)
{
  return addPropertyTextItem("PASSWORD", editor, name, displayname, description, value, chars_disabled, validate)
}

function addPropertyTextItem(type, editor, name, displayname, description, value, chars_disabled, validate)
{
  var row = addTag(editor);
  var namecell = addTag(row, null, "propertyeditorname");
  namecell.innerHTML = displayname;
  var editcell = addTag(row, null, "propertyeditor");
  var edittext = document.createElement("INPUT");
  edittext.type = type;
  edittext.className = "propertyeditor";
  editcell.appendChild(edittext);
  edittext.dialogWindow = editor.dialogWindow;
  if (chars_disabled != "disabled")
    edittext.editName = editor.objectName + "." + name;
  edittext.descriptionText = description;
  edittext.displayName = displayname;
  edittext.dialogClass = editor.dialogClass;
  edittext.originalValue = value;

  if (value)
    edittext.value = value;
  if (validate == "true")
  {
    edittext.onkeydown = function(et)
    {
      var e = et || window.event;
      var b = e.target || e.srcElement;
      setTimeout("validateDialog('" + b.dialogClass + "')", 100);
    }
  }
  else if (validate)
  {
    edittext.style.color = chars_disabled == "disabled" ? "maroon" : "black";
    edittext.onkeydown = function(et)
    {
      var e = et || window.event;
      validateElement = e.target || e.srcElement;
      setTimeout(validate + "()", 100);
    }
  }
  if (chars_disabled == "disabled")
  {
    edittext.readOnly = true;
    edittext.style.color = "#6f6d6f";
  }
  else if (chars_disabled)
  {
    edittext.allowedChars = chars_disabled;
    edittext.onkeypress = function(et)
    {
      var e = et || window.event;
      var b = e.target || e.srcElement;
      var k = e.keyCode || e.which;
      if (k < 32)
        return true;
      var c = String.fromCharCode(k);
      if (b.allowedChars.indexOf(c) < 0)
        return c == "," && b.allowedChars.indexOf(".") >= 0;
      if (c == "-" && b.allowedChars.indexOf(c) == 0)
      {
        if (document.all)
          return (new String(b.value)).length == 0;
        return (b.value.length == 0);
      }
      return true;
    }
  }
  edittext.onfocus = function(et)
  {
    var e = et || window.event;
    var b = e.target || e.srcElement;
    setpropertydescription(b);
  }

  return edittext;  
}

function closeMenus()
{
  var els = document.getElementsByTagName("DIV");
  for (var i = 0; i < els.length; i++)
    if (els[i].className == "propertyeditoroptions")
      els[i].style.display = "none"; 
  document.body.onmousedown = null;
}

function setpropertydescription(b, index)
{
  var d = document.getElementById("propertyeditordescription");
  if (d)
    if (b.descriptionText)
  {
    var s = b.descriptionText;
    if (s.indexOf("|") >= 0)
    {
      var ss = s.split("|");
      if (index)
        s = ss[index];
      else
        s = ss[0];
    }
    d.innerHTML = "<b>" + b.displayName + ":</b> " + s;
  }
  else d.innerHTML = b.displayName;
}

function DropDown(editor, name, displayname, description, value)
{
  var row = addTag(editor);
  var namecell = addTag(row, null, "propertyeditorname");
  namecell.innerHTML = displayname;
  var editcell = addTag(row, null, "propertyeditor");
  if (!document.all)
    editcell = addTag(editcell, "DIV");
  editcell.style.position = "relative";
  this.edittext = addTag(editcell, "INPUT", "propertyeditor");
  this.edittext.type = "TEXT";
  if (value)
    this.edittext.value = value;
  this.edittext.readOnly = true;
  this.edittext.style.cursor = "pointer";
  this.edittext.editName = editor.objectName + "." + name;
  this.edittext.dialogClass = editor.dialogClass;

  var arrow = addTag(editcell, "IMG", "propertyeditorarrow");
  arrow.src = "arrowdown.gif.sax";
  this.edittext.descriptionText = arrow.descriptionText = description;
  this.edittext.displayName = arrow.displayName = displayname;
  this.edittext.dialogWindow = arrow.dialogWindow = editor.dialogWindow;

  this.edittext.onmousedown = arrow.onmousedown = function(et)
  {
    var e = et || window.event;
    var b = e.target || e.srcElement;
    setpropertydescription(b);
  }

  this.edittext.onmouseup = arrow.onmouseup = function(et)
  {
    var e = et || window.event;
    var b = e.target || e.srcElement;
    var td = findParent(b, "TD");
    b.optionList.style.left = calculateLeft(td, b.dialogWindow) - 1;
    b.optionList.style.top = calculateTop(td, b.dialogWindow) + td.offsetHeight;
    b.optionList.style.display = "";
    b.optionList.style.zIndex = 999;
    b.optionList.style.width = td.offsetWidth + 2;
  }
  
  this.optdiv = addTag(editor.dialogWindow, "DIV", "propertyeditoroptions");
  this.edittext.optionList = arrow.optionList = this.optdiv;
  this.optdiv.style.display = "none";

}

function addPropertySelect(editor, name, displayname, description, value /*,values*/)
{
  var dd = new DropDown(editor, name, displayname, description, value);

  var options = addTag(dd.optdiv, "TABLE");
  options.style.width = "100%";
  var hiddenvalue;

  for (var i = 5; i < arguments.length; i++)
  {
    if (i % 2 == 1)
      hiddenvalue = arguments[i];
    else
    {
      var cell = addTag(addTag(options), null, "propertyeditoroption");
      cell.innerHTML = arguments[i]; 
      cell.editorElement = dd.edittext;
      cell.dialogWindow = editor.dialogWindow;
      cell.hiddenValue = hiddenvalue;
      if (dd.edittext.value == hiddenvalue)
      {
        dd.edittext.value = arguments[i];
        dd.edittext.hiddenValue = hiddenvalue;
      }
      cell.onmouseover = function(et)
      {
        var e = et || window.event;
        var b = e.target || e.srcElement;
        b.className = "propertyeditoroptionhover";
      }
      cell.onmouseout = function(et)
      {
        var e = et || window.event;
        var b = e.target || e.srcElement;
        b.className = "propertyeditoroption";
      }
      cell.onmousedown = function(et)
      {
        var e = et || window.event;
      }
      cell.onmouseup = function(et)
      {
        var e = et || window.event;
        var b = e.target || e.srcElement;
        b.editorElement.value = b.innerHTML;
        b.editorElement.hiddenValue = b.hiddenValue;
        closeMenus();
      }
    }
  }
}

function addWait(dialog)
{
  var img = addTag(addTag(dialog, "DIV", "wait"), "IMG");
  img.src = "ajax-loader.gif.sax";
  return img;
}

function createMenu()
{
  var menutable = addTag(document.body, "TABLE");
  menutable.cellPadding = 0;
  menutable.cellSpacing = 0;
  return addTag(menutable);
}

function createLogo(menu, src)
{
  var img = addTag(addTag(menu), "IMG");
  img.src = src;
  return img;
}

function createTab(menu, title, selected)
{
  var leftcell = addTag(menu);
  leftcell.menuTitle = title;
  leftcell.menuType = "left";
  var left = addTag(leftcell, "IMG");
  left.src = "clear.gif.sax";
  left.width = 5;
  if (selected)
    leftcell.style.backgroundImage = "url(topmenutableft.gif.sax)";

  var center = addTag(menu, null, "menutab");
  center.innerHTML = title;
  center.menuTitle = title;
  center.menuType = "";
  if (selected)
    center.style.backgroundImage = "url(topmenutab.gif.sax)";

  var rightcell = addTag(menu);
  rightcell.menuTitle = title;
  rightcell.menuType = "right";
  var right = addTag(rightcell, "IMG");
  right.src = "clear.gif.sax";
  right.width = 5;
  if (selected)
    rightcell.style.backgroundImage = "url(topmenutabright.gif.sax)";

  var menutable = addTag(document.body, "TABLE", "menubar");
  if (!selected)
    menutable.style.display = "none";
  menutable.menuTitle = title;

  center.onmouseover = function(et)
  {
    var e = et || window.event;
    var b = e.target || e.srcElement;
    var tds = document.getElementsByTagName("TD");
    for (var td = 0; td < tds.length; td++)
      if (tds[td].menuTitle == b.menuTitle && (!tds[td].style.backgroundImage || tds[td].style.backgroundImage.indexOf("hover") > 0))
        tds[td].style.backgroundImage = "url(topmenutabhover" + tds[td].menuType + ".gif.sax)";
  };
  center.onmousedown = function(et)
  {
    var e = et || window.event;
    var b = e.target || e.srcElement;
    var tds = document.getElementsByTagName("TD");
    for (var td = 0; td < tds.length; td++)
      if (tds[td].menuTitle)
        tds[td].style.backgroundImage = tds[td].menuTitle == b.menuTitle ? "url(topmenutab" + tds[td].menuType + ".gif.sax)" : "";
    var bars = document.getElementsByTagName("TABLE");
    for (var bar = 0; bar < bars.length; bar++)
      if (bars[bar].menuTitle)
        bars[bar].style.display = bars[bar].menuTitle == b.menuTitle ? "" : "none";
  };
  center.onmouseout = function(et)
  {
    var e = et || window.event;
    var b = e.target || e.srcElement;
    var tds = document.getElementsByTagName("TD");
    for (var td = 0; td < tds.length; td++)
      if (tds[td].menuTitle == b.menuTitle && tds[td].style.backgroundImage)
        if (tds[td].style.backgroundImage.indexOf("hover") > 0)
          tds[td].style.backgroundImage = "";
  };

  return addTag(menutable);
}

function createMenuItem(bar, obj, name, title, img)
{
  var cell = addTag(bar, null, "menuitem");
  var image = addTag(addTag(cell, "DIV", "menuitemimage"), "IMG", "menuitemimage");
  image.src = img;
  var text = addTag(cell, "DIV", "menuitemtext");
  text.innerHTML = title;

  image.menuItemName = text.menuItemName = cell.menuItemName = name;
  image.menuClass = text.menuClass = cell.menuClass = obj;
  image.menuItemCell = text.menuItemCell = cell;

  image.onmouseover = text.onmouseover = function(et)
  {
    var e = et || window.event;
    var b = e.target || e.srcElement;
    if (b.menuItemCell)
      b.menuItemCell.className = "menuitemhover";
  };

  image.onmouseout = text.onmouseout = function(et)
  {
    var e = et || window.event;
    var b = e.target || e.srcElement;
    if (b.menuItemCell)
      b.menuItemCell.className = "menuitem";
  };

  cell.onmouseup = function(et)
  {
    var e = et || window.event;
    var b = e.target || e.srcElement;
    OnClick(b.menuClass, b.menuItemName);
  };
}
  
var sortcolumn = 0;
var sortorder = 0;

function sortCompare (a, b) 
{
  var aa = a.cells[sortcolumn].sortValue;
  var bb = b.cells[sortcolumn].sortValue;

  if (aa == bb) 
    return 0;
  var res = aa < bb ? -1 : 1;
  return sortorder == 0 ? res : -res; 
}

function sortTable(headercell)
{
  sortcolumn = headercell.columnNumber;
  var table = headercell.parentTable;

  var rows = new Array();
  for (var r = 1; r < table.rows.length; r++)
    rows.push(table.rows[r]);
 
  rows.sort(sortCompare);

  for (var i = 1; i < table.rows.length - 1; i++) 
    if (table.rows[i] != rows[i - 1])
      table.rows[i].parentNode.insertBefore(rows[i - 1], table.rows[i]);
}

function createTable()
{
  document.getElementById("moldcontent").innerHTML = "";
  var t = addTag(document.getElementById("moldcontent"), "TABLE", "datatable");
  t.cellSpacing = 1;
  t.cellPadding = 2;
  return t;
}

function selectTableRow(cell)
{
  var table = cell.parentTable;
  var row = cell.parentNode;

  for (var r = 1; r < table.rows.length; r++)
  {
    var sel = row == table.rows[r];
    for (var c = 0; c < table.rows[r].cells.length; c++)
    {
      if (sel)
        table.rows[r].cells[c].className = c == 0 ? "leftcellselected" : "datacellselected";
      else 
      {
        if (table.rows[r].cells[c].className.indexOf("selected") < 0)
          break;
        table.rows[r].cells[c].className = c == 0 ? "leftcell" : "datacell";
      }
    }
  }
  
  OnClick(row.tableClass, row.dataId);
}

function addHeaderRow(table)
{
  var row = addTag(table);
  var align;
  addTag(row, null, "topleftcell");
  for (var i = 1; i < arguments.length; i++)
  {
    if (i % 2 == 1)
      align = arguments[i];
    else
    {
      var cell = addTag(row, null, "headercell");
      cell.innerHTML = arguments[i];
      cell.columnNumber = i / 2;
      cell.parentTable = table;
      cell.style.textAlign = align;
      cell.onclick = function(et)
      {
        var e = et || window.event;
        var b = e.target || e.srcElement;
        sortTable(b);
      }
    }
  }
}

function addDataRow(table, classname, id)
{
  var row = addTag(table);
  row.dataId = id;
  row.tableClass = classname;
  var sortvalue;
  var leftcell = addTag(row, null, "leftcell");
  leftcell.parentTable = table;
  leftcell.onclick = function(et)
  {
    var e = et || window.event;
    var b = e.target || e.srcElement;
    selectTableRow(b);
  };

  for (var i = 3; i < arguments.length; i++)
  {
    if (i % 2 == 1)
      sortvalue = arguments[i];
    else
    {
      var cell = addTag(row, null, "datacell");
      cell.innerHTML = arguments[i];
      cell.columnNumber = (i - 2) / 2;
      cell.parentTable = table;
      cell.sortValue = sortvalue;
      cell.style.textAlign = table.rows[0].cells[cell.columnNumber].style.textAlign;
      cell.onclick = function(et)
      {
        var e = et || window.event;
        var b = e.target || e.srcElement;
        selectTableRow(b);
      }
    }
  }
}

function validateEmail() 
{
  var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  validateElement.style.color = re.test(validateElement.value) ? "black" : "maroon";
  enableDialog();
}

function validatePersonName()
{
  var up = -1;
  var lo = -1;
  if (validateElement.value)
  {
    var v = validateElement.value;
    var u = v.toUpperCase();
    var l = v.toLowerCase();
    
    for (var i = 0; i < v.length; i++)
    {
      if (l.charAt(i) == u.charAt(i) && "- ".indexOf(l.charAt(i)) < 0)
      {
        up = -2;
        break;
      }
      if (v.charAt(i) == u.charAt(i))
        up = i;
      else if (v.charAt(i) == l.charAt(i))
        lo = i;
    }
  }
  validateElement.style.color = up > -1 && up < lo ? "black" : "maroon";
  enableDialog();
}

function validatePassword()
{
  var pw = validateElement.value;
  if (pw == validateElement.originalValue)
  {
    setpropertydescription(validateElement, 0);
    validateElement.style.color = "black";
    enableDialog();
    return;
  }
  
  var ok = false;
  if (pw.length < 8)
    setpropertydescription(validateElement, 0);
  else
  {  
    var blocks = 0;

    for (i = 0; i < pw.length; i++)
      if ("qwertyuioplkjhmngfdsazxcvb".indexOf(pw.charAt(i)) >= 0)
        blocks |= 1;
      else if ("QWERTYUIOPLKJHNMBVCXZASDFG".indexOf(pw.charAt(i)) >= 0)
        blocks |= 2;
      else if ("0123456789".indexOf(pw.charAt(i)) >= 0)
        blocks |= 4;
      else 
        blocks |= 8;

    setpropertydescription(validateElement, (ok = blocks == 15) ? 2 : 1);
  }
  validateElement.style.color = ok ? "black" : "maroon";
  enableDialog();
}

