/* Minification failed. Returning unminified contents.
(2,17): run-time error CSS1031: Expected selector, found '='
(2,17): run-time error CSS1025: Expected comma or open brace, found '='
(4,13): run-time error CSS1031: Expected selector, found '='
(4,13): run-time error CSS1025: Expected comma or open brace, found '='
(5,13): run-time error CSS1031: Expected selector, found '='
(5,13): run-time error CSS1025: Expected comma or open brace, found '='
(7,10): run-time error CSS1031: Expected selector, found 'showSingle('
(7,10): run-time error CSS1025: Expected comma or open brace, found 'showSingle('
(11,10): run-time error CSS1031: Expected selector, found 'changeCat('
(11,10): run-time error CSS1025: Expected comma or open brace, found 'changeCat('
(28,10): run-time error CSS1031: Expected selector, found 'showStyle('
(28,10): run-time error CSS1025: Expected comma or open brace, found 'showStyle('
(47,10): run-time error CSS1031: Expected selector, found 'showStyleNovel('
(47,10): run-time error CSS1025: Expected comma or open brace, found 'showStyleNovel('
(67,10): run-time error CSS1031: Expected selector, found 'removeSOverlay('
(67,10): run-time error CSS1025: Expected comma or open brace, found 'removeSOverlay('
(74,10): run-time error CSS1031: Expected selector, found 'attachOverlay('
(74,10): run-time error CSS1025: Expected comma or open brace, found 'attachOverlay('
(98,10): run-time error CSS1031: Expected selector, found 'changePose('
(98,10): run-time error CSS1025: Expected comma or open brace, found 'changePose('
(111,10): run-time error CSS1031: Expected selector, found 'changePoseWStyle('
(111,10): run-time error CSS1025: Expected comma or open brace, found 'changePoseWStyle('
(123,10): run-time error CSS1031: Expected selector, found 'changeColor('
(123,10): run-time error CSS1025: Expected comma or open brace, found 'changeColor('
(133,1): run-time error CSS1019: Unexpected token, found '$'
(133,2): run-time error CSS1019: Unexpected token, found '('
(133,12): run-time error CSS1031: Expected selector, found '('
(133,12): run-time error CSS1025: Expected comma or open brace, found '('
(136,2): run-time error CSS1019: Unexpected token, found ')'
(138,10): run-time error CSS1031: Expected selector, found 'addPrepayDone('
(138,10): run-time error CSS1025: Expected comma or open brace, found 'addPrepayDone('
(147,10): run-time error CSS1031: Expected selector, found 'orderStyle('
(147,10): run-time error CSS1025: Expected comma or open brace, found 'orderStyle('
 */

var pixelSource = '/content/img/imgTr978.gif';

var preload = new Image();
preload.src = pixelSource;

function showSingle() {
    $('#modSinglePose').modal();
}

function changeCat(catID, catDesc) {
    var flyerCode = $('#_curCode').val();
    var cat = catID;
    var shopMode = $('#_curShopMode').val();
    $('#_curCat').val(cat);

    $('#divCurCat').html(catDesc);

    var url = "/Purchase/updateStylesView";

    $.post(url, { "flyerCode": flyerCode, "catStr": cat, "shopMode": shopMode }, function (data) {
        $('#modalCategory').modal('hide')
        $("#styleView").html(data);
    })

}

function showStyle(templateID, dispUrl, warningText) {
  
    $('#_curTemplateID').val(templateID);
    $('#_curStyleDef').val(dispUrl);
    $("#imgSelectedStyle").attr("src", dispUrl);
    attachOverlay();

    $('#_curPoseCode').val($('#_curCode').val());

    $('#divChooseWarningText').html(warningText);
    if (warningText.length > 0) 
        $('#divChooseWarning').show();
    else
        $('#divChooseWarning').hide();

    $('#modShowStyle').modal();

}

function showStyleNovel(templateID, dispUrl, warningText, orderID) {

    $('#_curTemplateID').val(templateID);
    $('#_curStyleDef').val(dispUrl);
    $("#imgSelectedStyle").attr("src", dispUrl);
    attachOverlay();

    $('#_curCode').val(orderID);
    $('#_curPoseCode').val($('#_curCode').val());

    $('#divChooseWarningText').html(warningText);
    if (warningText.length > 0)
        $('#divChooseWarning').show();
    else
        $('#divChooseWarning').hide();

    $('#modShowStyle').modal();

}

function removeSOverlay()
{
   
    $('.protectionOverlay').remove();
   
}

function attachOverlay() {
    $('#imgSelectedStyle').on('mouseenter touchstart', function (e) {
      
        var img = $(this);

        if (img.hasClass('protectionOverlay'))
            return;

        var pos = img.offset();
        var overlay = $('<img class="protectionOverlay" src="' + pixelSource + '" width="' + img.width() + '" height="' + img.height() + '" />').css({ position: 'absolute', zIndex: 9999999, left: pos.left, top: pos.top }).appendTo('body').bind('mouseleave', function () {
            setTimeout(function () { overlay.remove(); }, 0, $(this));
        });
        if ('ontouchstart' in window) $(document).one('touchend', function ()
        {
            setTimeout(function ()
            {
               
                overlay.remove();
            }, 0, overlay);
        });
    });

}

function changePose(orderCode) {
    var curCat = $('#_curCat').val();
    var shopMode = $('#_curShopMode').val();

    var url = "/Purchase/updateStylesView";
    $('#_curCode').val(orderCode);

    $.post(url, { "flyerCode": orderCode, "catStr": curCat, "shopMode": shopMode }, function (data) {
        $('#modalPoses').modal('hide');
        $("#styleView").html(data);
    });
}

function changePoseWStyle(orderCode) {
    var tmplateID = $('#_curTemplateID').val();
    var styleDef = $('#_curStyleDef').val();
    var url = "/Purchase/getStylePose";

    $.post(url, { "orderCode": orderCode, "templateID": tmplateID, "styleDefStr": styleDef }, function (data) {
        $("#imgSelectedStyle").attr("src", data);
        $('#_curStyleDef').val(data);
        $('#_curPoseCode').val(orderCode);
    });
}

function changeColor(color) {
    var tmplateID = $('#_curTemplateID').val();
    var styleDef = $('#_curStyleDef').val();

    $.post("/Purchase/getStyleColor", { "templateID": tmplateID, "styleDefStr": styleDef, "color": color }, function (data) {
        $("#imgSelectedStyle").attr("src", data);
        $('#_curStyleDef').val(data);
    });
}

$(function () {
    $('[data-toggle="tooltip"]').tooltip();

});

function addPrepayDone(result) {

    $('#modPreviewInfo').modal('hide');
    if (result.length > 0) {
        $('#_curEntryID').val(result);
        orderStyle(false);
    }
}

function orderStyle(giftMode) {

    if ($('#_curEntryID').val() === "0") {
      
        $("#modShowStyle").removeClass("fade").modal("hide");
        $('#modPreviewInfo').modal();
        return;
    }
    var oc = $('#_curPoseCode').val();

    var item = {
        "ent": $('#_curEntryID').val(),
        "code": oc,  //$('#_curCode').val(),
        "cat": $('#_curCat').val(),
        "temp": $('#_curTemplateID').val(),
        "ldef": $('#_curStyleDef').val()
    };

    var s = JSON.stringify(item);
    var s64 = Base64.encode(s);

    if (giftMode)
        window.location = "/PurchaseGift?s=" + s64;
    else
        window.location = "/PurchaseStyle?s=" + s64;

}
