// add trim function to String objects
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
};


var timeoutAjaxId=null;
var aliveCount = 0;



function setUpTimeAjaxTimeOut (req)
{
  if (timeoutAjaxId !== null)
  {
    clearTimeout(timeoutAjaxId);
  }
  
  if (req !== null && req.responseText.trim() !== '')
  {
    var msg = '<div style="margin:20;">';
    msg += req.responseText;
    msg += spButton('continue', 'spWindowClose();', 'restartWarning', 'left');
    msg += '<br /></div>';
    hideFlash();
    spWindowOpen(msg, 350);
  }
  
  timeoutAjaxId = setTimeout("handleTimeAjaxOut()", 300000);
}

function handleTimeAjaxOut ()
{
  var params = 'dec=none&alive=' + (aliveCount++);
  spAjaxRequest(setUpTimeAjaxTimeOut, '/drills/KeepAlive.do;jsessionid=' + jSession, params, '');
}
      
setTimeout("setUpTimeAjaxTimeOut(null)", 1000);

// JavaScript Document



// check if this is the first time the current user has used the selected tool
function checkFirstUse (type, sportCodeId)
{
  if (type !== null)
  {
    if (sportCodeId === null)
    {
      sportCodeId = -1;
    }
    
    var params = 'type=' + type;
    params += '&scId=' + sportCodeId;
    
    spAjaxRequest(checkFirstUseResponse, '/drills/CheckFirstUse.do', params, '');
  }
}


// process the response from checking first use of a website tool
function checkFirstUseResponse (req)
{
  var wasFirstUse = false;
  if (req.responseText !== null)
  {
    wasFirstUse = (req.responseText.indexOf('true') >= 0);
  }
  
  /* don't actually need to do anything after the ajax call
  if (wasFirstUse)
  {
    alert('WAS the user\'s first use');
  }
  else
  {
    alert('was NOT the user\'s first use');
  }*/
}





// homePage expand samples
function expandSamples()
  {
    var box= document.getElementById('samples');
    if(box) {
      box.style.height='470px';
    }
  }

// Logging
function spLog(spText)
  {
    var box = document.getElementById('spLogWindow');
    if(box) box.innerHTML+='<div class="spLogEntry">'+spText+'</div>';
  }
  
function spSetUpLog()
  {
    var objOverlay = document.getElementById('spLogWindow');
  if(objOverlay){
    objOverlay.style.display = 'block';    
    }
  else {
    var objBody = document.getElementsByTagName("body").item(0);
    var objOverlay = document.createElement("div");
    objOverlay.setAttribute('id','spLogWindow');
    if(objBody) objBody.insertBefore(objOverlay, objBody.firstChild);
    }
  }


function findSignUp(signup)
  {
    var box=document.getElementById('signUp');
    if(box){
      toggleDivs('signUp','movie');toggleDivs('','signIn');
    }
    else {
      document.location.href="http://www.sportplan.net/drills/signin.jsp?signUp="+signup;
    }
  }


function spLink(href,titleText)
  {
  this.href=href;
  this.titleText=titleText;
  }



var doneCheckForLinks=false;
function checkForLinks()
{
  var jsonFileNameDiv = document.getElementById('jsonFileName');
  
   if(! doneCheckForLinks){
  if (jsonFileNameDiv !== null)
  {
    spAjaxRequest(checkForLinksResponse, jsonFileNameDiv.innerHTML, '', '');
  }
  else
  {
    var practiceJsonDiv = document.getElementById('pracIndexJSON');
    if (practiceJsonDiv !== null)
    {
    
      checkForLinksResponse(null);
    } 
  }
  doneCheckForLinks=true;
  }
}


function checkForLinksResponse (req)
{
  var box = document.getElementById('pracHolderMain');
  if (box)
  {
    box.style.height=parseInt(box.offsetHeight)+'px';
  }

      
  var doLinks = true;
  var box = document.getElementById('theH1');
  if (box)
  {
    if (box.innerHTML.indexOf('Folder') > 0)
    {
      doLinks = false;
    }
  }
  
  //alert(doLinks);
  if (doLinks)
  {
    if (document.location.href.indexOf('category') < 0)
    {
      // check not category index page
      pracResult = '';
   
      var pLinksJSON = null;
      if (req !== null)
      {
        pLinksJSON = req.responseText;
      }
      else
      {
        var pLinksJSONDiv = document.getElementById('pracIndexJSON');
        if (pLinksJSONDiv !== null)
        {
          pLinksJSON = pLinksJSONDiv.innerHTML;
        }
      }
      
      
      
      if (pLinksJSON && pLinksJSON.length > 5)
      {
        
		buildPractLinksJSON(pLinksJSON);
        if (host.indexOf('sportplan1') < 0)
        {
          var box = document.getElementById('debugBox');
          if (box)
          {
            box.style.display = 'none';
          }
        }
      }
      else 
      {
        //alert("here");
        var pLinks = document.getElementById('linksList');
        if (pLinks)
        {
          buildPractLinks('linksList');
        }
      }
      var box = document.getElementById('notLoggedHeader');
      if (box)
      {
        slidedown('notLoggedHeader');
      }
      box = document.getElementById('fairUsageNotice');
      if (box)
      {
    		box.style.display='none';
    		box = document.getElementById('fairUsageNoticeMini');
				if(box)
        {
        	box.style.display = 'block';
        }
		  }
      
      var box = document.getElementById('sportInterestQ');
      if (box)
      {
        box.style.display = 'block';
      }
    }
  }
  
  checkSearchBut();
  
  var spBox = document.getElementById('tp');
  if (spBox)
  {
  	var sizeArray = getPageSize();
  	spBox.style.width = (sizeArray[0] - 10) + 'px';
  	spBox.style.height = "17px";
  	spBox.style.overflow = 'hidden';
	}
	

}

var moreLinks=1;

function checkSearchBut()
	{

	var sizeArray = getPageSize();
  if (sizeArray[2] < 1000)
  {
  	var spBox = document.getElementById('searchBut');
  	if (spBox)
    {
      spBox.style.display = "none";
    }
	}
	//if(lastEmail=='john@sportplan.net') alert(sizeArray[2]);
	if ((lastSportName=='Hockey'||lastSportName=='Field Hockey')&& sizeArray[2] < 1030)
  {
  	var spBox = document.getElementById('searchBut');
  	if (spBox)
    {
      spBox.style.display = "none";
    }
	}
	
		var spBox1 = document.getElementById('sportChoice');
  	if(spBox1) {
			var spBox = document.getElementById('searchBut');
  		if (spBox)
    	{
      	spBox.style.display = "none";
    	}
    }
		
	}



