

Object.extend = function(destination, source){
  for (property in source)
    destination[property] = source[property];
  return destination;
};


if (window.HTMLElement){
  HTMLElement.prototype.__defineSetter__("innerText",function(sText) { var parsedText=document.createTextNode(sText); this. TML=parsedText; return parsedText; });
  HTMLElement.prototype.__defineGetter__("innerText",function(){ var r=this.ownerDocument.createRange(); r.selectNodeContents(this); return r.toString(); });
  HTMLElement.prototype.__defineGetter__("children", function(){
    for (var i = 0; i < this.childNodes.length; i++) {
      var node = this.childNodes[i];
      if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
        this.removeChild(node);
    }
    return this.childNodes;
  });
}

var Element = {
  next : function(elem) {
    var n = elem;
    do {
       n = n.nextSibling;
    } while (n && n.nodeType != 1)
    return n;
  },
  prev : function(elem) {
    var n = elem;
    do{
       n = n.previousSibling;
    } while (n && n.nodeType != 1)
    return n;
  },
  show : function(elem, arg) {
    if (navigator.isIE()) if (arg=="table" || arg=="table-row" || arg=="table-cell") arg = "block";
    elem.style.display = (typeof(arg) == "undefined") ? "" : arg;

  },
  hide : function(elem) {
    elem.style.display = "none";
  },
  remove : function(elem) {
    elem.parentNode.removeChild(elem);
  },
  addClass : function(elem, className) {
    if (!this.hasClass(elem, className)){
      var arr = elem.className.split(" ");
      arr.push(className);
      elem.className = arr.join(" ");
    }
  },
  removeClass :function(elem, className) {
    if (this.hasClass(elem, className)){
      var arr = elem.className.split(" ");
      arr.remove(className);
      elem.className = arr.join(" ");
    }
  },
  hasClass : function(elem, className) {
     var arr = elem.className.split(" ");
     return arr.inArray(className);
  },
  contains : function(elem, find){
    do {
      if (find == elem)
      {
        return true;
      }
    } while(find = find.parentNode)
    return false;
  },
  getPosition : function(elem) {
    var valueT = 0, valueL = 0;
    do {
      valueT += elem.offsetTop  || 0;
      valueL += elem.offsetLeft || 0;
      elem = elem.offsetParent;
    } while (elem);
    var pos = {top:valueT,left:valueL};
    return pos;
  },
  getStyle: function(element, style) {
    element = $(element);
    style = style == 'float' ? 'cssFloat' : style;
    var value = '';
    try {
        var value = element.style[style];
    } catch(ex) {
        return value;
    }
    if (!value) {
      if(element.currentStyle) {
        value = element.currentStyle[style];
      } else {
        var css = document.defaultView.getComputedStyle(element, null);
        value = css ? css[style] : null;
      }
    }
    if (style == 'opacity') return value ? parseFloat(value) : 1.0;
    return value == 'auto' ? null : value;
  },
  setSelectable: function(elem, selectable)
  {
    if (navigator.isFirefox()) {
      if (selectable)
        elem.style.MozUserSelect = "";
      else
        elem.style.MozUserSelect = "none";
    }
    else {
      if (selectable)
        Event.stopObserving(elem, "selectstart", this._falseFunction);
      else
        Event.observe(elem, "selectstart", this._falseFunction);
    }
  },
  _falseFunction: function() {
    return false;
  },
  cleanWhitespace: function(element) {
    for (var i = 0; i < element.childNodes.length; i++) {
      var node = element.childNodes[i];
      if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) 
        element.removeChild(node);
    }
  }
};


if (window.Event) {
  Event.prototype.__defineSetter__("returnValue",function(e){ if(!e)this.preventDefault(); return e;});
  Event.prototype.__defineGetter__("srcElement",function(){ var node=this.target;while(node.nodeType!=1){node=node.parentNode};return node;});
  Event.prototype.__defineSetter__("cancelBubble",function(b){ if(b)this.stopPropagation(); return b; });
} else {
  var Event = new Object();
}


