//5秒钟后转到首页
var count = 5; 

function SetTime(url, tip) 
{ 
    var waitTime = $$("IDH_WaitTime"); 
    if(count == 0) 
    { 
		window.location = url;
    }
    else 
    { 
        waitTime.innerText = count + " 秒钟后转到" + tip;
        count--; 
        window.setTimeout(function(){SetTime(url, tip)}, 1000); 
    } 
}
//////////////////////////////////////////////////
// 功能: 隐藏一组对象,显示指定对象
// 参数: formName-触发对象名
//          toName-目标对象名
//          showID-需要显示的对象索引
//          tabClass-触发对象需要改变的class名称
//          oldClass-非触发对象需要改变的oldClass名称
// 返回:ture为成功 flash为失败
//////////////////////////////////////////////////
function TabObj(formName, toName, showIndex, tabClass, oldClass)
{
	var i = 0;
	var toObj = $$(toName + i);
	while (toObj != null)
	{
		toObj.style.display = "none";
		$$(formName + i).className = oldClass;
		i++;
		toObj = $$(toName + i);
	}
	try
	{
		$$(toName + showIndex).style.display = "";
		$$(formName + showIndex).className = tabClass;
		return true;
	}
	catch(ex)
	{
		return false;
	}
}
//////////////////////////////////////////////////
// 功能: 返回只为数字的数据
//////////////////////////////////////////////////
function IsDigit(){
  return ((event.keyCode >= 48) && (event.keyCode <= 57)) || (event.keyCode == 13);
}
//////////////////////////////////////////////////
// 功能: 获取字符串的字节长度(汉字算成两个字节)
// 参数: sValue-要检查的字符串
// 返回: 字符串的字节长度(10进制数字表示)
//////////////////////////////////////////////////
function GetStrLen(sValue)
{
  var cArr = sValue.match(/[^\x00-\xff]/ig);
  return sValue.length + (cArr == null ? 0 : cArr.length);
}
//////////////////////////////////////////////////
// 功能: 检测是否符合指定规则
// 参数: Str-要检查的对象 Style-需要匹配的逻辑
// 返回: true false
//////////////////////////////////////////////////
function RegExpTest(Str, Style)
{
	if (Style == "N") {
		Style = /^\d*$/;//0和正整数
	}else if (Style == "+N") {
		Style = /^[0-9]*[1-9][0-9]*$/;//大于0的正整数
	}else if (Style == "MAIL") {
		Style = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;//Email地址
	}else if (Style == "ACC") {
		Style = /^[a-zA-Z0-9]{4,16}$/;//长度为4-16个字母、数字组合
	}else if (Style == "ID") {
		Style = /^[0-9]{15}$|^[0-9]{17}[0-9xX]{1}$/;//身份证
	}else if (Style == "DATE") {
		Style = /^\d{4}\-\d{1,2}-\d{1,2}$/;//日期 2008-07-23
    } else if (Style == "DATETIME") { 
		Style = /^\d{4}\-\d{1,2}-\d{1,2} \d{1,2}:\d{2}:\d{2}$/;//日期和时间 2008-07-23 0:00:00
	}else if (Style == "UP") {
		Style = /^\/[\d]{6}\/.+$/;//上传文件夹的子目录 /200807/xxxxxxxxxxx
	}else{
		return false;
	}
	return Style.test(Str);
}
//去除字符串中左右空白字符
String.prototype.trim = function()   
{   
	return this.replace(/(^\s*)|(\s*$)/g,   "");
}
//////////////////////////////////////////////////
// 功能: 根据传入的code值返回消息提示(必须有g_aTip二维数组)
// 参数: code - 数字代码
// 返回: tip - 提示
//////////////////////////////////////////////////
function CodeToTip(code)
{
	for (i = 0; i < g_aTip.length; i++)
	{
		if (g_aTip[i][0] == code) {
		    return g_aTip[i][1];
		}
	}
	return code;
}
//////////////////////////////////////////////////
// 功能: 检测多选按钮是否有选中
// 参数: obj-需要检测的控件
// 返回: true-有被选中 false-没有被选中
//////////////////////////////////////////////////
function CheckBox(obj){
	for (i = 0;i < obj.length;i++){
		if (obj(i).checked){
			return true;
		}
	}
	if (obj.checked){
		return true;
	}
}
//复制下拉列表内容
function CopyOption(from, to)
{
	try
	{
		for (var i = 0; i < from.options.length; i++)
		{
			if(from.options[i].selected)
			{
				var e = from.options[i];
				to.options.add(new Option(e.text, e.value));
			}
		}
	}catch(ex){}
} 
//移动下拉列表内容
function MoveOption(from, to)
{
	try
	{
		for (var i = 0; i < from.options.length; i++)
		{
			if(from.options[i].selected)
			{
				var e = from.options[i];
				to.options.add(new Option(e.text, e.value));
				from.remove(i);
				i--;
			}
		}
	}catch(ex){}
}
//删除下拉列表内容
function DeleteOption(obj)
{
	try
	{
		for (var i = 0; i < obj.options.length; i++)
		{
			if(obj.options[i].selected)
			{
				obj.remove(i);
				i--;
			}
		}
	}catch(ex){}
}  
//////////////////////////////////////////////////
// 功能: 建立上传控件
// 参数: target - 上传成功后保存文件地址的对象ID urlValue - 地址的默认值
// 返回: 上传控件字符串
//////////////////////////////////////////////////
function CreateUpload(target, urlValue)
{
    var urlDisplay = "display: none;";
    var urlChecked;

    var fileDisplay;
    var fileChecked = "checked=\"checked\"";
    
    if (urlValue != "")
    {
        var tmp = urlDisplay;
        urlDisplay = fileDisplay;
        fileDisplay = tmp;
        
        tmp = urlChecked;
        urlChecked = fileChecked;
        fileChecked = tmp;
    }

	//上传控件全局随机字符串
	g_UploadRndStr = (Math.random() + "K").substr(3, 4);
	
	var sHtml = "<input id=\"" + target + "\" style=\"width: 240px; float: left;" + urlDisplay + "\" class=\"inputText1\" type=\"text\" value=\"" + urlValue + "\" check=\"RF|RV$L$0$40\" tip=\"GAME_IMG1_EMPTY|GAME_IMG1_BOUND\" \/>";
	sHtml += "<div id=\"IDH_FileCase_" + g_UploadRndStr + "\" class=\"tip\" style=\"width:270px;height:19px; float: left;\">";
	sHtml += "<iframe id=\"IDH_File_" + g_UploadRndStr + "\" style=\"width: 204px; height: 19px; float: left;" + fileDisplay + "\" src=\"/common/upload.aspx?target=" + target + "&rndstr=" + g_UploadRndStr + "\" scrolling=\"no\" frameborder=\"0\" ><\/iframe>";
	sHtml += "<input id=\"IDC_BtnSubmit\" type=\"button\" onclick=\"CheckUpload(IDH_File_" + g_UploadRndStr + ")\" class=\"inputButton1\" style=\"height: 19px; margin-left:2px; float:left\" value=\"上传\" \/>";
	sHtml += "<\/div>";
	sHtml += "<input name=\"IDC_Img_Mode_" + g_UploadRndStr + "\" " + fileChecked + " type=\"radio\" onclick=\"$$('" + target + "').style.display='none';$$('IDH_FileCase_" + g_UploadRndStr + "').style.display=''\" \/>本地";
	sHtml += "<input name=\"IDC_Img_Mode_" + g_UploadRndStr + "\" " + urlChecked + " type=\"radio\" onclick=\"$$('" + target + "').style.display='';$$('IDH_FileCase_" + g_UploadRndStr + "').style.display='none'\" \/>网络";
	sHtml += " <span id=\"IDH_File_View_" + g_UploadRndStr + "\"><\/span>";
	
	return sHtml;
}
//检测上传控件里面的值,合法则提高,否则提示
function CheckUpload(oIframe, gAllowType)
{
	var postedFileInput = oIframe.IDH_UpLoadForm.IDC_PostedFile;
	var val = postedFileInput.value

	if (!/^[a-zA-Z]{1}:\\.+.[a-zA-Z0-9]{1,6}$/.test(val))
	{
		alert("该地址无效,请重新选择!");
		postedFileInput.focus();
	}
	else if (gAllowType && !IsAllowType(GetFileExt(val), gAllowType))
	{
		alert("该文件格式无效!允许格式为:" + gAllowType);
		postedFileInput.focus();
	}
	else
	{
		oIframe.IDH_UpLoadForm.submit();
	}
}
//////////////////////////////////////////////////
// 功能: 全选或全不选一组CheckBox
// 参数: chkall-全选按钮 obj-需要全选的按钮组
//////////////////////////////////////////////////
function SelectAllGroup(chkall,obj){
	if (obj){
		for (var i = 0;i < obj.length;i++){
			obj[i].checked = chkall.checked;
		}
		obj.checked = chkall.checked;
	}
}
//////////////////////////////////////////////////
// 功能: 全选或全不选所有CheckBox
// 参数: chkall-全选按钮 obj-需要全选的按钮组
//////////////////////////////////////////////////
function SelectAll(chkall){
    var all = document.getElementsByTagName( "*" );

    for(var i = 0; i < all.length; i++)
    {
        if (all[i].tagName == "INPUT" && all[i].type == "checkbox")
        {
            all[i].checked = chkall.checked;
        }
    }
}
//////////////////////////////////////////////////
// 功能: 全选或全不选一序列CheckBox
// 参数: chkall-全选按钮 chkBoxID-需要选择的CheckBox的ID# nBegin-开始 nEnd-结束
//////////////////////////////////////////////////
function SelectAllList(chkall, chkBoxID, nBegin, nEnd){
    var oChkBox;
   var i = 0; 
    
    if (nBegin)
   { 
	    for (var i = nBegin;i <= nEnd;i++){
	        oChkBox = $$(chkBoxID + i);
		    oChkBox.checked = chkall.checked;
	    }
	}
	else
	{
		do
		{
		    i++;
		    oChkBox = $$(chkBoxID + i);
		    if (oChkBox)
		    {
		        oChkBox.checked = chkall.checked;
		    } 
		}
		while (oChkBox)
	}
}
//////////////////////////////////////////////////
// 功能: 将提交控件禁用或取消禁用
// 参数: obj-对象 flag-true false
//////////////////////////////////////////////////
function DisableObj(obj, flag)
{
	try{
		obj.disabled = flag;
	}
	catch (e) {}
}
//////////////////////////////////////////////////
// 功能: 根据对象ID获取对象的值
// 参数: objID - 对象ID
// 返回: 该对象的值
//////////////////////////////////////////////////
function GetValueById(objID)
{
	try
	{
		return Escape($$(objID).value);
	}
	catch (ex)	
	{
		return "";
	}
}
//////////////////////////////////////////////////
// 功能: 根据对象名称获取一组对象的值
// 参数: oName - 对象名称
// 返回: 用逗号隔开的字符串 如 1,2,3,4
//////////////////////////////////////////////////
function GetValueByName(oName)
{
	var obj = document.getElementsByName(oName);
	var sResult = "";
	for (var i = 0;i < obj.length;i++)
	{
		if (sResult != "")
		{
		    sResult += ",";
		}
		sResult += Escape(obj[i].value);
	}
	return sResult;
}
//////////////////////////////////////////////////
// 功能: 根据选定的对象名称获取一组对象的值
// 参数: oName - 对象名称
// 返回: 用逗号隔开的字符串 如 1,2,3,4
//////////////////////////////////////////////////
function GetValueByChkBoxName(oName)
{
	var obj = document.getElementsByName(oName);
	var sResult = "";
	for (var i = 0;i < obj.length;i++)
	{
		if (obj[i].checked)
		{
			if (sResult != "")
			{
			    sResult += ",";
			}
			sResult += Escape(obj[i].value);
		}
	}
	return sResult;
}
//////////////////////////////////////////////////
// 功能: 根据ID获取数据
// 参数: objID-对象ID字符串
//////////////////////////////////////////////////
function $$(objID)
{
	return document.getElementById(objID);
}
//////////////////////////////////////////////////
// 功能: 编码成UTF-8
//////////////////////////////////////////////////
function Escape(s)
{
	s = s.replace(/\·/g,"%a1%a4");
	s = s.replace(/\×/g,"%a1%c1");
	s = escape(s);
	s = s.replace(/\+/g,"%2b");
	s = s.replace(/%25a1%25a4/g,"%a1%a4");
	s = s.replace(/%25a1%25c1/g,"%a1%c1");
	return s;
}
//摧毁对象
function DestroyObj(obj)
{
	try
	{
		obj.parentNode.removeChild(obj);
	}
	catch(e){}
}
//向指定位置的光标区插入代码
//function InsertCode(code, target)
//{
//	//获取选区
//	var oSelectionRange = target.document.selection.createRange();
//	//获取选区类型
//	var oSelectionType = target.document.selection.type;
//	//焦点定位到选区
//	oSelectionRange.select();
//	
//	if(oSelectionType.toLowerCase() == "text" || oSelectionType.toLowerCase() == "none")
//	{
//		oSelectionRange.pasteHTML(code);
//	}
//}
//格式化时间
Date.prototype.format = function(format)
{
	var o = {
	"M+" : this.getMonth()+1, //month
	"d+" : this.getDate(),    //day
	"h+" : this.getHours(),   //hour
	"m+" : this.getMinutes(), //minute
	"s+" : this.getSeconds(), //second
	"q+" : Math.floor((this.getMonth()+3)/3),  //quarter
	"S" : this.getMilliseconds() //millisecond
	}
	if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
	(this.getFullYear()+"").substr(4 - RegExp.$1.length));
	for(var k in o)if(new RegExp("("+ k +")").test(format))
	format = format.replace(RegExp.$1,
	RegExp.$1.length==1 ? o[k] :
	("00"+ o[k]).substr((""+ o[k]).length));
	return format;
}
//格式化HTML
function FormatHTML(s)
{
	var url = document.URL;
	url = url.substr(0, url.lastIndexOf('/') + 1);
	
	//清除虚拟地址
	s = s.replace(eval("/" + url.replace(/\//gi,"\\/") + "/gi"), "");
	s = s.replace(eval("/http:\\/\\/" + document.domain + "/gi"), "");
	//清除<a></a>无效代码
	s = s.replace(/<a+[^<]*><\/a>/gi, "");

	return s;//.toLowerCase();
}
//创建图片的HTML代码
function CreateImgHTML(val, width, height, ps)
{
	var sHtml = "<img";
	if (val != "") sHtml += " src=\"" + AddPath(val) + "\"";
	if (RegExpTest(width, "+N") && RegExpTest(height, "+N")) sHtml += " style=\"width:" + width + "px;height:" + height + "px;\"";
	if (ps && ps != "") sHtml += " alt=\"" + ps + "\"";
	sHtml += " border=0>";
	
	return sHtml;
}
//创建媒体的HTML代码
function CreateMovieHTML(val, width, height)
{
	var sHtml;
	
	if (GetFileExt(val).toLowerCase() == "sfwf")
	{
	
	}
	else
	{
		sHtml = "<embed";
		if (val != "") sHtml += " src=\"" + AddPath(val) + "\"";
		if (RegExpTest(width, "+N") && RegExpTest(height, "+N")) sHtml += " style=\"width:" + width + "px;height:" + height + "px;\"";
		sHtml += " type=audio\/x-pn-realaudio-plugin><\/embed>";
	}
			
	return sHtml;
}
//查看上传文件
function InsertFileView(imgCase, urlID)
{
	var val = $$(urlID).value;
	if (IsAllowType(GetFileExt(val), "jpg|gif|bmp"))
	{
		imgCase.innerHTML = "<a href=\"javascript:;\" class=\"a_blue\" onmouseover=\"this.innerHTML = '查看<span style=\\\'position: absolute;\\\'>' + CreateImgHTML(\'" + val + "\') + '<\\/span>';\" onmouseout=\"this.innerText='查看'\" style=\"cursor: pointer;\">查看<\/a>";
	}
	else if (IsAllowType(GetFileExt(val), "swf|avi|asf|wmv|rm|ra|ram"))
	{
		imgCase.innerHTML = "<a href=\"javascript:;\" class=\"a_blue\" onclick=\"if (this.innerText == '播放') {this.innerHTML = '关闭<span style=\\\'position: absolute;\\\'>' + CreateMovieHTML(\'" + val + "\') + '<\\/span>';} else {this.innerText = '播放';}\" style=\"cursor: pointer;\">播放<\/a>";
	}
	else
	{
		imgCase.innerHTML = "<a href=\"" + AddPath(val) + "\" class=\"a_blue\"  target==\"_blank\">打开<\/a>";
	}
}
//获取文件后缀
function GetFileExt(fullName)
{
	return fullName.substr(fullName.lastIndexOf('.') + 1);
}
//是否为允许上传的类型
function IsAllowType(fileExt, gAllowType)
{
    var aAllowType = gAllowType.split('|');
    for (var i = 0; i < aAllowType.length; i++)
    {
        if (fileExt.toLowerCase() == aAllowType[i].toLowerCase())
        {
            return true;
        }
    }
    return false;
}
//将是上传文件夹的子目录的文件增加上传路径
function AddPath(path)
{
	if (RegExpTest(path, "UP"))
	{
		return "/UploadFile" + path;
	}
	return path;
}
//创建进度条
function CreateLoading(){
	RemoveLoading()
	
	var loading = document.createElement("div");
	loading.id = "Loading";
	loading.className = "loading";
	loading.style.left = "0px";
	loading.style.top = "0px";
	document.body.appendChild(loading);
	loading.innerText = "Loading...";
	
	LoadingPos();
	window.onscroll=LoadingPos;
	window.onresize=LoadingPos;

	//将进度条居中
	function LoadingPos()
	{
		PosCenter($$("Loading"));
	}
}
//销毁进度条
function RemoveLoading()
{
	window.onscroll=null;
	window.onresize=null;
	DestroyObj($$("Loading"))
}
//////////////////////////////////////////////////
// 功能: 创建对话框
// 参数: 
//		 msg - 消息
//		 okFunc - 点击确定后执行的函数字符串,如:"myfunction(parm)"
//		 type - 窗口类型 空为确定窗口 confirm为确认窗口 prompt为输入窗口
//		 isModal - 是否为模态窗口
//		 width - 输入窗口的宽 height - 输入窗口的高
//		 title - 窗口的标题
//////////////////////////////////////////////////
function ShowDialog(msg, okFunc, type, isModal, width, height, title)
{
	//摧毁进度条
	RemoveLoading();
		
	if (msg)
	{
		//是否设置了宽度
		width = width ? width : 145;
		//是否设置了高度
		height = height ? height : 45;
		//是否设置了标题
		title = title ? title : "DreamGame Message";
		//dlgOk的名称
		dlgOK = "DlgOK" + Math.random();
		var sHtml = "<table class=\"dialog_table\" cellpadding=\"5\">"
		//消息
		sHtml += "<tr>";
		sHtml += "<td  nowrap=\"nowrap\">"
		sHtml += msg;
		sHtml += "<\/td>";
		sHtml += "<\/tr>";
		//输入框
		if (type == "prompt")
		{
			sHtml += "<tr>";
			sHtml += "<td>";
			sHtml += "<textarea id=\"DlgValue\" class=\"textArea1\" style=\"overflow:auto;width:" + width + "px;height:" + height + "px\"><\/textarea>";
			sHtml += "<\/td>";
			sHtml += "<\/tr>";
		}

		sHtml += "<tr>";
		sHtml += "<td>";
		//确定按钮
		sHtml += "<input id=\"" + dlgOK + "\" type=\"button\" class=\"inputButton1\" value=\"确 定\" style=\"width:50px;\" \/>";
		//取消按钮
		if (type == "confirm" || type == "prompt")
		{
			sHtml += "　";
			sHtml += "<input id=\"DlgCancel\" type=\"button\" class=\"inputButton1\" value=\"取 消\" style=\"width:50px;\" \/>";
		}
		sHtml += "<\/td>";
		sHtml += "<\/tr>";
		sHtml += "<\/table>";
		
		//创建窗口
		CreateDialog(title, sHtml);
		
		//确定按钮触发
		$$(dlgOK).onclick = function()
		{
			if (okFunc)
			{
				eval(okFunc);
			}
			else
			{
				RemoveDialog();
			}
		}

		//取消按钮触发
		if (type == "confirm" || type == "prompt")
		{
			$$("DlgCancel").onclick = function()
			{
				RemoveDialog();
			}
		}

		$$(dlgOK).focus();
	}
	else
	{
		if (okFunc)
		{
			eval(okFunc);
		}
	}
}
//////////////////////////////////////////////////
// 功能: 在鼠标位置创建一个空面板
// 参数: title - 窗口标题 html - 插入代码 isModal - 是(默认)否模态窗口 isDrag - 是(默认)否可拖动
//////////////////////////////////////////////////
function CreatePanel(html, isModal, isDrag)
{
	if (html)
	{
		DestroyObj($$("DialogDrag"));
		DestroyObj($$("DialogMask"));

		//创建对话框
		var dialog = document.createElement("div");
		dialog.id = "DialogDrag";
		dialog.className = "dragobj";
		dialog.style.top = "0px";
		dialog.style.left = "0px";
		document.body.appendChild(dialog);

		//窗体
		var sHtml = "<table id=\"Dialog\" class=\"dialog draghot\" cellpadding=\"5\" cellspacing=\"1\"  oncontextmenu=\"return false\">"
		sHtml += "<tbody class=\"tbody\">";
		//内容
		sHtml += "<tr>";
		sHtml += "<td class=\"text\">";

		sHtml += html;

		sHtml += "<div style=\"text-align:center;\"><a class=\"a_red\" href=\"javascript:RemoveDialog();\">关 闭<\/a><\/div><\/td>";
		sHtml += "<\/tr>";
		sHtml += "<\/tbody>"
		sHtml += "<\/table>";
		
		dialog.innerHTML = sHtml;
		
		PosMouse($$("Dialog"));
		
		//是否可拖动
		if (isDrag != false)
		{
			document.onmousedown=Drag;
			document.onmousemove=MoveMask;
			document.onmouseup=new Function("isdrag=false");
		}
	}
}
//////////////////////////////////////////////////
// 功能: 在屏幕正中间创建空窗口
// 参数: title - 窗口标题 html - 插入代码 isModal - 是(默认)否模态窗口 isDrag - 是(默认)否可拖动
//////////////////////////////////////////////////
function CreateDialog(title, html, isModal, isDrag)
{
	if (html)
	{
		DestroyObj($$("DialogDrag"));
		DestroyObj($$("DialogMask"));

		//创建对话框
		var dialog = document.createElement("div");
		dialog.id = "DialogDrag";
		dialog.className = "dragobj";
		dialog.style.top = "0px";
		dialog.style.left = "0px";
		document.body.appendChild(dialog);

		//窗体
		var sHtml = "<table id=\"Dialog\" class=\"dialog\" cellpadding=\"5\" cellspacing=\"1\"  oncontextmenu=\"return false\">"
		sHtml += "<tbody class=\"tbody\">";
		//标题
		sHtml += "<tr class=\"draghot\">";
		sHtml += "<td class=\"title\" nowrap=\"nowrap\">" + title + "<\/td>";
		sHtml += "<\/tr>";
		//内容
		sHtml += "<tr>";
		sHtml += "<td class=\"text\">";

		sHtml += html;

		sHtml += "<\/td>";
		sHtml += "<\/tr>";
		sHtml += "<\/tbody>"
		sHtml += "<\/table>";
		
		dialog.innerHTML = sHtml;
		
		//对话框居中
		PosCenter($$("Dialog"));
		
		//是否为模态窗口
		if (isModal != false)
		{
			var mask = document.createElement("div");
			mask.id = "DialogMask";
			mask.className = "dialog_mask";
			document.body.appendChild(mask);
		}
		
		//是否可拖动
		if (isDrag != false)
		{
			document.onmousedown=Drag;
			document.onmousemove=MoveMask;
			document.onmouseup=new Function("isdrag=false");
		}

		//将Dialog和MSAK居中
		window.onscroll=DialogPos;
		window.onresize=DialogPos;
		function DialogPos()
		{
			PosCenter($$("Dialog"));
			MoveMask();
		}
	}
}
//销毁对话框
function RemoveDialog()
{
	window.onscroll=null;
	window.onresize=null;
	document.onmousedown=null;
	document.onmousemove=null;
	document.onmouseup=null;
	DestroyObj($$("DialogDrag"));
	DestroyObj($$("DialogMask"));
	sHtml = null;
	dialog = null;
	mask = null;
}
//////////////////////////////////////////////////
// 功能: 将对象设置为鼠标指针位置
// 参数: objID-对象
//////////////////////////////////////////////////
function PosMouse(obj)
{
	var oEl = document.documentElement;
	
	var ie=document.all;
	try
	{
		var mouseX = ie ? event.clientX : e.clientX;
		var mouseY = ie ? event.clientY : e.clientY;
	}
	catch (ex)
	{
		mouseX = g_mouseX;
		mouseY = g_mouseY;
	}
		
	obj.style.top = (mouseY + oEl.scrollTop) + "px";
	obj.style.left = (mouseX + oEl.scrollLeft + 20) + "px";
}
//////////////////////////////////////////////////
// 功能: 将对象居中
// 参数: objID-对象
//////////////////////////////////////////////////
function PosCenter(obj)
{
	var oEl = document.documentElement;
	try
	{
		obj.style.top=oEl.scrollTop + (oEl.clientHeight-obj.offsetHeight)/2 - oEl.parentNode.body.offsetTop + "px";
		obj.style.left=oEl.scrollLeft + (oEl.clientWidth-obj.offsetWidth)/2 - oEl.parentNode.body.offsetLeft + "px";
	}
	catch(ex){}
}
//////////////////////////////////////////////////
// 功能: MASK挡住鼠标
//////////////////////////////////////////////////
function MoveMask(e)
{
	var mask = $$("DialogMask");
	if (mask)
	{
		var ie=document.all;
		var dEl = document.documentElement;
		var half = mask.offsetWidth/2;
		var mouseX = ie ? event.clientX : e.clientX;
		var mouseY = ie ? event.clientY : e.clientY;

		if (mouseX >= half && mouseX <= dEl.clientWidth - half)
		{
			mask.style.left = dEl.scrollLeft + mouseX - half + "px";
		}
		if (mouseY >= half && mouseY <= dEl.clientHeight - half)
		{
			mask.style.top = dEl.scrollTop + mouseY - half + "px";
		}
	}
}
//////////////////////////////////////////////////
// 功能: 拖动对象
// 说明: class为draghot-有效区域 class为dragobj-需要拖动的对象
//////////////////////////////////////////////////
function Drag(e) {
	//是否IE浏览器
	var ie=document.all;
	var mouseBtn = ie ? event.button : e.which;
	if (mouseBtn == 1)
	{
		//鼠标坐标
		var mouseX = ie ? event.clientX : e.clientX;
		var mouseY = ie ? event.clientY : e.clientY;
		var oDragHandle = ie ? event.srcElement : e.target;
		var oDragObj = oDragHandle;
		var dialog = $$("Dialog")
		var topElement = "HTML";
		
		while (oDragHandle.tagName != topElement && oDragHandle.className.indexOf("draghot") == -1)
		{
			oDragHandle = ie ? oDragHandle.parentElement : oDragHandle.parentNode;
		}
		while (oDragObj.tagName != topElement && oDragObj.className.indexOf("dragobj") == -1)
		{
			oDragObj = ie ? oDragObj.parentElement : oDragObj.parentNode;
		}
		
		if (oDragHandle.className.indexOf("draghot") != -1)
		{
			isdrag = true;
			var dEl = document.documentElement;
			objX = parseInt(oDragObj.style.left + dEl.parentNode.body.offsetLeft);
			objY = parseInt(oDragObj.style.top + dEl.parentNode.body.offsetTop);
 
			document.onmousemove=function(e)
			{
				//鼠标坐标
				var NewMouseX = ie ? event.clientX : e.clientX;
				var NewMouseY = ie ? event.clientY : e.clientY;
				MoveMask(e);
				if (isdrag)
				{
					if (NewMouseX >= dialog.offsetWidth && NewMouseX <= dEl.clientWidth - dialog.offsetWidth)
					{
						oDragObj.style.left = objX + NewMouseX - mouseX + "px";
					}
					if (NewMouseY >= 25 && NewMouseY <= dEl.clientHeight - dialog.offsetHeight)
					{
						oDragObj.style.top = objY + NewMouseY - mouseY+"px";
					}
				}
			}
		}
	}
}
//////////////////////////////////////////////////
// 功能: 创建颜色选取面板
// 参数: okFunc - 需要执行的函数
// 返回: sColor - 色值(okFunc的参数)
//////////////////////////////////////////////////
function CrateColorBar(okFunc)
{
	DestroyObj($$("IDH_Editor_ColorBar"));
	
	var oColorBar = document.createElement("dl");
	oColorBar.id = "IDH_Editor_ColorBar";
	oColorBar.className = "editor_color_bar";
	oColorBar.oncontextmenu = function(){ return false };

	var oEl = document.documentElement;
	
	oColorBar.style.top = (event.clientY + oEl.scrollTop - 5) + "px";
	oColorBar.style.left = (event.clientX + oEl.scrollLeft -5) + "px";
	
	document.body.appendChild(oColorBar);
	
	//为oColorBar添加一个group属性
	var nnm = oColorBar.attributes;
	var namedItem = document.createAttribute("group");
	namedItem.value = "NH_SelectColor";
	nnm.setNamedItem(namedItem);
	
	var sHtml = "<dd group=\"NH_SelectColor\" style=\"background-color: #FF6666\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #FF9966\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #FFFF66\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #66FF66\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #99FFFF\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #6666FF\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #FF66FF\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #FFFFFF\" ><\/dd>";
	
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #FF0000\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #FF6600\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #FFFF00\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #00FF00\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #00FFFF\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #0000FF\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #FF00FF\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #CCCCCC\" ><\/dd>";
	
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #CC0000\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #CC6600\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #CCCC00\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #00CC00\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #00CCCC\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #0000CC\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #CC00CC\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #999999\" ><\/dd>";
	
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #990000\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #996600\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #999900\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #009900\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #009999\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #000099\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #990099\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #666666\" ><\/dd>";
	
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #660000\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #663300\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #666600\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #006600\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #006666\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #000066\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #660066\" ><\/dd>";
	sHtml += "<dd group=\"NH_SelectColor\" style=\"background-color: #000000\" ><\/dd>";
	
	sHtml += "<dt group=\"NH_SelectColor\" id=\"IDC_Editor_ColorBar_View\">";
	sHtml += "<input group=\"NH_SelectColor\" id=\"IDC_Editor_ColorBar_Value\" type=\"text\" size=\"6\" maxlength=\"7\" \/>";
	sHtml += "<\/dt>";
	
	oColorBar.innerHTML = sHtml;
	
	oColorBar.onmouseout = GetColor;
	var oView = $$("IDC_Editor_ColorBar_View"), oInput = $$("IDC_Editor_ColorBar_Value");
	var oElement, sColor, nTime;

	function GetColor()
	{
		//获取鼠标指向的对象
		//如果出错,停止获取并销毁面板(切换窗口时遇到)
		try
		{
			oElement = document.elementFromPoint(event.clientX, event.clientY);
			sColor = oElement.style.backgroundColor;
		}
		catch (ex)
		{
			DestroyObj(oColorBar);
			oColorBar.onmouseout = null;
			return;
		}
	
		//鼠标离开选择面板500毫秒后摧毁该面板
		if (oElement.getAttribute("group") != "NH_SelectColor")
		{
			nTime = setTimeout("DestroyObj($$('" + oColorBar.id + "'))", 500);
		}
		else
		{
			clearTimeout(nTime);
		}
		//对象为色块
		if (oElement.tagName == "DD")
		{
			oInput.value = oElement.style.backgroundColor;
			//单击鼠标指向的元素
			oElement.onclick = function()
			{
				eval(okFunc);
				DestroyObj(oColorBar);
			}
		}
		//预览块
		if (oElement.tagName == "DT")
		{
			//单击鼠标指向的元素
			oElement.ondblclick = function()
			{
				if (oElement.tagName != "INPUT")
				{
					eval(okFunc);
					DestroyObj(oColorBar);
				}
			}
		}
		//输入值
		if (oElement.tagName == "INPUT")
		{
			oElement.onkeyup = function()
			{
				if (event.keyCode == 13)
				{
					SetColor();
					eval(okFunc);
					DestroyObj(oColorBar);
				}
			}
		}
		SetColor();
		//设置颜色
		function SetColor()
		{
			try
			{
				oView.style.backgroundColor = oInput.value;
			}
			catch(e)
			{
				oView.style.backgroundColor = "#000000";
				oInput.value = oView.style.backgroundColor;
			}
			sColor = oView.style.backgroundColor;
		}
	}
}
//让Firefox和IE兼容
function RescriptFirefox()
{
	if(!document.all)   
	{
		//重写outerHTML
		HTMLElement.prototype.__defineGetter__("outerHTML",
			function()
			{
				var a = this.attributes, str = "<" + this.tagName;
				for (var i = 0; i < a.length; i++)
				{
					if (a[i].specified)
					{
						str += " " + a[i].name + '="' + a[i].value + '"';
					}
				}
				if (!this.canHaveChildren)
				{
					return str + " />";
				}

				return str + ">" + this.innerHTML + "</" + this.tagName + ">";
			}
		);
		HTMLElement.prototype.__defineSetter__("outerHTML",
			function(s)
			{
				var d = document.createElement("DIV");
				d.innerHTML = s;
				for (var i = 0; i < d.childNodes.length; i++)
				{
					this.parentNode.insertBefore(d.childNodes[i],   this);
				}
				this.parentNode.removeChild(this);
			}
		);
		HTMLElement.prototype.__defineGetter__("canHaveChildren",
			function()
			{
				return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/.test(this.tagName.toLowerCase());
			}
		);
		//重写innerText
		HTMLElement.prototype.__defineGetter__("innerText", 
		function()
		{
			var anyString = "";
			var childS = this.childNodes;
			for (var i = 0; i < childS.length; i++)
			{
				if (childS[i].nodeType == 1)
					anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText;
				else if(childS[i].nodeType==3)
					anyString += childS[i].nodeValue;
			}
			return anyString;
		}
		); 
		HTMLElement.prototype.__defineSetter__(     "innerText", 
		function(sText){
			this.textContent = sText; 
		}
		);
		//重写Event
		window.constructor.prototype.__defineGetter__("event",function(){
                var func = arguments.callee.caller;
                while(func != null){
                        var arg0 = func.arguments[0];
                        if(arg0 && (arg0.constructor==Event || arg0.constructor ==MouseEvent)){
                                return arg0;
                        }
                        func = func.caller;
                }
            return null;
        });
//        Event.prototype.__defineGetter__("fromElement",   function   ()   {   
//          var   node;   
//          if   (this.type   ==   "mouseover")   
//              node   =   this.relatedTarget;   
//          else   if   (this.type   ==   "mouseout")   
//              node   =   this.target;   
//          if   (!node)   return;   
//          while   (node.nodeType   !=   1)   node   =   node.parentNode;   
//          return   node;   
//      });   
//      Event.prototype.__defineGetter__("toElement",   function   ()   {   
//          var   node;   
//          if   (this.type   ==   "mouseout")   
//              node   =   this.relatedTarget;   
//          else   if   (this.type   ==   "mouseover")   
//              node   =   this.target;   
//          if   (!node)   return;   
//          while   (node.nodeType   !=   1)   node   =   node.parentNode;   
//          return   node;   
//      });
	}
}
RescriptFirefox();