function buildPractLinksJSON(pracJson)
{
  //alert(pracDiv.innerHTML);removeXML(removeQUOT())removeXML()
  var result = '';
  var doneAd = false;
  var adPosition = Math.floor(Math.random() * 6);
//alert("test");
  // if it is too big remove XML doesn't work 
  var jsonString = findStart(pracJson);
  jsonString = jsonString.replace(/</g," ");
  jsonString = jsonString.replace(/>/g," ");

  //if(lastEmail=='bram@sportplan.com') alert(jsonString.substring(14500));
  var practice = eval("("+jsonString+")");
  var practice = practice.practices;

  // choosing random practice on opening a category
  var pLinks = document.getElementById('catOptions');
  if (!pLinks)
  {
    var findBox = document.getElementById('thisIsSportHome');
    if (!findBox)
    {
      document.location.href = host + '/' + practice[Math.floor(Math.random() * practice.length)].linkHref + '?' + linkApp;
      return false;
    }
  }
  
  var showPractices = 6;
  var foundOutLine = document.getElementById('outlineGoogle');
  if(isMember)
  {
    showPractices = 200;
  }
  
  for(var j = 0; j < showPractices && j < practice.length; j++)
  {
    if (foundOutLine && !doneAd && adPosition == j)
    {
      result += '<div class="pracListHolder" id="inlineGoogle" ></div>';
      doneAd = true;
    }
    
    if (!isMember)
    {
      var r=parseInt(Math.floor(Math.random() * practice.length));
    }
    else
    {
      var r = j;
    }
    
	var spBox=document.getElementById('pLH'+practice[r].oldPracticeCode);
	
	if (spBox === null) {
	
		result += '<div class="pracListHolder false_cursor" ';
		if (!isMember || (top.location != self.location)) {
			if (document.location.href.indexOf('planner') > 0 || document.location.href.indexOf('EditSession') > 0) {
				if (!SportCategories.sports[selectedLibrary[0]].libraries[selectedLibrary[1]].member) {
					result += 'onclick="loadRandom();">';
				}
				else 
					result += 'onclick="loadPractice(\'' + practice[r].linkHref + '\',\'line 627\');">';
			}
			
			else {
				try {
					result += 'onclick="document.location.href=\'' + host + '/' + practice[r].linkHref + '?' + linkApp + '\';">';
				} 
				catch (err) {
					result += 'onclick="document.location.href=\'' + host + '/' + practice[r].linkHref + ';">';
					
				}
			}
			
		}
		else {
			result += 'onclick="loadPractice(\'' + practice[r].linkHref + '\',\'line 633\');">';
		}
		
		result += '<div class="pracListHolderSQ" id="pLH' + practice[r].oldPracticeCode + '">';
		result += '<div style="width:100px;height:66px;background-color:' + practice[r].pracBGColor + ';" bgcolor="' + practice[r].pracBGColor + '">';
		if (isMember || lastEmail == '') {
			if (practice[r].fileType == '9') {
				result += '<img src="http://www.sportplan.net/' + practice[r].pracSportDir + '/' + practice[r].fileName + '.jpg" height="66" width="100" />';
			}
			else 
				if (practice[r].fileType == '10') {
					result += '<img src="http://www.sportplan.net/' + practice[r].pracSportDir + '/' + practice[r].fileName + '.gif" height="66" width="100" />';
				}
				else {
					if (lastSportName == 'Rounders' ||lastSportName == 'Golf' || lastSportName == 'Volleyball' || lastSportName == 'Workout' || lastSportName == 'Agility' || lastSportName == 'Athletics' || lastSportName == 'Handball' || lastSportName == 'Basketball' || lastSportName == 'Cricket' || lastSportName == 'Tennis' || lastSportName == 'Gymnastics' || lastSportName == 'Netball' || lastSportName == 'Rugby' || lastSportName == 'Hockey' || lastSportName == 'Field Hockey' || lastSportName == 'Football' || lastSportName == 'Soccer') {
						result += '<img src="http://www.sportplan.net/' + practice[r].pracSportDir + '/thumbs/100/' + practice[r].fileName;
						if (practice[r].fileType == 'VMP4' || practice[r].fileType == 'ANIM' || practice[r].fileType == 'CHLK' || practice[r].fileType == 'CUST' || practice[r].fileType == 'ADUP') {
							result += '.png" height="66" width="100">';
						}
						else {
							result += '.gif" height="66" width="100">';
						}
					}
					else {
						result += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" align="right"';
						result += 'height="66" width="100">';
						result += '<param name="movie" value="http://www.sportplan.net/' + practice[r].pracSportDir + '/' + practice[r].fileName + '.swf">';
						result += '<param name="quality" value="low">';
						result += '<param name="play" value="true">';
						//result += '<param name="wmode" value="transparent">';
						result += '<param name="bgcolor" value="' + practice[r].pracBGColor + '">';
						result += '<embed src="http://www.sportplan.net/' + practice[r].pracSportDir + '/' + practice[r].fileName + '.swf"';
						result += 'quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"';
						result += 'height="66" width="100" bgcolor="' + practice[r].pracBGColor + '" play="true" ></object>'; //wmode="transparent"
					}
				}
		}
		else {
			if (practice[r].fileType == '9') {
				result += '<img src="http://www.sportplan.net/' + practice[r].pracSportDir + '/' + practice[r].fileName + '.jpg" height="36" width="54" />';
			}
			else {
				if (lastSportName == 'Golf' || lastSportName == 'Rounders' || lastSportName == 'Volleyball' || lastSportName == 'Workout' || lastSportName == 'Agility' || lastSportName == 'Athletics' || lastSportName == 'Basketball' || lastSportName == 'Cricket' || lastSportName == 'Handball' || lastSportName == 'Tennis' || lastSportName == 'Gymnastics' || lastSportName == 'Netball' || lastSportName == 'Rugby' || lastSportName == 'Hockey' || lastSportName == 'Field Hockey' || lastSportName == 'Football' || lastSportName == 'Soccer') {
					result += '<img src="http://www.sportplan.net/' + practice[r].pracSportDir + '/thumbs/54/' + practice[r].fileName;
					if (practice[r].fileType == 'VMP4' || practice[r].fileType == 'ANIM' || practice[r].fileType == 'CHLK' || practice[r].fileType == 'CUST' || practice[r].fileType == 'ADUP') {
						result += '.png" >';
					}
					else {
						result += '.gif" >';
					}
				}
				else {
					result += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" align="right"';
					result += 'height="36" width="54">';
					result += '<param name="movie" value="http://www.sportplan.net/' + practice[r].pracSportDir + '/' + practice[r].fileName + '.swf">';
					result += '<param name="quality" value="low">';
					result += '<param name="play" value="false">';
					//result += '<param name="wmode" value="transparent">';
					result += '<param name="bgcolor" value="' + practice[r].pracBGColor + '">';
					result += '<embed src="http://www.sportplan.net/' + practice[r].pracSportDir + '/' + practice[r].fileName + '.swf"';
					result += 'quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"';
					result += 'height="36" width="54" bgcolor="' + practice[r].pracBGColor + '" play="false" ></object>'; //wmode="transparent"
				}
			}
		}
		
		result += '</div></div>';
		
		result += '<div class="pracTextMenu"><Strong>' + practice[r].pracTitle.substring(0, 26) + '</strong><br/>';
		//practice[r].pracDescription=removeXML(practice[r].pracDescription);
		result += practice[r].pracDescription.substring(0, 50);
		
		if (adminAccess) {
			result += '<a href="' + host + '/adminapp/EditPractice.do?oldPracticeCode=' + practice[r].oldPracticeCode + '" target="_blank">Edit </a>';
		}
		result += '</div></div>';
		// write sample practice if category home page 
		if (!isMember && j == 0) {
			var myBox = document.getElementById('catSample');
			if (myBox) {
				myBox.innerHTML = result + '<center><span style="font-size:10px;">CLICK ON DRILL TO VIEW</span></center>';
				result = '';
			}
		}
		else 
			if (isMember) {
				var myBox = document.getElementById('getRandom');
				//alert("getRandom");
				if (myBox) {
					if (myBox.innerHTML == 'random') {
						var r = Math.floor(Math.random() * practice.length);
						//alert(r);
						loadPractice(practice[r].linkHref, 'line 741');
						myBox.innerHTML = '';
					}
				}
			}
	}
    
   /// end of new sample practice
  }
    
  /*
  if(isMember&&practice.length>9) 
  {
    result+='<div style="height:20px;"><a href="javascript:checkForLinks();" class="moreDrillsBut">&nbsp; &nbsp; more Drills >>>&nbsp; &nbsp; </a></div>';
  } */
  if (!isMember && practice.length > showPractices)
  {
    result += '<div class="pracListHolder">Practices in this folder have been limited as you do not have full membership please ';
	if(lastEmail!='') result += '<a href="/drills/SetupTUD.do?forward=subscribe&sportName='+lastSportName+'" onClick="_gaq.push([\'_trackEvent\', \'Upgrade\', \'MorePractices\', \''+lastSportName+'\']);" >subscribe</a> for full access!</div>';
  	else result += 'subscribe for full access!</div>';
  }
  
  var pLinks = document.getElementById('catOptions');
  if(iPad) pLinks.style.height = practice.length * 80 + 'px' ;
  if (pLinks)
  {
  	var jsonFileNameDiv = document.getElementById('jsonFileName1');
		 if (jsonFileNameDiv !== null) {
		 	if(moreLinks>1) pLinks.innerHTML += result;
			else pLinks.innerHTML += result;
			var jsonFileNameDiv = document.getElementById('jsonFileName'+moreLinks++);
			if (jsonFileNameDiv !== null) {
		 		spAjaxRequest(checkForLinksResponse, jsonFileNameDiv.innerHTML, '', '');
				return;
		 	}
		 }
		 else pLinks.innerHTML = result;
    var pLinks = document.getElementById('linksList');
    if(pLinks)
    {
      pLinks.style.display='none';
    }
      
    var pLinks = document.getElementById('pLinks');
    if(pLinks)
    {
      pLinks.style.display='none';
    }
    
    var pLinks = document.getElementById('emailTop');
    if(pLinks)
    {
      pLinks.style.display='none';
    }
  }
  
  if (!pLinks)
  {
    var pLinks = document.getElementById('linksList');
    if(pLinks) {
		pLinks.innerHTML = result;
    pLinks.style.height = '460px'
    pLinks.style.height = pLinks.offsetHeight + 'px';}
  }
  
  // push inline google advert
  var spBox1 = document.getElementById('inlineGoogle');
  var spBox2 = document.getElementById('outlineGoogle');
  if(spBox1 && spBox2)
  {
    spBox1.innerHTML = spBox2.innerHTML;
  }
}

var thePLinks = new Array();

function buildPractLinks(linkDiv)
  {
var pLinks=document.getElementById(linkDiv);
if(pLinks) {
var theString=pLinks.innerHTML;
var theLinks = new Array();

while(theString.indexOf('href="')>0)
  { 
      theString=theString.substring((theString.indexOf('href="')+6),theString.length);
    // link 
    var theHref = theString.substring(0,theString.indexOf('"'));
    theHref=removeSpaces (theHref);
    theString=theString.substring((theString.indexOf('>')+1),theString.length);
    // link Text
    var theTitleText=theString.substring(0,theString.indexOf('<'));
    var thisLink= new spLink(theHref,theTitleText);
    theLinks[theLinks.length] = thisLink;
  }

// add randomizizer here  
// only if not Sportplan 1
if(host.indexOf('sportplan1')>-1){
  for(var j=0;j<theLinks.length;j++)
    {
            thePLinks[j]=theLinks[j];      
    }
}
else {
  for(var j=0;j<theLinks.length;j++)
    {
      thePLinks[j]=theLinks[Math.floor(Math.random() * theLinks.length)];
    }
}
var htmlString=pLinks.innerHTML;
if(htmlString.indexOf('</H3>')>-1) pLinks.innerHTML=htmlString.substring(0,(htmlString.indexOf('</H3>')+5))+'<div id="pract0"></div><!-- next -->'+htmlString.substring((htmlString.indexOf('</H3>')+5),htmlString.length);
else if(htmlString.indexOf('</h3>')>-1) pLinks.innerHTML=htmlString.substring(0,(htmlString.indexOf('</h3>')+5))+'<div id="pract0"></div><!-- next -->'+htmlString.substring((htmlString.indexOf('</h3>')+5),htmlString.length);
else pLinks.innerHTML='<div id="pract0"></div><!-- next -->'+htmlString.innerHTML; 


spAjaxRequestWithId(processPractLink,
          host+thePLinks[0].href,
          'dec=dirDrill',
          0,
          'pract0');
}
}

function removeNL(s) {
  /*
  ** Remove NewLine, CarriageReturn and Tab characters from a String
  **   s  string to be processed
  ** returns new string
  */
  r = "";
  for (i=0; i < s.length; i++)
  {
    if (s.charAt(i) != '\n' &&
        s.charAt(i) != '\r' &&
        s.charAt(i) != '\t' &&
        s.charAt(i) != '&')
    {
      r += s.charAt(i);
    }
    else if (s.charAt(i) == '\n')
    {
      r += '<br />';
    }
    else if (s.charAt(i) == '&')
    {
      r += ' amp; ';
    }
  }

  return r;
}