Object.extend(String.prototype, {
  trim : function() { return this.replace(/^\s*(.*?)\s*$/, '$1'); },
  escape : function() { return this.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');},
  isEmpty : function() { return (this.trim() == ''); },
  isEmail : function() { var reg = /^([a-z0-9+_]|\-|\.|\-)+@(\w+\.)+[a-z]{2,4}$/i; return reg.test(this); },
  isDate : function() { var reg = /^\d{4}-(0?[1-9]|1[0-2])-(0?[1-9]|[1-2]\d|3[0-1])$/; return reg.test(this); },
  isTime : function() { var reg = /^([0-1]\d|2[0-3]):[0-5]\d:[0-5]\d$/; return reg.test(this); }
});


Object.extend(navigator, {
  isIE : function() { return this.userAgent.toLowerCase().indexOf("msie") != - 1; },
  isFirefox : function() { return this.userAgent.toLowerCase().indexOf("firefox") != - 1; },
  isSafari : function() { return this.userAgent.toLowerCase().indexOf("safari") != - 1; },
  isOpera : function() { return this.userAgent.toLowerCase().indexOf("opera") != - 1; }
});


Object.extend(document, {
  getCookie : function(sName) {
    var aCookie = this.cookie.split("; ");
    for (var i=0; i < aCookie.length; i++){
      var aCrumb = aCookie[i].split("=");
      if (sName == aCrumb[0]) return decodeURIComponent(aCrumb[1]);
    }
    return null;
  },

  setCookie : function(sName, sValue, sExpires) {
    var sCookie = sName + "=" + encodeURIComponent(sValue);
    if (sExpires != null) sCookie += "; expires=" + sExpires;
    this.cookie = sCookie;
  },

  removeCookie : function(sName) {
    this.cookie = sName + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
  },

  require : function(path, callback, type){
    var s,i;
    var id = path.replace(".","").replace("/","");

    if (!type || type == "js"){
      var ss = this.getElementsByTagName("script");
      for(i =0;i < ss.length; i++){
        if(ss[i].src && ss[i].src.indexOf(path) != -1)return ss[i];
      }

      s      = $ce("script");
      s.id   = id;
      s.type = "text/javascript";
      s.src  = path;
    }
    else {
      var ss = this.getElementsByTagName("link");
      for(i =0;i < ss.length; i++){
        if(ss[i].src && ss[i].src.indexOf(path) != -1)return ss[i];
      }

      s = $ce("link");
      s = document.createElement("link");
      s.rel = "stylesheet";
      s.type = "text/css";
      s.href = path;
      s.disabled = false;
    }
    var head = this.getElementsByTagName("head")[0];
    head.appendChild(s);
    if (callback) {
      if (!navigator.isIE() && type == "css") {
        window.setTimeout(function(){callback.call()}, 500);
      }
      else {
        s.onload = s.onreadystatechange= function(){
          if(this.readyState && this.readyState=="loading")return;
          callback.call();
        }
      }
    }
  }
});


Object.extend(Array.prototype, {
  isEmpty : function() { return (this.length == 0); },
  inArray : function(item) { return (this.itemIndex(item) > -1); },
  remove : function(item, num) { var removed = 0;
  for (var i=0; i<this.length; i++) {
    if (this[i] == item) {
      this.splice(i, 1);
      if (num > 0 && num >= removed) break;
        removed++;
      }
    }
  },
  itemIndex : function(item) { var reval = -1; for (var i=0; i<this.length; i++) { if (this[i] == item) { reval = i; break; } } return reval; }
});

Object.extend(Event, {
  pointerX: function(event) {
    return event.pageX || (event.clientX +
      (document.documentElement.scrollLeft || document.body.scrollLeft));
  },
  pointerY: function(event) {
    return event.pageY || (event.clientY +
      (document.documentElement.scrollTop || document.body.scrollTop));
  },
  observers: false,
  _observeAndCache: function(element, name, observer, useCapture) {
    if (!this.observers) this.observers = [];
    if (element.addEventListener) {
      this.observers.push([element, name, observer, useCapture]);
      element.addEventListener(name, observer, useCapture);
    } else if (element.attachEvent) {
      this.observers.push([element, name, observer, useCapture]);
      element.attachEvent('on' + name, observer);
    }
  },
  observe: function(element, name, observer, useCapture) {
    useCapture = useCapture || false;

    if (name == 'keypress' &&
        ((navigator.appVersion.indexOf('AppleWebKit') > 0)
        || element.attachEvent))
      name = 'keydown';

    this._observeAndCache(element, name, observer, useCapture);
  },
  stopObserving: function(element, name, observer, useCapture) {
    useCapture = useCapture || false;

    if (name == 'keypress' &&
        ((navigator.appVersion.indexOf('AppleWebKit') > 0)
        || element.detachEvent))
      name = 'keydown';

    if (element.removeEventListener) {
      element.removeEventListener(name, observer, useCapture);
    } else if (element.detachEvent) {
      element.detachEvent('on' + name, observer);
    }
  }
});

if (window.HTMLTableRowElement)
  HTMLTableRowElement.prototype.__defineGetter__('rowIndex', function() { var index = -1; var table = this.parentNode.parentNode; for (i = 0; i < table.rows.length; i ++ ) { if (table.rows[i] == this) { index = i; break; } } return index; });


if (!window.HTMLElement) {
  window['innerHeight'] = { valueOf:function(){return document.documentElement.clientHeight;}, toString:function(){return document.documentElement.clientHeight;} };
  window['innerWidth'] = { valueOf:function(){return document.documentElement.clientWidth;}, toString:function(){return document.documentElement.clientWidth;} };
};



if (typeof(Function.prototype.call) != "function") {
  Function.prototype.call = function (obj) {
    obj._554fcae493e564ee0dc75bdf2ebf94ca = this;
    var args = [];
    for (var i = 0; i < arguments.length - 1; i++){
      args[i] = "arguments[" + (i + 1) + "]";
    }
    var result = eval("obj._554fcae493e564ee0dc75bdf2ebf94ca(" + args.join(",") + ");");
    delete obj._554fcae493e564ee0dc75bdf2ebf94ca;

    return result;
  }
}
Function.prototype.bind = function(object) { var __method = this; return function(){__method.apply(object, arguments); }};

function $(id, win) {
  var elem;
  if (typeof win === 'undefined') win = window;
  elem = (typeof(id)=="string") ? win.document.getElementById(id) : elem = id;

  return elem;
}

function $ce(tagName, doc) {
  if (typeof doc === 'undefined') doc = document;
  var newElem = doc.createElement(tagName);
  return newElem;
}

function $class(className, parentElement, tagName) {
  var elements = new Array();
  var children = ($(parentElement) || document.body).getElementsByTagName(tagName||'*');
  for(var i=0; i<children.length; i++) {
    if (children[i].className.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
      elements.push(children[i]);
  }
  elements.item = function(idx){
   return this[idx];
  };
  return elements;
}


function fixEvent(e, win) { if (typeof win === 'undefined') win = window; var evt = (typeof e == "undefined") ? win.event : e; return evt;}
function confirm_redirect(msg, url) { if (confirm(msg)) location.href=url; }


var ui = {};


var Ajax = {
  
  _onComplete : function () {},
  _onRunning : function () {},
  method : 'GET',

  
  setReturnType : function (type) {
    if (typeof(type) == 'string' && (type.toUpperCase() == 'JSON' || type.toUpperCase() == 'XML' || type.toUpperCase() == 'TEXT')) {
      this.returnType = type.toUpperCase();
  }},

  
  addVal : function (key, val) {
    if (!this.data) this.data = new Object;
    this.data[key] = val;
  },

  
  call : function (url, callback, method, asyn) {
    
    if (typeof(method) == 'string' && (method.toUpperCase() == 'GET' || method.toUpperCase() == 'POST'))
      method = method.toUpperCase();
    else{
      if (data && data.length>0)
        method = 'POST';
      else
        method = 'GET';
    }
    
    this.method = method;

    
    var data = '';
    if (this.data) {
      data += this.joinData(this.data);
      delete(this.data);
    }
    
    var returnType = '';
    if (this.returnType) {
      returnType = this.returnType;
      delete(this.returnType);
    }else
      returnType = 'JSON';

    if (asyn != undefined)
      asyn = asyn ? true : false;
    else
      asyn = true;


    if (method == "GET"){
      url += url.indexOf("?") >= 0 ? "&" : "?";
      if (data && data.length > 0) {url += data; data =''}
    }

    
    if (window.XMLHttpRequest) {
        var xhr = new XMLHttpRequest();
    }else{
        var MSXML = ['MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP'];
        for(var n = 0; n < MSXML.length; n ++) {
            try {
                var xhr = new ActiveXObject(MSXML[n]);
                break;
            } catch(e) {}
    }}

        try {
      if (typeof(this._onRunning) == 'function') this._onRunning();
      xhr.open(method, url, asyn);
      xhr.setRequestHeader('Ajax-Request', "1");
      if (method == 'POST')
          xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
      
      if (asyn) {
        
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4) {
                if (typeof(Ajax._onComplete) == 'function') Ajax._onComplete();
                if (xhr.status == 200) {
                  if (typeof(callback) == 'function') {
                    var result = Ajax.parseResult(xhr, returnType);
                    callback(result, xhr.responseText);
                }}else{                  throw("An HTTP error " + xhr.status + "occurred. \n" + url);
                }
                xhr = null;
            }
        };
        if (xhr != null) xhr.send(data);
      }else{
        
       
       xhr.send(data);
       if (typeof(Ajax._onComplete) == 'function') Ajax._onComplete();
       if (xhr.status == 200) {
         var result = this.parseResult(xhr, returnType);

         if (typeof(callback) == 'function') callback(result, xhr.responseText);
         return result;
        }else{          throw("An HTTP error " + xhr.status + "occurred. \n" + url);
      }}
    }catch(e){alert(e);}
  },

  joinData : function (param, pre){
    var returnVal = '';
    if (typeof(param) == 'string') {
        var pos = param.indexOf('=');
        if (pos > 0)
          returnVal += this.encode(param.substr(0, pos)) + '=' + this.encode(param.substr(pos+1)) + '&';
        else
          returnVal += 'noindex[]=' + this.encode(param) + '&';
    }
    else if (typeof(param) == 'object') {
      for (n in param) {
        switch (typeof(param[n])) {
          case 'string':
            if (pre == undefined) {
              returnVal += n + '=' + this.encode(param[n]) + '&';
            } else {
              returnVal += pre + '[' + n + ']=' + this.encode(param[n]) + '&';
            }
            break;

          case 'number':
            if (pre == undefined) {
              returnVal += n + '=' + param[n] + '&';
            } else {
              returnVal += pre + '[' + n + ']=' + param[n] + '&';
            }
            break;

          case 'boolean':
            var val = param[i] ? 1 : 0;
            if (pre == undefined) {
              returnVal += n + '=' + val + '&';
            } else {
              returnVal += pre + '[' + n + ']=' + val + '&';
            }
            break;

          case 'object':
            if(param[n].length == 0){
              if (pre == undefined) {
                returnVal += n + '=&';
              } else {
                returnVal += pre + '[' + n + ']=&';
            }}else{
              if (pre == undefined) {
                returnVal += this.joinData(param[n], n);
              } else {
                returnVal += this.joinData(param[n], pre + '[' + n + ']');
              }
            }
            break;

          default:
            
        }
      }
    }
    if (pre == undefined)  returnVal = returnVal.substr(0, returnVal.length -1);    return returnVal;
  },

  encode : function(str) {
    return encodeURIComponent(str);
  },

  
  parseResult : function (xhr, returnType) {
    var result;
    if (returnType == 'JSON') {
      
      result = Ajax.parseJSON(xhr.responseText);
      if (!result) result = {};
    }
    else if (returnType == 'TEXT') {
      result = xhr.responseText;
    }
    else if (returnType == 'XML') {
      result = xhr.responseXML;
    }

    return result;
  },

  parseJSON : function (filter) {
    try {
        if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.
                test(filter)) {
            var j = eval('(' + filter + ')');
            if (typeof filter === 'function') {

                function walk(k, v) {
                    if (v && typeof v === 'object') {
                        for (var i in v) {
                            if (v.hasOwnProperty(i)) {
                                v[i] = walk(i, v[i]);
                    }}}
                    return filter(k, v);
                }
                j = walk('', j);
            }
            return j;
        }
    } catch (e) {}}};
