// 获取编辑器中HTML内容
function getEditorHTMLContents(EditorName) {
    var oEditor = FCKeditorAPI.GetInstance(EditorName);
    return (oEditor.GetXHTML(true));
}

// 获取编辑器中文字内容
function getEditorTextContents(EditorName) {
    var oEditor = FCKeditorAPI.GetInstance(EditorName);
    return (oEditor.EditorDocument.body.innerText);
}

// 设置编辑器中内容
function SetEditorContents(EditorName, ContentStr) {
    var oEditor = FCKeditorAPI.GetInstance(EditorName);
    oEditor.SetHTML(ContentStr);
}
function jumpPage(pageIndex, max) {
    if (pageIndex < 1 || pageIndex > max) {
        return;
    }
    document.getElementById("pageIndex").value = pageIndex;
    doJumpPage();
}
function jumpToPage() {
    var jumpToPageIndex = document.getElementById("pageIndexInput").value;
    var jumpToPageIndexValue = parseInt(jumpToPageIndex);
    if (!jumpToPageIndexValue) {
        alert("\u8bf7\u8f93\u5165\u4e00\u4e2a\u6b63\u786e\u7684\u6570\u503c");
        document.getElementById("pageIndexInput").focus();
        return;
    }
    var jumpToPageMaxValue = parseInt(document.getElementById("pageCount").value);
    if (jumpToPageIndex < 1 || jumpToPageIndex > jumpToPageMaxValue) {
        alert("\u8bf7\u8f93\u5165\u4e00\u4e2a\u4ecb\u4e8e1\u548c" + jumpToPageMaxValue + "\u7684\u6570\u503c");
        document.getElementById("pageIndexInput").focus();
        return;
    }
    document.getElementById("pageIndex").value = jumpToPageIndexValue;
    doJumpPage();
}
function dispatch(link) {
    location.href = link;
}
function openInfoWindow(action) {
    try {
        document.getElementById("ajaxAction").value = action;
        refreshItem("windowInsideDIV");
    }
    catch (e) {
        alert("\u63d0\u4ea4\u6570\u636e\u51fa\u9519");
    }
}
function closeInfoWindow() {
    document.getElementById("windowInsideDIV").innerHTML = "";
    hideWindow("infoWindow");
}
function doAction(action) {
    try {
        document.getElementById("ajaxAction").value = action;
        refreshItem("hiddenSpan");
    }
    catch (e) {
        alert("\u63d0\u4ea4\u6570\u636e\u51fa\u9519");
    }
}
function doFckAction(action) {
    if (checkContent()) {
        doAction(action);
    }
}
function doSubmit(action) {
    try {
        var tmpAction = document.getElementById("mainForm").attributes["action"].value;
        var tmpTarget = document.getElementById("mainForm").attributes["target"].value;
        document.getElementById("mainForm").attributes["action"].value = "/ajax";
        document.getElementById("mainForm").attributes["target"].value = "hiddenIframe";
        document.getElementById("module").value = "ajax";
        document.getElementById("action").value = action;
        document.getElementById("mainForm").submit();
        document.getElementById("mainForm").attributes["action"].value = tmpAction;
        document.getElementById("mainForm").attributes["target"].value = tmpTarget;
    }
    catch (e) {
        alert("\u63d0\u4ea4\u6570\u636e\u51fa\u9519");
    }
}
function checkContent() {
    document.getElementById("content").value = getEditorHTMLContents("content");
    if (document.getElementById("content").value.length > 65535) {
        alert("\u5185\u5bb9\u8fc7\u957f\uff0c\u8bf7\u63a7\u5236\u572810000\u5b57\u4ee5\u5185");
        return false;
    } else {
        if (document.getElementById("content").value.match("<script")) {
            alert("\u5185\u5bb9\u4e2d\u542b\u6709\u4e0d\u5b89\u5168\u7684\u811a\u672c\u4ee3\u7801\uff0c\u8bf7\u68c0\u67e5\u60a8\u7684\u5185\u5bb9");
            return false;
        }
    }
    return true;
}
function clearFiles() {
    var nodeArray = document.getElementsByTagName("input");
    for (i = 0; i < nodeArray.length; i++) {
        var tmpobj = nodeArray[i];
        var stype = tmpobj.type;
        if (stype == "file") {
            tmpobj.outerHTML = tmpobj.outerHTML;
        }
    }
}
function preLogin() {
    if (document.getElementById("isUserLogined").value == "true") {
        alert("\u767b\u5f55\u5df2\u7ecf\u8d85\u65f6\uff0c\u8bf7\u91cd\u65b0\u767b\u9646");
    } else {
        alert("\u60a8\u5c1a\u672a\u767b\u5f55\u7cfb\u7edf\uff0c\u8bf7\u5148\u767b\u5f55");
    }
    location.href = "/index.html";
}
function logoff() {
    location.href = "/logoff.do";
}
function login() {
    location.href = "/login.html";
}

