
/////////////////////////////////////////
//
//  function for search box in the header
//
function requestSearch(tbxID, BaseURL, strCulture) {
    var pathName = "/cps/rde/xchg/ballyfitness/xsl/hs.xsl/-/html/search.htm";
    var queryStart = ((strCulture == "es") ? "?rdeLocale=es&searchtext=" : "?rdeLocale=en&searchtext=");
    var selector = "#" + tbxID;
    var textboxes = $(selector);
    if (textboxes.length > 0) {
        var SearchText = textboxes[0].value;
        var FilteredSearch = SearchText.replace(/[^a-zA-Z 0-9]+/g, "");
        //window.location.replace(BaseURL + pathName + queryStart  + SearchText);
        window.open(BaseURL + pathName + queryStart + FilteredSearch, "_self");
    }
}

function getBaseURL() {
    if (window.location.port != "") {
        return window.location.protocol
      + "//" + window.location.hostname
      + ":" + window.location.port;
    }
    else {
        return window.location.protocol
      + "//" + window.location.hostname;
    }
}

$(window).load(function(){
    preloadImages();
///////////////////////////////////////////////////////////////////////////////
//     Altered to handle UpdatePanels
//    initRollovers();
//    initPrint();
//    initClearValue();
//    initToggle();
//    initHelp();
//    initTabbing();
//    initEmail();
});
        var postbackElement;
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);

        function beginRequest(sender, args) {
            postbackElement = args.get_postBackElement();
        }
        function pageLoaded(sender, args) {
            var updatedPanels = args.get_panelsUpdated();
            if (typeof(postbackElement) === "undefined") { //Full postback
                //preloadImages();
                initRollovers();
                initPrint();
                initClearValue();
                initToggle();
                initHelp();
                initTabbing();
                //initEmail();
                return;
            } 
            else {
                for (i=0; i < updatedPanels.length; i++) {            
                    //preloadImages();
                    initRollovers(updatedPanels[i].id);
                    initPrint(updatedPanels[i].id);
                    initClearValue(updatedPanels[i].id);
                    initToggle(updatedPanels[i].id);
                    initHelp(updatedPanels[i].id);
                    initTabbing(updatedPanels[i].id);
                    //initEmail(updatedPanels[i].id);
                }
            }

        }
///////////////////////////////////////////////////////////////////////////////




var browser = navigator.appName;
var versionInfo = navigator.appVersion;
var versionNum = parseFloat(versionInfo);
var vendor = navigator.vendor;
var IE = "Microsoft Internet Explorer";
var IE6 = "MSIE 6.0";
var IE7 = "MSIE 7.0";
var safari = "Apple Computer, Inc.";
var classAttribute = classAttr();   //Get the appropriate class attribute to set. IE and Firefox use different attributes for class in the DOM.
var imagePath = "Controls/Images/";


/* preload images function :
-------------------------------------------------------------------------*/
//This function is mostly because IE 6 isn't loading the background images of the help dynamic layers.
//var dynImg = ["bg-form-help.gif","bg-form-help-arrow.gif","bg-form-help-top.gif","bg-form-help-btm.gif","bg-large-help.gif","bg-large-help-arrow.gif","bg-large-help-top.gif","bg-large-help-btm.gif"];
var dynImg = ["bg-form-help.gif"    ,"bg-form-help-arrow.gif"
    ,"bg-form-help-top.gif"         ,"bg-form-help-btm.gif"
    ,"bg-large-help.gif"            ,"bg-large-help-arrow.gif"
    ,"bg-large-help-btm.gif"        ,"btn-close-help.gif"
    ,"bg-site-login-pane-top.gif"   ,"bg-site-login-pane-btm.gif"
    ,"bg-login-pane-input.gif"];

var preloadFlag = false;
function preloadImages() {
	for (i=0; i<dynImg.length; i++) {
		var images = new Array();
		images[i] = new Image();
		images[i].src = imagePath + dynImg[i];
	}
	preloadFlag = true;
}
/* preload images function ^
-------------------------------------------------------------------------*/




/* image rollover funtion :
-------------------------------------------------------------------------*/

