﻿// JScript 檔
///Class代號：      MessageBox
///Class名稱：      讀取MessageBox.xml文件信息
///程式說明:     　 從MessageBox.xml文件中循環讀取符合要求的信息
///xx.YYYY/MM/DD    VER     AUTHOR       COMMENTS(說明修改的內容)  
///1.2008/3/18       1.00    Nio        CREATE 

function ShowInfo(strCode,strPara)
{
    try
    {
        if(strPara==undefined) strPara='';
        var messageStr = getMsg(strCode,strPara);
        document.getElementById("o_PopupWintitleEl").innerHTML="系統訊息";//抓取提示窗口的標頭ID  
        document.getElementById("o_PopupWinaCnt").innerHTML=messageStr;//抓取提示窗口的顯示內容的超鏈接ID 
        ErrorColor();
        PopupWin1espopup_ShowPopup1();
    } catch(oc)
    {
        if(document.getElementById("o_PopupWintitleEl")!=null)
        document.getElementById("o_PopupWintitleEl").style.display="none";
        if(document.getElementById("o_PopupWinaCnt")!=null)
        document.getElementById("o_PopupWinaCnt").style.display="none";
    }
    return false;
}

function ShowError(strCode,strPara,strLanguage)
{
    try
    {
        if(strPara==undefined) strPara='';
        var messageStr = getMsg(strCode,strPara,strLanguage);
        var messageStr2 = getMsg(strPara,strCode,strLanguage);
        document.getElementById("o_PopupWintitleEl").innerHTML=messageStr2;//抓取提示窗口的標頭ID  
        document.getElementById("o_PopupWinaCnt").innerHTML=messageStr;//抓取提示窗口的顯示內容的超鏈接ID 
        ErrorColor();
        PopupWin1espopup_ShowPopup1();
    } catch(oc)
    {
        if(document.getElementById("o_PopupWintitleEl")!=null)
        document.getElementById("o_PopupWintitleEl").style.display="none";
        if(document.getElementById("o_PopupWinaCnt")!=null)
        document.getElementById("o_PopupWinaCnt").style.display="none";
    }
    return false;
}
function ShowOk(strCode,strPara,strLanguage)
{
    try
    {
        if(strPara==undefined) strPara='';
        var messageStr = getMsg(strCode,strPara,strLanguage);
        var messageStr2 = getMsg(strPara,strCode,strLanguage);
        document.getElementById("o_PopupWintitleEl").innerHTML=messageStr2;//抓取提示窗口的標頭ID  
        document.getElementById("o_PopupWinaCnt").innerHTML=messageStr;//抓取提示窗口的顯示內容的超鏈接ID  
        OkColor();
        PopupWin1espopup_ShowPopup1();
     } catch(oc)
    {
        if(document.getElementById("o_PopupWintitleEl")!=null)
            document.getElementById("o_PopupWintitleEl").style.display="none";
        if(document.getElementById("o_PopupWinaCnt")!=null)
            document.getElementById("o_PopupWinaCnt").style.display="none";
    } 
    return false;
}
function PopupWin1espopup_ShowPopup1(show)
{
  //if (PopupWin1dxTimer!=-1) { el.filters.blendTrans.stop(); }
//o_PopupWintmrHide
  if ((o_PopupWintmrHide!=-1) && ((show!=null) && (show==o_PopupWinshowBy)))
  {
    clearInterval(o_PopupWintmrHide);
    o_PopupWintmrHide=setInterval(o_PopupWinespopup_tmrHideTimer,o_PopupWinhideAfter);
    return;
  }
  if (o_PopupWintmrId!=-1) return;
  o_PopupWinshowBy=show;

  elCnt=document.getElementById('o_PopupWin_content')
  elTit=document.getElementById('o_PopupWin_header');
  el=document.getElementById('o_PopupWin');
  el.style.left=o_PopupWinoldLeft==null?"":o_PopupWinoldLeft;
  el.style.top='';
  el.style.filter='';

  if (o_PopupWintmrHide!=-1) clearInterval(o_PopupWintmrHide); o_PopupWintmrHide=-1;

  document.getElementById('o_PopupWin_header').style.display='none';
  document.getElementById('o_PopupWin_content').style.display='none';

  if (navigator.userAgent.indexOf('Opera')!=-1)
    el.style.bottom=(document.body.scrollHeight*1-document.body.scrollTop*1
                    -document.body.offsetHeight*1+1*o_PopupWinpopupBottom)+'px';
  
  if (o_PopupWinbChangeTexts)
  {
    o_PopupWinbChangeTexts=false;
    document.getElementById('o_PopupWinaCnt').innerHTML=o_PopupWinnMsg;
    document.getElementById('o_PopupWintitleEl').innerHTML=o_PopupWinnTitle;
  }

  o_PopupWinactualHgt=0; el.style.height=o_PopupWinactualHgt+'px';
  el.style.visibility='';
  if (!o_PopupWinresetTimer) el.style.display='';
  o_PopupWintmrId=setInterval(o_PopupWinespopup_tmrTimer,(o_PopupWinresetTimer?1000:20));
}
        /*

當提示為成功時改變MSN的顏色
*/
function OkColor()
{
     document.getElementById("o_PopupWin").style.cssText = '';
    document.all.o_PopupWin.style.backgroundColor = '#E0E9F8';
    document.all.o_PopupWin.style.borderRight = '1px solid #455690';
    document.all.o_PopupWin.style.borderBottom='1px solid #455690';
    document.all.o_PopupWin.style.borderLeft='1px solid #B9C9EF';
    document.all.o_PopupWin.style.borderTop='1px solid #B9C9EF';
    document.all.o_PopupWin.style.position='absolute';
    document.all.o_PopupWin.style.zindex='9999';
    document.all.o_PopupWin.style.width='200px';
    document.all.o_PopupWin.style.height='100px';
    document.all.o_PopupWin.style.right='15px';
    document.all.o_PopupWin.style.bottom='15px';
 
    document.getElementById("o_PopupWin_header").style.cssText = '';
    document.getElementById("o_PopupWin_header").style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#FFE0E9F8', EndColorStr='#FFFFFFFF')";
    document.getElementById("o_PopupWin_header").style.cursor='default';
    document.getElementById("o_PopupWin_header").style.position='absolute'
    document.getElementById("o_PopupWin_header").style.left='2px';
    document.getElementById("o_PopupWin_header").style.width='194px';
    document.getElementById("o_PopupWin_header").style.top='2px';
    document.getElementById("o_PopupWin_header").style.height='14px';
    document.getElementById("o_PopupWin_header").style.font='12px arial,sans-serif';
    document.getElementById("o_PopupWin_header").style.color='#1F336B';
    document.getElementById("o_PopupWin_header").style.textDecoration='none';

    
    document.getElementById("o_PopupWin_content").style.cssText = '';
    document.getElementById("o_PopupWin_content").style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#FFE0E9F8', EndColorStr='#FFFFFFFF')";
     document.getElementById("o_PopupWin_content").style.borderLeft='1px solid #728EB8';
     document.getElementById("o_PopupWin_content").style.borderTop='1px solid #728EB8';
     document.getElementById("o_PopupWin_content").style.borderBottom='1px solid #B9C9EF';
     document.getElementById("o_PopupWin_content").style.borderRight='1px solid #B9C9EF';
     document.getElementById("o_PopupWin_content").style.background='#E0E9F8';
     document.getElementById("o_PopupWin_content").style.padding='2px';
     document.getElementById("o_PopupWin_content").style.overflow='hidden';
     document.getElementById("o_PopupWin_content").style.textAlign='center';
     document.getElementById("o_PopupWin_content").style.position='absolute';
     document.getElementById("o_PopupWin_content").style.left='2px';
     document.getElementById("o_PopupWin_content").style.width='194px';
     document.getElementById("o_PopupWin_content").style.top='20px';
     document.getElementById("o_PopupWin_content").style.height='76px';
}
/*
當提示為錯天時改變MSN的顏色
*/
function ErrorColor()
{
    document.getElementById("o_PopupWin").style.cssText = '';
    document.all.o_PopupWin.style.backgroundColor = '#DCC8C8';
    document.all.o_PopupWin.style.borderRight = '1px solid #800000';
    document.all.o_PopupWin.style.borderBottom='1px solid #800000';
    document.all.o_PopupWin.style.borderLeft='1px solid #C8AAAA';
    document.all.o_PopupWin.style.borderTop='1px solid #C8AAAA';
    document.all.o_PopupWin.style.position='absolute';
    document.all.o_PopupWin.style.zindex='9999';
    document.all.o_PopupWin.style.width='200px';
    document.all.o_PopupWin.style.height='100px';
    document.all.o_PopupWin.style.right='15px';
    document.all.o_PopupWin.style.bottom='15px';
 
    document.getElementById("o_PopupWin_header").style.cssText = '';
    document.getElementById("o_PopupWin_header").style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#FFDCC8C8', EndColorStr='#FFFFFFFF')";
    document.getElementById("o_PopupWin_header").style.cursor='default';//
    document.getElementById("o_PopupWin_header").style.position='absolute'
    document.getElementById("o_PopupWin_header").style.left='2px';
    document.getElementById("o_PopupWin_header").style.width='194px';
    document.getElementById("o_PopupWin_header").style.top='2px';
    document.getElementById("o_PopupWin_header").style.height='14px';
    document.getElementById("o_PopupWin_header").style.font='12px arial,sans-serif';
    document.getElementById("o_PopupWin_header").style.color='#400000';
    document.getElementById("o_PopupWin_header").style.textDecoration='none';

    
    document.getElementById("o_PopupWin_content").style.cssText = '';
    document.getElementById("o_PopupWin_content").style.filter = "progid:DXImageTransform.Microsoft.Gradient(GradientType=0,StartColorStr='#FFDCC8C8', EndColorStr='#FFFFFFFF')";
     document.getElementById("o_PopupWin_content").style.borderLeft='1px solid #A05A5A';
     document.getElementById("o_PopupWin_content").style.borderTop='1px solid #A05A5A';
     document.getElementById("o_PopupWin_content").style.borderBottom='1px solid #C8AAAA';
     document.getElementById("o_PopupWin_content").style.borderRight='1px solid #C8AAAA';
     document.getElementById("o_PopupWin_content").style.background='#DCC8C8';
     document.getElementById("o_PopupWin_content").style.padding='2px';
     document.getElementById("o_PopupWin_content").style.overflow='hidden';
     document.getElementById("o_PopupWin_content").style.textAlign='center';
     document.getElementById("o_PopupWin_content").style.position='absolute';
     document.getElementById("o_PopupWin_content").style.left='2px';
     document.getElementById("o_PopupWin_content").style.width='194px';
     document.getElementById("o_PopupWin_content").style.top='20px';
     document.getElementById("o_PopupWin_content").style.height='76px';
}


