/*
<!--- AUTHOR: Davin Leier --->
<!--- DATE CREATED: 2006.03.08 --->
<!--- PURPOSE: Javascript to display the GF class description DHTML and it's variations --->
<!--- REVISIONS: 
--->
*/

// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE;

if (document.all) { // Internet Explorer
	IE = true;
} else if (document.getElementById) { // Netcsape 6
	IE = false;
} else if (document.layers) { // Netscape
	IE = false;
} 

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// Temporary variables to hold mouse x-y pos.s
var tempX = 0;
var tempY = 0;

// Preload any images being displayed
if (document.images) {
	searchingImage = new Image();
	searchingImage.src = "/images/modules/searching/SearchingAnimation.gif";
	
	ltfLogo = new Image();
	ltfLogo.src = "/images/group_fitness/class_pop_up/ltf_logo.gif";
	
	classDescriptionImage = new Image();
	classDescriptionImage.src = "/images/group_fitness/class_pop_up/class_description_header.gif";
	
	rssLogo = new Image();
	rssLogo.src = "/images/rss/rss_logo.gif";
}

// Main function to retrieve mouse x-y pos.s
function getMouseX(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  return tempX
}
function getMouseY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempY < 0){tempY = 0}
  return tempY
}

// Function to show the class description in a HTML Div Popu for a Group Fitness class
function showClassDescription(event,classID,clubID,className,skillLevel,skillLevelColor,description)	{
	if(!event){
		event = document.captureEvents(Event.MOUSEOVER)
	}
	if (!document.createElement)	{
		return;
	}
    var elmDiv = document.createElement('div');
	if (typeof(elmDiv.innerHTML) != 'string')	{
		return;
	}
	elmDiv.id  = 'classdescription';	
	
	var divWidth = 340;
	var divHeight = 200;
	
	var posX = getMouseX(event);
	var posY = getMouseY(event);	
	var myWidth = getWindowWidth() ;
	var myHeight = getWindowHeight() ;

	if (myWidth < posX + divWidth){
		posX = posX - divWidth;
	}	
	/*
	if (myHeight < posY + divHeight){
		posY = posY - divHeight;
	}
	*/
	elmDiv.style.cssText = 
         'position: absolute; left: '+posX+'px; top: '+posY+'px;' 
         + 'width: '+divWidth+'px;'
         + 'padding: 4px;'
		 + 'overflow: auto;'
		 + 'height: '+divHeight+'px;'
		 + 'background-color: #ffffff;'
		 + 'border: 2px Solid #999999;';

	var html = '<table width="100%" border="0" cellpadding="0" cellspacing="0">'
				+ '<tr><td style="width: 110px; text-align: center; padding: 9px 0px 4px 0px;"><img src="'
				+ ltfLogo.src
				+ '" width="92" height="37" alt="Life Time Fitness" border="0"></td><td style="background-color: #80465f; padding: 12px 0px 15px 10px;"><img src="'
				+ classDescriptionImage.src
				+ '" width="147" height="18" alt="Class description" border="0"></td></tr><tr><td colspan="2" style="padding: 5px 10px;"><div style="text-align: right;"><a href="javascript: hideClassDescription();">Close</a></div><div style="font-weight: bold;">'
				+ className
				+ '</div><div style="color: #'
				+ skillLevelColor
				+ '; font-weight: bold;">'
				+ skillLevel
				+ '</div><div>'
				+ description
				+ '</div><div style="padding-top: 5px;"><a href="index.cfm?strWebAction=class_finder_results&intClassId='
				+ classID
				+'&listClubIds='
				+ clubID
				+'">View this Class at Other Clubs</a></div></td></tr>'
				/*
				+'<a href="http://www.lifetimefitness.com/rss/index.cfm?strWebAction=gf_class_feed&intClubId='
				+ clubID
				+'&intClassId='
				+ classID
				+'" onClick="openRSSPanel(this.href);hideClassDescription();return(false);"><img src="'
				+ rssLogo.src
				+'" width="12" height="12" alt="Add to RSS Feed"> RSS Feed</a>'
				*/
				+'</table>';

    document.body.appendChild(elmDiv);
    elmDiv.innerHTML = html;
}
function openRSSPanel(rssLink){	
	var width = 390;
	var height = 195;
	var x = (800 - width) / 2 ;
	var y = (screen.height - height) / 2 ;
	
	var encodedFeedLink = URLEncode(rssLink);
	
	openWindow('/rss/index.cfm?strWebAction=pick_rss_reader&strFeedLink='+encodedFeedLink,'RSS',width, height, x, y, 'no');
}
// Hides the Group Fitness Class description
function hideClassDescription()	{
	var elmDiv = document.getElementById('classdescription');
	if (elmDiv)	
		{
          elmDiv.parentNode.removeChild(elmDiv);
        }
}

