﻿var WinTaskLastTopIndex=0;
var WinTaskExistNum=0;	/* 存在的任务栏数量 */
var WinTaskCounter=0;	/* 任务栏数量 */
var WinTaskOffset=0;	/* 任务栏X坐标值 */
var WinTaskStep=82;	/* 任务栏宽度 */

var Cls=0;
var Nor=1;
var Min=2;
var Max=3;

var OffSetY = 0;
var OffSetX = 0;
var GlobalObjID = "";
var IsCatchWindow = false;
var IsReSizeCatch = false;

var zIndex = 1000000;
var sWindowMain = new Array();
var WindowsType = new Array();
var WindowsStatus = new Array();
var WinTaskStatus = new Array();
var WinTaskBarList = new Array();


/* 交换任务栏对象内容 */
function SwapTaskBar(TaskID1,TaskID2) {
	//alert("TaskID1="+TaskID1+"\r\nTaskID2="+TaskID2);
	if (TaskID1==TaskID2) return;

	/* 获取内容 */
	var TBody1=$("WinTaskNum_"+TaskID1).innerHTML;
	var TBody2=$("WinTaskNum_"+TaskID2).innerHTML;

	/* 获取位置 */
	var TOffset1=$("Task_"+WinTaskBarList['ID2Name'+TaskID1]).style.left;
	var TOffset2=$("Task_"+WinTaskBarList['ID2Name'+TaskID2]).style.left;

	/* 获取参数 */
	var TID2Name1=WinTaskBarList['ID2Name'+TaskID1];//返回Name
	var TID2Name2=WinTaskBarList['ID2Name'+TaskID2];
	var TName2ID1=WinTaskBarList['Name2ID'+TID2Name1];//返回ID
	var TName2ID2=WinTaskBarList['Name2ID'+TID2Name2];

	/* ////////////////////////////////////////交换对象//////////////////////////////////////// */

	/* 交换内容 */
	$("WinTaskNum_"+TaskID1).innerHTML=TBody2;
	$("WinTaskNum_"+TaskID2).innerHTML=TBody1;

	/* 交换位置 */
	$("Task_"+WinTaskBarList['ID2Name'+TaskID1]).style.left=TOffset2;
	$("Task_"+WinTaskBarList['ID2Name'+TaskID2]).style.left=TOffset1;

	/* 交换参数 */
	WinTaskBarList['ID2Name'+TaskID1]=TID2Name2;
	WinTaskBarList['ID2Name'+TaskID2]=TID2Name1;
	WinTaskBarList['Name2ID'+TID2Name1]=TName2ID2;
	WinTaskBarList['Name2ID'+TID2Name2]=TName2ID1;
};

/* 显示任务栏对象 */
function ShowTaskBar(ObjID) {
	if ($("Task_"+ObjID)!=null) {
		/* 显示 */
		$("Task_"+ObjID).style.visibility="visible";
		WinTaskStatus[ObjID]=Nor;

		/* 交换 */
		SwapTaskBar(WinTaskBarList['Name2ID'+ObjID],WinTaskExistNum);
		WinTaskExistNum++;
	}
};

/* 隐藏任务栏对象 */
function HideTaskBar(ObjID) {
	if ($("Task_"+ObjID)!=null) {
		/* 交换 */
		SwapTaskBar(WinTaskBarList['Name2ID'+ObjID],WinTaskExistNum-1);
		WinTaskExistNum--;

		/* 隐藏 */
		$("Task_"+ObjID).style.visibility="hidden";
		WinTaskStatus[ObjID]=Cls;
	}
};

/* 更改任务栏对象状态 */
function ChangeTaskBar(ObjID) {
	if (WinTaskStatus[ObjID]!=Nor) {
		$("Task_"+ObjID).style.background="url(images/skins/bicq/task_obj_1.gif)";
		ShowWindow(ObjID);
		WinTaskStatus[ObjID]=Nor;

		/* 将窗口位置调整到正确 */
		if ($("MainFrameWindow_"+ObjID).offsetTop<=0) {
			$("MainFrameWindow_"+ObjID).style.top = "0px";
		}
	}
	else {
		if (GetWindowFocusIndex(ObjID)<(zIndex+IconzIndex)) {
			if (WinTaskLastTopIndex!=(zIndex+IconzIndex)) {
				WinTaskStatus[ObjID]=Min;
				ChangeTaskBar(ObjID);
				return;
			}
		}

		$("Task_"+ObjID).style.background="url(images/skins/bicq/task_obj_2.gif)";
		SetMinWindow(ObjID);
		WinTaskStatus[ObjID]=Min;

		/* 记录最高索引 */
		WinTaskLastTopIndex=zIndex+IconzIndex;
	}
};