// JScript 檔
//---------------------------------------------------------------------[在頁面上彈出信息提示] (函數)
//Author        ：Nio
//Last Modifiy  ：2008/03/18
function Show(strCode,StrPara,strLanguage)
{
   var msg=getMsg(strCode,StrPara,strLanguage);
   alert(msg);

}

//---------------------------------------------------------------------[給指定的Web控件,彈出確認框信息提示] (函數)
//Author        ：Nio
//Last Modifiy  ：2008/03/18
function ShowConfirm(strCode,StrPara,strLanguage)
{
   var msg=getMsg(strCode,StrPara,strLanguage);
   return  confirm(msg);
}
//---------------------------------------------------------------------[彈出信息提示,並轉向指的頁面] (函數)
//Author        ：Nio
//Last Modifiy  ：2008/03/18
function ShowAndRedirect(strCode,StrPara,url,strLanguage)
{
	 var msg=getMsg(strCode,StrPara,strLanguage);
	 alert(msg);
	 self.location.href=url;

}

//---------------------------------------------------------------------[彈出信息提示,並轉向指的頁面] (函數)
//Author        ：Nio
//Last Modifiy  ：2008/03/18
function ShowAndRedirectTop(strCode,StrPara,url,strLanguage)
{
	 var msg=getMsg(strCode,StrPara,strLanguage);
	 alert(msg);
	 window.parent.location.href=url;

}

