
/* PriceSmart.com Javascript code for Search functions */

/* VARIABLES */

// The first time the field gets focus, store the "search..." text
var g_bSearchFirstFocus = true;
var g_strSearchText = "";


/* FUNCTIONS */

function SubmitSearch( ) {
	// Get a pointer to the search form
	var objForm = DocumentObject( "search-form", false );
	
	// Make sure the field isn't empty
	if ( objForm.Keywords.value == ""  ||  objForm.Keywords.value == g_strSearchText ) {
		if ( ! g_bSearchFirstFocus ) {
			objForm.Keywords.value = g_strSearchText;
		}
	} else {
		if ( ! g_bSearchFirstFocus ) {
			// Submit the form
			objForm.submit();
		}
	}
}

function SearchFieldFocus( ) {
	// Get a pointer to the search form
	var objForm = DocumentObject( "search-form", false );

	// If this is the first time the field is selected, store the 'search...' text
	if ( g_bSearchFirstFocus ) {
		g_strSearchText = objForm.Keywords.value;
		g_bSearchFirstFocus = false;
	}
	
	if ( objForm.Keywords.value = g_strSearchText ) {
		objForm.Keywords.value = "";
	}
}

function SearchFieldBlur( ) {

	// Get a pointer to the search form
	var objForm = DocumentObject( "search-form", false );

	// Restore the 'search...' text if the field is blank
	if ( ! g_bSearchFirstFocus && objForm.Keywords.value == "" ) {
		objForm.Keywords.value = g_strSearchText;
	}
}