﻿var HostDefault = "http://www.mychineselearning.com";
var HostAnalysis = "http://student.mychineselearning.com";
var HostKids = "http://kids.mychineselearning.com";
var HostLesson = "http://learnchinese.mychineselearning.com";
var HostService = "http://www.mychineselearning.com/WebService/";
var HostSignUp = HostDefault + "/FreeTrial/SignUp.aspx";
var HostSignUpSuccess = HostDefault + "/FreeTrial/Success.html";
var HostVoice = "http://www1.mychineselearning.com:81";
var ContactMode = 1;

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 = {};
MCL.HtmlSelect =
{
    show: function() {
        $("select").each(function() { $(this).css("visibility", "visible"); });
    },
    hide: function() {
        $("select").each(function() { $(this).css("visibility", "hidden"); });
    }

};
MCL.UTC = {
    tm: function() {
        var ed = new Date();
        var now = parseInt(ed.getTime());

        var et = (86400 - ed.getHours() * 3600 - ed.getMinutes() * 60 - ed.getSeconds());
        ed.setTime(now + 1000 * (et - ed.getTimezoneOffset() * 60));
        return ed.toGMTString();
    },
    now: function() {
        var ed = new Date();
        var now = parseInt(ed.getTime());

        var et = (86400 - ed.getHours() * 3600 - ed.getMinutes() * 60 - ed.getSeconds());
        ed.setTime(now + 1000 * 86400 * 182);
        return ed.toGMTString();
    }
};
MCL.Cookie = {
    Get: function(name) {
        var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
        if (arr != null)
            return unescape(arr[2]);
        return "";
    },
    Set: function(name, val, cotp) {
        var date =new Date();
        var cookie = "";
        if (cotp == 0) {
            cookie = name + "=" + val + ";";
        }
        else if (cotp == 1) {
            var datey = new Date((date.getFullYear() + 5), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());
            cookie = name + "=" + val + ";expires=" + datey.toGMTString() + ";";
        }
        else if (cotp == 2) {
            var datey = new Date(date.getFullYear(), date.getMonth(), date.getDate(), (date.getHours() + 1), date.getMinutes(), date.getSeconds());
            cookie = name + "=" + val + ";expires=" + datey.toGMTString() + ";";
        }
        else if (cotp == 3) {
            cookie = name + "=" + val + ";expires=" + MCL.UTC.tm() + ";";
        }
        var d = "mychineselearning.com"; //MCL.Domain.Get(document.domain);
        if (d != "") {
            cookie += "domain=." + d + ";";
        }
        cookie += "path=" + "/;";
        document.cookie = cookie;
    }

};
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;
    },
    GetScreen: function() {
        var c = "";

        if (self.screen) {
            c = screen.width + "x" + screen.height;
        }

        return c;
    },
    GetAgent: function() {
        var a = "";
        var n = navigator;

        if (n.userAgent) {
            a = n.userAgent;
        }

        return a;
    },
    GetCookieEnabled: function() {
        var c = "";
        var n = navigator;
        c = n.cookieEnabled ? 1 : 0;

        return c;
    },
    GetTimeZoneOffset: function() {
        return new Date().getTimezoneOffset() / 60 * -1;
    }
};