//设置首页
var siteUrl = "http://www.chuchuguo.com/";
var siteName = "http://www.chuchuguo.com/";
function setHomepage() {
    if (document.all) {
        document.body.style.behavior = "url(#default#homepage)";
        document.body.setHomePage(siteUrl);
    } else {
        if (window.sidebar) {
            if (window.netscape) {
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                }
                catch (e) {
                    alert("\u8be5\u64cd\u4f5c\u88ab\u6d4f\u89c8\u5668\u62d2\u7edd\uff0c\u5982\u679c\u60f3\u542f\u7528\u8be5\u529f\u80fd\uff0c\u8bf7\u5728\u5730\u5740\u680f\u5185\u8f93\u5165 about:config,\u7136\u540e\u5c06\u9879 signed.applets.codebase_principal_support \u503c\u8be5\u4e3atrue");
                }
            }
            var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref("browser.startup.homepage", siteUrl);
        }
    }
}

//添加网页到收藏夹
function addfavorite() {
    if (document.all) {
        window.external.addFavorite(siteUrl, siteName);
    } else {
        if (window.sidebar) {
            window.sidebar.addPanel(siteName, siteUrl, "");
        }
    }
}
function changeRandomImage() {
    document.getElementById("randomNumberImage").src = "/randomNumberImage?temp=" + (new Date().getTime().toString(36));
}
function checkImage(pathField) {
    var imgRe = /^.+\.(jpg|jpeg|gif|png)$/i;
    var path = pathField.value;
    if (path.search(imgRe) == -1) {
        alert("\u8bf7\u4e0a\u4f20\u683c\u5f0f\u4e3aJPG\u3001PNG\u6216\u8005GIF\u7684\u56fe\u7247!");
        return;
    }
    return true;
}

