﻿/*
** Returns a new string in which all leading 
** and trailing occurrences of a set of 
** specified characters from the current 
** String object are removed
*/
String.prototype.Trim = function () {
    return this.replace(/^\s+|\s+$/g, '');
}
/*
** Get the key (strParamName)
** and return the value of the key
** from the url
*/
function getURLParam(strParamName) {
    var strReturn = '';
    var strHref = window.location.href;
    if (strHref.indexOf('?') > -1) {
        var strQueryString = strHref.substr(strHref.indexOf('?')).toLowerCase();
        var aQueryString = strQueryString.split('&');
        for (var iParam = 0; iParam < aQueryString.length; iParam++) {
            if (aQueryString[iParam].indexOf(strParamName.toLowerCase() + '=') > -1) {
                var aParam = aQueryString[iParam].split('=');
                strReturn = aParam[1];
                break;
            }
        }
    }
    return unescape(strReturn);
}
/*
** Get the function name and add it to the onload page event
*/
function MossOnLoad(funName) {
    if (typeof (_spBodyOnLoadFunctionNames) != 'undefined') {
        if (_spBodyOnLoadFunctionNames != null) {
            _spBodyOnLoadFunctionNames.push(funName);
        }
        else {
            window.onload = eval(funName + '()');
        }
    }
    else {
        window.onload = eval(funName + '()');
    }
}
function LoadSearchText() {
    var searchText = getURLParam('k');
    if (searchText.Trim() != '') {
        document.getElementById('txtSearch').value = searchText;
    }
}
MossOnLoad('LoadSearchText');
function SerachResult() {
    var searchWord = document.getElementById('txtSearch').value;
    if (searchWord.Trim() == '') {
        document.getElementById('txtSearch').focus();
        return;
    }
    searchWord = escape(searchWord.Trim());
    var url = SearchPage + '?s=' + Scope + '&k=' + searchWord; 
    window.location = url;
}

