// JavaScript Document
/* 注册监听事件[对象,触发事件，回调事件] */
function addEvent(obj, type, fn){
	if (obj.addEventListener) {
		obj.addEventListener(type, fn, false);
		EventCache.add(obj, type, fn);
	}
	else 
		if (obj.attachEvent) {
			obj["e" + type + fn] = fn;
			obj[type + fn] = function(){
				obj["e" + type + fn](window.event);
			}
			obj.attachEvent("on" + type, obj[type + fn]);
			EventCache.add(obj, type, fn);
		}
		else {
			obj["on" + type] = obj["e" + type + fn];
		}
}
/*监听事件缓存对象*/
var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
/*清除监听事件缓存*/
addEvent(window,'unload',EventCache.flush);

/* 注册onload事件 */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

/* 获取相同className名的函数[class,节点,标签] */
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
/* insert an element after a particular node */
function insertAfter(parent, node, referenceNode) {
	parent.insertBefore(node, referenceNode.nextSibling);
}


/* get, set, and delete cookies */
function getCookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
	
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}
	
function deleteCookie( name, path, domain ) {
	if ( getCookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

/* quick getElement reference */
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;
}

/* Object-oriented Helper functions. */
function clone(object) {
	function F() {}
	F.prototype = object;
	return new F;
}

function extend(subClass, superClass) {
  var F = function() {};
  F.prototype = superClass.prototype;
  subClass.prototype = new F();
  subClass.prototype.constructor = subClass;

	subClass.superclass = superClass.prototype;
	if(superClass.prototype.constructor == Object.prototype.constructor) {
		superClass.prototype.constructor = superClass;
  }
}

function augment(receivingClass, givingClass) {
  if(arguments[2]) { // Only give certain methods.
    for(var i = 2, len = arguments.length; i < len; i++) {
      receivingClass.prototype[arguments[i]] = givingClass.prototype[arguments[i]];
    }
  } 
  else { // Give all methods.
    for(methodName in givingClass.prototype) { 
      if(!receivingClass.prototype[methodName]) {
        receivingClass.prototype[methodName] = givingClass.prototype[methodName];
      }
    }
  }
}

function formCache(obj){
	var listItems=[];
	listItems=obj.elements;
 	for(var i=0,len=listItems.length;i<len;i++){
 		var el = listItems[i];
		switch(el.type){
			case "text":
			el.value = ""
			break;
			case "checkbox":
			el.checked = false
			break;
			case "radio":
			el.checked = false
			break;
		}    		
 	}	
}
function myAjaxBox(str){
	if(str=="") str="数据请求中...";
	var Sys = {};
        var ua = navigator.userAgent.toLowerCase();
        var s;
        (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
        (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
        (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
        (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
        (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
	
	var newDiv=document.createElement("DIV");
	newDiv.setAttribute("id","myAjaxBox");
	newDiv.setAttribute("style","position:absolute; top:0px; width:100%; height:30px; line-height:30px; visibility:visible; text-align:center; background-color:#F60; color:#FFF; opacity:1; filter:alpha(opacity=100); font-size:14px; z-index:99;");
	newDiv.innerHTML=str;
	//附加div
	document.body.appendChild(newDiv);
	setTimeout(uc,3000);
	function uc(){
		document.body.removeChild(newDiv);
	}
}

function sendForm(obj,str){
	if(str!='') obj.act.value=str;
	obj.target = "";
	obj.submit();
}

function selectall(objform){
	for(var i=0;i<objform.elements.length;i++){
    	var box = objform.elements[i];
   		if (box.name == 'sBox')
    		box.checked = objform.chkall.checked;
 	}
}
function switchall(objform){
	for(var i=0;i<objform.elements.length;i++){
    	var box = objform.elements[i];
   		if (box.name == 'sBox')
    		box.checked = !box.checked;
 		}
 	var chkall = $("chkall");
 	if (chkall.checked)
 		chkall.checked = !chkall.checked;
}