function removeXML(theString)
  {
    
    while(theString.indexOf('&lt;')>-1)
      {  
          if(theString.indexOf('&gt;')>-1) theString=theString.substring(0,theString.indexOf('&lt;'))+' '+theString.substring((theString.indexOf('&gt;')+4),theString.length);
      		else theString=theString.substring(0,theString.indexOf('&lt;'))+' '+theString.substring((theString.indexOf('&lt;')+4),theString.length); 
      }
    while(theString.indexOf('<b>')>-1)
      {  
          theString=theString.substring(0,theString.indexOf('<b>'))+' '+theString.substring((theString.indexOf('<b>')+3),theString.length);
      }
    while(theString.indexOf('<\b>')>-1)
      {  
          theString=theString.substring(0,theString.indexOf('<b>'))+theString.substring((theString.indexOf('<\b>')+4),theString.length);
      }
    while(theString.indexOf('\n')>-1)
      {  
          theString=theString.substring(0,theString.indexOf('\n'))+' '+theString.substring((theString.indexOf('\n')+1),theString.length);
      }
    while(theString.indexOf('\r\n')>-1)
      {  
          theString=theString.substring(0,theString.indexOf('\r\n'))+' '+theString.substring((theString.indexOf('\r\n')+1),theString.length);
      }
    while(theString.indexOf('&amp;#39;')>-1)
      {  
          theString=theString.substring(0,theString.indexOf('&amp;#39;'))+'\''+theString.substring((theString.indexOf('&amp;#39;')+9),theString.length);
      }
    return theString;
  }
  
// not finished 
function removeQUOT(theString)
  {
    var theSplit = theString.split("&qu");
    theString='';
    for(i=0;i<theSplit.length;i++){
      theString+=theSplit[i];
    }
    var theSplit = theString.split("ot;");
    theString='';
    for(i=0;i<theSplit.length;i++){
      theString+=theSplit[i];
    }
    
    return theString;
  }
  
var pracResult;
function processPractLink(req,id)
  {
    
    var pracNum=parseInt(id);
    
    
      var practice = eval("("+req.responseText+")");
      
          pracDebug(practice,pracNum); 
          
      var result='<div class="pracListHolder false_cursor" onclick="document.location.href=\''+host+thePLinks[pracNum].href+'?'+linkApp+'\';"><div class="sbl"><div class="sbr"><div class="stl"><div class="str" >';
      result+='<center><div style="width:54px;height:36px;margin-right:5px;border:1px solid #cccccc;margin-bottom:5px;background-color:'+practice.pracBGColor+';" bgcolor="'+practice.pracBGColor+'">';
      result+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" align="right"';
      result+='height="36" width="54">';
      result+='<param name="movie" value="http://www.sportplan.net/viewer/movies/'+practice.pracSportDir+'/'+practice.fileName+'.swf">';
      result+='<param name="quality" value="low">';
      result+='<param name="play" value="false">';
      //result+='<param name="wmode" value="transparent">';
      result+='<param name="bgcolor" value="'+practice.pracBGColor+'">';
      result+='<embed src="http://www.sportplan.net/viewer/movies/'+practice.pracSportDir+'/'+practice.fileName+'.swf"';
      result+='quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"';
      result+='height="36" width="54" bgcolor="'+practice.pracBGColor+'" play="false" ></object>';  //wmode="transparent"
      result+='</div>';
      result+='<div id="pracText"><Strong>'+practice.pracTitle.substring(0,26)+'</strong><br/>';
      practice.pracDescription=removeXML(practice.pracDescription);
      result+=practice.pracDescription.substring(0,80);
      if(adminAccess) result+='<a href="'+host+'/adminapp/EditPractice.do?oldPracticeCode='+practice.oldPracticeCode+'" target="_blank">Edit </a>';
      result += '</div></center></div></div></div></div></div>';    
      pracResult+= result;
    
    //var pLinks=document.getElementById('linksList');
    //if(!pLinks) var pLinks=document.getElementById('pLinks');
    //if(pLinks) pLinks.innerHTML=pLinks.innerHTML.substring(0,pLinks.innerHTML.indexOf('<!-- next -->'))+'<div id="pract'+(pracNum+1)+'"></div><!-- next -->'+pLinks.innerHTML.substring((pLinks.innerHTML.indexOf('<!-- next -->')+13),pLinks.innerHTML.length);
    
    
    
    if((pracNum<8&&pracNum+1<thePLinks.length-1)||(host.indexOf('sportplan1')>-1&&pracNum+1<thePLinks.length-1)){
      setTimeout("spAjaxRequestWithId(processPractLink,"+
          "'"+host+thePLinks[pracNum+1].href+"',"+
          "'dec=dirDrill',"+
          (pracNum+1)+","+
          "'pract"+(pracNum+1)+"')",1); //2500
    }
    else {
      var pLinks=document.getElementById('linksList');
      if(!pLinks) var pLinks=document.getElementById('pLinks');
      pLinks.innerHTML=pracResult;
      pLinks.style.height='460px';
      pLinks.style.height=pLinks.offsetHeight+'px';
    }
    
  }




 function checkFields (theForm)
  {
    var message = '';
    theForm.reference.value=removeSpaces(theForm.reference.value);
      if(theForm.sendername.value=='')
    {
      message += "\nYour Name";
    }
    
    
    if(theForm.sender.value=='')
    {
      message += "\nYour Address";
    }
    else if(theForm.sender.value.indexOf("@") == -1)
    {
      message += "\nCorrect address for Your Address";
    }
    
    if(theForm.friendsname.value=='')
    {
      message += "\nFriend's Name";
    }
    
    if(theForm.receiver.value=='')
    {
      message += "\nReceiver Address";
    }
    else if(theForm.receiver.value.indexOf("@") == -1)
    {
      message += "\nCorrect address for Receiver's Address";
    }
    
    if(theForm.subject.value=='')
    {
      message += "\nA Subject";
    }
   
    if(message!='')
    {
      message = "There are some errors with the email form missing the following:" + message;
      //alert(message);
      return false;
    }
    
    return true;
  } 
 
function removeAmpersands (note)
{
  if (note != null)
  {
    var i = note.indexOf("&");
    while(i >= 0)
    {
      note = note.substring(0,i) + "%26" + note.substring(i+1,note.length);
      i = note.indexOf("&");
    }
  }
  return note;
}

function removeAmp (note)
{
  if (note != null)
  {
    var i = note.indexOf("&amp;");
    while(i >= 0)
    {
      note = note.substring(0,i) + "&" + note.substring(i+5,note.length);
      i = note.indexOf("&amp;");
    }
  }
  return note;
}



function collectVariables(thisForm)
  {
    var theString='';
     var element;
    for(var i = 0; i < thisForm.elements.length; i++)
        {
        element = thisForm.elements[i];
        if(element != null)
          {
            if(element.type == 'radio')
            {
              if(element.checked)
                {
                  theString += element.name + '=' + removeAmpersands(element.value) + '&';
                }
            }
            else
            {
              theString += element.name + '=' + removeAmpersands(element.value) + '&';
            }
        }
      }
    //theString = theString.split("?").join("");
         theString = theString.split("'").join("");
     return theString;
  }

function sendEmail(passedForm)
  {
    var theForm=passedForm;
    
    if (theForm == null)
    {
      theForm = document.emailForm;
    }
    
    if(checkFields(theForm)){
    var theParams=collectVariables(theForm);
    if(pageTracker) pageTracker._trackPageview('/sendingEmail/'+theForm.receiver.value);
    toggleDivs('sending','emailFormHolder');
    if(top.location != self.location){
        var  newwindow=window.open(host+'/drills/email.do;jsessionid='+jSession+'?'+theParams,'email','height=400,width=200');
    if (window.focus) {newwindow.focus()}      
    }
    else {
    setTimeout("spAjaxRequestWithId(emailSent,'/drills/email.do','"+theParams+"',0,'sending')",500);
    }
    }
  }

function emailSent()
  {
    var box = document.getElementById('sending');
     if (box) box.innerHTML = '<center>' + langres_spLib_emailSent + '</center>';
    setTimeout("resetEmailForm()",2000);
    doAfterEmail();
  }

function resetEmailForm()
  {
    var box = document.getElementById('sending');
    if (box) box.innerHTML = '<center>' + langres_spLib_sending + '</center>';
    toggleDivs('','emailForm');
    toggleDivs('emailFormHolder','sending');
  }

function addbookmark(bookmarkurl,bookmarktitle){
  bookmarkurl=location;
    if (document.all){  window.external.AddFavorite(bookmarkurl,bookmarktitle); }

}

function stopProp(ev)
{
if (!ev) var ev = window.event;
   ev.cancelBubble = true;
      if (ev.cancelBubble) ;
      else ev.stopPropagation();
}






  
function pracDebug(prac,pracNum)
  {
    var spResult='';
    
    if(host.indexOf('sportplan1')>-1){
      spResult+='{"linkHref":"'+thePLinks[pracNum].href+'"';
      spResult+=',"fileType":"'+prac.fileType+'"';
      spResult+=',"pracBGColor":"'+prac.pracBGColor+'"';
      spResult+=',"pracSportDir":"viewer/movies/'+prac.pracSportDir+'"';
      spResult+=',"fileName":"'+prac.fileName+'"';
      spResult+=',"pracTitle":"'+prac.pracTitle.substring(0,26)+'"';
      spResult+=',"pracDescription":"'+removeXML(prac.pracDescription).substring(0,80)+'"},';
      //alert(spResult);
      
      var spBox = document.getElementById("debugBox");
      if(spBox){debugBox.innerHTML+=spResult;
      debugBox.style.display="block";}
    }
  }
  


function enlargeHome(sport)
  {
    if(top.location != self.location){
        alert("Not Available ");    
    }
    else {
    var spHTML='';
    spHTML+='<div id="enLargeContent">&nbsp;</div>';
    hideFlash();
    var randomSample=Math.floor(Math.random() * 3);
    if(randomSample>=3) randomSample=0;
    spWindowOpen(spHTML,640);
    if(login) {  if(pageTracker) pageTracker._trackPageview('/enLargeSampleLoggedInHome'+sport);
    spAjaxRequestWithId(upDateEnlarge,
          host+samples[sport][randomSample],
          'dec=dirDrill',
          0,
          'enLargeContent');
    }
    else {  if(pageTracker) pageTracker._trackPageview('/enLargeSampleHome'+sport);
    spAjaxRequestWithId(upDateEnlargeHome,
          samples[sport][randomSample],
          'dec=dirDrill',
          0,
          'enLargeContent');
    }}
  }

