/**
 * All dates chessclub Rhy Rheinfelden
 * Model
 * Author: H. Kortschak
 * Date: 2. 4. 2011
 * Version: 2.0
 */


var DATECTRL = 0;
var DATEDISP = 1;
var DATEINFO = 2;

// keys below are deprecated, use DATEXXX keys above
var KEY  = 0;
var DATE = 1;
var INFO = 2;
var RESULT = 3;
var nTournaments = 12;

var FREE     = "Freier Spielbetrieb/Nachspielrunden";
var auswaerts = ", auswärts";

var WPTEXT = "Runde Wanderpreis";
var WPNRUNDE = "WP  Nachspielrunde";
var TCTEXT = "Runde";
var TRAINING = "19.30 - 20.30, Moderation ";


var CATEGORY_VM   = "Meisterschaft";
var CATEGORY_WP   = "WPT";
var CATEGORY_RAPID = "Rapid, HC, Blitz";
var CATEGORY_SGM1 = "SGM 1";
var CATEGORY_SGM2 = "SGM 2";
var CATEGORY_SMM  = "SMM";     
var CATEGORY_NMM  = "NMM";
var CATEGORY_VEREIN   = "Verein";
var CATEGORY_TRAINING = "Training";
var CATEGORY_FREEPLAY = "Spielen";
var CATEGORY_TEAMCUP  = "Teamcup";
var CATEGORY_REGION   = "Region";

var YEAR = 2012; // adjust it manually, not before the contents of the agenda changed. 
var LYEAR = YEAR - 1;
var NYEAR = YEAR + 1;

SGM_Rhy1 = [[0, "28. 01. 2012", "4. Runde Riehen 3"],
	    [0, "18. 02. 2012", "5. Runde Therwil 2" + auswaerts],
	    [0, "03. 03. 2012", "6. Runde Basel SG 2"],
	    [0, "24. 03. 2012", "7. Runde spielfrei " ]];

SGM_Rhy2 = [[0, "28. 01. 2012", "4. Runde Birseck 2"],
	    [0, "18. 02. 2012", "5. Runde Freiamt 2" + auswaerts],
	    [0, "03. 03. 2012", "6. Runde Züri Letzi"],
	    [0, "24. 03. 2012", "7. Runde Döttingen-Klingnau" + auswaerts]];

SMM_Rhy  = [[0, "13. 03. 2012", "1. Runde Basel" + auswaerts],
	    [0, "10. 04. 2012", "2. Runde Riehen"],
	    [0, "23. 04. 2012", "3. Runde Olten" + auswaerts],
	    [0, "29. 05. 2012", "4. Runde Zofingen" + auswaerts],
	    [0, "22. 06. 2012", "5. Runde Birseck" + auswaerts],
	    [0, "21. 08. 2012", "6. Runde Muttenz"],
	    [0, "18. 09. 2012", "7. Runde Novartis"]];

NMM_Rhy  = [[0, "05. 03. 2012", "5. Runde Gundeldingen" + auswaerts]];

Verein_Rhy = [
	      [0, "24. 01. 2012", "Generalversammlung, Spiellokal 19:30h"]];

VM_Rhy = [[0, "14. 02. 2012", "Start Vereinsturnier Fischermodus!"],
	  [0, "06. 03. 2012", "2. Runde"],
	  [0, "27. 03. 2012", "3. Runde"],
	  [0, "17. 04. 2012", "4. Runde"],
	  [0, "08. 05. 2012", "5. Runde"],
	  [0, "05. 06. 2012", "6. Runde"],
	  [0, "26. 06. 2012", "7. Runde"],
	  [0, "17. 07. 2012", "8. Runde"],
	  [0, "07. 08. 2012", "9. Runde"],
	  [0, "28. 08. 2012", "10. Runde"],
	  [0, "25. 09. 2012", "11. Runde"],
	  [0, "16. 10. 2012", "12. Runde"],
	  [0, "06. 11. 2012", "13. Runde"],
	  [0, "27. 11. 2012", "14. Runde"],
	  [0, "18. 12. 2012", "15. Runde"]];

WP_Rhy = [[0, "", ""] ];

Rapid_Rhy = [[0, "31. 01. 2012", "Rapid 4"],
	     [0, "07 .02. 2012", "Rapid 5"],
	     [0, "28. 02. 2012", "Rapid 6"],
	     [0, "20. 03. 2012", "Rapid 7"],
	     [0, "03. 04. 2012", "Blitz 1"],
	     [0, "24. 04. 2012", "Handicap 1"],
	     [0, "22. 05. 2012", "Handicap 2"],
	     [0, "12. 06. 2012", "Blitz 2"],
	     [0, "10. 07. 2012", "Handicap 3"],
	     [0, "11. 09. 2012", "Blitz 3"],
	     [0, "04. 12. 2012", "Blitz 4 (Samichlaus)"]];

/*
 * Non displayable table for result page control.
 */
WP_Tech =  [[0, "16. 08. 2011"],
	    [0, "13. 09. 2011"],
	    [0, "04. 10. 2011"],
	    [0, "25. 10. 2011"],
	    [0, "15. 11. 2011"],
	    [0, "20. 12. 2011"],
	    [0, "17. 01. 2012"]];

Training_Rhy = [[0, "", "", "", ""]];

FreePlay_Rhy = [[0, "03. 01. 2012", FREE, "", ""]];

Teamcup_Rhy = [[0, "", "4. " + TCTEXT, "", ""]];

Region_Rhy = [[0, "", ""]];
	 

/**
   The function calculates date values from the strings found in scheduleTable[i][DATEDISP],
   adds the numeric value of one day and assigns the values to scheduleTable[i][DATECTRL]. 
   These values serves as control element in order to update the next date view on the home page.
   Date ranges of the form "01. 01. 2010 - 05.01.2010" are supported. 
   The dash is the token so as to parse the end date of the range.
   Contains the cell scheduleTable[i][DATECTRL] a value other than 0 then no date is assigned.
 */
function calcDateCTRL( scheduleTable ){
  var date = new Date();

  for( var i = 0; i < scheduleTable.length; ++i ){
    if( scheduleTable[i][DATECTRL] == 0 && scheduleTable[i][DATEDISP] != "" ){
      var ds = (scheduleTable[i][DATEDISP]).split("-"); // split date range if available
      if( ds.length > 1 ) {
	ds = ds[1].split("."); // split date into day, month and year
      } else {
	ds = (scheduleTable[i][DATEDISP]).split("."); // split date into day, month and year
      }
      var d = new Date(ds[2],ds[1]-1,ds[0],0,0,0,0);
      scheduleTable[i][DATECTRL] = d.getTime() + (1000 * 60 * 60 * 24);  // add the numeric value of one day
    }
  }

}

// feed actual dates to tables
function initDateTables(){
  calcDateCTRL( SGM_Rhy1 );
  calcDateCTRL( SGM_Rhy2 );
  calcDateCTRL( SMM_Rhy );
  calcDateCTRL( NMM_Rhy );
  calcDateCTRL( Verein_Rhy );
  calcDateCTRL( VM_Rhy );
  calcDateCTRL( WP_Rhy );
  calcDateCTRL( Rapid_Rhy );
  calcDateCTRL( Training_Rhy);
  calcDateCTRL( FreePlay_Rhy );
  calcDateCTRL( Teamcup_Rhy );
  calcDateCTRL( Region_Rhy );
}

////// main /////
initDateTables();

