﻿//建立xmlDocument对象
function createDomDocument(xml)
{
	var xmlData;
	try
	{
		xmlData = new ActiveXObject("Msxml2.DOMDocument");
	}
	catch(e)
	{
		xmlData = ActiveXObject("Msxml.DOMDocument");
	}
	xmlData.async = false;
	xmlData.loadXML(xml);
	
	return xmlData;
}

/*使用xmlhttp方式已同步方式向服务端请求数据*/
function ajexSubmit(type,pams)
{
    var xmlhttp = createXMLHttpRequest();
    xmlhttp.open("GET", "/WebApp/BDQS/Services/AjexServices.aspx?TN=" + type + "&P="+ escape(pams) + "&R=" + Math.round(Math.random()*10000).toString(), false);
    xmlhttp.send();
    
    return xmlhttp.responseText;
}
	
function createXMLHttpRequest()
{ 
    var obj = null; 
    try 
    { 
        obj = new ActiveXObject('Msxml2.XMLHTTP'); 
    }
    catch(e) 
    { 
        try
        {
            obj = new ActiveXObject('Microsoft.XMLHTTP');
        } 
        catch(oc) 
        {
            obj = null
        } 
    } 
    if (!obj && typeof XMLHttpRequest != 'undefined') { 
        obj = new XMLHttpRequest();
    } 
    
    return obj; 
}
/***************/

