// Fixlist Version 4.3
// Copyright (c) 1998-2010
// Phil Davison
// http://www.phildavison.ukpc.net/fixlist/
//
// This copyright message must be retained. Please make sure you read the
// software licence


// Data for league fixtures
//

URL = "index.php?page="		// first part of web links

//  the arrays within leaguefix, below, are set out as follows...
//	new Array("Opponent", "home date", "away date", "end of hyperlink")

leaguefix = new Array(	


new Array("AFC Sudbury", "03/03/12","", "12/11/11","", "sudburyinfo"),
new Array("Brentwood Town", "14/01/12","", "27/09/11","", "brentwoodinfo"), 
new Array("Chatham Town", "21/02/12","", "19/11/11","", "chathaminfo"),
new Array("Cheshunt", "24/09/11","", "14/04/12","", "cheshuntinfo"), 
new Array("Grays Athletic", "03/12/11","", "28/04/12","", "graysinfo"), 
new Array("Great Wakering Rovers", "28/01/12","", "15/10/11","", "wakeringinfo"), 
new Array("Harlow Town", "31/03/12","", "13/09/11","", "harlowinfo"),
new Array("Heybridge Swifts", "18/02/12","", "29/10/11","", "heybridgeinfo"),
new Array("Ilford", "17/03/12","", "20/08/11","", "ilfordinfo"), 
new Array("Leiston", "21/04/12","", "10/12/11","", "leistoninfo"), 
new Array("Maldon &amp; Tiptree", "27/08/11","", "24/03/12","", "maldoninfo"), 
new Array("Needham Market", "10/09/11","", "07/04/12","", "needhammarketinfo"),
new Array("Potters Bar Town", "04/10/11","", "21/01/12","", "pottersbarinfo"), 
new Array("Redbridge", "02/01/12","3.00pm", "29/08/11","3.00pm", "redbridgeinfo"), 
new Array("Romford", "01/10/11","", "07/01/12","", "romfordinfo"), 
new Array("Soham Town Rangers", "26/11/11","", "11/02/11","", "sohaminfo"), 
new Array("Thamesmead Town", "17/12/11","", "20/09/11","", "thamesmeadinfo"),
new Array("Tilbury", "23/08/11","", "31/12/11","1.00pm", "tilburyinfo"), 
new Array("Waltham Abbey", "09/04/12","", "26/12/11","3.00pm", "walthamabbeyinfo"), 
new Array("Waltham Forest", "29/11/11","", "25/02/12","", "walthamforestinfo"), 
new Array("Ware", "05/11/11","","10/03/12","", "wareinfo")

   )
//


// Data for other fixtures
//
otherfix = new Array(

new Array("Harefield United", "H", "09/11/11","", "MSC1", ""),
new Array("AFC Sudbury", "H", "14/11/11","", "LC3", "sudburyinfo"),
new Array("Chertsey Town", "a", "02/08/11","", "Fr", "chertseyinfo"),
new Array("Enfield (1893)", "H", "02/03/11","", "MCC1", ""),
new Array("Colney Heath", "a", "29/07/10","", "Fr", "colneyheathinfo"),
new Array("Thamesmead Town", "a", "22/10/11","", "FAT1q", "thamesmeadinfo"),
new Array("Potters Bar Town", "a", "12/10/10","", "CMC2", "pottersbarinfo"),

new Array("Stotfold", "a", "03/09/11","", "FACp", "stotfoldinfo"),
new Array("Tottenham Hotspur XI", "H", "16/11/11","7.30pm", "Fr", "spursinfo"),
new Array("North Greenford United", "a", "31/01/12","", "MCC2", "northgreenfordinfo"),
new Array("Lowestoft Town", "a", "23/07/11","", "Fr", "lowestoftinfo"),
new Array("East Thurrock United", "a", "16/08/11","", "Fr", "eastthurrockinfo"),
new Array("Hertford Town", "a", "26/07/11","", "Fr", "hertfordinfo"),
new Array("Chalfont St Peter", "a", "06/08/11","", "Fr", "chalfontinfo"),
new Array("Wealdstone", "H", "06/12/11","", "MSC2", "wealdstoneinfo"),
new Array("Worthing", "H", "26/09/10","", "FAC 2q", ""),
new Array("Met Police (Bushey)", "a", "27/07/10","6.30pm", "Fr", "metpolbusheyinfo")

   )
//

// Initialise some variables
//
lge = "RL1N"			// how you want the league name shown
now = new Date			// the current date
i = 0				// loop variable
ii = 0				// increment variable within loop
league = leaguefix.length	// no of league opponents
other = otherfix.length		// no of other games
games = (league * 2) + other 	// total number of games
wdayko = "7.45pm"		// default midweek kick off time
wendko = "3.00pm"		// default weekend kick off time
tempteam = ""			// }
tempven = ""			// }
tempcomp = ""			// } for use in
tempdate = new Date		// } bubble sort
tempko = ""			// }
templink = ""			// }
//