// Shows the Group Fitness class attribute description in DHTML Div popup
function showAttributeDescription(event,description){
	if(!event){
		event = document.captureEvents(Event.MOUSEOVER)
	}
	if (!document.createElement)	{
		return;
	}
    var elmDiv = document.createElement('div');
	if (typeof(elmDiv.innerHTML) != 'string')	{
		return;
	}
	elmDiv.id  = 'attributedescription';	
	
	var posX = getMouseX(event) + 15;
	var posY = getMouseY(event);

	elmDiv.style.cssText = 
     'position: absolute; left: '+posX+'px; top: '+posY+'px;' 
     + 'padding: 4px;'
		 + 'background-color: #ffffff;'
		 + 'border: 2px Solid #999999;';

	var html = '<span style="font-size: 10px;">'
				+ description 
				+ '</span>';

  document.body.appendChild(elmDiv);
  elmDiv.innerHTML = html;
}

// Hides the Group Fitness Class attribute description 
function hideAttributeDescription()	{
	var elmDiv = document.getElementById('attributedescription');
	if (elmDiv)	
		{
     elmDiv.parentNode.removeChild(elmDiv);
    }
}

// Shows DHTML Div popup showing a searching graphic for the GF and MA when a search is performed
function showProcessingMessage() {
	if (!document.createElement)	{
		return;
	}
    var elmDiv = document.createElement('div');
	if (typeof(elmDiv.innerHTML) != 'string')	{
		return;
	}
	elmDiv.id  = 'processingMessage';	
	
	var posX = 300;
	var posY = 250;

	elmDiv.style.cssText = 'position: absolute; left: '+posX+'px; top: '+posY+'px;' 
							+ 'z-index:100;'
     						+ 'padding: 4px;'
							+ 'background-color: #ffffff;'
							+ 'border: 2px Solid #999999;'
							+ 'width: 200px;'
							+ 'height: 200px;';

	var html = '<div style="text-align: center;"><img src="'
				+ searchingImage.src
				+ '" alt="Searching..." border="0"></div>'
				+ '<div style="text-align: center;"><a href="javascript:void(0);" onClick="hideProcessingMessage();">Close</a></div>';

   document.body.appendChild(elmDiv);
   elmDiv.innerHTML = html;
}

// Hides the GF and MA searching DHTML popup div
function hideProcessingMessage()	{
	var elmDiv = document.getElementById('processingMessage');
	if (elmDiv)	
		{
     elmDiv.parentNode.removeChild(elmDiv);
    }
}

// Checks to make sure that an activity is selected on the MA main page
function checkActivityId() {
	var f = document.activitiesForm;
	if (f.intActivityId.value == "") {
		alert("You must select an Activity.");
		f.intActivityId.focus();
	} else {
		showProcessingMessage();
		f.submit();
	}
}

// Show a DHTML div with the text to display passed and the width passed in to it. The popup opens 
function showPopupDiv(event,text,divWidth){
	if(!event){
		event = document.captureEvents(Event.ONCLICK)
	}
	if (!document.createElement)	{
		return;
	}
	if (!divWidth){
		var divWidth = 400;
	}
    var elmDiv = document.createElement('div');
	if (typeof(elmDiv.innerHTML) != 'string')	{
		return;
	}
	elmDiv.id  = 'popupDiv';	
	
	var posX = getMouseX(event);
	var myWidth = getWindowWidth() ;
	
	if (myWidth < posX + divWidth + 20){
		posX = posX - divWidth;
	}	
	
	var posY = getMouseY(event);

	elmDiv.style.cssText = 'position: absolute; left: '+posX+'px; top: '+posY+'px;' 
     						+ 'padding: 4px;'
							+ 'background-color: #ffffff;'
							+ 'border: 2px Solid #999999;'
							+ 'width: '
							+ divWidth
							+ 'px;'
							+ 'font-size: 10px;';

	var html = '<div style="text-align: right;"><a href="javascript:void(0);" onClick="closePopupDiv();" style="font-size: 10px;">Close</a></div>'
				+ text ;

  document.body.appendChild(elmDiv);
  elmDiv.innerHTML = html;
}

// Hide the popup div
function closePopupDiv()	{
	var elmDiv = document.getElementById('popupDiv');
	if (elmDiv)	
		{
     elmDiv.parentNode.removeChild(elmDiv);
    }
}

// Get the width of the browser window
function getWindowWidth() {
	var myWidth = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) {
		  //Non-IE
		  myWidth = window.innerWidth;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		  //IE 6+ in 'standards compliant mode'
		  myWidth = document.documentElement.clientWidth;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		  //IE 4 compatible
		  myWidth = document.body.clientWidth;
		}
	
	return myWidth; 	
}

// Get the height of the browser window
function getWindowHeight() {
	var myHeight = 0;
	
	if( typeof( window.innerWidth ) == 'number' ) {
		  //Non-IE
		  myHeight = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		  //IE 6+ in 'standards compliant mode'
		  myHeight = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		  //IE 4 compatible
		  myHeight = document.body.clientHeight;
		}
	
	return myHeight; 	
}
function URLEncode(string)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = string;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};
//-->