/* 在任务栏添加一个对象 */
function AddTaskObj(ObjID) {
	if (WinTaskBarList[ObjID]==1) return;

	var TaskIcon=($("BICQWindowIcon_"+ObjID).style.backgroundImage).replace(/url\((.*)\)/gi,"$1");
	var TitleName=$("BICQWindowTitleName_"+ObjID).innerHTML;
	var TaskName=(TitleName.replace(/[^\x00-\xff]/gi,"  ").length<=8 ? TitleName : TitleName.substr(0,3)+"..");
	var iShtml="<span id=\"WinTaskNum_"+WinTaskCounter+"\"><span id=\"Task_"+ObjID+"\" style=\"position:absolute;top:2px;left:"+WinTaskOffset+"px;width:"+WinTaskStep+"px;height:27px;background-image: url(images/skins/bicq/task_obj_1.gif);visibility:hidden;\" onClick=\"ChangeTaskBar('"+ObjID+"');\" title=\""+TitleName+"\"><span style=\"position:absolute;left:3px;top:4px;width:20px;height:20px;background-image: url("+TaskIcon+");\"></span><span style=\"position:absolute;left:25px;top:10px;width:100%;\" class=\"TaskTitle\">"+TaskName+"</span></span></span>";
	if (Microsoft_IE) {
		$("TaskBar").insertAdjacentHTML("beforeEnd",iShtml);
	}
	else {
		$("TaskBar").innerHTML+=iShtml;
	}

	WinTaskOffset+=(WinTaskStep+1);
	WinTaskBarList[ObjID]=1;
	WinTaskStatus[ObjID]=Cls;

	WinTaskBarList['ID2Name'+WinTaskCounter]=ObjID;
	WinTaskBarList['Name2ID'+ObjID]=WinTaskCounter;
	WinTaskCounter++;
};

/* 设置任务栏闪烁 */
function SetTaskObjFlash(ObjID) {
	if (GetWindowFocusIndex(ObjID)==(zIndex+IconzIndex) && (WindowsStatus[ObjID]==Nor || WindowsStatus[ObjID]==Max)) return;// 如果已经获得焦点就返回
	if ($("Task_"+ObjID).style.visibility!="hidden") {// 任务栏存在的情况下
		var task_obj_status=1;
		if (WindowsStatus[ObjID]==Min) {
			task_obj_status=2;
		}
		else {
			task_obj_status=1;
		}
		if ($("Task_"+ObjID)) $("Task_"+ObjID).style.backgroundImage="url(images/skins/bicq/task_obj_"+task_obj_status+"_flash.gif)";
	}
};

/* 获取当前窗口宽高 */
function GetCurrentWH() {
	if (Microsoft_IE) {
		CurrentBodyWidth=parent.document.documentElement.clientWidth;
		CurrentBodyHeight=parent.document.documentElement.clientHeight;
	}
	else {
		CurrentBodyWidth=parent.innerWidth;
		CurrentBodyHeight=parent.innerHeight;
	}
};

/* 获得当前窗口的z-index值 */
function GetWindowFocusIndex(ObjID) {
	return $("MainFrameWindow_"+ObjID).style.zIndex;
};

/* 设置焦点函数 */
function SetFocus(ObjID) {
	GlobalObjID=ObjID;
	$("MainFrameWindow_"+ObjID).style.zIndex=(++zIndex+IconzIndex);

	/* 恢复闪烁的任务栏 */
	if ($("Task_"+ObjID)) $("Task_"+ObjID).style.background="url(images/skins/bicq/task_obj_1.gif)";
};

/* 判断窗口是否超出边界 */
function CheckWindowIsOut(ObjID) {
	var Obj_Blank_Left=CurrentBodyWidth-sWindowMain[ObjID+"_width"];
	var Obj_Blank_Top=CurrentBodyHeight-25-29;

	if ($("MainFrameWindow_"+ObjID).offsetTop<=0) {
		$("MainFrameWindow_"+ObjID).style.top = "0px";
	}
	if ($("MainFrameWindow_"+ObjID).offsetTop>=Obj_Blank_Top) {
		$("MainFrameWindow_"+ObjID).style.top = Obj_Blank_Top+"px";
	}

	//if ($("MainFrameWindow_"+ObjID).offsetLeft<=0) {
	//	$("MainFrameWindow_"+ObjID).style.left = "0px";
	//}
	//if ($("MainFrameWindow_"+ObjID).offsetLeft>=Obj_Blank_Left) {
	//	$("MainFrameWindow_"+ObjID).style.left = Obj_Blank_Left+"px";
	//}
};

/* 设置最小化窗口函数 */
function SetMinWindow(ObjID) {
	if (WindowsType[ObjID+"_min"]!=1) return;

	/* 关闭窗口 */
	$("MainFrameWindow_"+ObjID).style.visibility="hidden";
	WindowsStatus[ObjID]=Min;
};

/* 最小化窗口函数 */
function MinWindow(ObjID) {
	/* 如果窗口处于关闭状态则返回 */
	if (WindowsStatus[ObjID]==Cls) return;

	SetMinWindow(ObjID);
	ChangeTaskBar(ObjID);
};

