// MISCELLANEOUS FUNCTIONS (STORED PROCEDURES)
// sp_misc.js
// NB: NEEDS database.js

// :: FUNCTIONS
// f_rtnOfficialLinks() - RTNS LINKS TO BDBA AND RDG WEBSITES
// f_rtnSeasonLinks(HRef,CurID,ShowAll,SubDir) - DISPLAY LINKS TO OTHER SEASONS (VERTICAL)
// f_rtnSectionLinks(SeasonID) - DISPLAYS LINKS TO OTHER SEASON SECTIONS (HORIZ)

// RTNS LINKS TO BDBA AND RDG (OFFICIAL) WEBSITES TO GET AT RESULTS
// NB: Does not require other .js units
// *** NOT USED ANYMORE SINCE WORDS VARY ON PAGES ***
function f_rtnOfficialLinks() {
	var t = '<p>Check out the <a href="/matches/tables.php">Summary Page</a> for a table of all the teams and how many matches have been won, lost and drawn etc.  See also the <a href="/links/framed.php?url=http://www.bdba.co.uk/tables.php">results tables on the BDBA website</a> and the <a href="/links/framed.php?url=http://www.reading-badminton.org.uk/LeagueStandings.php">current league standings on the Reading League website</a> for an idea of how we are doing, or have done, in the leagues.</p>';
	return t;	
}

// DISPLAY LINKS TO OTHER SEASONS, CURRENT SEASON IS NOT SELECTABLE
// CurID - CURRENT SEASON ID
// ShowAll - true/false - SHOW THE 'ALL SEASONS BTN'?
// SubDir - FILE IS IN SEASON SUB DIRECTORY (ie 0102/notes.html), AS OPPOSED TO (teams.html?0102)
function f_rtnSeasonLinks(HRef,CurID,ShowAll,SubDir) {
  var t, i, fields, desc;

  // INIT
  if (typeof(SubDir) == 'undefined') SubDir = false;
  t = '<DIV>Other Seasons...';

  // STEP THROUGH SEASONS
  // NB: 'All Seasons' IS FIRST IN LIST
  for (i=0; i<SeasonArr.length; i++) {
    fields = SeasonArr[i].split(',');

    if ((i == 0) && (!ShowAll)) {
      continue;
    }

    // NEED TO CHOP OFF 'Season ' FROM i=1..
    // OTHERWISE DOES NOT FIT ON BTN FACE!
    desc = fields[1];
    if (i > 0) {
      desc = desc.substring(7);
    }

    t += '<DIV CLASS="btn">';
    if (fields[0] != CurID) {
      if (SubDir) {
        t += '<A HREF="/matches/' + fields[0] + '/' + HRef + '">' + desc + '</A>';
      } else {
        t += '<A HREF="' + HRef + '?' + fields[0] + '">' + desc + '</A>';
      }
    } else {
      t += '<B>' + desc + '</B>';
    }
    t += '</DIV>';
  }

  t += '</DIV>';

  return t;
}

// RTN LINE OF BTNS TO LINK TO...
// FIXTURES / RESULTS / REPORTS / TABLES / TEAMS
// Force - true/false DISPLAY LINKS FOR CURRENT SEASON (DEFAULT false)
// TxtOnly - true/false (DEFAULT false) Displays links as plain text
function f_rtnSectionLinks(SeasonID,Force,TxtOnly) {
  var t, all, season, fn, h, i;
  var sections = new Array('Notes','Fixtures','Results','Reports','Tables','Teams');

  // INIT
  t = '';
  all = '';
  if (typeof(Force) == 'undefined') Force = false;
  if (typeof(TxtOnly) == 'undefined') TxtOnly = false;	
  season = f_getSeason(SeasonID);

  // IF CURRENT SEASON, THEN RETURN
  if ((!Force) && (SeasonID == f_getCurrentSeasonID())) return '';

  // NB: _ALL DEFINED IN database.js
  if (SeasonID == _ALL) all = 'All ';

  // EXTRACT NAME OF FILE FROM .href (WITHOUT .html)
  h = location.href;
  fn = h.substring((h.lastIndexOf('/') + 1),(h.indexOf('.')));

	if (!TxtOnly) {
	  t += '<DIV STYLE="margin:0;padding:0;margin-bottom:15px;border:1px solid #000000">';
	  t += '<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0 BORDERCOLOR="#000000"';
		t += ' style="';
		t += 'width:100%;';
		t += 'background-color:#cccc99;';
		t += 'border:2px solid #999966;';	// form.options
		t += 'border-top-color:#FFFFCC;';
		t += 'border-left-color:#FFFFCC;';
		t += '"><tr>';
	}	
  for (i=0; i<sections.length; i++) {
    // ALL - NO NOTES or TEAMS
    if ((SeasonID == _ALL) && ((i == 0) || (i == 5))) continue;
    if (!TxtOnly) {
			t += '<TD><DIV CLASS="btn" STYLE="width:90px;">';
		} else if (t > ' ') {
			t += ' | ';
		}
    // DON'T LINK TO CURRENT FILE
    if (sections[i].toLowerCase() != fn) {
      t += '<A';
			if (!TxtOnly) { t += ' STYLE="width:88px;"'; }
			t += ' TITLE="' + season + '" HREF="/matches/';
      if (i == 0) {
        t += SeasonID + '/' + sections[i].toLowerCase() + '.html';
      } else {
        t += sections[i].toLowerCase() + '.html?' + SeasonID;
      }
      t += '">';
    }
    if (i != 4) t += all;	// TABLES
    t += sections[i];
    if (sections[i].toLowerCase() != fn) t += '</A>';
    if (!TxtOnly) { t += '</DIV></TD>'; }
  }
	if (!TxtOnly) {
	  t += '</TR></TABLE>';
	  t += '</DIV>';
	}

  return t;
}
