﻿   $(document).ready(function (){
	    $('#HotVoteBodyDiv').corner({
			  tl: { radius: 0 },
			  tr: { radius: 0 },
			  bl: { radius: 4 },
			  br: { radius: 4 }}
	    );
	    $('#LittleEvent1').corner({
			  tl: { radius: 4 },
			  tr: { radius: 4 },
			  bl: { radius: 4 },
			  br: { radius: 4 }}
	    );
	    $('#LittleEvent2').corner({
			  tl: { radius: 4 },
			  tr: { radius: 4 },
			  bl: { radius: 4 },
			  br: { radius: 4 }}
	    );
	    $('#SearchFormDiv').corner({
			  tl: { radius: 4 },
			  tr: { radius: 4 },
			  bl: { radius: 4 },
			  br: { radius: 4 }}
	    );
	    $('#LastBodyDiv').corner({
			  tl: { radius: 0 },
			  tr: { radius: 0 },
			  bl: { radius: 4 },
			  br: { radius: 4 }}
	    );
	    $('#SuperVoteBody').corner({
			  tl: { radius: 0 },
			  tr: { radius: 0 },
			  bl: { radius: 4 },
			  br: { radius: 4 }}
	    );
	    $('#NewReplyBody').corner({
			  tl: { radius: 0 },
			  tr: { radius: 0 },
			  bl: { radius: 4 },
			  br: { radius: 4 }}
	    );
	    setTimeout(function(){getContent("/KusoVote/Ajax/DefaultNewReply.aspx","NewReplyData")},500);
	    setTimeout(function(){getContent("/KusoVote/Ajax/DefaultLastVote.aspx","LastBody")},200);
	    showHotVote(Math.floor(Math.random()*5)+1);
	});
	
	function getContent(url,divName,id){

	    $.ajax({
            type:"POST",
            url:url,
            data:"id="+id,
            dataType:"html",
            success:function(data){
                setloadpic("","hide");
                if(data == "0"){
                    alert("error");
                }else{
                    $("#"+divName).fadeTo(0,0).html(data).fadeTo("slow",1);	 
                }
                       
            },
            error:function(data,e,x){
                //alert(e);
            },
            beforeSend:function(){
            
            },
            complete:function(){
            },
            anync:false

        });
	    
	}
	var ChangeID = 0;
	function ChangeNewVote(id){
	    if(ChangeID != id){
	        ChangeID = id;
	        setloadpic("","show");
	        $("span[id*='NewVoteOption']").css('color','#7D7D7D');
	        $("#NewVoteOption"+id).css('color','#6BB2BE');
	        getContent("/KusoVote/Ajax/DefaultNewVote.aspx","NewVoteData",id);
	    }
	    
        
	}
	function ChangeSuperTab(id){
        for(i=1;i<=4;i++){
            $("#SuperTab"+i).removeClass("SuperVoteOptionOn");
            $("#SuperTab"+i).addClass("SuperVoteOptionOff");
        }
        $("#SuperTab"+id).addClass("SuperVoteOptionOn");
        setloadpic("","show");
        $.ajax({
            type:"POST",
            url:"/KusoVote/Ajax/DefaultRightHot.aspx",
            data:"Mode="+id,
            dataType:"html",
            success:function(data){
                setloadpic("","hide");
                if(data == "0"){
                    alert("error");
                }else{
                    $("#SuperVote").fadeTo(0,0).html(data).fadeTo("slow",1);	 
                }
                       
            },
            error:function(data,e,x){
                alert(e);
            },
            beforeSend:function(){
            
            },
            complete:function(){
            },
            anync:false

        });
    }
    function getSearch(key){
        window.open("/KusoVote/Search.aspx?K="+encodeURIComponent(key));
    }
    var nowHot = 0;
    var hotPlay = 0;
    function showHotVote(num){
        if(nowHot != HotVote[num] && hotPlay == 0){
            hotPlay = 1;
            nowHot = HotVote[num];
            for(i=1;i<=5;i++){
                $("#HotVoteI"+i).get(0).src = "/KusoVote/images/Hot"+i+"Off.gif";
                $("#HotVoteTable"+HotVote[i]).hide();
            }
            $("#HotVoteBodyDiv").height($("#HotVoteTable"+HotVote[num]).height());
            $("#HotVoteI"+num).get(0).src = "/KusoVote/images/Hot"+num+"On.gif";
            $("#HotVoteTable"+HotVote[num]).slideDown("1000",function(){hotPlay=0});
            
        }
        
    }
    function DefaultHotVote(num){
        
	    $("#SendVoteBtn:button").attr("disabled", true);
	    var A = "";
	    if($("#DAns_"+num).attr("type") == "checkbox"){
	        A = $.checkboxV("DAns_"+num);
	    }else{
	        A = $.radioV("DAns_"+num);
	    }
	    if(A== ""){
	        $("#DAns_"+num).focus();
	        alert("請選擇您要投票的選項");
	        $("#SendVoteBtn:button").attr("disabled", false);
	        return false;
	    }
	    setloadpic("SendVoteBtn","show");
	    $.ajax({
            type:"POST",
            url:"/KusoVote/My/Ajax/SendVote.aspx",
            data:"id="+num+"&A="+A,
            dataType:"html",
            success:function(data){
                if(data == 4){
                    setloadpic("","hide");
                    alert("系統錯誤，或您輸入不正確的資訊!!");
                }else if(data == 2){
                    setloadpic("","hide");
                    alert("您已經投過這篇主題囉!!");
                    getHotResult(num,"HotVoteAjaxDiv"+num) 
                }else if(data == 3){
                    setloadpic("","hide");
                    alert("您尚未登入會員，請先於左上方登入會員!!");
                    /*NowEvent = "DefaultVote";
                    showLoginForm();*/
                }else if(data == 5){
                    setloadpic("","hide");
                    alert("投票時間已過!!");
                    getHotResult(num,"HotVoteAjaxDiv"+num) 
                }else{
                    NowEvent = "";
                    getHotResult(num,"HotVoteAjaxDiv"+num)           
                }
                $("#SendVoteBtn:button").attr("disabled", false);	        
            },
            error:function(data,e,x){
                alert(e);
            },
            beforeSend:function(){
            
            },
            complete:function(){
            },
            anync:false

        });
    }
    function getHotResult(num,divName){
        $.ajax({
            type:"POST",
            url:"/KusoVote/Ajax/DefaultHotAjaxResult.aspx",
            data:"id="+num,
            dataType:"html",
            success:function(data){
                if(data == 0){
                    setloadpic("","hide");
                    alert("系統錯誤，或您輸入不正確的資訊!!");
                }else{
                    setloadpic("","hide");
                    $("#HotVoteAjaxDiv"+num).fadeTo(0,0).html(data).fadeTo("slow",1);;         
                }        
            },
            error:function(data,e,x){
                alert(e);
            },
            beforeSend:function(){
            
            },
            complete:function(){
            },
            anync:false

        });
    }
    function showLoginForm(){
        $.setupJMPopups({ screenLockerBackground: "#333333", screenLockerOpacity: "0.7" }); 
        openStaticPopup();
    }
    function openStaticPopup() { 
        $.openPopupLayer({ name: "D_LoginMain", url: "/KusoVote/My/Ajax/Login.aspx" }); 
    }
    function SearchKey(){
        if($.trim($("#Key").val()) == ""){
            alert("請輸入要搜尋的關鍵字");
            $("#Key").focus();
            return false ;
        }else{
            location.href="Search.aspx?id="+$("#ctl00_ContentPlaceHolder1_DropChaneel").val()+"&K="+encodeURIComponent($("#Key").val());
        }
        
    }