function getXMLHTML()
{

        //alert("dfsdfsdf");
    var objXMLHTML;
     if (window.ActiveXObject)
    {
          var arrSignatures = ["MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0",
                               "MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument",
                               "Microsoft.XmlDom"];
                         
          for (var i=0; i < arrSignatures.length; i++) {
              try {
        
                  objXMLHTML = new ActiveXObject(arrSignatures[i]);
                  //oDoc.async="false";
       
              } catch (oError) {
                  //ignore
              }
          }          

     }
    else
    {
        if (document.implementation && document.implementation.createDocument)
        {
             objXMLHTML = document.implementation.createDocument("","",null);             
        }
    }
    return objXMLHTML;
}


//*****************************************************
//* 函數名稱: getMsg
//* 目    的: 將訊息return給頁面
//* 參    數: s_MsgCode(訊息ID)
//* 範    例: getMsg('000000')
//*****************************************************
function getMsg(s_MsgCode,strPara,strLanguage)
{
    var k = strLanguage.split('-')[1];
        
    var oDoc = getXMLHTML();
    
    var result = "Data/Message.xml";
    oDoc.async=false;
    oDoc.load(result);
    var root=oDoc.documentElement;
       // alert("11111111111111111");
    if(root==null)
    {
        var result ="../Data/Message.xml";
        oDoc.async=false;
        oDoc.load(result);
        var root=oDoc.documentElement;
        if(root==null)
        {
            var result ="../../Data/Message.xml";
            oDoc.async=false;
            oDoc.load(result);
            var root=oDoc.documentElement;
             if(root==null)
            {
                var result ="../../../Data/Message.xml";
                oDoc.async=false;
                oDoc.load(result);
                var root=oDoc.documentElement;
            }
        }
    }
        //alert("2222222222222222222222");
    if (root==null) return "Error";
    //alert(root.selectSingleNode("/MessageSettingConfig/MessageContent[MsgID='" + s_MsgCode + "']/tw").text);

     return(RePlace(root.selectSingleNode("/MessageSettingConfig/MessageContent[MsgID='" + s_MsgCode + "']/"+k).text,strPara));

//    var i; 
//    for(i=0;i<root.childNodes.length;i++)
//    {     
//        alert("33333333333333333333333");
//        alert(root);
//        alert(root.childNodes[i]);
//        alert(root.childNodes[i].id);
//        alert(root.childNodes[i].type);
//        if(root.childNodes[i].childNodes[0].text==s_MsgCode)
//        {
//           if(root.childNodes[i].childNodes[k].text.length>0)
//           {
//              if(strPara==null||strPara==""||strPara=="undefine")
//                  return root.childNodes[i].childNodes[k].text
//              else            
//              return(RePlace(root.childNodes[i].childNodes[k].text,strPara));
//           }
//           else
//           {
//            return "ID"+s_MsgCode+", Message  value not find";
//           }
//          
//        }
//    }
   return "ID"+s_MsgCode+",Message  value not find";
}