//弹出Div效果
function setCoordination() {
    document.getElementById("mask").style.height = document.documentElement.clientHeight + "px";
    document.getElementById("mask").style.width = document.documentElement.clientWidth + "px";
}
function showWindow(displayedID) {
    var displayedWindow = document.getElementById(displayedID);
    var height = parseInt(displayedWindow.clientHeight);
    var width = parseInt(displayedWindow.clientWidth);
    var position = getPosition();
    var topAdded = (position.height - height) / 2;
    var leftAdded = (position.width - width) / 2;

    // displayedWindow.style.top = ( position.top + topAdded - 46) + "px";
    displayedWindow.style.top = (position.top + topAdded) + "px";
    displayedWindow.style.left = (position.left + leftAdded) + "px";
    displayedWindow.style.visibility = "visible";
    var mask = document.getElementById("mask");
    mask.style.visibility = "visible";
}
function hideWindow(hiddenID) {
    var hiddenWindow = document.getElementById(hiddenID);
    hiddenWindow.style.visibility = "hidden";
    var mask = document.getElementById("mask");
    mask.style.visibility = "hidden";
}
function getPosition() {
    var top = document.documentElement.scrollTop;
    var left = document.documentElement.scrollLeft;
    var height = document.documentElement.clientHeight;
    var width = document.documentElement.clientWidth;
    return {top:top, left:left, height:height, width:width};
}
function forumTopicSearch() {
    var keyWord = document.getElementById("keyWord").value;
    var forumBoardID = document.getElementById("forumBoardID").value;
    location.href = encodeURI("/forum/" + forumBoardID + ".html?keyWord=" + keyWord);
}
function replyForumArticleView(articleID) {
    document.getElementById("forumArticleID").value = articleID;
    openInfoWindow("replyForumArticleWindow");
}
function modifyForumArticleView(articleID) {
    document.getElementById("forumArticleID").value = articleID;
    openInfoWindow("modifyForumArticleWindow");
}
function deleteForumArticle(articleID) {
    document.getElementById("forumArticleID").value = articleID;
    doAction("deleteForumArticle");
}
function modifyForumTopicView(articleID) {
    document.getElementById("forumArticleID").value = articleID;
    openInfoWindow("modifyForumTopicWindow");
}
function updateUserPicture() {
    var tmpobj = document.getElementById("pictureImg");
    tmpobj.outerHTML = tmpobj.outerHTML;
    if (checkImage(document.getElementById("pictureImage"), "")) {
        doSubmit("updateUserPicture");
    }
}