/* Function to initalize rollover */
///////////////////////////////////////////////////////////////////////////////
//     Altered to handle UpdatePanels
//function initRollovers(){
//	var rollovers = getElementsByClass('rollover',null,null);	//Get elements with a class of "rollover"
function initRollovers(UpdatePanelID){	

	var selector = ".rollover";	
	if (UpdatePanelID != null)
	{
	  selector = "#" + UpdatePanelID + " " + selector;
    }
    var rollovers = $(selector);
///////////////////////////////////////////////////////////////////////////////

	if (rollovers.length > 0){		//If there is at least one element with a class "rollover"
		for(var i=0;i<rollovers.length;i++){	//Loop through all elements with class "rollover"
			var classValue = rollovers[i].getAttribute(classAttribute);
			
			if((versionInfo.match(IE6) != null) && (classValue.match('tpng') != null) ){ //If the browser is IE6 and a transparent png				
				addEvent(rollovers[i],'mouseover',rolloverPNG);	//Attach mouseover event
				addEvent(rollovers[i],'mouseout',rolloverPNG);	//Attach mouseout event	
			}
			else {
				addEvent(rollovers[i],'mouseover',rollover);	//Attach mouseover event
				addEvent(rollovers[i],'mouseout',rollover);	//Attach mouseout event
			}
		}		
	}
}

// This function grabs the src attribute and replaces "off" with "on" (for mouseover) or "on" with "off (for mouseout) in the attribute string. KM
function rollover(event) {
	var etype = event.type;
	var imgSrc = getObjectAttribute(this,"src");
	var newImgSrc;
	
	if (etype == 'mouseover'){
	    newImgSrc = imgSrc.replace('off.','on.','gi');
		this.setAttribute("src",newImgSrc);
	}
	
	else if (etype == 'mouseout') {
	    newImgSrc = imgSrc.replace('on.','off.','gi');
		this.setAttribute("src",newImgSrc);
	}
}

// IE 6 transparent PNG rollover function. KM
function rolloverPNG(event) {
	var etype = event.type;
	var imgSrc = getObjectAttribute(this,"name");
	var newImgSrc;
	
	if (etype == 'mouseover'){
	    newImgSrc = imgSrc.replace('off.','on.','gi');
		this.setAttribute('src',newImgSrc);
	}
	
	else if (etype == 'mouseout') {
	    newImgSrc = imgSrc.replace('on.','off.','gi');
		this.setAttribute('src',newImgSrc);
	}
}

// When function needs to be added inline (e.g. dynamically added content) KM
function rolloverInline(imgId,type) {
	var imgSrc = $("#" + imgId).attr("src");//jquery
	var newImgSrc;	

	if (type == 'over'){
	    newImgSrc = imgSrc.replace('off.','on.','gi');

	}
	else if (type == 'out') {
	    newImgSrc = imgSrc.replace('on.','off.','gi');
	}	
	$("#" + imgId).attr("src",newImgSrc);//jquery
}
/* image rollover function ^
-------------------------------------------------------------------------*/

/* pop up function :
-------------------------------------------------------------------------*/
function popWindow(href,title,sb,width,height) {
	window.open(href,title,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+ sb +',resizable=0,width='+ width +',height='+ height +',top=150,left=150');
}
/* pop up function ^
-------------------------------------------------------------------------*/

/* print functions :
-------------------------------------------------------------------------*/
///////////////////////////////////////////////////////////////////////////////
//     Altered to handle UpdatePanels
//function initPrint(){	
//	var printBtns = $(".print-button");
function initPrint(UpdatePanelID){	

	var selector = ".print-button";	
	if (UpdatePanelID != null)
	{
	  selector = "#" + UpdatePanelID + " " + selector;
    }
    var printBtns = $(selector);
///////////////////////////////////////////////////////////////////////////////
		
	printBtns.each(function(){         
        $(this).click(function(){
            window.print();
        });
    });
}
/* print functions ^
-------------------------------------------------------------------------*/


/* email functions :
-------------------------------------------------------------------------*/
//function initEmail(){	
//	var printBtns = $(".email-button");
//	var sendPage = "send-to-friend.htm";
	
//	printBtns.each(function(){         
//        $(this).click(function(){
//            popWindow(sendPage,"send_email","yes","300","300");
//        });
//    });
//}
/* email functions ^
-------------------------------------------------------------------------*/


