// Fixlist Version 4.0
// Copyright (c) 2001
// Phil Davison
// http://www.cyclops.force9.co.uk/fixture list/index.htm
//
// 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 resleaguefix, below, are set out as follows...
//	new Array("Opponent", "home date", "away date", "end of hyperlink")

resleaguefix = new Array(	
new Array("AFC Hornchurch", "25/04/12", "18/08/11", ""),
new Array("Billericay Town", "18/01/12", "31/08/11", ""),
new Array("Braintree Town", "11/04/12", "18/04/12", ""),
new Array("Brentwood Town", "21/03/12", "28/09/11", ""),
new Array("Chelmsford City","23/11/11", "14/12/10", ""),
new Array("Cheshunt","04/04/12", "15/02/11", ""),
new Array("Ebbsfleet Utd", "07/03/12", "14/09/11", ""),
new Array("Enfield (1893)","28/03/12", "01/02/11", ""),
new Array("Harlow Town","14/03/12", "22/02/12", ""),
new Array("Potters Bar Town", "04/01/12", "11/01/12", "")
 
  )
//


// Data for other fixtures
//
resotherfix = new Array(

new Array("Park View", "H", "20/11/08", "MPC2", ""),
new Array("Wealdstone", "H", "15/02/12", "PC4", ""),
new Array("Goffs Oak (7.15pm)", "New River", "28/07/11", "Fr", ""),
new Array("Tokyngton Manor", "a", "03/08/11", "Fr", ""),
new Array("Cockfosters", "a", "30/07/11", "Fr", ""),
new Array("Sandridge Rovers", "a", "09/08/11", "Fr", "")

   )
//

// Initialise some variables
//
reslge = "CL"			// how you want the league name shown
now = new Date			// the current date
i = 0				// loop variable
ii = 0				// increment variable within loop
leaguer = resleaguefix.length	// no of league opponents
otherr = resotherfix.length		// no of other games
gamesr = (leaguer * 2) + otherr 	// total number of games
tempresteam = ""			// }
tempvenr = ""			// } for use in
tempcompr = ""			// } bubble sort
tempresdate = new Date		// }
templinkr = ""			// }
//

// Define arrays
//
resteam = new Array()	// teams (league and other)
venuer = new Array()	// venue (by default "home", "away" or "neutral" but user definable)
resmd = new Array ()	// match date as a string
mresdate = new Array()	// match date in date format
compr = new Array()	// competition
mlinkr = new Array()	// link to website

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<leaguer; i++) {
  resteam[ii] = resleaguefix[i][0]
  venuer[ii] = "H"		// if you want to show the venue another way, change it here
  resmd[ii] = resleaguefix[i][1]

	yr = resmd[ii].split("/") [2]
	yr = Math.floor(yr)
	yr = Math.floor(yr+2000)
	mth = Math.floor(resmd[ii].split("/") [1])
	dy = Math.floor(resmd[ii].split("/") [0])
	mresdate[ii] = new Date(yr, mth-1, dy)


  compr[ii] = reslge		// if you want to show the competition another way, change it above
  if(resleaguefix[i][3]!="") {
    mlinkr[ii] = URL+resleaguefix[i][3]
  } else {
    mlinkr[ii] = ""
  }
  ii++

  resteam[ii] = resleaguefix[i][0]
  venuer[ii] = "a"		// if you want to show the venue another way, change it here
  resmd[ii] = resleaguefix[i][2]

	yr = resmd[ii].split("/") [2]
	yr = Math.floor(yr)
	yr = Math.floor(yr+2000)
	mth = Math.floor(resmd[ii].split("/") [1])
	dy = Math.floor(resmd[ii].split("/") [0])
	mresdate[ii] = new Date(yr, mth-1, dy)

  compr[ii] = reslge		// if you want to show the competition another way, change it above
  if(resleaguefix[i][3]!="") {
    mlinkr[ii] = URL+resleaguefix[i][3]
  } else {
    mlinkr[ii] = ""
  }
  ii++

}
//
// loop to put other games into array
//


for(i=ii; i<gamesr; i++) {
  resteam[i] = resotherfix[i-ii][0] 
  venuer[i] = resotherfix[i-ii][1]	  // the venue will be shown as you put it in the array above
  resmd[i] = resotherfix[i-ii][2]

	yr = resmd[i].split("/") [2]
	yr = Math.floor(yr)
	yr = Math.floor(yr+2000)
	mth = Math.floor(resmd[i].split("/") [1])
	dy = Math.floor(resmd[i].split("/") [0])
	mresdate[i] = new Date(yr, mth-1, dy)

  compr[i] = resotherfix[i-ii][3]	  // the competition will be shown as you put it in the array above
  
  if(resotherfix[i-ii][4]!="") {
    mlinkr[i] = URL+resotherfix[i-ii][4]
  } else {
    mlinkr[i] = ""
  }
}
//
// Bubble sort
//
for(i=0; i<gamesr; i++) {
  for(ii=i; ii<gamesr; ii++) {
    if(mresdate[i] > mresdate[ii]) {
      tempresdate = mresdate[i]
      tempresmd = resmd[i]
      tempresteam = resteam[i]
      tempvenr = venuer[i]
      tempcompr = compr[i]
      templinkr = mlinkr[i]
      mresdate[i] = mresdate[ii]
      resmd[i] = resmd[ii]
      resteam[i] = resteam[ii]
      venuer[i] = venuer[ii]
      compr[i] = compr[ii]
      mlinkr[i] = mlinkr[ii]
      mresdate[ii] = tempresdate
      resmd[ii] = tempresmd
      resteam[ii] = tempresteam
      venuer[ii] = tempvenr
      compr[ii] = tempcompr
      mlinkr[ii] = templinkr
    }
  }
}


//
// 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<gamesr; i++) {
  mnumr = Math.floor(mresdate[i])
  if(mresdate[i].getDay() == 6 || mresdate[i].getDay() == 0) {
    mnumr = mnumr + 61200000
  } else {
    mnumr = mnumr + 75600000
  }
  mresdate[i] = new Date(mnumr)
}
//

// Is the game today or later?
//

nresteam = new Array()	// }
nvenr = new Array()	// } used for comparing
ndr = new Array ()	// } match date with today
nresdate = new Array()	// }
ncompr = new Array()	// }
nlinkr = new Array()	// }


ii=0
for(i=0; i<gamesr; i++) {
  if(mresdate[i] >= now) {
    nresdate[ii] = mresdate[i]
    nresteam[ii] = resteam[i]
    nvenr[ii] = venuer[i]
    ncompr[ii] = compr[i]
    nlinkr[ii] = mlinkr[i]
    ii++
  }
}

