﻿/*
*author:吴增伟
*email:hdysj#126.com
*started at 2009-11-10
*@fileoverview 统一网站模板
*version:1.0
*/
var HostDefault = "http://www.mychineselearning.com";
var HostAnalysis = "http://student.mychineselearning.com";
var HostKids = "http://kds.mychineselearning.com";
var HostLesson = "http://learnchinese.mychineselearning.com";
var HostSignUp = HostDefault + "/FreeTrial/SignUp.aspx";
var HostSignUpSuccess = HostDefault + "/FreeTrial/Success.html";
var Fid = function(obj) {
    return document.getElementById(obj);
};
//是否空值
function Fempty(v) { return (("" == v || undefined == v || null == v) ? true : false); };
//优化字符串
var StringBuffer = function()
{ this._string = new Array; };
StringBuffer.prototype.append = function(str) {
    this._string.push(str);
};
StringBuffer.prototype.toString = function() {
    return this._string.join("");
};
var MCL = {};
//显示/隐藏htmlselect控件
MCL.HtmlSelect =
{
    show: function() {
        $("select").each(function() { $(this).css("visibility", "visible"); });
    },
    hide: function() {
        $("select").each(function() { $(this).css("visibility", "hidden"); });
    }

};
//弹出效果
MCL.Window = {
careatePanl: function(title, noclose) {
    if (noclose) {
        MCLTemplate.WindowsPanl.PopWindowNoClose();
    }
    else {
        MCLTemplate.WindowsPanl.PopWindow();
    }
    var height = document.body.clientHeight;
    //document.body.clientHeight;
    $("#WindowBackGround").css("display", "block");
    $("#WindowBackGround").width(document.body.clientWidth);
    $("#WindowBackGround").height(height);

    $("#Window_Msg_Container").css("display", "block");
    $("#Window_Msg_Container").css("marginLeft", (document.body.clientWidth - $("#Window_Msg_Container").width()) / 2 + "px");
    $("#Window_Msg_Container").css("marginTop", 20);
    $("#Window_Title").html(title);
    MCL.HtmlSelect.hide();

},
show: function(strform, title, width, noclose) {
    MCL.Window.careatePanl(title, noclose);
    if (typeof width != "undefined") {
        $("#Window_Msg_Container").width(width);
        // $("#Window_Msg_Container").css("marginLeft", "-345");
        // $("#Window_Msg_Container").css("marginTop", -100 + document.documentElement.scrollTop);
    }
    else {
        $("#Window_Msg_Container").width(440);
    }
    $("#Window_Msg_Container").css("marginLeft", (document.body.clientWidth - $("#Window_Msg_Container").width()) / 2 + "px");

    $("#Window_Msg_Info").css("display", "block");
    $("#Window_Msg_Info").html(strform);
    var top = (document.body.clientHeight - $("#Window_Msg_Container").height()) / 2;
    //if (top < 0) {
        top = 50;
   // }
    $("#Window_Msg_Container").css("marginTop", top + "px");

},
    hide: function() {
        $("#WindowBackGround").css("display", "none");
        $("#Window_Msg_Container").css("display", "none");
        $("#Window_Msg_Info").css("display", "none");
        //$("#Window_Msg_Info").html("");
        $("#Window_Msg").css("display", "none");
        //$("#Window_Msg").html("");
        MCL.HtmlSelect.show();
    },
    error: function(errinfo) {
        if (typeof errinfo == 'undefined') {
            errinfo = "系统忙,请稍候再操作！";
        }
        $("#Window_Msg_Info").css("display", "none");
        $("#Window_Msg").css("display", "block");
        $("#Window_Msg").html("<img src='/images/msg/error.gif' alt=''/> " + errinfo);
        setTimeout("MCL.Window.hide()", 1500);
    },
    posting: function(msg) {
        if (typeof msg == 'undefined') {
            msg = "数据提交中,请稍候...";
        }
        $("#Window_Msg_Info").css("display", "none");
        $("#Window_Msg").css("display", "block");
        $("#Window_Msg").html("<img src='/images/msg/LoadingLit.gif' alt=''/> " + msg);
    },
    loading: function(msg) {
        if (typeof msg == 'undefined') {
            msg = "数据加载中,请稍候...";
        }
        $("#Window_Msg_Info").css("display", "none");
        $("#Window_Msg").css("display", "block");
        $("#Window_Msg").html("<img src='/images/msg/LoadingLit.gif' alt=''/> " + msg);
    },
    success: function(msg, callback) {
        if (typeof msg == 'undefined') {
            msg = "操作成功！";
        }
        $("#Window_Msg_Info").css("display", "none");
        $("#Window_Msg").css("display", "block");
        $("#Window_Msg").html("<img src='/images/msg/LoadingLit.gif' alt=''/> " + msg);
        setTimeout("MCL.Window.hide();" + callback, 1500);
    },
    successref: function(msg) {
        if (typeof msg == 'undefined') {
            msg = "操作成功！";
        }
        $("#Window_Msg_Info").css("display", "none");
        $("#Window_Msg").css("display", "block");
        $("#Window_Msg").html("<img src='/images/msg/LoadingLit.gif' alt=''/> " + msg);
        setTimeout("location.replace(location.href.replace(new RegExp('#\w+','ig'),''));", 1500);
    }
};
MCL.Cookie = {
    Set: function(name, value) {
        document.cookie = name + "=" + escape(value)+";path=/;";
    },
    Get: function(name) {
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null) return unescape(arr[2]); return null;
    },
    Del: function(name) {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = MCL.Cookie.Get(name);
        if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    }
};
MCL.Message = {
    error: function(msg) {
        $("#WarpInfo").css("display", "block");
        $("#divIframe").css("display", "none");
        $("#WarpInfo>div").eq(0).css("display", "none");
        $("#WarpInfo>div").eq(2).css("display", "none");
        $("#WarpInfo>div").eq(1).css("display", "block");
        if (typeof msg != 'undefined') {
            $("#WarpInfo>div").eq(1).html(msg);
        }
        else {
            $("#WarpInfo>div").eq(1).html("You do not have the permission, please contact the administrator");
        }
    },
    parentError: function(msg) {
        if (top.location.href == self.location.href) {
            MCL.Cookie.Set("ErrorMsg", msg);
            location.href = '/';
        }
        else {
            parent.MCL.Message.error(msg);
        }
    },
    success: function(msg, url) {
        $("#WarpInfo").css("display", "block");
        $("#divIframe").css("display", "none");
        $("#WarpInfo>div").eq(1).css("display", "none");
        $("#WarpInfo>div").eq(0).css("display", "none");
        $("#WarpInfo>div").eq(2).css("display", "block");
        if (typeof msg != 'undefined') {
            $("#WarpInfo>div").eq(2).html(msg);
        }
        else {
            $("#WarpInfo>div").eq(2).html("Operation Successful");
        }
        if (typeof url == 'undefined') {
            setTimeout("MCL.Message.console()", 1000);
        }
        else {
            setTimeout("MCL.Message.console('" + url + "');", 3000);
        }
    },
    post: function(msg) {
        $("#WarpInfo").css("display", "block");
        $("#divIframe").css("display", "none");
        $("#WarpInfo>div").eq(1).css("display", "none");
        $("#WarpInfo>div").eq(2).css("display", "none");
        $("#WarpInfo>div").eq(0).css("display", "block");
        if (typeof msg != 'undefined') {
            $("#WarpInfo>div").eq(0).html(msg);
        }
        else {
            $("#WarpInfo>div").eq(0).html("Data submission, please do not refresh");
        }
    },
    console: function(url) {
        $("#WarpInfo").css("display", "none");
        $("#divIframe").css("display", "block");
        if (typeof url != 'undefined') {
            document.getElementById('iframeConsole').src = url;
        }
    }
};

