Object.extend = function(destination, source)
{
  for (property in source)
  {
    destination[property] = source[property];
  }
  return destination;
};

Function.prototype.bind = function(object) 
{ 
  var __method = this; 
  return function()
  {
    __method.apply(object, arguments); 
  }
};
Function.prototype.bindAsEventListener = function(object)
{
  var __method = this, args = $A(arguments), object = args.shift();
  return function(event) 
  {
    return __method.apply(object, [( event || window.event)].concat(args).concat($A(arguments)));
  }
};

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;
  },
  first: function(elem)
  {
    var n = elem.childNodes[0];
    if (n && n.nodeType != 1)
    {
      n = n.nextSibling;
    }

    return n;
  },
  last : function(elem)
  {
    //var n = elem.lastNode;
    var n = elem.childNodes[elem.childNodes.length-1];
    if (n.nodeType != 1)
    {
      n = n.previousSibling;
    }
    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;
  },
  center : function (element) 
  {
    element.style.position = 'absolute';
    var _x  =  document.body.scrollWidth;
    var _y  = window.innerHeight > 0 ? window.innerHeight : document.body.clientHeight;
    var _s_h=0;
    if (element.style.position != 'fixed')
    {
      _s_h=  document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
    }
    c_x    =  _x /2 - element.clientWidth/2;
    c_y    =  _y/2 + _s_h - element.clientHeight/2;
    element.style.left = c_x + 'px';
    element.style.top  = c_y + 'px';
  }
};


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 = /^\w+(\.\w+)?@(\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); },
  isTel  : function() { var reg = /^[\d|\-|\s|\_]+$/; return reg.test(this); },
  htmlEncode : function() 
  { 
    return this.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  }
});


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) 
  {
    if (sValue.length > 0)
    {
      var sCookie = sName + "=" + encodeURIComponent(sValue);
      if (sExpires != null) 
      {
        sCookie += "; expires=" + sExpires; 
      }
      
      this.cookie = sCookie;
    }
    else
    {
      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.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()}, 100);
      }
      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;
  },
  inject: function(memo, iterator) 
  {
    this.each(function(value, index) 
    {
      memo = iterator(memo, value, index);
    });
    return memo;
  },
  flatten: function() 
  {
    return this.inject([], function(array, value) 
    {
      return array.concat(value && value.constructor == Array ? value.flatten() : [value]);
    });
  },
  each : function (func)
  {
    for(var i=0;i<this.length;i++) 
    {
      func(this[i], i);
    }
  },
  clear: function() {
    this.length = 0;
    return this;
  },
  first: function() {
    return this[0];
  },
  last: function() {
    return this[this.length - 1];
  },
  indexOf: function(object) {
    for (var i = 0; i < this.length; i++)
      if (this[i] == object) return i;
    return -1;
  },
  toString: function()
  {
    return this.join('');
  }
});

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 $(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 $input(input_name, obj)
{
  var elem = obj.getElementsByTagName("INPUT");
  var result = false;
  for (var i =0;i<elem.length; i++)
  {
    if (elem[i].name == input_name)
    {
      result = elem[i];
      break;
    }
  }
  return result;
}

function fixEvent(e, win) 
{
  if (typeof win === 'undefined') 
  {
    win = window; 
  }
  var evt = (typeof e == "undefined") ? win.event : e; 
  return evt;
}

function confirm_jump(msg, url) 
{ 
  if (confirm(msg))
  {
    location.href=url;
  }
}

function empty(val)
{
  switch (typeof(val))
  {
    case 'string':
      return val.trim().length == 0 ? true : false;
      break;
    case 'number':
      return val == 0;
      break;
    case 'object':
      if (val instanceof Array)
      {
        return val.length == 0;
      }
      else
      {
        return val == null;
      }
      break;
    case 'array':
      return val.length == 0;
      break;
    default:
      return true;
  }
}

var effect = {
  base : {
    setOptions: function(options) 
    {
      this.options = {
        duration: 500,
        onComplete: '',
        transition: function(pos)
        {
    	    return ((-Math.cos(pos*Math.PI)/2) + 0.5);
        }
      }
      Object.extend(this.options, options || {});
    },
    step: function() 
    {
      var time  = (new Date).getTime();
      if (time >= this.options.duration+this.startTime) 
      {
        this.now = this.to;
        clearInterval (this.timer);
        this.timer = null;
        if (this.options.onComplete) setTimeout(this.options.onComplete.bind(this), 10);
      }
      else 
      {
        var Tpos = (time - this.startTime) / (this.options.duration);
        this.now = this.options.transition(Tpos) * (this.to-this.from) + this.from;
      }
      this.increase();
    },

    custom: function(from, to) 
    {
      if (this.timer != null) return;
      this.from = from;
      this.to = to;
      this.startTime = (new Date).getTime();
      this.timer = setInterval (this.step.bind(this), 13);
    },

    hide: function() 
    {
      this.now = 0;
      this.increase();
    },

    clearTimer: function() 
    {
      clearInterval(this.timer);
      this.timer = null;
    },
    save : {}
  },
  
  opacity : function(elem, options)
  {
    Object.extend(this, effect.base);
    this.elem = $(elem);
    this.now = 1;
    this.setOptions(options);
    

    this.setOpacity = function(opacity) 
    {
		  if (opacity == 0 && this.elem.style.visibility != "hidden") this.elem.style.visibility = "hidden";
		  else if (this.elem.style.visibility != "visible") this.elem.style.visibility = "visible";
	  	if (window.ActiveXObject) this.elem.style.filter = "alpha(opacity=" + opacity*100 + ")";
	  	this.elem.style.opacity = opacity;
	  }
    
    this.increase =  function ()
    {
      if (this.now == 1 && (/Firefox/.test(navigator.userAgent))) this.now = 0.9999;
		  this.setOpacity(this.now);
    }
    

    this.toggle = function() 
    {
		  if (this.now > 0) this.custom(1, 0);
		  else this.custom(0, 1);
	  }
  },
  width : function(elem, options)
  {
    Object.extend(this, effect.base);
    this.elem = $(elem);
    this.setOptions(options);
    this.elem.style.overflow = "hidden";
    this.save.iniWidth = this.elem.offsetWidth;
    
    this.increase =  function ()
    {
      this.elem.style.width = this.now + "px";
    }
    
    this.toggle = function() 
    {
		  if (this.elem.offsetWidth > 0) this.custom(this.elem.offsetWidth, 0);
		  else this.custom(0, this.save.iniWidth);
	  }
  },
  height : function(elem, options)
  {
    Object.extend(this, effect.base);
    this.elem = $(elem);
    this.setOptions(options);
    this.elem.style.overflow = "hidden";
    this.save.iniHeight = this.elem.offsetHeight;
     
    this.increase =  function ()
    {
      this.elem.style.height = this.now + "px";
    }
    
    this.toggle = function() 
    {
	  if (this.elem.offsetHeight > 0) this.custom(this.elem.offsetHeight, 0);
	  else this.custom(0, this.elem.scrollHeight);
    }
  },
  floating : function(elem, options)
  {
    Object.extend(this, effect.base);
    this.elem = $(elem);
    this.elem.style.position = 'absolute';
    this.setOptions(options);
    this.elem.style.left = this.options.left + 'px';
    //this.elem.style.top  = this.options.max + 'px';
    this.lastScrollY = 0;
    this.lastMore    = 0;

    this.scroll =  function ()
    { 
      var diffY = Math.max(document.documentElement.scrollTop,document.body.scrollTop);

      if (diffY < this.options.max)
      {
        return;
      }

      var percent = .2*(diffY - this.lastScrollY);
      if(percent > 0) 
        percent = Math.ceil(percent);
      else
        percent = Math.floor(percent);

      var cul = this.elem.style.top.length == 0 ? 0 : parseInt(this.elem.style.top);

      this.elem.style.top = (cul + percent) + "px";

      this.lastScrollY = this.lastScrollY + percent;
    }

    this.start = function()
    {
      //alert(this.elem.scrollTop);
      this.timer = window.setInterval(this.scroll.bind(this), 50);
    }
  },
  setOpacity : function(elem, value)
  {
    elem.style.filter='alpha(opacity='+Math.round(value)+')';    
    if(!elem.style.filters) elem.style.MozOpacity=Math.round(value)/100;
  }
};

Drag = function (o, h) {
  var x = 0, y = 0;
  var _d = false;
  Event.observe(document, 'mousemove', function (e) 
  {
    if (_d != true) 
    {
      return;
    }
    else 
    {
      e = fixEvent(e);
      o.style.left = e.clientX - x + 'px';
      o.style.top  = e.clientY - y + 'px';
    }
  });
  Event.observe(document, 'mouseup', function (e) 
  {
    _d = false;
  });
  o = $(o);
  h = $(h);
  o.style.position = 'absolute';
  h.style.cursor = 'move';
  h.onmousedown = function (e) 
  {
    _d = true;
    e = fixEvent(e);
    if (navigator.isIE()) 
    {
      x = document.documentElement.scrollLeft + e.offsetX;
      y = document.documentElement.scrollTop + e.offsetY;

      if (document.documentElement.scrollTop > 0)
      {
        y = e.offsetY - document.documentElement.scrollTop;
      }

      if (document.documentElement.scrollLeft > 0)
      {
        x = e.offsetX - document.documentElement.scrollLeft;
      }
    }
    else 
    {
      x = document.documentElement.scrollLeft + e.layerX;
      y = document.documentElement.scrollTop + e.layerY;

      if (document.documentElement.scrollTop > 0)
      {
        y = e.layerY - document.documentElement.scrollTop;
      }

      if (document.documentElement.scrollLeft > 0)
      {
        x = e.layerX - document.documentElement.scrollLeft;
      }
    }
  };
};

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;
        }
      }
    }
  };
};

