///-------------------------------------------------------------------------
//jQuery弹出窗口 By Await [2010-08-12]
//--------------------------------------------------------------------------
/*参数：[可选参数在调用时可写可不写,其他为必写]
----------------------------------------------------------------------------
title:	窗口标题
content:  内容(可选内容为){ text | id | img | url | iframe }
width:	内容宽度
height:	内容高度
drag:  是否可以拖动(ture为是,false为否)
showbg:	[可选参数]设置是否显示遮罩层(false为不显示,true为显示)
------------------------------------------------------------------------*/
//示例:
//------------------------------------------------------------------------
//tipsWindown("例子","text:例子","500","400","true","3000","0","exa")
//------------------------------------------------------------------------
var showWindown = true;
function tipsWindown(title,content,drag,showbg) {
	$("#windown-box").remove(); //请除内容
	var width = 700;
	var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
	var height = clientHeight * 0.85;

	if(showWindown == true) {
		var simpleWindown_html = new String;
		simpleWindown_html = "<div id=\"windownbg\" style=\"height:"+$(document).height()+"px;;filter:alpha(opacity=0);opacity:0;z-index: 999901\"><iframe style=\"width:100%;height:100%;border:none;filter:alpha(opacity=0);opacity:0;\"></iframe></div>";
		simpleWindown_html += "<div id=\"windown-box\">";
		simpleWindown_html += "<div id=\"windown-title\"><h2></h2><span id=\"windown-close\">关闭</span></div>";
		simpleWindown_html += "<div id=\"windown-content-border\"><div id=\"windown-content\"></div></div>";
		simpleWindown_html += "</div>";
		$("body").append(simpleWindown_html);
		show = false;
	}
	$("#windown-content").html("<img src='/images/loading.gif' class='loading' />");
	$.ajax({
		error:function(){
			$("#windown-content").html("<p class='windown-error'>Loading Error...</p>");
		},
		success:function(html){
			$("#windown-content").html("<iframe src=\""+content+"\" width=\"100%\" height=\""+parseInt(height)+"px"+"\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"></iframe>");
		}
	});
	$("#windown-title h2").html(title);
	if(showbg == "true") {$("#windownbg").show();}else {$("#windownbg").remove();};
	$("#windownbg").animate({opacity:"0.5"},"normal");//设置透明度
	$("#windown-box").show();
	if( height >= 527 ) {
		$("#windown-title").css({width:(parseInt(width)+22)+"px"});
		$("#windown-content").css({width:(parseInt(width)+17)+"px",height:height+"px"});
	}else {
		$("#windown-title").css({width:(parseInt(width)+10)+"px"});
		$("#windown-content").css({width:width+"px",height:height+"px"});
	}
	var cw,ch,est = document.documentElement.scrollTop;//窗口的高和宽
	//取得窗口的高和宽
	if (self.innerHeight) {
		cw=self.innerWidth;
		ch=self.innerHeight;
	}else if (document.documentElement&&document.documentElement.clientHeight) {
		cw=document.documentElement.clientWidth;
		ch=document.documentElement.clientHeight;
	} else if (document.body) {
		cw=document.body.clientWidth;
		ch=document.body.clientHeight;
	}
	var isIE6=false;
	if (isIE6) {
		$("#windown-box").css({left:"50%",top:(parseInt((ch)/2)+est)+"px",marginTop: -((parseInt(height)+53)/2)+"px",marginLeft:-((parseInt(width)+32)/2)+"px",zIndex: "999999"});
	}else {
		$("#windown-box").css({left:"50%",top:"50%",marginTop:-((parseInt(height)+53)/2)+"px",marginLeft:-((parseInt(width)+32)/2)+"px",zIndex: "999999"});
	};
	var Drag_ID = document.getElementById("windown-box"),DragHead = document.getElementById("windown-title");
	var moveX = 0,moveY = 0,moveTop,moveLeft = 0,moveable = false;
	if (isIE6) {
		moveTop = est;
	}else {
		moveTop = 0;
	}
	var	sw = Drag_ID.scrollWidth,sh = Drag_ID.scrollHeight;
	DragHead.onmouseover = function(e) {
		if(drag == "true"){DragHead.style.cursor = "move";}else{DragHead.style.cursor = "default";}
	};
	DragHead.onmousedown = function(e) {
		$("#windown-box").css({opacity:"0.5"},"normal");
		if(drag == "true"){moveable = true;}else{moveable = false;}
		e = window.event?window.event:e;
		var ol = Drag_ID.offsetLeft, ot = Drag_ID.offsetTop-moveTop;
		moveX = e.clientX-ol;
		moveY = e.clientY-ot;
		document.onmousemove = function(e) {
			if (moveable) {
				e = window.event?window.event:e;
				var x = e.clientX - moveX;
				var y = e.clientY - moveY;
				if ( x > 0 &&( x + sw < cw) && y > 0 && (y + sh < ch) ) {
					Drag_ID.style.left = x + "px";
					Drag_ID.style.top = parseInt(y+moveTop) + "px";
					Drag_ID.style.margin = "auto";
				}
			}
		}
		document.onmouseup = function () {moveable = false;$("#windown-box").css({opacity:"1"},"normal");};
		Drag_ID.onselectstart = function(e){return false;}
	}
	var closeWindown = function() {
		$("#windown-box").fadeOut("slow",function(){$(this).remove();});
		$("#windownbg").remove();
	}
	$(function(){
		$("#windown-close").click(function(){
			closeWindown();
		});
	});
}
