﻿// We have 2 headers therefore we have two similar search functions
// Search functionality for header1, the name is validateSearch() but it should be search1()
// It only validates when the serach textbox is empty
function validateSearch1() 
{
    var val = document.forms[0].keyword.value;
   
    if (val == "" || val == null) {
        alert("Please type the word or words you wish to search for in the search box.");
    } else {
            window.location.href = 'search1.aspx?q=' + val;
    
    }
}

// Search funtionality for header2 its the same as validatesSearch1 except it calls search2.aspxpage
function validateSearch2() 
{
    var val = document.forms[0].keyword.value;
    
    if (val == "" || val == null) {
        alert("Please type the word or words you wish to search for in the search box.");
    } else {

            window.location.href = 'search2.aspx?q=' + val;
    }
}

// this was not required feauture but we did implement it because it makes search easier
// it allows you to use the enter key execute search
function submitViaEnter1(evt) 
{
    evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    var form = target.form;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);

    if (charCode == 13) {
        var val = document.forms[0].keyword.value;

        if (val == "" || val == null) {
            alert("Please type the word or words you wish to search for in the search box.");
        } else {

            window.location.href = 'search1.aspx?q=' + val;
            return false;
        }        
    }
}

// this was not required feauture but we did implement it because it makes search easier
// it allows you to use the enter key execute search
function submitViaEnter2(evt) 
{
    evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    var form = target.form;
    var charCode = (evt.charCode) ? evt.charCode :
        ((evt.which) ? evt.which : evt.keyCode);

    if (charCode == 13) {
        var val = document.forms[0].keyword.value;

        if (val == "" || val == null) {
            alert("Please type the word or words you wish to search for in the search box.");
        } else {

            window.location.href = 'search2.aspx?q=' + val;
            return false;
        }
    }
}