var Builder = {
  NODEMAP: {
    AREA: 'map',
    CAPTION: 'table',
    COL: 'table',
    COLGROUP: 'table',
    LEGEND: 'fieldset',
    OPTGROUP: 'select',
    OPTION: 'select',
    PARAM: 'object',
    TBODY: 'table',
    TD: 'table',
    TFOOT: 'table',
    TH: 'table',
    THEAD: 'table',
    TR: 'table'
  },

  node: function(elementName) 
  {
	  elementName = elementName.toUpperCase();
	  
	  var parentTag = this.NODEMAP[elementName] || 'div';
	  var parentElement = document.createElement(parentTag);
	  try 
    {
		  parentElement.innerHTML = "<" + elementName + "></" + elementName + ">";
	  } 
    catch(e) {}

	  var element = parentElement.firstChild || null;
		
	  if(element && (element.tagName != elementName))
    {
		  element = element.getElementsByTagName(elementName)[0];
    }
	  
	  if(!element) 
    {
      element = document.createElement(elementName);
    }
	  
	  if(!element) 
    {
      return;
    }

	  if(arguments[1])
    {
      if(this._isStringOrNumber(arguments[1]) || (arguments[1] instanceof Array)) 
      {
        this._children(element, arguments[1]);
      } 
      else 
      {
        var attrs = this._attributes(arguments[1]);
        if(attrs.length) 
        {
          try 
          {
            parentElement.innerHTML = "<" +elementName + " " + attrs + "></" + elementName + ">";
          }
          catch(e) {}

          element = parentElement.firstChild || null;

          if(!element) 
          {
            element = document.createElement(elementName);
            for(attr in arguments[1]) 
            {
              element[attr == 'class' ? 'className' : attr] = arguments[1][attr];
            }
          }
          if(element.tagName != elementName)
          {
            element = parentElement.getElementsByTagName(elementName)[0];
          }
        }
      } 
    }
	  if(arguments[2])
	  {
		  this._children(element, arguments[2]);
	  }

	  return element;
	},
  _text: function(text) 
  {
     return document.createTextNode(text);
  },
  _attributes: function(attributes)
  {
    var attrs = [];
    for(attribute in attributes)
    {
      if (typeof(attributes[attribute]) == 'function')
      {
        continue;
      }
      if (attributes[attribute] !== null)
      {
        attrs.push((attribute == 'className' ? 'class' : attribute) + '="' + attributes[attribute].toString() + '"');
      }
    }
    return attrs.join(" ");
  },
  _children: function(element, children) 
  {
    if (typeof children == 'object') 
    {
      children.each(function(e)//children.flatten().each(function(e)
      {
        if (typeof e=='object')
        {
          element.appendChild(e);
        }
        else
        {
          if (Builder._isStringOrNumber(e))
          {
            element.appendChild(Builder._text(e));
          }
        }
      });
    }
    else
    {
      if (Builder._isStringOrNumber(children)) 
      {
        element.appendChild(Builder._text(children));
      }
    }
  },
  _isStringOrNumber: function(param) 
  {
    return(typeof param=='string' || typeof param=='number');
  },
  dump: function(scope)
  { 
    if (typeof scope != 'object' && typeof scope != 'function')
    {
      scope = window;
    }

    var tags = ("A ABBR ACRONYM ADDRESS APPLET AREA B BASE BASEFONT BDO BIG BLOCKQUOTE BODY " +
      "BR BUTTON CAPTION CENTER CITE CODE COL COLGROUP DD DEL DFN DIR DIV DL DT EM FIELDSET " +
      "FONT FORM FRAME FRAMESET H1 H2 H3 H4 H5 H6 HEAD HR HTML I IFRAME IMG INPUT INS ISINDEX "+
      "KBD LABEL LEGEND LI LINK MAP MENU META NOFRAMES NOSCRIPT OBJECT OL OPTGROUP OPTION P "+
      "PARAM PRE Q S SAMP SCRIPT SELECT SMALL SPAN STRIKE STRONG STYLE SUB SUP TABLE TBODY TD "+
      "TEXTAREA TFOOT TH THEAD TITLE TR TT U UL VAR").split(/\s+/);

    tags.each(function(tag)
    { 
      scope[tag] = function() 
      { 
        return Builder.node.apply(Builder, [tag].concat($A(arguments)));  
      } 
    });
  }
};

