// SearchValidation.js


	
			
/* 
If javascript enabled, remove the search field label and use it as a placeholder in the search field.
When the user clicks into the field (focus) to add a search string, remove the placeholder.
When the user goes away from the field (blur) without entering a search string, replace the placeholder.
If the user has entered a search string, leave the string in place.

If javascript not enabled, search field label is visible.
 */

$(document).ready(function() {
  var searchLabel = $('#CatalogSearchForm label').remove().text();
  
  $('#searchTerm').addClass('placeholder').val(searchLabel).focus(function() {
    if (this.value == searchLabel) {
      $(this).removeClass('placeholder').val('');
    };
  }).blur(function() {
    if (this.value == '') {
      $(this).addClass('placeholder').val(searchLabel);
    };
  });
  $('#CatalogSearchForm').submit(function() {
    if ($('#searchTerm').val() == searchLabel) {
      $('#searchTerm').val('');
    }
  });
  
});


		
			
/* 
If javascript enabled, remove the search field label and use it as a placeholder in the search field.
When the user clicks into the field (focus) to add a search string, remove the placeholder.
When the user goes away from the field (blur) without entering a search string, replace the placeholder.
If the user has entered a search string, leave the string in place.

If javascript not enabled, search field label is visible.
 */

$(document).ready(function() {
  var searchLabel2 = $('#frmFreeTextSearchForm label').remove().text();
  $('#searchbox').addClass('placeholder').val(searchLabel2).focus(function() {
    if (this.value == searchLabel2) {
      $(this).removeClass('placeholder').val('');
    };
  }).blur(function() {
    if (this.value == '') {
      $(this).addClass('placeholder').val(searchLabel2);
    };
  });
  $('#frmFreeTextSearchForm').submit(function() {
    if ($('#searchbox').val() == searchLabel2) {
      $('#searchbox').val('');
    }
  });
});




//////////////////////////////////////////////////////////
// This function will prevent submission of the specified
// form if the value of the specified field is null or whitespace.
// 
// If submission is prevented, the specified error will be 
// displayed in a messagebox.
//////////////////////////////////////////////////////////
function doSubmit(form, fieldName, errorMessage) {
	var fieldValue = form.elements[fieldName].value;
	var trimmed = fieldValue.replace(/^\s+|\s+$/g, '') ;
	if (trimmed=="") {
		alert(errorMessage);
		return false;
	} else {
		return true;
	}	
}