﻿function getNavCookie(name) {
    if (document.cookie.length > 0) {
        start = document.cookie.indexOf(name + "=");
        if (start != -1) {
            start += name.length + 1;
            end = document.cookie.indexOf(";", start);
            if (end == -1) end = document.cookie.length;
            return unescape(document.cookie.substring(start, end));
        }
    }
    return "";
}

function DeactivateAll() {
    $('#ProjectDetailDiscussionSwitch').removeClass('ol-DiscussionSummaryHeadline');
    $('#ProjectDetailBlogSwitch').removeClass('ol-DiscussionSummaryHeadline');
    $('#ProjectDetailFAQSwitch').removeClass('ol-DiscussionSummaryHeadline');
    
    $('#ProjectDetailDiscussionSwitch').addClass('ol-DiscussionSummaryHeadlineInactive');
    $('#ProjectDetailBlogSwitch').addClass('ol-DiscussionSummaryHeadlineInactive');
    $('#ProjectDetailFAQSwitch').addClass('ol-DiscussionSummaryHeadlineInactive');
}

function SetupProjectDetailNavigation() {
    // set discussion visiable by default
    $('#ProjectDetailLowerLeftZoneWrapper').show();
    
    $('#ProjectDetailLowerLeftZoneWrapper table div:eq(0)').hide();
    $('#projectBlogList').hide();
    $('#projectDiscussionList').hide();

    // show one of the three
    if ($('#ProjectDetailBlogSwitch').length > 0) {
        $('#projectBlogList').show();
    } else if ($('#ProjectDetailDiscussionSwitch').length > 0) {
        $('#projectDiscussionList').show();
    }
    else if ($('#ProjectDetailFAQSwitch').length > 0) {
        $('#ProjectDetailLowerLeftZoneWrapper table div:eq(0)').show();
    }

    $('#ProjectDetailDiscussionSwitch').click(function() {

        // show the discussions
        DeactivateAll();
        $('#ProjectDetailDiscussionSwitch').removeClass('ol-DiscussionSummaryHeadlineInactive');
        $('#ProjectDetailDiscussionSwitch').addClass('ol-DiscussionSummaryHeadline');

        $('#ProjectDetailLowerLeftZoneWrapper table div:eq(0)').hide();
        $('#projectBlogList').hide();
        $('#projectDiscussionList').show();

        // force silverlight to recalc the size for the html scroller
        recalculateSize();
    });

    $('#ProjectDetailBlogSwitch').click(function() {
        // show the blogs
        DeactivateAll();
        $('#ProjectDetailBlogSwitch').removeClass('ol-DiscussionSummaryHeadlineInactive');
        $('#ProjectDetailBlogSwitch').addClass('ol-DiscussionSummaryHeadline');

        $('#ProjectDetailLowerLeftZoneWrapper table div:eq(0)').hide();
        $('#projectDiscussionList').hide();
        $('#projectBlogList').show();

        // force silverlight to recalc the size for the html scroller
        recalculateSize();        
    });

    $('#ProjectDetailFAQSwitch').click(function() {
        // show the faq
        DeactivateAll();
        $('#ProjectDetailFAQSwitch').removeClass('ol-DiscussionSummaryHeadlineInactive');
        $('#ProjectDetailFAQSwitch').addClass('ol-DiscussionSummaryHeadline');

        $('#ProjectDetailLowerLeftZoneWrapper table div:eq(0)').show();
        $('#projectDiscussionList').hide();
        $('#projectBlogList').hide();

        // force silverlight to recalc the size for the html scroller
        recalculateSize();        
    });

    // remove the vertical spacing from the webpart zone
    $('#ProjectDetailLowerLeftZoneWrapper div.ms-PartSpacingVertical').remove();
}

function SetSelectedCategory(name) {
    $('.ol-CategoryNavSubSelected').addClass('ol-CategoryNavSub');
    $('.ol-CategoryNavSubSelected').removeClass('ol-CategoryNavSubSelected');
    $('.ol-CategoryNavSub[id="category_' + name + '"]').addClass('ol-CategoryNavSubSelected');
}

function recalculateSize() {
    try {
        top.frameLoaded($(document).height());
    }
    catch (e) { }
}

/* Feedback Functions */

function ShowFeedbackWindow() {
    // Check browser version and determine correct "display" css value
    var sDisplayCSSValue = "table";
    if (navigator.appName == "Microsoft Internet Explorer") {
        sDisplayCSSValue = "block";
    }
    var FeedbackTable = document.getElementById("FeedbackTable");

    // unhide table
    FeedbackTable.style.display = sDisplayCSSValue;
    // Position box so it lands in center of scrolled window
    FeedbackTable.style.top = (document.body.scrollTop);

    $('#FeedbackDiv1').css("margin-top", "40px");
    $('#FeedbackFrameDiv').html('');
    $('#FeedbackFrameDiv').append('<iframe frameborder="0" width="700" height="450" style="border: 0;" src="/_layouts/olsite/Feedback.aspx"></iframe>');

    //Show semi-transparent white background
    var backgroundWhite = document.getElementById("backgroundWhite");
    backgroundWhite.style.display = "block";
    backgroundWhite.style.height = document.body.scrollHeight;
    // Show Slide Show window
    document.getElementById("FeedbackDiv1").style.display = sDisplayCSSValue;
}

function CloseFeedbackWindow() {
    //Hide semi-transparent white background
    backgroundWhite.style.display = "none";
    // Hide Span
    FeedbackDiv1.style.display = "none";
    // Hide table
    FeedbackTable.style.display = "none";
}