winIEpass = ((navigator.appName.indexOf("Microsoft") != -1) &&
  (navigator.appVersion.indexOf("Windows") != -1)) &&
  (parseFloat(navigator.appVersion) >= 4) ? true : false;

NNpass = ((navigator.appName == "Netscape") &&
  (navigator.userAgent.indexOf("Mozilla") != -1) &&
  (parseFloat(navigator.appVersion) >= 4) &&
  (navigator.javaEnabled())) ? true : false;

  supportedBrowser = (winIEpass || NNpass) ? true : false;

function Text2XML(XMLText)
{
  if (window.ActiveXObject)
  {
    // code voor Internet Explorer
    var xmlSelect = new ActiveXObject("Microsoft.XMLDOM");
    xmlSelect.async = "false";
    xmlSelect.loadXML(XMLText);
  }
  else
  {
    // code voor Mozilla, Firefox, Opera, etc.
    var parser = new DOMParser();
    var xmlSelect = parser.parseFromString(XMLText, "text/xml");
  }
  return xmlSelect;
}

function LargeImage(ImageName)
{
  OpenDialog(ImageName, 700, 470, this);
}

function tDialogResponse(Response)
{
  this.Response = Response;
}

function LeadingZero2(Nr)
{
	return (Nr < 10) ? "0" + Nr : Nr;
}

function MySQLDate2ddmmjjjj(MySQLDate)
{
  DateArray = MySQLDate.split(' ', 2);
  if (DateArray.length < 2)
    return '';
  Date = DateArray[0];
  DateArray = Date.split('-', 3);
  if (DateArray.length < 3)
    return '';
  Dag = LeadingZero2(DateArray[2].toInt());
  Maand = LeadingZero2(DateArray[1].toInt());
  Jaar = DateArray[0];
  return Dag + '-' + Maand + '-' + Jaar;
}

function DecimalCorrect(FieldName, Decimals)
{
  EditControl = document.getElementById(FieldName);
  Value = Math.abs(EditControl.value.replace(',', '.'));
  if (isNaN(Value))
    Value = 0;

  Value1 = Math.round(Value);
  Value2 = String(Math.round(Math.pow(10, Decimals) * (Value - Value1))) + '000000';
  Value2 = Value2.slice(0, Decimals);
  EditControl.value = Value1 + '.' + Value2;
}

function ValidInteger(edtName, Message)
{
  edtName = document.getElementById(edtName);
  NrValue = edtName.value;
  StringValid = NrValue.length > 0;
  for (var i=0; i < NrValue.length; i++)
    if ((NrValue.charCodeAt(i) < 48) || (NrValue.charCodeAt(i) > 57))
    {
      StringValid = false;
      break;
    }
  if (!StringValid)
    alert(Message);
  return StringValid;
}

function ValidFloat(edtName, Message)
{
  edtName = document.getElementById(edtName);
  NrValue = edtName.value;
  NrValue = NrValue.replace(',','.');
  StringValid = NrValue.length > 0;
  PointFound = false;
  for (var i=0; i < NrValue.length; i++)
    if ((!PointFound) && (NrValue.charCodeAt(i) == 46))
      PointFound = true;
    else
      if ((NrValue.charCodeAt(i) < 48) || (NrValue.charCodeAt(i) > 57) )
      {
        StringValid = false;
        break;
      }
  if (!StringValid)
    alert(Message);
  return StringValid;
}

//--- Standard object Prototypes ---------------------------------------------//
String.prototype.trim = function()
{
  return this.replace(/^\s+|\s+$/, '');
};

String.prototype.toInt = function()
{
  return Math.round(this);
}

String.prototype.format = function()
{
  var str = this;
  for(var i=0;i<arguments.length;i++)
  {
    var re = new RegExp('\\{' + (i) + '\\}','gm');
    str = str.replace(re, arguments[i]);
  }
  return str;
}  // a="De waarde is {0} en de 2e waarde is {1}".format(Waarde1, Waarde2);

String.prototype.DecodeHTML = function()
{
//  var str = unescape(this);
  var str = this;
// String.fromCharCode(0x0022);
  str = str.replace(/&lt;/gi, "<");
  str = str.replace(/&gt;/gi, ">");
  //str = str.replace(/&euml;/gi, "ë");
  str = str.replace(/&amp;/gi, "&");
  return str;
}

