///********************************************************************///
//*新启科技大屏学习模式
//*作者：张新
//*时间：2015年02月10日
///********************************************************************///
//*********************多语言开始*****************************//
var lgcs = "";
if (QueryString("lg") != "") {
    lgcs = "?lg=" + QueryString("lg");
}
document.write(unescape("%3Cscript src='/Ajax/GetLanguage.ashx" + lgcs + "' type='text/javascript'%3E%3C/script%3E"));
//**********************多语言结束******************************//
$.ajaxSetup({
    cache: false
});
var Tstate = 1; //计时器，0暂停，1正常
var Key = ""; //当前课程ID
var playVodieId = ""; //章节ID 4ba62105-d9e1-485f-bead-5c341334c96f
var playTime = 0; //视频播放时间
var furl = "", //当前视频地址
    code = "", //校验代码
	office = "";//当前正在打开的文档地址
var moshi = 0;//模式0默认样式，模式1不显示聊天
var script_content = "";
$(function () {
    //当页面加载完成后触发
    Key = QueryString("key"); //获得课程ID
    resizeU();
    $(window).resize(resizeU); //界面尺寸初始化
    Cptoolbind(); //绑定章节列表伸缩功能
    GetEvalUation(); //课程评价
});


//*********************************界面样式↓********************************************//
function resizeU() {
    /// <summary>
    /// 初始化界面尺寸
    /// </summary>
    var height = $(window).height();
    $("#Vmain").height(height - 50 + "px");
    $("#a1").height(height - 80 + "px");

    $("#VmainTool").height($(window).height() - 50 + "px");
	if(moshi == 0)
	{
		$("#Vmain").width($(window).width() - 283 + "px");
		if ($("#Vtool").css("right") != "0px") {
			$("#Vtool").animate({ right: "0px" }, 300);
		}
	}
	else
	{
		$("#Vmain").width($(window).width() - 10 + "px");
		$("#VmainTool_btn").parent().hide();
	}
    createCode(); //产生校验码
}
//*********************************主程序，课程与章节目录********************************************//
function Cptoolbind() {
    /// <summary>
    /// 绑定章节列表伸缩功能
    /// </summary>
    //*************绑定章节列表伸缩功能*****************//
    var shensuo;
    $("#Cptool").mousemove(function () {
        $("#Cptool").stop().animate({ left: "0px" }, 200);
        $("#chapter_btn").attr("src", "images/left_t.png");
        $("#chapter_btn").attr("title", lgzjycmulist);
    });
    $("#Cptool").mouseleave(shensuo = function () {
        $("#Cptool").stop().animate({ left: "-260px" }, 300);
        $("#chapter_btn").attr("src", "images/right.png");
        $("#chapter_btn").attr("title", lgzjxsmulist);
    });
    //setTimeout(shensuo, 1000); //看清楚章节后自动缩入
    //*************绑定章节列表伸缩功能*****************//

    progress(); //进度条

    //载入章节
    $.get("/Training/Learn/GetInteracts.ashx", { action: "Chapter", Key: Key }, function (MyJson) {
        if (MyJson != "") {
           // try {
                var MyWinList = eval('(' + MyJson + ')');
                if (MyWinList.length > 0) {
                    var chapterhtml = "";
                    var dqzhangjie = "";
                    //加载章节目录完成，开始加载课程
                    var jiyi = getCookie("CS-" + Key);
                    var jyzr = false; //记忆是否载入成功
                    chapterhtml = "<ul>";
                 
                    for (var i = 0; i < MyWinList.length; i++) {
                        var zhangjie = MyWinList[i].CoursewareDetail_Chapters;
                        var name = MyWinList[i].CoursewareDetail_Name;
                        var lihtml = "<li id='" + MyWinList[i].CoursewareDetail_CdId + "'><p class=\"radius\"></p><a href=\"#\" onclick=\"openvodie('" + MyWinList[i].CoursewareDetail_CdId + "','" + MyWinList[i].CoursewareDetail_FileResource + "')\" class=\"left_line\">" + name + "</a></li>";
                        if (zhangjie == dqzhangjie) { //本章节课程累加
                            chapterhtml += lihtml
                        } else {
                            chapterhtml += "</ul><ul><div class=\"tit\"><img src=\"images/jian.png\" style=\"margin: 0 5px -3px 0;\" />" + zhangjie + "</div>";
                            chapterhtml += lihtml;
                            dqzhangjie = zhangjie;
                        }

                        //更具记忆加载课程
                        if (jiyi != "" && jiyi.split("|")[0] == MyWinList[i].CoursewareDetail_CdId) {
                            openvodie(MyWinList[i].CoursewareDetail_CdId, MyWinList[i].CoursewareDetail_FileResource);
                            var jytime = jiyi.split("|")[1]; //以下为为跳转子章节对应的节点
                            if (jytime != "" && jytime != "0") {

                                setTimeout(function () {
                                    try {

                                        CKobject.getObjectById('ckplayer_a1').videoSeek(jytime);
                                        //alert(jytime);
                                    }
                                    catch (e) {
                                        // 如果非视频课程则走这 alert(jytime+"|"+e.toString()); 
                                    }
                                }, 1000);
                            }
                            jyzr = true;
                        }
                    }
                    chapterhtml += "</ul>";
                    $("#chapter").prepend(chapterhtml);
                    $("#chapter li:odd").css("background-color", "#fff");  //改变偶数行背景色


                    if (!jyzr) {
                        //未找到播放记录
                        openvodie(MyWinList[0].CoursewareDetail_CdId, MyWinList[0].CoursewareDetail_FileResource);
                    }
                }
                else {
                    $("#chapter").html("<center>" + lgwzdrhxx + "</center>");
                }
           // }
           // catch (e) {
           //     alert(e);
           //     $("#chapter").html(MyJson);
           // }
        }
        else {
            $("#chapter").html("<center>" + lgwzdrhxx + "</center>");
        }
    });
}
function progress() {
    /// <summary>
    /// 载入课程进度并触发计时器
    /// </summary>
    $.get("/Training/Learn/GetInteracts.ashx", { action: "Progress", Key: Key }, function (jindu) {
        if (jindu == "" || jindu == "0,0") {
            //未登录进度不计
            $("#Cptooljindu").html("");
        }
        else {
            //将初始化数据绑定
            $("#jindu_num").html(jindu.split(",")[0]);
            $("#jindu_count").html(jindu.split(",")[1]);

            var c = 0; //计时器
            //var cath = 0; //备份计时
            var zd = 0; //整点记录
            $('body').everyTime('1s', 'Prpgress', function () {
                if (c == 0) {
                    var numbers = document.getElementById("jindu_num").innerHTML;
                    c = Number(numbers) * 60;
                }
                if (Tstate == 1) {
                    c = c + 1;
                    var min = parseInt(c / 60); // 分钟数
                    var lastsecs = c % 60;
                    if(lastsecs <= 9)
                    {
                        lastsecs = "0"+lastsecs;
                    }
    
                    var count = document.getElementById("jindu_count").innerHTML;
                    //整点播报
                    if (min != zd) {
                        $.get("/Training/Learn/GetInteracts.ashx", { action: "Zhengdian", Key: Key, Cime: min, Code: code }, function (jindu) {
                            if (jindu == "ok") {

                            }
                            else {
                                showTipsMsg(lgjsqyc, 1000, 3);
                            }
                        });
                        zd = min;
                    }

                    if (min >= count) {//超出后
                        $('body').stopTime('Prpgress');
                        document.getElementById("jindu_tiao").style.width = "100%";
			document.getElementById("jindu_num").innerHTML = min;
                    }
                    else {
                        document.getElementById("jindu_num").innerHTML = min + "." + lastsecs;
                        if (parseFloat((c / 60) * 100 / count) <= 100) {
                            document.getElementById("jindu_tiao").style.width = parseFloat((c / 60) * 100 / count) + "%";
                        }
                    }
                    // alert(min);
                }
                else {
                    //本段代码解开注释后，暂停后余数会被清空掉
                    //                    try {
                    //                        c = parseInt(c / 60) * 60;  //一旦暂停则会清除余数
                    //                        cath = c;
                    //                    } catch (e) {
                    //                        c = cath;
                    //                    }

                }
            }, 0, true);

        }

    })
}
function openvodie(pid, pfile) {
    /// <summary>
    /// 播放指定视频
    /// </summary>
    playVodieId = pid;
    var Height = $(window).height() - 100;


    //将正在学习的课程在章节中标注
    setTimeout(function () {
        $("#chapter li").removeClass();
        $("#" + pid).addClass("hover");
    }, 1000);

    //取得课程对应的问答
    GetInteracts(); //获得互动内容

    //更具实际情况加载对应的课程组件
    var mima = jiema(pfile);
    var houzhui = mima.substring(mima.lastIndexOf(".") + 1); //获得主视频后缀名
    if (houzhui.indexOf("?") >= 0) {
        houzhui = mima.substring(mima.lastIndexOf(".") + 1, mima.lastIndexOf("?"));
    }
   
    if (houzhui == "htm" || houzhui == "html") {
        //静态类内容
        AddHtml("video", Height, mima);
    }
    else if (houzhui == "flv" || houzhui == "mp4") {
        //网络视频类内容
        AddVideo("video", Height, mima);
    }
    else if (houzhui == "swf") {
        //flash动画或播放器格式
        ADDflash("video", Height, mima);
    }
    else {
        //其他乱七八糟视频格式
     
        AddSanFang("video", Height, mima);
    }

    //播放记忆
    cookielog("CS-" + Key, pid + "|0");

    //************************组件加载及实现方法*************************************//
    
    function AddHtml(Cantent, Height, mima) {
        /// <summary>
        /// 静态类内容
        /// </summary>
        $("#" + Cantent).html("");
        $("#" + Cantent).append("<iframe  style=\"text-align: left; background-color: #fff; background-position: center;background-repeat: no-repeat; border: none; width: 100%;Height:" + Height + "px\" src='" + mima + "'></iframe>");
    }
    function AddVideo(Cantent, Height, mima) {
        /// <summary>
        /// 增加视频组件
        /// </summary>
        //$("#" + Cantent).html("<div id='a1'></div>");

        //获得视频对应的课程脚本
        $.get("/Training/Learn/GetInteracts.ashx", { action: "Jiaoben", key: Key, pid: playVodieId }, function (data) {

            var params = { bgcolor: '#000', allowFullScreen: true, allowScriptAccess: 'always', wmode: 'opaque' };
            var video = [mima + '->video/mp4'];

            var flashvars = { f: mima.replace('\\', '/'),
                c: 0, p: 1, b: 0, h: 3,
                my_url: encodeURIComponent(window.location.href),
                loaded: 'loadedHandler'
            }; //还要增加其他参数


            //如果有课程脚本，则需要把脚本标注进来
            try {
                if (data != "0") {
                    var Scriptlist = eval('(' + data + ')').jiaoben;
                    scriptlist = Scriptlist; //将脚本数据保存下来，已被后面监听需要

                    //下面正在组织左侧目录结构，将脚本部分插入
                    var k = "", n = "";
                    if (Scriptlist.length > 0) {
                        var jblidiv = "<div class='points'>";
                        var officeindex = 0;
                        for (var i = 0; i < Scriptlist.length; i++) {
                            var Script_ID = Scriptlist[i].SCRIPT_ID;
                            var Script_CS_ID = Scriptlist[i].SCRIPT_CS_ID;
                            var Script_Time = Scriptlist[i].SCRIPT_TIME;
                            var Script_title = Scriptlist[i].SCRIPT_TITLE;
                            var Script_PranterID = Scriptlist[i].SCRIPT_PRANTERID;
                            var Script_Type = Scriptlist[i].SCRIPT_TYPE;
                            var Script_path = Scriptlist[i].SCRIPT_PATH;

                            //给播放器追加描点
                            k += Script_Time == "" ? "0" : Script_Time + "|";
                            n += Script_title + "|";

                            //只有在知识点的情况下在左侧目录中增加
                            if (Script_Type == "知识点") {
                                jblidiv += "<a href='#' onclick=\"openDialog('/Training/Courseware/Courseware_Script_Zhishi.aspx?id=" + Script_ID + "','Courseware_Script_Zhishi' , '" + Script_title + "', '80%', '80%', 20, 20)\">" + Script_title + " [" + Script_Time + "秒]</a>";
                            }
                            else if (Script_Type == "文档") {
                                //窗体切换成三分屏模式
                                if (officeindex == 0) {
                                    //1、新将主视频放到一个角落
                                    var sf_videocss = { position: 'fixed', right: '0', bottom: '0', width: '300px', height: '200px', margin: '0' };
                                    $("#video").css(sf_videocss);
                                    $("#a1").height("200px");
                                    var opslist = Script_path.split(",");
                                    AddOffice(opslist[0], 0); //当检测到界面中含有文档时，启动三分屏界面模式,加载第一个文档，不跳转界面
                                }
                                officeindex++;
                            }
                            else {

                            }
                        }
                        jblidiv += "</div>";
                        flashvars.k = k.substr(0, k.length - 1);
                        flashvars.n = n.substr(0, n.length - 1);
                        script_content = jblidiv;
                        $("#" + playVodieId).append(jblidiv); //将脚本提示加在章节目录上

                        JShtml = getscript();

                    }
                }
            }
            catch (e) { }
            CKobject.embed('/Training/Learn/m/ckplayer/ckplayer.swf', 'a1', 'ckplayer_a1', '100%', '100%', false, flashvars, video, params);

        });

    }

    function ADDflash(Cantent, Height, mima) {
        /// <summary>
        /// 增加FLASH组件
        /// </summary>
        //$("#" + Cantent).html("<div id='a1'></div>");
        var params = { bgcolor: '#000', allowFullScreen: true, allowScriptAccess: 'always', wmode: 'opaque' };
        var flashvars = {};
        var attributes = { id: 'game_ring', name: 'game_ring' };
        swfobject.embedSWF(mima, "a1", "100%", Height, "10.2.0", "/live/expressInstall.swf", flashvars, params, attributes);

    }

    function AddSanFang(Cantent, Height, mima) {
        /// <summary>
        /// 引入第三方播放器(暂用影音先锋)
        /// </summary>

        $("#" + Cantent).html("");
        $("#" + Cantent).append("<OBJECT id=Xfplay name=Xfplay onerror=\"$('#" + Cantent + "').html('<center><br />" + lgninxuyaoanzhuangchajian + "<br /><a href=http://www.xfplay.com>" + lgdianjixiazaibofangqi + "</a><br />" + lganzhuangwanchenghoushuaxin + "</center>')\" CLASSID=\"CLSID:E38F2429-07FE-464A-9DF6-C14EF88117DD\" width=\"100%\" height=\"" + Height + "\"><PARAM NAME=\"URL\" VALUE=\"" + mima + "\" width=\"100%\" height=\"" + Height + "\"><embed type=\"application/xfplay-plugin\" id=\"Xfplay2\" name=\"Xfplay2\" PARAM_URL=\"" + mima + "\"  width=\"100%\" height=\"" + Height + "\"></embed></OBJECT>");
        //alert($("#" + Cantent).html());
        var XfplayIEFF;
        var isIE = true;
        var Install = false;
        var checkIEorFirefox = {};
        if (window.ActiveXObject || window.ActiveXObject !== undefined) {
            checkIEorFirefox.ie = "yes";
            XfplayIEFF = document.getElementById("Xfplay");
        } else {
            isIE = false;
            checkIEorFirefox.firefox = "yes";
            XfplayIEFF = document.getElementById("Xfplay2");

            var $E = function () { var c = $E.caller; while (c.caller) c = c.caller; return c.arguments[0] };
            __defineGetter__("event", $E);
        }

        if (!isIE) {
            if (navigator.plugins) {
                for (i = 0; i < navigator.plugins.length; i++) {
                    var n = navigator.plugins[i].name;
                    if (navigator.plugins[n][0]['type'] == 'application/xfplay-plugin') {
                        Install = true; break;
                    }
                }
            }
            if (!Install) {
                var hight = $(window).height() - 80;
                XfplayIEFF.style.display = 'none';
                mima = "/Training/Learn/m/xfplay/error.htm";
                //NewstartLearn.AddHtml(ID, Cantent, Height, Flashvars);
                $("#video").html("<iframe src=\"" + mima + "\"   style=\"text-align: left; background-color: #fff; background-position: center;background-repeat: no-repeat;color:#fff; border: none; width: 100%;Height:" + hight + "px\" ></iframe>"); //插入在线文档
            }
        }
        else {
            if (getxfdx('Xfplay2') != null) {
                getxfdx('Xfplay2').style.display = 'none';
            }
            //alert(XfplayIEFF);
            if (XfplayIEFF != null && XfplayIEFF.style.display == 'none') {
                //alert("插件未安装");
            } else {
                Install = true;
            }
        }
    }
}
var scriptlist = []; //当前需要处理的脚本
var JShtml = "";
var zt = -1; //当前已经出发了的脚本时间点
function getscript() {
    //*************************************************************//
    //这里的原理有点绕，说明下，下面的工作是拼接一个字符串
    //这个字符串会被转化成函数，并追加到监控视频播放时间函数里
    //*************************************************************//
    var Scriptlist = scriptlist;
    var jshtml = "function fn(s) {";
    //增加每个脚本的事件监听
    for (var i = 0; i < Scriptlist.length; i++) {
        var Script_ID = Scriptlist[i].SCRIPT_ID;
        var Script_CS_ID = Scriptlist[i].SCRIPT_CS_ID;
        var Script_Time = Scriptlist[i].SCRIPT_TIME;
        var Script_title = Scriptlist[i].SCRIPT_TITLE;
        var Script_PranterID = Scriptlist[i].SCRIPT_PRANTERID;
        var Script_Type = Scriptlist[i].SCRIPT_TYPE;
        var Script_path = Scriptlist[i].SCRIPT_PATH;
        //jshtml += "alert('a');";
        jshtml += "if (parseInt(s) == " + Script_Time + " && zt != " + Script_Time + ") {";
        //在这里可以扩展其他的交互功能
        if (Script_Type == "知识点") {
            jshtml += "CKobject.getObjectById('ckplayer_a1').videoPause();zt = parseInt(s);";
            jshtml += "openDialog(\"/Training/Courseware/Courseware_Script_Zhishi.aspx?id=" + Script_ID + "\",'Courseware_Script_Zhishi','" + Script_title + "', '80%', '80%',20,20)";
        }
        else if (Script_Type == "提问") {
            jshtml += "CKobject.getObjectById('ckplayer_a1').videoPause();zt = parseInt(s);askshow('" + Script_title + "','" + Script_path + "')";
        }
		else if (Script_Type == "文档") {
		    //文档翻页
		    var opslist = Script_path.split(",");
		    jshtml += "zt = parseInt(s);AddOffice('" + opslist[0] + "','" + opslist[1] + "');";
        }
        else {
            //未知脚本类型
        }
        jshtml += "}";
    }
    jshtml += "}";
    return jshtml;
}

