﻿
$(document).ready(function() {

    var input = $('input#searchtext');
    var searchbox = $('div#sitesection');
    var reset = $('div.reset');
    var textv = input.val();

    input.blur();
    input.bind('focus', function() {
        searchbox.css({ "background-position": "0px -18px" });
    });
    input.bind('blur', function() {
        if (input.val() == '') {
            searchbox.css({ "background-position": "0px 0px" });
        }
    });
    var content = input.val();

    reset.bind('click', function() {
        reset.css({ "display": "none" });
        input.val('');
    });


    input.keyup(function() {
        if (input.val() == '') {
            reset.css({ "display": "none" });
        }
        else {
            reset.css({ "display": "block" });
        }
    });

    input.keydown(function(event) {
        if (event.keyCode == '13') {
            var textValue = input.val();
            var numValue = textValue - 0;
            if (numValue != textValue) {
                location.href = '/site-search/?cx=009299960045195658964%3Aphd-rnu5jpm&cof=FORID%3A9&ie=UTF-8&q=' + textValue;
            }
            else {
                if (numValue >= 1000000 && numValue <= 70000000) {
                    location.href = '/site-search/?q=' + numValue;
                }
                else {
                    location.href = '/site-search/?cx=009299960045195658964%3Aphd-rnu5jpm&cof=FORID%3A9&ie=UTF-8&q=' + numValue;
                }
            }
            return false;
        }
    });
});