Array.prototype.HasValue = function(Value)
{
  return (this.Find(Value) > -1);
}

Array.prototype.Find = function(Value)
{
  Result = -1;
  for (var i = 0; i < this.length; i++)
    if (this[i] == Value)
    {
      Result = i;
      break;
    }
  return Result;
}

// dHTMLWindow class -----------------------------------------------------------
function TdHTMLWindow(divName, iframeName)
{
  this.Div = document.getElementById(divName);
  this.Frame = document.getElementById(iframeName);
  this.Control_1 = '';
  this.Control_2 = '';
  this.Control_3 = '';
  this.Control_4 = '';
  this.Value_1 = '';
  this.Value_2 = '';
  this.Done = false;
  this.WindowName = '';
  this.Focus = function ()
  {
  }

  this.IsVisible = function ()
  {
    return (this.Div.style.visibility != 'hidden');
  }
  this.KeyEvent = function () {};
  this.Show = function()
  {
    this.Div.style.visibility = '';
  }

  this.Hide = function()
  {
    this.Div.style.visibility = 'hidden';
  }

  this.Load = function(URL, Left, Top, Width, Height)
  {
    this.Done = false;
    this.KeyEvent = function () {};
    this.Div.style.left = Left;
    this.Div.style.top = Top;
    this.Div.style.width = Width;
    this.Div.style.height = Height;
    this.Frame.src = URL;
  }
  this.Frame.ControlObject = this;
  return this;
}


// Dialogs ---------------------------------------------------------------------
function OpenDialog(FilePath, Width, Height, ParentObject)
{
  var sFeatures= "dialogHeight: " + Height + "px; dialogWidth: " + Width + "px; edge: raised; " +
    "center: 1; help: 0; resizable: 0; status: 1;";
  window.showModalDialog(FilePath, ParentObject, sFeatures);
}

function OpenKalender(DatumVeld, KalenderKnop)
{
  Left = document.getElementById(KalenderKnop).offsetLeft - 160;
  Top = document.getElementById(KalenderKnop).offsetTop + 20;

  if (oMain = document.getElementById('contentDiv'))
  {
    Left = Left + oMain.offsetLeft;
    Top = Top + oMain.offsetTop;
  }

  MydHTML.Control_1 = document.getElementById(DatumVeld);
  MydHTML.Control_2 = document.getElementById(KalenderKnop);
  MydHTML.Load('../_include/Kalender.php', Left, Top, 180, '');
  MydHTML.Show();
}

function DatumOnKeyPress()
{
  if ((window.event.keyCode < 58) && (window.event.keyCode > 47))
  {}  //  0-9
  else
    if (window.event.keyCode != 45)
      window.event.keyCode = 0;

  // TODO: Deze check zou ook tijdens invoer een correct datum formaat kunnen
  //   forceren. Dan zou ook CTRL-V en rechter muis click gefilterd moeten worden.
}

function Datum_Ok(DatumTekst, EmptyOk)
{
  if (DatumTekst != '')
  {
    Result = false;
    try
    {
      DateArray = DatumTekst.split('-', 3);
      Dag = DateArray[0].toInt();
      Maand = DateArray[1].toInt();
      Jaar = DateArray[2].toInt();

  //  Controleer of datum geldig is minder dan 2209032000000 ms (70 jaar) voor
  //  of 4102488000000 ms (130 jaar) na 01-01-1970 (Unix timestamp) ligt.
      var MyDate = new Date();
      //alert('Date: ' + MyDate);
      MyDate.setFullYear(Jaar, Maand - 1, Dag);
      if (!isNaN(MyDate))
        if ( (MyDate.getTime() > - 2209032000000) && (MyDate.getTime() < 4102488000000) )
          if ( (MyDate.getFullYear() == Jaar) && (MyDate.getDate() == Dag) && (MyDate.getMonth() == (Maand - 1)) )
            Result = true;
    }
    catch(err) { }
    return Result;
  }
  else
    return EmptyOk;
}