function askshow(title, nei) {
    /// <summary>
    /// 组织出提问界面
    /// </summary>
    if (nei != undefined && nei != null && nei != "") {
        var askhtml = "<div id='CourAsk_bg'></div><div id='CourAsk'><h1>" + title + "</h1><ol type='A'>";
        var opslist = nei.split(",");
        for (var i = 0; i < opslist.length - 1; i++) {
            var ops = opslist[i].split("|");
            askhtml += "<li onclick=\"askgoto('" + ops[1] + "')\" ><a href='#'>" + ops[0] + "</a></li>";
        }
        askhtml += "</ol></div>";
        //alert(askhtml);
        $("body").prepend(askhtml);
        $("#CourAsk").animate({ top: '50px' });
        window.top.onfocus = function () { };
    }
}
function askgoto(time) {
    /// <summary>
    /// 更具答案跳转
    /// </summary>

    $("#CourAsk_bg").remove();
    $("#CourAsk").remove();
    if (time != "" && time != null && time != undefined) {//无需跳转
        if (!isNaN(time)) {//当为数字时
            //alert(JShtml);
            //eval(JShtml); //将拼好的字符，转成函数
            //fn(times); //将这个函数运行一下
            CKobject.getObjectById('ckplayer_a1').videoSeek(time);
            getscript();
            eval(JShtml); //将拼好的字符，转成函数
            //fn(playTime); //将这个函数运行一下
            //alert(playTime);
        }
        else if (time.substr(0, 7) == "http://") {
            window.location = time;
        }
        else {

        }
    }
}
//开关灯(暂留扩展)
function closelights() {//关灯

}
function openlights() {//开灯

}

