﻿// JScript 文件

//---------------------------------------------------------------------[在页面上弹出信息提示] (函数)
//Author        ：Lanny
//Last Modifiy  ：2009/1/10
function Show(strCode,StrPara)
{
   if(StrPara==undefined) StrPara='';
   var msg=ShowMessage(strCode,StrPara);
   alert(msg);
}
//---------------------------------------------------------------------[給指定的Web控件,弹出确认框信息提示] (函数)
//Author        ：Lanny
//Last Modifiy  ：2009/1/10
function ShowConfirm(strCode,StrPara)
{
    if(StrPara==undefined) StrPara='';
   var msg=ShowMessage(strCode,StrPara);
   if(status=="XML Error!"){
        alert(msg);
        return false
   }
   else{
        return  confirm(msg);
    }
}
//---------------------------------------------------------------------[彈出信息提示,並轉向指的頁面] (函數)
//Author        ：Lanny
//Last Modifiy  ：2007/7/10
function ShowAndRedirect(strCode,StrPara,url)
{
	 var msg=ShowMessage(strCode,StrPara);
	 alert(msg);
	 top.location.href=url;
}
//---------------------------------------------------------------------[彈出信息提示,並轉向指的頁面] (函數)
//Author        ：Lanny
//Last Modifiy  ：2007/7/10
function ShowAndBaseRedirect(strCode,StrPara,url)
{
	 var msg=ShowMessage(strCode,StrPara);
	 alert(msg);
	 window.location.href=url;
}
function ReplMsgDesc(vstrMsg,vstrPara){

		var vntArray=vstrPara.split('$');
		for(var i=0;i<vntArray.length;i++){
		    var strRepl ='{'+ i +'}' ;
			var intPos = vstrMsg.indexOf(strRepl);
			if(intPos!=-1){
				vstrMsg = vstrMsg.replace(strRepl, vntArray[i]);
			}
		}
		return vstrMsg
}

function ShowMessage(strCode,vstrPara)
{
  var strOut;
  try{
        var url = window.location.href;
        if(document.getElementById('hidAdminPort')==null){
            url = 'Data/MessageBox.xml';
        }
        else{
            url = document.location.protocol + "//" + document.location.host + "/" + document.location.pathname.split("/")[1] + '/Data/MessageBox.xml';
        }
        var objxmlDoc = LoadXml(url);  
        if(objxmlDoc==null)
        {
            url = document.location.protocol + "//" + document.location.host + "/" + '/Data/MessageBox.xml';
            objxmlDoc = LoadXml(url);  
        }

        if(typeof(objxmlDoc)=='object'){
            try{
               var objNode = objxmlDoc.selectSingleNode("//message[@id='" + strCode + "']");       
               strOut=ReplMsgDesc(objNode.attributes[1].text,vstrPara);
            }catch(e){
               strOut='沒找到对应消息ID!\n请参见'+url;
            }
        }
    }catch(e){
       strOut='沒找到'+url+'\n请与管理员联系!';
    }
 return strOut;
}
//讀取XML擋
function LoadXml(vstrReq){
//var strReq;				variable to hold request string
	var root, source;		//A couple of XMLDOM objects (document and 
	var sT;
	//Show a searching message
	status = 'searching, please wait....';
	//Create an xml document object, and load the Admin's response
	source = new ActiveXObject('Microsoft.XMLDOM');
	source.async = false;

	//Send the request string and read the result into the XMLDOM object
	source.load(vstrReq);
	//Check to see if there was an error parsing the response from the Admin
	if (source.parseError != 0){
		sT = 'XML Error...\n reason:' + source.parseError.reason + '\n';
		sT += 'errorCode:' + source.parseError.errorCode + '\n';
		sT += 'filepos:' + source.parseError.filepos + '\n';
		sT += 'line:' + source.parseError.line + '\n';
		sT += 'linepos:' + source.parseError.linepos + '\n';
		sT += 'reason:' + source.parseError.reason + '\n';
		sT += 'srcText:' + source.parseError.srcText + '\n';
		sT += '<pre>' + source.xml + '</pre>\n';
		//alert(sT);
		status = 'XML Error!';
		return null;
		}
	else {
		root = source.documentElement;		//Get a reference to root XML object
		status = 'Done';
		return root;}
}