/* 最大化窗口函数 */
function MaxWindow(ObjID) {
	if (WindowsType[ObjID+"_max"]!=1) return;

	if (WindowsStatus[ObjID] != Max && WindowsStatus['MAX_'+ObjID]!=Max) {
		var sWidth=CurrentBodyWidth;
		var sHeight=CurrentBodyHeight-25-29+14;

		/* 主窗口 */
		$("MainFrameWindow_"+ObjID).style.left="0px";
		$("MainFrameWindow_"+ObjID).style.top="0px";
		$("MainFrameWindow_"+ObjID).style.width=sWidth+"px";
		$("MainFrameWindow_"+ObjID).style.height=sHeight+"px";

		/* 窗口标题栏 */
		$("BICQWindowTitleC_"+ObjID).style.width=(sWidth-8)+"px";
		$("BICQWindowTitleR_"+ObjID).style.left=(sWidth-4)+"px";

		/* 窗口按钮 */
		if (WindowsType[ObjID+"_min"]==1) $("BICQWindowMin_"+ObjID).style.left=(sWidth-81)+"px";
		$("BICQWindowMax_"+ObjID).style.left=(sWidth-56)+"px";
		$("BICQWindowCls_"+ObjID).style.left=(sWidth-30)+"px";

		/* 窗口状态栏 */
		$("BICQWindowStatus_"+ObjID).style.top=(sHeight+4)+"px";
		$("BICQWindowStatus_"+ObjID).style.width=(sWidth-2)+"px";
		$("BICQWindowStatusi_"+ObjID).style.left=(sWidth-11)+"px";
		$("BICQWindowStatusBar_"+ObjID).width=(sWidth-8);
		$("BICQWindowStatusRight_"+ObjID).style.left=(sWidth-4)+"px";

		/* 窗口边框 */
		$("BICQWindowBoxLine_"+ObjID).style.width=(sWidth-2)+"px";
		$("BICQWindowBoxLine_"+ObjID).style.height=(sHeight-2-17)+"px";

		/* 窗口内容 */
		$("BICQWindowContent_"+ObjID).style.width=(sWidth-2)+"px";
		$("BICQWindowContent_"+ObjID).style.height=(sHeight-2-15)+"px";

		/* 窗口阻挡 */
		if ($("BICQWindowBoxFrame_"+ObjID)) {
			$("BICQWindowBoxFrame_"+ObjID).style.width=sWidth+"px";
			$("BICQWindowBoxFrame_"+ObjID).style.height=sHeight+"px";
		}

		/* 更换按钮图标 */
		$("BICQWindowMax_"+ObjID).style.background="url(images/skins/bicq/max_button_r.gif)";
		WindowsStatus[ObjID]=Max;
		WindowsStatus['MAX_'+ObjID]=Max;

		/* 重新设置子窗口位置 */
		$("SubWindow_"+ObjID).style.top=(sHeight+7)+"px";
		$("SubWindow_"+ObjID).style.width=(sWidth)+"px";
		$("SubWindowTC_"+ObjID).width=sWidth-10;
		$("SubWindowBC_"+ObjID).width=sWidth-10;
		$("SubWindowTR_"+ObjID).style.left=(sWidth-5)+"px";
		$("SubWindowTT1_"+ObjID).style.width=(sWidth-2)+"px";
		$("SubWindowTT2_"+ObjID).style.width=(sWidth-4)+"px";
		$("SubWindowTT3_"+ObjID).style.width=(sWidth-10)+"px";
		$("SubWindowTT4_"+ObjID).style.left=(sWidth-5)+"px";
		if ($("SubWindowFrame_"+ObjID)) {
			$("SubWindowFrame_"+ObjID).style.width=sWidth+"px";
			$("SubWindowFrame_"+ObjID).style.height=sHeight+"px";
		}
	}
	else {
		/* 主窗口 */
		$("MainFrameWindow_"+ObjID).style.left=sWindowMain[ObjID+"_left"]+"px";
		$("MainFrameWindow_"+ObjID).style.top=sWindowMain[ObjID+"_top"]+8+"px";
		$("MainFrameWindow_"+ObjID).style.width=sWindowMain[ObjID+"_width"]+"px";
		$("MainFrameWindow_"+ObjID).style.height=sWindowMain[ObjID+"_height"]+"px";

		/* 窗口标题栏 */
		$("BICQWindowTitleC_"+ObjID).style.width=(sWindowMain[ObjID+"_width"]-8)+"px";
		$("BICQWindowTitleR_"+ObjID).style.left=(sWindowMain[ObjID+"_width"]-4)+"px";

		/* 窗口按钮 */
		if (WindowsType[ObjID+"_min"]==1) $("BICQWindowMin_"+ObjID).style.left=(sWindowMain[ObjID+"_width"]-81)+"px";
		$("BICQWindowMax_"+ObjID).style.left=(sWindowMain[ObjID+"_width"]-56)+"px";
		$("BICQWindowCls_"+ObjID).style.left=(sWindowMain[ObjID+"_width"]-30)+"px";

		/* 窗口状态栏 */
		$("BICQWindowStatus_"+ObjID).style.top=(sWindowMain[ObjID+"_height"]-2-17)+"px";
		$("BICQWindowStatus_"+ObjID).style.width=(sWindowMain[ObjID+"_width"]-2)+"px";
		$("BICQWindowStatusi_"+ObjID).style.left=(sWindowMain[ObjID+"_width"]-11)+"px";
		$("BICQWindowStatusBar_"+ObjID).width=(sWindowMain[ObjID+"_width"]-8);
		$("BICQWindowStatusRight_"+ObjID).style.left=(sWindowMain[ObjID+"_width"]-4)+"px";

		/* 窗口边框 */
		$("BICQWindowBoxLine_"+ObjID).style.width=(sWindowMain[ObjID+"_width"]-2)+"px";
		$("BICQWindowBoxLine_"+ObjID).style.height=(sWindowMain[ObjID+"_height"]-25-17)+"px";

		/* 窗口内容 */
		$("BICQWindowContent_"+ObjID).style.width=(sWindowMain[ObjID+"_width"]-2)+"px";
		$("BICQWindowContent_"+ObjID).style.height=(sWindowMain[ObjID+"_height"]-23-17)+"px";

		/* 窗口阻挡 */
		if ($("BICQWindowBoxFrame_"+ObjID)) {
			$("BICQWindowBoxFrame_"+ObjID).style.width=sWindowMain[ObjID+"_width"]+"px";
			$("BICQWindowBoxFrame_"+ObjID).style.height=sWindowMain[ObjID+"_height"]+"px";
		}

		/* 更换按钮图标 */
		$("BICQWindowMax_"+ObjID).style.background="url(images/skins/bicq/max_button.gif)";
		WindowsStatus[ObjID]=Nor;
		WindowsStatus['MAX_'+ObjID]=Nor;

		/* 重新设置子窗口位置 */
		$("SubWindow_"+ObjID).style.top=(sWindowMain[ObjID+"_height"]+7-23)+"px";
		$("SubWindow_"+ObjID).style.width=(sWindowMain[ObjID+"_width"])+"px";
		$("SubWindowTC_"+ObjID).width=sWindowMain[ObjID+"_width"]-10;
		$("SubWindowBC_"+ObjID).width=sWindowMain[ObjID+"_width"]-10;
		$("SubWindowTR_"+ObjID).style.left=(sWindowMain[ObjID+"_width"]-5)+"px";
		$("SubWindowTT1_"+ObjID).style.width=(sWindowMain[ObjID+"_width"]-2)+"px";
		$("SubWindowTT2_"+ObjID).style.width=(sWindowMain[ObjID+"_width"]-4)+"px";
		$("SubWindowTT3_"+ObjID).style.width=(sWindowMain[ObjID+"_width"]-10)+"px";
		$("SubWindowTT4_"+ObjID).style.left=(sWindowMain[ObjID+"_width"]-5)+"px";
		if ($("SubWindowFrame_"+ObjID)) {
			$("SubWindowFrame_"+ObjID).style.width=sWindowMain[ObjID+"_width"]+"px";
			$("SubWindowFrame_"+ObjID).style.height=sWindowMain[ObjID+"_height"]+"px";
		}
	}
};

