﻿
var nStr1 = new Array('日','一','二','三','四','五','六','七','八','九','十')
var now;var SY;var SM;var SD;
var IMGDIR='timepiece/images';
var hiddenobj =pmwindragstart= new Array();
function cyclical(num) { return(Gan[num%10]+Zhi[num%12]) }
function YYMMDD() { return('<font style="font-size:14px">'+SY+'年'+(SM+1)+'月'+SD+'日</font>')}
function weekday(){
    var cl = '<font style="font-size:12px"';
    if (now.getDay() == 0) cl += ' color=#ffffff';
    if (now.getDay() == 6) cl += ' color=#ffffff';
    return(cl+'>星期'+nStr1[now.getDay()]+'</font>')
}
function showcal() {
	now = new Date();SY = now.getFullYear();SM = now.getMonth();SD = now.getDate();
	var hh = now.getHours();var mm = now.getMinutes();var ss = now.getTime() % 60000;
	ss = (ss - (ss % 1000)) / 1000;
	if (hh < 10) hh='0'+hh;
	if (mm < 10) mm='0'+mm;
	hh+=':'+mm;
	if (ss < 10) ss='0'+ss;
	hh +=":"+ss
	var str=' '+YYMMDD()+' '+weekday()+" <span id=ClockTime>"+hh+'</span> <span id=MyClock onclick="javascript:pmwin( \'open\',\'timepiece/myclock.htm\', 320 , 340,\'\')" style="cursor:pointer;color:#f82f00" title=点击设置闹钟><span>'
	$('timepiece').innerHTML=str
	window.setTimeout("showcal()", 1000);
}
function pmwin(action, param, pmwidth , pmheight,is_none) {
	var objs = document.getElementsByTagName("OBJECT");
	
	if(action == 'open') {
		if(is_none!='none') createBlurDiv()//打开背景
		for(i = 0;i < objs.length; i ++) {
			if(objs[i].style.visibility != 'hidden') {
				objs[i].setAttribute("oldvisibility", objs[i].style.visibility);
				objs[i].style.visibility = 'hidden';
			}
		}
		var clientWidth = document.body.clientWidth;
		var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
		var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
//		var pmwidth = pmwidth?600:pmwidth;
//		var pmheight = clientHeight * 0.9;
//		
		if(!$('pmlayer')) {
			div = document.createElement('div');div.id = 'pmlayer';
			div.style.width = pmwidth + 'px';
			div.style.height = pmheight + 'px';
			div.style.left = ((clientWidth - pmwidth) / 2) + 'px';
			div.style.position = 'absolute';
			div.style.zIndex = '999';
			$('append_parent').appendChild(div);
			$('pmlayer').innerHTML = '<div style="width: '+pmwidth+'px; margin: 10px auto; text-align: left">' +
				'<div style="width: '+pmwidth+'px; height: ' + pmheight + 'px; position: relative; left: -6px; top: -3px">' +
				'<div style="position: relative; left: 0px; top: 0px; width: '+pmwidth+'px; height: 30px; margin-bottom: -30px;"></div>' +
				'<img  onclick="pmwin(\'close\')" style="cursor:pointer;position: absolute; right: 44px; top: 16px" src="' + IMGDIR +'/close.gif" title="关闭" />'+
				'<img style="cursor: move;position: absolute;  right: 20px; top: 16px" src="' + IMGDIR +'/move.gif" title="按住移动"  onmouseover="pmwindrag(this)" />' +
				'<div id="pmwinmask" style="margin-top: 30px; position: absolute; width: 100%; height: 100%; display: none"></div><iframe id="pmframe" name="pmframe" style="width:' + pmwidth + 'px;height:100%" allowTransparency="true" frameborder="0"></iframe></div></div>';
		}
		$('pmlayer').style.display = (is_none==''?'':is_none);
		$('pmlayer').style.top = ((clientHeight - pmheight) / 2 + scrollTop) + 'px';

		pmframe.location = param;

	} else if(action == 'close') {
		removeBlurDiv()//关闭背景
		for(i = 0;i < objs.length; i ++) {
			if(objs[i].attributes['oldvisibility']) {
				objs[i].style.visibility = objs[i].attributes['oldvisibility'].nodeValue;
				objs[i].removeAttribute('oldvisibility');
			}
		}
		hiddenobj = new Array();
		$('pmlayer').style.display = 'none';
	}
}

function pmwindrag(obj) {
	obj.onmousedown = function(e) {
		if(is_ie) {
			document.body.onselectstart = function() {
				return false;
			}
		}
		pmwindragstart = is_ie ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
		pmwindragstart[2] = parseInt($('pmlayer').style.left);
		pmwindragstart[3] = parseInt($('pmlayer').style.top);
		$('pmwinmask').style.display = '';
		doane(e);
	}

	_attachEvent(document.body, 'mousemove', function(e) {
													  
		if(pmwindragstart[0]) {
			var pmwindragnow = is_ie ? [event.clientX, event.clientY] : [e.clientX, e.clientY];
			with($('pmlayer')) {
				style.left = (pmwindragstart[2] + pmwindragnow[0] - pmwindragstart[0]) + 'px';
				style.top = (pmwindragstart[3] + pmwindragnow[1] - pmwindragstart[1]) + 'px';
			}
			doane(e);
		}
	});
	
	obj.onmouseup = function(e) {
		if(is_ie) {
			document.body.onselectstart = function() {
				return true;
			}
		}
		pmwindragstart = [];
		$('pmwinmask').style.display = 'none';
		doane(e);
	}
	obj.onmouseover = null;
}





//时钟
showcal();
