﻿// JScript 文件

// JavaScript Document
// 返回XML文档
var __bIsCallBack = true;
var __bIsIE = false;
var __nDx = 0;
var __nDy = 0;

var __oWaitMessage = null;
var __nWaitTimeID  = 0;

var __xmlHttp       = null;
var __fnCallBack    = null;
var __fnArray       = new Array();
var __nWaitCallBack = 0;
var stroldFnName = null;
var __oBodyObjToPopup = null;

function $(id)
{
	return document.getElementById(id);
}

function __fnGetRequestString(strName)
{
    if(typeof(strName) == "string" && strName.length > 0)
    {
        strName = strName.toLowerCase();
        var tempLocation = window.location.href.toLowerCase();
        var _index = tempLocation.indexOf("?");
        if(_index > -1)
        {
            tempLocation = tempLocation.substring(_index + 1);
        }
        var requestArray = tempLocation.split("&");
        var nLength = strName.length + 1;
        for(var i=0; i<requestArray.length; i++)
        {
            if((requestArray[i].length > nLength) && requestArray[i].substring(0, nLength) == (strName + "="))
            {
                return unescape(requestArray[i].substring(nLength));
            }
        }
        return "";
    }
    else
    {
        return "";
    }
}

function ImportScript(uri, sync, callback)
{
  if(sync)
  {
    document.write('<script type="text/javascript" src="' + encodeURI(uri) + '"></script>');
  }
  else {
    var s = document.getElementsByTagName("head").appendChild(document.createElement("script"));
    s.type = "text/javascript";
    s.src = uri;
    s.onload = callback;
  }
}

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);
	}
	tempXmlDoc.async = false;
	return tempXmlDoc;
}


if(window.ActiveXObject)
{
    __bIsIE = true;
}

//得到所有节点
function GetNodesByPath(strXml, strPath)
{
    var xmldoc = GetXmlDocByXml(strXml);
    if(xmldoc.hasChildNodes && xmldoc.documentElement.hasChildNodes)
    {
        return __fnGetXmlList(xmldoc.documentElement, strPath);
    }
    else
    {
        return null;
    }
}

//得到XML加载strXML,返回 xml文档
function GetXmlDocByXml(strXML)
{
    var xmlDoc = NewXmlDoc();
    if(typeof(strXML) == "string" && strXML.length > 0)
    {
        if(__bIsIE)
        {
            xmlDoc.loadXML(strXML);
        }
        else
        {
            var dp = new DOMParser();
			xmlDoc = dp.parseFromString(strXML, "text/xml");
			//alert(xmlDoc.documentElement.childNodes.length);
        }
    }
    return xmlDoc;
}

//得到节点下所有附合节点名的节点
function __fnGetXmlList(node, strPath)
{
    if(node != null && node.hasChildNodes)
	{
	    var oList = null;
	    var nLen  = 0;
	    if(__bIsIE)
	    {
		    oList = node.selectNodes(strPath);
	    }
	    else
	    {
    	    
	        oList = new Array(node.childNodes.length);
	        for(var i=0; i<node.childNodes.length; i++)
	        {
		        if(node.childNodes[i].nodeName == strPath)
		        {
			        oList[nLen] = node.childNodes[i];
			        nLen++;
		        }
	        }
	        oList.length = nLen;
	    }
	    return oList;
	}
	else
	{
	    return null;
	}
}


//显示等待信息 处理大数据时使用
//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 = "正在处理中...";
		}
	}
}


