﻿function selectTag(tagName, bodyName, tagNum, tagIndex, nomalStyle, curStyle) {
    // 标签
    for (i = 1; i <= tagNum; i++) {
        document.getElementById(tagName + i).className = nomalStyle;
    }
    document.getElementById(tagName + tagIndex).className = curStyle;
    // 标签内容
    for (i = 1; j = document.getElementById(bodyName + i); i++) {
        j.style.display = "none";
    }
    document.getElementById(bodyName + tagIndex).style.display = "block";
}
var getFFVersion = navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
//extra height in px to add to iframe in FireFox 1.0+ browsers
var FFextraHeight = getFFVersion >= 0.1 ? 16 : 0
function dyniframesize(iframename) {
    var pTar = null;
    if (document.getElementById) {
        pTar = document.getElementById(iframename);
    }
    else {
        eval('pTar = ' + iframename + ';');
    }
    if (pTar && !window.opera) {
        //begin resizing iframe
        pTar.style.display = "block"

        if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) {
            //ns6 syntax
            pTar.height = pTar.contentDocument.body.offsetHeight + FFextraHeight;
        }
        else
            if (pTar.Document && pTar.Document.body.scrollHeight) {
                //ie5+ syntax
                pTar.height = pTar.Document.body.scrollHeight;
            }
    }
}
//课堂主页事件
function toolBar_MOver(tbNo) {
    document.getElementById("tool" + tbNo).className = "tool" + tbNo + "_MOver";
}
function toolBar_MOut(tbNo) {
    document.getElementById("tool" + tbNo).className = "tool" + tbNo + "_MOut";
}
function gotoKT(ktName) {
    window.open("http://www.ztone.cc/StudyCenter/" + ktName);
}
function AutoResizeImage(maxWidth, maxHeight, objImg) {
    if (typeof (objImg) == 'string') {
        objImg = $(objImg);
    }
    var img = new Image();
    img.onload = function () {
        var hRatio;
        var wRatio;
        var Ratio = 1;
        var w = img.width;
        var h = img.height;
        wRatio = maxWidth / w;
        hRatio = maxHeight / h;
        wRatio = wRatio > 1 ? 1 : wRatio;
        hRatio = hRatio > 1 ? 1 : hRatio;
        if (maxWidth == 0 && maxHeight == 0) {
            Ratio = 1;
        }
        else if (maxWidth == 0) {//
            if (hRatio < 1) Ratio = hRatio;
        } else if (maxHeight == 0) {
            if (wRatio < 1) Ratio = wRatio;
        } else {
            Ratio = (wRatio <= hRatio ? wRatio : hRatio);
        }
        if (Ratio < 1) {
            w = w * Ratio;
            h = h * Ratio;
        }
        objImg.height = h;
        objImg.width = w;
        this.onload = function () { }
    }
    img.src = objImg.src;
}
//统计字符长度（区分中英文）
function getLength(stringIn) {
    var strLength = 0;
    for (var i = 0; i < stringIn.length; i++) {
        if (stringIn.charCodeAt(i) > 255) {
            strLength += 2;
        }
        else {
            strLength += 1;
        }

    }
    return strLength;
}

function checklen(textareaName, maxLength, charNumSpan) {
    document.getElementById(charNumSpan).innerHTML = (maxLength - getLength(document.getElementById(textareaName).value)) / 2;
}
//wbfunc
var divHeight = 0;
var alphaValue = 0;
var divOldHeight = 0;
function getAndShowNewWB(divID) {
    document.getElementById(divID).style.filter = "alpha(opacity=0)";
    divOldHeight = document.getElementById(divID).offsetHeight;
    divHeight = 0;
    alphaValue = 0;
    openNewWB(divID);
    showNewWB(divID)
}

function openNewWB(divID) {
    var newWBDiv = document.getElementById(divID);
    divHeight = divHeight + 5;
    newWBDiv.style.height = divHeight;
    var t1 = setTimeout("openNewWB('" + divID + "');", 100);
    if (divHeight >= divOldHeight) {
        newWBDiv.style.height = divOldHeight;
        clearTimeout(t1);
    }
}

function showNewWB(divID) {
    var newWBDiv = document.getElementById(divID);
    if (alphaValue <= 100) {
        alphaValue += 10;
        newWBDiv.style.filter = "alpha(opacity=" + alphaValue + ")";
    }
    var t2 = setTimeout("showNewWB('" + divID + "');", 200);
    if (alphaValue >= 100) {
        clearTimeout(t2);
    }
}

//会员中心中显示模块
function selModule(tagIndex) {
    if (document.getElementById("chModule" + tagIndex).style.display == "none") {
        alphaValue = 0;
        document.getElementById("chModule" + tagIndex).style.display = "block";
        document.getElementById("chModule" + tagIndex).style.filter = "alpha(opacity=0)";
        showNewWB("chModule" + tagIndex);
    }
    else {
        document.getElementById("chModule" + tagIndex).style.display = "none";
    }
}
function Fcalendar(field) {
    var rtn = window.showModalDialog("http://www.ztone.cc/TY/selDate.aspx", "", "dialogWidth:290px;dialogHeight:250px;status:no;help:no;scrolling=no;scrollbars=no");
    if (rtn != null)
        field.value = rtn;
    return;
}

//显示课时要点
function showYD(divID, arID) {
    if (document.getElementById(divID).style.display == "block") {
        document.getElementById(arID).src = "http://www.ztone.cc/images/show.png";
        document.getElementById(arID).title = "显示本课要点";
        document.getElementById(divID).style.display = "none";
    }
    else {
        document.getElementById(arID).src = "http://www.ztone.cc/images/hide.png";
        document.getElementById(arID).title = "隐藏本课要点";
        document.getElementById(divID).style.display = "block";
    }
}
