﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />
var current = 'Home';
$(document).ready(function() {

    // 初始化默认单元格
    $("#Upload").css({ 'display': 'none' });
    $("#LatestArticles").css({ 'display': 'none' });
    $("#Copyright").css({ 'display': 'none' });
    $("#Description").css({ 'display': 'none' });

    $("#Intro").css({ 'display': '' });
    $("#Prize").css({ 'display': 'none' });
    $("#Activities").css({ 'display': '' });
    $("#PrizeList").css({ 'display': 'none' });
    $("#NavigationList>li>a").mouseover(function() {
        if ($(this).attr("id") != current) {
            var imageurl = $(this).children("img").attr("src");
            $(this).children("img").attr("src", imageurl.replace(".png", "_h.png"));
        }
    });
    $("#NavigationList>li>a").mouseout(function() {
        if ($(this).attr("id") != current) {
            var imageurl = $(this).children("img").attr("src");
            $(this).children("img").attr("src", imageurl.replace("_h.png", ".png"));
        }
    });
    // 点击链接相应跳转
    $("#NavigationList a").click(function() {
        var id = $(this).attr("id");
        var url1 = $("#" + current).children("img").attr("src");
        var url2 = $(this).children("img").attr("src");
        $("#" + current).children("img").attr("src", url1.replace("_h.png", ".png"));
        $("#" + id).children("img").attr("src", url2);
        current = id;
        if (id == "Home") {
            $("#Intro").css({ 'display': '' });
            $("#Upload").css("display", "none");
            $("#Copyright").css("display", "none");
            $("#LatestArticles").css("display", "none");
            $("#ArticleList").css("display", "");
            $("#Beginner").css("display", "");
            $("#Description").css({ 'display': 'none' });
        }
        else {
            $("#Intro").css({ 'display': 'none' });
            $("#Upload").css("display", "");
            $("#Copyright").css("display", "");
            $("#LatestArticles").css("display", "");
            $("#ArticleList").css("display", "none");
            $("#Beginner").css("display", "none");
            $("#Description").css({ 'display': '' });
            //alert($("#Description>p")[0].innerHTML);
            //alert(id);

            if (id == "Windows7") {
                $("#Windows7_Article").css("display", "");
                $("#No_Article").css("display", "none");
            }
            else {
                $("#Windows7_Article").css("display", "none");
                $("#No_Article").css("display", "");
            }
            var type = "";
            if (id == "Tools") {
                type = "开发工具和语言";
                $("#Description>p")[0].innerHTML = "开发工具和语言包含：Visual Studio，Visual Basic，Visual C++，Visual C#，Visual Studio Team System。";
            }
            else if (id == "DotNet") {
                type = ".NET开发";
                $("#Description>p")[0].innerHTML = ".NET 开发包含：.NET Framework。";
            }
            else if (id == "Enterprise") {
                type = "企业开发";
                $("#Description>p")[0].innerHTML = "企业开发包含：SQL Server，Windows Server 2008。";
            }
            else if (id == "Web") {
                type = "Web开发";
                $("#Description>p")[0].innerHTML = "Web 开发包含：ASP.NET，Silverlight，Internet Explorer。";
            }
            else if (id == "Windows") {
                type = "Windows开发";
                $("#Description>p")[0].innerHTML = "Windows 开发包含：Windows Client，Windows Mobile。";
            }
            else if (id == "Office") {
                type = "Office开发";
                $("#Description>p")[0].innerHTML = "Office 开发包含：SharePoint，Office。";
            }
            else if (id == "Other") {
                type = "其他";
                $("#Description>p")[0].innerHTML = "其他相关技术文章。";
            }
            $("#Category")[0].value = $(this).attr("id");
            $("#UploadSteps>H2>span").text('我要"晒" ' + type + '文章');
            $("#LatestArticles>H2>span").text(type + "最新原创文章");
        }
        //        var currentLeft = $(this).position().left;
        //        $("#NavigationHoverBackground").css({ 'margin-left': currentLeft });
    });
        $("div.Button>img").click(function() {
            var id = $(this).attr("id").replace("img_", "");
            var url1 = $("#" + current).children("img").attr("src");
            var url2 = $("#" + id).children("img").attr("src");
            $("#" + current).children("img").attr("src", url1.replace("_h.png", ".png"));
            $("#" + id).children("img").attr("src", url2.replace(".png", "_h.png"));
            current = id;
            if (id == "Home") {
                $("#Upload").css("display", "none");
                $("#Copyright").css("display", "none");
                $("#LatestArticles").css("display", "none");
                $("#ArticleList").css("display", "");
                $("#Beginner").css("display", "");
            }
            else {
                var type = "";
                if (id == "Tools") {
                    type = "开发工具和语言 ";
                }
                else if (id == "DotNet") {
                    type = ".NET开发 ";
                }
                else if (id == "Web") {
                    type = "Web开发 ";
                }
                else if (id == "Windows") {
                    type = "Windows开发 ";
                }
                $("#UploadSteps>H2>span").text('我要"晒" ' + type + '文章');
                $("#Category")[0].value = id;
                $("#Upload").css("display", "");
                $("#Copyright").css("display", "");
                $("#LatestArticles").css("display", "");
                $("#ArticleList").css("display", "none");
                $("#Beginner").css("display", "none");
                if (id == "Windows7") {
                    $("#Windows7_Article").css("display", "");
                    $("#No_Article").css("display", "none");
                }
                else {
                    $("#Windows7_Article").css("display", "none");
                    $("#No_Article").css("display", "");

                }
            }
        });
    $("#uploadMoreButton").click(function() {
        $("#UploadControls")[0].innerHTML += '<input type="file" name="File3" title="请点击右侧浏览按钮" /><br/>';
        /****---ljh---****/
        //解决IE6下upload层下边背景线问题,配合IE6下特写样式 _height:280px;
        if ($.browser.version == '6.0') {
            $("#Upload").css("height", $("#Upload").height() + 22);
        }
        /****---ljh---****/
    });

    $("#ibnUpload").click(function() {
        var hasFile = false;
        var isFormatOk = true;
        /****---ljh---****/
        var emailRe = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
        var urlRe = /^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&amp;=]*)?$/;
        var fullName = document.getElementById("txtFullName").value;
        var email = document.getElementById("txtEmail").value;
        var url = document.getElementById("txtUrl").value;
        if (fullName == "") {
            alert("姓名不能为空！");
            return false;
        }
        if (email == "") {
            alert("电子邮件地址不能为空！");
            return false;
        }
        else if (emailRe.test(email) == false) {
            alert("电子邮件地址格式不正确！");
            return false;
        }
        if ($("#rbtArticleType>TBODY>TR>TD>INPUT").eq(0).attr("checked") == true) {
            hasFile = false;
            /****---ljh---****/

            var uploadControl = $("input[type='file']");
            uploadControl.each(function() {
                if (this.value != "") {
                    hasFile = true;
                    var extensionName = this.value.substr(this.value.lastIndexOf('.') + 1);
                    if ((extensionName != 'doc') && (extensionName != 'docx') && (extensionName != 'pdf') &&
                    (extensionName != 'xps') && (extensionName != 'txt') && (extensionName != 'rtf')) {
                        {
                            alert('只允许上传后缀为doc docx pdf xps txt或rtf格式的文件。');
                            isFormatOk = false;
                        }
                    }
                }
            });
            if (!hasFile) {
                alert('请至少选择一个上传文件！');
            }
            /****---ljh---****/
        }
        if ($("#rbtArticleType>TBODY>TR>TD>INPUT").eq(1).attr("checked") == true) {
            hasFile = true;
            if (url == "") {
                alert("文章地址不能为空！");
                return false;
            }
            else if (urlRe.test(url) == false) {
                alert("文章地址格式不正确！");
                return false;
            }
        }
        if (hasFile && isFormatOk && document.getElementById("txtFullName").value != "" && document.getElementById("txtEmail").value != "") {//此处不可用$("txtFullName").Text(),否则报错
            openBox();
            return false;
        }
        /****---ljh---****/
        return hasFile && isFormatOk;

    });
    $("#rbtArticleType>TBODY>TR>TD>INPUT").eq(0).click(function() {
        $("#FileType").css("display", "");
        $("#ImportantNotice").css("display", "");
        $("#ArticleUrl").css("display", "none");
    });
    $("#rbtArticleType>TBODY>TR>TD>INPUT").eq(1).click(function() {
        $("#FileType").css("display", "none");
        $("#ImportantNotice").css("display", "none");
        $("#ArticleUrl").css("display", "");
    });
});

