﻿var TaxonomyId = 0;

jQuery(document).ready(function() {
    jQuery.noConflict();
    jQuery('#' + ServerVariables.PanelBrowseId).hide();
    jQuery('#TechPapersBrowseByCategory ul').hide();
    jQuery('#TechPapersBrowseByCategory').find('a[href=#TechnicalPapers]').click(function() {
        var a = jQuery(this);
        var ul = a.next('ul');
        TaxonomyId = a.attr('TaxonomyId');
        //Remove selected class for all links
        jQuery('#TechPapersBrowseByCategory').find('a').removeClass("vItemSelected");
        a.addClass("vItemSelected");
        if (ul.html() != null) {
            if (ul.css('display') == 'none') {
                jQuery('#TechPapersBrowseByCategory ul').hide();
                a.parents('ul').show();
                ul.show();
            } else {
                ul.hide();
            }
        }
        jQuery('#Articles').html('<img src="/images/loading.gif" alt="Loading..." />');
        var data = {
            TaxonomyId: TaxonomyId
        };
        jQuery.post(
            "/IA/TechPapers3.ashx",
            jQuery.param(data),
            function(response) {
                jQuery('#Articles').html(response);
            }
        );
        return true;
    });
    jQuery('#TechPapersBrowseByMarketSegment ul').hide();
    jQuery('#TechPapersBrowseByMarketSegment').find('a[href=#TechnicalPapers]').click(function() {
        var a = jQuery(this);
        var ul = a.next('ul');
        TaxonomyId = a.attr('TaxonomyId');
        //Remove selected class for all links
        jQuery('#TechPapersBrowseByMarketSegment').find('a').removeClass("vItemSelected");
        a.addClass("vItemSelected");
        if (ul.html() != null) {
            if (ul.css('display') == 'none') {
                jQuery('#TechPapersBrowseByMarketSegment ul').hide();
                a.parents('ul').show();
                ul.show();
            } else {
                ul.hide();
            }
        }
        jQuery('#Articles').html('<img src="/images/loading.gif" alt="Loading..." />');
        var data = {
            TaxonomyId: TaxonomyId
        };
        jQuery.post(
            "/IA/TechPapers3.ashx",
            jQuery.param(data),
            function(response) {
                jQuery('#Articles').html(response);
            }
        );
        return true;
    });
    jQuery('#TechPapersBrowseByYear ul').hide();
    jQuery('#TechPapersBrowseByYear').find('a[href=#TechnicalPapers]').click(function() {
        var a = jQuery(this);
        var ul = a.next('ul');
        TaxonomyId = a.attr('TaxonomyId');
        //Remove selected class for all links
        jQuery('#TechPapersBrowseByYear').find('a').removeClass("vItemSelected");
        a.addClass("vItemSelected");
        if (ul.html() != null) {
            if (ul.css('display') == 'none') {
                jQuery('#TechPapersBrowseByYear ul').hide();
                a.parents('ul').show();
                ul.show();
            } else {
                ul.hide();
            }
        }
        jQuery('#Articles').html('<img src="/images/loading.gif" alt="Loading..." />');
        var data = {
            TaxonomyId: TaxonomyId
        };
        jQuery.post(
            "/IA/TechPapers3.ashx",
            jQuery.param(data),
            function(response) {
                jQuery('#Articles').html(response);
            }
        );
        return true;
    });
    jQuery('#' + ServerVariables.ButtonSearchId).click(function(event) {
        event.preventDefault();
        jQuery('#Articles').html('<img src="/images/loading.gif" alt="Loading..." />');
        // Search By Category
        var RadioButtonSearchAll = document.getElementById(ServerVariables.RadioButtonSearchAllId);
        var DropDownListCategories = document.getElementById(ServerVariables.DropDownListCategoriesId);
        var category = 'Technical Papers';
        if (RadioButtonSearchAll.checked == false) {
            category = DropDownListCategories.value;
        }
        // Search By Year
        var RadioButtonPublicationDateSpecificYear = document.getElementById(ServerVariables.RadioButtonPublicationDateSpecificYearId);
        var RadioButtonPublicationDateRange = document.getElementById(ServerVariables.RadioButtonPublicationDateRangeId);
        var start;
        var stop;
        if (RadioButtonPublicationDateSpecificYear.checked == true) {
            var DropDownListPublicationDateSpecificYear = document.getElementById(ServerVariables.DropDownListPublicationDateSpecificYearId);
            start = DropDownListPublicationDateSpecificYear.value;
            stop = start;
        } else if (RadioButtonPublicationDateRange.checked == true) {
            var DropDownListPublicationDateStartingYear = document.getElementById(ServerVariables.DropDownListPublicationDateStartingYearId);
            var DropDownListPublicationDateEndingYear = document.getElementById(ServerVariables.DropDownListPublicationDateEndingYearId);
            start = DropDownListPublicationDateStartingYear.value;
            stop = DropDownListPublicationDateEndingYear.value;
            if (start > stop) {
                var temp = stop;
                stop = start;
                start = temp;
            }
        } else {
            var DropDownListPublicationDateStartingYear = document.getElementById(ServerVariables.DropDownListPublicationDateStartingYearId);
            var DropDownListPublicationDateEndingYear = document.getElementById(ServerVariables.DropDownListPublicationDateEndingYearId);
            start = DropDownListPublicationDateStartingYear.options[0].value;
            stop = DropDownListPublicationDateEndingYear.options[DropDownListPublicationDateEndingYear.options.length - 1].value;
        }
        // Search Text
        var TextBoxSearch = document.getElementById(ServerVariables.TextBoxSearchId);
        if (TextBoxSearch.value != '') {
            var TextBoxAuthorsLastName = document.getElementById(ServerVariables.TextBoxAuthorsLastNameId);
            var DropDownListSort = document.getElementById(ServerVariables.DropDownListSortId);
            var DropDownListOrder = document.getElementById(ServerVariables.DropDownListOrderId);
            var data = {
                Category: category,
                SearchText: TextBoxSearch.value,
                AuthorsLastName: TextBoxAuthorsLastName.value,
                Start: start,
                Stop: stop
            };
            jQuery.post(
                "/IA/TechPapers3.ashx",
                jQuery.param(data),
                function(response) {
                    jQuery('#Articles').html(response);
                    // Sort
                    //jQuery("#Articles").find("div").tsort({ order: DropDownListOrder.value, attr: DropDownListSort.value });
                    /// <debug>
                    //var TextBoxDebug = document.getElementById(ServerVariables.TextBoxDebugId);
                    //TextBoxDebug.value = response;
                    /// </debug>
                }
            );
        } else {
            jQuery('#Articles').html("");
        }
        return false;
    });
    jQuery('#' + ServerVariables.Button2ndSearchId).click(function(event) {
        event.preventDefault();
        return document.getElementById(ServerVariables.ButtonSearchId).click();
    });
    jQuery('#' + ServerVariables.ButtonResetId).click(function(event) {
        event.preventDefault();
        var RadioButtonSearchAll = document.getElementById(ServerVariables.RadioButtonSearchAllId);
        RadioButtonSearchAll.checked = true;
        var TextBoxSearch = document.getElementById(ServerVariables.TextBoxSearchId);
        TextBoxSearch.value = '';
        var TextBoxAuthorsLastName = document.getElementById(ServerVariables.TextBoxAuthorsLastNameId);
        TextBoxAuthorsLastName.value = '';
        var RadioButtonPublicationDateAll = document.getElementById(ServerVariables.RadioButtonPublicationDateAllId);
        RadioButtonPublicationDateAll.checked = true;
        var DropDownListPublicationDateStartingYear = document.getElementById(ServerVariables.DropDownListPublicationDateStartingYearId);
        DropDownListPublicationDateStartingYear.selectedIndex = 0;
        var DropDownListPublicationDateEndingYear = document.getElementById(ServerVariables.DropDownListPublicationDateEndingYearId);
        DropDownListPublicationDateEndingYear.selectedIndex = DropDownListPublicationDateEndingYear.options.length - 1;
        return false;
    });
});

function slide_trigger_onclick() {
    if (jQuery('#' + ServerVariables.PanelSearchId).is(':visible')) {
        jQuery('#' + ServerVariables.PanelSearchId).hide();
        jQuery('#' + ServerVariables.PanelBrowseId).show();
        jQuery('.search_trigger').html('(Show Options)');
        jQuery('.browse_trigger').html('(Hide Options)');
    }
    else {
        jQuery('#' + ServerVariables.PanelSearchId).show();
        jQuery('#' + ServerVariables.PanelBrowseId).hide();
        jQuery('.search_trigger').html('(Hide Options)');
        jQuery('.browse_trigger').html('(Show Options)');
    }
}