var zantingdian = -1; //上一次暂停点记录（防止重复暂停）
function loadedHandler() {
    /// <summary>
    /// 播放器加载完成监听
    /// </summary>
    //播放与暂停监听
    CKobject.getObjectById('ckplayer_a1').addListener('play', 'Ckplay');
    CKobject.getObjectById('ckplayer_a1').addListener('pause', 'Ckpause');

    //增加播放时间监听
    CKobject.getObjectById('ckplayer_a1').addListener('time', 'timego');

    //增加播放完成的监听,延时是因为需要等播放器加载完成
    CKobject.getObjectById('ckplayer_a1').addListener('ended', 'VideoPlayEndedHandler');

    //浏览器失去焦点和获得焦点自动暂停播放
    window.top.onblur = function () {
        if (zantingdian == -1)//弹出窗口后无效
        {
            try {
                Tstate = 0;
                CKobject.getObjectById('ckplayer_a1').videoPause();
            }
            catch (e) { }
        }
    };
    window.top.onfocus = function () {
        if (zantingdian == -1)//弹出窗口后无效
        {
            try {
                Tstate = 1;
                CKobject.getObjectById('ckplayer_a1').videoPlay();
            }
            catch (e) { }
        }
    }
}
function Ckplay() {
    /// <summary>
    /// 播放器开始播放触发
    /// </summary>
    Tstate = 1;
}
function Ckpause() {
    /// <summary>
    /// 播放器暂停时触发
    /// </summary>
    Tstate = 0;
}
function timego(times) {
    /// <summary>
    /// 监听视频播放时间
    /// </summary>
    playTime = times;

    //播放记忆
    cookielog("CS-" + Key, playVodieId + "|" + playTime);

    eval(JShtml); //将拼好的字符，转成函数
    fn(times); //将这个函数运行一下
}
function VideoPlayEndedHandler() {
    /// <summary>
    /// 视频播放完成后出发
    /// </summary>

    var pindex = $("#chapter li").index($("#" + playVodieId)); //找到当前播放的索引

    if (pindex < ($("#chapter li").length - 1)) {
        //alert($("#chapter li").eq(pindex + 1).html());
        showTipsMsg(lgjxxyxj, 2000, 1);
        $("#chapter li").eq(pindex + 1).find("a").click();
    }
    else {
        //alert(lgbfwb);
    }
}
//*********************************主程序，课程与章节目录结束********************************************//