//索引图片切换效果
var firstIndex = 1;
function isActive(countInput) {
    var count = parseInt(countInput);
    var imageIndex = document.getElementById("img_index").getElementsByTagName("td");
    var imageNum = imageIndex.length;
    document.getElementById("arrow_left").style.background = "url('/images/bg_arrow_left.gif') no-repeat left top";
    if (imageNum > count + 2) {
        document.getElementById("arrow_right").style.background = "url('/images/bg_arrow_right.gif') no-repeat left bottom";
        for (var i = count + 1; i < imageNum - 1; i++) {
            imageIndex[i].style.display = "none";
        }
    } else {
        document.getElementById("arrow_right").style.background = "url('/images/bg_arrow_right.gif') no-repeat left top";
    }
}
function setVisible(index, parentId, tagName) {
    var listItem = document.getElementById(parentId).getElementsByTagName(tagName);
    var indexItem = document.getElementById("img_index").getElementsByTagName("a");
    for (var i = 0; i < listItem.length; i++) {
        listItem[i].style.display = "none";
        indexItem[i].className = "";
    }
    listItem[parseInt(index) - 1].style.display = "block";
    indexItem[parseInt(index) - 1].className = "on";
}
function addImgIndex(countInput) {
    var count = parseInt(countInput);
    var imageIndex = document.getElementById("img_index").getElementsByTagName("td");
    var imageNum = imageIndex.length;
    if (imageNum - firstIndex > count + 1) {
        document.getElementById("arrow_left").style.background = "url('/images/bg_arrow_left.gif') no-repeat left bottom";
        for (var i = 1; i <= imageNum - 2; i++) {
            imageIndex[i].style.display = "none";
        }
        firstIndex++;
        for (var i = 0; i < count; i++) {
            imageIndex[firstIndex + i].style.display = "";
        }
        if (imageNum - firstIndex > count + 1) {
            document.getElementById("arrow_right").style.background = "url('/images/bg_arrow_right.gif') no-repeat left bottom";
        } else {
            document.getElementById("arrow_right").style.background = "url('/images/bg_arrow_right.gif') no-repeat left top";
        }
    }
}
function subImgIndex(countInput) {
    var count = parseInt(countInput);
    var imageIndex = document.getElementById("img_index").getElementsByTagName("td");
    var imageNum = imageIndex.length;
    if (firstIndex > 1) {
        document.getElementById("arrow_right").style.background = "url('/images/bg_arrow_right.gif') no-repeat left bottom";
        for (var i = 1; i <= imageNum - 2; i++) {
            imageIndex[i].style.display = "none";
        }
        firstIndex--;
        for (var i = 0; i < count; i++) {
            imageIndex[firstIndex + i].style.display = "";
        }
        if (firstIndex > 1) {
            document.getElementById("arrow_left").style.background = "url('/images/bg_arrow_left.gif') no-repeat left bottom";
        } else {
            document.getElementById("arrow_left").style.background = "url('/images/bg_arrow_left.gif') no-repeat left top";
        }
    }
}
function SetTable(updateDiv, fromDiv) {
    $("#" + fromDiv).parent().find(".hover").attr("class", "");
    $("#" + fromDiv).attr("class", "hover");
    var fromDiv = fromDiv.substring(0, fromDiv.length - 4);
    $("#" + updateDiv).html($("#" + fromDiv).html());
}
function nameSearch() {
    var module = "";
    var type = document.getElementById("topStudyTypeSelectValue").value;
    if (type == "2") {
        module = "mba";
    } else {
        if (type == "3") {
            module = "bachelor";
        } else {
            module = "master";
        }
    }
    location.href = encodeURI("/" + module + "/search.do?keyWord=" + document.getElementById("keyWord").value);
}
function detailSearch() {
    var type = document.getElementById("studyTypeSelectValue").value;
    if (type == "1") {
        masterSearch();
    } else {
        if (type == "2") {
            mbaSearch();
        } else {
            if (type == "3") {
                bachelorSearch();
            } else {
                alert("\u8bf7\u5148\u9009\u62e9\u4e00\u9879\u60a8\u7684\u7559\u5b66\u7c7b\u578b\uff01");
                document.getElementById("studyTypeSelectValue").focus();
            }
        }
    }
}
function masterSearch() {
    var module = "";
    var state = document.getElementById("stateSelectValue").value;
    var level = document.getElementById("levelSelectValue").value.split(",");
    var fee = document.getElementById("feeSelectValue").value.split(",");
    var fromFee = 0;
    var toFee = 0;
    var fromRank = 0;
    var toRank = 0;
    if (level.length == 2) {
        fromRank = level[0];
        toRank = level[1];
    }
    if (fee.length == 2) {
        fromFee = fee[0];
        toFee = fee[1];
    }
    var professional = document.getElementById("professionalSelectValue").value;
    var direction = document.getElementById("directionSelectValue").value;
    var url = "/master/" + (state == "" ? "0" : state) + "-" + fromRank + "-" + toRank + "-" + fromFee + "-" + toFee + "-" + (professional == "" ? "0" : professional) + "-" + (direction == "" ? "0" : direction) + "-0.html";
    location.href = url;
}
function mbaSearch() {
    var module = "";
    var state = document.getElementById("stateSelectValue").value;
    var level = document.getElementById("levelSelectValue").value.split(",");
    var fee = document.getElementById("feeSelectValue").value.split(",");
    var fromFee = 0;
    var toFee = 0;
    var fromRank = 0;
    var toRank = 0;
    if (level.length == 2) {
        fromRank = level[0];
        toRank = level[1];
    }
    if (fee.length == 2) {
        fromFee = fee[0];
        toFee = fee[1];
    }
    var url = "/mba/" + (state == "" ? "0" : state) + "-" + fromRank + "-" + toRank + "-" + fromFee + "-" + toFee + "-0.html";
    location.href = url;
}
function bachelorSearch() {
    var module = "";
    var state = document.getElementById("stateSelectValue").value;
    var level = document.getElementById("levelSelectValue").value.split(",");
    var fee = document.getElementById("feeSelectValue").value.split(",");
    var fromFee = 0;
    var toFee = 0;
    var fromRank = 0;
    var toRank = 0;
    if (level.length == 2) {
        fromRank = level[0];
        toRank = level[1];
    }
    if (fee.length == 2) {
        fromFee = fee[0];
        toFee = fee[1];
    }
    var url = "/bachelor/" + (state == "" ? "0" : state) + "-" + fromRank + "-" + toRank + "-" + fromFee + "-" + toFee + "-0.html";
    location.href = url;
}
function setHotKey(type, name) {
    document.getElementById("topStudyTypeSelectValue").value = type;
    document.getElementById("keyWord").value = name;
    nameSearch();
}
function setHotKey2(type, setHotKey2, professional) {
    document.getElementById("topStudyTypeSelectValue").value = type;
    document.getElementById("keyWord").value = name;
    var module = "";
    var type = document.getElementById("topStudyTypeSelectValue").value;
    if (type == "2") {
        module = "mba";
    } else {
        if (type == "3") {
            module = "bachelor";
        } else {
            module = "master";
        }
    }
    location.href = encodeURI("/" + module + "/search.do?keyWord=" + document.getElementById("keyWord").value + "&professional=" + professional);
}
function addTargetMba(mbaID) {
    document.getElementById("mbaID").value = mbaID;
    doAction("addTargetMba");
}
function addTargetMba2(mbaID) {
    document.getElementById("mbaID").value = mbaID;
    doAction("addTargetMba2");
}
function addTargetMba3(mbaID) {
    document.getElementById("mbaID").value = mbaID;
    doAction("addTargetMba3");
}
function removeTargetMba(mbaID) {
    document.getElementById("mbaID").value = mbaID;
    doAction("removeTargetMba");
}
function addTargetBachelor(bachelorID) {
    document.getElementById("bachelorID").value = bachelorID;
    doAction("addTargetBachelor");
}
function addTargetBachelor2(bachelorID) {
    document.getElementById("bachelorID").value = bachelorID;
    doAction("addTargetBachelor2");
}
function addTargetBachelor3(bachelorID) {
    document.getElementById("bachelorID").value = bachelorID;
    doAction("addTargetBachelor3");
}
function removeTargetBachelor(bachelorID) {
    document.getElementById("bachelorID").value = bachelorID;
    doAction("removeTargetBachelor");
}
function addTargetMaster(masterID) {
    document.getElementById("masterID").value = masterID;
    doAction("addTargetMaster");
}
function addTargetMaster2(masterID) {
    document.getElementById("masterID").value = masterID;
    doAction("addTargetMaster2");
}
function addTargetMaster3(masterID) {
    document.getElementById("masterID").value = masterID;
    doAction("addTargetMaster3");
}
function removeTargetMaster(masterID) {
    document.getElementById("masterID").value = masterID;
    doAction("removeTargetMaster");
}
function resetProfessionSelect() {
    var type = document.getElementById("studyTypeSelectValue").value;
    if (type == "1") {
        document.getElementById("professionalSelectDiv").style.display = "block";
    } else {
        document.getElementById("professionalSelectDiv").style.display = "none";
    }
}

