// schedule.js JavaScript file
// Updated on Feb-22-09
//
// function StringArray(n)
//       Tom Holden 4-1-2007
// This function is used to create a multi-element array
//
//  n - The number of elements
//

function StringArray (n) {
  this.length = n;
  for (var i =1; i <= n; i++) {
    this[i] = ' '
  }
}

//
// function schedule(j,type,ahead)
//       Tom Holden 4-1-2007
// This function is used to produce the rows of the requested table type
// This can be used to produce the signup pages or the regular schedule
// The data base of the year is here - but eventually this should be in the database!!
// Also the Google Buy Now buttons are here as they must be manually generated
//
//  j         Current index into the season array - probably could be local!!! 
//
//  type      Description
//   0        This the current sign-up list with only the next 60 days
//   1        This is the complete schedule with no payment buttons
//   2        This is the remaining schedule with only the cart payment buttons
//   3        This is the membership purchase page
//  ahead     This tells the function to look at the entire schedule if it is not 0
//

function schedule(j,type,ahead) {

var currentdate = 0;
var startdate = 0;
currentdate = new Date();

course = new StringArray(26);
itemno = new StringArray(26);
signup = new StringArray(26);
play = new StringArray(26);
cost = new StringArray(26);
specsgn = new StringArray(26);
membership = new StringArray(7);
memitem = new StringArray(7);
deadline = new StringArray(7);

// Fields for tournaments - this needs to be converted to the real database soon

course = ["","Santa Clara","Metropolitan","Poppy Hills","Paradise Valley", "Rancho Solano","San Juan Oaks","San Juan Oaks + CC","Club Championship", "Summitpointe","Coyote Moon","Old Greenwood","Roddy Ranch","Laguna Seca","Sunol Valley","San Juan Oaks","Monarch Bay","Silver Creek","Poppy Hills","Bodega Harbor","Bodega Harbor","Tilden Park","Hiddenbrooke","San Jose Muni","Pajaro Valley",  "Los Lagos"]
itemno = ["",      "200901",     "200902",       "200903",        "200904",     "200905",     "200906",             "200906+CC",               "CC",       "200907",     "200908",       "200909",     "200910",     "200911",     "200912",       "200811",     "200812",      "200813",     "200814",       "200815",       "200816",     "200817",      "200818",       "200819",       "200820",     "200821"]
signup = ["", "22 FEB 2009","06 MAR 2009",     "22 FEB 2009",   "26 MAR 2009","26 MAR 2009","16 APR 2009",       "16 APR 2009",       "16 APR 2009",  "29 APR 2009","21 APR 2009",  "21 APR 2009","29 MAY 2009","13 JUN 2009","25 JUN 2009",  "20 JUN 2008","11 JUL 2008", "25 JUL 2008","02 JUL 2008",  "15 AUG 2008",  "15 AUG 2008","29 AUG 2008", "05 SEP 2008",  "19 SEP 2008",  "03 OCT 2008","17 OCT 2008"]
play   = ["", "08 MAR 2009","22 MAR 2009",     "04 APR 2009",   "18 APR 2009","19 APR 2009","02 MAY 2009",       "02 MAY 2009",       "02 MAY 2009",  "16 MAY 2009","30 MAY 2009",  "31 MAY 2009","13 JUN 2009","28 JUN 2009","12 JUL 2009",  "12 JUL 2008","26 JUL 2008", "07 AUG 2008","17 AUG 2008",  "30 AUG 2008",  "31 AUG 2008","13 SEP 2008", "28 SEP 2008",  "11 OCT 2008",  "25 OCT 2008","08 NOV 2008"]
cost   = [0,70,63,83,73,73,81,91,10,60,108,108,65,51,66,51,76,74,80,81,62,58,71,67,71,67,71,51]
// Any extra days needed for sign up
specsgn= [0, 0, 0,15, 0, 0, 0, 0, 0, 0, 10, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

// Fields for Membership signup
membership = ["","2010 Renewal","2010 Renewal NSC","2010 Club Transfer","2010 Club Transfer NSC","2010 New Member","2010 New Member NSC"]
memitem = [0,56,46,56,46,66,56]
deadline = ["","14 DEC 2009","14 DEC 2009",   "13 DEC 2010",        "13 DEC 2010",   "13 DEC 2010","13 DEC 2010"]



//        0  1  2  3  4  5  6                              7                              8                              9                              10                             11                             12                             13                             14                             15                             16                             17                             18                            

startdate = currentdate;
playdate = new Date(play[j]);
signupdate = new Date(signup[j]);
signupdate.setHours(23);
signupdate.setMinutes(59);

today = new Date();
//	document.write(type);

//if (type==0 || type==1 || type==2) {
if (type==0 || type==1 || type==2) {

  if (ahead==0) {
     if(  ((startdate.setDate(startdate.getDate()+50+specsgn[j])) >= new Date(play[j])) && ( new Date() < new Date(play[j]) )  ) {

	document.write('<tr><td width="103" height="35" align="center"><font color="#000000">');
		if(today > signupdate) {
//		document.write(today.getDate());
//		document.write(playdate.getDate());
//		document.write(playdate.getDate()-4);
// If the current date is after the signup deadline put the "Waitlist" banner in the grid, if the playdate is within 4 days change to "Contact Officers" from "Waitlist"
		if(today.getDate() > (playdate.getDate()-4)) {
			document.write('<b><font color="#FF0000">Contact Officers</font></b><p>');
		}
		else {
		document.write('<b><font color="#FF0000">Waitlist</font></b><p>');
		}
		
	 }
    
	document.write(course[j]);
	document.write('</font></td><td height="35" align="center" width="157"><b><font color="#FF0000" size="2">');
	document.write(signup[j].substring(0,6));
	document.write('</font></b></td> <td height="35" align="center" width="221"><b><font color="#000000" size="2">');
	document.write(play[j].substring(0,6));
	document.write('</font></b></td> <td height="35" align="center" width="234"><font color="#000000" size="2">Price: $');
	document.write(cost[j]);
	document.write('</font></td>');
//		document.write(j,itemno[j]);  debug message
	if( type==0) {
		document.write('<td height="35" align="center" width="234">');
		if(specsgn[j]==0) {
			document.write(addbuttons(course[j],itemno[j],cost[j],0));
		}
		else {
			document.write('<b><font color="#FF0000"><p>*See Note</font></b>');
			document.write(addbuttons(course[j],itemno[j],cost[j],0));
		}
		document.write('</font></td> <td height="35" align="center" width="234">');
		document.write(addbuttons(course[j],itemno[j],cost[j],1));
		document.write('</font></td>');

		document.write('</font></td> <td height="35" align="center" width="234">');
		document.write(addbuttons(course[j],itemno[j],cost[j],2));
		document.write('</font></td>');
	}
    }
  }
  else if(type==1) {
	document.write('<tr><td width="103" height="35" align="center"><font color="#000000">');
	document.write(course[j]);
	document.write('</font></td><td height="35" align="center" width="157"><b><font color="#FF0000" size="2">');
	document.write(signup[j].substring(0,6));
	document.write('</font></b></td> <td height="35" align="center" width="221"><b><font color="#000000" size="2">');
	document.write(play[j].substring(0,6));
	document.write('</font></b></td> <td height="35" align="center" width="234"><font color="#000000" size="2">Price: $');
	document.write(cost[j]);
	document.write('</font></td>');
  }
  else if(type==2 && ( new Date() < new Date(play[j]) )) {
	document.write('<tr><td width="103" height="35" align="center"><font color="#000000">');
	document.write(course[j]);
	document.write('</font></td><td height="35" align="center" width="157"><b><font color="#FF0000" size="2">');
	document.write(signup[j].substring(0,6));
	document.write('</font></b></td> <td height="35" align="center" width="221"><b><font color="#000000" size="2">');
	document.write(play[j].substring(0,6));
	document.write('</font></b></td> <td height="35" align="center" width="234"><font color="#000000" size="2">Price: $');
	document.write(cost[j]);
	document.write('</font></td>');
	document.write('<td height="35" align="center" width="234">');
	document.write(addbuttons(course[j],itemno[j],cost[j],1));
	document.write('</font></td>');
  }
  }
//	document.write('</tr>');

// It must be type 3 so execute code below
else {
//		document.write(" Current Date= ", new Date()," Deadline= ", new Date(deadline[j]));
	if( new Date() > new Date(deadline[j]) ) {
//		document.write('Past Date');
		if(j==2) j = 6;
		else if(j==1) j = 5;
	}
//	document.write('Signup =',' j =',j,' Date= ',new Date(),' deadline= ',new Date(deadline[j]));
	document.write('<tr><td width="103" height="35" align="center"><font color="#000000">');
	document.write(membership[j]);
	document.write('</font></td><td height="35" align="center" width="157"><b><font color="#FF0000" size="2">$');
	document.write(memitem[j]);
	document.write('</font></b></td> <td height="35" align="center" width="221"><b><font color="#000000" size="2">');

	if( new Date() > new Date(deadline[j]) ) {

		if(memitem[j] == "46") {
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$1.68</b></font>');
		}
		else if (memitem[j] == "56") {
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$1.98</b></font>');
		}
		else if (memitem[j] == "66") {
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$2.28</b></font>');
		}
	}
	else {	
		document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>None!</b></font>');
	}
    document.write(addbuttons(membership[j],membership[j],memitem[j],0));
	document.write('</font></b></td> <td height="35" align="center" width="221"><b><font color="#000000" size="2">');
	if( new Date() > new Date(deadline[j]) ) {

	switch (j){
		case 1:
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$1.98</b></font><form action="https://checkout.google.com/cws/v2/Merchant/543027796700938/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"><input name="item_name_1" type="hidden" value="Renewal"/><input name="item_description_1" type="hidden" value="Renewal"/><input name="item_quantity_1" type="hidden" value="1"/><input name="item_price_1" type="hidden" value="57.98"/><input name="item_currency_1" type="hidden" value="USD"/><input name="_charset_" type="hidden" value="utf-8"/><input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=543027796700938&amp;w=121&amp;h=44&amp;style=trans&amp;variant=text&amp;loc=en_US" type="image"/></form>');
			break;
		case 2:
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$1.68</b></font><form action="https://checkout.google.com/cws/v2/Merchant/543027796700938/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"><input name="item_name_1" type="hidden" value="Renewal NSC"/><input name="item_description_1" type="hidden" value="Renewal NSC"/><input name="item_quantity_1" type="hidden" value="1"/><input name="item_price_1" type="hidden" value="47.68"/><input name="item_currency_1" type="hidden" value="USD"/><input name="_charset_" type="hidden" value="utf-8"/><input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=543027796700938&amp;w=121&amp;h=44&amp;style=trans&amp;variant=text&amp;loc=en_US" type="image"/></form>');
			break;
		case 3:
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$1.98</b></font><form action="https://checkout.google.com/cws/v2/Merchant/543027796700938/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"><input name="item_name_1" type="hidden" value="Club Transfer"/><input name="item_description_1" type="hidden" value="Club Transfer"/><input name="item_quantity_1" type="hidden" value="1"/><input name="item_price_1" type="hidden" value="57.98"/><input name="item_currency_1" type="hidden" value="USD"/><input name="_charset_" type="hidden" value="utf-8"/><input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=543027796700938&amp;w=121&amp;h=44&amp;style=trans&amp;variant=text&amp;loc=en_US" type="image"/></form>');
			break;
		case 4:
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$1.68</b></font><form action="https://checkout.google.com/cws/v2/Merchant/543027796700938/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"><input name="item_name_1" type="hidden" value="Club Transfer NSC"/><input name="item_description_1" type="hidden" value="Club Transfer NSC"/><input name="item_quantity_1" type="hidden" value="1"/><input name="item_price_1" type="hidden" value="47.68"/><input name="item_currency_1" type="hidden" value="USD"/><input name="_charset_" type="hidden" value="utf-8"/><input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=543027796700938&amp;w=121&amp;h=44&amp;style=trans&amp;variant=text&amp;loc=en_US" type="image"/></form>');
			break;
		case 5:
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$2.28</b></font><form action="https://checkout.google.com/cws/v2/Merchant/543027796700938/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"><input name="item_name_1" type="hidden" value="New Member"/><input name="item_description_1" type="hidden" value="New Member"/><input name="item_quantity_1" type="hidden" value="1"/><input name="item_price_1" type="hidden" value="68.28"/><input name="item_currency_1" type="hidden" value="USD"/><input name="_charset_" type="hidden" value="utf-8"/><input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=543027796700938&amp;w=121&amp;h=44&amp;style=trans&amp;variant=text&amp;loc=en_US" type="image"/></form>');
			break;
		case 6:
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$1.98</b></font><form action="https://checkout.google.com/cws/v2/Merchant/543027796700938/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"><input name="item_name_1" type="hidden" value="New Member NSC"/><input name="item_description_1" type="hidden" value="New Member NSC"/><input name="item_quantity_1" type="hidden" value="1"/><input name="item_price_1" type="hidden" value="57.98"/><input name="item_currency_1" type="hidden" value="USD"/><input name="_charset_" type="hidden" value="utf-8"/><input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=543027796700938&amp;w=121&amp;h=44&amp;style=trans&amp;variant=text&amp;loc=en_US" type="image"/></form>');
			break;
		default:
			break;
	}
	}
	else {	
	switch (j){
		case 1:
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$None</b></font><form action="https://checkout.google.com/cws/v2/Merchant/543027796700938/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"><input name="item_name_1" type="hidden" value="Renewal"/><input name="item_description_1" type="hidden" value="Renewal"/><input name="item_quantity_1" type="hidden" value="1"/><input name="item_price_1" type="hidden" value="56.00"/><input name="item_currency_1" type="hidden" value="USD"/><input name="_charset_" type="hidden" value="utf-8"/><input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=543027796700938&amp;w=121&amp;h=44&amp;style=trans&amp;variant=text&amp;loc=en_US" type="image"/></form>');
			break;
		case 2:
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$None</b></font><form action="https://checkout.google.com/cws/v2/Merchant/543027796700938/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"><input name="item_name_1" type="hidden" value="Renewal NSC"/><input name="item_description_1" type="hidden" value="Renewal NSC"/><input name="item_quantity_1" type="hidden" value="1"/><input name="item_price_1" type="hidden" value="46.00"/><input name="item_currency_1" type="hidden" value="USD"/><input name="_charset_" type="hidden" value="utf-8"/><input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=543027796700938&amp;w=121&amp;h=44&amp;style=trans&amp;variant=text&amp;loc=en_US" type="image"/></form>');
			break;
		case 3:
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$None</b></font><form action="https://checkout.google.com/cws/v2/Merchant/543027796700938/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"><input name="item_name_1" type="hidden" value="Club Transfer"/><input name="item_description_1" type="hidden" value="Club Transfer"/><input name="item_quantity_1" type="hidden" value="1"/><input name="item_price_1" type="hidden" value="56.00"/><input name="item_currency_1" type="hidden" value="USD"/><input name="_charset_" type="hidden" value="utf-8"/><input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=543027796700938&amp;w=121&amp;h=44&amp;style=trans&amp;variant=text&amp;loc=en_US" type="image"/></form>');
			break;
		case 4:
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$None</b></font><form action="https://checkout.google.com/cws/v2/Merchant/543027796700938/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"><input name="item_name_1" type="hidden" value="Club Transfer NSC"/><input name="item_description_1" type="hidden" value="Club Transfer NSC"/><input name="item_quantity_1" type="hidden" value="1"/><input name="item_price_1" type="hidden" value="46.00"/><input name="item_currency_1" type="hidden" value="USD"/><input name="_charset_" type="hidden" value="utf-8"/><input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=543027796700938&amp;w=121&amp;h=44&amp;style=trans&amp;variant=text&amp;loc=en_US" type="image"/></form>');
			break;
		case 5:
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$None</b></font><form action="https://checkout.google.com/cws/v2/Merchant/543027796700938/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"><input name="item_name_1" type="hidden" value="New Member"/><input name="item_description_1" type="hidden" value="New Member"/><input name="item_quantity_1" type="hidden" value="1"/><input name="item_price_1" type="hidden" value="66.00"/><input name="item_currency_1" type="hidden" value="USD"/><input name="_charset_" type="hidden" value="utf-8"/><input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=543027796700938&amp;w=121&amp;h=44&amp;style=trans&amp;variant=text&amp;loc=en_US" type="image"/></form>');
			break;
		case 6:
			document.write('<font color="#000000">Charge:</font> <font color="#FF0000"><b>$None</b></font><form action="https://checkout.google.com/cws/v2/Merchant/543027796700938/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm"><input name="item_name_1" type="hidden" value="New Member NSC"/><input name="item_description_1" type="hidden" value="New Member NSC"/><input name="item_quantity_1" type="hidden" value="1"/><input name="item_price_1" type="hidden" value="56.00"/><input name="item_currency_1" type="hidden" value="USD"/><input name="_charset_" type="hidden" value="utf-8"/><input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=543027796700938&amp;w=121&amp;h=44&amp;style=trans&amp;variant=text&amp;loc=en_US" type="image"/></form>');
			break;
		default:
			break;
	}
	}
}

return;

}
//
// function writetablehdr(type)
//       Tom Holden 4-1-2007
// This function is used to write out the top of the table for the schedule or signup online pages
// By using the type the function knows what columns to print for the header
//
//  Type      Description
//   0        This the current sign-up list with only the next 60 days
//   1        This is the complete schedule with no payment buttons
//   2        This is the remaining schedule with only the cart payment buttons
//   3 or more        This is should write out the purchase membership table header
//

function writetablehdr (type) {
 if (type<3){
  document.write('<tr><td width="103" height="34" align="center"><p align="center"><b><font color="#000080">Tournament</font></b></p></td>');
  document.write('<td height="34" align="center" width="157"><b><font color="#000080">Deadline</font></b></td><td height="34" align="center" width="221">');
  document.write('<b><font color="#000080">Playdate</font></b></td><td height="34" align="center" width="234"><b><font color="#000080">Cost</font></b></td>');
  }
  else {
  document.write('<tr><td width="103" height="34" align="center"><p align="center"><b><font color="#000080">Membership</font></b></p></td>');
  document.write('<td height="34" align="center" width="157"><b><font color="#000080">Cost</font></b></td><td height="34" align="center" width="221">');
  document.write('<img  src="https://www.paypal.com/en_US/i/bnr/bnr_paymentsBy_150x40.gif" border="0" alt="Additional Options"></td>');
  document.write('<td height="34" align="center" width="234"><img src="https://checkout.google.com/seller/accept/images/sc.gif" width="72" height="73" alt="Google Checkout Acceptance Mark" /></td>');
  }
  if (type==0){
    document.write('<td height="34" align="center" width="234"><b><font color="#000080">Instant Buy</font></b></td>');
  }
  if (type==0 || type==2) {
    document.write('<td height="34" align="center" width="234"><form action="https://www.paypal.com/cgi-bin/webscr" target="paypal" method="post"><input type="hidden" name="bn" value="AMPPFPWZ.301">');
    document.write('<input type="hidden" name="cmd" value="_cart"><input type="hidden" name="business" value="signup07@nasga.com" >');
    document.write('<input type="hidden" name="display" value="1"><input type="image" src="http://images.paypal.com/images/view_cart.gif" border="0" name="submit" width="130" height="32"></form><b><font color="#000080">Multiple Items</font></b></td>');
  }
  if (type==0) {
    document.write('<td height="34" align="center" width="234"><b><font color="#000080">Google Instant Buy</font></b></td>');
  }
  document.write('</tr>');
}
//-->