//*********************************右侧工具区********************************************//
function VmainTool() {
    /// <summary>
    /// 显示隐藏工具箱
    /// </summary>
    if ($("#Vtool").css("right") == "0px") {
        $("#Vtool").animate({ right: "-282px" }, 300);
        $("#VmainTool_btn").attr("src", "images/left_t.png");
        $("#VmainTool_btn").attr("title", lgzjxsmulist);

        $("#Vmain").width($(window).width() + "px");
    }
    else {
        $("#Vtool").animate({ right: "0px" }, 300);
        $("#VmainTool_btn").attr("src", "images/right.png");
        $("#VmainTool_btn").attr("title", lgzjycmulist);

        $("#Vmain").width($(window).width() - 283 + "px");
    }

}
function rightgo(obj, id) {
    /// <summary>
    /// 切换右侧工具条
    /// </summary>
    $("#right_menu li").removeClass("li_home");
    $(obj).addClass("li_home");
    if (id == 1) {//问答
        $("#Interacts").show();
        $("#Notes").hide();
        $("#rightmain").hide();
        $("#About").hide();
    }
    else if (id == 2) {
        GetNotes();
        $("#Interacts").hide();
        $("#Notes").show();
        $("#rightmain").hide();
        $("#About").hide();
    }
    else if (id == 3) {//分享
        $("#rightmain").attr("src", "Learn_Shares.aspx?Key=" + Key);
        $("#rightmain").show();
        $("#Interacts").hide();
        $("#Notes").hide();
        $("#About").hide();
    } else if (id == 4) {//作业考试等
        $("#rightmain").attr("src", "/Training/TrainingTest/GetExamList.aspx?key=" + Key);
        $("#rightmain").show();
        $("#Interacts").hide();
        $("#Notes").hide();
        $("#About").hide();
    } else if (id == 5) {//简介
        if ($("#AboutMain").html() == "") {
            $.get("/Training/Learn/Learn_CustomGet.ashx",
                        { Key: Key, Code: "About" },
          function (data) {
              $("#AboutMain").html(data);
          });
        }
        $("#Interacts").hide();
        $("#Notes").hide();
        $("#rightmain").hide();
        $("#About").show();
    }
    else {

    }
    if ($("#Vtool").css("right") != "0px") {

        $("#Vtool").animate({ right: "0px" }, 300);
        $("#VmainTool_btn").attr("src", "images/right.png");
        $("#VmainTool_btn").attr("title", lgzjycmulist);
        $("#Vmain").width($(window).width() - 283 + "px");
		
		$("#VmainTool_btn").parent().hide();
    }
}
function GetInteracts() {
    /// <summary>
    /// 获得课程问答留言
    /// </summary>
    $("#interMain").html("<center><img src=\"/LiveTelecast/Images/loadingNow.gif\" /></center>");
    $.get("/Training/Learn/GetInteracts.ashx", { action: "Interacts", Key: Key, pid: playVodieId }, function (MyJson) {
        if (MyJson != "") {
            try {
                //alert(playVodieId);
                var MyWinList = eval('(' + MyJson + ')');
               
                if (MyWinList.length > 0) {
                    $("#interMain").html("");
                    for (var i = 0; i < MyWinList.length; i++) {
                      
                        var ID = MyWinList[i].Interacts_ItId;
                        var UID = MyWinList[i].Interacts_AnswerId;
                        var UName = MyWinList[i].Interacts_AnswerName;
                        var UTID = MyWinList[i].Interacts_ToItId;
                        var UTNAME = MyWinList[i].Interacts_ToAnswerName;
                        var Ucount = MyWinList[i].Shares_AnswerContext;
                        var PlayTimes = MyWinList[i].PlayTime;
                        var ptime = "<span class=\"fr\">" + PlayTimes + "秒</span>";
                        if (PlayTimes == "0") { ptime = ""; }
                        if (UTNAME == "") {
                            $("#interMain").append("<li id=\"" + ID + "\" class=\"clear\"><div class=\"fl tou\"><img src=\"/mall/User_Image.ashx?id=" + UID + "\" width=\"52\" height=\"52\" /></div><div class=\"huifu\"><span class=\"name\">" + UName + "：</span>" + Ucount + "<br />" + ptime + "</div></li>");
                        }
                        else {
                            $("#" + UTID).append("<div id=\"" + ID + "\" class=\"clear teacher\"><div class=\"huifu\"><span class=\"name\">" + UName + "</span> 回复 <span class=\"name\">" + UTNAME + "：</span>" + Ucount + "<br /></div></div>");
                        }
                    }
                    $("#interMain li:odd").css("background-color", "#f8f8f8");  //改变偶数行背景色
                }
                else {
                    $("#interMain").html("<center>" + lgzwfy + "</center>");
                }
            }
            catch (e) {
                // alert(e);
                //$("#interMain").html(MyJson);
            }
        }
        else {
            $("#interMain").html("<center>" + lgzwfy + "</center>");
        }
    });
}
function GetNotes() {
    /// <summary>
    /// 获得自己的笔记
    /// </summary>
    $("#notesMain").html("<center><img src=\"/LiveTelecast/Images/loadingNow.gif\" /></center>");
    $.getScript("/Training/Learn/notes.ashx?action=getnotes&Key=" + Key + "&pid=" + playVodieId + "&Time=" + playTime, function () {
        binddel();
        bindedit();
    });
    $("#notesMain").scrollTop(100);

}
function setnotes() {
    /// <summary>
    /// 笔记
    /// </summary>
    var text = escape($("#notesText").val()).replace("%0A", "</br>");
    text = unescape(text);
    $.get("/Training/Learn/notes.ashx",
            { action: "save", Key: Key, pid: playVodieId, Time: playTime, Text: text },
            function (data) {
                if (data == "ok") {
                    GetNotes();

                }
                else if (data == "nouser") {
                    showTipsMsg(lgjinzhinimingliuyan, 1000, 3);
                }
                else {
                    showTipsMsg(lgfayanshibai, 1000, 5);
                }
            });
}
//绑定编辑笔记事件
function bindedit() {
    $(".editimg").click(function () {
        var id = $(this).attr("data");
        var text = $(this).attr("thtm");
        $("#span_" + id).remove();
        $("#" + id).append("<span id=\"span_" + id + "\"><input id=\"edit_" + id + "\" class=\"note_edit\" type=\"text\" value=\"" + text + "\" /><input onclick=\"NoteEdit('" + id + "','edit_" + id + "')\" type=\"button\" value=\"" + lgqd + "\" /><span>");
    });
}
//编辑笔记
function NoteEdit(id, textid) {
    $.get("/Training/Learn/notes.ashx", { action: "edit", Key: id, Text: $("#" + textid).val() }, function (data) {
        if (data == "ok") {
            GetNotes();
        }
        else {
            showTipsMsg(lgczshibai, 1000, 5);
        }
    });
}
//删除笔记
function binddel() {
    $(".delimg").click(function () {
        if (confirm(lgqrsanchu2)) {
            $.get("/Training/Learn/notes.ashx",
            { action: "del", Key: $(this).attr("data") },
            function (data) {
                if (data == "ok") {
                    GetNotes();
                }
                else {
                    showTipsMsg(lgdel5, 1000, 5);
                }
            });
        }
    });
}


