O3Global.Types = new function()
{
  // Validate email
  function validateEmail(sEmail)
  {
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    return filter.test(sEmail);
  }

  // Check for array
  function isArray(a)
  {
    if(a && a.constructor && a.constructor.toString().indexOf("Array") != -1)
      return true;

    return false;
  }

  // Compare 2 associative arrays
  function arrayCompare(a1, a2, bOneSidedMatch)
  {
    // Check if both are arrays
    if(!isArray(a1) || !isArray(a2))
      return false;

    // Loop a1 and check a2
    for(var s in a1)
    {
      if(a1[s] != a2[s])
        return false;
    }

    // Loop reversed (a2 might have more params)
    if(!bOneSidedMatch)
    {
      for(var s in a2)
      {
        if(a1[s] != a2[s])
          return false;
      }
    }

    // They are the same
    return true;
  }

  // Check numeric
  function isNumeric(sText)
  {
    if(sText == null)
      return false;

    // Ensure string
    sText = "" + sText;

    var sValidChars = "-0123456789";
    var cChar;

    for(var i = 0; i < sText.length; i++) 
    {
      cChar = sText.charAt(i);
      if(sValidChars.indexOf(cChar) == -1)
        return false;
    }

    // All ok
    return true;
  }

  // Proper URL encoder
  function encodeURL(sURL)
  {
    // Make sure we have a string
    sURL = "" + sURL;

    // The Javascript escape and unescape functions do not correspond
    // with what browsers actually do...
    var SAFECHARS = "0123456789" +                 // Numeric
                    "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
                    "abcdefghijklmnopqrstuvwxyz" +
                    "-_.!~*'()";                   // RFC2396 Mark characters
    var HEX = "0123456789ABCDEF";

    var sEncoded = "";
    for(var i = 0; i < sURL.length; i++ )
    {
      var c = sURL.charAt(i);
      if(c == " ")
        sEncoded += "+"; // x-www-urlencoded, rather than %20
      else if(SAFECHARS.indexOf(c) != -1)
        sEncoded += c;
      else
      {
        var charCode = c.charCodeAt(0);
        if(charCode > 255)
        {
          alert("Unicode Character '" + c + "' cannot be encoded using standard URL encoding.\n" +
                "(URL encoding only supports 8-bit characters.)\n" +
                "A space (+) will be substituted." );
            sEncoded += "+";
        }
        else
        {
          sEncoded += "%";
          sEncoded += HEX.charAt((charCode >> 4) & 0xF);
          sEncoded += HEX.charAt(charCode & 0xF);
        }
      }
    } // for

    return sEncoded;
  }

  // Bind public functions
  this.validateEmail = validateEmail;
  this.isArray       = isArray;
  this.arrayCompare  = arrayCompare;
  this.isNumeric     = isNumeric;
  this.encodeURL     = encodeURL;
}