﻿  var openDocObj=null;
//  if(!openDocObj)
//   {

//       // 操作系统必须安装Office和其SharePoint组件才能使用，默认已经安装

//       try{openDocObj = new ActiveXObject("SharePoint.OpenDocuments.3")}catch(e){

//          try{openDocObj = new ActiveXObject("SharePoint.OpenDocuments.2")}catch(e){

//             try{openDocObj = new ActiveXObject("SharePoint.OpenDocuments.1")}catch(e){

//                alert("你没有安装Office组件!");

//             }

//          }

//       }

//   }



//var openDocObj = new ActiveXObject("SharePoint.OpenDocuments.2"); // 为了兼容Office XP，可以创建“SharePoint.OpenDocuments.1” 


//var mStyleFile='../../App_Themes/default/BasicStyle.css';

    var mRootDir=getRootPath()+getVRootDir();
   mRootDir = 'http://www.cfjczx.com';
    
    var mStyleFile=mRootDir+'/App_Themes/default/BasicStyle.css';
    
    if (getIEVersion()=="IE6")
    {
        if (screen.width == 1024 && screen.height == 768)
        {
           mStyleFile=mRootDir+'/App_Themes/IE1024/Style1024.css';
           if (document.getElementsByTagName("link").length>0)
            document.getElementsByTagName("link")[0].href=mStyleFile;
                     
        }
       
        if (screen.width == 1280 && screen.height == 800)
        {
           mStyleFile=mRootDir+'/App_Themes/IE1024/Style1280_800.css';
           if (document.getElementsByTagName("link").length>0)
            document.getElementsByTagName("link")[0].href=mStyleFile;
                     
        }
        
         
        
        if (screen.width == 1152 && screen.height == 864)
        {
            mStyleFile=mRootDir+'/App_Themes/default/BasicStyle.css';
            if (document.getElementsByTagName("link").length>0)
            document.getElementsByTagName("link")[0].href=mStyleFile;
          
        }
    }
    else if (getIEVersion()=="IE7")
    {
        mStyleFile=mRootDir+'/App_Themes/IE7/IE7_Style1024.css';
          if (document.getElementsByTagName("link").length>0)
            document.getElementsByTagName("link")[0].href=mStyleFile;

    }
    else
    {  //IE8
        mStyleFile=mRootDir+'/App_Themes/IE8/IE8_Style1024.css';
          if (document.getElementsByTagName("link").length>0)
            document.getElementsByTagName("link")[0].href=mStyleFile;
    }



    mStyleFile=mRootDir+'/App_Themes/default/Dialog.css';
    if (document.getElementsByTagName("link").length>1)      
          document.getElementsByTagName("link")[1].href=mStyleFile;
          
          //alert(mStyleFile);
          
    //window.alert(   document.getElementsByTagName("link").length);
    //window.alert(   document.getElementsByTagName("link")[0].href);
    
    
    
        
    
///操作文档
function OfficeEdit(mType,mFileName,mFieldValueList)
{
        //openDocObj.ViewDocument("http://localhost:43403//sample.doc"); 
        //openDocObj.EditDocument("http://localhost/sample.doc");
        //alert(getRootPath());
        //alert(mFileName);
        var mFile='';
        var mPath=''
        if (mFileName.indexOf('/')>=0)
        {
            mPath=getRootPath();
           mFile=mPath+ mFileName;
         }
        else
        {
            mPath=getRootPath()+'/OperationData/MultiMediaData/';
            mFile=mPath+ mFileName;            
         }
             
        
        //var mFile=mPath+ mFileName;
        
        
        //window.alert('1'); 
        //alert( mFileName);
        
        //document.getElementById("UC_F003_HidFileName").value;
        
        if (mType==1)
        {//编辑
        //window.alert(mFieldValueList);
            var mCount=getwordcount(mFieldValueList,'@');
            //window.alert('3');
            if (mCount>0 && mFieldValueList!='')
            { 
            //window.alert('4');             
                var wordObj = new ActiveXObject("Word.Application");             
                if(wordObj==null){  alert( "不能创建Word对象！"); }                
                wordObj.visible=false; 
                this.wordObj = wordObj; 
                
                this.docObj = this.wordObj.Documents.Open(mFile);
                                
                if (this.wordObj.ActiveDocument.ReadOnly!=true)
                { //更新变量
                var  mFieldValue = "";
                var  mMyVar = "";
                var  mMyVal = "";
                for (var i=0;i<mCount ;i++)
                {
                   //window.alert(mFieldValue);
                   mFieldValue=getwordnum(mFieldValueList,i,"@");
                   mMyVar=getwordnum(mFieldValue,0,"|");
                   mMyVal=getwordnum(mFieldValue,1,"|");
                   
                   this.wordObj.ActiveDocument.Variables(mMyVar).Value = mMyVal;
                }
                //var  mMyVar = "MyVar";
                //this.wordObj.ActiveDocument.Variables(mMyVar).Value = document.getElementById("UC_F003_TextBox1").value;
                this.wordObj.ActiveDocument.Fields.Update();                
                this.wordObj.ActiveDocument.Save();   
                
                //将WORD文件另存为TXT文件
                //this.wordObj.ActiveDocument.SaveAs("c:\\3333.txt", 2);
                          
                                    
                }
                
                if (this.wordObj !=null)
                { 
                   this.wordObj.Quit(); 
                } 
            }
            openDocObj.EditDocument(mFile);
        }
        else
        {//查看
          openDocObj.ViewDocument(mFile);
        }


    
  
}