function upDateEnlargeHome(req,id)
  {
    var pracNum=parseInt(id);
    var practice = eval("("+req.responseText+")");
    
    var result='<center>';
		practice.baseDir='viewer/movies/'+practice.pracSportDir;
  //  result+='<div style="margin:6px;border:1px solid #ff0000;padding:6px;"><span style="font-size:16px;color:#0000cc;"><strong>' + langres_spLib_affordNotToJoin + '</strong></span><br/> ' + langres_spLib_joinOver3000 + '<a href="javascript:spWindowClose();toggleDivs(\'signUpHome\',\'home\');" >' + langres_spLib_signUpNow + '</a></div>';
  result+=drawPractice(practice,(parseInt(practice.width)*1.2),(parseInt(practice.height)*1.2))
  /*  result+='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" ';
      result+='height="'+(parseInt(practice.height)*1.2)+'" width="'+(parseInt(practice.width)*1.2)+'">';
      result+='<param name="movie" value="http://www.sportplan.net/viewer/movies/'+practice.pracSportDir+'/'+practice.fileName+'.swf">';
      result+='<param name="quality" value="high">';
      result+='<param name="play" value="true">';
      result+='<param name="bgcolor" value="'+practice.pracBGColor+'">';
      result+='<embed src="http://www.sportplan.net/viewer/movies/'+practice.pracSportDir+'/'+practice.fileName+'.swf"';
      result+='quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"';
      result+='height="'+(parseInt(practice.height)*1.2)+'" width="'+(parseInt(practice.width)*1.2)+'" bgcolor="'+practice.pracBGColor+'" play="true"></object>'
   */   
      // var box=document.getElementById('googleAdBlock');
      // if(box) result+='<div style="margin:6px;border:1px solid #dddddd;padding:6px;">'+box.innerHTML+'</div>';
      var folderName=practice.pracSportName;
     
      if(practice.pracSportName=='Table Tennis') folderName='Table-Tennis';
      if(practice.pracSportName=='Schools Tennis') folderName='Schools-Tennis';
      if(practice.pracSportName=='Junior Golf') folderName='Junior-Golf';
      if(practice.pracSportName=='Grass Roots Cricket') folderName='Grass-Roots-Cricket';
      if(practice.pracSportName=='Field Hockey') folderName='Hockey';
 	
	  result+='<div style="margin:6px;border:1px solid #cccccc;padding:6px;"><a href="javascript:spWindowClose();document.location.href=\'http://'+sphost+'/drills/'+folderName+'/'+practice.pracFolderName+'/practiceIndex.jsp'+'?'+linkApp+'\';" ><span style="font-size:14px;"><strong> see more similar drills </strong></span></a></div>';
      
      result+='<div style="margin:6px;border:1px solid #cccccc;padding:6px;"><a href="javascript:spWindowClose();" ><span style="font-size:14px;"><strong>' + langres_spLib_clickForMore + practice.pracSportName+ '</strong></span></a></div>';
      result+='</center>';
     
      // add email link 
      //result+='<br/><a href="javascript:spWindowClose();toggleDivs(\'emailForm\',\'\');" ><img src="/drills/img/email.gif" border="0" alt="email" align="absmiddle"> Email this Drill</a>';
    spWindowOpen(result,640);
  }

function spButton(spButLabel,spButOnClick,spButId,spAlign)
  {
  var spHTML='';
  spHTML+='<div id="'+spButId+'" onclick="'+spButOnClick+'" class="spButtonDiv_'+spAlign+'" >'; // align="left"
    spHTML+='<table width="10" border="0" cellspacing="0" cellpadding="0"><tr>';
    spHTML+='<td><img src="/ltad/app/images/sGreyButleft.gif" align="absmiddle" ></td>';
    spHTML+='<td nowrap class="spButton_c">&nbsp;'+spButLabel+'&nbsp;</td>';
    spHTML+='<td><img src="/ltad/app/images/sGreyButRight.gif" align="top" ></td>';
    spHTML+='</tr></table></div>';
  return spHTML;
  }

function saveUADetails()
  {
    var thisForm=document.EditUserDetailsForm;
    var params=collectVariables(thisForm);
    if(document.EditUserDetailsForm.postCode.value=='') 
    	{
    	alert("Please complete address details:\n - postcode/zip is required");
    	return false;
    	}
    spAjaxRequestWithId(prepareForm,
          '/drills/UpdateBasicUserDetails.do',
          params,
          0,
          'uaEdit');
    
  }

function checkForUsedUSI(sportCodeId,arrayOfUSI)
  {
    for(var i=0;i<arrayOfUSI.length;i++)
      if(sportCodeId==arrayOfUSI[i]) return true;
    return false;
  }
  


function changePage(sportName)
  {
    document.location.href=host+'/drills/'+sportName+'/index.jsp'+'?'+linkApp;
  }
  


function enlargeBlip(video,width,height)
  {
  var result='<center>';
  result+='<div style="margin-top:2px;border:1px solid #333333;width:'+width+'px;">';
  result+='<embed src="http://blip.tv/play/'+video+'" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" allowscriptaccess="always" allowfullscreen="true"></embed>';
  result+='</div></center>';
  spWindowOpen(result,width);
  }


function tierPlainContent(objMenu,objImage)
{
   var myElement = document.getElementById(objMenu,objImage); 
   if (myElement.style.display == "none")
   {
       myElement.style.display = "block";
       objImage.src = "/cs/img/cross.up.gif";
   }
   else
   {
       myElement.style.display = "none";
       objImage.src = "/cs/img/cross.down.gif";
   }
}



// edit the keywords linked to the practice
function editDrillKeywords (practiceVariantId)
{
  var keywordsSpan = document.getElementById('keywords');
  if (keywordsSpan != null)
  {
    var keywords = keywordsSpan.innerHTML.replace(', ', '\n');
    var displayHTML = '<div style="margin:0px 30px 50px 30px;">';
    displayHTML += '<h2 style="color:#0071B6;">Edit Keywords</h2>';
    displayHTML += '<form name="KeywordsForm">';
    displayHTML += '<textarea name="kws" rows="6" cols="25">' + keywords + '</textarea>';
    displayHTML += '</form>';
    displayHTML += spButton('update', 'updateDrillKeywords(' + practiceVariantId + ');', 'UpdateBut', 'left');
    displayHTML += '</div>';
    
    spWindowOpen(displayHTML, 300);
  }
}

var lastKeywords = null;
// update the keywords that a linked to the current practice
function updateDrillKeywords (practiceVariantId)
{
  var kForm = document.KeywordsForm;
  if (kForm != null)
  {
    var keywords = kForm.kws.value;
    lastKeywords = keywords;
    var params = 'pvId=' + practiceVariantId;
    params += '&lc=' + currentLang;
    params += '&kws=' + keywords;
    
    spAjaxRequest(updateDrillKeywordsResponse, '/drills/UpdatePracticeKeywords.do', params, '');
  }
}


// process the response from updating the keywords for the practice
function updateDrillKeywordsResponse (req)
{
  if (req.responseText.indexOf('success') < 0)
  {
    alert('updating keywords failed');
    return;
  }
  
  var keywordsSpan = document.getElementById('keywords');
  if (keywordsSpan != null)
  {
    keywordsSpan.innerHTML = lastKeywords.replace('\n', ', ');
  }
  
  var tagsDiv = document.getElementById('tags');
  if (tagsDiv != null)
  {
    tagsDiv.innerHTML += '<span style="margin-left:5px;"><img src="/drills/img/ok.png" alt="done" /></span>';
  }
  
  spWindowClose();
}




var miniAdverts= new Array();
miniAdverts['H1']= langres_spLib_practiceTakenFrom + '<a href="/drills/Hockey/proplans/mhPackProPlans.jsp" target="_blank">Coaching the Basics of Hockey</a>';
miniAdverts['R1']= langres_spLib_practiceTakenFrom + '<a href="/drills/Rugby/manuals/beginners.jsp" target="_blank">The Beginners Coaching Manual</a>';
miniAdverts['R2']= langres_spLib_practiceTakenFrom + '<a href="/drills/Rugby/manuals/contactRugby.jsp" target="_blank">Introducing Contact Rugby Manual</a>';
miniAdverts['R3']= langres_spLib_practiceTakenFrom + '<a href="/drills/Rugby/manuals/breakdownRugby.jsp" target="_blank">Introduction to Breakdown and Set Pieces Coaching Manual</a>';
miniAdverts['F1']= langres_spLib_practiceTakenFrom + '<a href="/drills/Football/proplans/footballCoachingGuide.jsp" target="_blank">The Shooting Coaching Guide</a>';
miniAdverts['F2']= langres_spLib_practiceTakenFrom + '<a href="/drills/Football/proplans/footballCoachingGuide.jsp" target="_blank">The Dribbling and Passing Coaching Guide</a>';
miniAdverts['F3']= langres_spLib_practiceTakenFrom + '<a href="/drills/Football/proplans/footballCoachingGuide.jsp" target="_blank">The Warm-Up and Cool Down Coaching Guide</a>';




function playBlip(videoString)
	{
	hideFlash();
	var result='<center>';
	result+='<embed src="http://blip.tv/play/'+videoString+'" type="application/x-shockwave-flash" width="300" height="240" allowscriptaccess="always" allowfullscreen="true"></embed>';
	result+='<div>'+spButton('Close Window','spWindowClose();','closeWindow','left');+'</div>';
		
	result+='</center>';
	spWindowOpen(result,400);
	}
  


function sessionTellMoreRecent(num)
  	{
	 	var box = document.getElementById('sessionTellMoreDiv'+num);
		if(box){
		var result=box.innerHTML;
		result+='<div>'+spButton(langres_spLib_closeWindow,'spWindowClose();','closeWindow','left');+'</div>'
		spWindowOpen(result,600);
		}
		
	}


function putSessionIndexCookie(sportName,sessionIndex)
  {
      var today5Days=new Date();
	  today5Days.setDate(today5Days.getDate() + 5);
      putCookie('si'+sportName,sessionIndex,today5Days);
  }

function  getSessionIndexCookie(sportName)
	{
		var si_details = getCookieName('si'+sportName);
		 if(si_details) if(si_details.length>0) {
			 	spAjaxRequestWithId(displaySessionWeek,
									host+'/drills/'+sportName+'/getSessionWeek.jsp',
									'si='+si_details,
									0,
									'sessionWeekHolder');
				}
	}

function displaySessionWeek(req,id)
	{
		var spBox=document.getElementById('sessionWeekHolder');
		if(spBox) spBox.innerHTML=req.responseText;
	}



/*
 * function to count the words of a given text string
 */