/* 禁止窗口操作 */
function DisableWindowAction() {
	$("MainTaskBar").style.zIndex=zIndex+IconzIndex;
	$("GlobalContrl").style.zIndex=zIndex+IconzIndex;
	$("GlobalContrl").style.visibility="visible";

	/* 禁止热键 */
	HotKeyDisabled=0;
};

/* 允许窗口操作 */
function EnableWindowAction() {
	$("MainTaskBar").style.zIndex=100000000000000;
	$("GlobalContrl").style.visibility="hidden";
	if ($("TheMainTitle")) $("TheMainTitle").style.display="none";

	/* 允许热键 */
	HotKeyDisabled=0;
};

/* 显示窗口函数 */
function ShowWindow(ObjID) {
	/* 如果不存在这个窗口则返回 */
	if (!WindowExists(ObjID)) return;

	if (WindowsType[ObjID+"_min"]==1 && WindowsStatus[ObjID]==Cls) {
		/* 添加到任务栏 */
		AddTaskObj(ObjID);

		/* 显示任务栏对象 */
		ShowTaskBar(ObjID);
	}

	/* 显示窗口 */
	$("MainFrameWindow_"+ObjID).style.visibility="visible";
	WindowsStatus[ObjID]=Nor;

	/* 设置焦点 */
	setTimeout("SetFocus('"+ObjID+"');",50);

	/* 禁止窗口操作 */
	if (WindowsType[ObjID+"_min"]==0 && ObjID!="Install") {
		setTimeout("DisableWindowAction();",100);
	}
};

/* 关闭窗口函数 */
function CloseWindows(ObjID) {
	/* 检查是否视频窗口 */
	sObjID=ObjID.split("_");
	if (sObjID[0]=="Video") {
		CloseVideo(sObjID[1]);
		return;
	}
	CloseWindow(ObjID);
}
function CloseWindow(ObjID) {
	/* 关闭窗口 */
	$("MainFrameWindow_"+ObjID).style.visibility="hidden";
	WindowsStatus[ObjID]=Cls;

	if (WindowsType[ObjID+"_min"]==1) {
		/* 隐藏任务栏对象 */
		HideTaskBar(ObjID);
	}
	else {
		/* 允许窗口操作 */
		EnableWindowAction();
	}
};

/* 改变鼠标指针样式 */
function ChangeMouseStatus(sT,ObjID) {
	if (WindowsType[ObjID+"_max"]!=1 || WindowsStatus[ObjID]==Max) return;

	if (sT==1) {
		$("BICQWindowStatusi_"+ObjID).style.cursor="nw-resize";
	}
	else if (sT==2) {
		$("BICQWindowStatusi_"+ObjID).style.cursor="default";
	}
};

/* 重新设置窗口-锁定 */
function ReSizeCatch(ObjID) {
	GlobalObjID=ObjID;
	IsReSizeCatch=true;
};

/* 重新设置窗口-释放 */
function ReSizeRelease() {
	GlobalObjID="";
	IsReSizeCatch=false;
};

