﻿function printWorkContent(content_id) {
    var work_content_preview = $(content_id);
    var header = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml' ><html><head><link href=\"/AltStyles/printsubmission.css\" type=\"text/css\" rel=\"stylesheet\" /></head><body><div id=\"work_preview\">";
    var footer = "</div></body></html>";
    var win = window.open("", "print_work_content_window", "", false);

    win.document.write(header + work_content_preview.html() + footer);
    win.document.close();
    return false;
}

Print = {
    Categories: function(type) {
        var content = $("#cat_" + type).html();
        var menu = $("#cat_" + type + "_menu").html();
        var special = $("#cat_specialawards").html();
        var logo = "<img src='/Images/alliance_logo_630x85.gif' alt='Alliance Logo' />";
        var header = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml' ><html><head><link href=\"/AltStyles/printsubmission.css\" type=\"text/css\" rel=\"stylesheet\" /></head><body><div id=\"work_preview\">";
        var footer = "</div></body></html>";
        var win = window.open("", "print_categories", "", false);

        win.document.write(header + logo + special + menu + content + footer);
        win.document.close();
        return false;
    }
}

WorkRegistration = {
    workBoxes: [],
    ResetWorkBoxIds: function() {
        this.workBoxes = [];
    },
    CurrentWorkBoxId: function() {
        return this.workBoxes[this.workBoxes.length - 1];
    },
    AddWorkBox: function(id) {
        this.workBoxes.push(id);
        this.workBoxes = this.workBoxes.sort();
    },
    RemoveWorkBox: function(id) {
        this.workBoxes = jQuery.grep(this.workBoxes, function(val) {
            return val != id;
        });
        this.RebuildWorkIds();
    },
    RebuildWorkIds: function() {
        $(".work_id").each(function(index) {
            $(this).text(index + 1);
        });
    }
}

function confirmLink(link, message) {
    if (confirm(message)) {
        var f = document.createElement('form');
        f.action = link.href;
        f.method = 'POST';
        link.parentNode.appendChild(f);
        f.submit();
        return false;
    }
    else {
        return false;
    }
}

function getItemsNumber() {
    var itemHeight = 122;
    var itemWidth = 122;
    var windowHeight = $(window).height();
    var windowWidth = $(window).width();
    var verticalCount = Math.floor(windowHeight / itemHeight);
    var horizontalCount = Math.floor(windowWidth / itemWidth);
    var count = verticalCount * horizontalCount;
    if (count == 0) {
        count = [horizontalCount, verticalCount, 1].filter(function(e) { return e > 0 })[0];
    }
    return count;
}

function ToggleMenuCategory(sLayerId, oParentLayer) {
    var oLayer = document.getElementById(sLayerId);

    if (oLayer != null) {
        var isDisplayed = (oLayer.style.display == "block" || oLayer.style.display == "");

        oLayer.style.display = (isDisplayed) ? "none" : "block";
        oParentLayer.style.backgroundImage = (isDisplayed) ? "url('/images/plus.jpg')" : "url('/images/minus.jpg')";
    }
}