function countWords (text)
{
  var fullStr = text + " ";
  var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
  var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
  var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
  var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
  var splitString = cleanedStr.split(" ");
  var word_count = splitString.length -1;
  
  if (fullStr.length <2)
  {
    word_count = 0;
  }
  
  if (word_count == 1)
  {
    wordOrWords = ' ' + langres_spLib_word
  }
  else
  {
    wordOrWords = ' ' + langres_spLib_words;
  }
  
  return word_count + wordOrWords;
}

function removeEditor(id)
{
  try
  {
    if (tinyMCE.get(id))
    {
      tinyMCE.execCommand('mceRemoveControl', false, id);
    }
  }
  catch (e)
  {
    // ignore error
    spLog('error whilst removing tinyMCE editor, tinyMCE may not be defined');
  }  
}

function addEditor(id)
{
  try
  {
    if (!tinyMCE.get(id))
    {
      tinyMCE.execCommand('mceAddControl', false, id);
      var box = document.getElementById('toggleBut');
      if (box)
      {
        box.style.display='none';
      }
    }
  }
  catch (e)
  {
    // ignore error
    spLog('error whilst removing tinyMCE editor, tinyMCE may not be defined');
  }  
}


function loadYouTube(youTubeId,playerId)
		{
		var result='';
		result += '<object width= "300" height="242"><param name="movie" value="http://www.youtube.com/v/' + youTubeId + '&autoplay=1&rel=0&fs=1&color1=0x3a3a3a&color2=0x999999&border=0&loop=0"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/'  + youTubeId + '&autoplay=1&rel=0&fs=1&color1=0x3a3a3a&color2=0x999999&border=0&loop=0" type="application/x-shockwave-flash" allowfullscreen="true" width="300" height="242"></embed></object>';
		var spBox = document.getElementById(playerId);
		if(spBox) {
			if(spBox.innerHTML.indexOf('object')==-1) spBox.innerHTML=result;
			
			}
		}



var all_sport_categories = null;
  
/*
 * set the sport categories list from ajax req
 */  
function setAllSportCategories (req)
{
  all_sport_categories = eval("(" + req.responseText + ")");
}


// get a specific SportCategoryDetail.categoryName for the given Sport.sportCodeId,
//  Lanuage.languageCode and SportCategoryDetail.sportCategoryId

function getSportCategoryName (sportCodeId, languageCode, sportCategoryId)
{
  if (all_sport_categories != null)
  {
    for (var i = 0; i < all_sport_categories.length; i++)
    {
      if (all_sport_categories[i].sportCodeId == sportCodeId)
      {
        var langs = all_sport_categories[i].languages;
        for (var j = 0; j < langs.length; j++)
        {
          if (langs[j].languageCode == languageCode)
          {
            var scs = langs[j].sportCategories;
            for (var k = 0; k < scs.length; k++)
            {
              if (scs[k].sportCategoryId == sportCategoryId)
              {
                return scs[k].categoryName;
              }
            }
          }
        }
      }
    }
  }
  
  return null;
}


/*
 * get a list of SportCategoryDetails for the given Sport.sportCodeId and Lanuage.languageCode
 */
function getSportCategories (sportCodeId, languageCode, onlyUserCategories)
{
  if (onlyUserCategories == null || onlyUserCategories != true)
  {
    onlyUserCategories = false;
  }
  
  if (all_sport_categories != null)
  {
    for (var i = 0; i < all_sport_categories.length; i++)
    {
      if (all_sport_categories[i].sportCodeId == sportCodeId)
      {
        var langs = all_sport_categories[i].languages;
        for (var j = 0; j < langs.length; j++)
        {
          if (langs[j].languageCode == languageCode)
          {
            var scs = langs[j].sportCategories;
            if (onlyUserCategories)
            {
              var userCategories = new Array();
              for (var k = 0; k < scs.length; k++)
              {
                if (scs[k].userCategory)
                {
                  userCategories[userCategories.length] = scs[k];
                }
              }
              
              return userCategories;
            }
            else
            {
              return scs;
            }
          }
        }
      }
    }
  }
  
  return null;
}


function startSpSearch()
	{
		var result='';
		if(sphost=='www.irbcoaching.com'&&lastSportName=='') lastSportName='Rugby';
		
  	result += '<h2>'  + langres_spLib_search + '</h2>';
  result += langres_spLib_searchDrillsAndAnswers;
	if(sphost=='www.irbcoaching.com'&&lastSportName=='')	result+= '<form method="GET" action="http://'+sphost+'/drills/search/index.jsp">	';
	else result+= '<form method="GET" action="http://'+sphost+'/drills/search/search2010.jsp">	';
		if(lastSportName!='Sports'||lastSportName=='')
			{
			result+= '<input type="hidden" value="'+lastSportName+'" name="sport"/>';
		
			}
		else {
		result += langres_spLib_selectSport + '&nbsp;&nbsp;';
    if(sphost=='www.irbcoaching.com'&&lastSportName=='') result+= '<select name="sport" ><option value="-1">&lt;' + langres_spLib_select + '&gt;</option>';
    else result+= '<select name="s" ><option value="-1">&lt;' + langres_spLib_select + '&gt;</option>';
    result+= '<option value="Athletics">Athletics</option>  ';
    result+= '<option value="Basketball">Basketball</option>';  
    result+= '<option value="Cricket">Cricket</option>';  
    result+= '<option value="Golf">Golf</option>  ';
    result+= '<option value="Handball">Handball</option>';  
    result+= '<option value="Hockey">Hockey</option>';  
    result+= '<option value="Judo">Judo</option>  ';
    result+= '<option value="Junior Golf">Junior Golf</option>';
    result += '<option value="Netball">Netball</option>';
    result+= '<option value="Rugby">Rugby</option>  ';
    result+= '<option value="Strength">Strength</option>  ';
    result+= '<option value="Swimming">Swimming</option>';  
    result+= '<option value="Tennis">Tennis</option>  ';
    result+= '<option value="Volleyball">Volleyball</option>  ';
    result+= '<option value="Workout">Workout</option></select>';
		result+= '<br/><br/>';
		}
		result+= '<input type="text" value="'+lastSearchQuery+'" name="q"/>';
		result+= '<input type="submit" value="' + langres_spLib_search + '"/> <span style="font-size:6px;color:#33ccff;">BETA</span>';
		
		result+= '</form>';
		
		//hideFlash();
		spWindowOpen(result,300);
	}
	
function insertMoviePlayer(thePractice,spWidth,spHeight)
		{
		var result='';
		var paddingLeft,showPadding=0;
		//alert(document.getElementById(playerId));
		//alert("spHeight: "+spHeight + "thePractice.height: "+thePractice.height + "ratio :"+spHeight/thePractice.height);
		if(spHeight>thePractice.height) {
			// calc scale with player
			//alert("spWidth: "+spWidth + "ratio :"+spWidth/thePractice.width);
			//alert("spHeight: "+spHeight + "ratio :"+spHeight/parseInt(thePractice.height));
			var ratio = spHeight/(parseInt(thePractice.height)+25);
			// new height =
			//spHeight= parseInt((parseInt(thePractice.height)+25)*ratio);
			var tempSpWidth = parseInt((parseInt(thePractice.width))*ratio);
			paddingLeft=(spWidth-tempSpWidth)/2;
			spWidth=tempSpWidth;
			result+='<div style="padding-left:'+paddingLeft+'px;">';
			var showPadding=1;
			//alert("spHeight: "+spHeight + "ratio :"+ratio);
		}
		//if(lastEmail=='johndnurse@gmail.com') alert("w:"+thePractice.width+" h:"+thePractice.height+" w:"+spWidth+" h:"+spHeight);
		if(thePractice.height==600&&(thePractice.width==302||thePractice.width==301||thePractice.width==300||thePractice.width==299||thePractice.width==298)) {var spPlayer='300600';if(spHeight==600) spHeight=625;}
		else if((thePractice.height==500||thePractice.height==501)&&(thePractice.width==302||thePractice.width==301||thePractice.width==300||thePractice.width==299||thePractice.width==298)) {var spPlayer='300500';if(spHeight==500||spHeight==501) spHeight=525;}
		else if((thePractice.height==302||thePractice.height==300||thePractice.height==301||thePractice.height==299||thePractice.height==298)&&(thePractice.width==302||thePractice.width==301||thePractice.width==300||thePractice.width==299||thePractice.width==298)) {var spPlayer='300300';if(spHeight==300||spHeight==299||spHeight==298||spHeight==301) spHeight=325;}
		else if((thePractice.height==360||thePractice.height==361||thePractice.height==359)&&(thePractice.width==621||thePractice.width==620||thePractice.width==619)) {var spPlayer='620360';if(spHeight==360) spHeight=385;}
		else if((thePractice.height==180||thePractice.height==181||thePractice.height==289)&&(thePractice.width==341||thePractice.width==340||thePractice.width==339)) {var spPlayer='340180';if(spHeight==180) spHeight=205;}
		else if(thePractice.height==thePractice.width) { var spPlayer='300300';if(spHeight==210) spHeight=225;}
		else  {var spPlayer='300200';if(spHeight==200||spHeight==201||spHeight==199) spHeight=225;}
		if(thePractice.created) {var tempDate=new stringToDate(thePractice.created);
		var july1st = new Date();
		july1st = july1st.setFullYear(2010,6,20);
		if(tempDate>july1st) {var spPlayerPrefix='playerB';var frameRate=25;}
		else {var spPlayerPrefix='player';var frameRate=15;}
		} else {var spPlayerPrefix='playerB';var frameRate=25;}
		result+='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+spWidth+'" height="'+spHeight+'" id="player" align="middle">';
		result+='<param name="allowScriptAccess" value="sameDomain" />';
		result+='<param name="allowFullScreen" value="false" />';
		result+='<param name="movie" value="/drills/chalkBoard/players/'+spPlayerPrefix+spPlayer+'.swf?fileName='+escape(thePractice.swfSource)+'&frameRate='+frameRate+'" /><param name="quality" value="high" /><embed wmode="transparent" onmouseup="slideDown(\'rateThis\');return true;" src="/drills/chalkBoard/players/'+spPlayerPrefix+spPlayer+'.swf?fileName='+escape(thePractice.swfSource)+'&frameRate='+frameRate+'" quality="high" width="'+spWidth+'" height="'+spHeight+'" name="player" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />';
		result+='</object>';
		if(showPadding) result+='</div>';
		 return result
		
		}

