'use strict';
(function() {
    // sitetools - script tweaks to top-right tool area - DJB Labcare

    // When accessed through a third-party server, remove language flags;
    // replace with UK flag pointing back to main .co.uk site. In particular
    // this will happen when the site is being viewed through Google Translate
    //
    if (location.host!='www.djblabcare.co.uk' && location.host!='www.djblabcare.local') {
        var sitelangs= id('sitelangs');
        sitelangs.innerHTML= '';
        sitelangs.appendChild(el('a', {href: 'http://www.djblabcare.co.uk', target: '_top'}, [
            el('img', {src: 'http://www.djblabcare.co.uk/img/lang/en.gif'})
        ]));
    }

    // Search box label
    //
    var query= id('sitesearch').elements['q'];
    function searchcheck() {
        if (query.value==='' || query.value==='(site search)') {
            cl(query).add('disabled');
            query.value= '(site search)';
            query.onfocus= function() {
                query.value= '';
                cl(query).remove('disabled');
            };
        }
    }
    searchcheck();
    ev(window, 'load', searchcheck);

    // Don't submit empty search query
    //
    id('sitesearch').onsubmit= function() {
        if (query.value==='(site search)' || query.value.trim()==='') {
            alert('Please enter word(s) to search for');
            query.focus();
            return false;
        }
    }

    // Hack min-height to try to persuade the footer to the bottom
    //
    function footit() {
        var h= document.documentElement.clientHeight;
        if (id('content'))
            id('content').style.minHeight= Math.max(h-280, 620)+'px'
        if (id('products'))
            id('products').style.minHeight= Math.max(h-420, 480)+'px'
    }
    ev(window, 'resize', footit);
    ev(window, 'load', footit);
    ev(window, 'DOMContentLoaded', footit);
})();


