<!--
//  SYSTEM      :  pascual jstool
//  PROGRAM     :  pascual
//  CREATE      :  2007.5.8
//  FILE NAME   :  basetype.js
/*<![CDATA[*/
  var JClass = {
    create: function() {
      return function() {
        this.initialize.apply(this, arguments);
      }
    },
    emptyFunction : function() {}
  }

  Object.extend = function(destination, source) {
    for (var property in source) {
      destination[property] = source[property];
    }
    return destination;
  }
  window.$=function(obj){return typeof(obj)=="string"?(document.getElementById(obj)):obj}
  window.DeleteObj=function(obj){if($(obj)!=null){$(obj).parentNode.removeChild($(obj))}}
  window.DropObj=
    function(obj, ischild){
      if($(obj)!=null){
        while ( obj.hasChildNodes() ) {
          window.DropObj(obj.lastChild, 1);
          obj.removeChild(obj.lastChild);
        }
        if(!ischild) obj.parentNode.removeChild(obj);
      }else {
        return false;
      }
    }
  
  window.browser = new function ()
  {
    var a,ua = navigator.userAgent;
    prototype = { 
      safari    : ((a=ua.split('AppleWebKit/')[1])?a.split('(')[0].split('.')[0]:0)>=124 ,
      konqueror : ((a=ua.split('Konqueror/')[1])?a.split(';')[0]:0)>=3.3 ,
      mozes     : ((a=ua.split('Gecko/')[1])?a.split(' ')[0]:0) >= 20011128 ,
      opera     : (!!window.opera) && ((typeof XMLHttpRequest)=='function') ,
      msie      : (!!window.ActiveXObject)?((ua.match(/MSIE/))?true:false):false
    }
    Object.extend(this, prototype);
  }

