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 MaxFileSize = 52428800;

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(); });
});


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) {
            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 {
            CheckFileProgress();
        }
    }, "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) {}