﻿var onLoadText = 'Search EFEF';
function OnSearchBoxKeyPress(textbox, e) {
    // depends on event helper script
    var evt = e.get_domEvent();
    if (KeyPressed(evt, 13)) {
        var tBox = textbox.get_element();
        var urlPath = $(tBox).data('UrlPath');
        Search(tBox, urlPath);
        e.set_cancel(true); // essential to avoid postback
        return false;
    }
}
function Search(textbox, urlPath) 
{
    if (textbox.value.length >= 2 && textbox.value != onLoadText) 
    {
        var wLoc = urlPath + '?searchtext=' + textbox.value.trimEnd();
        window.location = wLoc;
        return false;
    }
    else 
    {
        return false;
    }
}
function SearchBoxFocus(textbox) 
{
    textbox.value = textbox.value == onLoadText ? '' : textbox.value;
}
function RadSearchBoxFocus(sender, eventArgs) 
{
    var val = sender.get_value();
    sender.set_value(val == onLoadText ? '' : val);
}

var themeSearchContainer;
var themeSearchCtrl;
var themeSearchTimeout;
var themeSearchTimeoutVal = 10000;
function ShowSearchByThemePanel() {
    themeSearchContainer = $('#themeSearchBarContainer');
    if (themeSearchContainer.height() == 0) {
        $('#themedSearchBarSet').show();
        clearTimeout(themeSearchTimeout);
        themeSearchCtrl = $('#themeSearchBarCtrl');
        $('#themeSearchBarInf').html('Select an icon to search EFEF by theme');
        themeSearchContainer.animate({ height: '62px' }, 300, function() {
            themeSearchContainer.animate({ width: '958px' }, 800, function() {
                $('#themeSearchBarCtrl').animate({ height: '30px' }, 400);
                SetThemeBarTimeOut(themeSearchContainer, themeSearchCtrl);
                RemoveThemeBarTimeOutOnHover();
            });
        });
    }
    else {
        HideSearchByThemePanel(themeSearchContainer, themeSearchCtrl);
    }
    return false;
}
function HideSearchByThemePanel(themeSearchContainer, themeSearchCtrl) {
    if (themeSearchCtrl.height() == 30) {
        $('#themedSearchBarSet').unbind('mouseleave');
        $('#themedSearchBarSet').unbind('mouseenter');
        themeSearchCtrl.animate({ height: '0px' }, 400, function() {
            themeSearchContainer.animate({ width: '72px' }, 800, function() {
                themeSearchContainer.animate({ height: '0px' }, 300);
            });
        });
    }
}
function ThemeMouseOver(link, theme) {
    var themeInf = $('#themeSearchBarInf');
    $('img', link).attr('src', '/CMSPages/GetFile.aspx?guid=' + theme.ImagePath4);
    themeInf.hide();
    themeInf.html(link.rel);
    themeInf.show();
}
function ThemeMouseOut(link, theme) {
    $('img', link).attr('src', '/CMSPages/GetFile.aspx?guid=' + theme.ImagePath1);
}
function SetThemeBarTimeOut(themeSearchContainer, themeSearchCtrl) {
    themeSearchTimeout = setTimeout(function() { HideSearchByThemePanel(themeSearchContainer, themeSearchCtrl); }, themeSearchTimeoutVal);
    $('#themedSearchBarSet').bind('mouseleave', function() {
        themeSearchTimeout = setTimeout(function() { HideSearchByThemePanel(themeSearchContainer, themeSearchCtrl); }, themeSearchTimeoutVal);
    });
}
function RemoveThemeBarTimeOutOnHover()
{
    $('#themedSearchBarSet').bind('mouseenter', function() {
        clearTimeout(themeSearchTimeout);
    });
}