if ( ! Object.prototype.toJSONString) {
    Array.prototype.toJSONString = function () {
        var a = ['['],            b,            i,            l = this.length,
            v;
        function p(s) {
            if (b) {
              a.push(',');
            }
            a.push(s);
            b = true;
        }

        for (i = 0; i < l; i ++) {
            v = this[i];
            switch (typeof v) {

            case 'undefined':
            case 'function':
            case 'unknown':
                break;

            case 'object':
                if (v) {
                    if (typeof v.toJSONString === 'function') {
                        p(v.toJSONString());
                    }
                } else {
                    p("null");
                }
                break;

            default:
                p(v.toJSONString());
            }
        }
        a.push(']');
        return a.join('');
    };

    Boolean.prototype.toJSONString = function () {
        return String(this);
    };

    Date.prototype.toJSONString = function () {
        function f(n) {
            return n < 10 ? '0' + n : n;
        }

        return '"' + this.getFullYear() + '-' +
                f(this.getMonth() + 1) + '-' +
                f(this.getDate()) + 'T' +
                f(this.getHours()) + ':' +
                f(this.getMinutes()) + ':' +
                f(this.getSeconds()) + '"';
    };

    Number.prototype.toJSONString = function () {
        return isFinite(this) ? String(this) : "null";
    };

    Object.prototype.toJSONString = function () {
        var a = ['{'],            b,            k,            v;
        function p(s) {
            if (b) {
                a.push(',');
            }
            a.push(k.toJSONString(), ':', s);
            b = true;
        }
        for (k in this) {
            if (this.hasOwnProperty(k)) {
                v = this[k];
                switch (typeof v) {
                case 'undefined':
                case 'function':
                case 'unknown':
                    break;
                case 'object':
                    if (v) {
                        if (typeof v.toJSONString === 'function') {
                            p(v.toJSONString());
                        }
                    } else {
                        p("null");
                    }
                    break;
                default:
                    p(v.toJSONString());
                }
            }
        }
        a.push('}');
        return a.join('');
    };

    (function (s) {
        var m = {
            '\b': '\\b',
            '\t': '\\t',
            '\n': '\\n',
            '\f': '\\f',
            '\r': '\\r',
            '"' : '\\"',
            '\\': '\\\\'
        };

        s.parseJSON = function (filter) {
            try {
                if (/^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.
                        test(this)) {

                    var j = eval('(' + this + ')');
                    if (typeof filter === 'function') {

                        function walk(k, v) {
                            if (v && typeof v === 'object') {
                                for (var i in v) {
                                    if (v.hasOwnProperty(i)) {
                                        v[i] = walk(i, v[i]);
                                    }
                                }
                            }
                            return filter(k, v);
                        }

                        j = walk('', j);
                    }
                    return j;
                }
            } catch (e) {
            }
            throw new SyntaxError("parseJSON");
        };

        s.toJSONString = function () {          var _self = this.replace("&", "%26");

          if (/["\\\x00-\x1f]/.test(this)) {
              return '"' + _self.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                  var c = m[b];
                  if (c) {
                      return c;
                  }
                  c = b.charCodeAt();
                  return '\\u00' +
                      Math.floor(c / 16).toString(16) +
                      (c % 16).toString(16);
              }) + '"';
          }
          return '"' + _self + '"';
        };
    })(String.prototype);
}


window.threadList = {};
ui.effect = {
  FadeTo:function(element, start, end, duration, callback){
    var self = element, step = 0;
    if(end == undefined){
        end=start;
        duration=0;
    }
    var tid = "___a2d3e" + Math.floor(Math.random()*10+1);

    if(duration<=0) start=end;
    else step=10*(end-start)/duration;
    function t(){
        start+= step;
        if((start-end)*step>=0)start=end;

        self.style.filter='alpha(opacity='+Math.round(start)+')';

        if(!self.style.filters) self.style.MozOpacity=Math.round(start)/100;
        if(start!=end)
           window.threadList[tid] = window.setTimeout(arguments.callee,10);
        else if(callback) callback.call();

    };

    window.threadList[tid] = window.setTimeout(t, 10);
    return tid;
  },
  _setOpacity:function(elem, value)
  {
    elem.style.filter='alpha(opacity='+Math.round(value)+')';
    if(!elem.style.filters) elem.style.MozOpacity=Math.round(value)/100;
  },
  ResizeTo:function(element,width, height, duration){
    var self = element, step = 0;
    var startWidth = self.offsetWidth;
    var startHeight = self.offsetHeight;

    stepW = 10 * (width-self.offsetWidth)/duration;
    stepH = 10 * (height-self.offsetHeight)/duration;

    function t(){
      startWidth += stepW;
      startHeight += stepH;

      if((startWidth-width)*stepW>=0)startWidth=width;
      if((startHeight-height)*stepH>=0)startHeight=height;

      self.style.width = parseInt(startWidth) + "px";
      self.style.height = parseInt(startHeight) + "px";

      if(startWidth!=width && startHeight != height)window.setTimeout(arguments.callee,10);
    };
    window.setTimeout(t,10);
  },
  SlideUp: function(){},
  ResizeHeightTo:function(element, height, duration, callback){
    var self = element, step = 0;
    var startHeight = self.offsetHeight;

    step = parseInt(10 * (height-self.offsetHeight)/duration);
    s = true;
    if (step>0) {
        s = false;
    }
    function t(){
        startHeight += step;
        if((s && (startHeight-height) < 0) || (!s && (startHeight-height) > 0)) {
            startHeight=height;
        }
        self.style.height = startHeight + "px";
        if(startHeight != height)window.setTimeout(arguments.callee,10);
        else if(callback) callback();
    };
    window.setTimeout(t,10);
  }
  ,MoveTo:function(element, x, y, duration){
    var self = element, step = 0;
    var startLeft = Element.getPosition(self).left;
    var startTop = Element.getPosition(self).top;

    stepL = 10 * (x-self.offsetWidth)/duration;
    stepH = 10 * (height-self.offsetHeight)/duration;

    function t(){
      startWidth += stepW;
      startHeight += stepH;

      if((startWidth-width)*stepW>=0)startWidth=width;
      if((startHeight-height)*stepH>=0)startHeight=height;

      self.style.width = parseInt(startWidth) + "px";
      self.style.height = parseInt(startHeight) + "px";

      if(startWidth!=width && startHeight != height)window.setTimeout(arguments.callee,10);
    };
    window.setTimeout(t,10);
  },
  blink : function(element, time) {
    var count = 0;
    function t()
    {
      if (count>=time)
      {
        ui.effect._setOpacity(element, 100);
        return;
      }
      count++;
      if (count%2 == 0)ui.effect._setOpacity(element, 90);else ui.effect._setOpacity(element, 30);
      window.setTimeout(arguments.callee, 120);
    }
    window.setTimeout(t,10);
  }
  ,scroll:function(direction, element, distance, duration, callback){
    var self = element;
    var step = 10*(distance)/duration;
    var scrollLeft = self.scrollLeft;
    var target = distance;
    var callback = callback ? callback : new Fucnction();
    function t() {
        switch(direction){
            case 'left':
                if(self.scrollLeft > (target+scrollLeft)) {
                  self.scrollLeft = distance+scrollLeft;
                  callback.call();
                  return;
                };
                self.scrollLeft += step;
                break;
            case 'right':
                self.scrollLeft -= step;
                if (self.scrollLeft<=0 || self.scrollLeft<=(scrollLeft - distance)) {
                  self.scrollLeft = scrollLeft - distance;
                  callback.call();
                  return;
                };
                break;
        };
        window.setTimeout(arguments.callee,10);
    };
    window.setTimeout(t,10);
  },
  shadow: function (obj) {
    var shadow = $ce('div');
    shadow.className     = 'ECM_shadow_layer';
    shadow.style.cssText = 'background:#aaaaaa none repeat scroll 0%;';
    shadow.style.zIndex= obj.style.zIndex;    shadow.style.height= obj.style.height;
    shadow.style.top   = obj.style.top;
    shadow.style.left  = obj.style.left;
    shadow.style.position = 'fixed';
    if (navigator.isIE()) {
      shadow.style.position = 'absolute';
      Event.observe(window, 'scroll', function () {
        shadow.style.top= (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop) + 100;
      });
    }
    obj.style.position = 'relative';
    obj.style.left    = '-3px';
    obj.style.top     = '-3px';
    shadow.appendChild(obj);
    return shadow;
  }
};

