﻿var studyType;
var type;
var isguess = false;
var isstudy = false;
var siteId = 1;

function Validator(id, st, t,sid) {
    studyType = st;
    type = t;
    siteId = sid;
    var sta = UserCheck();
    if (sta == 0) {
        OpenLogin(id);
    } 
    else {
        if (studyType == 3 || (type > 3 && type !=6)) {
            alert("此功能不提供免费试用!");
        }
        else if (type == 6) {
		studyType  = 3;
            OpenExam(0);
            alert("免费考前押题共1套,如需更多精准考前押题请联系网站客服!");
        }
        else {
            if (id > 0) {
                OpenExam(" + id + ");
                alert("免费试用只针对第一章节的第一套试题!");
            }
            else {
                OpenExam(id);
            }
        }
    }
}

function GuessQueValidator() {
    alert("此功能不对免费试用开放!");
}

function SendGuessQueValidator() {
    alert("请到正式页面获取赠送押题!");
    window.location.href = "http://exam.bkw.cn/jinrong/";
}

function OpenLogin(id) {
    var loginHref = "../IframeLogin.aspx?cid=" + cid + "&uid=" + id + "&rand=" + Math.random();
    $.fn.colorbox({
        href: loginHref,
        width: "400px",
        height: "280px",
        opacity: "0.3",
        iframe: true,
        onClosed: function() {
            if (control) {
                if (UserCheck() > 0) {
                    Validator(id, studyType, type,siteId);
                    LoginCheck();
                }
            }
        }
    });
}

//function OpenCourse(id) {

//    var courseHref = "../IframeOpenCourse.aspx?cid=" + cid + "&rand=" + Math.random();
//    $.fn.colorbox({
//        href: courseHref,
//        width: "775",
//        height: "435",
//        opacity: "0.3",
//        scrolling: true,
//        iframe: true,
//        onClosed: function() {
//            if (control) {
//                state = UserCheck();
//                if (state != 11 && state != 15) {
//                    Validator(id, studyType, type,siteId);
//                }
//            }
//        }
//    });
//}

function OpenCourse(id, m) {
    UserCheck(function (sta) {
        if (sta == 0) {
            LoginAll();
        }
        else {
            var courseHref = "../Ajax/Redirect.ashx?cid=" + cid + "&m=" + m;
            window.open(courseHref);
        }
    });
}

function OpenExam(id) {
    var answerHref = "../OLSv5.0.html?mid=" + mid + "&cid=" + cid + "&uid=" + id + "&stype=" + studyType + "&type=" + type + "&target=free" + "&siteId=" + siteId + "&rand=" + Math.random();
    $.fn.colorbox({
        href: answerHref,
        iframe: true,
        width: "870px",
        height: "687px",
        onClosed: function() {
            OpenConsultant();
        }
    });
}

function OpenConsultant() {
    var answerHref = "../IframeOpenConsultant.aspx";
    $.fn.colorbox({
        href: answerHref,
        iframe: true,
        width: "264px",
        height: "310px"
    });
}

function UserCheck() {
    var result = 0;
    $.ajax({
        url: "../Ajax/UserCheck.ashx",
        type: 'get',
        data: "cid=" + cid + "&rand=" + Math.random(),
        async: false,
        success: function(str) { result = str; }
    });
    return result;
}

function ClosePage() {
    if (isstudy) {
        $.ajax({
            url: '../Ajax/SaveStudyRecord.ashx',
            type: 'post',
            async: true,
            cache: false,
            data: "mid=" + mid + "&cid=" + cid + "&uid=0&t=0&type=" + type + "&rand=" + Math.random()
        });
    }
}