function drawAnimatorDrill(thePractice,spWidth,spHeight,inPopUp)
	{
	// first convert BG -> Hex to Dec
	  //draw Player Holder
		var result='';
		
		
				
		if(spHeight==300||spHeight==301) var spDisplayHeight=325;
		else if(spHeight==180||spHeight==181) var spDisplayHeight=205;
		else if(spHeight==600) var spDisplayHeight=625;
		else if(spHeight==360||spHeight==361||spHeight==359) var spDisplayHeight=385;
		else if(spHeight==500||spHeight==501) var spDisplayHeight=525;
		else if(spHeight==200||spHeight==201||spHeight==199) var spDisplayHeight=225;
		else var spDisplayHeight=325;
		
		if(spDisplayHeight>(spHeight+28)) spDisplayHeight=spHeight;
		
		
		
		//else if(lastEmail='john@sportplan.net') alert("animator dimensions error>> w:"+spWidth+" : "+spHeight);
		//result+='<div class="myPlayer" style="display:block;width:'+width+'px;height:'+(height)+'px;background-image:url('+imgSource+');" ';
		//result+=' onclick="loadMovieSP9a(\''+swfSource+'\','+width+','+height+','+bgColor+',\''+playerIndex+'\');" id="'+playerIndex+'"><img src="/drills/img/play_large.png" alt="play"/></div>';
		result+='<div style="display:block;width:'+spWidth+'px;height:'+spDisplayHeight+'px;"';
		if(inPopUp==null) result+=' id="movieHolder">';
		else result+=' >';
		result+=insertMoviePlayer(thePractice,spWidth,spHeight);
		result+='</div>';
		return result;
	}

function TempPractice(swfSource,swfWidth,swfHeight)
	{
		this.swfSource=swfSource;
		this.width=swfWidth;
		this.height=swfHeight;
	}
	
function writeOutAnimatorDrill(swfSource,swfWidth,swfHeight,inPopUp)
	{
		var tempPractice = new TempPractice(swfSource,parseInt(swfWidth),parseInt(swfHeight));
		var result='';
		
		result += drawAnimatorDrill(tempPractice,swfWidth,swfHeight,inPopUp);
		
		return result;
	}

function enlargeAnimatorDrill(swfSource,swfWidth,swfHeight)
	{
		var tempPractice = new TempPractice(swfSource,parseInt(swfWidth),parseInt(swfHeight));
		var result='';
		result += '<center>';
		result += '<div style="height:'+((parseInt(swfHeight)*2)+20)+'px;">';
		result += drawAnimatorDrill(tempPractice,parseInt(swfWidth)*2,parseInt(swfHeight)*2);
		
    result += '</div>';
    result+=spButton(langres_spLib_closeWindow,'spWindowClose();','close','');
    result += '</center>';
    hideFlash();
		spWindowOpen(result,(parseInt(swfWidth)*2)+20);
	}

function startBounce()
	{
	}
	
function openCloseFolders(spBlock)
  {
  var pageDivs = document.getElementsByTagName('div');
  for(var i=0;i<pageDivs.length;i++)
    {
    if(pageDivs[i].className=='foldersFold') {
      
      if(pageDivs[i].id!=spBlock) pageDivs[i].style.display='none';
      }
    }
  var spBox= getElementsById(spBlock);
  for(var i=0;i<spBox.length;i++)
    {
      if(spBox[i].style.display=='none') spBox[i].style.display='block';
      else if(spBox[i].style.display=='block') spBox[i].style.display='none';
    }
  }

 function translateToEnglish(srcLang,spText)
 	{
 	var theSpText=document.getElementById(spText);
 	if(theSpText) {alert(theSpText.innerHTML);
  google.language.translate(theSpText.innerHTML, srcLang, "en", function(result) {
  if (!result.error) {
    spWindowOpen(result.translation,400);
  } else spWindowOpen(result.translation,400);});
  }}
 
 function translateAnswer(targetLang)
 	{
 	var theSpText=document.getElementById('answerText');
 	if(theSpText) {alert('Translation text ==\n'+theSpText.value+ '\n\n--Translated with Google Translate');
 	
  google.language.translate(theSpText.value + '\n\n--Translated with Google Translate', "en", targetLang, function(result) {
  if (!result.error) {
  	var theSpText=document.getElementById('answerText');
    theSpText.value = result.translation;
  } else {
  	var theSpText=document.getElementById('answerText');
    theSpText.value = result.translation;
  }});
  }}
  
  var sportsPlans = null;
/*
 * load the Session Plans that belong to the current user for the currently selected sport (if there is one)
 */
function loadCurrentSportsPlans ()
{
  spAjaxRequest(processPlans, "/drills/SportsPlans.do", "", "");
}
/*
 * process the found Session Plans into the global array object
 */
function processPlans (req)
{
  var spBox = document.getElementById("recentPlansHolder");
  	
	 if(spBox){
	 
	 if(req==null)
   {
	 	if(spBox.style.display == 'none')
    {
    	var spBox = document.getElementById("recentPlansHolderInside");
    	if(findStart(spBox.innerHTML).indexOf('[]')>-1) {
    		var spBox=document.getElementById('videoTutor');
   			if(spBox) spBox.style.display='block';
   			var spBox=document.getElementById('recentPlansHolder');
   			if(spBox) spBox.style.display='none';
   			loadCurrentSportsPlans ();
   			return false;
    		}
    	 sportsPlans = eval("([" + findStart(spBox.innerHTML) + "])");
    }
    }
	  else
    {
			sportsPlans = eval("(" + req.responseText + ")");
  	}}
  
	if(sportsPlans){	
  var result = '';
 // result += '<div id="recentPlans" style="background-color:#E0ECFF;border:1px solid #E0ECFF;">';
 // result += '<div style="padding:3px;font-size:11px;color:#000066;">Recent Plans</div>';
  result += '<div style="background-color:#efefef;width:132px;overflow:hidden;">'
	for (var i = 0; i < sportsPlans.length && i < 4; i++)
	{
  	result += '<div style="width:500px;height:20px;overflow:hidden;">';
		result += '<a href="/drills/EditSession.do?seId=' + sportsPlans[i].id + '&OpenedSession=true&action=&open=true" style="text-decoration:none;color:#000099;font-size:12px;"><img src="/userapp/app/images/sessFile.gif" align="absmiddle" border="0"> ' + cleanTitle(sportsPlans[i].title) + '</a>';
		result += '</div>';
	}

	result += '<div style="width:132px;text-align:right;"><a href="' + host + '/drills/MyStuff/FindSessions.do" style="text-decoration:none;color:#000099;font-size:9px;">'+langres_spLib_myStuff+' >></a></div>';
	result += '</div>';

  var spBox = document.getElementById("recentPlansHolderInside");
  if(spBox)
  {
    spBox.innerHTML=result;
  }

  
  if(sportsPlans&&sportsPlans.length>0){
   var spBox=document.getElementById('videoTutor');
   if(spBox) spBox.style.display='none';
   var spBox=document.getElementById('recentPlansHolder');
   if(spBox) spBox.style.display='block';
  }}
}