document.require("js/ui.dialog/style.css", null, "css");

var DIALOG_WARNING = 0;
var DIALOG_MESSAGE = 1;
var DIALOG_CONFIRM = 2;
var DIALOG_USERDEF = 3;
var DIALOG_PROMPT  = 4;
var DIALOG_LOGINFORM = 5;
var DIALOG_TIP = 6;
var DIALOG_PROGRESS = 7;

var DIALOG_ACTION_CLOSE = 10;

Dialog = function (dType) {
  var self = this;
  this.type = dType;
  this.body       = null;
  this.className  = null;
  this.content  = 'Undefine';
  this.title    = '';
  this.width    = 300;
  this.height    = 0;
  this.isLockScreen = true;
  this.summary   = '';
  this.inputSize = 25;
  this.inputType = 'text';
  this.value = '';
  this.locker  = null;
  this.isShadow = true;
  this.isSingle = false;
  this.inDoc    = false;
  this.isDraggable = true;
  this.refer   = null;
  this.autoCloseTime = 0;
  this.timeoutID = null;
  this.fadeTime   = 0;
  this.okBtnName = lang.confirm ? lang.confirm : 'OK';
  this.cancelBtnName = lang.cancel ? lang.cancel : 'Cancel';
  this.closeBtnName = lang.close ? lang.close : 'X';
  this.value = '';
  this.components = {
    icon    : 'info',
    buttons : [],
    inputs  : [],
    summary : null,
    titleBar: null,
    titleText:null,
    closeButton:null,
    contentBody:null,
    messageBody:null,
    messageText:null,
    buttonsBar :null,
    progressBar:null
  };
  this.onChange = function () {
    self.value = this.value;
  };
  this.onClose = function () { return true; };
  this.onOK    = function () {
    self.close();
  };
  this.onLoad  = function () {

  };
  this.createDialogBody();
};
Dialog.prototype.init       = function () {
  switch (this.type) {
  case DIALOG_CONFIRM:
    this.addButton(this.okBtnName, this.onOK, true);
    this.addButton(this.cancelBtnName, DIALOG_ACTION_CLOSE);
    break;
  case DIALOG_PROMPT:
    this.value= '';
    this.content += ': ';
    this.addButton(this.okBtnName, this.onOK, true);
    this.addButton(this.cancelBtnName, DIALOG_ACTION_CLOSE);
    this.addInput(this.inputSize, this.inputType);
    this.addSummary(this.summary);
    break;
  case DIALOG_WARNING:
    this.components.icon = 'warn';
    this.addButton(this.okBtnName, this.onOK, true);
    this.addButton(this.cancelBtnName, DIALOG_ACTION_CLOSE);
    break;
  case DIALOG_MESSAGE:
    this.addButton(this.okBtnName, this.onOK, true);
    break;
  case DIALOG_USERDEF:
    break;
  case DIALOG_TIP:
    this.isLockScreen = false;
    this.isShadow     = false;
    this.isDraggable  = false;
    this.className    = 'ECM_dialog_tip';
    break;
  case DIALOG_PROGRESS:
    this.showProgressCtrl();
    break;
  default:
    break;
  }
};
Dialog.prototype.createDialogBody = function () {
  

  
  this.body = $ce('div');
  
  this.components.titleBar = $ce('h3');
  this.components.titleText = $ce('span');
  this.components.closeButton = $ce('span');
  
  this.components.contentBody = $ce('div');
  this.components.messageBody = $ce('div');
  this.components.messageText = $ce('div');
  this.components.buttonsBar  = $ce('div');

  this.body.appendChild(this.components.titleBar);
  this.body.appendChild(this.components.contentBody);

  this.components.titleBar.appendChild(this.components.titleText);
  this.components.titleBar.appendChild(this.components.closeButton);

  this.components.contentBody.appendChild(this.components.messageBody);
  this.components.messageBody.appendChild(this.components.messageText);
  this.components.contentBody.appendChild(this.components.buttonsBar);
};
Dialog.prototype.setSize   = function (w, h) {
  if (!isNaN(w)) {
    this.width = w;
  }
  if (!isNaN(h)) {
    this.height = h;
  }
};
Dialog.prototype.setStyle  = function (c) {
  if (c) {
    this.className = c;
  }
};
Dialog.prototype.setContent = function (t, c) {
  this.title = t;
  this.content = c;
};
Dialog.prototype.changeContent = function (t, c) {
  this.components.titleText.innerHTML = t;
  this.components.messageText.innerHTML = c;
};
Dialog.prototype.addButton  = function (n, e, strike, close) {
  var self = this;
  var b = $ce('input');
  b.type = 'button';
  b.value = n;

  if (strike)
  {
    b.className = 'ECM_dialog_strike_button';
  }
  switch (e) {
  case DIALOG_ACTION_CLOSE:
    b.onclick = this.close.bind(this);
    break;
  default:
    if (close) {
      b.onclick = function () {
        if(e)e();
        self.close();
      };
    }
    else {
      if(e)b.onclick = e;
    }
    break;
  }
  if (!this.inDoc) {
    this.components.buttons.push(b);
  }
  else {
    this.components.buttonsBar.appendChild(b);
    if (this.components.buttonsBar.style.display == 'none') {
      this.components.buttonsBar.style.display = '';
    }
  }
};
Dialog.prototype.addInput  = function (size, type) {
  if (!type) {
    type = 'text';
  }
  if (!size) {
    size = 25;
  }
  var _ipt = $ce('input');
  _ipt.type = type;
  _ipt.size = size;
  _ipt.onchange = this.onChange;
  this.components.inputs.push(_ipt);
};
Dialog.prototype.addSummary = function (text) {
  var _s = $ce('div');
  _s.className = 'ECM_dialog_summary';
  _s.innerHTML = text;
  this.components.summary = _s;
};
Dialog.prototype.showProgressCtrl = function () {
  this.components.progressCtrl = $ce('div');
  this.components.progressCtrl.className = 'ECM_dialog_progress_bar';
  this.components.icon = null;
  this.components.progressDetail = $ce('div');
  this.components.progressDetail.className = 'ECM_dialog_progress_detail';
  this.components.messageBody.style.textAlign = 'center';
  this.components.messageBody.appendChild(this.components.progressCtrl);
  this.components.messageBody.appendChild(this.components.progressDetail);
};
Dialog.prototype.addResult = function (n, r, e) {
  var l = $ce('div');
  var rzt = $ce('span');
  var m = $ce('span');
  l.className = 'ECM_dialog_progress_result_item';
  rzt.innerHTML = r;
  rzt.className = 'result';
  m.innerHTML = n;
  l.appendChild(rzt);
  l.appendChild(m);
  if (e) {
    e();
  }
  this.components.progressDetail.appendChild(l);
};
Dialog.prototype.hideProgressCtrl = function () {
  this.components.progressCtrl.style.display = 'none';
};
Dialog.prototype.pointTo     = function (o) {
  this.refer  = o;
};
Dialog.prototype.show      = function () {
  this.init();
  var self = this;

  
  
  this.components.titleText.innerHTML = this.title;
  this.components.closeButton.innerHTML = this.closeBtnName;
  this.components.closeButton.title   = this.closeBtnName;
  this.components.closeButton.onclick = this.close.bind(this);

  
  this.components.messageText.innerHTML = this.content;

  
  this.body.className = this.className ? this.className : 'ECM_dialog_box';  this.components.titleBar.className  = 'ECM_dialog_title';  this.components.closeButton.className = 'ECM_dialog_close_button';  this.components.titleText.className      = 'ECM_dialog_title_span';  this.components.contentBody.className    = 'ECM_dialog_body';  this.components.messageBody.className    = 'ECM_dialog_message_body';  this.components.messageText.className    = 'ECM_dialog_message_text';  this.components.buttonsBar.className      = 'ECM_dialog_button_bar';

  if (this.components.inputs.length > 0) {
    for (var i=0; i<this.components.inputs.length; i++) {
      this.components.messageText.appendChild(this.components.inputs[i]);
    }
  }
  if (this.components.summary != null) {
    this.components.messageBody.appendChild(this.components.summary);
  }

  if (this.components.buttons.length > 0) {
    for (var i=0; i<this.components.buttons.length; i++) {
      this.components.buttonsBar.appendChild(this.components.buttons[i]);
    }
    this.components.messageBody.style.paddingBottom = '10px';
  }
  else {
    this.components.buttonsBar.style.display = 'none';
  }

  if (this.components.icon !== null) {
    this.components.contentBody.className += ' ECM_dialog_icon_'+this.components.icon;
    this.components.messageBody.style.paddingLeft = '35px';
  }

  
  if (this.className) {
    this.body.className = this.className;
  }
  if (this.width) {
    this.body.style.width = this.width + 'px';
  }
  if (this.height) {
    this.body.style.height = this.height + 'px';
  }
  if (this.isShadow) {
    this.body = ui.effect.shadow(this.body);
  }

  
  if (this.isLockScreen) {
    this.body.style.zIndex = 99999;
    this.lockScreen();
  }
  else {
    this.body.style.zIndex = 999;
  }

  
  if (this.isDraggable) {
    new ui.Draggable(this.body, this.components.titleBar);
  }

  if (!this.isSingle || !this.inDoc) {
    
    this.body.style.visibility = 'hidden';
    this.body.style.top = '-100000px';

    document.body.appendChild(this.body);
    this.inDoc = true;
  }
  else {
    Element.show(this.body);
  }
  
  if (this.refer) {
    this.body.style.position = 'absolute';
    var pos = Element.getPosition(this.refer);
    this.body.style.left= pos.left - this.body.offsetWidth/2 + this.refer.offsetWidth/2 + 'px';
    if ((pos.top - (document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop))+this.body.offsetHeight > window.innerHeight) {
      this.body.style.top = pos.top - this.body.offsetHeight + 'px';
      this.components.titleBar.className = 'ECM_dialog_title_bottom';
      this.body.appendChild(this.components.titleBar);
    }
    else {
      this.body.style.top = pos.top + this.refer.offsetHeight + 'px';
    }
  }
  else {
    this.moveToCenter();
  }
  if (this.fadeTime > 0) {
    
    this.body.style.opacity = 0;
    this.body.style.filter='alpha(opacity=0)';
    this.body.style.visibility = 'visible';
    this.setAutoClose();
    ui.effect.FadeTo(this.body, 0, 100, this.fadeTime * 1000);
  }
  else {
    this.body.style.visibility = 'visible';
    this.setAutoClose();
  }
  if (this.onLoad) {
    this.onLoad();
  }
};
Dialog.prototype.moveToCenter = function () {
  var _x  =  document.body.scrollWidth;
  var _y  = window.innerHeight > 0 ? window.innerHeight : document.body.clientHeight;
  var _s_h=0;
  if (this.body.style.position != 'fixed') {
    _s_h=  document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
  }
  c_x    =  _x /2 - this.width/2;
  c_y    =  _y/2 + _s_h - this.body.clientHeight/2;
  this.body.style.left = c_x + 'px';
  this.body.style.top  = c_y + 'px';
};
Dialog.prototype.close     = function () {
  if (this.body !== null) {
    var self = this;
    if (this.onClose) {
      if(!this.onClose())return;
    }
    if (this.fadeTime) {
      ui.effect.FadeTo(this.body, 100, 0, this.fadeTime * 1000, function () {
        if (!self.isSingle) {
          Element.remove(self.body);
          self.body = null;
        }
        else {
          Element.hide(self.body);
        }
      });
    }
    else {
      if (!this.isSingle) {
        Element.remove(this.body);
        this.body = null;
      }
      else {
        Element.hide(this.body);
      }
    }
    if (this.isLockScreen) {
      this.unlockScreen();
    }
  }
};
Dialog.prototype.isClosed   = function () {
  return (this.body.style.display == 'none' || !this.inDoc) ? true : false;
};
Dialog.prototype.lockScreen = function () {
  if (this.locker === null)
  {
    this.locker = new ui.utils.locker();
  }
  this.locker.lock(20);
};
Dialog.prototype.unlockScreen= function () {
  if (this.locker !== null)
  {
    this.locker.unLock();
  }
};
Dialog.prototype.setAutoClose = function () {
  if (this.autoCloseTime) {
    var self = this;
    this.body.onmouseover = function () {
      clearTimeout(self.timeoutID);
    };
    this.body.onmouseout = function () {
      self.setAutoClose();
    };
    this.timeoutID = setTimeout(function () {
      self.close();
    }, (this.autoCloseTime+this.fadeTime) * 1000);
  }
};
Dialog.prototype.focus = function () {
  if (this.components.inputs[0]) {
    this.components.inputs[0].focus();
  }
};

