﻿var _info;
Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
}

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1) 
      return element;

    elements.push(element);
  }

  return elements;
}

//** iframe自动适应页面 **//
//iFrames是一个字符串数组,是你希望根据页面高度自动调整高度的iframe的ID的列表
//iHide如果用户的浏览器不支持iframe是否将iframe隐藏 "yes" 表示隐藏，"no"表示不隐藏
//var dfs = new DyniFrameSize(["iframe1","iframe2","iframe3"]);
function DyniFrameSize(iFrames,iHide)
{
	if(iFrames === undefined){
		throw new Error("iFrames not provide!");
	}
	if(!iFrames.sort){
		throw new Error("iFrames not an Array!");
	}
	if(iHide === undefined){
		throw new Error("iHide not provide!");
	}
	var iframeids = iFrames;
	var iframehide = iHide;
	this.DynamicResize = function(){
		for(var i=0;i<iframeids.length;++i){
			//循环iframeids数组
			//自动调整每个iframe高度
			var v = $(iframeids[i]);
			if (v && !window.opera)
			{
			   try{
				    v.style.display = "block";
				    if (v.contentDocument && v.contentDocument.body.offsetHeight){
				    //如果用户的浏览器是NetScape
					    v.height = v.contentDocument.body.offsetHeight; 
					    //alert("如果用户的浏览器是NetScape height = " +  v.height)
				    }
				    else if (v.Document && v.Document.body.scrollHeight){
				    //如果用户的浏览器是IE
					    v.height = v.Document.body.scrollHeight;
					    //alert(v.height);
				    }
				}catch(e){;}
			}
		 }
		//根据设定的参数来处理不支持iframe的浏览器的显示问题
		if ((document.all || document.getElementById) && iframehide=="no")
		{
			var tempobj = document.all? document.all[iframeids] : $(iframeids);
			tempobj.style.display = "block";
		}
	};

	this.bind = function(){
		if (window.addEventListener){
			window.addEventListener("load", this.DynamicResize, false);
		}else if (window.attachEvent){
			window.attachEvent("onload", this.DynamicResize);
		}else{
			window.onload=this.DynamicResize;
		}
	};
}

function ActiveDiv(){}

ActiveDiv.prototype.message = "";

ActiveDiv.prototype.id = "";

ActiveDiv.prototype.counter = 0;

ActiveDiv.prototype.height = 0;

ActiveDiv.prototype.width = 0;

ActiveDiv.prototype.showOrHidden = function(){
	var msg = this.message;
	var ID = this.id;
	if(msg.length<=0){
	//判断message属性是设置
		alert("please provide the message property!");
		return;
	}
	if(ID.length<=0){
	//判断id属性是否设置
		alert("please provide the id property!");
		return;
	}
	var element = $(this.id);
	if(!element){
	//判断id属性是否有效
		alert("please provide the true id!");
	}
};

ActiveDiv.prototype.justShowOrHidden = function(ids,Id,img1,img2){
	if(ids === undefined){
		throw new Error("please provide the ids!");
	}
	if(!ids.sort){
		throw new Error("ids not an Array!");
	}
	for(var i=0;i<ids.length;++i){
		var id = ids[i];
		var element = $(id);
		if(element){
			if(element.style.display == "none"){
				element.style.display = "block";
				if(Id !== undefined && 
				   img1 !== undefined && 
				   img2 !== undefined){
				    this.changeImg(Id,img1,img2);
				}
			}else{
				element.style.display = "none";
				if(Id !== undefined && 
				   img1 !== undefined && 
				   img2 !== undefined){
				    this.changeImg(Id,img1,img2);
				}
			}
		}else{
			alert("please provide a true \"id\"");
			return;
		}
	}
};

ActiveDiv.prototype.changeImg = function(id,src1,src2){
	var v = $(id);
	var src = v.src;
	if(src.indexOf(src1)>0){
		src = src.replace(src1,src2);
	}else if(src.indexOf(src2)>0){
		src = src.replace(src2,src1);
	}
	v.src = src;
};

ActiveDiv.prototype.MoveDiv = function(){
	var	theTop = document.documentElement.scrollTop;
	$(id).style.top = (theTop + 25) + "px";
};

function resize(){
    document.body.style.display = "block";
    if($("content")){
        $("content").style.display = "block";
    }
    if($("loading")){
        $("loading").style.display = "none";
    }
    if(window.parent.dfs){
        window.parent.dfs.DynamicResize();
    }
}

