﻿// 解决 FF 没有 outerHTML
if(window.HTMLElement) {
	HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){
	var r=this.ownerDocument.createRange();
	r.setStartBefore(this);
	var df=r.createContextualFragment(sHTML);
	this.parentNode.replaceChild(df,this);
	return sHTML;
	});

	HTMLElement.prototype.__defineGetter__("outerHTML",function(){
	var attr;
	var attrs=this.attributes;
	var str="<"+this.tagName.toLowerCase();
	for(var i=0;i<attrs.length;i++){
		attr=attrs[i];
		if(attr.specified)
			str+=" "+attr.name+'="'+attr.value+'"';
		}
	if(!this.canHaveChildren)
		return str+">";
	return str+">"+this.innerHTML+"</"+this.tagName.toLowerCase()+">";
	});

	HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
	switch(this.tagName.toLowerCase()){
		case "area":
		case "base":
		case "basefont":
		case "col":
		case "frame":
		case "hr":
		case "img":
		case "br":
		case "input":
		case "isindex":
		case "link":
		case "meta":
		case "param":
		return false;
	}
	return true;
	});
}

// 弹出中央窗口,示例: <a href="#" onclick="openWinCenter(this.href,'newwin','width=320,height=240,status=no,menubar=no,resize=yes');return false"></a>
function openWinCenter(url, wname, wopt) {
	var newopt = "", wHeight = 0, wWidth = 0;
	if (wopt != undefined) {
		var woptlist = wopt.replace(/ /g, "").split(",");
		for (var i in woptlist) {
			if (woptlist[i].match(/^height=/i)) {
				wHeight = parseInt(woptlist[i].substr(7),10);
				if (!isNaN(wHeight)) newopt += "top=" + Math.floor((screen.availHeight - wHeight) / 2) + ",";
			}
			if (woptlist[i].match(/^width=/i)) {
				wWidth = parseInt(woptlist[i].substr(6),10);
				if (!isNaN(wWidth)) newopt += "left=" + Math.floor((screen.availWidth - wWidth) / 2) + ",";
			}
		}
	}
	return window.open(url, wname, newopt + wopt);
}

// 加载Flash文件,示例: <script type="text/javascript">swf('demo.swf','480','320');</script>
function swf(src,w,h){
	html = '';
	html += '<object type="application/x-shockwave-flash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=10,0.12.36" id="param" width="'+w+'" height="'+h+'">';
	html += '<param name="movie" value="'+src+'">';
	html += '<param name="quality" value="high">';
	html += '<param name="bgcolor" value="#FFFFFF">';
	html += '<param name="menu" value="false">';
	html += '<param name="allowFullScreen" value="true">';
	html += '<param name="wmode" value="transparent">';
	html += '<param name="swliveconnect" value="true">';
	html += '<embed src="'+src+'" quality="high" bgcolor="#FFFFFF" menu="false" width="'+w+'" height="'+h+'" swliveconnect="true" id="param" name="param" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
	html += '</object>';
	document.write(html);
}

function ReImgSize(intWidth){
		var imgwidth = intWidth;
		for (i = 0; i < document.images.length; i++)
		{
		var imageWidth;
		var imageHeight;
			if (document.images[i].width > imgwidth)
			{
				imageWidth = document.images[i].width;
				imageHeight = document.images[i].height;

				document.images[i].width = imgwidth;
				try{
					document.images[i].outerHTML="<a href='javascript:void(0)' onclick=openWinCenter('../image-view.aspx?image="+document.images[i].src+"','imageview','width="+imageWidth+",height="+imageHeight+",status=no,menubar=no,resize=yes')" + " title='在新窗口打开图片'>"+document.images[i].outerHTML+"</a>"
				}catch(e){}
			}
		}
	}

function upChar(bytesize, mententname, textlimitname){
	var strCount = 0;
	var tempStr, tempStrMax;	
	for(i = 0;i < document.getElementById(mententname).value.length;i++){
		tempStr = document.getElementById(mententname).value.charAt(i);
		strCount += 1 ;
	}
	if (strCount > bytesize){
		alert("最大允许 " + bytesize + " 个文字,超出部分自动删除!");		
		strCount = 0;		
		tempStrMax = "";
		for(i = 0; i < document.getElementById(mententname).value.length; i++) {
			tempStr = document.getElementById(mententname).value.charAt(i);
			strCount += 1 ;
			if (strCount > bytesize)
			{
				strCount -= 1 ;	
				break;	      		
			}
			else tempStrMax += tempStr;
		}
		document.getElementById(mententname).value = tempStrMax;
	}
	document.getElementById(textlimitname).innerHTML = strCount;
	}
	
// floatDiv
var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
var isNS = navigator.appName == "Netscape";

function getRef(id) {
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) return document.layers[id];
}

function moveDiv(div,top) {

	var yMenuFrom, yMenuTo, yOffset, timeoutNextCheck;
	if (isNS4) {
		var divMenu = document[div];
		yMenuFrom = divMenu.top;
		yMenuTo = window.pageYOffset + top;
	} else if (isDOM) {
		var divMenu = getRef(div);
		yMenuFrom = parseInt (divMenu.style.top, 10);
		yMenuTo = (isNS ? window.pageYOffset : document.documentElement.scrollTop) + top;
	}
	timeoutNextCheck = 30;

	if (yMenuFrom != yMenuTo) {
		yOffset = Math.ceil(Math.abs(yMenuTo - yMenuFrom) / 20);
	if (yMenuTo < yMenuFrom)
		yOffset = -yOffset;
	if (isNS4)
		divMenu.top += yOffset;
	else if (isDOM)
		divMenu.style.top = parseInt (divMenu.style.top, 10) + yOffset +"px";
		timeoutNextCheck = 5;
	}
	setTimeout ("moveDiv('" + div + "'," + top + ")", timeoutNextCheck);
}

function floatDiv(floatdiv,top) {
	if (isNS4) {
		var div = document[floatdiv];
		div.top = top.pageYOffset + 400;
		div.visibility = "visible";
		moveDiv(floatdiv,top);
	} else if (isDOM) {
		var div = getRef(floatdiv);
		div.style.top = (isNS ? window.pageYOffset : document.body.scrollTop) + 400 +"px";
		div.style.visibility = "visible";
		moveDiv(floatdiv,top);
	}
}

function TimeRefresh()
{
$.ajax({url: '/getime.aspx',
		type: 'get',
		dataType: 'xml',
		timeout: 20000,
		error: function(){
			   },
		success: function(result){
			{
				$('#nowtime').fadeOut(500,function(){
					$('#nowtime').text($("Time" , result).text());
				}); 
				$('#nowtime').fadeIn(1500);
			}
		}
})
}
setInterval('TimeRefresh()',60000);