function setchart() {
    /// <summary>
    /// 提问
    /// </summary>
    var text = escape($("#interText").val()).replace("%0A", "</br>");
    text = unescape(text);
    $.get("/Training/Learn/Interacts.ashx",
            { Key: Key, pid: playVodieId, Time: playTime, Text: text },
            function (data) {
                if (data == "ok") {
                    GetInteracts();
                    document.getElementById("interText").value = "";//提问成功后清空文本框
                    //$("#interMain").prepend("<li class=\"clear\"><div class=\"huifu\"><span class=\"name\">我说：</span>" + $("#interText").val() + "<br /></div></li>");
                } else if (data == "1ok") {
                    alert(lghudongshenhe);
                }
                else if (data == "nouser") {
                    alert(lgjinzhinimingliuyan);
                }
                else {
                    alert(lgfayanshibai);
                }
            });
}
function GetEvalUation() {
    /// <summary>
    /// 课程点评
    /// </summary>
    $.get("/Training/Learn/GetInteracts.ashx", { action: "Pingjia", Key: Key }, function (MyJson) {
        $("#pingjia").html("<a class=\"fr pingjia\" href=\"#\" onclick=\"AddEvalUation()\" ><span style=\"color: #d6d260;\">评价" + MyJson.split(",")[0] + "颗星</span>（" + MyJson.split(",")[1] + "人）</a>");
    });
}
function AddEvalUation() {
    /// <summary>
    /// 课程点评
    /// </summary>
    var url = "/Mall/Eval/EvalUation_Form.aspx?key=" + Key;
    openDialog(url, 'EvalUation_Form', lgdianping, "85%", "85%", 50, 50);
}