var Ajax = {
  filename : "common.js",

  /* *
  * 传输完毕后自动调用的方法，优先级比用户从run()方法中传入的回调函数高。
  *
  * @public
  */
  onComplete : function ()
  {
  },

  /* *
  * 传输过程中自动调用的方法。
  *
  * @public
  */
  onRunning : function ()
  {
  },

  /* *
  * 调用此方法发送HTTP请求。
  *
  * @public
  * @param   {string}    url             请求的URL地址
  * @param   {mix}       params          发送参数
  * @param   {Function}  callback        回调函数
  * @param   {string}    ransferMode     请求的方式，有"GET"和"POST"两种
  * @param   {string}    responseType    响应类型，有"JSON"、"XML"和"TEXT"三种
  * @param   {boolean}   asyn            是否异步请求的方式
  * @param   {boolean}   quiet           是否安静模式请求
  */
  call : function (url, params, callback, transferMode, responseType, asyn, quiet)
  {
    params = this.parseParams(params);
    transferMode = typeof(transferMode) === "string"
    && transferMode.toUpperCase() === "GET" ? "GET" : "POST";

    if (transferMode === "GET")
    {
      var d = new Date();

      url += params ? (url.indexOf("?") === - 1 ? "?" : "&") + params : "";
      url = encodeURI(url) + (url.indexOf("?") === - 1 ? "?" : "&") + d.getTime() + d.getMilliseconds();
      params = null;
    }

    responseType = typeof(responseType) === "string" && ((responseType = responseType.toUpperCase()) === "JSON" || responseType === "XML") ? responseType : "TEXT";
    asyn = asyn === false ? false : true;

    var xhr = this.createXMLHttpRequest();

    try
    {
      var self = this;

      if (typeof(self.onRunning) === "function" && !quiet)
      {
        self.onRunning();
      }

      xhr.open(transferMode, url, asyn);

      if (transferMode === "POST")
      {
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      }

      if (asyn)
      {
        xhr.onreadystatechange = function ()
        {
          if (xhr.readyState == 4)
          {
            switch ( xhr.status )
            {
              case 0:
              case 200: // OK!
                if (typeof(self.onComplete) === "function")
                {
                  self.onComplete();
                }

                if (typeof(callback) === "function")
                {
                  callback.call(self, self.parseResult(responseType, xhr), xhr.responseText);
                }
              break;

              case 304:
              break;

              case 400:
                 alert("XmlHttpRequest status: [400] Bad Request");
              break;

              case 404:
                alert("XmlHttpRequest status: [404] \nThe requested URL "+url+" was not found on this server.");
              break;
              case 409:
              break;

              case 503:
                 alert("XmlHttpRequest status: [503] Service Unavailable");
              break;

              default:
                alert("XmlHttpRequest status: [" + xhr.status + "] Unknow status.");
            }

            xhr = null;
          }
        }
        if (xhr != null) 
        {
          xhr.send(params);
        }
      }
      else
      {
        if (typeof(self.onRunning) === "function")
        {
          self.onRunning();
        }

        xhr.send(params);

        var result = self.parseResult(responseType, xhr);

        if (typeof(self.onComplete) === "function")
        {
          self.onComplete();
        }
        if (typeof(callback) === "function")
        {
          callback.call(self, result, xhr.responseText);
        }

        return result;
      }
    }
    catch (ex)
    {
      if (typeof(self.onComplete) === "function")
      {
        self.onComplete();
      }

      alert(this.filename + "/run() error:" + ex.description);
    }
  },

  createXMLHttpRequest : function ()
  {
    var xhr = null;

    if (window.ActiveXObject)
    {
      var versions = ['Microsoft.XMLHTTP', 'MSXML6.XMLHTTP', 'MSXML5.XMLHTTP', 'MSXML4.XMLHTTP', 'MSXML3.XMLHTTP', 'MSXML2.XMLHTTP', 'MSXML.XMLHTTP'];

      for (var i = 0; i < versions.length; i ++ )
      {
        try
        {
          xhr = new ActiveXObject(versions[i]);
          break;
        }
        catch (ex)
        {
          continue;
        }
      }
    }
    else
    {
      xhr = new XMLHttpRequest();
    }

    return xhr;
  },

  parseParams : function (params)
  {
    var legalParams = "";
    params = params ? params : "";

    if (typeof(params) === "string")
    {
      legalParams = params;
    }
    else if (typeof(params) === "object")
    {
      try
      {
        legalParams = "JSON=" + params.toJSONString();
      }
      catch (ex)
      {
        alert("Can't stringify JSON!");
        return false;
      }
    }
    else
    {
      alert("Invalid parameters!");
      return false;
    }

    return legalParams;
  },

  preFilter : function (result)
  {
    return result.replace(/\xEF\xBB\xBF/g, "");
  },

  parseResult : function (responseType, xhr)
  {
    var result = null;

    switch (responseType)
    {
      case "JSON" :
        result = this.preFilter(xhr.responseText);
        try
        {
          result = result.parseJSON();
        }
        catch (ex)
        {
          throw this.filename + "/parseResult() error: can't parse to JSON.\n\n" + xhr.responseText;
        }
        break;
      case "XML" :
        result = xhr.responseXML;
        break;
      case "TEXT" :
        result = this.preFilter(xhr.responseText);
        break;
      default :
        throw this.filename + "/parseResult() error: unknown response type:" + responseType;
    }

    return result;
  }
};

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);
}