// Define arrays
//
team = new Array()	// teams (league and other)
venue = new Array()	// venue (by default "home", "away" or "neutral" but user definable)
md = new Array ()	// match date as a string
mdate = new Array()	// match date in date format
mko = new Array()	// match kick off time
comp = new Array()	// competition
mlink = new Array()	// link to website
nteam = new Array()	// }
nven = new Array()	// } used for comparing
nd = new Array ()	// } match date with today
ndate = new Array()	// }
nko = new Array()	// }
ncomp = new Array()	// }
nlink = new Array()	// }

dday = new Array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
dmon = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")

//
// loop to put league games into array
//
ii=0
for(i=0; i<league; i++) {
  team[ii] = leaguefix[i][0]
  venue[ii] = "H"		// if you want to show the venue another way, change it here
  md[ii] = leaguefix[i][1]

	yr = md[ii].split("/") [2]
	yr = Math.floor(yr)
	yr = Math.floor(yr+2000)
	mth = Math.floor(md[ii].split("/") [1])
	dy = Math.floor(md[ii].split("/") [0])
	mdate[ii] = new Date(yr, mth-1, dy)
  mko[ii] = leaguefix[i][2]


  comp[ii] = lge		// if you want to show the competition another way, change it above
  if(leaguefix[i][3]!="") {
    mlink[ii] = URL+leaguefix[i][5]
  } else {
    mlink[ii] = ""
  }
  ii++

  team[ii] = leaguefix[i][0]
  venue[ii] = "a"		// if you want to show the venue another way, change it here
  md[ii] = leaguefix[i][3]

	yr = md[ii].split("/") [2]
	yr = Math.floor(yr)
	yr = Math.floor(yr+2000)
	mth = Math.floor(md[ii].split("/") [1])
	dy = Math.floor(md[ii].split("/") [0])
	mdate[ii] = new Date(yr, mth-1, dy)
  mko[ii] = leaguefix[i][4]

  comp[ii] = lge		// if you want to show the competition another way, change it above
  if(leaguefix[i][5]!="") {
    mlink[ii] = URL+leaguefix[i][5]
  } else {
    mlink[ii] = ""
  }
  ii++

}
//


// loop to put other games into array
//

for(i=ii; i<games; i++) {
  team[i] = otherfix[i-ii][0]
  venue[i] = otherfix[i-ii][1]	  // the venue will be shown as you put it in the array above
  md[i] = otherfix[i-ii][2]

	yr = md[i].split("/") [2]
	yr = Math.floor(yr)
	yr = Math.floor(yr+2000)
	mth = Math.floor(md[i].split("/") [1])
	dy = Math.floor(md[i].split("/") [0])
	mdate[i] = new Date(yr, mth-1, dy)
  mko[i] = otherfix[i-ii][3]
  comp[i] = otherfix[i-ii][4]	  // the competition will be shown as you put it in the array above

  if(otherfix[i-ii][5]!="") {
    mlink[i] = URL+otherfix[i-ii][5]
  } else {
    mlink[i] = ""
  }
}
//
// Bubble sort
//
for(i=0; i<games; i++) {
  for(ii=i; ii<games; ii++) {
    if(mdate[i] > mdate[ii]) {
      tempdate = mdate[i]
      tempmd = md[i]
      tempko = mko[i]
      tempteam = team[i]
      tempven = venue[i]
      tempcomp = comp[i]
      templink = mlink[i]
      mdate[i] = mdate[ii]
      md[i] = md[ii]
      mko[i] = mko[ii]
      team[i] = team[ii]
      venue[i] = venue[ii]
      comp[i] = comp[ii]
      mlink[i] = mlink[ii]
      mdate[ii] = tempdate
      md[ii] = tempmd
      mko[ii] = tempko
      team[ii] = tempteam
      venue[ii] = tempven
      comp[ii] = tempcomp
      mlink[ii] = templink
    }
  }
}


//
// Change the check time for weekends or weekdays
// NB: Bank holiday Mondays will be treated as ordinary weekdays and updated at 9pm
//

for(i=0; i<games; i++) {
  mnum = Math.floor(mdate[i])
  if(mdate[i].getDay() == 6 || mdate[i].getDay() == 0) {
    mnum = mnum + 61200000
    if(mko[i].length == 0) {
      mko[i] = wendko
    }
  } else {
    mnum = mnum + 75600000
    if(mko[i].length == 0) {
      mko[i] = wdayko
    }
  }
  mdate[i] = new Date(mnum)
}

//

// Is the game today or later?
//
ii=0
for(i=0; i<games; i++) {
  if(mdate[i] >= now) {
    ndate[ii] = mdate[i]
    nko[ii] = mko[i]
    nteam[ii] = team[i]
    nven[ii] = venue[i]
    ncomp[ii] = comp[i]
    nlink[ii] = mlink[i]
    ii++
  }
}

