﻿$(document).ready(function () {
    $('body').bidCardReader({
        onFinishReading: function (control, readValue) {
            console.log(readValue);
            $.ajax({
                type: "POST",
                url: $Url.resolve("~/Bidder/SetBidderNumberByBidCard"),
                data: "{bidCard:'" + readValue + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    if (result.sucess) {
                        window.location = '/Bids/MyBids'
                    }
                    else {
                        //$('.field-validation-error span').text(result.errorMessage);
                        var url = encodeURIComponent('/Bidder/CardRegistration?redirectTo=/Bids/MyBids&card=' + readValue);
                        window.location = '/PopUp/OpenInPopUp?url=' + url + '&title=Card Registration&width=550&height=600';
                    }
                },
                error: function (a, b, c) {
                    acAlert({
                        title: 'Bid Card reading',
                        message: 'There was an error while reading the bid card.'
                    });
                }
            })
        }
    });
});