addLoadEvent = function(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
};
navBgSwap = function(){
	var lis = $$('#nav li'), len = lis.length, i = 1;
	for( i; i < len -1 ; i ++ ){
		if(lis[i].hasClassName('nav_on')) continue;
		lis[i].onmouseover = function(){
			this.addClassName('nav_on');
		};
		lis[i].onmouseout = function(){
			this.removeClassName('nav_on');
		}
	}
};
LoadScript = function(url, target, charset){
	var target = $(target) || document.getElementsByTagName("head")[0];
	var charset = charset || 'utf-8';
	var arr, fn, id, js;
	arr = url.split('/');
	fn = arr[arr.length-1].split('.');
	id = fn[0];
	if($(id)){
		return false;
	}
	js   = document.createElement("script");
	js.type  = "text/javascript";
	js.defer = "defer";
	js.src   = url;
	js.id    = id;
	js.charset = charset;
	target.appendChild(js);
};
showDialog = function (url,name, options)
{
	var opt = {w:640, h:450, l:200, t:180};
	var options;
	if(Object.extend){
		options = Object.extend(opt, options || {});
	}else{
		options = options || opt;
	}
	var url = url || 'about:blank';
	var name = name || 'Gosun';
	var winpopus = showModalDialog(url, name, 'dialogWidth:'+options.w+'; dialogHeight:'+options.h
	+'; dialogTop:'+options.t+'; dialogLeft:'+options.l+';help: no; scroll: yes; status: no');
};
winX = function(url, name, options){
	try{
		showDialog(url, name, options);
	}catch(e){
		openwin(url, name, options);
	}
};
delConfirm = function(msg){
	var msg = msg || '确认要删除该记录';
	return confirm(msg);
};
getCheckbox = function(name, container){
	var obj, value = [];
	if(container){
		obj = $(container).getElementsBySelector('input[name="'+ name +'"]');
	}else{
		obj = document.getElementsByName(name);
	}
	if(!obj){
		return false;
	}
	for(var i=0; i<obj.length; i++){
		if(obj[i].checked == true && obj[i].disabled == false){
			value.push(obj[i].value);
		}
	}
	return value.length>0? value: false;
};
getRadio = function(name, container){
	var obj, value = false;
	if(container){
		obj = $(container).getElementsBySelector('input[name="'+ name +'"]');
	}else{
		obj = document.getElementsByName(name);
	}
	if(!obj){
		return false;
	}
	for(var i=0; i<obj.length; i++){
		if(obj[i].checked == true && obj[i].disabled == false){
			value = obj[i].value;
			break;
		}
	}
	return value;
};
checkall = function(form, obj)
{
	var form = (typeof form == 'object') ? form : $(form);
	var	colInputs = $$('input[type="checkbox"]');
	var _chk = obj.checked;
	var i=0, len = colInputs.length;
	for	(i; i < len; i++)
	{
		colInputs[i].checked= _chk;
	}
};

allSelect = function (form){
	var form = (typeof form == 'object') ? form : $(form);
	var	colInputs = form.getElementsByTagName("input");
	var i=0, len = colInputs.length;
	for	(i; i < len; i++)
	{
		colInputs[i].checked= true;
	}
};