MCL.Domain = {
    lz_c_ctry_top_domain: function(str) {
        var pattern = "/^aero$|^cat$|^coop$|^int$|^museum$|^pro$|^travel$|^xxx$|^com$|^net$|^gov$|^org$|^mil$|^edu$|^biz$|^info$|^name$|^ac$|^mil$|^co$|^ed$|^gv$|^nt$|^bj$|^hz$|^sh$|^tj$|^cq$|^he$|^nm$|^ln$|^jl$|^hl$|^js$|^zj$|^ah$|^hb$|^hn$|^gd$|^gx$|^hi$|^sc$|^gz$|^yn$|^xz$|^sn$|^gs$|^qh$|^nx$|^xj$|^tw$|^hk$|^mo$|^fj$|^ha$|^jx$|^sd$|^sx$/i";

        if (str.match(pattern)) { return 1; }

        return 0;
    },
    lz_c_ctry_domain: function(str) {
        var pattern = "/^ac$|^ad$|^ae$|^af$|^ag$|^ai$|^al$|^am$|^an$|^ao$|^aq$|^ar$|^as$|^at$|^au$|^aw$|^az$|^ba$|^bb$|^bd$|^be$|^bf$|^bg$|^bh$|^bi$|^bj$|^bm$|^bo$|^br$|^bs$|^bt$|^bv$|^bw$|^by$|^bz$|^ca$|^cc$|^cd$|^cf$|^cg$|^ch$|^ci$|^ck$|^cl$|^cm$|^cn$|^co$|^cr$|^cs$|^cu$|^cv$|^cx$|^cy$|^cz$|^de$|^dj$|^dk$|^dm$|^do$|^dz$|^ec$|^ee$|^eg$|^eh$|^er$|^es$|^et$|^eu$|^fi$|^fj$|^fk$|^fm$|^fo$|^fr$|^ly$|^hk$|^hm$|^hn$|^hr$|^ht$|^hu$|^id$|^ie$|^il$|^im$|^in$|^io$|^ir$|^is$|^it$|^je$|^jm$|^jo$|^jp$|^ke$|^kg$|^kh$|^ki$|^km$|^kn$|^kp$|^kr$|^kw$|^ky$|^kz$|^la$|^lb$|^lc$|^li$|^lk$|^lr$|^ls$|^lt$|^lu$|^lv$|^ly$|^ga$|^gb$|^gd$|^ge$|^gf$|^gg$|^gh$|^gi$|^gl$|^gm$|^gn$|^gp$|^gq$|^gr$|^gs$|^gt$|^gu$|^gw$|^gy$|^ma$|^mc$|^md$|^mg$|^mh$|^mk$|^ml$|^mm$|^mn$|^mo$|^mp$|^mq$|^mr$|^ms$|^mt$|^mu$|^mv$|^mw$|^mx$|^my$|^mz$|^na$|^nc$|^ne$|^nf$|^ng$|^ni$|^nl$|^no$|^np$|^nr$|^nu$|^nz$|^om$|^re$|^ro$|^ru$|^rw$|^pa$|^pe$|^pf$|^pg$|^ph$|^pk$|^pl$|^pm$|^pr$|^ps$|^pt$|^pw$|^py$|^qa$|^wf$|^ws$|^sa$|^sb$|^sc$|^sd$|^se$|^sg$|^sh$|^si$|^sj$|^sk$|^sl$|^sm$|^sn$|^so$|^sr$|^st$|^su$|^sv$|^sy$|^sz$|^tc$|^td$|^tf$|^th$|^tg$|^tj$|^tk$|^tm$|^tn$|^to$|^tp$|^tr$|^tt$|^tv$|^tw$|^tz$|^ua$|^ug$|^uk$|^um$|^us$|^uy$|^uz$|^va$|^vc$|^ve$|^vg$|^vi$|^vn$|^vu$|^ye$|^yt$|^yu$|^za$|^zm$|^zr$|^zw$/i";

        if (str.match(pattern)) { return 1; }

        return 0;
    },
    Get: function(host) {
        var d = host.replace(/^www\./, "");

        var ss = d.split(".");
        var l = ss.length;

        if (l == 3) {
            if (MCL.Domain.lz_c_ctry_top_domain(ss[1]) && MCL.Domain.lz_c_ctry_domain(ss[2])) {
            }
            else {
                d = ss[1] + "." + ss[2];
            }
        }
        else if (l >= 3) {

            var ip_pat = "^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$";

            if (host.match(ip_pat)) {
                return d;
            }

            if (MCL.Domain.lz_c_ctry_top_domain(ss[l - 2]) && MCL.Domain.lz_c_ctry_domain(ss[l - 1])) {
                d = ss[l - 3] + "." + ss[l - 2] + "." + ss[l - 1];
            }
            else {
                d = ss[l - 2] + "." + ss[l - 1];
            }
        }

        return d;
    }
};
MCL.Country = {
    Load: function() {
        $.getScript(HostDefault+"/script/Country.js", function() {
            var indexed = 0;
            var lang = MCL.LocalUser.GetLanguage();
            if (lang.indexOf("-") > 0) {
                lang = lang.split("-")[1];
            }
            for (var i = 0; i < country.DataTable.length; i++) {
                if (country.DataTable[i].Code.toLowerCase() == lang) {
                    indexed = i;

                }
                Fid("txtSignNationality").options.add(new Option(country.DataTable[i].CountryName, country.DataTable[i].Code + "|" + country.DataTable[i].AreaCode));
            }
            Fid("txtSignNationality").options[indexed].selected = true;
            Fid("txtSignAreaCode").value = Fid("txtSignNationality").options[indexed].value.split("|")[1];
            Fid("hidCountryID").value = Fid("txtSignNationality").options[indexed].value.split("|")[0];
        });

    }

};
//弹出效果
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", -50 + document.documentElement.scrollTop);
        $("#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).width() - $("#Window_Msg_Container").width()) / 2 + "px");

        $("#Window_Msg_Info").css("display", "block");
        $("#Window_Msg").css("display", "none");
        $("#Window_Msg_Info").html(strform);
        var top = (document.documentElement.clientHeight - $("#Window_Msg_Container").height()) / 2+ $(document).scrollTop();
        if (top < 0) {
            top = 10;
        }
        $("#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 = "System is busy, please try again later!";
        }
        $("#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 = "Data submission, please wait a moment...";
        }
        $("#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 = "Data loading, please wait a moment...";
        }
        $("#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 = "Successful operation!";
        }
        $("#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 = "Successful operation!";
        }
        $("#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);
        setTimeout("document.getElementById('iframeConsole').document.location.reload()", 1500);
    }
};
MCL.SignUp = function(obj) {
    this.objectName = obj;
    this.isBlank = false;
    this.isReadUVID = true;
    this.isManualUncoode = false;
    this.ManualUncode = "";

    this.getObjectName = function() { return this.objectName; };
    this.Check = function() {

        if (Fid(this.objectName.LinkName) && Fid(this.objectName.Email)) {
            var regName = /\w+/;
            var regEmail = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
            var regAreaCode = /\d{1,4}/;
            var regPhone = /(\d{3,4}([ |\-])?){2,4}/;
            var vaild = true;
            var temp = "";
            if ($.trim(Fid(this.objectName.LinkName).value) == "") {
                temp = "Please fill your name.\n";
                vaild = false;
            }
            if (!regEmail.test(Fid(this.objectName.Email).value)) {
                temp = temp + "The email address entered is incorrectly formatted.!\n";
                vaild = false;
            }
            if (!regAreaCode.test(Fid(this.objectName.AreaCode).value)) {
                temp = temp + "IDD Code is requaired 1-4 digits in length!\n";
                vaild = false;
            }
            if (!regPhone.test(Fid(this.objectName.Tel).value)) {
                temp = temp + "Phone number is 6 digits at least in length!\n";
                vaild = false;
            }
            if (Fid(this.objectName.InvitationCode)) {
                if (Fid(this.objectName.InvitationCode).value != "") {
                    if (!regName.test(Fid(this.objectName.InvitationCode).value)) {

                        temp = temp + "Please fill correct Invitation Code!\n";
                        vaild = false;
                    }
                }
            }
            if (!vaild) {
                alert(temp);
            }
            return vaild;
        }
        else {
            alert("Registration failed1");
            MCL.CreateLink(HostSignUp, this.isBlank);
        }
    };
    this.getValue = function(objName) {
        var value = "";
        if (typeof objName == "string") {
            if (Fid(objName)) {
                if (Fid(objName).type == "checkbox" || Fid(objName).type == "radio") {
                    value = Fid(objName).checked;
                }
                else {
                    value = Fid(objName).value;
                }
            }
        }
        return value;
    };
    this.Post = function() {
        if (!this.Check()) {
            return;
        }
        if (!Fid(this.objectName.LinkName)) {
            MCL.CreateLink(HostSignUp);
            return;
        }
        if (!Fid(this.objectName.Email)) {
            MCL.CreateLink(HostSignUp);
            return;
        }
        var isblank = this.isBlank;
        var _email = this.getValue(this.objectName.Email); ;
        var par = "linkName=" + this.getValue(this.objectName.LinkName) + "&email=" + this.getValue(this.objectName.Email);
        par = par + "&area=" + this.getValue(this.objectName.AreaCode) + "&phone=" + this.getValue(this.objectName.Tel);
        if (this.isManualUncoode) {
            par = par + "&UnionCode=" + this.ManualUncode;
        }
        par = par + "&InvitationCode=" + this.getValue(this.objectName.InvitationCode);
        par = par + "&IsGroup=" + this.getValue(this.objectName.GroupID);

        par = par + "&country=" + this.getValue(this.objectName.CountryCode);
        par = par + "&timeoffset=" + MCL.LocalUser.GetTimeZoneOffset();
        par = par + "&OccupationAim=" + escape(this.getValue(this.objectName.OccupationAim));
      
        if (this.isReadUVID) {
            par = par + "&uvid=" + MCL.Cookie.Get("MCL_UV");
        }
        //alert(par);
        var postmsg = "<img src=\"" + HostDefault + "/images/LiveLoading.gif\" alt='' style='float:left;'/> Posting SignUp ...";
        $("#" + this.objectName.ButtonSubmit).parent().append(postmsg);
        $("#" + this.objectName.ButtonSubmit).css("display", "none");
        $.getScript(HostService + "SignUp.ashx?" + par, function() {
            if (SignUpMsg == "OK") {
                alert("Thank you for signing up at MyChineseLearning.com. Your course consultant will contact you soon.");
                MCL.CreateLink(HostSignUpSuccess + "?email=" + _email, isblank);

            }
            else {
                alert("Registration failed" + isblank);
                MCL.CreateLink(HostSignUp, isblank);
            }
        });
    };
    this.init = function() {
        if (typeof obj == 'undefined') {
            this.objectName = { LinkName: "txtSignName", Email: "txtSignEmail", AreaCode: "txtSignAreaCode", Tel: "txtSignPhone", Nationality: "txtSignNationality", CountryCode: "hidCountryID", InvitationCode: "txtSignCode", GroupID: "chkIsGroup", ButtonSubmit: "SignSubmit", AjaxPannel: "SignPost",OccupationAim: "txtOccupationAim" };
        }
        var objectparent = this;
        if (typeof this.objectName.ButtonSubmit == "string") {
            if (Fid(this.objectName.ButtonSubmit)) {
                Fid(this.objectName.ButtonSubmit).onclick = function() { objectparent.Post(); };
            }
        }
        if (typeof this.objectName.CountryCode == 'undefined' || typeof this.objectName.AreaCode == 'undefined' || typeof this.objectName.Nationality == 'undefined') {
            if (typeof this.objectName.ButtonSubmit == "string") {
                if (Fid(this.objectName.ButtonSubmit)) {
                    Fid(this.objectName.ButtonSubmit).onclick = function() { MCL.CreateLink(HostSignUp); };
                }
            }
            return;
        }
        if (Fid(objectparent.objectName.Nationality)) {
            $.getScript(HostDefault + "/script/Country.js", function() {
                var indexed = 0;
                var lang = MCL.LocalUser.GetLanguage();
                if (lang.indexOf("-") > 0) {
                    lang = lang.split("-")[1];
                }
                for (var i = 0; i < country.DataTable.length; i++) {
                    if (country.DataTable[i].Code.toLowerCase() == lang) {
                        indexed = i;

                    }
                    Fid(objectparent.objectName.Nationality).options.add(new Option(country.DataTable[i].CountryName, country.DataTable[i].Code + "|" + country.DataTable[i].AreaCode));
                }
                Fid(objectparent.objectName.Nationality).options[indexed].selected = true;
                Fid(objectparent.objectName.AreaCode).value = Fid(objectparent.objectName.Nationality).options[indexed].value.split("|")[1];
                Fid(objectparent.objectName.CountryCode).value = Fid(objectparent.objectName.Nationality).options[indexed].value.split("|")[0];
            });
            Fid(objectparent.objectName.Nationality).onchange = function() {
                Fid(objectparent.objectName.AreaCode).value = this.value.split("|")[1];
                Fid(objectparent.objectName.CountryCode).value = this.value.split("|")[0];
            }
        }

    };
};
MCL.Encode = function(str) {
    var e = "", i = 0;

    for (i = 0; i < str.length; i++) {
        if (str.charCodeAt(i) >= 0 && str.charCodeAt(i) <= 255) {
            e = e + escape(str.charAt(i));
        }
        else {
            e = e + str.charAt(i);
        }
    }

    return e;
};
MCL.Analysis = function() {
    try {
        var expire_time = 1800;
        var host = document.location.host;
        var domain = host;
        var path = "http://www.mychineselearning.com/webservice/Analysis.ashx";
        var hashval = 0;
        for (i = 0; i < domain.length; i++) {
            hashval += domain.charCodeAt(i);
        }

        var uv_id = MCL.Cookie.Get("MCL_UV");
        var uv_new = 0;
        if (uv_id == "") {
            uv_new = 1;

            var rand1 = parseInt(Math.random() * 4000000000);
            var rand2 = parseInt(Math.random() * 4000000000);
            uv_id = String(rand1) + String(rand2);

            MCL.Cookie.Set("MCL_UV", uv_id, 1);
        }

        var ref = document.referrer;
        ref = MCL.Encode(String(ref));

        var url = document.URL;
        url = MCL.Encode(String(url));

        var title = document.title;
        title = escape(String(title));
        var repeat = MCL.Cookie.Get("AI_repeat");
        if (repeat == "") {
            repeat = 0;
        }
        else {
            repeat = parseInt(repeat) + 1;
        }
        MCL.Cookie.Set("AI_repeat", repeat, 2);
        var charset = document.charset;
        charset = MCL.Encode(String(charset));
        var agent = MCL.LocalUser.GetAgent();
        agent = MCL.Encode(String(agent));
        var screen = MCL.LocalUser.GetScreen();
        screen = MCL.Encode(String(screen));
        var language = MCL.LocalUser.GetLanguage();
        language = MCL.Encode(language);
        var timezoneOffset = MCL.LocalUser.GetTimeZoneOffset();
        dest = path + "?uv_id=" + uv_id + "&repeat=" + repeat + "&uv_new=" + uv_new + "&ref=" + escape(ref) + "&url=" + escape(url) + "&screen=" + escape(screen) + "&charset=" + escape(charset) + "&domain=" + escape(domain);
        dest = dest + "&language=" + escape(language) + "&timezoneOffset=" + escape(timezoneOffset) + "&cnu=" + String(Math.random());
         if (document.URL.indexOf("?debug")>0)
         { alert(dest); } 
       document.write("<img src=\"" + dest + "\" border=\"0\" width=\"0\" height=\"0\" >");
    } 
    catch (e) { 
    }

};
MCL.Dict = {
    Search: function() {
        if ($.trim(Fid("DictSearchTxt").value) != "") {
            var txtvalue = $.trim(Fid("DictSearchTxt").value).replace("'", "").replace("´", ""); ;
            if (txtvalue != "")
                var regenglish = /([a-zA-Z]|\s)+/;
            if (regenglish.test(txtvalue)) {
                location.href = HostDefault + '/endict/' + txtvalue;
            }
            else {
                location.href = HostDefault + '/dict/' + txtvalue;
            }
        }

    },
    MusicInit: function(code) {
    var url = HostDefault + "/data/dict/mp3/" + code + ".mp3";
       // var flash = MCL.Flash.Mp3(url,false,false);
        //Fid("flashPlayer").innerHTML = flash;
        document.write(flash);
    },
    AutoComplate: function(txt) {
        var regenglish = /([a-zA-Z]|\s)+/;
        if (regenglish.test(txt)) {
            $.ajax({ type: "POST", url: HostService + "getenglishdict.ashx", data: "key=" + txt, dataType: "json", error: function() { alert(); }, success: function(json) { MCL.Dict.AutoComlateHandler(json, txt, 'en'); } });
        }
        else {
            $.ajax({ type: "POST", url: HostService + "getdictchinese.ashx", data: "key=" + txt, dataType: "json", error: function() { alert(); }, success: function(json) { MCL.Dict.AutoComlateHandler(json, txt, 'zh'); } });
        }
    },
    AutoComlateHandler: function(Json, key, type) {
        key = key.toLowerCase();
        $("#AutoComplate").css("display", "none");
        if (typeof Json != 'undefined') {

            var temp = "";
            var objhref = HostDefault + '/endict/';
            if (type == "zh") {
                objhref = HostDefault + '/dict/';
            }
            if (Json.DataTable.length > 0) {
                for (var i = 0; i < Json.DataTable.length; i++) {
                    var charobj = Json.DataTable[i].source.replace("´", "'");
                    temp = temp + "<a href='#' onclick='location.href=\"" + objhref + charobj + "\"'>" + charobj.toLowerCase().replace(key, "<span>" + key + "</span>") + "</a>";
                }
                $("#AutoComplate").css("display", "block");
                $("#AutoComplate").html(temp);
            }

        }
    }
};
MCL.Flash = {
    Mp3: function(url, isauto, isreplay) {
        var autoplay = 0;
        var autoreplay = 1;
        if (typeof isauto == 'undefined') {
            isauto = true;
        }
        if (typeof isreplay == 'undefined') {
            isreplay = true;
        }
        if (isauto == true) {
            autoplay = 1;
        }
        else {
            autoplay = 0;
        }
        if (isreplay) {
            autoreplay = 1;
        }
        else {
            autoreplay = 0;
        }

        var flash = "";
        flash = flash + '<object type="application/x-shockwave-flash" data="' + HostDefault + '/video/dewplayer-mini.swf" width="20" height="20" id="dewplayermini" name="dewplayermini">';
        flash = flash + '<param name="movie" value="' + HostDefault + '/video/dewplayer-mini.swf" />';
        flash = flash + '<param name="wmode" value="transparent"> ';
        flash = flash + '<param name="flashvars" value="mp3=' + url + '&amp;autostart='+autoplay+'&amp;autoreplay='+autoreplay+'" />';
        flash = flash + '</object>';
        return flash;
    }
};
MCL.FlashPlayer = {
    getFlashObject: function(movieName) {
        if (window.document[movieName]) {
            return window.document[movieName];
        }
        if (navigator.appName.indexOf("Microsoft Internet") == -1) {
            if (document.embeds && document.embeds[movieName])
                return document.embeds[movieName];
        }
        else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
        {
            return document.getElementById(movieName);
        }
    },

    play: function(c) {
        this.init()
        var asound = MCL.Voice.getFlashObject("asound");
        if (asound) {
            asound.SetVariable("f", c);
            asound.GotoFrame(1);
        }
    },

    stop: function() {
        var asound = MCL.Voice.getFlashObject("asound");
        if (asound) {
            asound.GotoFrame(3);
        }
    },

    init: function() {
        if (!document.getElementById("asound")) {
            var html_object = "<object style=\"height:0px;width:0px;overflow:hidden;\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"0\" height=\"0\" id=\"asound\" align=\"absmiddle\">";
            html_object = html_object + "<param name=\"allowScriptAccess\" value=\"sameDomain\" />";
            html_object = html_object + "<param name=\"movie\" value=\"/video/asound.swf\" /><param name=\"quality\" value=\"high\" />";
            html_object = html_object + "<embed src=\"/video/asound.swf\" quality=\"high\" width=\"0\" height=\"0\" name=\"asound\" align=\"absmiddle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />";
            html_object = html_object + "</object>";
            $("body").append(html_object);
        }
    }
};
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(HostService + "ServiceIsOnline.ashx",
    function() {
        if (ServiceOnline == "True") {
            Fid("LiveChatBg").src = MCL.LiveChat.imgOnline;
            Fid("LiveChatBg").onclick = function() {
            window.open("http://chat.mychineselearning.com/client.php ", "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.Bookmark = function() {
    if (window.sidebar) {
        window.sidebar.addPanel("MyChineselearning", HostDefault, "");
    }
    else if (document.all) {
    window.external.AddFavorite(HostDefault, "MyChineselearning");
    }
};
MCL.CreateLink = function(url, isblank) {
    var referLink = document.createElement('a');
    referLink.href = url;
    referLink.id = "GlobalLinks"
    var istop = false;
    if (typeof isblank == 'undefined') {
    }
    else {
        if (isblank) {
            referLink.target = "_top"
            istop = true;
        }
    }
    document.body.appendChild(referLink);
    if (document.all) {
        referLink.click();
    }
    else {
        if (istop) {
            parent.location.href = url;
        }
        else {
            location.href = url;
        }
    }
};
MCL.Account = {
    StudentID: 0,
    Email: "",
    LinkName: "",
    Login: function() {
    MCL.Window.show("<iframe src='/Login.aspx' frameborder=\"0\" width=\"100%\" ></iframe>", "Please log in to continue", 400);
    },
    IsLogin: function() {
        $.getScript(HostService + "islogin.ashx");
    }
};
MCL.Init = function() {
try{
    //****************************/
    //默认注册按钮
    var defaultSignUp = new MCL.SignUp();
    defaultSignUp.init();
    //****************************/
    if (Fid("DictSearchTxt")) {
        $("#DictSearchTxt").bind("keyup", function(event) {
            var txtvalue = $.trim(this.value).replace("'", "").replace("´", "");
            if (event.keyCode == 13) {
                MCL.Dict.Search();

            }
            if ($.trim(this.value) != "") {
                MCL.Dict.AutoComplate(txtvalue);
            }
            else {
                $("#AutoComplate").css("display", "none");
            }
            return;
        });

    }
    if (typeof hidUVID != 'undefined') {
        hidUVID.value = MCL.Cookie.Get("MCL_UV");
        hidTimeOffSet.value = MCL.LocalUser.GetTimeZoneOffset();
    }
    if (document.URL.indexOf("?debug=zengwei") > 0) {
        alert(country.DataTable[0].CountryName);
    }
   
    MCL.LiveChat.init();
    }
    catch(e)
    {}

};

