function GotoPage(cntId) {
  if (document.getElementById('SessionId').value != '')
     document.location = 'PageContent?ContentId='+cntId+'&SessionId='+document.getElementById('SessionId').value+'&co=1';
  else
     document.location = 'PageContent?ContentId='+cntId;
}
function GotoMenuPage(mnuId) {
  if (document.getElementById('SessionId').value != '')
     document.location = 'PageContent?MenuId='+mnuId+'&SessionId='+document.getElementById('SessionId').value+'&co=1';
  else
     document.location = 'PageContent?MenuId='+mnuId;
}
function GoHome() {
  document.location = 'PageContent?SiteId='+document.getElementById('thisWebSiteId').value+'&ContentId=-1';
}
function DisplaySection(theSection)
{  
   document.getElementById(theSection).style.display = ''; 
}
function SubmitForm() {
   document.LeagueInfo.CloseUp.value = '1';
   document.LeagueInfo.submit(); 
}
function Cancel() {
  opener.focus();
  window.close();
}
function DoOnLoad() {

}
function setCookie(c_name,value,exdays){
  var exdate=new Date();
  exdate.setDate(exdate.getDate() + exdays);
  var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
  document.cookie=c_name + "=" + c_value;
}
function FindCoach() {
  document.Team.PickPersonId.value='';
  document.Team.PickPersonType.value='CH';
  peopleWin = window.open("FindPerson?SessionId="+document.getElementById('SessionId').value, "FindPeople", "width=700, height=600, toolbar=no, status=yes, dependent=yes, scrollbar=yes, resizable=yes" );
  peopleWin.focus(); 
}
function SortOnHeading(colName) {
  if (BasePageContentURL() == '') {
    document.LeagueInfo.CloseUp.value = '';
    document.LeagueInfo.ColumnSort.value = colName;
    document.LeagueInfo.submit(); 
  }
  else
    document.location = BasePageContentURL()+'&sortOn='+colName;
}
function JumpToPage(pageName) {
   document.LeagueInfo.CloseUp.value = '';
   document.LeagueInfo.GotoPage.value = pageName;
   document.LeagueInfo.submit(); 
}
function BasePageContentURL() {
   var sResult = '';
   if (document.getElementById('thisMenuId') != null) {
      sResult = 'PageContent?';
      var sMenuId = document.getElementById('thisMenuId').value;
      if (sMenuId != '')
         sResult = sResult + 'MenuId='+sMenuId;
      else {
         var sContentId = document.getElementById('thisContentId').value;
         if (sContentId != '')
            sResult = sResult + 'ContentId='+sContentId;
      }		
      if (document.getElementById('SessionId').value != '')
         sResult = sResult + '&SessionId='+document.getElementById('SessionId').value;
   }
   return sResult;
}
function TeamFacilityPick() {
  document.location = BasePageContentURL()+'&gotoFacilityId='+document.getElementById('cbFacilityPick').value;
  setCookie('szsFacility', document.getElementById('cbFacilityPick').value, 60);
}
function JumpToLeaguePage(pageName) {
  if (BasePageContentURL() == '') {
    document.LeagueInfo.CloseUp.value = '';
    document.LeagueInfo.GotoLeaguePage.value = pageName;
    document.LeagueInfo.submit();   
  }
  else
     document.location = BasePageContentURL()+'&gotoPage='+pageName;  
}
function EditPlayer(tpId) {
  playerWin = window.open("EditPlayer?SessionId="+document.getElementById('SessionId').value+"&TeamPlayerId="+tpId, "EditPlayer", "width=700, height=600, toolbar=no, status=yes, dependent=yes, scrollbar=yes, resizable=yes" );
  playerWin.focus(); 
}
function EditGame(gmId) {
  gameWin = window.open("EditGame?SessionId="+document.getElementById('SessionId').value+"&GameId="+gmId, "EditGame", "width=700, height=600, toolbar=no, status=yes, dependent=yes, scrollbar=yes, resizable=yes" );
  gameWin.focus(); 
}
function EditPractice(prId) {
  pracWin = window.open("EditPractice?SessionId="+document.getElementById('SessionId').value+"&PracticeId="+prId, "EditPractice", "width=700, height=600, toolbar=no, status=yes, dependent=yes, scrollbar=yes, resizable=yes" );
  pracWin.focus(); 
}
function EditEvent(teId) {
  eventWin = window.open("EditEvent?SessionId="+document.getElementById('SessionId').value+"&TeamEventId="+teId, "EditEvent", "width=700, height=600, toolbar=no, status=yes, dependent=yes, scrollbar=yes, resizable=yes" );
  eventWin.focus(); 
}
function EditPerson(thePersonId) {
  persWin = window.open("EditPerson?SessionId="+document.getElementById('SessionId').value+"&PersonId="+thePersonId, "EditPerson", "width=700, height=700, toolbar=no, status=yes, dependent=yes, resizable=yes, scrollbars=yes" );
  persWin.focus(); 
}
function ViewProfile(thePersonId) {
  profileWin = window.open("ViewProfile?SessionId="+document.getElementById('SessionId').value+"&PersonId="+thePersonId, "IndProfile", "screenX=100, screenY=300, width=400, height=250, toolbar=no, status=yes, dependent=yes, scrollbar=yes, resizable=yes" );
  profileWin.focus(); 
}
function PresentProgram(theProgId) {
  document.LeagueInfo.GotoProgram.value=theProgId;
  document.LeagueInfo.submit(); 
}
function PresentSeason(theSeasonId) {
  document.LeagueInfo.GotoSeason.value=theSeasonId;
  document.LeagueInfo.submit(); 
}  
function PresentDivGroup(theGroupId) {
  document.LeagueInfo.GotoDivGroup.value=theGroupId;
  document.LeagueInfo.submit(); 
}
function PresentDivision(theDivisionId) {
  document.LeagueInfo.GotoDivision.value=theDivisionId;
  document.LeagueInfo.submit(); 
}
function PresentTeam(theTeamId) {
  teamWin = window.open('TeamSite?TeamId='+theTeamId, "TeamProfile", "screenX=100, screenY=150, width=900, height=700, toolbar=no, status=yes, dependent=yes, scrollbars=yes, resizable=yes" );
  teamWin.focus(); 
}
function PresentFacility(theFacilityId) {
  teamWin = window.open('TeamSite?TeamId='+theTeamId, "TeamProfile", "screenX=100, screenY=150, width=900, height=700, toolbar=no, status=yes, dependent=yes, scrollbars=yes, resizable=yes" );
  teamWin.focus(); 
}
function EditTeam(theTeamId) {
  document.location = 'EditTeam?SessionId='+document.getElementById('SessionId').value+'&TeamId='+theTeamId;
}
function GotoTeamStats(theTeamId) {
  document.LeagueInfo.StatsTeamId.value = theTeamId;
  document.LeagueInfo.submit();
}
function ChangeStandingsView() {
  document.location = BasePageContentURL()+'&ViewStandings='+document.getElementById('cbViewStandings').value;
}
function ChangeSeason() {
  document.location = BasePageContentURL()+'&ViewSeason='+document.getElementById('cbSeason').value;
}
function GetGameSheet(gameId) {
  var sURL = 'OpenGameSheet?SessionId='+document.getElementById('SessionId').value+'&GameId='+gameId;
  gasWin = window.open(sURL, "GameSheetSummary", "screenX=100, screenY=100, width=860, height=700, toolbar=no, status=yes, dependent=yes, scrollbars=yes, resizable=yes" );
  gasWin.focus(); 
}
function CheckIsIE() { 
  if (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER') { return true;} 
  else { return false; } 
} 
function PrintThisPage() { 
  if (CheckIsIE() == true) { 
    if (document.ifWorkspace) {
       document.ifWorkspace.focus(); 
       document.ifWorkspace.print(); 
	} else
	   window.print();   
  } else { 
     if (window.frames['ifWorkspace']) {
        window.frames['ifWorkspace'].focus(); 
        window.frames['ifWorkspace'].print();
     } else
	   window.print();		
  }
} 
function PagePasswordLogin() {
  document.location = BasePageContentURL() + '&pagepw=' + document.getElementById('pagePassword').value;
}
function tableRowsToCSV(theRows) {
	var csv = "";
	var csvRow = "";
	var theCells;
	var cellData = '';
	for (var r=0;r<theRows.length;r++) {
	  theCells = theRows.item(r).cells;
	  for (var c=0;c<theCells.length;c++) {
	    cellData = '';
	    cellData = theCells.item(c).innerHTML;
		<!-- alert(c + ',' + r + ' = ' + cellData); -->
		if (cellData) {
	       if (cellData.indexOf(",") != -1) 
		      cellData = "'"+cellData+"'";
	       if (cellData != "") 
		      csvRow += ","+cellData;
		} else
		  csvRow += ","+cellData;
	  }
	  if (csvRow != "") 
	     csvRow = csvRow.substring(1,csvRow.length);
	  csv += csvRow+"\n";
	  csvRow = "";
	}
	return csv;
}
function ExportTable(toTableName, exportAs) {
    var theTable, theTableBody;
    theTable = document.getElementById(toTableName);
    theTableBody = theTable.tBodies[0];
	alert('Exporting table ' + toTableName);
	var csvText = tableRowsToCSV(theTable.rows);
	csvText += tableRowsToCSV(theTableBody.rows);
	//open the iframe doc for writing
	var expIFrame;
	var doc = window.document;
	doc.open('text/plain','replace');
	doc.charset = "utf-8";
	doc.write(csvText);
	doc.close();
	var fileName = 'c:\\Apps\\' + exportAs + '.csv';
	doc.execCommand("SaveAs", null, fileName);
	alert('Table exported to ' + fileName);
}