function RePlace(Strss,Str)
{
   var vntArray=Str.split(';');
		for(var i=0;i<vntArray.length;i++){
		    var strRepl ='{'+ i +'}' ;
			var intPos = Strss.indexOf(strRepl);
			if(intPos!=-1){
				Strss = Strss.replace(strRepl, vntArray[i]);
			}
		}
		return Strss;
}


// check for XPath implementation
if( document.implementation.hasFeature("XPath", "3.0") )
{ Element.prototype.__defineGetter__("text",function(){ return this.textContent; });
   // prototying the XMLDocument
   XMLDocument.prototype.selectNodes = function(cXPathString, xNode)
   {
      if( !xNode ) { xNode = this; } 
      var oNSResolver = this.createNSResolver(this.documentElement)
      var aItems = this.evaluate(cXPathString, xNode, oNSResolver, 
                   XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)

      var aResult = [];
      for( var i = 0; i < aItems.snapshotLength; i++)
      {
         aResult[i] =  aItems.snapshotItem(i);
      }
      return aResult;
   }

   // prototying the Element
   Element.prototype.selectNodes = function(cXPathString)
   {//alert('ff4');
      if(this.ownerDocument.selectNodes)
      {
         return this.ownerDocument.selectNodes(cXPathString, this);
      }
      else{throw "For XML Elements Only";}
   }
}


// check for XPath implementation
if( document.implementation.hasFeature("XPath", "3.0") )
{
   // prototying the XMLDocument
   XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode)
   {//alert('ff2');
      if( !xNode ) { xNode = this; } 
      var xItems = this.selectNodes(cXPathString, xNode);
   //   alert(xItems[0]);
      if( xItems.length > 0 )
      {
         return xItems[0];
      }
      else
      {
         return null;
      }
   }
   
   // prototying the Element
   Element.prototype.selectSingleNode = function(cXPathString)
   {   
      if(this.ownerDocument.selectSingleNode)
      {
         return this.ownerDocument.selectSingleNode(cXPathString, this);
      }
      else{throw "For XML Elements Only";}
   }
}
