//var k_push_vars = {
//    "display_after": 30,
//    "view_percentage": 20,
//    "popup_font_color": "#000000",
//    "popup_background": "#ffffff",
//    "popup_separator": "#D4E2F0",
//    "header": "Your feedback is important to us!",
//    "question": "Would you be willing to give us a short (1 minute) feedback?",
//    "footer": "Thank you for helping us improve our website",
//    "remind": "Remind me later",
//    "remind_font_color": "#3882C3",
//    "yes": "Yes",
//    "no": "No",
//    "text_direction": "ltr",
//    "images_dir": "images/",
//    "yes_background": "#76AC78",
//    "no_background": "#8D9B86",
//    "site_code": 2259914
//};

var img1 = new Image(); img1.src = "images/blank.png";
var img2 = new Image(); img2.src = "images/BnBrowse.png";
var EmptyCheck = 0;

function AlignFooter() {
    if ((jQuery(window).height() + 5) >= jQuery(document).height()) {
        var fh = jQuery("#FooterContent").height();
        var fw = jQuery("#FooterContent").width();
        var pb = jQuery(window).height() - jQuery("form").height() + fh;
        jQuery("form").css({ paddingBottom: pb + "px" });
        jQuery("#FooterContent").css({ position: "absolute", bottom: "0px", left: "0px", width: fw + "px", height: fh + "px" });
    }
}
jQuery(function () {
    AlignFooter();
    jQuery(document).resize(function () { AlignFooter(); });
    AddFeedBack();
});

function AddFeedBack() {
    $("body").append("<div id='FeedBackDiv'><a href='http://www.reviewcentre.com/write-a-review-1415989.html' target='_blank'><img src='images/Feedback.gif' alt='Feedback/Review' /></a></div>");
    var css = "#FeedBackDiv{position:fixed;left:0px;bottom:0px;z-index:9999999;width:81px;height:81px;_position:absolute;";
    if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
        css += "_top:expression(document.documentElement.scrollTop+document.documentElement.clientHeight-this.clientHeight);_left:0px;}";
    } else {
        css += "_top:expression(document.body.scrollTop+document.body.clientHeight-this.clientHeight);_left:0px;}";
    }
    $("body").append("<style type='text/css'>" + css + "</style>");
}

function SetUploader(InputFile, UploadImage) {
    $("#" + UploadImage).click(function() {
        var UploadedFile = $("#" + InputFile).val();
        if (UploadedFile == "") {
            alert("Please select a file to upload");
            $("#" + InputFile).focus();
            return false;
        } else {
            var Extension = UploadedFile.substring(UploadedFile.lastIndexOf(".")).toLowerCase();
            if (Extension != ".jpg" && Extension != ".jpeg" && Extension != ".tif" && Extension != ".tiff") {
                alert("Invalid file selected. Currently we only support jpg and tif files.");
                return false;
            }
        }
        $("form").attr("target", "hiddenFrame");
        ShowFileProgress();
        return true;
    });
}

function ShowFileProgress() {
    if (jQuery("#Overlay").id == undefined) EnableOverlay();
    var WaitingBox = jQuery("<div></div>").attr("id", "WaitingBox").css({
        width: "400px",
        height: "126px",
        left: (jQuery(document).width() - 400) / 2 + "px",
        top: (jQuery(window).height() - 126 - 100) / 2 + "px"
    });
    if ($.browser.version == "6.0") {
        var offset = jQuery(window).width() - jQuery(".MainContainer").width();
        WaitingBox.css({ position: "absolute", left: (jQuery(window).width() - 400 + offset) / 2 + "px" });
    }
    jQuery("#Overlay").append(WaitingBox);

    var ProgressBarFlash = jQuery("<div></div>").attr("id", "ProgressBarFlash").css({width: "400px", height: "100px", overflow: "hidden"});
    WaitingBox.append(ProgressBarFlash);

    var ProgressBarContainer = jQuery("<div></div>").attr("id", "ProgressBarContainer").addClass("ProgressBarContainer");
    ProgressBarContainer.html("<div id='ProgressBarText'>Please wait...</div><div id='ProgressBar'></div>");
    WaitingBox.append(ProgressBarContainer);

    $('#ProgressBarFlash').flash({
        src: 'flash/loading-circle.swf',
        width: 400,
        height: 100,
        wmode: "transparent"
    });
    CheckFileProgress();
}

function CheckFileProgress() {
    $.get("UploadProgress.ashx", {
        DJUploadStatus: UploadKey,
        ts: new Date().getTime()
    }, function(data) {
        var status = $(data).find("status");
        var empty = status.attr('empty');
        if (!empty) {
			EmptyCheck=0;
            var percent = status.attr('progress');
            var file = status.attr('file');
            var kbs = Math.round(parseInt(status.attr('bytes')) / 1024);
            var size = Math.round(parseInt(status.attr('size')) / 1024);
            //var data = "\n\n" + 'Uploading ' + file + ' ... ' + kbs + ' of ' + size + ' KB (' + percent + "%)" + "\n\n" + $(data).find("*").text();
            $("#ProgressBarText").html(percent + "%");
            $("#ProgressBar").css({ width: percent + "%" });
            if (percent == 100) {
                $("#ProgressBarText").html("Please wait while our software checks your image quality...");
                $("#ProgressBar").css({ width: "0%" });
            }
            else CheckFileProgress();
        } else {
            EmptyCheck += 1;
            if (EmptyCheck < 100)
                CheckFileProgress();
            else {
                alert("Maximum file size allowed is 50MB. Please upload again by reducing your file size to 50 MB.");
                document.location.replace(document.location.href);
            }
        }
    }, "xml");
}

