﻿
function pubAjax()
{
     //定义XMLHttpRequest对象
     var http_request=false;
     
     //开始初始化XMLHttpRequest对象 
     if(window.XMLHttpRequest){//Mozilla等浏览器初始化XMLHttpRequest过程
         http_request=new XMLHttpRequest();
         //有些版本的Mozilla浏览器处理服务器返回的未包含XML mime-type头部信息的内容时会出错.
         //因此,要确保返回的内容包含text/xml信息.
         if(http_request.overrideMimeType){
             http_request.overrideMimeType("text/xml");
         }
     }
     else if(window.ActiveXObject){//IE浏览器初始化XMLHttpRequest过程
         try{
             http_request=new ActiveXObject("Msxml2.XMLHTTP");
         }
         catch(e){
             try{
                 http_request=new ActiveXObject("Microsoft.XMLHTTP");
             }
             catch(e){}
         }
     }
     
     return http_request;
     //异常,创建对象失败
//     if(!http_request){
//         window.alert("不能创建XMLHttpRequest对象实例!");
//         return false;
//     }
}

//判断用户是否已登录

function checkuser()
{
    var url = "http://training.haoyisheng.com/olat_web/checkInVideo.do";
    // 加随机数防止缓存
    if (url.indexOf("?") > 0)
    {
        url += "&randnum=" + Math.random();
    }
    else
    {
        url += "?randnum=" + Math.random();
    }

    var http = pubAjax();
    http.open("GET", url,false);
    http.onreadystatechange = getCallback;
    http.send(null);    
    
    function getCallback() 
    {
        if (http.readyState == 4) 
        {
            if (http.status == 200) 
            {                
                var sResult = http.responseText;
                aryResult = sResult.split("#");  //1#登录成功
                if (aryResult[0] == 1)
                {  
                   //alert("登录成功"+sResult);                   
                }
                else
                {
                    alert("用户未登录，请登录后再学习课程。");
                    window.location = "http://training.haoyisheng.com";
                }
            }
            else 
            {
                    
                alert("系统未响应，请稍后再试！");
                window.location = "http://training.haoyisheng.com";
            }
            http = null;
        } 
    }

    return;    
}

checkuser();

