﻿    String.prototype.trim = function () {
        return this.replace(/^\s*/, "").replace(/\s*$/, "");
    }
    function sendQuery() {
        jQuery('.validation-search-header').hide();
        var keyword = document.getElementById("q").value;
        if (keyword == "Example: Accounting")
            keyword = "";
        if (keyword.trim() == "") {
            jQuery('#KeywordSearchInvalidKeywordErrorMessage').show();
            jQuery('#KeywordSearchInvalidKeywordErrorMessage').click(function () {
                jQuery('#KeywordSearchInvalidKeywordErrorMessage').hide();
            });
            return;
        }
        else {
            SearchBlockUI();
        }
        var zipcode = document.getElementById("keywordzipcode").value;

        location.href = "/search.aspx?q=" + encodeURIComponent(keyword) + "&zip=" + zipcode;
    }

    jQuery(document).ready(function () {
        jQuery('#q').keypress(function (e) {
            var key = e.keyCode || e.which;
            if (key == 13) {
                e.preventDefault();
                jQuery('#search_btn').click();
            }
        });

        jQuery('#keywordzipcode').keypress(function (e) {
            var key = e.keyCode || e.which;
            if (key == 13) {
                e.preventDefault();
                jQuery('#search_btn').click();
            }
        });

        // we don't want this for any other sites besides collegeinfo at the moment
        //jQuery('[id="q"]').autocomplete({
        //    minLength: 3,
        //    source: '/keywordAutoComplete.ashx'
        //});

        var stext = document.getElementById("q");
        if (stext.value == "" || stext.value == "Example: Accounting") {
            stext.className = "search-border-color";
        }
        else {
            stext.className = "";
        }
    });

    function SearchBlockUI() {
        jQuery("#keywordsearch").block({
            message: '<div style=\'font-family:Tahoma;font-size:18px;color:#bababa;float:left;\'><img src="/~/media/Images/LeadgenSites/Common/ajax_loader.ashx">LOADING...</div>',
            centerY: false,
            css: { bottom: '1px', top: '1px', border: '3px solid #aaa', width: '350px', height:'auto' },
			overlayCSS: { backgroundColor: '#000', opacity: 0.6, cursor: 'default' }
        });
    }

    var onEndSearch = function () {
        jQuery("#keywordsearch").unblock();
    }

    var searchParm = Sys.WebForms.PageRequestManager.getInstance();
    searchParm.add_endRequest(onEndSearch);

