﻿Ext.onReady(function() {
    var control = Ext.get('search-control');
    var searchForm = Ext.get('search-control-form');
    var search = Ext.get('search-control-input');
    var options = Ext.get('search-control-options');
    var optionWeb = Ext.get('search-control-option-website');
    var optionBookstore = Ext.get('search-control-option-bookstore');
    var optionsCls = 'hidden'
    var activeCls = 'current';
    var grayCls = 'search-control-input-empty';
    
    search.on('focus', function(e, t) {
        this.removeClass(grayCls);
        options.removeClass(optionsCls);
    }, search)
    search.on('blur', function(e, t) {
        options.addClass(optionsCls);
        if (String.trim(this.dom.value) == "") {
            var currentValue = this.dom.value;
            if (currentValue == "") {
                this.addClass(grayCls);
            }
        }
    }, search, { buffer: 1000 });

    optionWeb.on('click', function(e) {
        search.focus();
        searchForm.dom.action = 'search.aspx';
    }, optionWeb);
    optionBookstore.on('click', function(e) {
        search.focus();
        searchForm.dom.action = 'http://cebsrv10/bookstore-uk/search.aspx'; 
    }, optionBookstore);
});