﻿//A collection of JQuery DHTML effects and functionality to hide/show the xref basic/advanced search widget
$(document).ready(function () {
    var aSearch = '#AdvancedSearch';
    var sSearch = '#BasicSearch';
    var focCatalog = '#focusCatalog';
    var foc1 = '#focus1';
    var cHome = '#content_home';
    $(aSearch).add(sSearch).each(function () {
        $(this).click(function () {
            $('.search_xref').each(function () {
                if (!$(this).is(':visible')) {
                    $(this).slideDown('slow');

                    //This section is required only for the www.novaplus.com site
                    //it moves the focux widgets on the right side up and down.
                    if ($(focCatalog).length == 1) {
                        var height = 0;
                        var totalHeight = 0;
                        var p = $(this);
                        var i = p.css('top').toString().replace('px', '') * 1;
                        height = ($(this).attr('id').indexOf('Advanced') > -1) == true ? 273 : 129;
                        totalHeight = height;
                        i = i + height;
                        i = i + 10;
                        $(focCatalog).animate({ top: i }, 300);
                        p = $(focCatalog);
                        height = p.height().toString().replace('px', '') * 1;
                        totalHeight = totalHeight + height;
                        i = i + height;
                        i = i + 10;
                        $(foc1).animate({ top: i }, 300);
                        p = $(foc1);
                        height = p.height().toString().replace('px', '') * 1;
                        totalHeight = totalHeight + height;

                        var chHeight = $(cHome).height().toString().replace('px', '') * 1;
                        var x = (totalHeight - chHeight) + 10;
                        $(cHome).animate({ height: chHeight + x }, 300);
                    }
                }
                else {
                    $(this).fadeOut(0);
                }
            });
            return false;
        });
    });

    $('#Xref_form').add('#Xref_form_Advanced').each(function () {
        $(this).submit(function () {
            var page = ($(this).attr('id').indexOf('Advanced') > -1) == true ? 'Advanced.aspx' : 'Basic.aspx';
            var formAction = [];
            formAction['local'] = 'http://localhost/xref/' + page;
            formAction['dev'] = 'http://uit-xref.novaplus.com/' + page;
            formAction['uat'] = 'http://sit-xref.novaplus.com/' + page;
            formAction['prod'] = 'http://xref.novaplus.com/' + page;
            var mode = 'local';
            if (window.location.hostname.indexOf('uit-www.') == 0) {
                mode = 'dev'
            }
            if (window.location.hostname.indexOf('sit-www.') == 0) {
                mode = 'uat'
            }
            if (window.location.hostname.indexOf('www.') == 0) {
                mode = 'prod'
            }
            $(this).attr('action', formAction[mode]);
            var elements = $('#' + $(this).attr('id') + ' :input');
            var elements = $.grep(elements, function (value) { return $(value).val().length >= 3 && $(value).val().length <= 100; });
            if (elements.length > 0) {
                return true;
            }

            $(this).parent().parent().qtip({
                content: {
                    title: {
                        text: 'Error',
                        button: 'Close'
                    },
                    text: 'At minimum of 3 characters and a maximum of 100 characters is required to perform a cross reference product search.'
                },
                position: {
                    corner: {
                        target: 'center',
                        tooltip: 'center'
                    }
                },

                show: {
                    when: false, // Don't specify a show event
                    ready: true, // Show the tooltip when ready
                    solo: true
                },
                hide: { when: { event: 'unfocus' }, delay: 1500, effect: { type: 'fade'} },
                style: {

                    padding: 5,
                    textAlign: 'center',
                    tip: true,
                    name: 'red',
                    background: '#FFFFFF'

                }
            });

            return false;
        });
    });
});