/* 移动窗口函数 */
function MoveWindow(evt) {
	if (GlobalObjID=="") return;

	if (IsCatchWindow) {
		if (WindowsStatus[GlobalObjID]!=Nor || WindowsStatus['MAX_'+GlobalObjID]==Max) return;

		/* 得到鼠标坐标 */
		var x = Microsoft_IE ? event.clientX+document.documentElement.scrollLeft:evt.pageX;
		var y = Microsoft_IE ? event.clientY+document.documentElement.scrollTop:evt.pageY;

		/* 计算窗口坐标 */
		$("MainFrameWindow_"+GlobalObjID).style.left=x+OffSetX+'px';
		$("MainFrameWindow_"+GlobalObjID).style.top=y+OffSetY+'px';

		/* 记录窗口的坐标 */
		sWindowMain[GlobalObjID+"_left"]=x+OffSetX;
		sWindowMain[GlobalObjID+"_top"]=y+OffSetY;

		/* 检查窗口是否超出了范围 */
		CheckWindowIsOut(GlobalObjID);
	}

	/* 调整窗口大小 */

	if (IsReSizeCatch) {
		if (WindowsType[GlobalObjID+"_max"]!=1 || WindowsStatus[GlobalObjID]==Max) return;

		/* 得到鼠标坐标 */
		var x= Microsoft_IE ? event.clientX+document.documentElement.scrollLeft:evt.pageX;
		var y= Microsoft_IE ? event.clientY+document.documentElement.scrollTop:evt.pageY;

		/* 计算当前窗口大小 */
		var sWidth=x-sWindowMain[GlobalObjID+"_left"]+5;
		var sHeight=y-sWindowMain[GlobalObjID+"_top"]+5;

		/* 判断窗口是否超过了正常范围 */
		if (sWidth<=110) sWidth=110;
		if (sHeight<=110) sHeight=110;
		if (sWidth>=CurrentBodyWidth) sWidth=CurrentBodyWidth;
		if (sHeight>=(CurrentBodyHeight-32)) sHeight=CurrentBodyHeight-32;

		/* 记录窗口大小 */
		sWindowMain[GlobalObjID+"_width"]=sWidth;
		sWindowMain[GlobalObjID+"_height"]=sHeight+17;

		/* 主窗口 */
		$("MainFrameWindow_"+GlobalObjID).style.width=sWidth+"px";
		$("MainFrameWindow_"+GlobalObjID).style.height=sHeight+"px";

		/* 窗口标题栏 */
		$("BICQWindowTitleC_"+GlobalObjID).style.width=(sWidth-8)+"px";
		$("BICQWindowTitleR_"+GlobalObjID).style.left=(sWidth-4)+"px";

		/* 窗口按钮 */
		if (WindowsType[GlobalObjID+"_min"]==1) $("BICQWindowMin_"+GlobalObjID).style.left=(sWidth-(WindowsType[GlobalObjID+"_max"]==1 ? 81 : 56))+"px";
		if (WindowsType[GlobalObjID+"_max"]==1) $("BICQWindowMax_"+GlobalObjID).style.left=(sWidth-56)+"px";
		$("BICQWindowCls_"+GlobalObjID).style.left=(sWidth-30)+"px";

		/* 窗口状态栏 */
		$("BICQWindowStatus_"+GlobalObjID).style.top=(sHeight-2)+"px";
		$("BICQWindowStatus_"+GlobalObjID).style.width=(sWidth-2)+"px";
		$("BICQWindowStatusi_"+GlobalObjID).style.left=(sWidth-11)+"px";
		$("BICQWindowStatusBar_"+GlobalObjID).width=(sWidth-8);
		$("BICQWindowStatusRight_"+GlobalObjID).style.left=(sWidth-4)+"px";

		/* 窗口边框 */
		$("BICQWindowBoxLine_"+GlobalObjID).style.width=(sWidth-2)+"px";
		$("BICQWindowBoxLine_"+GlobalObjID).style.height=(sHeight-25)+"px";

		/* 窗口内容 */
		$("BICQWindowContent_"+GlobalObjID).style.width=(sWidth-2)+"px";
		$("BICQWindowContent_"+GlobalObjID).style.height=(sHeight-23)+"px";

		/* 窗口阻挡 */
		if ($("BICQWindowBoxFrame_"+GlobalObjID)) {
			$("BICQWindowBoxFrame_"+GlobalObjID).style.width=sWidth+"px";
			$("BICQWindowBoxFrame_"+GlobalObjID).style.height=sHeight+"px";
		}

		/* 重新设置子窗口位置 */
		$("SubWindow_"+GlobalObjID).style.top=(sHeight+1)+"px";
		$("SubWindow_"+GlobalObjID).style.width=(sWidth)+"px";
		$("SubWindowTC_"+GlobalObjID).width=sWidth-10;
		$("SubWindowBC_"+GlobalObjID).width=sWidth-10;
		$("SubWindowTR_"+GlobalObjID).style.left=(sWidth-5)+"px";
		$("SubWindowTT1_"+GlobalObjID).style.width=(sWidth-2)+"px";
		$("SubWindowTT2_"+GlobalObjID).style.width=(sWidth-4)+"px";
		$("SubWindowTT3_"+GlobalObjID).style.width=(sWidth-10)+"px";
		$("SubWindowTT4_"+GlobalObjID).style.left=(sWidth-5)+"px";
		if ($("SubWindowFrame_"+GlobalObjID)) {
			$("SubWindowFrame_"+GlobalObjID).style.width=sWidth+"px";
			$("SubWindowFrame_"+GlobalObjID).style.height=sHeight+"px";
		}
	}
};

/* 锁定窗口函数 */
function CatchWindow(evt) {
	if (GlobalObjID=="" || WindowsStatus[GlobalObjID]!=Nor || WindowsStatus['MAX_'+GlobalObjID]==Max) return;

	IsCatchWindow=true;
	OffSetX=parseInt($("MainFrameWindow_"+GlobalObjID).style.left)-(Microsoft_IE ? event.clientX+document.documentElement.scrollLeft : evt.pageX);
	OffSetY=parseInt($("MainFrameWindow_"+GlobalObjID).style.top)-(Microsoft_IE ? event.clientY+document.documentElement.scrollTop : evt.pageY);
};