function cleanTitle(spString)
	{
		spString=spString.replace(/#039;/g,'\'');
		return spString;
	}

function slideDown(spObj)
	{
		var spBox= document.getElementById(spObj);
		if(spBox) spBox.style.display='block';
		//slidedown(spObj);
	}
	

function updateLikeThis(spURL,spTitle)
	{
		var result='';
		result+='<a title="Send to Facebook" target="_blank" href="//www.addthis.com/bookmark.php?pub=johndnurse&amp;v=250&amp;source=tbx-250&amp;tt=0&amp;s=facebook&amp;url='+escape(spURL)+'&amp;title='+spTitle+'&amp;content=&amp;sms_ss=1&amp;lng=en" class="addthis_button_facebook at300b"><span class="at300bs at15t_facebook"></span></a>';
    result+='<a title="Tweet This" target="_blank" href="//www.addthis.com/bookmark.php?pub=johndnurse&amp;v=250&amp;source=tbx-250&amp;tt=0&amp;s=twitter&amp;url='+escape(spURL)+'&amp;title='+spTitle+'&amp;content=&amp;sms_ss=1&amp;lng=en" class="addthis_button_twitter at300b"><span class="at300bs at15t_twitter"></span></a>';
	  result+='<a title="Send to Facebook_like" target="_blank" href="//www.addthis.com/bookmark.php?pub=johndnurse&amp;v=250&amp;source=tbx-250&amp;tt=0&amp;s=facebook_like&amp;url='+escape(spURL)+'&amp;title='+spTitle+'&amp;content=&amp;sms_ss=1&amp;lng=en" class="addthis_button_facebook_like at300b" style="width: 50px;"><iframe src="//www.facebook.com/plugins/like.php?href='+escape(spURL)+'&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp;action=like&amp;font=arial&amp;" style="overflow: hidden; border: 0px none; width: 82px; height: 25px; margin-top: -2px;"></iframe></a>';
		result+='<div class="atclear"></div>';
		var spBox= document.getElementById('likeThis');
		if(spBox) {
			spBox.innerHTML=result;
			
			}
		var spBox= document.getElementById('rateThis');
		if(spBox) {
		// no need to hide it
		//	spBox.style.display="none";
			}
	 /// reset stars.
	 var result='';
	 result+='<img src="/drills/img/2010/star1.png" onmouseover="highlight(this.id)" onclick="setStar(this.id)" onmouseout="losehighlight(this.id)" id="1" style="width:20px; height:20px; float:left;" />';
		result+='<img src="/drills/img/2010/star1.png" onmouseover="highlight(this.id)" onclick="setStar(this.id)" onmouseout="losehighlight(this.id)" id="2" style="width:20px; height:20px; float:left;" />';
	result+='<img src="/drills/img/2010/star1.png" onmouseover="highlight(this.id)" onclick="setStar(this.id)" onmouseout="losehighlight(this.id)" id="3" style="width:20px; height:20px; float:left;" />';
	result+='<img src="/drills/img/2010/star1.png" onmouseover="highlight(this.id)" onclick="setStar(this.id)" onmouseout="losehighlight(this.id)" id="4" style="width:20px; height:20px; float:left;" />';
	result+='<img src="/drills/img/2010/star1.png" onmouseover="highlight(this.id)" onclick="setStar(this.id)" onmouseout="losehighlight(this.id)" id="5" style="width:20px; height:20px; float:left;" />';
	 var spBox= document.getElementById('rateStars');
	 if(spBox) {
			spBox.innerHTML=result;
			set=false;
			
			}
	
	}
	
/*
 * convert a string formatted date into a date object
 */
function stringToDate(spDateString)
{
  MyDate = spDateString;
  MD_i1 = MyDate.indexOf(' ');
  MD_Date = MyDate.substring(0,MD_i1);
  MD_Time = MyDate.substring(MD_i1 + 1);
  MD_i2 = MD_Date.indexOf('/');
  MD_i3 = MD_Date.indexOf('/',MD_i2 + 1);
  MD_D = MD_Date.substring(0,MD_i2);
  MD_M = MD_Date.substring(MD_i2 + 1, MD_i3);
  MD_Y = MD_Date.substring(MD_i3 + 1);
  MD_i4 = MD_Time.indexOf(':');
  MD_H = MD_Time.substring(0, MD_i4);
  MD_N = parseInt(MD_Time.substring(MD_i4 + 1));
  MD_S = 0;
  
  if ((isNaN(MD_Y)) || (isNaN(MD_M)) || (isNaN(MD_D)) || (isNaN(MD_H)) || (isNaN(MD_N)) || (isNaN(MD_S)))
  {
    //alert('Not numeric.');
    DObj = '*** error';
  }
  else
  {
    MD_M = MD_M - 1; // Jan-Dec=00-11
    if (MD_Time.toLowerCase().indexOf('pm') > -1)
    {
      if (MD_H != 12)
      {
        MD_H = MD_H * 1+12;
      }
    }
    else
    {
      if (MD_H == 12)
      {
        MD_H = 0;
      }
    }
    
    DObj = new Date(MD_Y, MD_M, MD_D, MD_H, MD_N, MD_S);
  }

  return DObj;
}

function spPlannerDemoOpen()
{
    var objOverlay = document.getElementById('overlayUG');
  if(objOverlay){
    objOverlay.style.display = 'block';    
    objOverlay.style.width = '100%';
    }
  else {
    var objBody = document.getElementsByTagName("body").item(0);
    
    // create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
    var objOverlay = document.createElement("div");
    objOverlay.setAttribute('id','overlay');
    objOverlay.onclick = function () { /*hideLightbox();*/ return false;};
    objOverlay.style.display = 'block';
    objOverlay.style.position = 'absolute';
    objOverlay.style.top = '0';
    objOverlay.style.left = '0';
    objOverlay.style.zIndex = '150';
     objOverlay.style.width = '100%';
    if(objBody) objBody.insertBefore(objOverlay, objBody.firstChild);
    }
  var arrayPageSize = getPageSize();
    objOverlay.style.height = (arrayPageSize[1] + 'px');
    objOverlay.style.display = 'block';
    var myWidth = 0, myHeight = 0;
        if( typeof( window.innerWidth ) == 'number' ) {
              myWidth = window.innerWidth;
              myHeight = window.innerHeight;
        } 
        else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
            //IE 6+ in 'standards compliant mode'
            myWidth = document.documentElement.clientWidth;
            myHeight = document.documentElement.clientHeight;
          } 
        else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
            //IE 4 compatible
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
          }
  
    var objWindow = document.getElementById('spUGWindow');
  if(objWindow){
    objWindow.style.display = 'block';    
   // objWindow.style.width = (spWidth+14)+'px';
  	
		}
	else {
	var objBody = document.getElementsByTagName("body").item(0);
		var objWindow = document.createElement("div");
			objWindow.setAttribute('id','spPLWindow'); // change Name 
			objWindow.className='spPLWindow';
			objWindow.style.zIndex = '151';
	 		//objWindow.style.width = (spWidth+14)+'px';
			objBody.insertBefore(objWindow, objBody.firstChild);
		
		var objCloseButton = document.createElement("div");
		objCloseButton.onclick = function () { /*hideLightbox();*/ spWindowClose();return false;};
		objCloseButton.setAttribute('id','spUGWindowClose');
		objCloseButton.className='alphacube_close';
		 objCloseButton.style.display='block';
			objWindow.appendChild(objCloseButton);
        }
    
    
    
    if(!tdContent) {
      var tdContent=document.getElementById('spPLWindow');
      }
    var result='';
    result+='<div style="width:650px;padding:5px;background-color:#000000;"><embed src="http://blip.tv/play/hIVUgfruFwA" type="application/x-shockwave-flash" width="640" height="510" allowscriptaccess="always" allowfullscreen="true"></embed>'
    result+='<div style="cursor:pointer;color:#ffffff;" onclick="spWindowClosePLD();return false;">Close Window</div></center></div>';
    tdContent.innerHTML=result;
    var IpopTop = (myHeight - objWindow.offsetHeight) / 2;
    var IpopLeft = (myWidth - objWindow.offsetWidth) / 2;
  
  
    
    if(IpopTop<10) IpopTop=10;
    objWindow.style.left=(IpopLeft + document.body.scrollLeft+ document.documentElement.scrollLeft)+'px';
    objWindow.style.top=(IpopTop + document.body.scrollTop + document.documentElement.scrollTop)+'px';
  
  }

function spWindowClosePLD()
{ 
 objOverlay = document.getElementById('overlay');
  if (objOverlay != null)
  {
    objOverlay.style.display = 'none';
    objOverlay.style.width = '0px';
    objOverlay.style.height = '0px';
    
    var objWindow=document.getElementById('spPLWindow');
    if(objWindow) 
    {    
      objWindow.style.display='none';
      objWindow.style.left=-800+'px';
      objWindow.innerHTML='';
    }
    
    showFlash();
  }
}