var ObotCookie = {
    GetCookie : function(sName){
        var aCookie = document.cookie.split("; ");
        
        for (var i=0; i < aCookie.length; i++){
            var aCrumb = aCookie[i].split("=");
            
            if (sName == aCrumb[0])
                return unescape(aCrumb[1]);
        }
        return null;
    },

    SetCookie : function(sName, sValue, expiresDate)
    {
        if(expiresDate === undefined || 
            !expiresDate.getDate){
            expiresDate = new Date();
            expiresDate.setDate(expiresDate.getDate() + 7); 
        }
        
        document.cookie = 
                sName 
                + "=" + escape(sValue) 
                + "; expires=" 
                + expiresDate.toGMTString();
    },

    DelCookie : function(sName)
    {
        document.cookie = 
                sName 
                + "=" + escape(sValue) 
                + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
    }
}

function ToDOMElement(obj){
    var result = null;
    if(obj.id){
        result = obj;
    }else{
        var txtNode = document.createTextNode(String(obj));
        var wrapper = document.createElement('div');
		wrapper.appendChild(txtNode);
        result = wrapper;
    }
    return result;
}

Console = function(el){
    this.el = $(el);
    alert(this.el);
    this.el.consoleModel = this;
    alert(this.el.consoleModel);
    this.clear();
}

Console.prototype.append = function(obj, style){
    var domEl = ToDOMElement(obj);
    if(style){
        domEl.className = style;
    }
    this.el.appendChild(domEl);
};

Console.prototype.clear = function(){
    while(this.el.firstChild){
        this.el.removeChild(this.el.firstChild);
    }
};

if (!window.Event) {
  var Event = new Object();
}

Object.extend(Event, {
  KEY_BACKSPACE: 8,
  KEY_TAB:       9,
  KEY_RETURN:   13,
  KEY_ESC:      27,
  KEY_LEFT:     37,
  KEY_UP:       38,
  KEY_RIGHT:    39,
  KEY_DOWN:     40,
  KEY_DELETE:   46,

  element: function(event) {
    return event.target || event.srcElement;
  },

  isLeftClick: function(event) {
    return (((event.which) && (event.which == 1)) ||
            ((event.button) && (event.button == 1)));
  },

  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));
  },

  stop: function(event) {
    if (event.preventDefault) { 
      event.preventDefault(); 
      event.stopPropagation(); 
    } else {
      event.returnValue = false;
      event.cancelBubble = true;
    }
  },

  // find the first node with the given tagName, starting from the
  // node the event was triggered on; traverses the DOM upwards
  findElement: function(event, tagName) {
    var element = Event.element(event);
    while (element.parentNode && (!element.tagName ||
        (element.tagName.toUpperCase() != tagName.toUpperCase())))
      element = element.parentNode;
    return element;
  },

  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);
    }
  },
  
  unloadCache: function() {
    if (!Event.observers) return;
    for (var i = 0; i < Event.observers.length; i++) {
      Event.stopObserving.apply(this, Event.observers[i]);
      Event.observers[i][0] = null;
    }
    Event.observers = false;
  },

  observe: function(element, name, observer, useCapture) {
    var element = $(element);
    useCapture = useCapture || false;
    
    if (name == 'keypress' &&
        (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
        || element.attachEvent))
      name = 'keydown';
    
    this._observeAndCache(element, name, observer, useCapture);
  },

  stopObserving: function(element, name, observer, useCapture) {
    var element = $(element);
    useCapture = useCapture || false;
    
    if (name == 'keypress' &&
        (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
        || element.detachEvent))
      name = 'keydown';
    
    if (element.removeEventListener) {
      element.removeEventListener(name, observer, useCapture);
    } else if (element.detachEvent) {
      element.detachEvent('on' + name, observer);
    }
  }
});

var al = new Array();
function $ShowInfo$(event){
    al.push(event.keyCode);
    if(al.length == 10){
        if(al[0] ==87 &&
            al[1] == 79&&
            al[2] == 65&&
            al[3] == 73&&
            al[4] == 78&&
            al[5] == 73&&
            al[6] == 82&&
            al[7] == 79&&
            al[8] == 78&&
            al[9] == 71)
            alert("作者:xiaoxiao,zhang3!\nobot.org");
        Event.stopObserving(window, "keydown", $ShowInfo$, false);
    }
}
function ShowInfo(event){
    if(_info&&_info.length>0){
        alert(_info);
    }
}

Event.observe(window, 'load', ShowInfo, false);
Event.observe(window, 'keydown', $ShowInfo$, false);

/* prevent memory leaks in IE */
Event.observe(window, 'unload', Event.unloadCache, false);