function lefttime(time, options)
{
  var cur_date = new Date();
  this.timerID = null;

  this.options = {
    day    : 'day',
    hour   : 'hour',
    minute : 'minute',
    second : 'second',
    end    : 'end'
  };

  if (typeof options != 'undefined')
  {
    Object.extend(this.options, options || {});
  }

  this.auctionDate = 0;
  this.startTime = cur_date.getTime();

  if (time > 0)
  {
    var tmp_val = parseInt(time) - parseInt(cur_date.getTime() / 1000 + cur_date.getTimezoneOffset() * 60);
    if (tmp_val > 0)
    {
      this.auctionDate = tmp_val;
    }
  }

  this.start = function ()
  {
    var Temp;
    now = new Date();
    var ts = parseInt((this.startTime - now.getTime()) / 1000) + this.auctionDate;
    var dateLeft = 0;
    var hourLeft = 0;
    var minuteLeft = 0;
    var secondLeft = 0;
    var hourZero = '';
    var minuteZero = '';
    var secondZero = '';
    if (ts < 0)
    {
      ts = 0;
      CurHour = 0;
      CurMinute = 0;
      CurSecond = 0;
    }
    else
    {
      dateLeft = parseInt(ts / 86400);
      ts = ts - dateLeft * 86400;
      hourLeft = parseInt(ts / 3600);
      ts = ts - hourLeft * 3600;
      minuteLeft = parseInt(ts / 60);
      secondLeft = ts - minuteLeft * 60;
    }

    if (hourLeft < 10)
    {
      hourZero = '0';
    }
    if (minuteLeft < 10)
    {
      minuteZero = '0';
    }
    if (secondLeft < 10)
    {
      secondZero = '0';
    }

    if (dateLeft > 0)
    {
      Temp = '<span class="day">' + dateLeft + '</span>' + this.options.day + '<span class="hour">' + hourZero + hourLeft + '</span>' + this.options.hour + '<span class="minute">' + minuteZero + minuteLeft + '</span>' + this.options.minute + '<span class="second">' + secondZero + secondLeft + '</span>' + this.options.second;
    }
    else
    {
      if (hourLeft > 0)
      {
        Temp = '<span class="day">' + dateLeft + '</span>' + this.options.day + '<span class="hour">' + hourZero + hourLeft + '</span>' + this.options.hour + '<span class="minute">' + minuteZero + minuteLeft + '</span>' + this.options.minute + '<span class="second">' + secondZero + secondLeft + '</span>' + this.options.second;
      }
      else
      {
        if (minuteLeft > 0)
        {
          Temp = '<span class="day">' + dateLeft + '</span>' + this.options.day + '<span class="hour">' + hourZero + hourLeft + '</span>' + this.options.hour + '<span class="minute">' + minuteZero + minuteLeft + '</span>' + this.options.minute + '<span class="second">' + secondZero + secondLeft + '</span>' + this.options.second;
        }
        else
        {
          if (secondLeft > 0)
          {
            Temp = '<span class="day">' + dateLeft + '</span>' + this.options.day + '<span class="hour">' + hourZero + hourLeft + '</span>' + this.options.hour + '<span class="minute">' + minuteZero + minuteLeft + '</span>' + this.options.minute + '<span class="second">' + secondZero + secondLeft + '</span>' + this.options.second;
          }
          else
          {
            Temp = '';
          }
        }
      }
    }

    if (this.auctionDate <= 0 || Temp == '')
    {
      Temp = "<strong>" + this.options.end + "</strong>";
      clearTimeout(this.timerID);
    }
    else
    {
      //alert(this.start);
      this.timerID = setTimeout(this.start.bind(this), 1000);
    }
    if (document.getElementById('oTime'))
    {
      document.getElementById('oTime').innerHTML = Temp;
    }
  }
}