//prototype
//outerHTML

  if(window.addEventListener && typeof(HTMLElement)!="undefined" && !window.opera)
  {
    HTMLElement.prototype.__defineGetter__("outerHTML",function()
    {
      var a=this.attributes, str="<"+this.tagName, i=0;for(;i<a.length;i++)
      if(a[i].specified) str+=" "+a[i].name+'="'+a[i].value+'"';
      if(!this.canHaveChildren) return str+" />";
      return str+">"+this.innerHTML+"</"+this.tagName+">";
    });
    HTMLElement.prototype.__defineSetter__("outerHTML",function(s)
    {
      var r = this.ownerDocument.createRange();
      r.setStartBefore(this);
      var df = r.createContextualFragment(s);
      this.parentNode.replaceChild(df, this);
      return s;
    });
    HTMLElement.prototype.__defineGetter__("canHaveChildren",function()
    {
      return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
    });

//event && srcElement && runtimeStyle
    HTMLElement.prototype.__defineGetter__("runtimeStyle",function(){return this.style; });
    window.constructor.prototype.__defineGetter__("event",window_prototype_get_event);
    //Event.prototype.__defineGetter__("srcElement",function(){return this.target;});
    Event.prototype.__defineGetter__("srcElement", function(ee){var n=(ee)?ee.target:this.target; while (n.nodeType!=1)n=n.parentNode;return n;}); 
    HTMLElement.prototype.__defineGetter__("currentStyle", function(){return window.getComputedStyle(this, "")});
  }

  function window_prototype_get_event()
  {
    if(document.all) return window.event;
    func=window_prototype_get_event.caller;
    
    while(func!=null) {
      var arg0=func.arguments[0];
      if(arg0) {
        if(arg0.constructor==Event || arg0.constructor==MouseEvent) {
          return arg0;
        }
      }
      func=func.caller;
    }
    return null;
  }

  var StringPlus = {
    ltrim : function(chars) {
      chars = chars || "\\s";
      return this.replace(new RegExp("^[" + chars + "]+", "g"), "");
    },
    rtrim : function(chars){
      chars = chars || "\\s";
      return this.replace(new RegExp("[" + chars + "]+$", "g"), "");
    },
    trim : function(chars){
      return this.ltrim(chars).rtrim(chars);
    },
    strip: function() {
      return this.replace(/^\s+/, '').replace(/\s+$/, '');
    },
    strlen : function(){
      var len, i;
      for(len = 0, i=0;i< this.length;i++) len += (this.charCodeAt(i) > 255)?2:1;
      return len;
    },
    utf8_encode : function(){ 
      var str = this;
      var utftext = "";
      for (var n = 0; n < str.length; n++) {
        var c = str.charCodeAt(n);
        if (c < 128) {
        	utftext += String.fromCharCode(c);
        }else if((c > 127) && (c < 2048)) {
          utftext += String.fromCharCode((c >> 6) | 192);
          utftext += String.fromCharCode((c & 63) | 128);
        }else {
          utftext += String.fromCharCode((c >> 12) | 224);
          utftext += String.fromCharCode(((c >> 6) & 63) | 128);
          utftext += String.fromCharCode((c & 63) | 128);
        }
      }
      return utftext;
    },
    utf8_decode : function() {
      var dectext = "";
      var i = 0;
      var c = c1 = c2 = 0;
      var str = this;
      while ( i < str.length ) {
      	c = str.charCodeAt(i);
      	if (c < 128) {
      	  dectext += String.fromCharCode(c);
      	  i++;
      	}else if((c > 191) && (c < 224)) {
      	  c2 = str.charCodeAt(i+1);
      	  dectext += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
      	  i += 2;
      	}else {
      	  c2 = str.charCodeAt(i+1);
      	  c3 = str.charCodeAt(i+2);
      	  dectext += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
      	  i += 3;
      	}
      }
      return dectext;
    },
    urlencode : function() {
      return escape(this.utf8_encode());
    },
    urldecode : function () {
      return unescape(this).utf8_decode();
    },
    base64_encode : function(){
      return this.base64.encode(this.utf8_encode());
    },
    base64_decode : function(){
      return this.base64.decode(this);
    },
//from http://www.webtoolkit.info    
    base64 : {
      base64key : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
      
      encode : function (str) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;
        while (i < str.length) {
          chr1 = str.charCodeAt(i++);
          chr2 = str.charCodeAt(i++);
          chr3 = str.charCodeAt(i++);
          
          enc1 = chr1 >> 2;
          enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
          enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
          enc4 = chr3 & 63;
          
          if (isNaN(chr2)) {
            enc3 = enc4 = 64;
          } else if (isNaN(chr3)) {
            enc4 = 64;
          }
          output = output +
          this.base64key.charAt(enc1) + this.base64key.charAt(enc2) +
          this.base64key.charAt(enc3) + this.base64key.charAt(enc4);
        }
        return output;
      },
      decode : function(str){
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;
        
        str = str.replace(/[^A-Za-z0-9\+\/\=]/g, "");
        while (i < str.length) {
          enc1 = this.base64key.indexOf(str.charAt(i++));
          enc2 = this.base64key.indexOf(str.charAt(i++));
          enc3 = this.base64key.indexOf(str.charAt(i++));
          enc4 = this.base64key.indexOf(str.charAt(i++));
          
          chr1 = (enc1 << 2) | (enc2 >> 4);
          chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
          chr3 = ((enc3 & 3) << 6) | enc4;
          
          output = output + String.fromCharCode(chr1);
          
          if (enc3 != 64) {
            output = output + String.fromCharCode(chr2);
          }
          if (enc4 != 64) {
            output = output + String.fromCharCode(chr3);
          }
        }
        return output.utf8_decode();
      }
    }
  }

  Object.extend(String.prototype, StringPlus);

//@sample alert(" abc嘸蝦 ".trim().utf8_encode().utf8_decode());
//        alert(" 嘸蝦米輸入法 \r\n ".trim().base64_encode().base64_decode());
//        alert(" url輸入法 \r\n ".urlencode().urldecode());
  
  
  if(!Number.prototype.NaN0) {
    Number.prototype.NaN0=function(n) {
      var num = (typeof(n) == 'undefined')?this:n;
      if(isNaN(num)) return 0;
      return num;
    }
  }
  
  var Args_setTimeout = function(callback, timeout, param) {
    var args = Array.prototype.slice.call(arguments,2);
    var _cb = function(){callback.apply(null,args);}
    setTimeout(_cb,timeout);
  }
/*]]>*/
//-->


