﻿/*全局变量*/
var G_GlobalObjID="";
var G_IsCatchWindow = false;
var G_ForwardIndex = 10000;
var G_OffSetY = 0;
var G_OffSetX = 0;


/*设置焦点函数*/
function G_SetFocus(ObjID) {
	G_GlobalObjID=ObjID;
	$get_("GMainFrameWindow_"+ObjID).style.zIndex=++G_ForwardIndex;
};

/*锁定窗口函数*/
function G_CatchWindow(evt) {
	if (G_GlobalObjID=="") return;
	G_IsCatchWindow = true;

	G_OffSetX=parseInt($get_("GMainFrameWindow_"+G_GlobalObjID).style.left)-(G_Microsoft_IE ? event.clientX+document.documentElement.scrollLeft : evt.pageX);
	G_OffSetY=parseInt($get_("GMainFrameWindow_"+G_GlobalObjID).style.top)-(G_Microsoft_IE ? event.clientY+document.documentElement.scrollTop : evt.pageY);
};

/*释放窗口函数*/
function G_ReleaseWindow() {
	G_GlobalObjID="";
	G_IsCatchWindow = false;
};

/*移动窗口函数*/
function G_MoveWindow(evt) {
	if (G_GlobalObjID=="") return;

	if (G_IsCatchWindow) {
		/*得到鼠标坐标*/
		var x = G_Microsoft_IE ? event.clientX+document.documentElement.scrollLeft:evt.pageX;
		var y = G_Microsoft_IE ? event.clientY+document.documentElement.scrollTop:evt.pageY;

		/*计算窗口坐标*/
		$get_("GMainFrameWindow_"+G_GlobalObjID).style.left=x+G_OffSetX+'px';
		$get_("GMainFrameWindow_"+G_GlobalObjID).style.top=y+G_OffSetY+'px';
	}
};

/*显示窗口函数*/
function G_ShowWindow(ObjID) {
	/*如果不存在这个窗口则返回*/
	if (!G_CheckWindowExists(ObjID)) return;

	$get_("GMainFrameWindow_"+ObjID).style.display="";
	$get_("GWindowsTitle_"+ObjID).style.display="";

	/*设置焦点*/
	setTimeout("G_SetFocus('"+ObjID+"');",50);
};

/*关闭窗口函数*/
function G_CloseWindow(ObjID) {
	$get_("GMainFrameWindow_"+ObjID).style.display="none";
	$get_("GWindowsTitle_"+ObjID).style.display="none";
};

/* 检测窗口是否存在 */
function G_CheckWindowExists(ObjID) {
	if ($get_("GMainFrameWindow_"+ObjID)) {
		return true;
	}
	else {
		return false;
	}
};

/*
创建窗口函数
////////////////////////////////////////////////////////
//ObjID			ID(字符串)
//Left			X坐标
//Top			Y坐标
//Width			宽
//Height		高
//Ico			图标(16*16)
//Title			标题
//WinType		窗口创建方式(0首次创建,1后来创建)
//WinHtml		内容(html)
////////////////////////////////////////////////////////
*/
function G_CreateWindows(ObjID,Left,Top,Width,Height,Ico,Title,WinType,WinHtml) {
	/*如果存在这个窗口则返回*/
	if (G_CheckWindowExists(ObjID)) return;
	var BICQWindowsHtml=""
		+"<div id=\"GMainFrameWindow_"+ObjID+"\" style=\"position:absolute;display:none;left:"+Left+"px;top:"+Top+"px;width:"+Width+"px;height:"+(Height-1)+"px;z-index:"+G_ForwardIndex+";cursor:default;\" onClick=\"G_SetFocus('"+ObjID+"');\">"

			/*标题拖动层*/
			+"<div id=\"GWindowsTitle_"+ObjID+"\" style=\"position:absolute;display:none;left:0px;top:0px;width:"+Width+"px;height:23px;font-size:12px;\" onMouseDown=\"G_SetFocus('"+ObjID+"');G_CatchWindow(event);\" onMouseUp=\"G_ReleaseWindow();\">"
				/*窗口上部左中右图像*/
				+"<div style=\"position:absolute;left:0px;top:0px;width:4px;height:23px;background-image: url("+SETTINGS['home_url']+"/images/skins/bicq/bar_left_u.gif);\"></div>"
				+"<div style=\"position:absolute;left:4px;top:0px;width:"+(Width-8)+"px;height:23px;background-image: url("+SETTINGS['home_url']+"/images/skins/bicq/bar_top.gif);\">&nbsp;</div>"
				+"<div style=\"position:absolute;left:"+(Width-4)+"px;top:0px;width:4px;height:23px;background-image: url("+SETTINGS['home_url']+"/images/skins/bicq/bar_right_u.gif);\"></div>"

				/*标题栏小图标和标题名*/
				+"<div style=\"position:absolute;left:5px;top:1px;width:20px;height:20px;background-image: url("+Ico+");\" onDBlclick=\"G_CloseWindow('"+ObjID+"');\"></div>"
				+"<font color=\"#2E2B2B\"><b><span id=\"GWindowTitleName_"+ObjID+"\" style=\"position:absolute;left:28px;top:6px;\">"+Title+"</span></b></font>"

				/*关闭按钮*/
				+"<span style=\"position:absolute;left:"+(Width-30)+"px;top:0px;width:25px;height:15px;cursor: pointer;background-image: url("+SETTINGS['home_url']+"/images/skins/bicq/close_button.gif);\" onClick=\"G_CloseWindow('"+ObjID+"');\"></span>"
			+"</div>"

			/*窗口界线*/
			+"<span style=\"position:absolute;left:0px;top:22px;width:"+(Width-2)+"px;height:"+(Height-25)+"px;border:1px solid #0066AA;\"></span>"

			/*窗口内容*/
			+"<span style=\"position:absolute;left:1px;top:23px;width:"+(Width-2)+"px;height:"+(Height-25)+"px;\">"+WinHtml+"</span>"

			/*窗口下部左右图像*/
			//+"<span style=\"position:absolute;left:0px;top:"+(Height)+"px;\" style=\"background-color: #07528B;\"><img src=\""+SETTINGS['home_url']+"/images/skins/bicq/bar_left_d.gif\" width=\"4\" height=\"4\" border=\"0\"></span>"
			//+"<span style=\"position:absolute;left:"+(Width-4)+"px;top:"+(Height)+"px;\" style=\"background-color: #07528B;\"><img src=\""+SETTINGS['home_url']+"/images/skins/bicq/bar_right_d.gif\" width=\"4\" height=\"4\" border=\"0\"></span>"

			/*窗口阻挡*/
			+(G_Microsoft_IE ? "<iframe src=\"about:blank\" style=\"position:absolute; visibility:inherit; top:0px; left:0px; width:"+Width+"px; height:"+Height+"px; z-index:-1; filter:alpha(opacity=0,style=0);\"></iframe>" : "")
		+"</div>";

	if (WinType==1) {
		var sObj=document.createElement("span");
		sObj.innerHTML=BICQWindowsHtml;
		$get_("WindowsGlobalBodyIDS").appendChild(sObj);
	}
	else {
		document.write(BICQWindowsHtml);
	}
};
document.onmouseup=G_ReleaseWindow;
document.onmousemove=G_MoveWindow;