//替换表单特殊字符
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] != null  && typeof(obj.elements[i].type) != 'undefined' && obj.elements[i].type.toLowerCase().indexOf("text") > -1)
			{
				obj.elements[i].value = obj.elements[i].value.replace(/['<>`\"]/g, "");
				obj.elements[i].value = obj.elements[i].value.replace(/^\s{0,}|\s{0,}$/g, "");
				obj.elements[i].value = obj.elements[i].value.replace(/(我靠|我日|我操|操你|你妈|fuck|FUCK|bitch|他妈的|性爱|法\s{0,}轮\s{0,}功|法\s{0,}轮|falundafa|falun|江泽民|操你妈|三级片|普光网络|月赚千元)/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 OpenModalDialog(sUrl, sTitle, nWidth, nHeight, InParams, __fnCallBack)
{
    if(typeof(strPath) == "string")
    {
        sUrl 
    }
	var vVariables           = new Array();
	vVariables["InParam"]    = InParams;
	vVariables["DialogURL"]  = sUrl;
	vVariables["WindowHand"] = window;
	vVariables["FnCallBack"] = __fnCallBack;
	nWidth                   = parseInt(nWidth)  + 20;
	if(__bIsIE)
	{
	    nHeight = parseInt(nHeight) + 20;
	}
	var sFeatures = null;
	if(__bIsIE)
	{
	    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);
	}
	else
	{
	    sFeatures = 'width='+ nWidth.toString() +', height='+ nHeight.toString() +', scroll=no, status=no, resizable=no, center=yes,modal=yes';
	    window.open(sUrl, 'newWin', 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 fnGetEvent(e)
{
    var eve = null;
    if(e == null)
    {
        eve = __bIsIE ? window.event : fnSearchEvent();
    }
    else
    {
        eve = e;
    }
    return eve;
}

function Cookie()
{
	this.SetValue=function(name, value, year, dateType, path, secure)
	{
		var sDomain = null;
		var str= name + "=" + escape(value);
		if(typeof(year) != "undefined")
		{
		    var nextTime=new Date();
		    if(typeof(dateType) == "number")
		    {
		        switch(dateType)
		        {
		            case 0:
		                nextTime.setSeconds(nextTime.getSeconds() + year);
		                break;
		            case 1:
		                nextTime.setMinutes(nextTime.getMinutes() + year);
		                break;
		            case 2:
		                nextTime.setHours(nextTime.getHours() + year);
		                break;
		            case 3:
		                nextTime.setMonth(nextTime.getMonth() + year);
		                break;
		            default:
		                nextTime.setFullYear(nextTime.getFullYear() + year);
		                break;
		        }
		    }
		    else
		    {
		        nextTime.setDate(nextTime.getDate()+year);
		    }
			str+=";expires="+nextTime.toGMTString();
	    }
		if(path)
		{
			str+=";path="+path;
		}
		else
		{
		    str += ";path=/"
		}
		//str+=";domain="+sDomain;
		if(secure)
			str+=";secure";
		document.cookie = str + ";";
	};
	
	this.GetValue=function(name)
	{
	    var tempArray = document.cookie.split("; ");
	    name = name.toLowerCase();
	    for(var i=0; i<tempArray.length; i++)
	    {
	        if(tempArray[i].toLowerCase().indexOf(name) == 0)
	        {
	            return unescape(tempArray[i].substring(name.length + 1));
	        }
	    }
		//var rs=new RegExp("(^|)"+name+"=([^;]*)(;|$)","gi").exec(document.cookie),tmp;
		//if(tmp=rs)
		//	return unescape(tmp[2]);
		return "";
	};
}

function fnReplaceBadStr(str)
{
	if(str == null)
		return null;
	str = str.replace(/['|&<>`!;#$=\"]/g, "");
	return str.replace(/^\s{1,}|\s{1,}$/g, "").replace(/(我靠|我日|我操|操你|你妈|fuck|FUCK|bitch|他妈的|性爱|法\s{0,}轮\s{0,}功|falundafa|falun|江泽民|操你妈|三级片|普光网络|月赚千元)/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();
	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");
}


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, __fnArray[0][4]);
	}
}

function fnPushWaitArray(sFunctionName, InParams, sURL, fnCallBack, handType)
{
    var tempArray = new Array(5);
    tempArray[0] = sFunctionName;
    tempArray[1] = InParams;
    tempArray[2] = sURL;
    tempArray[3] = fnCallBack;
    tempArray[4] = handType;
    if(__fnArray != null)
    {
        __fnArray.push(tempArray);
	    if(__nWaitCallBack == 0)
	    {
		    __nWaitCallBack = window.setInterval(__fnWaitCallBack, 100);
	    }
	}
}

function fnCallEx(sFunctionName, InParams, sURL, fnCallBack, bState, handType)
{
    if(typeof(__fnArray) != "undefined" && __fnArray != null)
    {
	    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, handType);
		    }
		    return;
	    }
	}
	if(__fnCallBack != null && __fnCallBack != fnCallBack && (typeof(bState) == 'undefined'))
	{
		fnPushWaitArray(sFunctionName, InParams, sURL, fnCallBack, handType);
		return;
	}
	if((typeof(bState) != 'undefined') && bState && __fnCallBack != null)
	{
		return;
	}
	else if(bState)
	{
		if(__fnArray.length > 0)
		{
			__fnArray.shift();
		}
	}
	if(InParams == null)
	{
		InParams = new ParamClass();
	}
	if(__xmlHttp != null)
	{
	    __xmlHttp = null;
	    if(__bIsIE)
	    {
	        CollectGarbage();
	    }
	}
	__xmlHttp = GethttpRequest();
	var handState = typeof(handType) == "boolean" && handType ? fnHandleStateChangeEx : fnHandleStateChange;
	__xmlHttp.onreadystatechange = handState;
	stroldFnName = sFunctionName;
	InParams.__XmlDoc.documentElement.setAttribute("FunctionName", sFunctionName);
	__fnCallBack = fnCallBack;
	__xmlHttp.open("POST", sURL, true);
	__xmlHttp.send(InParams.ToString());
}

Function.prototype.bind = function(obj)
{
	var method = this,
	temp = function() {
	return method.apply(obj, arguments);
	};

	return temp;
}

function RequestXmlHttpEx(xmllist)
{
    xmllist[0].onreadystatechange = fnHandleStateChange.bind(xmllist)
	xmllist[0].open("POST", xmllist[4], true);
	xmllist[0].send(xmllist[3]);
} 

function GethttpRequest() //创建XMLHTTP对像； 
{
	if ( window.XMLHttpRequest )// Gecko
		return new XMLHttpRequest() ;
	else if ( window.ActiveXObject )// IE
		return new ActiveXObject("MsXml2.XmlHttp") ;
}

function fnHandleStateChangeEx()
{
    if(typeof(__xmlHttp) != "undefined" && __xmlHttp != null && __xmlHttp.readyState == 4)
	{
		if(__xmlHttp.status == 200 && __fnCallBack != null)
		{
			__fnCallBack(__xmlHttp.responseText);
		}
		__fnCallBack = null;
	}
}

function fnHandleStateChange()
{
	if(typeof(__xmlHttp) != "undefined" && __xmlHttp != null && __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)
{
    if(__bIsIE)
    {
        CollectGarbage();
    }
	this.ParamDoc = NewXmlDoc();
	this.oNode    = null;
	if(strXML && typeof(strXML) == "string")
	{
		if(window.ActiveXObject && typeof(this.ParamDoc.loadXML) != "undefined")
		{
			if(!this.ParamDoc.loadXML(strXML))
			{
				this.oNode = this.ParamDoc.createElement("Root");
				this.ParamDoc.appendChild(this.oNode);
			}
		}
		else
		{
			var dp = new DOMParser();
			this.ParamDoc = dp.parseFromString(strXML, "text/xml");
		}
	}
	else
	{
		this.oNode = this.ParamDoc.createElement("Root");
		this.ParamDoc.appendChild(this.oNode);
	}
	this.__XmlDoc = this.ParamDoc;
}

//设置节点的值
ParamClass.prototype.SetValue = function(sName, sValue, bIsCDATA)
{
	this.SearchNode(sName);
	if(this.oNode == null)
	{
		this.oNode = this.ParamDoc.createElement("Node");
		this.oNode.setAttribute("ParamName",  sName);
		if(typeof(bIsCDATA) != 'undefined' && bIsCDATA)
		{
			var oCDATE = this.ParamDoc.createCDATASection(sValue);
			this.oNode.appendChild(oCDATE);
		}
		else
		{
			this.oNode.setAttribute("ParamValue", sValue);
		}
		this.ParamDoc.documentElement.appendChild(this.oNode);
	}else
	{
		if(typeof(bIsCDATA) != 'undefined' && bIsCDATA)
		{
			this.oNode.childNodes[0].data = sValue;
		}
		else
		{
			this.oNode.setAttribute("ParamValue", sValue);
		}
	}
}

//得到节点值
ParamClass.prototype.GetValue = function(sName, bIsCDATA)
{
	this.SearchNode(sName);
	if(this.oNode == null)
	{
		return "";
	}
	else
	{
		if(typeof(bIsCDATA) != 'undefined' && bIsCDATA)
		{
			return this.oNode.childNodes[0].data;
		}
		else
		{
			return this.oNode.getAttribute("ParamValue");
		}
	}
}

//返回参数的?形式
ParamClass.prototype.ToParamString = function()
{
	var strParam = "?";
	var root = this.ParamDoc.documentElement;
	for(var i=0; i<root.childNodes.length; i++)
	{
		strParam +=
				 root.childNodes[i].getAttribute("ParamName")
				+ "="
				+ root.childNodes[i].getAttribute("ParamValue")
				+ "&";
	}
	return strParam;
}

//返回参数的XML
ParamClass.prototype.ToString = function()
{
	if(window.ActiveXObject)
	{
		return this.ParamDoc.xml;
	}
	else
	{
		var root = this.ParamDoc.documentElement;
		return serializeXml(root);
	}
}

//搜索节点
ParamClass.prototype.SearchNode = function(sName)
{
	this.oNode = null;
	if(window.ActiveXObject)
	{
		this.oNode = this.ParamDoc.selectSingleNode("//Root/Node[@ParamName='"+ sName +"']");
	}
	else
	{
		var root = this.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)
			{
				this.oNode = root.childNodes[i];
				break;
			}
		}
	}
}

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.toString().lastIndexOf("Event") > -1))
			{
				return __fncall.arguments[i];
			}
		}
		__fncall = __fncall.caller;
	}
	return window.event;
}

