<!--
//Iframe http
  HTTPIFM = function(){ return this.initialize.apply(this, arguments);}
  HTTPIFM.prototype = {
//  SYSTEM      :  PHTTPIFM
//  PROGRAM     :  pascual
//  CREATE      :  2007.5.20
//  FILE NAME   :  objtool.js
//@sample  
//  try {
//    request = new HTTPIFM({'onComplete' :completeCallback, 'onStart' : startCallback,'custom': "abc", 'timeout': 1000, 'DropSelf': true });
//  } catch (err) {
//    alert(err.message);
//  }
//  request.setOpt({'onComplete' :completeCallback, 'onStart' : startCallback,'custom': "abc", 'timeout': 1000});
//  request.submit(document.main);
//  request.abort();
//function startCallback() { //before submit
//  alert("資料讀取中...");
//  return true;
//}
//
//function completeCallback(response) { // data loload
//  alert("conplete");
//  if(response.timeout) return alert("timeout");
//  alert("custom data:" + response.custom);
//  alert("content" + response.content);
//}
    initialize	: function(args) {
      this.name_id = HTTPIFM.prototype.name_id ++;
      this.iframe(args);
    },
    name_id : 0,
    iframe : function(args){
      var iname = 'iname' + this.name_id ++;
      if(!args.parent) {
        var d = document.createElement('DIV');
        d.setAttribute("id", "_IFMHTTP" + iname);
        if(!args.src) args.src = "about:blank";
        d.innerHTML = '<iframe style="display:none" src="'+args.src+'" id="'+iname+'" name="'+iname+'" \
onload="HTTPIFM.prototype.onload(this);'+ args.onload +'" \
></iframe>';
        this.main = document.body.appendChild(d);
      }else{
        args.parent.innerHTML += '<iframe frameborder="0" src="about:blank" style="'+ args.style +'" id="'+iname+'" name="'+iname+'" \
onload="HTTPIFM.prototype.onload(this);'+ ((args.onload)?args.onload:"") +'" \
marginheight=0 marginwidth=0 scrolling="auto"></iframe>';
        this.main = args.parent;
      }
      if(args && args.onComplete && typeof(args.onComplete) == 'function') {
        $(iname).onComplete = args.onComplete;
      }
      
      this.iFrame = this.main.lastChild;
      this.iFrame.args = args;
      return this.main;
    },
    setOpt : function(args) {
      this.iFrame = this.main.lastChild;
      this.iFrame.args = args;
      if(args && args.onComplete && typeof(args.onComplete) == 'function') {
        this.main.lastChild.onComplete = args.onComplete;
      }
    },
    setTimeout : function(timeout){ this.iFrame.args.timeout = timeout;},
    submit : function(obj) {
      var args = this.iFrame.args;
      if(this.iFrame.submiting) this.abort(this.main.id);
      this.iFrame.submiting = true;
      if(args.timeout) window.setTimeout('HTTPIFM.prototype.abort(\''+ this.main.id +'\')', args.timeout);
      this.iFrame = this.main.lastChild;
      if(args.onStart && typeof(args.onStart) == 'function') args.onStart(args.custom);
      if(obj && typeof(obj) != 'undefined') {
        obj.setAttribute('target', this.iFrame.name);
        obj.submit();
      }else if(args.src){
        var old_src = this.iFrame.src;
        args.src += (args.src.indexOf('?') != -1)?"&" + (new Date().getTime()):"?" + (new Date().getTime());
        this.iFrame.contentWindow.document.location.href=args.src;
      }
      return;
    },
    abort: function(id){
      var main = (id)?$(id):this.main;
      if(!main) return;
      var iFrame = main.firstChild;
      if(!iFrame.submiting) return;
      iFrame.submiting = false;
      if(iFrame && !iFrame.doComplete) {
        iFrame.onDrop = 1;
        var callback = iFrame.onComplete;
        if(id && callback) callback({'content': '', 'timeout' : true, 'custom' : iFrame.args.custom});
        if(iFrame.args.DropSelf) DropObj(main);
      }
    },
    drop : function(){ DropObj(this.main);},
    onload : function(obj){
      if(!obj || !$(obj.id)) return;
      var main = obj.parentNode;
      try {
        if (obj.contentDocument) {
          var doc = obj.contentDocument;
        } else if (obj.contentWindow) {
          var doc = obj.contentWindow.document;
        } else {
          var doc = window.frames[id].document;
        }
      }catch(err) {}
      if(doc && doc.location.href == "about:blank") return false;
      if(!obj.onComplete || typeof(obj.onComplete) != 'function') {
        obj.submiting = false;
        if(obj.args && obj.args.DropSelf) DropObj(main);
      }
      if (typeof(obj.onComplete) == 'function' && obj) {
        var content = (doc)? (doc.body.innerHTML):"";
        if(obj.onDrop) return;
        obj.submiting = false;
        obj.doComplete = 1;
        obj.onComplete({'content': content, 'timeout' : false, 'custom' : obj.custom});
        if(obj.args.DropSelf) DropObj(main);
      }
    }
  }

  HTTPXML = function(){ return this.initialize.apply(this, arguments);}
  HTTPXML.prototype = {
//  SYSTEM      :  PHTTPXML
//  PROGRAM     :  pascual
//  CREATE      :  2007.5.20
//  FILE NAME   :  objtool.js
//@sample
//  var request = new HTTPXML();
//  var request = new HTTPXML({'data': "a=3&b=4", 'onComplete', myxml, 'custom': 'customData', 'timeout':1000 });
//  request.setOpt({'onComplete' : myxml, 'custom': "customData", 'timeout' : 1000});
//  request.setStringData("name=中文&id=pchome");
//  request.get("get_xmlhttp.htm");
//  request.get("get_xmlhttp.htm?name=天空&id=online");
//  request.post("get_xmlhttp.htm");
//  request.post("get_xmlhttp.htm?name=天空&id=online");

    all : [], Id : 0,
    initialize	: function(args) {
      var xmlhttp;
      if (window.ActiveXObject) {
        try {
          xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
        } catch(e) {
          try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch(e2) {
            throw new Error("can't get XMLHttpRequest");
          }
        }
      } else if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
      } else {
        throw new Error("can't get XMLHttpRequest");
      }
      this.xmlhttp = xmlhttp;
      this.noCache = true;
      this.allData = [];
      this.Headers = [];
      this.requests = 0;
      this.contentType = "application/x-www-form-urlencoded; charset=UTF-8";
      if(args) this.setOpt(args);
      HTTPXML.prototype.all[HTTPXML.prototype.Id ++] = this;
    },
    setData : function(name, value) {
      this.allData[encodeURIComponent(name)] = encodeURIComponent(value);
    },
    setStringData : function(data) {
      if(!data) return;
      var tmp = data.split('&');
      for(var i=0; i < tmp.length; i ++) {
        var sdata = tmp[i].split('=', 2);
        this.setData(sdata[0], sdata[1]);
      }
    },
    setHeader : function(headName, headValue) {this.Headers[headName] = headValue;},
    setOpt : function(args, type) {
      if(!args && !type) return;
      if(!args) args = [];
      if(args.url) this.action = args.action;
      if(args.data) this.setStringData(args.data);
      if(args.onComplete) this.onComplete = args.onComplete;
      if(args.onStart) this.onStart = args.onStart;
      if(args.custom) this.custom = args.custom;
      if(args.timeout) this.timeout = args.timeout;
    },
    clearOpt : function() { this.allData = [];this.Headers = [];this.setOpt("", 'clear');},
    get : function(url) {this.onsubmit('GET', url);},
    post : function(url) { this.onsubmit('POST', url);},
    onsubmit : function (method, url) {
      var requestUri = "";
      var thisptr = this;
      var customData = this.custom;
      var requests = ++this.requests ;
      thisptr.complete = false;

      if(url.indexOf('?')) {
        var tmp = url.split('?', 2);
        url = tmp[0];
        this.setStringData(tmp[1]);
      }

      if(this.timeout) setTimeout(function() { thisptr.requestTimeout(customData, requests)}, this.timeout);
      for(var name in this.allData) requestUri += '&' + name +'=' + this.allData[name];
      if(method == 'GET' && requestUri) url += '?' + requestUri.substring(1);
      
      if(this.noCache) url += (url.indexOf('?') != -1)?"&" + (new Date().getTime()):"?" + (new Date().getTime());
      this.clearOpt();
      this.xmlhttp.open(method,url ,true);

      this.xmlhttp.onreadystatechange = function() {
        if(thisptr.xmlhttp.readyState==4) {
          if(thisptr.complete) return;
          thisptr.complete = true;
          if(thisptr.onComplete) thisptr.onComplete({'status': thisptr.xmlhttp.status, 'content': thisptr.xmlhttp.responseText, 'timeout' : false, 'custom' : customData, xmlhttp : thisptr.xmlhttp});
          thisptr.xmlhttp.onreadystatechange = JClass.emptyFunction;
        }
      }

      this.xmlhttp.setRequestHeader("Content-Type", this.contentType);
      this.xmlhttp.setRequestHeader("Cache-Control", "no-cache");
      if(requestUri && method == 'POST' ) {
      	this.xmlhttp.send(requestUri.substring(1));
      } else {
        this.xmlhttp.send("");
      }
    },
    requestTimeout : function(customData, requests) {
      var readyState = this.xmlhttp.readyState;
      if(this.requests != requests) return;
      if(this.complete || (readyState >= 1 && (readyState == 4))) return;
      this.complete = true;
      this.xmlhttp.onreadystatechange = JClass.emptyFunction;
      this.xmlhttp.abort();
      if(this.onComplete) {
        this.onComplete({'status': 'timeout', 'content': "", 'timeout' : true, 'custom' : customData, xmlhttp : this.xmlhttp});
      }
    }
  }

