﻿$(function()
{


    $(".Box").corner("round");
    $(".Issuebox").corner("round");
    $(".Questionbox").corner("round");

    setInputHint($(".inputbox[title]"));
    setInputHint($("#tqbox"));


    $(".inputbox").blur();
    $(":checkbox").addClass("checkbox");




    $("#tss").click(function()
    {
        var tq = $("#tqbox");

        if (tq.val() == "" || tq.val() == tq[0].title)
        {
            tq.focus();
        }
        else
        {
            $("#tq").submit();
        }
    });
    $("#tq").submit(function()
    {
        var tq = $("#tqbox");

        if (tq.val() == "" || tq.val() == tq[0].title)
        {
            tq.focus();
            return false;
        }
        else
        {
            return true;
        }

    });
  //  getVoteHistory();   

});
var orgnews = "";
function getVoteHistory()
{
    $.ajax({
        action: "getvotehistory",
        url: "WebSvc/SurveySvc.asmx/glsvhsss",
        data: "{sid:0}",
        success: function(data)
        {
            if (data.d != null)
            {

                if (data.d != "")
                {
                    if (data.d != orgnews)
                    {

                        $("#votehistory").fadeOut().html("<b>最新动态:</b>&nbsp;" + data.d).fadeIn();
                        orgnews = data.d;
                    }
                    else
                    {


                    }
                }
                else
                {

                    $("#votehistory").fadeOut();
                    $("#votehistory").html("");
                }
            }
            setTimeout("getVoteHistory()", 5000);

        },
        error: function(xhr)
        {

            $("#votehistory").fadeOut();
            $("#votehistory").html("");
            setTimeout("getVoteHistory()", 5000);

        }
    });
}


function getVoteActions()
{

    
    
    
    $.ajax({
        action: "gethomepageids",
        url: "WebSvc/SurveySvc.asmx/glsvh",
        data: "{0}",
        success: function(data)
        {
            for (i = 0; i < data.d.length; i++)
            {
                surveyIds.push(data.d[i]);
            }
            //by default show the top one
            var firstItem = surveyIds[0];

            //if there're homepage survey need to display?
            var homeSid = $(document).getUrlParam("sid");

            if (homeSid != null && homeSid != 0)
            {
                $("#slideControl").removeClass("pause").addClass("play").attr("title", "自动循环已暂停，点击继续自动循环热门调查");
                var exist = false;
                firstItem = homeSid;
                for (i = 0; i < surveyIds.length; i++)
                {
                    if (surveyIds[i] == homeSid) //the survey is already listed
                    {
                        autoPlay = false;
                        exist = true;
                        break;
                    }
                }
                if (!exist)
                {
                    surveyIds.push(homeSid);
                    autoPlay = false;
                }
            }

            buildSlideBar(surveyIds);
            changeSlide(firstItem);
            setInterval("countVote()", 3000);
            initAutoplay();
        },
        error: function(xhr)
        {
            // do nothing
        }
    });

}

function setInputHint(target) {
    target.blur(function() {
        if ($(this).val() == "") {
            $(this).css("color", "#a1a1a1");
            $(this).val($(this)[0].title);
        }
    });
    target.focus(function() {
        if ($(this).val() == $(this)[0].title) {
            $(this).css("color", "#000");
            $(this).val("");
        }
    });
    $(function() {
        target.blur();
    });

}

function showError() {
    alert("系统出错。请检查您的网络连接并稍后重试。");
}

function showUrlWarning(target)
{

    var $ele = $(target);
    var url = $ele.attr("href");

    if (url != undefined) {
        if ($ele.next().hasClass("safediv")) {
            $ele.next().show();
        } else {
        var html = '<div style="left:' + $ele.position().left + 'px; top:' + ($ele.position().top + 15) + 'px" class="safediv"><span>您正要打开用户的博客，我们未对用户的博客进行检查，也许有潜在的危险</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="' + url + '" target="_blank" onclick="$(this).parent(\'.safediv\').hide()" >打开网址</a>&nbsp;&nbsp;<a href="javascript:void(0);" onclick="javascript:$(this).parent(\'.safediv\').hide()">取消</a></div>';
            $ele.after(html);
        }
    }
    return false;
}