/*用javascript对Coolie进行读写Begin*/
//获得Cookie解码后的值
function GetCookieVal(offset)
{
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
    endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

//设定Cookie值
function SetCookie(name, value)
{
    var expdate = new Date();
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
        document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
        +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
        +((secure == true) ? "; secure" : "");
}

//删除Cookie
function DelCookie(name)
{
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie (name);
    document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}

//获得Cookie的原始值
function GetCookie(name)
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        return GetCookieVal (j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}
/*用javascript对Coolie进行读写End*/

/*以对话框或窗口方式来打开自窗口Begin*/
var frameVirPath = "/WebApp/BDQS/Content.aspx";//从站点主目录引导的路径

function openDialogModule(type,module,inObj,height,width)
{
    var ranValue = parseInt(Math.random()*1000000);
    var reV;
    if (inObj != null)
	{
		reV = window.showModalDialog(frameVirPath + "?TN="+ type +"&K="+ module +"&P=" + escape(inObj.toString()) + "&R=" + ranValue,"","dialogWidth:"+ width +";dialogHeight:"+ height + ";resizable=yes;scrollbars=auto;");
	}
	else
	{
		reV = window.showModalDialog(frameVirPath + "?TN="+ type +"&K="+ module + "&R=" + ranValue,"","dialogWidth:"+ width +";dialogHeight:"+ height +";resizable=yes;scrollbars=auto;");
	}
	return reV;
}

function openDialogPage(url,height,width)
{
    return window.showModalDialog(url,"","dialogWidth:"+ width +";dialogHeight:"+ height +";resizable=yes;scrollbars=auto;");
}

function openWindowModule(type,module,inObj,height,width)
{
    var feature = "height="+height+",width="+width+",status=no,toolbar=no,menubar=no,center=yes,location=no,resizable=yes,scrollbars=yes";
	var screenHeight = window.screen.height;
	var screenWidth = window.screen.width;
	var tempHeight = height.replace("px","");
	var tempWidth = width.replace("px","");
	
	tempTop = (screenHeight - tempHeight) / 2;
	tempTop = tempTop * 0.8;
	tempLeft = (screenWidth - tempWidth) / 2;
	feature += ",top=" + tempTop + "px,left=" + tempLeft + "px";

	if (feature == "")
		feature = "height=600px,width=1000px,status=no,toolbar=no,menubar=no,center=yes,location=no,resizable=yes,scrollbars=yes";
		
    var url = frameVirPath + "?TN="+ type +"&K="+ module +"&P=" + escape(inObj.toString());
    window.open(url,'_blank',feature);
}

function openWindowPage(url,height,width)
{
    var feature = "height="+height+",width="+width+",status=no,toolbar=no,menubar=no,center=yes,location=no,resizable=yes,scrollbars=yes";
	var screenHeight = window.screen.height;
	var screenWidth = window.screen.width;
	var tempHeight = height.replace("px","");
	var tempWidth = width.replace("px","");
	
	tempTop = (screenHeight - tempHeight) / 2;
	tempTop = tempTop * 0.8;
	tempLeft = (screenWidth - tempWidth) / 2;
	feature += ",top=" + tempTop + "px,left=" + tempLeft + "px";

	if (feature == "")
		feature = "height=600px,width=1000px,status=no,toolbar=no,menubar=no,center=yes,location=no,resizable=yes,scrollbars=yes";
		
	window.open(url,'_blank',feature);
	
}
/*以对话框或窗口方式来打开自窗口End*/
function showOperationDetail(url)
{
    openWindowPage(url,"600px","750px");
}

//打开一个编码方式选择的对话框
function showEncodingChoiceDialog(userID)
{
    var reV = openDialogModule("Common","ExportEncodingChoice",userID,"180px","370px");
    if (reV == "1")
        return true;
    return false;
}

//显示Loading进度条的方法
var loadingTimer = 0;
function showLoadingContent(btn,text)
{
    try
    {
        loadingTimer = 0;
        if (btn != null)
            btn.disabled = true;
        setInterval("drawingLoadingTable('"+ text +"')",10); 
    }
    catch (e){alert(e);}
}

function drawingLoadingTable(text)
{
    var lineleft = 0;
    var lineright = 350 - (loadingTimer * 1);
    var linewidth = loadingTimer * 1;
    loadingTimer++;
    if (loadingTimer == 350)
        loadingTimer = 0;
    var tableHtml = "<table width='100%' height='100%'><tr><td bgcolor='#FFFFFF' align='center' valign='middle'><table width='300px' cellpadding='0' cellspacing='0' border='0' bgcolor='#FFFFFF'><tr><td width='"+ lineleft +"px' height='10px'></td><td width='"+ linewidth +"px' bgcolor='#1B61BC'></td><td width='"+ lineright +"px'></td></tr><tr><td colspan='3'  height='40px' align='center'><b>"+ text +"</b></td></tr></table></td></tr></table>";

    var width = document.body.clientWidth;
    var imgWidth = 350
    var left = (width - imgWidth) / 2 ;
    var top = 250;
    var loadingDiv = "<div id='loadingDiv' style='filter:alpha(opacity=80);Z-INDEX:101;visibility:visible;POSITION:absolute; left:0px;top:0px;width:100%;height:100%;'>"+ tableHtml +"</div>";

    loadingSpan.innerHTML = loadingDiv;
}

function closeLoading()
{
    loadingSpan.innerHTML = "";
}

    //网页内按下回车触发
function document.onkeydown()
{ 
    try
    {
        if(event.keyCode==13)
        {
            document.getElementById("btnSearch").click();   
            return false;                               
        }
    }
    catch(e)
    {
    }
}

function changeClassHover()
{
	var vobj = getOwnerTR(window.event.srcElement);

	if (vobj)
		setTRStyle(vobj);
}

function changeClassMoveOut()
{
	var vobj = getOwnerTR(window.event.srcElement);

	if (vobj)
		resetTRStyle(vobj);
}

function resetTRStyle(vobj)
{
	if (vobj.className != "gridSelectedHighlight")
		vobj.className = vobj.oldClassName;
}

function setTRStyle(vobj)
{
	if (vobj.className != "gridSelectedHighlight")
	{
		vobj.oldClassName = vobj.className;
		vobj.className = "gridHighlight";

		if (vobj.callFunc)
			vobj.callFunc("onMouseOverRow", vobj);
	}
}

function getOwnerTR(element)
{
	while (element && element.tagName.toUpperCase() != "TR")//行 TD单元格 TH表头
	{
		element = element.parentNode;

		if (element == null)
			break;
	}

	return element;
}
