cls = {
  tagt: function()
  {
    return navigator.userAgent.toLowerCase();
  },
  tisie: function()
  {
    return (cls.tagt().indexOf('msie')!= -1 && document.all);
  },
  txmlhttp: function()
  {
    var txmlObj = null;
    if(window.XMLHttpRequest)
    {
      txmlObj = new XMLHttpRequest();
    }
    else
    {
      if(window.ActiveXObject)
      {
        txmlObj = new ActiveXObject('Microsoft.XMLHTTP');
      };
    };
    return txmlObj;
  },
  tigets: function (_strers, _callback, _arg1)
  {
    var tstrers = _strers;
    var tcallback = _callback;
    var targ1 = _arg1;
    var txmlhttp = new cls.txmlhttp();
    txmlhttp.onreadystatechange = function()
    {
      if (txmlhttp.readyState == 4)
      {
        if (txmlhttp.status == 200 || txmlhttp.status == 304)
        {
          if (targ1) tcallback(txmlhttp.responseText, targ1);
          else tcallback(txmlhttp.responseText);
        }
        else tcallback('$error$');
      };
    };
    txmlhttp.open('get', tstrers, true);
    txmlhttp.send(null);
  },
  tiposts: function (_strers, _strform, _callback, _arg1)
  {
    var tstrers = _strers;
    var tstrform = _strform;
    var tcallback = _callback;
    var targ1 = _arg1;
    var txmlhttp = new cls.txmlhttp();
    txmlhttp.onreadystatechange = function()
    {
      if (txmlhttp.readyState == 4)
      {
        if (txmlhttp.status == 200 || txmlhttp.status == 304)
        {
          if (targ1) tcallback(txmlhttp.responseText, targ1);
          else tcallback(txmlhttp.responseText);
        }
        else tcallback('$error$');
      };
    };
    txmlhttp.open('post', tstrers, true);
    txmlhttp.setRequestHeader('Content-Length', tstrers.length);
    txmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    txmlhttp.send(tstrform);
  },
  treparameter: function(_para, _strers, _value)
  {
    var tpara = _para;
    var tstrers = _strers;
    var tvalue = _value;
    var tmpstr = '';
    if (!tpara) tmpstr = '?' + tstrers + '=' + tvalue;
    else
    {
      var tmypara = '&' + tpara.substr(1);
      if (tmypara.indexOf('&' + tstrers + '=') == -1) tmpstr = tpara + '&' + tstrers + '=' + tvalue;
      else
      {
        var tAry1 = tmypara.split('&' + tstrers + '=');
        var tmpvalue = tAry1[1];
        if (tmpvalue.indexOf('&') != -1)
        {
          var tAry2 = tmpvalue.split('&');
          tmpvalue = tAry2[0];
        };
        tmpstr = tmypara.replace('&' + tstrers + '=' + tmpvalue, '&' + tstrers + '=' + tvalue);
        tmpstr = '?' + tmpstr.substr(1);
      };
    };
    return tmpstr;
  },
  tgetMBcString: function(_strers, _length)
  {
    var tstrers = _strers;
    var tlength = _length;
    var tstring = '';
    var tstrings = '0123456789abcdefghijklmnopqrstuvwxyz~!@#$%^&*()';
    var tmpstring = '';
    var tMBLength = 0;
    if (tstrers)
    {
      for (ti = 0; ti < tstrers.length; ti ++)
      {
        tMBLength += 1;
        tstring = tstrers.substr(ti, 1).toLowerCase();
        if (tstrings.indexOf(tstring) == -1) tMBLength += 1;
        if (tMBLength <= tlength) tmpstring += tstring;
      };
    };
    if (tMBLength > tlength) tmpstring += '..';
    return tmpstring;
  },
  tgetNum: function(_strers, _default)
  {
    var tstrers = _strers;
    var tdefault = _default;
    var tnum = tdefault;
    try
    {
      var tnum1 = 0;
      if (tstrers.indexOf('.') == -1) tnum1 = parseInt(tstrers);
      else tnum1 = parseFloat(tstrers);
      if (!isNaN(tnum1)) tnum = tnum1;
    } catch(e){};
    return tnum;
  },
  tgetParameter: function(_strers, _strkey)
  {
    var tmpvalue = '';
    var tstrers = _strers;
    var tstrkey = _strkey;
    if (tstrers && tstrkey)
    {
      var tiname, tivalue, ticount;
      var tinum = tstrers.indexOf('?');
      tstrers = tstrers.substr(tinum + 1);
      var tarrtmp = tstrers.split('&');
      for(ticount = 0; ticount < tarrtmp.length; ticount ++)
      {
        tinum = tarrtmp[ticount].indexOf('=');
        if(tinum > 0)
        {
          tiname = tarrtmp[ticount].substring(0, tinum);
          tivalue = tarrtmp[ticount].substr(tinum + 1);
          if (tiname == tstrkey) tmpvalue = tivalue;
        };
      };
    };
    return tmpvalue;
  },
  tgetCheckboxsValue: function(_strname)
  {
    var tname = _strname;
    var tmpvalue = '';
    var tobjs = document.getElementsByName(tname);
    if (tobjs)
    {
      for (ti = 0; ti < tobjs.length; ti ++)
      {
        if (tobjs[ti].checked) tmpvalue += ',' + tobjs[ti].value;
      };
    };
    if (tmpvalue != '') tmpvalue = tmpvalue.substr(1);
    return tmpvalue;
  },
  thtmlEncode: function(_strers)
  {
    var tstrers = _strers;
    tstrers = tstrers.replace(/(\&)/g, '&amp;');
    tstrers = tstrers.replace(/(\>)/g, '&gt;');
    tstrers = tstrers.replace(/(\<)/g, '&lt;');
    tstrers = tstrers.replace(/(\")/g, '&quot;');
    return tstrers;
  },
  thtmlDecode: function(_strers)
  {
    var tstrers = _strers;
    tstrers = tstrers.replace(/(\&amp;)/g, '&');
    tstrers = tstrers.replace(/(\&gt;)/g, '>');
    tstrers = tstrers.replace(/(\&lt;)/g, '<');
    tstrers = tstrers.replace(/(\&quot;)/g, '"');
    return tstrers;
  },
  tquotEncode: function(_strers)
  {
    var tstrers = _strers;
    tstrers = tstrers.replace(/(\")/g, '&quot;');
    return tstrers;
  },
  tselOptions: function(_obj, _strvalue)
  {
    var tobj = _obj;
    var tvalue = _strvalue;
    for(ti = 0; ti < tobj.options.length; ti ++)
    {
      if(tobj.options[ti].value == tvalue)
      {
        tobj.options.selectedIndex = ti;
        break;
      };
    };
  },
  tselCheckboxs: function(_obj, _strname)
  {
    var tobj = _obj;
    var tname = _strname;
    var tobjs = document.getElementsByName(tname);
    if (tobj && tobjs)
    {
      for (ti = 0; ti < tobjs.length; ti ++) tobjs[ti].checked = tobj.checked;
    };
  },
  tswitchDisplay: function(_obj)
  {
    var tobj = _obj;
    if (tobj) tobj.style.display = tobj.style.display == 'none'? '': 'none';
  },
  tauthor: 'jetiben',
  temail: 'jetiben@hotmail.com',
  tsysinfo: 'JTBC',
  twebsite: 'http://www.jetiben.com/',
  tversion: '2.0'
};

cls.doc = {
  tscrollTop: function()
  {
    return document.documentElement.scrollTop;
  },
  tscrollLeft: function()
  {
    return document.documentElement.scrollLeft;
  },
  tscrollWidth: function()
  {
    return document.documentElement.scrollWidth;
  },
  tscrollHeight: function()
  {
    return document.documentElement.scrollHeight;
  },
  tclientWidth: function()
  {
    return document.documentElement.clientWidth;
  },
  tclientHeight: function()
  {
    return document.documentElement.clientHeight;
  }
};

cls.form = {
  tgetValues: function(_obj)
  {
    var tobj = _obj;
    var tmpValues = '';
    if (tobj)
    {
      var tInputObj = tobj.getElementsByTagName('input');
      for(ti = 0; ti < tInputObj.length; ti ++)
      {
        if (tInputObj[ti].type == 'text' || tInputObj[ti].type == 'password' || tInputObj[ti].type == 'hidden') tmpValues += tInputObj[ti].name + '=' + iescape(tInputObj[ti].value) + '&';
        else if (tInputObj[ti].type == 'radio')
        {
          if (tInputObj[ti].checked) tmpValues += tInputObj[ti].name + '=' + iescape(tInputObj[ti].value) + '&';
        }
        else if (tInputObj[ti].type == 'checkbox')
        {
          if (!(tmpValues.indexOf(tInputObj[ti].name + '=') == 0 || tmpValues.indexOf('&' + tInputObj[ti].name + '=') != -1))
          {
            var tCheckBoxValue = '';
            var tCheckBoxObjs = document.getElementsByName(tInputObj[ti].name);
            if (tCheckBoxObjs)
            {
              for (var tk = 0; tk < tCheckBoxObjs.length; tk ++)
              {
                if (tCheckBoxObjs[tk].checked) tCheckBoxValue = tCheckBoxValue + tCheckBoxObjs[tk].value + ',';
              };
            };
            if (tCheckBoxValue) tCheckBoxValue = tCheckBoxValue.substring(0, tCheckBoxValue.length - 1);
            tmpValues += tInputObj[ti].name + '=' + iescape(tCheckBoxValue) + '&';
          };
        };
      };
      var tSelectObj = tobj.getElementsByTagName('select');
      for(ti = 0; ti < tSelectObj.length; ti ++)
      {
        if (tSelectObj[ti].getAttribute('vtype') != 'all') tmpValues += tSelectObj[ti].name + '=' + iescape(tSelectObj[ti].value) + '&';
        else
        {
          var tselValue = '';
          for (tis = 0; tis < tSelectObj[ti].options.length; tis ++)
          {
            if (tselValue == '') tselValue = tSelectObj[ti].options[tis].value;
            else tselValue += '|' + tSelectObj[ti].options[tis].value;
          };
          tmpValues += tSelectObj[ti].name + '=' + iescape(tselValue) + '&';
        };
      };
      var tTextareaObj = tobj.getElementsByTagName('textarea');
      for(ti = 0; ti < tTextareaObj.length; ti ++)
      {
        tmpValues += tTextareaObj[ti].name + '=' + iescape(tTextareaObj[ti].value) + '&';
      };
    };
    if (tmpValues) tmpValues = tmpValues.substr(0, tmpValues.length - 1);
    return tmpValues;
  }
};

cls.img = {
  tResize: function(_obj, _width, _height)
  {
    var tobj = _obj;
    var twidth = _width;
    var theight = _height;
    var tImage = new Image();
    tImage.src = tobj.src;
    if (tImage.width > twidth && tImage.height > theight)
    {
      if ((tImage.width / twidth) > (tImage.height / theight)) tobj.width = twidth;
      else tobj.height = theight;
    }
    else
    {
      if (tImage.width > twidth && tImage.height <= theight) tobj.width = twidth;
      if (tImage.width <= twidth && tImage.height > theight) tobj.height = theight;
    };
  }
};

cls.mouse = {
  tx: function(_e)
  {
    var te = _e;
    var txNum = 0;
    if (window.event) txNum = cls.doc.tscrollLeft() + event.clientX;
    else txNum = te.pageX;
    return txNum;
  },
  ty: function(_e)
  {
    var te = _e;
    var tyNum = 0;
    if (window.event) tyNum = cls.doc.tscrollTop() + event.clientY;
    else tyNum = te.pageY;
    return tyNum;
  }
};

cls.style = {
  tover: function(_obj)
  {
    var tobj = _obj;
    if (tobj)
    {
      if (tobj.className == 'selected') tobj.className = tobj.getAttribute('oclass');
      tobj.setAttribute('oclass', tobj.className);
      tobj.className = 'selected';
    };
  },
  tout: function(_obj)
  {
    var tobj = _obj;
    if (tobj) tobj.className = tobj.getAttribute('oclass');
  }
};

cls.selects = {
  tAdd: function(_strid, _strero, _strers)
  {
    var tstrid = _strid;
    var tstrero = _strero;
    var tstrers = _strers;
    var tobj = $(tstrid);
    if (tobj)
    {
      var ti, tstr, tisext;
      for (ti = 0; ti < tobj.options.length; ti ++)
      {
        if (tobj.options[ti].text == tstrero &&  tobj.options[ti].value == tstrers) tisext = true;
      };
      if (!tisext) tobj.options.add(new Option(tstrero, tstrers));
    };
  },
  tRemove: function(_strid)
  {
    var tstrid = _strid;
    var tobj = $(tstrid);
    if (tobj)
    {
      var tidx = tobj.selectedIndex;
      if (tidx != -1) tobj.options[tidx] = null;
    };
  },
  tDisplace: function(_obj, _strindex, _strkey)
  {
    var tobj = _obj;
    var tstrindex = _strindex;
    var tstrkey = _strkey;
    if (tstrindex >= 0)
    {
      if (tobj)
      {
        var tstrvalue, tstrtext;
        tstrtext = tobj.options[tstrindex].text;
        tstrvalue = tobj.options[tstrindex].value;
        if (tstrkey == 38)
        {
          if (!(tstrindex == 0))
          {
            tobj.options[tstrindex].text = tobj.options[tstrindex - 1].text;
            tobj.options[tstrindex].value = tobj.options[tstrindex - 1].value;
            tobj.options[tstrindex - 1].text = tstrtext;
            tobj.options[tstrindex - 1].value = tstrvalue;
          };
        };
        if (tstrkey == 40)
        {
          if (!(tstrindex == (tobj.options.length - 1)))
          {
            tobj.options[tstrindex].text = tobj.options[tstrindex + 1].text;
            tobj.options[tstrindex].value = tobj.options[tstrindex + 1].value;
            tobj.options[tstrindex + 1].text = tstrtext;
            tobj.options[tstrindex + 1].value = tstrvalue;
          };
        };
      };
    };
  }
};