/* 释放窗口函数 */
function ReleaseWindow() {
	GlobalObjID="";
	IsCatchWindow=false;
	ReSizeRelease();
};

/* 窗口是否存在 */
function WindowExists(ObjID) {
	if (WindowsStatus[ObjID]=="undefined" || WindowsStatus[ObjID]==null) return 0;
	return 1;
};

/* 处理热键 */
function doHotKeyMoveWindow(evt) {
	var sOffset=0;
	var ObjID=GlobalObjID;
	if (GlobalObjID=="") return;

	evt=evt ? evt : (window.event ? window.event : null);
	if (evt.ctrlKey && evt.altKey) {
		/* 处理Ctrl+左键 */
		if (evt.keyCode==37) {
			evt.cancelBubble = true;
			sOffset=$("MainFrameWindow_"+GlobalObjID).offsetLeft;
			$("MainFrameWindow_"+GlobalObjID).style.left=(sOffset-5)+"px";
			CheckWindowIsOut(GlobalObjID);
		}
		/* 处理Ctrl+上键 */
		else if (evt.keyCode==38) {
			evt.cancelBubble = true;
			sOffset=$("MainFrameWindow_"+GlobalObjID).offsetTop;
			$("MainFrameWindow_"+GlobalObjID).style.top=(sOffset-5)+"px";
			CheckWindowIsOut(GlobalObjID);
		}
		/* 处理Ctrl+右键 */
		else if (evt.keyCode==39) {
			evt.cancelBubble = true;
			sOffset=$("MainFrameWindow_"+GlobalObjID).offsetLeft;
			$("MainFrameWindow_"+GlobalObjID).style.left=(sOffset+5)+"px";
			CheckWindowIsOut(GlobalObjID);
		}
		/* 处理Ctrl+下键 */
		else if (evt.keyCode==40) {
			evt.cancelBubble = true;
			sOffset=$("MainFrameWindow_"+GlobalObjID).offsetTop;
			$("MainFrameWindow_"+GlobalObjID).style.top=(sOffset+5)+"px";
			CheckWindowIsOut(GlobalObjID);
		}
	}
	/* 处理ESC键 */
	if (evt.keyCode==27) {
		ReleaseWindow();
		DesktopReleaseIcon();
	}
};