/* toggle pane functions :
-------------------------------------------------------------------------*/
///////////////////////////////////////////////////////////////////////////////
//     Altered to handle UpdatePanels
//function initToggle(){
//    var tObj = $(".toggle-button");
function initToggle(UpdatePanelID){	

	var selector = ".toggle-button";	
	if (UpdatePanelID != null)
	{
	  selector = "#" + UpdatePanelID + " " + selector;
    }
    var tObj = $(selector);
///////////////////////////////////////////////////////////////////////////////
    
    tObj.each(function(){         
        $(this).click(function(){
            togglePane(this);
        });
    });
}

function togglePane(obj){
    var pane;
    
    if($(obj).parent().hasClass("toggle-pane")){
        pane = $(obj).parent();
    }
    else {
        pane = $(obj).parent().find(".toggle-pane");    
    }
    
    toggle(pane);
}
/* toggle pane functions ^
-------------------------------------------------------------------------*/

/* help window functions :
-------------------------------------------------------------------------*/
///////////////////////////////////////////////////////////////////////////////
//     Altered to handle UpdatePanels
//function initHelp(){
//    var tObj = $(".help-button");
function initHelp(UpdatePanelID){	

	var selector = ".help-button";	
	if (UpdatePanelID != null)
	{
	  selector = "#" + UpdatePanelID + " " + selector;
	}
    var tObj = $(selector);
///////////////////////////////////////////////////////////////////////////////
    
    tObj.each(function(){         
        $(this).click(function(){
            toggleHelp(this);
        });
    });
}

function toggleHelp(obj){   
    var pane;
    
    if($(obj).parent().hasClass("help-text")){
        pane = $(obj).parent();
    }
    else if($(obj).siblings().hasClass("help-text")){
        pane = $(obj).parent().find(".help-text");
    }
    else {
        pane = $(obj).parent().parent().find(".help-text");    
    }

    var paneVis;

    //checks to see if the pane is already visible
    if ($(pane).css("display") == "block") 
    {
        paneVis = true;
    }
    
    $("div").filter(".help-text").hide();

    //////////////////////////////////////
    // Moved to try to fix image issues in ie6
    
    //A visible pane should not be toggled back on
    if (!paneVis) {
        toggle(pane);
    }
    
    var left;
    var top;
    
    if($(pane).hasClass("pricing-details")){
        left = -265;
        top = 4;
    }
    else {
        left = 15;
        top = 7;
    }
    position(obj, pane, left, top);
    
    $(pane).find("div.top").remove();
    $(pane).find("div.bottom").remove();
    $(pane).find("div.arrow").remove();
    $(pane).find("div.help-button").remove(); 
    
    var helpTop = document.createElement("div");
    $(helpTop).addClass("top");
    
    var helpBottom = document.createElement("div");
    $(helpBottom).addClass("bottom");
    
    var helpArrow = document.createElement("div");
    $(helpArrow).addClass("arrow");
    
    var closeBtn = document.createElement("img");
    $(closeBtn).addClass("button help-button");
    $(closeBtn).attr("src","Controls/Images/btn-close-help.gif");
    $(closeBtn).attr("width", "6");
    $(closeBtn).attr("height", "6");
    $(closeBtn).attr("alt", "Close");
    $(closeBtn).click(function(){
        toggle(pane);
    });
    
    $(pane).prepend(helpTop);
    $(pane).append(helpBottom);
    $(pane).append(helpArrow);
    $(pane).append(closeBtn);
    
    //////////////////////////////////////
    // Moved to try to fix image issues in ie6
    //toggle(pane);
    
    //var left;
    //var top;
    
    //if($(pane).hasClass("pricing-details")){
    //    left = -265;
    //    top = 4;
    //}
    //else {
    //    left = 15;
    //    top = 7;
    //}
    //position(obj, pane, left, top);
}
/* help window functions ^
-------------------------------------------------------------------------*/

/* expand item functions :
-------------------------------------------------------------------------*/
///////////////////////////////////////////////////////////////////////////////
//     Altered to handle UpdatePanels
//function initExpand(){
//    var tObj = $(".expand-header");
function initExpand(UpdatePanelID){	

	var selector = ".expand-header";	
	if (UpdatePanelID != null)
	{
	  selector = "#" + UpdatePanelID + " " + selector;
    }
    var tObj = $(selector);
///////////////////////////////////////////////////////////////////////////////
    
    tObj.each(function(){         
        $(this).click(function(){
            expand(this);
        });
    });
}