ui.utils = {};

ui.utils.tabForm  = function (formName, classActived) {
  this._curr = 0;
  if (classActived) this.actived = classActived; else this.actived = "actived";
  var _self = this;
  var form = $(formName);
  var tabBar = $class("tab-bar", form)[0];
  var tabPage = $class("tab-page", form)[0];

  $(formName).style.display = "block";
  tabBar.children[0].className = _self.actived;
  for (i=0; i<tabPage.children.length; i++)
    if (i > 0) Element.hide(tabPage.children[i]);

  tabBar.onclick = function(e) {
    var evt = fixEvent(e);
    var obj = evt.srcElement;
    if (obj.tagName == "LI") {
      for (i=0; i<tabBar.children.length; i++) {
        if (tabBar.children[i] == obj) {
          if (tabBar.children[i].getAttribute("disabled") == "true") return;
          tabBar.children[_self._curr].className = '';
          obj.className = _self.actived;
          Element.hide(tabPage.children[_self._curr]);
          Element.show(tabPage.children[i],'table');
          _self._curr = i;
          break;
        }
      }
    }
  };
};

ui.utils.ImagePreview = function(src, width, height)
{
  var img = new Image();
  var div = $ce("DIV");
  div.style.position = "absolute";
  div.style.top = "300px";
  div.innerHTML = "loading";
  img.src = src + "?r=" + Math.random();  img.onload = function()
  {
    img.width = img.height = 0;
    _w = img.width;
    _h = img.height;
    img.style.display = "";    ui.effect.ResizeTo(img, _w, _h,200);
  };
  div.appendChild(img);
  document.body.appendChild(div);
};