function resizeImages(obj, MaxW, MaxH) {
    var imageObject;
    if (obj != null) {
        imageObject = obj;
    }
    var state = imageObject.readyState;
    var oldImage = new Image();
    oldImage.src = imageObject.src;
    var dW = oldImage.width;
    var dH = oldImage.height;
    if (dW > MaxW || dH > MaxH) {
        var a = dW / MaxW;
        var b = dH / MaxH;
        if (b > a) {
            a = b;
        }
        dW = dW / a;
        dH = dH / a;
    }
    if (dW > 0 && dH > 0) {
        imageObject.width = dW;
    }
    imageObject.height = dH;
}

 function scrollInterval()
 {
var demo=document.getElementById("demo");
var demo1=document.getElementById("demo1");
var demo2=document.getElementById("demo2");
  demo2.innerHTML=demo1.innerHTML;
  if(demo.scrollTop == 2*demo1.scrollHeight-demo.offsetHeight)
  {
   demo.scrollTop=demo1.scrollHeight-demo.offsetHeight;
  }
  else
  {
   demo.scrollTop++;
  }
  if(demo.scrollTop%180==0)
  {
   window.setTimeout( "scrollInterval()", 2000 );
  }
   else
   {
   window.setTimeout( "scrollInterval()", 50 );
   }
 }