function expand(obj){
    var parent = $(obj).parent();
    var pane = $(parent).find(".expand-item");  
    
    if($(parent).hasClass("open")){
        $(parent).removeClass("open");
    }
    else {
        $(parent).addClass("open");    
    }
    
    toggle(pane);
}
/* expand item functions ^
-------------------------------------------------------------------------*/

/* Begin tab change functions :
-------------------------------------------------------------------------*/
///////////////////////////////////////////////////////////////////////////////
//     Altered to handle UpdatePanels
//function initTabbing(){	
//	var tabs = getElementsByClass("tab",null,null);	//Get elements with a class of "tab"
function initTabbing(UpdatePanelID){	

	var selector = ".tab";	
	if (UpdatePanelID != null)
	{
	  selector = "#" + UpdatePanelID + " " + selector;
    }
    var tabs = $(selector);
///////////////////////////////////////////////////////////////////////////////
	
	if (tabs.length > 0){		//If there is at least one element with a class "tab"
		for(var i=0;i<tabs.length;i++){	//Loop through all elements with class "tab"
			addEvent(tabs[i],"click",tabClick);	//Attach click event
			addEvent(tabs[i],"mouseover",tabHover);	//Attach over event
			addEvent(tabs[i],"mouseout",tabHover);	//Attach out event
		}		
	}
}

function tabClick(event){    
    var tabs = getElementsByClass("tab",null,null);	//Get tabs
    var tabSections = getElementsByClass("tab-section",null,null);   //Get tab body sections
    	
	for(var t=0;t<tabs.length;t++){ //Loop through all tabs
	    var tabObj = tabs[t];
	    var tabSectionObj = tabSections[t];
	    	    
	    if(tabObj == this){ //Change clicked tab on
            tabObj.setAttribute(classAttribute, "tab selected");
            tabSectionObj.style.display = "block";
	    }
	    else {	//Change other tabs off	        
            tabObj.setAttribute(classAttribute, "tab");
            tabSectionObj.style.display = "none";		    
	    }
	}
}

function tabHover(event){ 
    var etype = event.type;
	
	if (this.getAttribute(classAttribute) != "tab selected"){
	    if (etype == "mouseover"){
		    this.setAttribute(classAttribute,"tab hover");
	    }
    	
	    else if (etype == "mouseout") {
		    this.setAttribute(classAttribute,"tab");
	    }
	}
}
/* Begin tab change functions ^
-------------------------------------------------------------------------*/

/* thumbnail swapping functions :
-------------------------------------------------------------------------*/
var mainImageEl = ".large-image > .primary-image";
var speed = 400;
var opacity = 0.50;

function initProjectPhotos(){
	var thumbImages = $(".thumb").length;
	
	if (thumbImages > 0){//If there is at least one element with a class "thumbnail"		
		$(".thumb:gt(0)").fadeTo(10, opacity).mouseover(function(event){
		  $(this).fadeTo(speed, 1);
		}).mouseout(function(event){
		  $(this).fadeTo(speed, opacity);
		});
		$(".thumb").click(changeProjects);
	}
}

function changeProjects() {
    var clickedImage = $(this).attr("src").split(moduleImgPath)[1];
    var mainImage = $(mainImageEl).attr("src").split(moduleImgPath)[1];
	
    for(var i=0;i<moduleArr.length;i++){ 
        var imageThumb = moduleArr[i].split("::")[0];
        var imageLarge = moduleArr[i].split("::")[1]; 
        var imageCaption = moduleArr[i].split("::")[2];   
          
        if(clickedImage == imageThumb){
            $(this).fadeTo(1000, 1).unbind("mouseout");
			$(mainImageEl).attr("src",moduleImgPath + imageLarge); 
			$(".image-caption:eq(0)").html(imageCaption);
        }
        else{
            $(".thumb:eq("+i+")").unbind("mouseover").unbind("mouseout").fadeTo(10, opacity).mouseover(function(event){
		      $(this).fadeTo(speed, 1);
		    }).mouseout(function(event){
		      $(this).fadeTo(speed, opacity);
		    });
        }
    }	
}
/* thumbnail swapping functions ^
-------------------------------------------------------------------------*/


