﻿$(document).ready(function () {
    DD_roundies.addRule('.ui-corner-all', '10px');
    DD_roundies.addRule('.ui-corner-bottom', '0 0 10px 10px');

    // Dialogs
    $("#TermsAndCondDialog").dialog({
        autoOpen: false,
        width: 600,
        height: 550,
        resizable: false,
        title: "Terms And Conditions",
        buttons: { "Close": function () { $("#TermsAndCondDialog").dialog("close"); } }
    });

    $("#FloatingMessage").dialog({
        autoOpen: true,
        width: 500,
        height: 200,
        resizable: false,
        title: "Message",
        buttons: { "Close": function () { $("#FloatingMessage").dialog("close"); } }
    });

    $("#SubmitProfileMessage").dialog({
        autoOpen: true,
        width: 500,
        height: 200,
        resizable: false,
        title: "Message",
        buttons: { "Close": function () { $("#SubmitProfileMessage").dialog("close"); } }
    });

    $("#termsAndCond").click(function () { $("#TermsAndCondDialog").dialog("open"); });
    $("#sendPassword").bind("click", { useLocation: true, location: "default.aspx" }, PasswordReminder);

    $(function () {
        $("#accordion").accordion({ header: "h3", autoHeight: false, collapsible: true, active: false });
    });


    // ***** Bubble popup *****
    $('.resultImage').CreateBubblePopup({
        themePath: 'css/jquerybubblepopup-theme',
        position: 'left'
    });

    $('.resultImage').data('visible', false);

    $('.resultImage').mouseover(function () {

        $('.resultImage').data('visible', false);
        $(this).data('visible', true);

        var id = $(this).attr('id').replace('itemImg', '');

        //hide all popups, update the innerHtml and show this popup
        $('.resultImage').HideAllBubblePopups();
        if ($('#bubble' + id).html() != null) {
            $(this).SetBubblePopupInnerHtml($('#bubble' + id).html());
            $(this).ShowBubblePopup();
        }
    });

    $('.resultImage').mouseout(function () {

        $(this).HideBubblePopup();
    });
    // ***** Bubble popup *****

    // ***** Remove from list *****
    $('.removeFromHaveList').click(function () {
        var id = $(this).attr('id').replace('removeFromList', '');
        $.ajax({
            type: "POST",
            url: "jQueryServices.aspx/RemoveFromHaveList",
            data: "{'id':" + id + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: true,
            cache: false,
            success: function (msg) {
                useAfterCloseLocation = true;
                afterCloseLocation = "Have.aspx";
                $("#Message").html("Item removed");
                $("#Message").dialog("open");
            }
        });
    });

    $('.removeFromWantList').click(function () {
        var id = $(this).attr('id').replace('removeFromList', '');
        $.ajax({
            type: "POST",
            url: "jQueryServices.aspx/RemoveFromWantList",
            data: "{'id':" + id + "}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: true,
            cache: false,
            success: function (msg) {
                useAfterCloseLocation = true;
                afterCloseLocation = "Want.aspx";
                $("#Message").html("Item removed");
                $("#Message").dialog("open");
            }
        });
    });
    // ***** Remove from list *****
});

var intervalId;

function BlinkTimer(oBlink) {
    var o = $("#" + oBlink)
    o.toggleClass("blinkOn", 1000);
}

function Blink(oBlink) {
    intervalId = setInterval("BlinkTimer('" + oBlink + "')", 1000);
}

function PasswordReminder(event) {
    useAfterCloseLocation = event.data.useLocation;
    afterCloseLocation = event.data.location;

    var email = $("#TextEmail").val();
    var maidenName = $("#TextMaidenName").val();

    $.ajax({
        type: "POST",
        url: "jQueryServices.aspx/PasswordReminder",
        data: "{'email':'" + email + "', 'maidenName':'" + maidenName + "'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: true,
        cache: false,
        success: function (msg) {
            if (msg.d == "") {
                $("#Message").html("Password reminder was sent");
            }
            else {
                $("#Message").html(msg.d);
            }
            $("#Message").dialog("open");
        }
    });
}