//Calender  
  var Calender = {
//  SYSTEM      :  Calender
//  PROGRAM     :  pascual
//  CREATE      :  2007.5.20
//  FILE NAME   :  objtool.js
  //@sample  
  //try {
  //　var cal = new Calender.create({id: 'calendera', url : 'calender.htm', onSelect : do_calender, x : 100, y: 100, display: true});
  //} catch(err) {
  //　alert(err.message);
  //}
  //var cal = new Calender.create({id: 'calendera', url : 'calender.htm'});
  //cal.moveto(100, 100);
  //cal.url("calender.htm");
  //cal.display();
  //cal.onSelect(do_calender);
  //cal.onSelect( function(s_date){document.getElementById("cal").value = s_date;})
  //calendera = Calender.getElementById('calendera')
    element : [],
    create : function(args) {
      if(!args || !args.id || $(args.id)) {
        if(!args) throw new Error("args Error");
        if($(args.id)) throw new Error("Object :" + args.id + " exist!!");
        return false;
      }
      var d = document.createElement('div');
      d.id = args.id + "Q";
      d.style.position = "absolute";
      d.style.visibility = "hidden";
      d.innerHTML = '<iframe frameborder="0" src="'+ args.url +'" id="'+args.id+'" \
  name="'+args.id+'" onload="Calender.resize(this);" \
  marginheight=0 marginwidth=0 scrolling=no></iframe>';
      if(document.getElementsByTagName('BODY').length==0) document.write('<body>');
      document.body.appendChild(d);
      this.div = d;
      this.iframe = $(args.id);
      this.iframe.display = function(w,h){
      	var obj = d;
      	var left = parseInt(obj.save_left);
      	if(left + ((left + w) / 2)  > (document.body.scrollLeft + document.body.clientWidth)) {
      	  obj.style.left = left - w;
      	}
      	var top = parseInt(obj.save_top);
      	if(top + ((top + h) / 2)  > (document.body.scrollTop + document.body.clientHeight)) {      	  
      	  obj.style.top = top - h;
      	}      	
      };
      Object.extend(this, Calender.prototype);
      this.moveto(args.x, args.y);
      if(args.onSelect) this.onSelect(args.onSelect);
      Calender.element[args.id] = this;
      if(args.display) this.display();
    },
    getElementById : function( id) { return this.element[id]},
    resize : function (obj, timeout){
      var subWeb = document.frames ? document.frames[obj.name].document : obj.contentDocument;
      if(obj != null && subWeb != null) { 
        
        obj.style.height = subWeb.body.scrollHeight;
        if(browser.msie) {
          obj.style.width = subWeb.body.scrollWidth;
        } else {
          obj.style.width = subWeb.body.scrollWidth + (subWeb.body.scrollWidth - subWeb.body.clientWidth);
        }
      }
      obj.display(parseInt(obj.style.width), parseInt(obj.style.height));
      if(!timeout) Args_setTimeout(this.resize, 500, obj, 500);
    },
    prototype : {
      moveto : function(x, y){
        if(x) this.div.style.left = x + "px";
        if(y) this.div.style.top = y + "px";
      },
      display : function(){
      	var obj = this.div;
      	obj.save_left = obj.style.left;
      	obj.save_top = obj.style.top;
      	var left = parseInt(obj.style.left);
      	if(left + ((left + obj.offsetWidth) / 2)  > (document.body.scrollLeft + document.body.clientWidth)) {
      	  obj.style.left = left - obj.offsetWidth;
      	}
      	var top = parseInt(obj.style.top);
      	if(top + ((top + obj.offsetHeight) / 2)  > (document.body.scrollTop + document.body.clientHeight)) {      	  
      	  obj.style.top = top - obj.offsetHeight;
      	}
      	obj.style.visibility = "visible";
      },
      hidden : function(){this.div.style.visibility = "hidden";},
      onSelect : function(fun){
        this.div.onSelect = fun;
      },
      url : function(url){ this.iframe.src = url;}
    }
  }
  

  
  CookieHaldle = function(path, domain){
//@sample 
//var jscookie = new CookieHaldle(); || new CookieHaldle("/", "pchome.com.tw");
//jscookie.setCookie("key1", "value1", 10);
//alert(jscookie.getCookie("key1"));
//jscookie.deleteCookie("key1");
//alert(jscookie.getCookie("key1"));
    if(typeof(path) != 'undefined') this.path = path;
    if(typeof(domain) != 'undefined') this.domain = domain;
    this.setCookie = function (name, value, seconds, path, domain) {
      if (typeof(seconds) != 'undefined') {
      	var date = new Date();
      	date.setTime(date.getTime() + (seconds*1000));
      	var expires = "; expires=" + date.toGMTString();
      } else {
      	var expires = "";
      }
      var c_path = path || this.path || "/";
      var c_domain = domain || this.domain;
      document.cookie = name+"="+value+expires+"; path=" + c_path + 
      ((c_domain)?("; domain=" + c_domain):"");
    }

    this.getCookie = function (name) {
      name = name + "=";
      var carray = document.cookie.split(';');
      for(var i=0;i < carray.length;i++) {
      	var c = carray[i];
      	while (c.charAt(0)==' ') c = c.substring(1,c.length);
      	if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
      }
      return null;
    }
    this.deleteCookie = function (name, path, domain) { return this.setCookie(name, "", -1, path, domain); }
  }

  AUTOSELECT = function(){ return this.initialize.apply(this, arguments);}
  
  AUTOSELECT.prototype = {
//  SYSTEM      :  AUTOSELECT
//  PROGRAM     :  pascual
//  CREATE      :  2007.7.20
//  FILE NAME   :  objtool.js
//@sample    
// ... <input id="cal" type=text value="" title="jaja" onkeyup="autodirection(this, event)"> ...
//  var autoslt = new AUTOSELECT("myautoSlt");
//  autoslt.bindInput($('cal'));
//  function dodirection(response){
//    if(response.custom.input.value != response.custom.search_word) return;
//    autoslt.clearItem();
//    var data = response.content.split('\n');
//    for(var i=0 ; i < data.length; i ++) {
//      autoslt.setItem(data[i]);
//    }
//    autoslt.directionKey(response.custom.search_word, "", response.custom.keyCode);
//    window.search_request.sendtype = 0;
//  }
//  
//  function autodirection(obj, ee) {
//    if(!window.search_request) {
//      window.search_request= new HTTPXML();
//      if(!window.search_request) return;
//      window.search_request.sendtype = 0;
//      window.search_request.dataLen = 0;
//    }
//    var request = window.search_request;
//    if(request.dataLen == obj.value.length) {
//      autoslt.directionKey(obj.value, ee);
//      return;
//    }
//    request.dataLen = obj.value.length;
//    var mydata = { 'keyCode': ee.keyCode?ee.keyCode : ee.which, 'search_word' : obj.value, 'input' : obj};
//    request.setOpt({'onComplete' : dodirection, 'custom': mydata, 'timeout' : 2000});
//    request.setStringData("word=" + obj.value);
//    request.get("search_dir.htm");
//  }
    initialize	: function(objId) {
      if(!objId) throw new Error("object id is null");
      if($('objId')) throw new Error("object " + objId + " exist!!");
      //this.styleMouseOver = "color:#ffffff;backgroundColor:#7070d4;cursor:default;";
      this.styleMouseOver = "color:#000000;backgroundColor:#FFE1B4;cursor:default;";
      this.styleMouseOut = "color:#000000;backgroundColor:#ffffff;cursor:default;";
      this._o = document.body.appendChild(document.createElement("DIV"));
      this._o.style.border = "1px solid #333333";
      this._o.setAttribute('id', objId);
      this._o.style.position = "absolute";
      this._o.style.visibility = "hidden";
      this._o.style.zIndex = "999";
      this._o.style.background = "#FFFFFF";
      this._o._mouseOver = 0;
      this._o.onmouseover = this.setOver;
      this._o.onmouseout = this.setOut;
      this._item = [];
      this._key = [];
      this._itemValue = [];
      this._width = 0;
      this._input = null;
      this._o.selectId = -1;
    },
    
    setOver : function() {this._mouseOver = 1;},
    setOut : function() {this._mouseOver = 0;},
    
    clearItem : function() {
      this._item = [];
      this._key = [];
      this._itemValue = [];
    },
    
    bindInput : function(obj, width) {
      if(!obj) {
        this._input = "";
        return;
      }
      if(this._input) this._input._autoObj = null;
      this._input = obj;

      var offInfo = getOffset(this._input);
      this._o.style.left = offInfo.left + "px";
      this._o.style.width = (width)?width : (this._input.offsetWidth + "px");
      this._o.style.top = (offInfo.top + offInfo.height - 3) + "px";
      obj._autoObj = this._o;
      obj.onfocus = this.displayOnInput;
      obj.onblur = this.hiddenMeOnInput;
    },
    
    displayOnInput : function () { 
      if(this._autoObj.childNodes.length) this._autoObj.style.visibility = ""; 
    },

    hiddenMeOnInput : function () {
      if(!this._autoObj._mouseOver) this._autoObj.style.visibility = "hidden";
    },
    
    setItem : function(item, itemValue) { 
      if(!this._key[item]) {
    	this._item.push(item);
    	(itemValue)?this._itemValue.push(itemValue):this._itemValue.push(item);
      }
    },
    
    itemMouseOver : function() {
      var s = this._autoEnv.overStyle.split(";");
      for(var i = 0; i < s.length; i ++) {
        var item = s[i].split(":");
        if(item[1]) eval("this.style." + item[0] + "='" + item[1] +"'");
      }
      if(this._autoEnv.main.selectId != -1 && this._autoEnv.main.selectId != this.childId) {
      	this._autoEnv.main.childNodes[this._autoEnv.main.selectId].onmouseout();
      }
      this._autoEnv.main.selectId = this.childId;
    },
    
    itemMouseOut : function() {
      var s = this._autoEnv.outStyle.split(";");
      for(var i = 0; i < s.length; i ++) {
        var item = s[i].split(":");
        if(item[1]) eval("this.style." + item[0] + "='" + item[1] +"'");
      }
    },

    appenItem : function (showValue, itemValue, reVal){
      var div = document.createElement("DIV");
      div._autoEnv = {
                      "main"      : this._o,
                      "overStyle" : this.styleMouseOver,
                      "outStyle"  : this.styleMouseOut,
                      "input"     : this._input,
                      "value"     : itemValue
                    };
      div.style.width = "100%";
      div.onmouseover = this.itemMouseOver;
      div.onmouseout = this.itemMouseOut;
      div.onclick = this.doClick;
      div.style.padding="0px";
      div.childId = this._o.childNodes.length;
      if(reVal) {
        var reg = new RegExp("(" + reVal +")", "i");
        var mark_value = itemValue.replace(reg , "<strong>$1</strong>");
        div.innerHTML = showValue.replace(itemValue, mark_value);
        //div.innerHTML = showValue.replace(reg , "<strong>$1</strong>");
      } else {
        div.innerHTML = showValue;
      }
      div.childId = this._o.childNodes.length;
      this._o.appendChild(div);
    },
    
    doClick : function() {
      this._autoEnv.input.value = this._autoEnv.value;
      this._autoEnv.main.style.visibility = "hidden";
    },
    
    bindItem : function(){
      for(var i= 0; i < this._item.length; i ++) {
      	this.appenItem(this._item[i], this._itemValue[i]);
      }
    },
    hidden : function (type) {
      if(!type) this.clearItem();
      this._o.style.visibility = "hidden";
    },
    
    display : function () {
      if(!this._input) return;
      if(!this._o.childNodes.length) {
        this._o.style.visibility = "hidden";
        return;
      }
      var offInfo = getOffset(this._input);
      this._o.style.left = (offInfo.left - 2) + "px";
      this._o.style.top = (offInfo.top + offInfo.height - 3) + "px";
      this._o.style.visibility = "visible";
    },
    
    dodirect : function(keyCode) {
      if(!this._o.childNodes.length) return;
      
      if(keyCode == 40) {
        if(this._o.selectId >= 0) this._o.childNodes[this._o.selectId].onmouseout();
        if(this._o.selectId + 1 >= this._o.childNodes.length) this._o.selectId = -1;
        this._o.childNodes[++this._o.selectId].onmouseover();
        this._input.value = this._o.childNodes[this._o.selectId]._autoEnv.value;
      } else if(keyCode == 38) {
        if(this._o.selectId >= 0) this._o.childNodes[this._o.selectId--].onmouseout();
        if(this._o.selectId < 0) this._o.selectId = this._o.childNodes.length -1;
        this._o.childNodes[this._o.selectId].onmouseover();
        this._input.value = this._o.childNodes[this._o.selectId]._autoEnv.value;
      } else if(keyCode == 13) {
        if(this._o.selectId >=0 && this._o.selectId < this._o.childNodes.length) {
          this._input.value = this._o.childNodes[this._o.selectId]._autoEnv.value;
          this.hidden();
        }
      }
    },
    
    directionKey : function (val, ee, keyCode) {
      var hasItem = 0;
      if(!this._input) return;

      if(ee || keyCode) {
        var _k = (keyCode)?(keyCode):(ee.keyCode?ee.keyCode : ee.which);
        if( _k == 38 || _k == 40 || _k == 13 ) return this.dodirect(_k);
      }
      
      this._o.selectId = -1;
      this._o.innerHTML = "";
      if(val.length ==0) {
        this.hidden();
        return;
      }
      //var re = new RegExp("^" + val +"", "i");
      var re = new RegExp(val, "i");
      
      for(var i= 0; i < this._item.length; i ++) {
      	if(re.exec(this._itemValue[i])) {
      	  this.appenItem(this._item[i], this._itemValue[i], val);
      	  hasItem = 1;
      	}
      }
      
      if(!hasItem) {
        this._o.style.visibility = "hidden";
        return;
      }
      this.display();
    }
  }
//-->
