﻿var isOpen = false;
function PrintClick() {
    var uniqueId = $("#ctl00_ContentPlaceHolder1_hidUserId").val();
    $.get("Common/CountTimesPrinted.ashx?UniqueID=" + uniqueId, function (data) {
        if (data == "Y") {
            window.print();
        }
        else if (data == "N") {
            ShowCouponError();
        }
    });

    $(".closebox img").click(function () {
        closePopUp();
    });
}

function ShowCouponError() {
    var width = 610;
    var height = 130;
    var top;
    var left;
    var midleft;
    var midtop;
    var winheight;
    var winwidth;

    $(".pop_box").animate({ "opacity": 0 }, 1);
    left = parseInt(Math.ceil($("body").width()) / 2 - (parseInt(width) / 2));

    top = parseInt(($.pageHeight() - height) / 2) + $(document).scrollTop();
    winheight = parseInt($(document).height());
    midleft = parseInt(document.body.clientWidth) / 2;
    midtop = parseInt($.pageHeight() / 2) + $(document).scrollTop();
    winwidth = parseInt($("body").width());
    $(".pop_box").attr("style", "height:" + winheight + "px;width:" + winwidth + "px;");
    $(".pop_box").animate({ "opacity": 0.5 }, 50);
    $(".pop_cont").attr("style", "top:" + midtop + "px;width:1px;height:1px;left:" + midleft + "px;");
    $("#div_couponError").html('<iframe src="CouponError.html" frameborder="0" scrolling="no" width="1" height="1"></iframe>');
    $(".pop_cont").animate({ "width": width, "height": height, "left": left, "top": top, "opacity": 1 }, 600, "linear", function () {
        $("#div_couponError iframe").attr("style", "width:" + width + "px;height:" + height + "px;");
    });
    $(".pop_couponError").show();
    isOpen = true;
}

function closePopUp() {
    $(".pop_box").animate({ "opacity": 0 }, 500);
    $(".pop_cont").animate({ "opacity": 0 }, 500, function () {
        $(".pop_cont").hide();
        $(".pop_box").hide();
    });
    isOpen = false;
    window.location.href = "LogInEdit.aspx";
}

$.pageWidth = function () {
    return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

$.pageHeight = function () {
    return window.innerHeight != null ? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null ? document.body.clientHeight : null;
}