// Copyright Basement.nl, 2010

String.prototype.bas_trim = function()
{
  return this.replace(/^\s+|\s+$/g, "");
};

Array.prototype.bas_indexOf = function(AItem)
{
  var LResult = -1;
  for (var I = 0; I < this.length; I++)
  {
    if (this[I] == AItem)
    {
	  LResult = I;
      break;
    }
  }
  return LResult;
};

Array.prototype.unique = function()
{
  var r = [];
  o:for(var i = 0, n = this.length; i < n; i++)
  {
    for(var x = 0, y = r.length; x < y; x++)
    {
      if(r[x]==this[i])
      {
        continue o;
      }
	}
    r[r.length] = this[i];
  }
  return r;
};

function edChange(AID)
{
  document.getElementById(AID).value = document.getElementById(AID).value.replace(/</g, "(").replace(/>/g, ")");
}

function GetAjaxRequest()
{
  var Result = null;
  if (window.XMLHttpRequest)
  {
    Result = new XMLHttpRequest();
  }
  else
  {
    try
    {
      Result = new ActiveXObject("MSXML2.XMLHTTP.3.0");
    }
    catch (e_MSXML2)
    {
    }

    if (Result === null)
    {
       try
       {
         Result = new ActiveXObject("Microsoft.XMLHTTP");
       }
       catch (e_Microsoft)
       {
       }
     }
  }
  return Result; 
}

function AjaxRequest(AUrlHandler, AData, ACallBack)
{
  var LXmlHttpRequest = GetAjaxRequest();
  var LMethod;
  if (LXmlHttpRequest)
  {
    if (AData === null)
    {
      LMethod = "GET";
    }
    else
    {
      LMethod = "POST";
    }
      
    LXmlHttpRequest.open(LMethod, AUrlHandler, true);
    LXmlHttpRequest.onreadystatechange = function()
    {
      if (LXmlHttpRequest.readyState == 4)
      {
        ACallBack(LXmlHttpRequest.responseText);
      }
    };
    LXmlHttpRequest.send(AData);
    return true;
  }
  else
  {
    return false;
  }
}
