﻿ function browserinfo(){
        var Browser_Name=navigator.appName;
        var Browser_Version=parseFloat(navigator.appVersion);
        var Browser_Agent=navigator.userAgent;
        
        var Actual_Version,Actual_Name;
        
        var is_IE=(Browser_Name=="Microsoft Internet Explorer");
        var is_NN=(Browser_Name=="Netscape");
        
        if(is_NN){
            if(Browser_Version>=5.0){
                var Split_Sign=Browser_Agent.lastIndexOf("/");
                var Version=Browser_Agent.indexOf(" ",Split_Sign);
                var Bname=Browser_Agent.lastIndexOf(" ",Split_Sign);

                Actual_Version=Browser_Agent.substring(Split_Sign+1,Version);
                Actual_Name=Browser_Agent.substring(Bname+1,Split_Sign);
            }
            else{
                Actual_Version=Browser_Version;
                Actual_Name=Browser_Name;
            }
        }
        else if(is_IE){
            var Version_Start=Browser_Agent.indexOf("MSIE");
            var Version_End=Browser_Agent.indexOf(";",Version_Start);
            Actual_Version=Browser_Agent.substring(Version_Start+5,Version_End)
            Actual_Name=Browser_Name;
            
            if(Browser_Agent.indexOf("Maxthon")!=-1){
                Actual_Name+="(Maxthon)";
            }
            else if(Browser_Agent.indexOf("Opera")!=-1){
                Actual_Name="Opera";
                var tempstart=Browser_Agent.indexOf("Opera");
                var tempend=Browser_Agent.length;
                Actual_Version=Browser_Agent.substring(tempstart+6,tempend)
            }
        }
        else{
            Actual_Name="Unknown Navigator"
            Actual_Version="Unknown Version"
        }

        navigator.Actual_Name=Actual_Name;
        navigator.Actual_Version=Actual_Version;
        
        this.Name=Actual_Name;
        this.Version=Actual_Version;
}


function OpenGameWin(url)
{
    if(!IsAjaxUserLogin())
    {
        //alert("登陆后才能做练习哦，如果您还没有账号，就赶紧点击“新用户注册”吧");
        Tip("<a href=\"/login.aspx\">登录</a>后才能做练习哦，如果您还没有账号，就赶紧点击“<a href=\"/reg.aspx\">新用户注册</a>”吧");
        //ShowLogin();
        return;
    }
    
    if(!IsAjaxHasService())
    {
        //到支付入口处
        
        return;
    }    
    var content = SynGetContent(url)
    //OpenGame(content);

    OpenGameForDialog("/syncourse/play.aspx?vars="+escape(content));

}

function OpenGameForDialog(url) {
    var title = "游戏窗口";
    var Width = 1000;
    var Height = 750;
    if (screen.width < 1024 || screen.height < 768) {
        Width = 800;
        Height = 546;
    }
    if (navigator.Actual_Name == "Microsoft Internet Explorer" && navigator.Actual_Version == "6.0") {
        Height += 50;
    }
    var return_Value;
    window.showModalDialog(url, window, "dialogWidth:" + Width + "px;dialogHeight:" + Height + "px;center:yes;status:no;scroll:no;help:no;");
}

//字典窗口
function OpenWordDialog(url) {
    var title = "字典窗口";
    var Width = "638";
    if (navigator.Actual_Name == "Firefox") {
        var Height = "600";
    }
    else if (navigator.Actual_Name == "Microsoft Internet Explorer" && navigator.Actual_Version == "6.0") {
        var Height = "650";
    }
    else {
        var Height = "600";
    }
    var return_Value;
    window.showModalDialog(url, window, "dialogWidth:" + Width + "px;dialogHeight:" + Height + "px;center:yes;status:no;scroll:no;help:no;");
}
//字典flash窗口
function OpenWordFlashDialog(url) {
    var title = "字典flash窗口";
    var Width = "720";
    if (navigator.Actual_Name == "Firefox") {
        var Height = "600";
    }
    else if (navigator.Actual_Name == "Microsoft Internet Explorer" && navigator.Actual_Version == "6.0") {
        var Height = "650";
    }
    else {
        var Height = "600";
    }
    var return_Value;
    window.showModalDialog(url, window, "dialogWidth:" + Width + "px;dialogHeight:" + Height + "px;center:yes;status:no;scroll:no;help:no;");
}




function OpenFreeTelDialog(url) {
    var title = "免费电话";
    var Width = "500";
    if (navigator.Actual_Name == "Firefox") {
        var Height = "540";
    }
    else if (navigator.Actual_Name == "Microsoft Internet Explorer" && navigator.Actual_Version == "6.0") {
        var Height = "540";
    }
    else {
        var Height = "540";
    }
    var return_Value;
    //window.showModalDialog(url, window, "dialogWidth:" + Width + "px;dialogHeight:" + Height + "px;center:yes;status:no;scroll:no;help:no;");

    OpenWin(url, Width, Height, title);
}