//获取服务目录
function getRootPath(){
    var strFullPath=window.document.location.href;
      
      
    var strPath=window.document.location.pathname;

    // /JGSYS/InfoRemind.aspx
     
    
    
    var pos=strFullPath.indexOf(strPath);
    
    //根目录
    var prePath=strFullPath.substring(0,pos);
    
    //当前页面目录
    var postPath=strPath.substring(0,strPath.substr(1).indexOf('/')+1);
     
    //http://192.168.0.81/App_Themes/default/Dialog.css

    //返回根目录+页面目录
    //return(prePath+postPath);
    
    //返回根目录
    return(prePath);
}




//获取虚拟目录
function getVRootDir()
{
 
 //如果使用默认网站时mRootDir设置为"/"【C:\Inetpub\wwwroot】,为空或其它设置时为使用虚拟路径C:\Inetpub\wwwroot\JdSys
 
 var mRootDir='';


  var strPath=window.document.location.pathname;
  
  var mCount=getwordcount(strPath,'/');


  var mVRootDir='';
  
//    alert(getwordnum(strPath,1,"/"));
    if (mCount>1  && mRootDir!='/' && window.document.location.href.indexOf(":19773")<0  && window.document.location.href.indexOf("localhost:")<0 )
    {                     
           mVRootDir="/"+getwordnum(strPath,1,"/");
            
    }
  
    return mVRootDir;
        
}

function CloseWindows()
{
    window.close(); 
}


function getwordcount(str,splitstr) {
        
    return str.split(splitstr).length;
}

function getwordnum(str,index,splitstr) {
    var returnValue='';
    var arr=str.split(splitstr);
    if (arr!=null) {
        var count=arr.length;
        if (index<count&&index>=0) {
            returnValue=arr[index];
        }
    }
    return returnValue;
}





 function IpSeek()
   {    //获取外网IP----必须保证外网畅通的情况下
        xml = new ActiveXObject("Microsoft.XMLHTTP");     
        xml.open("GET","http://ipseeker.cn/",false);     
        xml.send(); 
        kk=xml.ResponseText;   
        i=kk.indexOf("查询结果一：");   
        var mIP=kk.substr(i+6,15);
        alert(mIP);  
    }
    
    
    function GetLocalIPAddress(mObj) 
    {  //获取本机所有IP,以";"分隔
    var obj = null; 
    var rslt = ""; 
    try 
    { 
        obj = new ActiveXObject("rcbdyctl.Setting"); 
        rslt = obj.GetIPAddress; 
        obj = null; 
    } 
    catch(e) 
    { 
        //异常发生 
    } 
        var mIp="";
        var mIpCount=getwordcount(rslt,";");
        
        if (mIpCount>1)
           mIp= getwordnum(rslt,0,";");
        else   
            mIp= rslt;
         
         document.getElementById(mObj).value=mIp;
         //alert(mIp);
    } 
    
    
    
    
 
function getIEVersion()//获取ie版本
{ 
   var mIE="";
    if(navigator.appName == "Microsoft Internet Explorer") 
    { 
        //if(navigator.appVersion.match(/8./i)=='8.') 
        if(navigator.appVersion.indexOf("MSIE 8.0")>=0)
           {
                  //alert( '当前浏览器是IE 8' )
                  mIE="IE8";
           }
           if(navigator.appVersion.indexOf("MSIE 7.0")>=0)
           //.match(/7./i)=='7.') 
           {
                  //alert( '当前浏览器是IE 7' )
                  mIE="IE7";
           }
           if(navigator.appVersion.indexOf("MSIE 6.0")>=0)
           //if(navigator.appVersion.match(/6./i)=='6.') 
           {
                  //alert( '当前浏览器是IE 6' )
                  mIE="IE6";
           }           
    } 
    return mIE;
} 
        