allUnSelect = function (form){
	var form = (typeof form == 'object') ? form : $(form);
	var	colInputs = form.getElementsByTagName("input");
	var i=0, len = colInputs.length;
	for	(i; i < len; i++)
	{
		colInputs[i].checked= false;
	}
};
InverSelect = function (form){
	var form = (typeof form == 'object') ? form : $(form);
	var	colInputs = form.getElementsByTagName("input");
	var i=0, len = colInputs.length;
	for	(i; i < len; i++)
	{
		colInputs[i].checked= !colInputs[i].checked;
	}
};
Common = {
	trim : function(str){
		return str.replace(/(^\s*)|(\s*$)/g, "");
	},
	strlen : function (str)
	{
		return str.replace(/[^\x00-\xff]/g, "**").length;
	},
	isdate : function (str){
		var result=str.match(/^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2})$/);
		if(result==null) return false;
		var d=new Date(result[1], result[3]-1, result[4]);
		return (d.getFullYear()==result[1] && d.getMonth()+1==result[3] && d.getDate()==result[4]);
	},
	isdatetime : function(val){
		var result=str.match(/^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
		if(result==null) return false;
		var d= new Date(result[1], result[3]-1, result[4], result[5], result[6], result[7]);
		return (d.getFullYear()==result[1]&&(d.getMonth()+1)==result[3]&&d.getDate()==result[4]&&d.getHours()==result[5]&&d.getMinutes()==result[6]&&d.getSeconds()==result[7]);
	},
	isnumber : function(val){
		var reg = /[\d|\.|,]+/;
		return reg.test(val);
	},
	isalphanumber : function (str){
		var result=str.match(/^[a-zA-Z0-9_]+$/);
		if(result==null) return false;
		return true;
	},
	isint : function(val){
		var reg = /\d+/;
		return reg.test(val);
	},
	isemail : function(email){
		var reg = /([\w|_|\.|\+]+)@([-|\w]+)\.([A-Za-z]{2,4})/;
		return reg.test( email );
	},
	isurl : function(url){
		var reg = /^[a-zA-z]+:\/\/(\w+(-\w+)*)(\.(\w+(-\w+)*))*(\?\S*)?$/;
		return reg.test(url);
	},
	isnotnull : function(str){
		return this.strlen(this.trim(str));
	},
	isimg : function(str, allowExt){
		var allowExt = allowExt || ['gif', 'jpg', 'jpeg'];
		var arr = this.trim(str).split('.');
		var ext = arr[arr.length-1].toLowerCase();
		if(allowExt.indexOf(ext) == -1){
			return false;
		}else{
			return true;
		}
	},
	dump : function( msg,time ){
		time = time && time * 1000 || 2000;
		if (typeof msg === "string"){
			if ( msg.indexOf('|') != -1 ){
				msg = '<p>'+ msg.split('|').join('</p><p>');
			}else{
				msg = '<p>' + msg;
			}
		}

		if (typeof msg === 'object'){
			var msgs = new Array();
			for(var p in msg){
				msgs.push(p + ':&nbsp;' + msg[p]);
			}
			msg = '<p>' + msgs.join('</p><p>');
		}


		if ( !$('debug_dump')){
			var _node = new Element('div', {id:'debug_dump'});
			$$('body')[0].insert({top:_node});
		}

		$('debug_dump').setStyle({
			position        : 'absolute',
			backgroundColor : '#000',
			opacity         :  '0.65',
			top             :  '0',
			left            :  '0',
			width           :  $$('body')[0].getWidth(),
			lineHeight      :  '28px',
			zIndex          :  '99999',
			textIndent      :  '20px',
			color           :  '#fff'
		}).update('输出结果是： '+ msg +'</p>').observe('click', function(event){
			this.onmouseout = function(){
				setTimeout(function(){
					$('debug_dump').remove();
				},time);
			};
		});
	}
};
jumpToPage = function(id){
	var page = parseInt($F(id), 10);
	if(isNaN(page)){
		alert('请输入一个正整数');
		$(id).value = '';
		return false;
	}
	var url = window.location.href;
	if(url.indexOf('?') != -1){
		window.location.href = url.replace(/page=[0-9]+/i, 'page='+page);
	}else{
		window.location.href = url+'?page='+page;
	}
};
poputip = {
	show:function(name){
		var tagObj = $(name);
		var tipObj = $(name+'-tip');
		var _offset = tagObj.cumulativeOffset();
		var dime = tipObj.getHeight();
		tipObj.setStyle({top:_offset[1]-dime+'px', left:_offset[0]+'px'}).show();
	},
	hide:function(name){
		$(name+'-tip').hide();
	}
};