ui.utils.locker = function(color) {
  this.layer = $ce("div");
  this.innerLayer = $ce("div");
  if (!color) color = "#000";
  this.layer.style.cssText = "background:" + color + ";left:0px;position:absolute;top:0px;z-index:9999;";
  this.innerLayer.style.position = "relative";
  this.innerLayer.style.left = this.innerLayer.style.top = "0px";
  
  ui.effect._setOpacity(this.layer, 30);
  this.layer.appendChild(this.innerLayer);

  Element.hide(this.layer);
  this.locked = false;
  
  document.body.appendChild(this.layer);
};

ui.utils.locker.prototype = {
  lock : function(opa) {
    if (!opa) opa = 50;
    ui.effect._setOpacity(this.layer, opa);
    Element.show(this.layer);
    this.locked = true;
    this.resize();
    if (navigator.isIE()) {
      dropDownLists = document.getElementsByTagName("SELECT");
      Outer: for (var i = 0; i< dropDownLists.length; i++) {
        var list = dropDownLists[i];
        var elem = list;
        Inter: do {
          if (Element.getStyle(elem, "position") == "absolute") {
            continue Outer;
          }
        } while((elem = elem.parentNode) != document.body)
        list.style.visibility = "hidden";
      }
    }
  },
  resize : function() {
    if (window.self.innerHeight) {
      this.innerHeight = Math.max(window.self.innerHeight,document.body.scrollHeight);
    } else {
      if (document.documentElement && document.documentElement.clientHeight) {
        this.innerHeight = Math.max(document.documentElement.clientHeight,document.documentElement.scrollHeight);
      } else if (document.body) {
        this.innerHeight = Math.max(document.body.clientHeight,document.body.scrollHeight);
      }
    }
    var innerWidth  = Math.min(document.body.scrollWidth, self.innerWidth||document.body.clientWidth);
    this.layer.style.width = innerWidth + "px";
    this.innerLayer.style.width = this.layer.style.width;
    var h = this.innerHeight-1;
    this.layer.style.height = h + "px";
    this.innerLayer.style.height = h + "px";

  },
  unLock : function() {
    this.locked = false;
    Element.hide(this.layer);
    if (navigator.isIE()) {
      dropDownLists = document.getElementsByTagName("SELECT");
      for (var i = 0; i< dropDownLists.length; i++) {
        dropDownLists[i].style.visibility = "";
      }
    }
  },
  appendChild : function(elem){
    this.innerLayer.appendChild(elem);
  }
};


ui.inlineEditBox = {
  sender : false,
  edit : function(sender,callback) {
    var self = this;
    this.sender = sender;
    if (sender.getAttribute("editing")!=null) return;
    var cacheText = sender.innerHTML;
    sender.innerHTML = "";
    var textBox = $ce("input");
    textBox.value = cacheText;
    textBox.onblur = (function(){
      sender.innerHTML = textBox.value;
      if (textBox.value != cacheText) callback(sender);
      this.endEdit();
    }).bind(this);

    textBox.onkeypress = function(event) {
      event = fixEvent(event);
      if (event.keyCode == 13) {
        this.blur();
        self.endEdit();
      } else if (event.keyCode == 27) {
        try {
          self.sender.innerHTML = cacheText;
          self.endEdit();
        }
        catch(ex) {
          alert(ex.description);
        }
      }
    };

    sender.appendChild(textBox);
    textBox.focus();
    sender.setAttribute("editing", true);
  },
  endEdit: function(){
    this.sender.removeAttribute("editing");
  }
};

ui.Draggable = function (o, h, m) {
  var x = 0, y = 0;
  var i=0;
  var draging = function (e) {
    e = fixEvent(e);
    o.style.left = (Event.pointerX(e) - x) + "px";
    o.style.top  = (Event.pointerY(e) - y) + "px";
    
  };

  var endDrag = function() {
    Event.stopObserving(document.body, 'mousemove', draging);
    Event.stopObserving(document.body, 'mouseup', endDrag);
    if(m)m.style.display = 'none';
    Element.setSelectable(document.body, true);
  };

  var starDrag = function(e) {
    e.returnValue = false;
    e = fixEvent(e);
    x = Event.pointerX(e) - o.offsetLeft;
    y = Event.pointerY(e) - o.offsetTop;
    Event.observe(document.body, 'mousemove', draging);
    Event.observe(document.body, 'mouseup', endDrag);
    Element.setSelectable(document.body, false);
    if(m)m.style.display = '';
  };

  Event.observe(h, 'mousedown', starDrag);
  h.style.cursor = 'move';
};

var hiddenobj = new Array();
var pmwinposition = new Array();
function pmwin(action, param) {
  var objs = document.getElementsByTagName("OBJECT");
  if(action == 'open') {
    for(i = 0;i < objs.length; i ++) {
      if(objs[i].style.visibility != 'hidden') {
        objs[i].setAttribute("oldvisibility", objs[i].style.visibility);
        objs[i].style.visibility = 'hidden';
      }
    }
    var clientWidth = document.body.clientWidth;
    var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
    var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
    var pmwidth = 800;
    var pmheight = clientHeight * 0.9;
    if(!$('pmlayer')) {
      div = $ce('div');div.id = 'pmlayer';
      div.style.width = pmwidth + 'px';
      div.style.height = pmheight + 'px';
      div.style.left = ((clientWidth - pmwidth) / 2) + 'px';
      div.style.position = 'absolute';
      div.style.zIndex = '999';
      document.body.appendChild(div);

      var code = "";

      if (navigator.isIE()) {
        code = '<iframe href="return false" style="width:' + pmwidth + 'px;height:'+pmheight+'px; position: absolute;  left:0px;top:0px; z-Index=-1;filter:alpha(opacity=0);" frameborder="0"></iframe>';
      }
      $('pmlayer').style.visibility = 'hidden';
      $('pmlayer').innerHTML = '<div style="width: 800px; background: #666666; margin: 5px auto; text-align: left">' +
        '<div style="width: 800px; height: ' + pmheight + 'px; padding: 1px; background: #FFFFFF; border: 1px solid #7597B8; position: relative; left: -6px; top: -3px;">' +
        '<div id="_pm_header_" style="cursor: move; position: relative; left: 0px; top: 0px; width: 800px; height: 30px; margin-bottom: -30px;"></div>' +
        '<a href="javascript:;" onclick="pmwin(\'close\')"><img style="position: absolute; right: 20px; top: 15px" src="data/images/close.gif" alt="' + lang.close + '" title="' + lang.close + '" /></a>' +
        '<div id="pmwinmask" style="margin-top: 30px; position: absolute; width: 100%; height: '+pmheight+'px; display: none"></div><iframe scrolling="yes" id="pmframe" name="pmframe" style="width:' + pmwidth + 'px;height:100%; overflow-x:hidden" allowTransparency="true" frameborder="0"></iframe>'+code+'</div></div>';
      new ui.Draggable(div, $('_pm_header_'), $('pmwinmask'));
      $('pmlayer').style.height = $('pmframe').clientHeight;
      $('pmlayer').style.visibility = 'visible';
    }
    $('pmlayer').style.display = '';
    $('pmlayer').style.top = ((clientHeight - pmheight) / 2 + scrollTop) + 'px';
    if(!param) {
      pmframe.location = 'index.php?app=pm';
    } else {
      pmframe.location = 'index.php?app=pm' + param;
    }
  } else if(action == 'close') {
    for(i = 0;i < objs.length; i ++) {
      if(objs[i].attributes['oldvisibility']) {
        objs[i].style.visibility = objs[i].attributes['oldvisibility'].nodeValue;
        objs[i].removeAttribute('oldvisibility');
      }
    }
    hiddenobj = new Array();
    $('pmlayer').style.display = 'none';
  }
}