function Redirect(URL) {
    setTimeout(function() {
        $("#ProgressBar").css({ width: "0%" });
        $("#ProgressBarFlash").hide("");
        $("#ProgressBarContainer").css({ marginTop: "50px", border: "none" });
        $("#ProgressBarText").css({ fontSize: "16px" }).html("Please wait...");
        document.location.href = URL;
    }, 1000);
}


function EnableOverlay() {
    if ($("#Overlay").length > 0) return;
    var offset = jQuery(window).width() - jQuery(".MainContainer").width();
    var IE8heightFix = 0;
    if ((jQuery(window).height() + 5) >= jQuery(document).height() && $.browser.msie && $.browser.version == "8.0")
        IE8heightFix = 4;
    
    jQuery(".MainContainer").append(jQuery("<div></div>").attr("id", "Overlay").css({
        position: "absolute",
        left: -offset + "px",
        top: "0px",
        zIndex: "999",
        width: jQuery(window).width() + (offset / 2) + "px",
        height: jQuery(document).height() - IE8heightFix + "px"
    }));
    if ($.browser.version == "6.0")
        $("#Overlay").css({ filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/blank.png,sizingmethod=scale)" });
    else
        $("#Overlay").css({ backgroundImage: "url(images/blank.png)" });
}

function DisableOverlay() {
    jQuery("#Overlay").remove();
}

try {
  document.execCommand("BackgroundImageCache", false, true);
} catch (err) { }


function NextBeeCoupon() {
    EnableOverlay();
    var CouponBox = jQuery("<div></div>").attr("id", "NextBeeCoupon").css({
        width: "466px",
        height: "396px",
        position: "fixed",
        background: "transparent url(images/NextBeeCoupon.png) no-repeat left top",
        left: (jQuery(document).width() - 466) / 2 + "px",
        top: "-150px"
    }).html("<h2>Please wait...</h2>");

    jQuery.getScript("http://rewards.nextbee.com/clientfiles/813/getRecipientCouponUK.php", function () {
        if (typeof (recipientCouponCode) != "undefined" && recipientCouponCode != null) {
            var fromName = "Your friend";
            var toName = "";
            if (typeof (from) != "undefined" && from != null && from != "") fromName = from;
            if (typeof (to) != "undefined" && to != null && to != "") toName = " " + to;
            jQuery.post("ViewCart.aspx", { Action: "ValidateVoucher", "recipientCouponCode": recipientCouponCode });
            jQuery("#NextBeeCoupon").html("<h2 class='NextBeeCouponCode'>Hello" + toName + "! Thanks for visiting Canvas4Life.<br/><br/>" + fromName + " recommended this site to you and we are delighted to offer you 10% off your next order.<br/><br/>Your unique coupon code is <span id='couponCode'>" + recipientCouponCode + "</span>.<br/><br/>This code will be automatically applied at checkout during your shopping session.<br/><a href='#' onclick='return CloseNextBeeCoupon();'><img src='images/bnContinue.png' align='right' alt='Continue'/></a></h2>");
        }
    });


    if (jQuery.browser.version == "6.0" && $.browser.msie) {
        var offset = jQuery(window).width() - jQuery(".MainContainer").width();
        CouponBox.css({ position: "absolute", left: (jQuery(window).width() - 388 + offset) / 2 + "px" });
    }
    jQuery("#Overlay").append(CouponBox);
    CouponBox.animate({
        top: (jQuery(window).height() - 396 + 100) / 2 + "px"
    }, 500).click(function () {
        jQuery("#couponCode").select();
    });
    return false;
}

function CloseNextBeeCoupon() {
    jQuery("#NextBeeCoupon").animate({
        top: "-150px"
    }, 200, function () {
        DisableOverlay();
    });
    return false;
}

function PayWithPaypal(oID) {
    ShowMessageOnOverlay();
    setTimeout(function () {
        $.get("Paypal.ashx?oID=" + oID, function (data) {
            data = eval('(' + data + ')');
            if (data.Html) $("body").append(data.Html);
        });
    }, 1000);
    return false;
}

function ShowMessageOnOverlay() {
    EnableOverlay();
    jQuery("#Overlay").append(jQuery("<div></div>").attr("id", "OverlayMessage").css({
        right: (jQuery(document).width() - 300) / 2 + "px",
        top: (jQuery(window).height() - 350) / 2 + "px",
        zIndex: 11,
        backgroundColor: "Transparent",
        backgroundRepeat: "repeat-x",
        border: "solid 1px #b186aa",
        fontSize: "30px",
        padding: "33px 50px 27px 50px",
        color: "#d2acca",
        backgroundColor: "#91197A",
        backgroundImage: "url(images/MsgBg.gif)"
    }).html("<object id='Ajaxloader' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='200' height='32'><param name='movie' value='images/loading.swf' /><param name='wmode' value='transparent' /><embed type='application/x-shockwave-flash' src='images/loading.swf' width='200' height='32' id='Ajaxloader' name='Ajaxloader' wmode='transparent' /></object>"));

    if (jQuery.browser.version == "6.0" && $.browser.msie)
        jQuery("#OverlayMessage").css({ position: "absolute" });
    else
        jQuery("#OverlayMessage").css({ position: "fixed" });
    return false;
};