function SynGetContent(url) {
    if (url.indexOf('?') > -1)
        url = url + "&rnd=" + Math.round(Math.random() * 9999);
    else
        url = url + "?rnd=" + Math.round(Math.random() * 9999);
    var str = $.ajax({
        url: url,
            async: false
        }).responseText;
        return str;
}

function OpenGame(content) {
    var flashWidth = 850;
    var flashHeight = 740;
    var top = (screen.height - flashHeight) / 2;
    var left = (screen.width - flashWidth) / 2;
    var height = screen.height - 140;
    if (height <= flashHeight) {
        flashHeight = height;
        flashWidth = (height / flashHeight) * flashWidth;
    }
    var html = buildFlashForVar("game", "/flash/main.swf", flashWidth, flashHeight, content,1);
    ShowBlockForKj(html, left, top);
}

function FlashClose() {
    $.unblockUI();
}

function TipClose() {
    $.unblockUI();
}

function ShowBlock(html,left,top) {
    $.blockUI({ message: html,
    css: { border: "0px", backgroundColor: 'transparent', left: left, top: top,width:0},
        overlayCSS: {
            backgroundColor: '#666',
            opacity: '0.6'
        }
        , fadeOut: 0
    });
}

function ShowBlockForKj(html, left, top) {
    $.blockUI({ message: html,
        css: { border: "0px", left: left, top: top, width: 0 },
        overlayCSS: {
            //"background-image": "url('/images/p_bg.jpg')",
            backgroundColor:"#8080FF",
            opacity: '1'
        }
        , fadeOut: 200
    });
}

function OpenGameWinForAdmin(url)
{
    var content = SynGetContent(url)
    //OpenGame(content);
    OpenGameForDialog("/syncourse/play.aspx?vars=" + escape(content));

}
    

function flash(obj, src, wid, hei)
{
	var tmp = "";
	tmp += "<object id='" + obj + "' classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 width='" + wid + "' height='" + hei +"'>";
	tmp += "<param name=movie value=" + src + ">";
	tmp += "<param name=quality value=high>";
	tmp += "<param name=wmode value=transparent>";
	tmp += "<embed id='" + obj + "' src=" + src + " quality=high pluginspage=https://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash width='" + wid + "' height='" + hei +"' wmode='transparent' allowScriptAccess=sameDomain>";
	tmp += "</object>";
	document.write (tmp);
}

function buildFlashForVar(obj, src, wid, hei, vars, isTransparent)
{
    var tmp = "";
    tmp += "<object id='" + obj + "' classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0 width='" + wid + "' height='" + hei + "'>";
    tmp += "<param name=movie value=" + src + ">";
    tmp += "<param name=quality value=high>";
    if (isTransparent == null || isTransparent == "" || isTransparent == "undefined")
        tmp += "<param name=wmode value=transparent>"; 
    
    if(vars != null && vars != "" && vars != "undefined")
        tmp += "<param name=FlashVars value='" + vars + "' />"
    tmp += "<embed id='" + obj + "' src='" + src;
    if (vars != null && vars != "" && vars != "undefined")
        tmp += "' FlashVars='" + vars;  
    tmp += "' quality=high pluginspage=https://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash type=application/x-shockwave-flash width='" + wid + "' height='" + hei + "' wmode='transparent' allowScriptAccess=sameDomain>";
    tmp += "</object>";
    return tmp;
}

function flashForVar(obj, src, wid, hei,vars) {
    var tmp = buildFlashForVar(obj, src, wid, hei,vars);
    document.write(tmp);
}

function ShowFlash(obj, src, wid, hei, vars, isTransparent) {
    var tmp = buildFlashForVar(obj, src, wid, hei, vars, isTransparent);
    document.write(tmp);
}


function OpenWin(url,width,height,name) 
    {
        xposition=0; yposition=0;
        if ((parseInt(navigator.appVersion) >= 4 ))
        {
            xposition = (screen.width - width) / 2;
            yposition = (screen.height - height) / 2;
        }
        theproperty= "width=" + width + "," 
        + "height=" + height + "," 
        + "location=0," 
        + "menubar=0,"
        + "resizable=1,"
        + "scrollbars=0,"
        + "status=0," 
        + "titlebar=0,"
        + "toolbar=0,"
        + "hotkeys=0,"
        + "screenx=" + xposition + "," //仅适用于Netscape
        + "screeny=" + yposition + "," //仅适用于Netscape
        + "left=" + xposition + "," //IE
        + "top=" + yposition; //IE
        window.open(url, name, theproperty);
}

function Trim(obj1){
	obj1 = obj1.replace(/^(\s+)|(\s+)$/g, "")
	return obj1;
}