Event.observe(window, 'load', function() {
  elms = $class("avatar");
  for (var i=0; i<elms.length; i++) {
    elms[i].onmouseover = function() {var mnu = $class("avatar-menu", this);var lnk = $class("avatar-link", this);mnu[0].style.display="block";lnk[0].className = "avatar-hover"; };
    elms[i].onmouseout = function() {var mnu = $class("avatar-menu", this);var lnk = $class("avatar-hover", this);mnu[0].style.display="none"; lnk[0].className = "avatar-link"; };
  }

  check_pm();
  if ($('pm_button')) {
    $('pm_button').onclick = function () {
      pmwin('open');
    };
  }

  if ($('addcart')) {
    $('addcart').onmouseover = showCartStatus;
  }
  cart_status_tip = new Dialog(DIALOG_TIP);
  cart_status_tip.setSize(250);
  cart_status_tip.isSingle = true;
  cart_status_tip.isDraggable = false;
  cart_status_tip.autoCloseTime = 3;
  cart_status_tip.fadeTime      = 0.3;
});

function showCartStatus() {
  if (cart_status_tip) {
    if(!cart_status_tip.isClosed()){
      return;
    }
    var cont = lang.cart_status.replace('[cart_goods_count]', $('cart_goods_count').innerHTML);
    cont = cont.replace('[cart_goods_amount]', priceFormat($('hidden_cart_goods_amount').value));
    cart_status_tip.setContent('', cont);
    cart_status_tip.pointTo($('addcart'));
    cart_status_tip.show();
  }
}


function check_pm() {
  if ($class("check_new_pm", "A").length > 0) {
    Ajax.call("index.php?app=member&act=check_new_pm", function(res){
      if (res.done) {
        var elem = $class("check_new_pm", "A")[0];
        if (!lang.pm) lang.pm = elem.innerHTML;
        if (res.retval == "new_pm") {
          elem.innerHTML = lang.new_pm;
          elem.style.color = "red";
        } else {
          elem.innerHTML = lang.pm;
          elem.style.color = "";
        }
        elem.onclick = function() {
          pmwin('open');
          if (elem.innerHTML == lang.new_pm){
            elem.innerHTML = lang.pm;
            elem.style.color = "";
          }
        }
      }
    });

    window.setTimeout(check_pm, 30000);
  }
}


function add_friend(userId, noAlert)
{
    Ajax.addVal('ret_url', encodeURIComponent(location.href));
    Ajax.addVal("friend_id", userId);
    Ajax.call("index.php?app=member&act=add_friend", function(res){
        if (res.msg == "NO_LOGIN")
        {
            document.location.href = res.retval;
        }
        else
        {
            if (!noAlert)
            {
              var d = new Dialog(DIALOG_MESSAGE);
              d.setContent(lang.system_notice, res.msg);
              d.show();
            }
        }
    }, "GET", false);
}


function addTag(goods_id)
{
  var tag_words = $('tag_words').value;
  if (tag_words.length == 0){
    alert(lang.tag_empty);
    return false;
  }
  Ajax.addVal('tag_words', tag_words);
  Ajax.call('index.php?app=goods&act=add_tag&id=' + goods_id, addTagResponse);
  return false;
}

function addTagResponse(result)
{
  if (!result.done){
    if (result.msg == 'NO_LOGIN')
    {
      if (confirm(lang.no_login))
      {
        location.href = "index.php?app=member&act=login&ret_url=" + encodeURIComponent(location.href);
      }
      return;
    }
  } else {
    $("tag_content").innerHTML = result.retval;
    $('tag_words').value = "";
  }
  if (result.msg.length > 0){
    alert(result.msg);
  }
}


function loadNextImage()
{
  if (curImage + 1 > imageUrl.length){
    curImage = 1;
  }else{
    curImage ++;
  }
  gotoImage();
}

function loadPreImage()
{
  if (curImage - 1 < 1){
    curImage = imageUrl.length;
  } else {
    curImage --;
  }
  gotoImage();
}

function gotoImage()
{
  var elem = $class("curPage");
  for (var i=0; i<elem.length; i++ ){
    elem[i].innerHTML = curImage;
  }
  var newImage = imageUrl[curImage -1].replace(/&amp;/g, '&');
  $("previewImage").src = newImage;
}



function addToFavorite(id)
{
  Ajax.call('index.php?app=member&act=add_favorite&id=' + id + '&ret_url=' + encodeURIComponent(location.href) , addToFavoriteRespond);
}

function addToFavoriteRespond(result, result_text){
  if (!result.done){
    if (result.msg == 'NO_LOGIN')
    {
      document.location.href = result.retval;
      return;
    }
  }
  if (result.msg.length > 0){
      alert(result.msg);
  }
}

function viewLargePic(){
  var pic = $("goods_pic").getAttribute("org");
  if (pic) {
    var win = window.open(pic ,'largePicture','width=800,height=600,resizable=yes');
    win.focus();
  }


  return false;
}

function changeGallery(event){
  var e = fixEvent(event);
  var elem = e.srcElement;
  if (elem.tagName == 'IMG' && elem.parentNode.tagName == 'A'){
    if (elem.parentNode.href != location.href){
      var gallerylist = $('gallerylist');
      for (var i=0;i< gallerylist.childNodes.length ;i++ ){
        if (gallerylist.childNodes[i].tagName == 'LI'){
          Element.removeClass(gallerylist.childNodes[i], "selected");
        }
      }

      var thumbImg = elem.parentNode.href;
      var thumb_org = elem.getAttribute("org");
      var goodsPic = $('goods_pic');
      goodsPic.src = thumbImg;
      goodsPic.setAttribute('org', thumb_org);
      if (typeof(_magnifier) == 'object') {_magnifier.setImage(thumb_org);}
      if (goodsPic.parentNode.style.backgroundImage) goodsPic.parentNode.style.backgroundImage = 'url(' + thumbImg + ')';
      Element.addClass(elem.parentNode.parentNode, "selected");
    }
  }
  return false;
}

