﻿//Add js onLoad event.
jQuery(document).ready(function () {

    // set the breadcrumb root
    jQuery(".topNavigation a").click(function () {
        if ($(this).attr("itemID")) {
            document.cookie = "BreadcrumbRootItem" + "=" + $(this).attr("itemID") + "; path=/;";
            return true;
        }
    });

    // clear the breadcrumb root
    jQuery(".footer-menu a").click(function () {
        document.cookie = "BreadcrumbRootItem=\"\"; path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT";
        return true;
    });

    // Search Input Field text label
    jQuery('.searchBox #searchInput').live('blur', function (event) {
        if (jQuery.trim($(this).val()) == '') {
            jQuery(this).val('search');
        }
    });

    jQuery('.searchBox #searchInput').live('focus', function (event) {
        if (jQuery(this).val() == "search") {
            jQuery(this).val('');
        }
    });

    //Search Button and input action
    jQuery("#searchBtn").click(changeSearchAction);
    SearchFldKey();
});


//Load Search Page
function changeSearchAction() {
    if (jQuery('#searchInput').attr("value") != '') {
        var searchUrl = '/Search-Results/?searchText=' + escape(jQuery('#searchInput').attr("value"));
        document.location.href = searchUrl;
    }
    return false;
}

//Get the onKeypress event for the text field and call the search after press enter/return (13);
function SearchFldKey() {
    var objSearchFld = null;
    objSearchFld = document.getElementById('searchInput');
    if (objSearchFld) {
        objSearchFld.onkeypress = function (e) {
            // Get an event object
            var code;
            if (!e) {
                var e = window.event;
            }
            if (e.keyCode) {
                code = e.keyCode;
            }
            else if (e.which) {
                code = e.which;
            }
            if (code) {
                if (code == 13) {
                    changeSearchAction();
                    return false;
                }
            }
        }
    }
}

