function $i(e) {
	return typeof(e)=='object' ? e : document.getElementById(e);
}

// 日期时间
var dateTime = function(o, d, w, t) {
	var $self = this;
	
	this.now		= new Date();
	this.showObj	= !!o ? $i(o) : null;
	this.timer		= null;
	this.tInt		= null;
	
	this.date = function() {
		var nY = $self.now.getFullYear(), nM = $self.now.getMonth()+1, nD = $self.now.getDate();
		return (nY +'年'+ nM +'月'+ nD +'日');
	};
	
	this.week = function() {
		return '星期'+'日一二三四五六'.charAt(new Date().getDay());
	};
	
	this.time = function() {
		var now = new Date();
		var nH = now.getHours(), nM = now.getMinutes(), nS = now.getSeconds();
		nH = nH >= 10 ? nH : '0'+ nH;
		nM = nM >= 10 ? nM : '0'+ nM;
		nS = nS >= 10 ? nS : '0'+ nS;
		var tmpStr = null;
		var tInt = null;
		if(this.timer == null){
			clearInterval(this.tInt);
			tmpStr = '<span id="_'+ o +'_timer">'+
					 nH +':'+ nM +':'+ nS +
					 '<\/span>';
			this.timer = $i('_'+ o +'_timer');
			this.tInt = setInterval(function(){$self.time();}, 1000);
			return tmpStr;
		}else{
			tmpStr = nH +':'+ nM +':'+ nS;
			this.timer.innerHTML = tmpStr;
		}
	};
	
	this.show = function() {
		if(this.showObj == null){ return;}
		var tnpStr = null;
		var tmpDate = new Array();
		tmpDate[0] = d ? this.date() : null;
		tmpDate[1] = w ? this.week() : null;
		tmpDate[2] = t ? this.time() : null;
		tnpStr = tmpDate.join('&nbsp;');
		this.showObj.innerHTML = tnpStr;
	}
};

function setDateTime() {
	$i("DateTime").innerHTML = new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());
};
