﻿// JScript File
function performEnterSearch(e, sSearchUrl, sSearchPhrase, rbSearchType) {
    var iKey;


    if (!e) {e = window.event;}
    iKey = e.keyCode;
    if (iKey == null) {iKey = e.which;}     //older firefox, opera
    
    //peform search only if key press is an enter
    if (iKey == 13)
    {    
        e.returnValue = false;      //cancel the event
        e.cancelBubble = true;      //cancel event bubbling to form submit
        if (e.stopPropagation) {e.stopPropagation();}
        performSearch(sSearchUrl, sSearchPhrase, rbSearchType);
    }
    
    return false;
}

function performSearch(sSearchUrl, sSearchPhrase, rbSearchType) {
	var sEncodedSearchPhrase = "";
	var sSearchType = "AND";


    if ((sSearchPhrase == null) || (sSearchPhrase == "")) {
		alert("Please enter a search phrase.");
		return;
    }
    
    //check for restricted characters
    if (sSearchPhrase.indexOf("<") > -1) {
        alert("The character sequence '<' is not allowed in searches.");
        return;
    }
    
    if (sSearchPhrase.indexOf(">") > -1) {
        alert("The character sequence '>' is not allowed in searches.");
        return;
    }
    
    //check if array of search type radio buttons is non null
    if (rbSearchType != null)
    {
        //loop through search types and use the one that is selected
        for (i=0; i<rbSearchType.length; i++) {
            if (rbSearchType[i].checked) {
                sSearchType = rbSearchType[i].value;
            }
        }
    }    
    
    //url encode search phrase
    sEncodedSearchPhrase = escape(sSearchPhrase);
    //for (i = 0; i < sSearchPhrase.length; i++) {
    //    if (sSearchPhrase.charAt(i) == " ") sEncodedSearchPhrase += "+";
    //    else sEncodedSearchPhrase += sSearchPhrase.charAt(i);
    //}

    window.location = sSearchUrl + "?SearchPhrase=" + sEncodedSearchPhrase + "&SearchType=" + sSearchType + "&Page=1&SearchArchive=1";
}

