﻿var ticks = 0;

String.prototype.trim = function()
{
    return this.replace(/(^\s+|(\s+$))/g, '').toLowerCase();
}
function UpdateTime() {
            var index=0;
            var data = "";
             
            $('.counter').each(function (index, value) {
                data += "&pid" + index + "=" + $(value).find(':input[type^="hidden"]').val() + "&localid" + index + "=" + $(value).attr('id');
                index++;
            });
            var theData = "operation=GetPriceInfo"+ data;
            $.ajax({
                type: "POST",
                url: $("#theLocalPath").val() + "scripts/AuctionClock.ashx",
                data: theData,

                success: function (returnObj) {

                    for (var i = 0; i < 10; i++) {
                        if (returnObj.PriceInformation != null) {
                            var priceInformation = returnObj.PriceInformation[i];
                            var labelMine = $("#uxHidLabMine").val();
                            var labelMined = $("#uxHidLabMined").val();
                            if (priceInformation != null && priceInformation.LocalId != null) {
                                var current = $('#' + priceInformation.LocalId + '>.price')[0].innerHTML.split(',')[1].trim();
                                var validat = priceInformation.Price.split(',')[1].trim();

                                if (current != validat) {
                                    jQuery.classBehaviours.handlers.animatedClassName.start($('#' + priceInformation.LocalId)[0]);
                                }
                                
                                 $('#' + priceInformation.LocalId + '>.price').html(priceInformation.Price);
                                if (priceInformation.IsMined == true) {
                                    //location.href = document.URL;
                                }
                            }
                        }
                    }
                }
            });
}
function UpdateClock() {
    if ($('.introHeader').hasClass('step_59')) {
        UpdateTime();
    }
    if (ticks == 5) {
        UpdateTime();
        ticks = 0;
    }
    ticks++;
}

$(document).ready(function () {
    if ($('#auctionClock').length > 0) {
        // there's a small delay each minute so make the interval less than a minute
        var timer = setInterval(UpdateClock, 1000);
    }
});