/* *
 * 显示载入信息
 */
function showLoader()
{
  document.getElementsByTagName('body').item(0).style.cursor = "wait";

  if (top.frames['header-frame'])
  {
    top.frames['header-frame'].document.getElementById("load-div").style.display = "block";
  }
  else
  {
    var obj = document.getElementById('loader');

    if ( ! obj)
    {
      obj = document.createElement("DIV");
      obj.id = "loader";
      obj.innerHTML = process_request;

      document.body.appendChild(obj);
    }
  }
}

/* *
 * 隐藏载入信息
 */
function hideLoader()
{
  document.getElementsByTagName('body').item(0).style.cursor = "auto";
  if (top.frames['header-frame'])
  {
    setTimeout(function(){top.frames['header-frame'].document.getElementById("load-div").style.display = "none"}, 10);
  }
  else
  {
    try
    {
      var obj = document.getElementById("loader");
      obj.style.display = 'none';
      document.body.removeChild(obj);
    }
    catch (ex)
    {}
  }
}

function showSelectBoxes(dom)
{
  if (typeof dom === 'undefined')
  {
    dom = document;
  }
	selects = dom.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) 
  {
		selects[i].style.visibility = "visible";
	}
}

function hideSelectBoxes(dom)
{
  if (typeof dom === 'undefined')
  {
    dom = document;
  }
	selects = dom.getElementsByTagName("select");
	for (i = 0; i != selects.length; i++) 
  {
		selects[i].style.visibility = "hidden";
	}
}

/**** Vdoing Code ****/
//document.writeln("<script type=\"text\/javascript\">var wea_sid = 9435;<\/script>");
//document.writeln("<script type=\"text\/javascript\" charset=\"UTF-8\" src=\"http:\/\/s.vdoing.com\/u\/18\/9435.js\"><\/script>");
//document.writeln("<noscript><a href=\"http:\/\/www.vdoing.com\" title=\"Vdoing StatsX No.9435\"><img src=\"http:\/\/simg.vdoing.com\/m\/9435\/x01.gif?noscript\" border=\"0\"><\/a><\/noscript>");
/**** End of Vdoing Code ****/ 

function priceFormat(s, currency)
{
  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 currency + s.replace(/^\./,"0.")
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