function AddOffice(officeurl,seekpage){
		/// <summary>
		/// 插入OFFICE到主屏幕(参数为文档地址，跳转页码)
		/// </summary>
    if (office != officeurl) {//当本文档还没有加载时
        var hight = $(window).height() - 80;
        $("#video_text").html("<iframe src=\"/Training/Courseware/Office/OfficeShow.aspx?p=" + officeurl + "\" id=\"officeiframe\" name=\"officeiframe\" style=\"text-align: left; background-color: #fff; background-position: center;background-repeat: no-repeat; border: none; width: 100%;Height:" + hight + "px\" ></iframe>"); //插入在线文档
        office = officeurl;
        Tstate = 1;
    } else {
        Tstate = 0;
    }
		//加载完成后，运行翻页方法.当seekpage等于0时不跳转
		if (seekpage != 0) {
		    // officeiframe.load(function () {
		    officeiframe.pagego(seekpage);
		   
		   // }); 
		    
//		    setTimeout(function () {
//		        try {
//		            officeiframe.pagego(seekpage);
//		        }
//		        catch (e) { alert(e); }
//		    }, 1000);
		    
		}
}


//*********************************右侧工具区********************************************//


//*********************************其它帮助********************************************//
function QueryString(fieldName) {
    /// <summary>
    /// 得到QueryString
    /// </summary>
    fieldName = fieldName.toLowerCase();
    var urlString = document.location.search.toLowerCase();
    if (urlString != null) {
        var typeQu = fieldName + "=";
        var urlEnd = urlString.indexOf(typeQu);
        if (urlEnd != -1) {
            var paramsUrl = urlString.substring(urlEnd + typeQu.length);
            var isEnd = paramsUrl.indexOf('&');
            if (isEnd != -1) {
                return paramsUrl.substring(0, isEnd);
            }
            else {
                return paramsUrl;
            }
        }
        else {
            return "";
        }
    }
    else {
        return "";
    }
}
function showTipsMsg(msg, time, type) {
    /// <summary>
    ///     1: showTipsMsg(msg, time, type) - 显示消息函数
    ///     &#10;   该函数短暂的显示消息（无操作按钮）
    /// </summary>
    /// <param name="msg" type="String">
    ///     消息内容，允许Html标签
    /// </param>
    /// <param name="time" type="Int">
    ///     消息停留时间，以毫秒(ms)单位
    /// </param>
    /// <param name="type" type="Int">
    ///     消息类型{ 4：成功，5：失败，3：警告 }
    /// </param>
    /// <returns type="void" />
    top.ZENG.msgbox.show(msg, type, time);
}
/*弹出网页
/*url:          表示请求路径
/*_id:          ID
/*_title:       标题名称
/*width:        宽度
/*height:       高度
---------------------------------------------------*/
function openDialog(url, _id, _title, _width, _height, left, top) {
    /// <summary>
    ///     1: openDialog(url, _id, _title, _width, _height, left, top) - 显示对话框,该对话框用于加载某一iframe框架并弹出
    ///     &#10;   显示对话框,该对话框用于加载某一iframe框架并弹出
    /// </summary>
    /// <param name="url" type="String">
    ///     消息内容，允许Html标签
    /// </param>
    /// <param name="_id" type="String">
    ///     要加载的iframe框架路径
    /// </param>
    /// <param name="_title" type="String">
    ///     消息框标题
    /// </param>
    /// <param name="_width" type="Int">
    ///     消息框宽度
    /// </param>
    /// <param name="_height" type="Int">
    ///     消息框高度
    /// </param>
    /// <param name="left" type="Int">
    ///     消息框x轴位置，以百分比(%)为单位
    /// </param>
    /// <param name="top" type="Int">
    ///     消息框y轴位置，以百分比(%)为单位
    /// </param>
    /// <returns type="void" />
    art.dialog.open(url, {
        id: _id,
        title: _title,
        width: _width,
        height: _height,
        left: left + '%',
        top: top + '%',
        background: '#000000',
        opacity: 0.1,
        lock: true,
        resize: false,
        close: function () { }
    }, false);
}
//窗口关闭
function OpenClose() {
    /// <summary>
    ///     1: OpenClose() - 关闭当前所有的弹窗窗口
    ///     &#10;   关闭当前所有的弹窗窗口
    /// </summary>
    /// <returns type="void" />
    art.dialog.close();
}
function cookielog(playid, value) {
    /// <summary>
    /// 记住视频id
    /// </summary>
    ///var value = $("input:checkbox:checked").val();
    //if (value == "on") {
    //获取当前时间 
    var date = new Date();
    //将date设置为30天以后的时间 
    var expiresDays = 30;
    date.setTime(date.getTime() + expiresDays * 24 * 3600 * 1000);
    document.cookie = playid + "=" + value + "; expires=" + date.toGMTString();
    // }
}
function getCookie(name) {
    /// <summary>
    /// 获取cookie
    /// </summary>
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for (var i = 0; i < arrCookie.length; i++) {
        var arr = arrCookie[i].split("=");
        if (arr[0] == name) return arr[1];
    }
    return "";
}
function createCode() {
    /// <summary>
    /// 创建校验码
    /// </summary>
    code = "";
    var codeLength = 4; //验证码的长度
    var checkCode = document.getElementById("code");
    var random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); //随机数
    for (var i = 0; i < codeLength; i++) {//循环操作
        var index = Math.floor(Math.random() * 36); //取得随机数的索引（0~35）
        code += random[index]; //根据索引取得随机数加到code上
    }
    cookielog("code", code);
}
//数据解码
var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var base64DecodeChars = new Array(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
function jiema(str) { var c1, c2, c3, c4; var i, len, out; len = str.length; i = 0; out = ""; while (i < len) { do { c1 = base64DecodeChars[str.charCodeAt(i++) & 255] } while (i < len && c1 == -1); if (c1 == -1) { break } do { c2 = base64DecodeChars[str.charCodeAt(i++) & 255] } while (i < len && c2 == -1); if (c2 == -1) { break } out += String.fromCharCode((c1 << 2) | ((c2 & 48) >> 4)); do { c3 = str.charCodeAt(i++) & 255; if (c3 == 61) { return out } c3 = base64DecodeChars[c3] } while (i < len && c3 == -1); if (c3 == -1) { break } out += String.fromCharCode(((c2 & 15) << 4) | ((c3 & 60) >> 2)); do { c4 = str.charCodeAt(i++) & 255; if (c4 == 61) { return out } c4 = base64DecodeChars[c4] } while (i < len && c4 == -1); if (c4 == -1) { break } out += String.fromCharCode(((c3 & 3) << 6) | c4) } return out };
//计时器
jQuery.fn.extend({ everyTime: function (interval, label, fn, times, belay) { return this.each(function () { jQuery.timer.add(this, interval, label, fn, times, belay); }); }, oneTime: function (interval, label, fn) { return this.each(function () { jQuery.timer.add(this, interval, label, fn, 1); }); }, stopTime: function (label, fn) { return this.each(function () { jQuery.timer.remove(this, label, fn); }); } }); jQuery.extend({ timer: { guid: 1, global: {}, regex: /^([0-9]+)\s*(.*s)?$/, powers: { 'ms': 1, 'cs': 10, 'ds': 100, 's': 1000, 'das': 10000, 'hs': 100000, 'ks': 1000000 }, timeParse: function (value) { if (value == undefined || value == null) return null; var result = this.regex.exec(jQuery.trim(value.toString())); if (result[2]) { var num = parseInt(result[1], 10); var mult = this.powers[result[2]] || 1; return num * mult; } else { return value; } }, add: function (element, interval, label, fn, times, belay) { var counter = 0; if (jQuery.isFunction(label)) { if (!times) times = fn; fn = label; label = interval; } interval = jQuery.timer.timeParse(interval); if (typeof interval != 'number' || isNaN(interval) || interval <= 0) return; if (times && times.constructor != Number) { belay = !!times; times = 0; } times = times || 0; belay = belay || false; if (!element.$timers) element.$timers = {}; if (!element.$timers[label]) element.$timers[label] = {}; fn.$timerID = fn.$timerID || this.guid++; var handler = function () { if (belay && this.inProgress) return; this.inProgress = true; if ((++counter > times && times !== 0) || fn.call(element, counter) === false) jQuery.timer.remove(element, label, fn); this.inProgress = false; }; handler.$timerID = fn.$timerID; if (!element.$timers[label][fn.$timerID]) element.$timers[label][fn.$timerID] = window.setInterval(handler, interval); if (!this.global[label]) this.global[label] = []; this.global[label].push(element); }, remove: function (element, label, fn) { var timers = element.$timers, ret; if (timers) { if (!label) { for (label in timers) this.remove(element, label, fn); } else if (timers[label]) { if (fn) { if (fn.$timerID) { window.clearInterval(timers[label][fn.$timerID]); delete timers[label][fn.$timerID]; } } else { for (var fn in timers[label]) { window.clearInterval(timers[label][fn]); delete timers[label][fn]; } } for (ret in timers[label]) break; if (!ret) { ret = null; delete timers[label]; } } for (ret in timers) break; if (!ret) element.$timers = null; } } } }); if (jQuery.browser.msie) jQuery(window).one("unload", function () { var global = jQuery.timer.global; for (var label in global) { var els = global[label], i = els.length; while (--i) jQuery.timer.remove(els[i], label); } });