function ValidEmpty(objInput, msgStr){
	if(Trim(objInput.value) == "") {
		alert("" + msgStr + "不能为空.");
		objInput.focus();
		return false;
	}

	return true;
}


function showPic(sUrl){ 
    var x,y; 
    x = event.clientX; 
    y = event.clientY; 
    document.getElementById("showPic").style.left = x+10; 
    document.getElementById("showPic").style.top = y+10; 
    document.getElementById("showPic").innerHTML = "<img src=\"" + sUrl + "\">"; 
    document.getElementById("showPic").style.display = "block"; 
} 
function hiddenPic(){ 
    document.getElementById("showPic").innerHTML = ""; 
    document.getElementById("showPic").style.display = "none"; 
} 


function ShowHTMLDialog(id,msg,url)
{

    var str = "    <div id=\"bg\" style=\"width:100%; background-color:Teal;margin:0;z-index:999;position:absolute;top:0;left:0;opacity:.40;filter:alpha(opacity=40);display:none\"><\/div>";
    str += "<div id=\"wnote\" style=\"z-index:1000;display:none;position:absolute;\">";
    str += "    <div id=\"wnote_top\"><img src=\"\/images\/wnote_top.gif\" \/><\/div>";
    str += "    <div id=\"wnote_main\"><p>";
    str += msg;
    str += "    </p>";
    str += "    <p><a href=\"javascript:void(0)\" onclick=\"CloseHTMLDialog('"+ id +"','" + url+ "')\"><img src=\"\/images\/btn_sure.gif\" \/></a><\/p>";
    str += "    <\/div>";
    str += "    <div id=\"wnote_bot\"><img src=\"\/images\/wnote_bot.gif\" \/><\/div>";
    str += "<\/div>";
    str += "<iframe id=\"bgframe\" scrolling=\"no\" frameborder=\"0\" style=\"position:absolute; z-index:1; left: 0px; top: 0px; width: 100%;opacity:.40;filter:alpha(opacity=40);\"></iframe>";
    document.getElementById(id).innerHTML = str;
    $('#bg').height(jQuery.iUtil.getScroll().h);
    $('#bgframe').height(jQuery.iUtil.getScroll().h);
    document.getElementById("bg").style.display="block";
    document.getElementById("wnote").style.display="block";
    size = jQuery.iUtil.getSize(document.getElementById("wnote"));
    document.getElementById("wnote").style.top = jQuery.iUtil.getScroll().t + (jQuery.iUtil.getScroll().ih-size.h)/2;
    document.getElementById("wnote").style.left = (jQuery.iUtil.getClient().w - size.w) /2;    
}


function CloseHTMLDialog(id,url)
{  
    document.getElementById("bg").style.display="none";      
    document.getElementById("wnote").style.display="none";
    document.getElementById(id).innerHTML = "";
    if(url != null && url != "" && url != "undefined")
        window.location.href = url;
}


function AjaxUserLogin()
{
    var str = $.ajax({
        url:"/common/ajaxUserLogin.aspx?rnd="+Math.round(Math.random()*9999),
        async: false                
    }).responseText;
    if(str == "1")
    {
        return true;
    }
    else
    {

        ShowLogin();
        return false;
    }
   return false;
}

function IsAjaxUserLogin()
{
    var str = $.ajax({
        url:"/common/ajaxUserLogin.aspx?rnd="+Math.round(Math.random()*9999),
        async: false                
    }).responseText;
    if(str == "1")
    {
        return true;
    }
    else {
        Tip("请填写用户名和密码后再评论！");
        return false;
    }
   return false;
}

function IsAjaxHasService()
{
    var str = $.ajax({
        url:"/common/HasService.aspx?rnd="+Math.round(Math.random()*9999),
        async: false                
    }).responseText;
    
    switch(str)
    {
        case "0":
        {
            Tip("您还没有购买哈哈学习卡，马上去<a href=\"/CardPose.aspx\">购买</a>");
             return false;
        }
        break;
        case "1":
        {
        //认证通过教师
            return true;
        }
        break;
        case "2"://未认证教师
        {
            Tip("您的资料还未认证，只有认证教师才能演示课件");
             return false;
        }
        break;
        case "3"://认证没有通过教师
        {
            Tip("您的资料认证没有通过，只有认证教师才能演示课件");
             return false;
        }
        break;
        case "4":
        {
            //认证通过教师
            return true;
        }
    }
   return false;
}




function Vote(id) {

    for (var i = 0; i < document.getElementsByName(id).length; i++) {
        if (document.getElementsByName(id)[i].checked) {
            $.ajax({
                type: "POST",
                url: "/vote.aspx",
                data: "inves=" + document.getElementsByName(id)[i].value,
                success: function(msg) {
                    location.href = "vote.aspx";
                }
            });
            break;
        }
    }

}