/* helper functions :
-------------------------------------------------------------------------*/
function toggle(pane){
    if($(pane).css("display") == "block"){
		$(pane).css("display", "none");
	}
	else {
		$(pane).css("display", "block");
	}
}

function position(obj, pane, left, top){
    var xPos = $(obj).position().left + left;
    var yPos = $(obj).position().top - top; 
    
    $(pane).css("left", xPos + "px");
	$(pane).css("top", yPos + "px");
}

/* Extracted from Prototype JS Library, http://prototype.conio.net/
 Written by Sam Stephenson, http://conio.net/ */
function _gel() {
  var elements = new Array();
  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string') element = (document.getElementById) ? document.getElementById(element) : eval("document.all."+element) ;
    if (arguments.length == 1) return element;
    elements.push(element);
  }
  return elements;
}

/* Function to grab all elements with a specific class name.
 Original written by Jonathan Snook, http://www.snook.ca/jonathan
 Add-ons by Robert Nyman, http://www.robertnyman.com 	
 Re-written by Zack Gilbert of Seen Creative, http://www.weareseencreative.com */
function getElementsByClass(className, elm, tag){
	if(elm == null) elm = document;
	if(tag == null) tag = '*';
	var elems = elm.getElementsByTagName(tag);
	var returnElems = new Array();
	className = className.replace(/\-/g, "\\-");
	var pattern = new RegExp("(^|\\s)" + className + "(\\s|$)");
	for(var i=0; i<elems.length; i++){
		if(pattern.test(elems[i].className)) returnElems.push(elems[i]);
	}
	return returnElems
}

/* Function to return the class attribute. IE and all other standards compliant browsers have different names for the class attribute object. */
function classAttr(){
	var class_att = null;
	if (browser == IE ){
		class_att = 'className';
	}
	else {
		class_att = 'class';
	}
	
	return class_att;
	
}
/* Functions to add/remove event listeners to objects
	Written by John Resig, http://ejohn.org */
function addEvent( obj, type, fn ) {
	if (obj.addEventListener) obj.addEventListener( type, fn, false );
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function removeEvent( obj, type, fn ) {
	if (obj.removeEventListener) obj.removeEventListener( type, fn, false );
	else if (obj.detachEvent) {
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
}
/* Functions to handle cross-browser events.
 Written by Zack Gilbert of Seen Creative, http://www.weareseencreative.com. */
/* get the target of an event object */
function getTarget(e) {
	return (e.target) ? e.target : e.srcElement;
}

/* Function to get object attribute text */
function getObjectAttribute(obj,attr){
	var attrValue = obj.getAttribute(attr);	
	return attrValue;
}

/* Function to get img extension */
function getImgExt(obj){
	var src = obj.getAttribute('src');

	var imgExtPosition = src.lastIndexOf('.') + 1;	//Get the extension. Add 1 to get only the extension, not .extension

	var extension;

	if(src.match('clearpixel.gif')){	//If IE and the image is a PNG, return 'png', because the PNG transparency function causes the img src to be clearpixel.gif.
		extension = 'png';
	}

	else {
		var extension = src.slice(imgExtPosition);
	}

	return extension;
}

/***** Begin clear value functions *****/
// This function can be used to add a click and focus event to any input with a class of "clear-value".
// The function clears the value of the input and removes the click and focus event, so the value doesn't get cleared everytime a user clicks in the input.
function initClearValue(UpdatePanelID) {
    var selector = ".clear-value";
    if (UpdatePanelID != null) {
        selector = "#" + UpdatePanelID + " " + selector;
    }
    var input = $(selector);

    if (input.length > 0) {
        for (var i = 0; i < input.length; i++) {
            if ((UpdatePanelID != null) && (UpdatePanelID.indexOf("udpGuestPass") > 0)) {
                $(input[i]).removeClass("clear-value");
            }
            else {
                $(input[i]).focus(function() {
                    $(this).val("");
                    $(this).removeClass("clear-value");
                    $(this).unbind("focus");
                });
            }
        }
    }
}
/***** End clear value functions *****/
/* helper functions ^
-------------------------------------------------------------------------*/



