var topRelative;
var leftRelative; 

// stemless blue balloon
try
{
    var termBalloon  = new Balloon;
    termBalloon.balloonTextSize  = '90%';
    termBalloon.vOffset          = 0;
    termBalloon.stemHeight  = 2;
    termBalloon.shadow           = 0;
    termBalloon.stem             = false;
    termBalloon.ieImage          = null;
    termBalloon.delayTime = 1;
}
catch(err)
{
}

function ShowVideo(ExerciseLibraryId)
{
    var URL = "video_viewer.aspx?Id=" + ExerciseLibraryId;
    OpenInNewWindow(URL, 431, 690);
}

function ShowHeartRate()
{
    var URL = "heart_rate.aspx";
    OpenInNewWindow(URL, 497, 690);
}

function NavToCalendar(item)
{
    var SelectedValue = item.options[item.selectedIndex].value;
    
    if(SelectedValue != "self")
        location.href = SelectedValue + "_calendar.aspx";
    else
        location.href = SelectedValue + "_events.aspx";
}

function ShowRequestSpot(id)
{
    var TopOfBaselineDiv = findPos(document.getElementById("BaselineForHeight"));
    document.getElementById("RequestSpot").style.top = (topRelative + topPageSpecific) + "px";
    document.getElementById("RequestSpot").style.left = (leftRelative + 300) + "px";    
    document.getElementById("RequestSpot").className="dayLayer";
    
    var SelectedClassId = document.getElementById("SelectedClassId")
    SelectedClassId.value = id;
}

function HideRequestSpot()
{
    document.getElementById("RequestSpot").className="hidden"
    return false;
}

function ShowDayEvents(day)
{
    var TopOfBaselineDiv = findPos(document.getElementById("BaselineForHeight"));
    document.getElementById("day" + day).style.top = (topRelative + topPageSpecific) + "px";
    document.getElementById("day" + day).style.left = (leftRelative + 300) + "px";    
    document.getElementById("day" + day).className="dayLayer";
}

function HideAnyOpenDayEvents()
{
    for(i = 1; i < 31; i++)
        document.getElementById("day" + i).className="hidden";
}

function HideDayEvents(day)
{
    document.getElementById("day" + day).className="hidden";
}

function findPos(obj) 
{
  
    var curleft = curtop = 0;
    if (obj.offsetParent)
    { 
        curleft = obj.offsetLeft
        curtop = obj.offsetTop

        while (obj = obj.offsetParent)
        { 
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    //alert(topRelative);
    topRelative = curleft;
    leftRelative = curleft
    
    //if(navigator.appName == "Microsoft Internet Explorer")
    //    topRelative = topRelative + 357
}

function MM_swapImgRestore()
{
    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() 
{
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) 
{
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() 
{
    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/// ----------------------------------------------------------------------------------
///		<summary>TrimString</summary>
///		<remarks>
///			Used to trim leading and trailing blank spaces from the string passed in to it.
///		</remarks>
///		<parameter type="string" name="TextToTrim">
///			String to remove leading and trailing spaces from
///		</parameter>
///		<returns type="string">Trimmed string</returns>
/// ----------------------------------------------------------------------------------
function TrimString(TextToTrim)
{
   
   var TrimmedString = "";
   var count = 0;
   var newArray = TextToTrim.split(" ")
   for (i = 0; i < newArray.length; i++)
   {
      if(newArray[i] != "")
      {
         if (count == 0)
            TrimmedString = newArray[i];
         else
            TrimmedString = TrimmedString + " " + newArray[i];
         count++;
      }
   }
   return TrimmedString;

}


/// ----------------------------------------------------------------------------------
///		<summary>IsNumeric</summary>
///		<remarks>
///			Used to determine if the string passed in contains only Numbers or not.
///		</remarks>
///		<parameter type="string" name="TextToTest">
///			String to check for all numeric characters
///		</parameter>
///		<returns type="bool">True if is all numeric else False</returns>
/// ----------------------------------------------------------------------------------
function IsNumeric(TextToTest)
{
	
	var ValidChars = "0123456789.";
	var IsNumber = true;
	var Char;

	for(i = 0; i < TextToTest.length && IsNumber == true; i++) 
	{ 
		Char = TextToTest.charAt(i); 
		if(ValidChars.indexOf(Char) == -1) 
			IsNumber = false;
	}
	return IsNumber;
	
}


/// ----------------------------------------------------------------------------------
///		<summary>OpenInNewWindow</summary>
///		<remarks>
///			Called to Open a new Centered Window based on the Height and Width specified
///			in the parameter list.
///		</remarks>
/// ----------------------------------------------------------------------------------
function OpenInNewWindow(Path, Height, Width)
{
	
	LeftPosition = (screen.width) ? (screen.width-Width) / 2 : 0;
	TopPosition = (screen.height) ? (screen.height-Height) / 2 : 0;

	TopPosition = TopPosition - 50;

	// Open the page identified in the parameter list with window settings assigned 
	TheOpenWindow = window.open(Path,'new','height='+Height+',width='+Width+',top='+TopPosition+',left='+LeftPosition+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=no');

	try
	{
		TheOpenWindow.focus();
	}
	catch(iError){}

}

/// ----------------------------------------------------------------------------------
///		<summary>ReturnToPreviousScreen</summary>
///		<remarks>
///		</remarks>
/// ----------------------------------------------------------------------------------
function ReturnToPreviousScreen()
{
	
	history.back();

}

/// ----------------------------------------------------------------------------------
///		<summary>LogoutUser</summary>
///		<remarks>
///			Called from the "Logout User" Link on top of all pages.
///		</remarks>
/// ----------------------------------------------------------------------------------
function LogoutUser()
{
	__doPostBack('Header:LogoutUser', '');

}



