<!--
///////////////////////////////////////////////////////////////////////////////
//
// 张树林 - 慧佳工作室
//
// Module Name:     tip-window.js
// Abstract:        提示窗口
// Version:         2.0
// Date				2009-02-01
// Author:          woods·zhang
// Email:           hoojar@163.com 
// MSN:             hoojar@hotmail.com
// Website:         http://www.hoojar.com/
// Copyright 2001-2007, Hoojar studio All Rights Reserved
//
// 版权 2001-2007，慧佳工作室所有版权保护
//The software for free software, allowing use, copy, 
//modify and distribute the software and files. Any 
//use of this software must place a copy of all the 
//above copyright notice. By the software Huijia studio 
//maintenance, if you have any queries please contact us.
//Thank you. 
//
//此软件为自由软件，允许使用、拷贝、修改、分发本软件及其文档。
//任何使用此软件的地方都得出现以上版权通告所有副本。此软件由
//慧佳工作室维护，如果您有什么疑问请与我们联系。谢谢使用。
//
///////////////////////////////////////////////////////////////////////////////

/**
 * 在页面上以层的形式展开窗口
 * @param string title 窗口标题
 * @param string content 要显示的内容
 * @param boolean modal 是否以遮罩的方式展示 true为是false为平常方式
 * @param string width 遮罩层的宽度 默认值为100% (100% 400px)
 * @param boolean cBtn 是否在最上标题栏显示关闭 (close bottom)
 * @param boolean rMenu 是否设置弹出右键菜(right menu)不可用，默认为可以 true为不可用false为可用
 * @param integer sTop 遮罩层的top位置 (shield top) 默认值 0px
 * @param integer wLeft 窗口层的left位置 (message X) 默认值居中
 * @param integer wTop 窗口层的top位置 (message Y) 默认值居中
 */
function tipWindow(title, content, width, modal, cBtn, rMenu, sTop, wLeft, wTop)
{
	var elm = (document.body.clientHeight == document.body.offsetHeight) ? document.documentElement : document.body;
	if (modal) //是否以遮罩的方式展示 true为是false为平常方式
	{
		var shield = document.createElement("div");
		shield.id = "shield";
		shield.style.position = "absolute";
		shield.style.left = "0px";
		shield.style.top = sTop || "0px";
		shield.style.width = "100%";
		shield.style.height = ((elm.clientHeight > elm.scrollHeight) ? elm.clientHeight : elm.scrollHeight) + "px";
		shield.style.background = "#1A2A34";
		shield.style.textAlign = "center";
		shield.style.zIndex = "10000";
		shield.style.filter = "alpha(opacity=40)";
		shield.style.opacity = 0.4;
	}

	var winDiv = document.createElement("div");
	winDiv.id = "winDiv";
	winDiv.style.zIndex = "10001";
	winDiv.className = "tipWindow";
	winDiv.style.position = "absolute";
	winDiv.style.width = width || "100%";

	var strHtml = "<div class=\"title\" style=\"cursor: move;\"><h1>" + title + "</h1>";
	if (cBtn){strHtml += "<span><a href=\"javascript:closeWindow()\" title=\"关闭窗口\"><img src=\"/images/close.gif\" border=\"0\"/></a></span>";}
	winDiv.innerHTML = strHtml + "</div>" + content;

	document.body.appendChild(winDiv);
	winDiv.style.left = wLeft || Math.floor((elm.clientWidth  - winDiv.offsetWidth)  / 2) + 'px';
	winDiv.style.top  = wTop  || Math.floor((elm.clientHeight - winDiv.offsetHeight) / 2) + elm.scrollTop + 'px';
	if (modal){document.body.appendChild(shield);} //是否以遮罩的方式展示 true为是false为平常方式
	if (rMenu){document.body.oncontextmenu = function(){return false;}} //判断是否可以弹出右键菜单 right menu true为不可以false为可以

	this.closeWindow = function()
	{
		document.body.removeChild(winDiv);
		document.body.removeChild(shield);
		document.body.onselectstart = function(){return true;}
		document.body.oncontextmenu = function(){return true;}
	}

	function dragWin() //移动窗口
	{
		winDiv.style.left = Math.floor((elm.clientWidth	 - winDiv.offsetWidth)  / 2) + 'px';
		winDiv.style.top  = Math.floor((elm.clientHeight - winDiv.offsetHeight) / 2) + elm.scrollTop + 'px';
	}
	window.onresize = window.onscroll = dragWin;
}

/*随意移动层*/
if (document.getElementById)
{
(
	function()
	{
		var dragok = false; var y, x, d, dy, dx;
		var elm = (document.body.clientHeight == document.body.offsetHeight) ? document.documentElement : document.body;
		function setOpacity(obj, opacity)
		{
			if (opacity > 1){opacity = opacity / 100;}
			if(!!navigator.userAgent.match(/MSIE/ig))
			{
				obj.style.zoom = 1;
				obj.style.filter = 'alpha(opacity=' + opacity * 100 +');';
			}
			else
			{
				obj.style.opacity = opacity;
			}
		}

		function move(e)
		{
			if (!e){e = window.event;}
			if (dragok)
			{
				setOpacity(d, 0.5);
				var left = dx + e.clientX - x; if (left <= 0){left = 0;}
				var mLeft = elm.clientWidth - d.offsetWidth; if (left >= mLeft){left = mLeft;}

				var top = dy + e.clientY - y; if (top <= elm.scrollTop){top = elm.scrollTop;}
				var mTop = (elm.clientHeight + elm.scrollTop) - d.offsetHeight;
				if (top >= mTop){top = mTop;}

				d.style.left = left + "px";
				d.style.top  = top + "px";
				return false;
			}
		}

		function down(e)
		{
			if (!e){e = window.event;}
			var temp = (typeof e.target != "undefined") ? e.target : e.srcElement;
			if (temp.tagName != "HTML"|"BODY" && temp.className != "tipWindow")
			{
				temp = (typeof temp.parentNode != "undefined") ? temp.parentNode : temp.parentElement;
			}

			if (temp.className == "tipWindow")
			{
				dragok = true; d = temp;
				dx = parseInt(temp.style.left + 0);
				dy = parseInt(temp.style.top + 0);
				x = e.clientX; y = e.clientY;
				document.onmousemove = move;
				return false;
			}
		}

		function up(){dragok = false; document.onmousemove = null; if(d){setOpacity(d, 1);}}
		document.onmouseup = up; document.onmousedown = down;
	}
)();
}
//-->