function addToCart(spec_id, goods_num, com_no){
  if (!spec_id)
  {
    alert(lang.invalid_spec_id);
    return;
  }
  goods_num = Number(goods_num);
  if ($('addcart_button').disabled) {
    var d = new Dialog(DIALOG_MESSAGE);
    d.setContent(lang.sys_msg, lang.select_action_first);
    d.show();
    return;
  }
  if (!goods_num || goods_num == 'NaN')
  {
    var d = new Dialog(DIALOG_WARNING);
    d.setContent(lang.sys_msg, lang.invalid_goods_num);
    d.show();

    return;
  }
  $('addcart_button').disabled = true;
  Ajax.call('index.php?app=shopping&act=add_to_cart&goods_number=' + goods_num + '&spec_id=' + spec_id, addToCartMsg);
}

function addToCartMsg(response){
  if (!response.done)
  {
    var d = new Dialog(DIALOG_WARNING);
    d.onOK = function () {
      $('goods_num').select();
      d.close();
    };
    d.setContent(lang.error, response.msg);
    d.show();
  $('addcart_button').disabled = false;
    return;
  }

  var d = new Dialog(DIALOG_TIP);
  d.setContent('', response.retval.msg);
  d.pointTo($('addcart_button'));
  d.addButton(lang.checkout_button_name, function () {
    window.location.href="index.php?app=shopping&act=shopping_cart";
  }, true);
  d.addButton(lang.shopping_button_name, function () {
    d.close();
    $('goods_num').disabled = false;
    $('addcart_button').disabled = false;
    showCartStatus();
  });
  d.show();
  $('goods_num').disabled = true;
  $('hidden_cart_goods_count').value = response.retval.count;
  $('cart_goods_count').innerHTML = Number(response.retval.count);
  $('hidden_cart_goods_amount').value = response.retval.amount;
}


function checkIntensity(pwd){
  var Mcolor = "#FFF",Lcolor = "#FFF",Hcolor = "#FFF";
  var m=0;
  var Modes = 0;
  for (i=0; i<pwd.length; i++){
    var charType = 0;
    var t = pwd.charCodeAt(i);
    if (t>=48 && t <=57){
      charType = 1;
    }else if (t>=65 && t <=90){
      charType = 2;
    }else if (t>=97 && t <=122)
      charType = 4;
    else
      charType = 4;
    Modes |= charType;
  }

  for (i=0;i<4;i++){
    if (Modes & 1) m++;
      Modes>>>=1;
  }
  if (pwd.length<=4){
    m = 1;
  }
  switch(m){
    case 1 :
      Lcolor = "2px solid red";
      Mcolor = Hcolor = "2px solid #DADADA";
    break;
    case 2 :
      Mcolor = "2px solid #f90";
      Lcolor = Hcolor = "2px solid #DADADA";
    break;
    case 3 :
      Hcolor = "2px solid #3c0";
      Lcolor = Mcolor = "2px solid #DADADA";
    break;
    case 4 :
      Hcolor = "2px solid #3c0";
      Lcolor = Mcolor = "2px solid #DADADA";
    break;
    default :
      Hcolor = Mcolor = Lcolor = "";
    break;
  }
  $("pwd_lower").style.borderBottom  = Lcolor;
  $("pwd_middle").style.borderBottom = Mcolor;
  $("pwd_high").style.borderBottom   = Hcolor;
}


function checkUserName(username){
    var target = $("checkusername");
    Element.removeClass(target, "error_msg");
    target.innerHTML = "<span class=\"tip_loading\">&nbsp;</span>";

    if (username.length < 3) {
        Element.addClass(target, "error_msg");
        target.innerHTML = lang.username_short;
    }else{
        Ajax.addVal('app', 'member');
        Ajax.addVal('act', 'check_user');
        Ajax.addVal('username', username);
        Ajax.call('index.php', function(result){
          if (result.done){
            Element.removeClass(target, "error_msg");
            target.innerHTML = "<span class=\"tip_checked\">&nbsp;</span>";
          }else{
            Element.addClass(target, "error_msg");
            target.innerHTML = result.msg;
          }
        }, 'GET');
    }
}


function checkUserEmail(email){
    var target = $("checkuseremail");
    Element.removeClass(target, "error_msg");
    target.innerHTML = "<span class=\"tip_loading\">&nbsp;</span>";

    if (email.length == 0 || (!email.isEmail())){
        Element.addClass(target, "error_msg");
        target.innerHTML = lang.email_invalid;
    }else{
        Ajax.addVal('app', 'member');
        Ajax.addVal('act', 'check_email');
        Ajax.addVal('email', email);
        Ajax.call('index.php', function(result){
          if (result.done){
            Element.removeClass(target, "error_msg");
            target.innerHTML = "<span class=\"tip_checked\">&nbsp;</span>";
          }else{
            Element.addClass(target, "error_msg");
            target.innerHTML = result.msg;
          }
        }, 'GET');
}}


function checkRepeatPassword(repeatpass){
 var target = $('checkrepeatpassword');
 var pass = $('password_id').value;

 if (pass.length == 0) {
    Element.addClass(target, "error_msg");
    target.innerHTML = lang.input_pass_first;
    return;
 }
 if (repeatpass.length == 0){
    Element.addClass(target, "error_msg");
    target.innerHTML = lang.repeat_pass_empty;
    return;
 }

 if (pass != repeatpass){
    Element.addClass(target, "error_msg");
    target.innerHTML = lang.repeat_pass_invalid;
    return;
 }

 Element.removeClass(target, "error_msg");
 target.innerHTML = "<span class=\"tip_checked\">&nbsp;</span>";

}
function showAskDialog(order_sn){
  var d = new Dialog(DIALOG_USERDEF);
  d.setContent(lang.pay_dialog_title, lang.pay_dialog_content);
  d.setSize(310);
  d.addButton(lang.pay_sucess, function () {
    window.location.href="index.php?app=member&act=order_view";
  }, true);
  d.addButton(lang.pay_faild, function () {
    window.location.href = 'index.php?app=shopping&act=pay_faild_notice&order_sn='+order_sn;
  });
  d.show();
}

function priceFormat(s){
  s = Math.ceil(s * 100)/100;
  s = s.toString();
  if(/[^0-9\.\-]/.test(s))
    return "invalid value";
  s=s.replace(/^(\d*)$/,"$1.");
  s=(s+"00").replace(/(\d*\.\d\d)\d*/,"$1");
  s=s.replace(".",",");
  var re=/(\d)(\d{3},)/;
  while(re.test(s)){
      s=s.replace(re,"$1,$2");
  }
  s=s.replace(/,(\d\d)$/,".$1");
  return lang.currency + s.replace(/^\./,"0.")
}


function show_msn_status(result)
{
    var innerFrame = document.getElementById('msn_status');

    var statusIcon = document.createElement('img');
    statusIcon.style.border = 'none';
    statusIcon.src = result.icon.url;
    statusIcon.width = result.icon.width;
    statusIcon.height = result.icon.height;
    statusIcon.alt = result.statusText;
    statusIcon.title = result.statusText;

    var displayName = document.createElement('span');

    if (result.status != "Offline")
    {
        document.require("http://settings.messenger.live.com/controls/1.0/PresenceButton.js");
        document.require("http://messenger.services.live.com/users/" + result.id + "/presence?dt=&mkt=zh-cn&cb=Microsoft_Live_Messenger_PresenceButton_onPresence");
        var show_name = result.displayName.length > 0 ? result.displayName : lang.online;
        displayName.innerHTML = "<a href='javascript:Microsoft_Live_Messenger_PresenceButton_startConversation(\"http://settings.messenger.live.com/Conversation/IMMe.aspx?invitee=" + result.id + "&mkt=zh-cn\");'>" + show_name + "</a>";
    }
    else
    {
        displayName.innerHTML = result.displayName.length > 0 ? result.displayName : lang.offline;
    }

    innerFrame.innerHTML = "";
    innerFrame.appendChild(statusIcon);
    innerFrame.appendChild(displayName);
    }