function fnResetIframeHeight()
{
	try
	{
	    if(parent.document.getElementById("ifrMain") != null)
	    {
		    parent.document.getElementById("ifrMain").height = document.body.scrollHeight;
		    
	    }
	}
	catch(err)
	{
	}
}

function AttachEvent(obj, sEventName, fnName, bCapture) {
    if (obj == null) {
        return;
    }
	if(obj.addEventListener)
	{
	    var __bCapture = (typeof(bCapture) != "undefined"  && bCapture) ? true : false;
		obj.addEventListener(sEventName, fnName, __bCapture);
	}
	else
	{
		obj.attachEvent("on"+ sEventName, fnName);
	}
}

function DeleteEvent(obj, sEventName, fnName)
{
	if(obj.addEventListener)
	{
		obj.removeEventListener(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 serializeXml(oNode)
{
    var oSerializer = new XMLSerializer();
    return oSerializer.serializeToString(oNode);
}


function __fnGetXmlNodeXml(oNode)
{
    if(oNode != null)
    {
        if(__bIsIE)
        {
            return oNode.xml;
        }
        else
        {
            return serializeXml(oNode);
        }
    }
    else
    {
        return "";
    }
}

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 fnClearLocation()
{
    __nDx = 0;
    __nDy = 0;
}
function fnGetLocation(oObject)
{
	if(oObject != null && typeof(oObject.offsetTop) != "undefined")
	{
		__nDx += parseInt(oObject.offsetLeft);
		__nDy += parseInt(oObject.offsetTop);
		if(typeof(oObject.offsetParent) != "undefined")
		{
			fnGetLocation(oObject.offsetParent);
		}
	}
}

function __fnClearBaseResource()
{
    if(__nWaitTimeID)
    {
        window.clearInterval(__nWaitTimeID);
    }
    __fnArray = null;
}

function __fnSetPageAction()
{
    __oBodyObjToPopup = (document.documentElement && (document.documentElement.clientWidth > 0)) ? document.documentElement : document.body;
	AttachEvent(document, "keydown", fnReSetPage);
}
__fnSetPageAction();