﻿/* function checkForText                                                      */
/* Check for content (text or an image) in an html element                    */
/*                                                                            */
/* Parameters:                                                                */
/*  Object objectToCheck - the elementID to check                             */
/*  Object objectToShow - the elementID to show                               */
/*  [Optional] String display - blank or null if not changing display,        */
/*               otherwise a valid display type (e.g. block or inline)        */
/*  [Optional] String visible - true if object's visibility should be set to  */
/*               visible                                                      */

function checkForText(objectToCheck, objectToShow, display, visible) {
  var objCheck = objectToCheck;
  if (objCheck.charAt(0) !== '.' && objCheck.charAt(0) !== '#') {
    objCheck = '#' + objCheck;
  }

  var objShow = objectToShow;
  if (objShow.charAt(0) !== '.' && objShow.charAt(0) !== '#') {
    objShow = '#' + objShow;
  }

  if ($(objCheck).length > 0 && ($(objCheck).text().trim() !== "" || $(objCheck + " img").length > 0)) {
    if (display !== "" && display != null) {
      $(objShow).css("display", checkDisplay(display));
    };
    if (visible !== "" || visible != null) {
      $(objShow).css("visibility", visible);
    };
  }
}


// Handle poor css support in certain browsers.
// (see also http://reference.sitepoint.com/css/display#usernote644)
function checkDisplay(display) {
  if (display === "table-row") {
    return "block";
  }
  return display;
}
