//****************************************************************
//****************************************************************
//	COPYRIGHT 2008, Vertex Software
//****************************************************************
//****************************************************************

//----------------------------------------------------------------
//----------------------------------------------------------------
// Elements that use the js_displayIfFilled class will be hidden
// if the TEXT of the elements is not empty. This means that
// non-breaking space tags only will NOT be considered content.
// If the js_displayIfFilled is followed by a class beginning with the name "filled_<targetClass>",
// the content of any elements having the targetClass applied are checked instead. 
// If any of the elements has content then the main parent element will be displayed.
// EXAMPLE:
// Notice that filled_element contains dynamic content. When the page is loaded, the div
// is checked and if no "non-empty" content is present, the element with the js_displayIfFilled
// class will be hidden.
//
// <div class="section defaultRightSection js_displayIfFilled filled_targetElement">
//  <h2>Featured Class Sponsor</h2>
//  <div class="targetElement">
//  {{INCLUDE:/programs/featured_class_sponsor_body.asp}}
//  </div>
// </div>
//----------------------------------------------------------------
//----------------------------------------------------------------



//-----------------------------------------------------------
// displayIfFilled
//-----------------------------------------------------------
function displayIfFilled( element ) {
	Initialize(element);
	

	//-----------------------------------------------------------
	// Initialize
	//-----------------------------------------------------------
	function Initialize( element ) {
		try {
			if (!element) return;
			var targetElements = $(element);
			var targetClass = (element.className.match( / (filled[^ ]*)/g ) ? RegExp.$1.replace( "filled_","") : "");
			if (targetClass) targetElements = $("." + targetClass);
			targetElements.each( function(index) {
				var targetText = $(this).text().replace( /[\n\r\t ]+/g, "");
				// If elements contains something other that whitespace, show element
				if (targetText) {
					$(element).show();
					Initialize.showed = true;
					}
				} );
			// If no elements found that caused the showed flag to be set, hide element
			if (!Initialize.showed) $(element).hide();
			}
		catch (error) {
			alert( "displayIfFilled.Initialize: " + error.description  );
			}
		}




	}


AttachBehaviors("displayIfFilled");