﻿// adds descriptive text to the search box
function setSearchPrompt(sText, sSearchId)
{
    var element = document.getElementById(sSearchId);
    if(element.value == '')
    {
        element.value = sText;
        element.style.color = '#c0c0c0';
    }
}

// clears text in the search box
function clearSearchPrompt(sText, sSearchId)
{
    var element = document.getElementById(sSearchId);
    if(element.value == sText)
    {
        element.value = '';
    }
    element.style.color = '#000000';
}

// clicks the button specified by oButtonIdToClick when enter key is pressed.
function onEnterKeyPressHandler(oButtonIdToClick)
{
	// process only the Enter key
	if(event.keyCode == 13)
	{
		// cancel the default submit
		event.returnValue = false;
		event.cancel = true;

		var oButtonToClick = document.getElementById(oButtonIdToClick);
		oButtonToClick.click();
	}
}

// clicks the link specified by oLinkIdToClick when enter key is pressed.
function onEnterKeyPressHandlerLink(oLinkIdToClick)
{
    // process only the Enter key
	if(event.keyCode == 13)
	{
		var oLinkToClick = document.getElementById(oLinkIdToClick);
		oLinkToClick.click();
	}
}

// redirects to the search results page with the query specified.
function redirectToSearch(sDefaultSearchText, sElementId)
{
    var element = document.getElementById(sElementId);
    var sSearchTerm = element.value;
    if(element.value == sDefaultSearchText)
    {
        sSearchTerm = '';
    }
    window.location.href = '/SearchResults.aspx?q=' + sSearchTerm;
}

// shows the callout specified by sCalloutElementId.
function showCallout(sCalloutElementId)
{
    document.getElementById(sCalloutElementId).style.display = 'block';
}

// hides the callout specified by sCalloutElementId.
function hideCallout(sCalloutElementId)
{
    document.getElementById(sCalloutElementId).style.display = 'none';
}

// validates the field and shows the callout
function showCalloutValidate(sCalloutElementId, sValidateFunction)
{
    document.getElementById(sCalloutElementId).style.display = 'block';
    if(sValidateFunction != '')
    {
        eval(sValidateFunction);
    }
}

// validates the field and hides the callout
function hideCalloutValidate(sCalloutElementId, sValidateFunction)
{
    document.getElementById(sCalloutElementId).style.display = 'none';
    if(sValidateFunction != '')
    {
        eval(sValidateFunction);
    }
}

// sets focus of control specified
function setLoadFocus(sElementId)
{
    document.getElementById(sElementId).focus();
}