function Tip(content) {
    var html = "";
    html += "<div id=\"ynote\" style=\"cursor:default\">";
    html += "<div id=\"ynote_top\"><p><a href=\"/index.aspx\" onclick=\"TipClose();return false\"><img src=\"\/images\/gclose.gif\" \/><\/a><\/p><\/div>";
    html += "<div  id=\"ynote_bg\" style=\"width:100%; height:50px; text-align:center; margin-left:auto; margin-right:auto;\"> ";
    html += "    <div style=\"text-align:center;  width:80%; margin-top:-10px; \"> ";
    html += "       <p style=\" width:90%; \">" + content + "<\/p> ";
    html += "    <\/div>";
    html += " <\/div>";
    html += "    <div id=\"ynote_bot\"> <p><a href=\"/index.aspx\" onclick=\"TipClose();return false\"><img src=\"\/images\/ysure.gif\" \/><\/a><\/p><\/div>";
    html += " <\/div>";
    //size = jQuery.iUtil.getSize(document.getElementById("ynote"));
    var top = (jQuery.iUtil.getScroll().ih - 400) / 2;
    var left = (jQuery.iUtil.getClient().w - 380) / 2;    
    ShowBlock(html,left,top)
}


function ShowLogin() {
    var html = "";
    html += " <div id=\"ynote\" style=\"cursor:default\">";
    html += "    <div id=\"ynote_login\"><p><a href=\"/index.aspx\" onclick=\"TipClose();return false\"><img src=\"\/images\/gclose.gif\" \/><\/a><\/p><\/div>";
    html += "    <div id=\"ynote_bg\" style=\"float:left; padding-left:30px\"> ";
    html += "         <p>用户名：<input name=\"txtCusName_ajax\" type=\"text\" id=\"txtCusName_ajax\" style=\"width:180px\"\/><br \/>";
    html += "            密&nbsp;&nbsp;&nbsp;码：<input name=\"txtPwd_ajax\" type=\"password\" id=\"txtPwd_ajax\" style=\"width:180px\"\/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br \/>";

    html += "           验证码：<input name=\"txtValidate_ajax\" type=\"text\" id=\"txtValidate_ajax\" style=\"width:100px\" \/><span stype=\" height:20px\">&nbsp;&nbsp;<img alt=\"看不清？点击换下一张\" id=\"validateCode\" src=\"/common\/VaImage.aspx\" onclick=\"refreshValidateCodeImage(this,\'/common\/VaImage.aspx\')\" \/></span>";
    html += "             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ";
    html += "         <br \/>新来的小朋友，马上<a href=\"\/reg.aspx\">注册<\/a>加入哈哈家族！";
    html += "         <\/p>";
    html += "    <\/div>";
    html += "    <div id=\"ynote_bot\"  style=\"float:left\"><p><a href=\"javascript:void(0);\" onclick=\"AjaxLogin();return false;\"><img src=\"\/images\/ymenu_login.gif\" \/><\/a>&nbsp;&nbsp;<a href=\"/index.aspx\" onclick=\"TipClose();return false\"><img src=\"\/images\/y_close.gif\" \/><\/a><\/p><\/div>";
    html += " <\/div>";

    var top = (jQuery.iUtil.getScroll().ih - 400) / 2;
    var left = (jQuery.iUtil.getClient().w - 380) / 2;
    ShowBlock(html, left, top)
    refreshValidateCodeImage(document.getElementById("validateCode"), '/common\/VaImage.aspx');
}


function refreshValidateCodeImage(ValidateCodeImageControl, NewUrl) {
    ValidateCodeImageControl.src = NewUrl + '?code=' + randomNum(10);
}

function randomNum(n) {
    var rnd = '';
    for (var i = 0; i < n; i++)
        rnd += Math.floor(Math.random() * 10);
    return rnd;
}

function AjaxLogin() {
    var cusvalidate = /^[a-zA-Z0-9_\u4e00-\u9fa5]+$/;
    var tname = document.getElementById("txtCusName_ajax").value;
    var tpwd = document.getElementById("txtPwd_ajax").value;
    var tvali = document.getElementById("txtValidate_ajax").value;
    if (tname == "" || tpwd == "") {
        alert("用户名密码不能为空！");
        return;
    }
    else if (tvali == "") {
        alert("验证码不能为空！");
        return;
    }
    else if (!cusvalidate.test(tname)) {
        alert("用户名不能输入特殊字符！");
        return;
    }

    $.ajax({
        type: "POST",
        url: "/common/ajaxLogin.aspx",
        data: "txtCusName=" + tname + "&txtPwd=" + tpwd + "&txtValidate=" + tvali,
        success: function(msg) {
            if (msg != "") {
                alert(msg);
            }
            else {
                window.location.reload();
            }
        }
    });
    return false;
}