/*
创建窗口函数
////////////////////////////////////////////////////////
// ObjID		ID(字符串)
// Left			X坐标
// Top			Y坐标
// Width		宽
// Height		高
// Ico			图标(16*16)
// Title		标题
// WinType		窗口创建方式(0首次创建,1后来创建)
// zCenter		是否居中(1居中)
// zMin			最小化按钮(0无,1有)
// zMax			最大化按钮(0无,1有)
// WinHtml		内容(html)
// WinSubContent	子窗口内容(html)
// sHeight		子窗口高度
////////////////////////////////////////////////////////
*/
function CreateWindows(ObjID,Left,Top,Width,Height,Ico,Title,WinType,zCenter,zMin,zMax,WinContent,WinSubContent,sHeight) {
	/* 如果存在这个窗口则返回 */
	if (WindowExists(ObjID)) return;

	/* 居中 */
	if (zCenter==1) {
		if (Left==0) Left=(CurrentBodyWidth-Width)/2;
		if (Top==0) Top=(CurrentBodyHeight-Height-32)/2;
	}

	var WinHTML=""
		+"<div id=\"MainFrameWindow_"+ObjID+"\" style=\"position:absolute;left:"+Left+"px;top:"+Top+"px;width:"+Width+"px;height:"+Height+"px;z-index:"+(zIndex+IconzIndex)+";visibility:hidden;\" onClick=\"SetFocus('"+ObjID+"');\">"
			/* 标题拖动层 */
			+"<div id=\"BICQWindow_"+ObjID+"\" style=\"position:absolute;left:0px;top:0px;width:"+Width+"px;\" onMouseDown=\"SetFocus('"+ObjID+"');CatchWindow(event);\" onMouseUp=\"ReleaseWindow();\">"

				/* 窗口上部左中右图像 */
				+"<div style=\"position:absolute;left:0px;top:0px;width:4px;height:23px;background-image: url(images/skins/bicq/bar_left_u.gif);\"></div>"
				+"<div id=\"BICQWindowTitleC_"+ObjID+"\" style=\"position:absolute;left:4px;top:0px;width:"+(Width-8)+"px;height:23px;background-image: url(images/skins/bicq/bar_top.gif);\" onDBlclick=\"MaxWindow('"+ObjID+"');\"></div>"
				+"<div id=\"BICQWindowTitleR_"+ObjID+"\" style=\"position:absolute;left:"+(Width-4)+"px;top:0px;width:4px;height:23px;background-image: url(images/skins/bicq/bar_right_u.gif);\"></div>"

				/* 标题栏小图标和标题名 */
				+"<div id=\"BICQWindowIcon_"+ObjID+"\" style=\"position:absolute;left:5px;top:1px;width:20px;height:20px;background-image: url("+Ico+");\" onDBlclick=\"CloseWindows('"+ObjID+"');\"></div>"
				+"<div id=\"BICQWindowTitleName_"+ObjID+"\" style=\"position:absolute;left:28px;top:6px;\" class=\"WindowTitleName\" onDBlclick=\"MaxWindow('"+ObjID+"');\">"+Title+"</div>"

				/* 窗口上的功能按钮 */
				+(zMin==1 ? "<div id=\"BICQWindowMin_"+ObjID+"\" style=\"position:absolute;left:"+(Width-(zMax==1 ? 81 : 56))+"px;top:0px;width:25px;height:15px;background-image: url(images/skins/bicq/min_button.gif);\" onClick=\"MinWindow('"+ObjID+"');\"></div>" : "")
				+(zMax==1 ? "<div id=\"BICQWindowMax_"+ObjID+"\" style=\"position:absolute;left:"+(Width-56)+"px;top:0px;width:25px;height:15px;background-image: url(images/skins/bicq/max_button.gif);\" onClick=\"MaxWindow('"+ObjID+"');\"></div>" : "")
				+"<div id=\"BICQWindowCls_"+ObjID+"\" style=\"position:absolute;left:"+(Width-30)+"px;top:0px;width:25px;height:15px;background-image: url(images/skins/bicq/close_button.gif);\" onClick=\"CloseWindows('"+ObjID+"');\"></div>"

			+"</div>"

			/* 窗口边框 */
			+"<div id=\"BICQWindowBoxLine_"+ObjID+"\" style=\"position:absolute;left:0px;top:22px;width:"+(Width-2)+"px;height:"+(Height-25-17)+"px;\" class=\"WindowBoxLine\"></div>"

			/* 窗口内容 */
			+"<div id=\"BICQWindowContent_"+ObjID+"\" style=\"position:absolute;left:1px;top:23px;width:"+(Width-2)+"px;height:"+(Height-25-15)+"px;overflow-x:hidden;overflow-y:hidden;\" class=\"WindowBoxColor\">"+WinContent+"</div>"

			/* 窗口状态栏 */
			+"<div id=\"BICQWindowStatus_"+ObjID+"\" style=\"position:absolute;width:"+(Width)+"px;height:4px;left:0px;top:"+(Height-19)+"px;\">"
				+"<div style=\"position:absolute;left:0px;top:0px;width:4px;height:4px;\"><img src=\"images/skins/bicq/bar_left_d.gif\" width=\"4\" height=\"4\" border=\"0\"></div>"
				+"<div style=\"position:absolute;left:4px;top:0px;width:"+(Width-8)+"px;height:4px;\"><img id=\"BICQWindowStatusBar_"+ObjID+"\" src=\"images/skins/bicq/bar_bottom.gif\" width=\""+(Width-8)+"\" height=\"4\" border=\"0\"></div>"
				+"<div id=\"BICQWindowStatusRight_"+ObjID+"\" style=\"position:absolute;left:"+(Width-4)+"px;top:0px;width:4px;height:4px;\"><img src=\"images/skins/bicq/bar_right_d.gif\" width=\"4\" height=\"4\" border=\"0\"></div>"
				+(zMax==1 ? "<div id=\"BICQWindowStatusi_"+ObjID+"\" style=\"position:absolute;width:10px;height:10px;left:"+(Width-10)+"px;top:-8px;\" onMouseOver=\"ChangeMouseStatus(1,'"+ObjID+"');\" onMouseOut=\"ChangeMouseStatus(2,'"+ObjID+"');\" onMouseDown=\"SetFocus('"+ObjID+"');ReSizeCatch('"+ObjID+"');\" onMouseUp=\"ReSizeRelease();\"></div>" : "")
			+"</div>"

			/* 窗口阻挡 */
			+(Microsoft_IE ? "<iframe id=\"BICQWindowBoxFrame_"+ObjID+"\" 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);-moz-opacity:.0;opacity:0.0;\" frameborder=0></iframe>" : "")

			/* 子窗口 */
			+CreateSubWindow(ObjID,WinSubContent,0,Height-16,Width,sHeight)
		+"</div>";

	WindowsType[ObjID+"_min"]=zMin;
	WindowsType[ObjID+"_max"]=zMax;
	WindowsStatus[ObjID]=Cls;

	sWindowMain[ObjID+"_width"]=Width;
	sWindowMain[ObjID+"_height"]=Height;
	sWindowMain[ObjID+"_left"]=Left;
	sWindowMain[ObjID+"_top"]=Top;

	if (WinType == "1") {
		var sObj=document.createElement("span");
		sObj.innerHTML=WinHTML;
		$("WindowsGlobalBodyIDS").appendChild(sObj);
	}
	else {
		document.write(WinHTML);
	}
	zIndex++;
};