MCL.Student = {};
MCL.Student.ISOCountry = {
    DataTable: null,
    init: function() {
        $.getJSON("/AJAX/GetISOCountryList.ashx", function(json) {
            if (typeof json != 'undefined') {
                drpCountry.length = 0;
                var index = 0;
                MCL.Student.ISOCountry.DataTable = json.DataTable;
                for (var i = 0; i < MCL.Student.ISOCountry.DataTable.length; i++) {
                    if (MCL.Student.ISOCountry.DataTable[i].Code == hidCountryCode.value) {
                        index = i;
                    }
                    drpCountry.options.add(new Option(MCL.Student.ISOCountry.DataTable[i].CountryName, MCL.Student.ISOCountry.DataTable[i].Code + "|" + MCL.Student.ISOCountry.DataTable[i].AreaCode));
                }
                if (hidCountryCode.value != "") {
                    drpCountry.options[index].selected = true;
                   
                    areaCode.value = drpCountry.options[index].value.split("|")[1];
                }
                else {
                    hidCountryCode.value = drpCountry.options[0].value.split("|")[0];
                    areaCode.value = drpCountry.options[0].value.split("|")[1];
                }
            }
        })
    }
};
MCL.LiveChat = {
    imgOnline: HostDefault + "/images/201006/livechat-online.gif",
    imgLeave: HostDefault + "/images/201006/livechat-offline.gif",
    init: function() {
        var strdate = new Date();
        var yyyy = strdate.getUTCFullYear();
        var MM = (strdate.getUTCMonth() + 1);
        var dd = strdate.getUTCDate();
        var hh = strdate.getUTCHours() < 10 ? "0" + strdate.getUTCHours() : strdate.getUTCHours();
        var mm = strdate.getUTCMinutes() < 10 ? "0" + strdate.getMinutes() : strdate.getUTCMinutes();
        var ss = strdate.getUTCSeconds() < 10 ? "0" + strdate.getUTCSeconds() : strdate.getUTCSeconds();
        var date1 = new Date();
        var IntervalID = "";
        if (Fid("LiveChatBg")) {
            if (date1.getHours() > 7 && date1.getHours() < 18) {
                if (IntervalID) {
                    window.clearInterval(IntervalID);
                }
                if (IntervalID == "") {
                    if (date1.getHours() == 7 && date1.getMinutes() > 30) {
                        window.setInterval("MCL.LiveChat.IsOnline()", 1000 * 60 * 5);
                    }
                    else if (date1.getHours() == 17 && date1.getMinutes() <= 30) {
                        window.setInterval("MCL.LiveChat.IsOnline()", 1000 * 60 * 5);
                    }
                    else {
                        window.setInterval("MCL.LiveChat.IsOnline()", 1000 * 60 * 60);
                    }
                }
            }
            else if (date1.getHours() > 0 && date1.getHours() < 8) {

                Fid("LiveChatBg").src = MCL.LiveChat.imgOnline;
                Fid("LiveChatBg").onclick = function() {
                    alert("There is no one is available now, please sign up for a free trial lesson.");
                    MCL.CreateLink(HostSignUp);
                }

            }
            else {
                window.setInterval(" MCL.LiveChat.IsOnline()", 1000 * 60 * 30);
            }
            MCL.LiveChat.IsOnline();
        }
    },
    IsOnline: function() {
        $.getScript(HostDefault + "/WebService/ServiceIsOnline.ashx",
    function() {
        if (ServiceOnline == "True") {
            Fid("LiveChatBg").src = MCL.LiveChat.imgOnline;
            Fid("LiveChatBg").onclick = function() {
                window.open(HostDefault + "/support.htm", "LiveSupport");
            }
        }
        else {
            Fid("LiveChatBg").src = MCL.LiveChat.imgLeave;
            Fid("LiveChatBg").onclick = function() {
                alert("There is no one is available now, please sign up for a free trial lesson.");
                MCL.CreateLink(HostSignUp);
            }
        }
        Fid("LiveChatBg").style.display = "block";
    });
    }
};
MCL.LocalUser = {
    GetLanguage: function() {
        var l = "";
        var n = navigator;

        if (n.language) {
            l = n.language.toLowerCase();
        }
        else
            if (n.browserLanguage) {
            l = n.browserLanguage.toLowerCase();
        }
        return l;
    } 
}
MCL.TimeZone =
{
    init: function() {
        $.getJSON("/AJAX/GetTimeZoneList.ashx?" + Math.random(), function(json) {

            if (typeof json != 'undefined') {
                var index = 0;

                for (var i = 0; i < json.length; i++) {
                    if (json[i].Id == hidTimeZone.value)
                        index = i;
                    drpTimeZone.options.add(new Option(json[i].DisplayName, json[i].Id));
                }
                drpTimeZone.options[index].selected = true;
            }
        });
    }
};
MCL.Init = function() { MCL.LiveChat.init(); };








