/// <reference path="jquery-1.3.2-vsdoc.js" />
/// <reference path="jquery.validate.js" />
/// <reference path="forms.js" />

//http://malsup.com/jquery/form/#api
//http://docs.jquery.com/Plugins/Validation/validate#options
// JavaScript Document
$(document).ready(function() {
    SetCountdownTicker();
    InsertBooksAjax(bIsLogin, iHomePageBooks, []);
});

function SetCountdownTicker() {
    var austDay = new Date();
    var dayarray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
    var montharray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    
    austDay = new Date(CurrentRaffleDate);

    $('#divTicker').countdown({ until: austDay, onExpiry: OnCountdownExpire, timezone: -4 });
    $('#NextDrawingDate').text('Next drawing scheduled for ' + dayarray[parseInt(austDay.getDay())] + ', ' + montharray[parseInt(austDay.getMonth())] + ' ' + austDay.getDate() + ', ' + austDay.getFullYear());
}

function OnCountdownExpire() {
    GetNewRaffleDate();    
}

function GetNewRaffleDate() {
    //Go to the server, change the Session date for the raffle and return new Raffle date:
    $.wsAjax({
        url: (urlPrefix + "services/RaffleService.asmx/ChangeCurrentRaffle"),
        data: function() {
            return {
                OldDate: ''
            }
        },
        success: function(result) {
            CurrentRaffleDate = result;
            //$('#divTicker').countdown('destroy');
            SetCountdownTicker();
            $("#DrawingCounter .WinnerAnnouncement").show();
        }
    });
}

function InsertBooksAjax(isLogin, iBooks, arrayObj) {
    var cat = $.url.param("cat");
        $.wsAjax({
        url: (urlPrefix + "services/BookService.asmx/GetHomePageBooksAjax"),
        data: function() {
            return {
                IsUserLogin: isLogin,
                numberOfBooks: iBooks,
                usedBooks: arrayObj,
                sCat: cat
            }
        },
        success: function(result) {
            if (!result || result == "") {
                //Error
                alert("Uh oh, there was a problem.  " + result);
            }
            else {
                //alert(result[0]);
                  $("#li_HorizontalSponsors").before(result[0]);
                 $("#li_HorizontalSponsors").after(result[1]);
                //$("#First6Books").html(result[0]);
                //$("#Last6Books").html(result[1]);
            }
        }
    });

}