function dynamic_content(elementID, content){
  if (document.all)
    document.element[elementID].innerHTML=content;
  else if (document.getElementById){
    rng = document.createRange();
    el = document.getElementById(elementID);
    rng.setStartBefore(el);
    htmlFrag = rng.createContextualFragment(content);
    while (el.hasChildNodes()) el.removeChild(el.lastChild);
    el.appendChild(htmlFrag);
  }
}

function isEqual(x, y)
{
  a = JSON.encode(x).toLowerCase();
  b = JSON.encode(y).toLowerCase();

//  alert(a+"\n\n"+b);
  return a == b;
}

var Style = {
  Background:function(obj, color) { 
    if (Test.isDefined(obj)) {
      if (Test.isArray(obj)) for (var i in obj) Style.Background(obj[i]);
      else if (Test.isObject(obj) && !Test.isString(color) && (Test.isObject(obj.obj) && Test.isString(obj.color))) Style.Background(obj.obj, obj.color);
      else if (Test.isString(obj) && Test.isString(color)) this.Background(document.getElementById(obj), color);
      else if (Test.isObject(obj) && Test.isString(color)) obj.style.background = color;
    }
  }
}

var Test = {
  isArray:function(o) { return Test.isDefined(o) && o.constructor == Array; },
  isBool:function(o) { return Test.isDefined(o) && o.constructor == Boolean; },
  isDefined:function(o) { return !Test.isUndefined(o); },
  isObject:function(o) { return typeof(o) == "object"; },
  isString:function(o) { return Test.isDefined(o) && o.constructor == String; },
  isUndefined:function(o) { return typeof(o) == "undefined"; }
}

var Utils =
{
  String:
  {
    no_accent:function(str, type)
    {
      if (typeof type == "undefined") type = 'a';
      switch(type) {
        case 'l':
          s = str.replace(/[\u00e7]/g, "c");
          s = s.replace(/[\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5]/g, "a");
          s = s.replace(/[\u00e8\u00e9\u00ea\u00eb]/g, "e");
          s = s.replace(/[\u00ec\u00ed\u00ee\u00ef]/g, "i");
          s = s.replace(/[\u00f2\u00f3\u00f4\u00f5\u00f6]/g, "o");
          s = s.replace(/[\u00f9\u00fa\u00fb\u00fc]/g, "u");
          return s;

        case 'u':
          s = str.replace(/[\u00c7]/g, "C");
          s = s.replace(/[\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5]/g, "A");
          s = s.replace(/[\u00c8\u00c9\u00ca\u00cb]/g, "E");
          s = s.replace(/[\u00cc\u00cd\u00ce\u00cf]/g, "I");
          s = s.replace(/[\u00d2\u00d3\u00d4\u00d5\u00d6]/g, "O");
          s = s.replace(/[\u00d9\u00da\u00db\u00dc]/g, "U");
          return s;

        default:
          s = Utils.String.no_accent(str, 'l');
          s = Utils.String.no_accent(s, 'u');
          return s;
      }
    }
  },

  Email:
  {
    pattern:function(name)
    {
      name = Utils.String.no_accent(name.toLowerCase(), 'l');
      a = name.split(/\s|[-]/g);
      email = '';
      for(i=0; i<a.length-1; i++) email = email + a[i].charAt(0);
      email = email + a[a.length-1];
      return email;
    },

    split:function(email)
    {
      return email.split(/[@]/g);
    }
  },

  Null:function(obj)
  {
    return (obj == null || obj.length == 0) ? null : obj;
  },

  Json:
  {
    encode:function(obj, lower)
    {
      if (typeof lower == "undefined") lower = true;
      json = JSON.encode(obj);
      return lower ? json.toLowerCase() : json;
    },

    decode:function(obj)
    {
      return JSON.decode(obj);
    }
  },

  Array:
  {
    is_index:function(array, obj)
    {
      return (is_int(obj) && obj >= 0 && obj < array.length);
    },

    find:function(array, obj)
    {
      index = -1
      for(i=0; i<array.length; i++) {
       if (isEqual(array[i], obj)) index = i;
      }
      return index;
    },

    removeAll:function(x, y)
    {
      if (y != null) {
        var index = new Array();
        var str = '';
        var cmd = "tmp = this.find(x, y[{INDEX}]); if(tmp >= 0) x.splice(tmp, 1);";
        for(i=0; i<y.length; i++) str += cmd.replace(/{INDEX}/g, i);
        eval(str);
      }
    }
  }
}

var Html =
{
  changeClass:function(id, className)
  {
    var e = document.getElementById(id);
    if (e != null) {
      e.setAttrribute("class", className);
      e.setAttrribute("className", className);
    }
  },
  
  form:
  {
    checkbox:
    {
      toArray:function(c)
      {
        if (c !== undefined) {
          o = new Array();
          if (c.length !== undefined) {
            for(i=0; i<c.length; i++) o.push(c[i].checked ? true : false);
          } else o.push(c.checked ? true : false);
          return o;
        } else return null;
      }
    }
  },
  
  img:function(src, width, height, alt) 
  {
    return "<img src='" + src + "' width='" + width + "' height='" + height + "' alt='" + alt + "'>";
  }
}