function removeBadCharacters(theString)
	{

	
	theString=removeNbsp(theString);
	theString=removeAmp(theString);
	theString=theString.replace(/–/g,'-');
	theString=theString.replace(/–/g,'-');
	
	theString=theString.replace(/’/g,'\'');
	theString=theString.replace(/‘/g,'\'');
	 /// clear newline characters which break eval statement 
        theString=theString.replace(/\n/g,'');
			
        /***** IE and Opera need this line also *****/
      theString=theString.replace(/\s/g,' ').replace(/  ,/g,''); 
	//theString=removeFunnyEncoding(theString);
	//theString=theString.replace(/^\s+|\s+$/g, '') ;
	theString=theString.replace(/[^a-zA-Z 0-9 \. , \? ' " !@#\$ \% \^ \& \* \( \) -_=\+;:<>\/\\\|\}\{\[\] /]+/g,'');
	return theString;
	}

function CountOb(target,spId)
	{
		this.target=target;
		this.spId=spId;
		this.spBox=document.getElementById(spId)
		this.count=0;
		this.timer;
	}

var countTo;

function startCountTo(target,spId)
	{
	countTo= new CountOb(target,spId);
	countTo.timer=setTimeout(contCount,100);
	}

function contCount()
	{
	if(countTo.spBox){
		countTo.spBox.innerHTML=countTo.count;
		countTo.count++;
		if(countTo.count<=countTo.target) countTo.timer=setTimeout(contCount,50);
		else countTo.timer=null;
	}
	}
	
function checkSpProgress()
	{
		spLoadJS('http://'+sphost+'/drills/layout/home/sportplanUsage.jsp','');
	}

function processUsage()
	{
	var hits=0;
	var kpis=0;
	for(var k=0;k<sportplanUsage.category.length;k++)
		{
		for(var i=0;i<sportplanUsage.category[k].kpis.length;i++)
			{
			kpis++;
			if(sportplanUsage.category[k].kpis[i].completed) hits++;
			}
		}
		var percentage=parseInt(hits/kpis*100);
		//if(lastEmail=='john@sportplan.net') {alert(hits);alert(kpis);}
		var offset=parseInt(percentage*1.18);
		var result='';
		
		result+='<div class="clear"></div>';
    result+='<dl>';
    result+='<dt>&nbsp;<strong>Sportplan User Level</strong> &nbsp;&nbsp;<a href="javascript:explainUsage();" style="font-size:8px;">Whats this?</a></dt>';
    result+='<div style="float:right;z-index:10;font-weight:bold;width:30px;padding-top:6px;padding-right:8px;font-size:10px;text-align:right;">';
    result+='<span id="spProgressCounter">&nbsp;</span>%';
    result+='</div><dd>';
    result+='<span><em style="left:'+offset+'px">'+percentage+'%</em></span>';
		result+='</dd></dl>     ';
			var spBox=document.getElementById('userProgress');
	if(spBox) spBox.innerHTML=result;
		var spBox=document.getElementById('spProgressCounter');
		if(spBox){
			startCountTo(percentage,'spProgressCounter');
		}
	}

function explainUsage()
	{
	 var result='<div style="padding:10px;">';
	 result+='<h2 class="spHeading" style="margin-top:0px;">Sportplan Usage Dashboard:</h2>';
	 
	 result+='<p>To help you become a better coach Sportplan have created some great online tools.<br/>Your Sportplan User Level lets you keep track of your progress in using these tools.</p>';
	 result+='<div style="width:730px;">';
	 for(var k=0;k<sportplanUsage.category.length;k++)
		{
		result+='<div style="border-top:1px solid #cccccc;padding-top:2px;">';
		result+='<h4 style="margin:0px;">'+sportplanUsage.category[k].heading+'</h4><div class="clear"></div>';
		for(var i=0;i<sportplanUsage.category[k].kpis.length;i++)
		{
		result+='<div style="width:228px;padding:2px;border:1px solid #ededed;float:left;height:50px;margin-top:4px;margin-left:8px;"><table width="220" cellpadding="0" cellspacing="0" border="0"><tr><td style="width:34px;" valign="top">';
	 	if(sportplanUsage.category[k].kpis[i].completed) result+='<img src="'+sportplanUsage.category[k].kpis[i].imageOn+'" /></td>';
	 	else result+='<img src="'+sportplanUsage.category[k].kpis[i].imageOff+'" /></td>';
	 	result+='<td style="width:186px;font-size:13px;height:45px;';
	 	if(sportplanUsage.category[k].kpis[i].completed) result+='background-image:url(/drills/img/2010/features/tick.gif);background-repeat:no-repeat;background-position:100% 100%;';
	 	result+='" valign="top">';
		result+='<strong>'+sportplanUsage.category[k].kpis[i].heading+'</strong><br/>';
		result+='<a href="javascript:showLearnMore('+k+','+i+');" style="font-size:11px;">Learn More</a><br/>';
		if(typeof sportplanUsage.category[k].kpis[i].asked != 'undefined') result+='Asked: '+sportplanUsage.category[k].kpis[i].asked+ '&nbsp;&nbsp;Answered: '+sportplanUsage.category[k].kpis[i].answered;
		else if(sportplanUsage.category[k].kpis[i].count!=''&&sportplanUsage.category[k].kpis[i].count!=null) result+='items: ' +sportplanUsage.category[k].kpis[i].count; 
		
		//result+=sportplanUsage.kpis[i].completed;
		result+='</td></tr></table></div>';
		}
		result+='<div class="clear"></div></div>';
		}
		result+='<div class="clear"></div>';
		result+='<center>'+spButton('Close Window','spWindowClose();','closeWindow','');+'</center>';
		result+='</div></div>';
	spWindowOpen(result,750);
	}

function showLearnMore(cat,kpi)
	{
		var result='<div style="padding:10px;">';
	 	result+='<div style="width:300px;padding:2px;"><table width="300" cellpadding="0" cellspacing="0" border="0"><tr><td style="width:34px;" valign="top">';
	 	result+='<img src="'+sportplanUsage.category[cat].kpis[kpi].imageOn+'" /></td>';
	 	result+='<td style="width:266px;color:#666666;font-size:13px;line-height:18px;';
	 	result+='" valign="top">';
		result+='<span style="font-size:14px;color:#000000;"><strong>'+sportplanUsage.category[cat].kpis[kpi].heading+'</strong></span><br/>';
		result+=sportplanUsage.category[cat].kpis[kpi].learnMore;
		result+='</td></tr></table></div>';
		result+='<div class="clear"></div>';
		result+='<center>'+spButton('Back to Dashboard','explainUsage();','closeWindow','');+'</center>';
		result+='</div>';
		spWindowOpen(result,320);
		
	}

function spLoadJS(href,scriptId) {
	
	if(scriptId!=null){
		var oldScriptTag = document.getElementById(scriptId);
  	if (oldScriptTag) {
    oldScriptTag.parentNode.removeChild(oldScriptTag);
    var oldScriptTag = document.getElementById('span'+scriptId);
    if(oldScriptTag) oldScriptTag.parentNode.removeChild(oldScriptTag);
    setTimeout('loadJS("'+href+'","'+scriptId+'")',100);
    return false; 
  	}
	}
	//if(lastEmail=='john@sportplan.net') alert(scriptId);
	var spBox= document.getElementById('insertThingsHere');
	var span = document.createElement('SPAN');
	span.style.display = 'none';
	if(scriptId!=null) span.setAttribute('id','span'+scriptId);
	else {
	var randomSample=Math.floor(Math.random() * 10000);
	scriptId='r'+	randomSample;
	span.setAttribute('id','span'+scriptId);
	}
	if(spBox) spBox.parentNode.insertBefore(span, spBox);
	else setTimeout('\'spLoadJS('+href+','+scriptId+')\'',5000);
	href=href.replace(/\s/g,"%20");
	if(lastEmail=='john@sportplan.net') if(scriptId=='spVideo') {
		var spBox=document.getElementById('spVSVProcessedResults');
  	if(spBox) spBox.innerHTML=href;
	}
	//if(lastEmail=='john@sportplan.net') prompt('',href);
	span.innerHTML = 'Text for stupid IE.<s'+'cript ></' + 'script>';
	setTimeout(function(){
			var s = span.getElementsByTagName('script')[0];
			s.language = 'JavaScript';
			if (s.setAttribute) {s.setAttribute('src', href);
			s.setAttribute('id', scriptId);
			} else s.src = href;}, 100);
}

function showFairUsage()
    {
    var spBox=document.getElementById('fairUsageNotice');
    if(spBox){
    var result=spBox.innerHTML;
    result+='<div>'+spButton('Close Window','spWindowClose();','closeWindow','left');+'</div>'
    hideFlash();
    
      spWindowOpen(result,500);
      }
    }




function popChangeSearchSportDrills()
{
var spBox=document.getElementById('drillsTabHome');
  //  if(spBox) spBox.innerHTML='';
  var spBox = document.getElementById('sportChoice');
  var infoBox = document.getElementById('searchSportHolder');
  var divPos = findPos(infoBox);
  var arrayPageSize = getPageSize();
  var result = '';
 
  result+='<div style="float: right; width: 15px; height: 30px; margin-right: 1px;">';
  result+='<a href="javascript:closeSearchSpPopDrills();" class="deleteButton"><img alt="del" src="/drills/img/1.gif" align="right" border="0" height="14" width="15"></a>';
  result+='</div>';
  
  result+='<span style="font-size:14px;"><strong>Choose Sport</strong></span>';
  
  result+=populateSportsChoiceDrills();
 
   
  var spPopUp = document.getElementById('searchSportContents');
  if (spPopUp) spPopUp.innerHTML=result;
  

  if(spBox){    //below
  	setSportChoiceLeftDrills();
      spBox.className='spmyStuffPop spLipTop';
      spBox.style.top=(divPos[1]+4)+'px';
      spBox.style.display='block';
      }
      
      //spBox.style.right=(divPos[0]-68)+'px';
}   

function setSportChoiceLeftDrills()
	{
	var infoBox = document.getElementById('drillsTabHome');
	var divPos = findPos(infoBox);
  var spBox = document.getElementById('sportChoice');
  if(spBox) {
  	spBox.style.right='';
  	spBox.style.left=(divPos[0]+-115)+'px';
	var browser=navigator.appName;
    var b_version=navigator.appVersion;
    var version=parseFloat(b_version);
    if(browser.indexOf('Microsoft')>-1) browser='Microsoft';

  	if(browser=='Microsoft') { spBox.style.left=divPos[0]+'px';
  	var spBox=document.getElementById('searchSportContents');
  	if(spBox) spBox.style.width='290px';
  	}
		} else setTimeout('setSportChoiceLeft()',1000);
	}  

function closeSearchSpPopDrills()
  {
    var spBox = document.getElementById('sportChoice');
    if(spBox) spBox.style.display='none';
	spBox.style.right='60px';
  	spBox.style.left='';
	spBox.style.top='130px';
  }
  
function findPos(obj)
{
  var curleft = curtop = 0;
  if (obj.offsetParent)
  {
    do
    {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
  }
  return [curleft,curtop];
} 

function populateSportsChoiceDrills()
{
  var box = document.getElementById('USIdetails');
  if (box && box.innerHTML.length > 5 || myUSI != null) {
  	if (myUSI == null) 
  		myUSI = eval("(" + findStart(box.innerHTML) + ")");
  	SL = eval("([" + fullSportsList + "])");
  	type = 'icon';
  	var result = '';
  	var result2 = '';
  	result += '<div class="clear" ></div>';
  	var foundSelected = 0;
  	var usedUSI = new Array();
  	if (studentName == 0&&myUSI.userSportInterests.length>0) {
  	
  	for (var i = 0; i < myUSI.userSportInterests.length; i++) {
  		if (!checkForUsedUSI(myUSI.userSportInterests[i].sportCodeId, usedUSI) && myUSI.userSportInterests[i].isDelete == 'false' && (myUSI.userSportInterests[i].interestId != -1 || studentAccount != 0)) {
  			result += '<div class="mySportBox">';
  			result += '<div class="floatStar">';
  			if (myUSI.userSportInterests[i].isMember == 'true') {
  				result += '<img src="/drills/img/2010/home/starOn.png" width="15" height="15" align="absmiddle">';
  			}
  			if (myUSI.userSportInterests[i].isMember == 'false') {
  				result += '<img src="/drills/img/2010/home/starOff.png" width="15" height="15" align="absmiddle">';
  			}
  			result += '</div>';
  			result += '<div style="margin-top:7px;text-align:center;">';
  			result += '<a href="http://' + sphost + '/drills/' + myUSI.userSportInterests[i].sportName + '/index.jsp" class="sportLinkHome"><img src="/drills/' + getSportImage(myUSI.userSportInterests[i].sportCodeId) + '" width="50" border="0" ></a>';
  			result += '<br><a href="http://' + sphost + '/drills/' + myUSI.userSportInterests[i].sportName + '/index.jsp" class="sportLink2010">' + myUSI.userSportInterests[i].sportName + '</a>';
  			result += '</div>';
  			result += '</div>';
  			usedUSI[usedUSI.length] = myUSI.userSportInterests[i].sportCodeId;
  			
  		}
  		
  	}

        result+='<div class="clear" ></div>';
        result+='<a href="javascript:startMySports();closeSearchSpPopDrills();" style="font-size:10px;color:#0082AC;">more sports? edit my sports</a>';
        
        result+='<div class="clear" style="border-bottom:1px solid #cccccc;"></div>';
  }else{
		for (var i = 0; i < SL.length; i++)
        {
            result+='<div class="mySportBox">';
             result+='<div class="floatStar">';
            if(SL[i].isMember=='true'){
              result+='<img src="/drills/img/2010/home/starOn.png" width="15" height="15" align="absmiddle">';
              }
            if(SL[i].isMember=='false'){ 
              result+='<img src="/drills/img/2010/home/starOff.png" width="15" height="15" align="absmiddle">';
              }
            result+='</div>';
            result+='<div style="margin-top:7px;text-align:center;">';
            result+='<a href="http://' + sphost + '/drills/' + SL[i].sportName+'/index.jsp" class="sportLinkHome"><img src="/drills/'+getSportImage(SL[i].sportCodeId)+'" width="50" border="0" ></a>';
            result+='<br><a href="http://' + sphost + '/drills/' + SL[i].sportName+'/index.jsp" class="sportLink2010">'+SL[i].sportName+'</a>';
            result+='</div>';
            result+='</div>';
           //  usedUSI[usedUSI.length]=SL[i].sportCodeId;
            
          
        }
	
    }    
        result+=result2;
        result+='<div class="clear" ></div>';
      
      return result;
      }
     return '';
}

function setSessionCountry(countryCode)
{
  var params = 'code=' + countryCode.toLowerCase();
  spAjaxRequest(countrySetReloadPage, '/drills/SetSessionCountry.do;jsessionid=' + jSession, params, '');
}

function countrySetReloadPage(req){
	window.location.reload();
}