function GetMainTitleArr(x,y) {
	var zArray=new Array(new Array(12,26,47),
		new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,22,26,30,38,47),
		new Array(7,19,20,21,22,23,26,27,28,29,30,31,39,43,44,45,46,47,49),
		new Array(7,19,22,23,24,25,26,47,50),
		new Array(7,19,22,27,29,36,37,38,39,40,41,47),
		new Array(7,19,22,28,32,40,42,43,44,45,46,47,48,49,50),
		new Array(7,12,19,20,21,22,26,27,29,32,37,40,47),
		new Array(1,2,3,4,5,6,7,8,9,10,11,12,13,19,22,24,25,30,31,32,38,40,45,47),
		new Array(7,19,22,38,40,43,45,47),
		new Array(7,19,22,24,25,26,27,28,29,30,31,39,43,45,46,47),
		new Array(7,19,22,26,28,38,40,43,45,47),
		new Array(7,19,20,21,22,26,28,38,41,43,45,48),
		new Array(7,19,22,25,28,32,37,41,43,45,48),
		new Array(7,13,25,28,32,36,43,45,46,48,50),
		new Array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,24,29,30,31,32,42,43,44,49,50),
		new Array(22,23,50)
	);

	var zHtml="";
	for (var i=0;i<zArray.length;i++) {
		for (var j=0;j<zArray[i].length;j++) {
			zHtml+="<div style=\"position: absolute;top:"+i+"px;left:"+zArray[i][j]+"px;\"><img src=\"images/blank.gif\" width=\"1\" height=\"1\" border=\"0\"></div>";
		}
	}
	zHtml="<div id=\"TheMainTitle\" style=\"position:absolute; left:"+(x-55)+"px;top:"+(y-50)+"px;display:none;\">"+zHtml+"</div>";
	return zHtml;
};

function CreateWaiter(Name,Left,Top) {
	var WaiterHtml=""
		+"<div id=\""+Name+"\" class=\"WindowWaiter\" style=\"position:absolute; left:"+Left+"px; top:"+Top+"px;\">"
		+"<div style=\"position:absolute; left:55px; top:30px; width:186px; font-weight: bold;\"><span id=\""+Name+"_Lable\">正在连接到服务器，请稍候。</span>&nbsp;<span id=\""+Name+"_TimerOut\" style=\"visibility:hidden;\">"+zTimerOut+"</span></div>"
		+(Microsoft_IE ? "<iframe src=\"about:blank\" style=\"position:absolute; visibility:inherit; top:0px; left:0px; width:100%; height:100%; z-index:-1; filter:Alpha(opacity=0);-moz-opacity:.0;opacity:0.0;\" frameborder=0></iframe>" : "")
		+"</div>";

	return WaiterHtml;
};

function CreateSubWindow(ObjID,sWinContent,Left,Top,Width,Height) {
	var sWinHTML=""
		+"<div id=\"SubWindow_"+ObjID+"\" style=\"position:absolute; left:"+Left+"px; top:"+Top+"px; width:"+Width+"px; height:"+(Height+5)+"px; overflow-x:hidden;overflow-y:hidden; visibility:hidden;\">"
		+"<div style=\"position:absolute;left:0px;top:0px;width:5px;height:5px;\"><img src=\"images/skins/bicq/sub_top_l.gif\" width=\"5\" height=\"5\" border=\"0\"></div>"
		+"<div style=\"position:absolute;left:5px;top:0px;width:5px;height:5px;\"><img id=\"SubWindowTC_"+ObjID+"\" src=\"images/skins/bicq/sub_top_c.gif\" width=\""+(Width-10)+"\" height=\"5\" border=\"0\"></div>"
		+"<div id=\"SubWindowTR_"+ObjID+"\" style=\"position:absolute;left:"+(Width-5)+"px;top:0px;width:5px;height:5px;\"><img src=\"images/skins/bicq/sub_top_r.gif\" width=\"5\" height=\"5\" border=\"0\"></div>"
		+"<div id=\"SubWindowTT1_"+ObjID+"\" style=\"position:absolute;left:0px;top:5px;width:"+(Width-2)+"px;height:"+(Height-5)+"px;\" class=\"SubWindow\"></div>"
		+"<div id=\"SubWindowTT2_"+ObjID+"\" style=\"position:absolute;left:1px;top:5px;width:"+(Width-4)+"px;height:"+(Height-5)+"px;\" class=\"SubWindowBox_1\"></div>"
		+"<div id=\"SubWindowTT3_"+ObjID+"\" style=\"position:absolute;left:5px;top:5px;width:"+(Width-10)+"px;height:"+(Height-5)+"px;\" class=\"SubWindowBox_2\">"+sWinContent+"</div>"
		+"<div style=\"position:absolute;left:0px;top:"+(Height)+"px;width:5px;height:5px;\"><img src=\"images/skins/bicq/sub_bottom_l.gif\" width=\"5\" height=\"5\" border=\"0\"></div>"
		+"<div style=\"position:absolute;left:5px;top:"+(Height)+"px;width:5px;height:5px;\"><img id=\"SubWindowBC_"+ObjID+"\" src=\"images/skins/bicq/sub_bottom_c.gif\" width=\""+(Width-10)+"\" height=\"5\" border=\"0\"></div>"
		+"<div id=\"SubWindowTT4_"+ObjID+"\" style=\"position:absolute;left:"+(Width-5)+"px;top:"+(Height)+"px;width:5px;height:5px;\"><img src=\"images/skins/bicq/sub_bottom_r.gif\" width=\"5\" height=\"5\" border=\"0\"></div>"

		/* 窗口阻挡 */
		+(Microsoft_IE ? "<iframe id=\"SubWindowFrame_"+ObjID+"\" 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);-moz-opacity:.0;opacity:0.0;\" frameborder=0></iframe>" : "")
		+"</div>";

	return sWinHTML;
};

GetCurrentWH();
document.onmousedown=onMouseDown_Click;
document.onmouseup=onMouseUp_Click;
document.onmousemove=onMouseMove_Click;
document.documentElement.onclick=onMouseClick_Click;
document.onkeydown=onKeyDown_Click;
document.onselectstart=DisableMouseEvent;
if (JsAllErrorDebug==0) document.oncontextmenu=DisableMouseEvent;
