﻿// Scripts to support Google Custom Search

// Retrieved from: http : // www . htmlcodetutorial . com/forms/index_famsupp_157.html
function submitenter(myfield, e) {
    var keycode;

    if (window.event)
        keycode = window.event.keyCode;
    else if (e)
        keycode = e.which;
    else
        return true;

    if (keycode == 13) {
        SearchSite();
        return false;
    }
    else
        return true;
}


// Retrieved from: http : // dotnetslackers . com /articles/aspnet/Implementing-Search-in-ASP-NET-with-Google-Custom-Search.aspx#944
function SearchSite() {
    var url = document.location.href;
    var searchUrl;
    
    // Determine at run-time whether the production or test site should be used
    if (url.match("www.cancersurvivorlink.org") != null) {
        searchUrl = 'http://www.cancersurvivorlink.org/SearchResults.aspx?cx=002047739903618439461:jdjpam3bhtu&cof=FORID%3A9&ie=UTF-8&q=';
    } else {
        searchUrl = 'http://test.cancersurvivorlink.org/SearchResults.aspx?cx=017549091722972267121:o65rcfadqky&cof=FORID%3A9&ie=UTF-8&q=';
    }

    document.location.href = searchUrl + URLEncode(document.getElementById('q').value) + '&sa=Search';    
}


// Swaps the background image when the user clicks the box
function searchmousedown() {
    var txt = document.getElementById("q");
    if (txt.value == "Search") {
        txt.value = "";
    }
}
