﻿// JScript File

      try
      {
            var regex=new RegExp("http://www.([a-z0-9A-Z]+\.[a-zA-Z]+).+");
            var str_domain=window.location.href.replace(regex,"$1");
            document.domain=str_domain;
            var divFrame=document.getElementById("frameContainer");           
            divFrame.innerHTML='<iframe  width="0" height="0"  id="t" name="dd"   src="http://med.'+str_domain+'/TransactFileService/proxy.htm"></iframe>';   
          
      }catch(e)
      {alert(e);}

      var Study={
      url:"",
      tt:null,
      catalogW:"", 
      type:"",
      content:"",
      user:"",
      cur_url:"",
      createBegin:function(userName,lessonType,subject){ 
      try{//debugger;
            //判断浏览器类型，只有ie6.0以上的可以继续学习功能
            if(!ieversion()){return;}
            var proxy=window.frames['dd'];
            var obj=proxy.document.getElementById("ocx1");
            //动态加载控件       ---------   by zmduan
            if(typeof obj.SaveFile=='undefined')
            {  
                var objStr='<object classid="clsid:863B212B-0786-4D31-ADF8-C43A20A03D2B" id="ocx1"  width="0" height="0" style="display:none;"></object> ';  
                proxy.document.body.innerHTML=objStr; 
                obj=proxy.document.getElementById("ocx1");           
            }
            //-----------------------------------
           if(typeof obj.SaveFile=='undefined')
           {
                studyRequreClient();
//                if(window.confirm("您还没有安装客户端，您要下载安装吗？"))
//                {
//                    var params=[];
//	                WebServiceClient.Invoke1(this.getStudyService(),"ClientDownPath",params,this.getClientPath);       
//	            }        
	            return;
           }
           if(window.location.href.indexOf("Learning.aspx")==-1)
           {
                if(Validate()=="1")
                {
                    studyRequreClient();
//                   if(window.confirm("您还没有安装客户端，您要下载安装吗？"))
//                    {
//                        var params=[];
//	                    WebServiceClient.Invoke1(this.getStudyService(),"ClientDownPath",params,this.getClientPath);       
//	                }        
	                return;
                }
                else if(Validate()=="2")
                {
                     if(window.confirm("您的客户端版本过低，需要重新下载才能使用，您要下载安装吗？"))
                    {
                        var params=[];
	                    WebServiceClient.Invoke1(this.getStudyService(),"ClientDownPath",params,this.getClientPath);       
	                 }   
	                 return;                
                }
                else
                {
                
                }
           }
           Study.tt=setTimeout("cancelLoading('');if(SOAPClient.xmlhttp)SOAPClient.xmlhttp.abort();alert('网络响应超时，请重试！');",30000);
           this.user=userName;
           this.content=subject;
           this.type=lessonType;
           if($('words_area')) $('words_area').innerHTML="";
           var localhref=window.location.href.split('/');
           this.cur_url=localhref[localhref.length-1];
           Lession.WebService=this.getStudyService();
           loading("课程创建中...");
           if($("jy_box")) 
           {             
                deleteMessage();
           }
           Lession.createLession(userName,lessonType,subject);
           
          }catch(e)
          {
            if(Study.tt != null)
            {
                clearTimeout(Study.tt);
            }
            alert("课程创建失败!");            
            cancelLoading("");
          }          
      },
      getStudyService:function()
      {
           var localhref=window.location.href;
           var start=localhref.indexOf("://");
           var head=localhref.substring(0,start+3);
           if(start != -1)
           {
              localhref=localhref.substring(start+3,localhref.length);                    
           }                    
           localhref=localhref.substring(0,localhref.indexOf("/")); 
           var service = head+localhref+"/study.asmx";
           return service;      
      },
      GoToStudy:function()
      {
        if(Study.tt != null)
        {
            clearTimeout(Study.tt);
        }
        //debugger;
        if(window.location.href.indexOf('Learning.aspx')==-1)
        {
            //window.location.href="../study/Learning.aspx?path="+Study.url+"&content="+Study.content+"&type="+Study.type+"&fromUrl="+Study.cur_url;
            window.location.href="http://www.isay365.com/study/Learning.aspx?path="+Study.url+"&content="+Study.content+"&type="+Study.type+"&fromUrl="+Study.cur_url;
        }
        else 
        { 
            Lession.getLessonText(Study.url,Study.type.toString());
        }
      },
      getClientPath:function(result)
      {         
            if(result && result.indexOf('.exe')!=-1)
             window.location.href=result;
            else
            alert("您还没有安装客户端，需要安装后才能开始学习！");
      }
  }
function EditionValidate(oldEdition,newEdition)
 {
    if(oldEdition.indexOf('.')!=-1 && newEdition.indexOf('.')!=-1)
    {
        if(oldEdition==newEdition)
        {
            return true;
        }
        var oldEditions=oldEdition.replace(/\./g,'');
        var newEditions=newEdition.replace(/\./g,'');
        if(oldEditions.length != newEditions.length)
        {
            return false;
        }
        if(parseInt(oldEditions)<parseInt(newEditions))
        {
            return true;
        }
        return false;        
    }
    return false;
 }
function Validate()
{
    if($('ocx_1'))
    {   
           
    }
   else
   {
       var divObject=document.createElement("div");
       divObject.id="objForDown";   
       divObject.style.display="none";
       divObject.innerHTML='<object classid="clsid:863B212B-0786-4D31-ADF8-C43A20A03D2B" id="ocx_1" width="0" height="0" style="display: none;"></object>';
       document.body.appendChild(divObject);
   }
  
   if(typeof ocx_1.GetEcpVersion=='undefined')
    {
    //未安装客户端
        return "1";
    }
    var newEdition=ocx_1.GetEcpVersion("");
    if(!EditionValidate(oldEdition,newEdition))
    {   
    //客户端版本过低
        return "2";
    }
    //客户端正常
    return "3";
}

function ieversion()
{
    //判断是ie内核的浏览器     
        var version=navigator.appVersion.toLowerCase();         
        if(version.indexOf("msie")==-1)
        {
            alert('学习功能现只支持IE浏览器！');
            return false;
        }
        try
        {
	        var index=version.indexOf("msie");
	        var ieVersion=parseFloat(version.substr(index+4))
	        if(ieVersion<6.0)
	        {
		        alert('在线学习需要ie6.0以上版本！');
		        return false;
	        }
        }catch(e){}
        return true;
}
