function pad(length,number) {
    var str = '' + number;
    while (str.length < length) {
        str = '0' + str;
    }
    return str;
}

function pad_dsply(length,number) {
    var str = '' + number;
    while (str.length < length) {
        //str = '&nbsp;&nbsp;' + str;
        str = '0' + str;        
    }
    return str;
}



today = new Date();

TZoffset = (today.getTimezoneOffset() / 60);
//document.write("the time zone offset is  " + TZoffset + "<br>");
//document.write("GMT  " + today.toGMTString() + "<br>");

currHour = today.getHours();
//document.write("curr Hour " + currHour + "<br>");

d = new Date();
gotMonth = pad(2,d.getMonth() + 1);
gotDate = pad(2,d.getDate());
gotYear = d.getFullYear();

//determine DST
dst_start = new Date("March 14, "+gotYear+" 02:00:00");
dst_start_day = dst_start.getDay();
dst_start.setDate(14-dst_start_day);

dst_end = new Date("November 07, "+gotYear+" 02:00:00");
dst_end_day = dst_end.getDay();
dst_end.setDate(7-dst_end_day);

//document.write(dst_start + " :  " + today + " : " + dst_end + "<br>");

if (today >= dst_start && today < dst_end) {
	dst = true;
} else {
	dst = false;
}
//document.write("DST  " + dst + "<br>");

//end DST determination

todaysDate = (gotMonth + "/" + gotDate + "/" + gotYear);
//document.write(todaysDate + "<br>");

dayNames = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
currDay = dayNames[today.getDay()];
//document.write(currDay + "<br>");

//Schedule arrays
//real schedule
Opponents = new Array("LOI", "RW", "UTC", "FS", "UW", "WYO", "WIS", "OSU", "MINN", "MSU", "NWU", "PSU", "UM", "IOWA", "Big10CG", "XMAS", "NYE");
GameDays = new Array("02/02/2011", "04/16/2011", "09/03/2010", "09/10/2010", "09/17/2010", "09/24/2010", "10/01/2010", "10/08/2010", "10/22/2010", "10/29/2010", "11/05/2010", "11/12/2010", "11/19/2010", "11/26/2010", "12/04/2010", "12/25/2010", "12/31/2010");

nextGameFound = false;
while (nextGameFound == false) {
	for (i=0; i <= (GameDays.length - 1); i++) {
		if (GameDays[i] >= todaysDate) {
			NextOpp = '#' + Opponents[i];
			NextGame = GameDays[i];
			nextGameFound = true;
			break;
		}
	}
}

//document.write("next game " + NextOpp + " " + NextGame + "<br />");

NextGameDate = new Date(NextGame);
DayofGame = dayNames[NextGameDate.getDay()];
//document.write("next game day is " + DayofGame + " on " + NextGame + "<br />");

msecPerDay = (24 * 60 * 60 * 1000);
ShippingDaysLeft = (Math.floor((NextGameDate.getTime() - today.getTime()) / msecPerDay)) + 1;
//document.write("calendar days til game " + ShippingDaysLeft + "<br>");

if (DayofGame == "Saturday") {					// sat next game
	if (ShippingDaysLeft >= 22) {                             	// with bye week
		ShippingDaysLeft-=7;
	} else if (ShippingDaysLeft >= 21) {
		ShippingDaysLeft-=6;
	} else if (ShippingDaysLeft >= 14) {                             	// with bye week
		ShippingDaysLeft-=5;
	} else if (ShippingDaysLeft >= 13) {
		ShippingDaysLeft-=4;
	} else if (ShippingDaysLeft > 6) {				// no bye
		ShippingDaysLeft-=3;
	} else if (ShippingDaysLeft > 5) {				
		ShippingDaysLeft-=2;
	} else {
		ShippingDaysLeft--;						// can't ship out on friday for sat game
	}
	beginDate = new Date();
	beginDate.setFullYear(2010,10,26);  // month 1-11
	endDate = new Date();
	endDate.setFullYear(2010,11,2);   // month 1-11	
	if (NextGameDate >= beginDate && NextGameDate <= endDate) {	// sat after thanksgiving game
		ShippingDaysLeft-=3;						// lose wed, thur and fri for sat game after Thxgiving
	}	
}												
if (DayofGame == "Friday") {  						// fri next game
	if (ShippingDaysLeft > 12) {                             	// with bye week
		ShippingDaysLeft-=4;
	} else if (ShippingDaysLeft > 11) {
		ShippingDaysLeft-=3;
	} else if (ShippingDaysLeft > 5) {				// no bye
		ShippingDaysLeft-=2;
	} else if (ShippingDaysLeft > 4) {
		ShippingDaysLeft--;
	}
	beginDate = new Date();
	beginDate.setFullYear(2010,10,25);  // month 1-11
	endDate = new Date();
	endDate.setFullYear(2010,11,1);   // month 1-11
	if (NextGameDate >= beginDate && NextGameDate <= endDate) {	// day after thanksgiving game
		ShippingDaysLeft-=2;						// lose wed & thur for fri game after Thxgiving
	}
}												
if (DayofGame == "Thursday") {  					// thur game
	if (ShippingDaysLeft > 11) {                             	// with bye week
		ShippingDaysLeft-=4;
	} else if (ShippingDaysLeft > 10) {
		ShippingDaysLeft-=3;
	} else if (ShippingDaysLeft > 4) {				// no bye
		ShippingDaysLeft-=2;
	} else if (ShippingDaysLeft > 3) {
		ShippingDaysLeft--;
	}
	beginDate = new Date();
	beginDate.setFullYear(2010,10,24);  // month 1-11
	endDate = new Date();
	endDate.setFullYear(2010,10,30);   // month 1-11	
	if (NextGameDate >= beginDate && NextGameDate <= endDate) {	// thanksgiving game
		ShippingDaysLeft--;						// lose wed for thur Thxgiving game
	}
}

// ship out date
ShipOutMsg = ("");
if (currDay == "Saturday" || currDay == "Sunday") {
	ShipOutMsg = ("In-Stock items will ship next Monday.");
}

//time zone / dst / noon correction of shipping days left
if (currDay != "Saturday" && currDay != "Sunday") {
	if (dst) {
		switch (TZoffset) {
			case 4:
			if (currHour >= 13) {                                          	// order after 12:00 CT pm in ETZ
				ShippingDaysLeft--;
				if (currDay == "Friday") {
					ShipOutMsg = ("Monday");
				} else {
					ShipOutMsg = ("morning");
				}				
			} else {
				ShipOutMsg = ("afternoon");				
			}
			break;			
			case 5:
			if (currHour >= 12) {                                          	// order after 12:00 CT pm in CTZ
				ShippingDaysLeft--;
				if (currDay == "Friday") {
					ShipOutMsg = ("Monday");
				} else {
					ShipOutMsg = ("morning");
				}				
			} else {
				ShipOutMsg = ("afternoon");	
			}			
			break;			
			case 6:
			if (currHour >= 11) {                                          	// order after 12:00 CT pm in MTZ
				ShippingDaysLeft--;
				if (currDay == "Friday") {
					ShipOutMsg = ("Monday");
				} else {
					ShipOutMsg = ("morning");
				}				
			} else {
				ShipOutMsg = ("afternoon");	
			}			
			break;			
			case 7:
			if (currHour >= 10) {                                          	// order after 12:00 CT pm in PTZ
				ShippingDaysLeft--;
				if (currDay == "Friday") {
					ShipOutMsg = ("Monday");
				} else {
					ShipOutMsg = ("morning");
				}				
			} else {
				ShipOutMsg = ("afternoon");	
			}			
			break;			
			case 8:
			if (currHour >= 9) {                                          	// order after 12:00 CT pm in ATZ
				ShippingDaysLeft--;
				if (currDay == "Friday") {
					ShipOutMsg = ("Monday");
				} else {
					ShipOutMsg = ("morning");
				}				
			} else {
				ShipOutMsg = ("afternoon");	
			}			
			break;			
			case 10:
			if (currHour >= 8) {                                          	// order after 12:00 CT pm in HTZ
				ShippingDaysLeft--;
				if (currDay == "Friday") {
					ShipOutMsg = ("Monday");
				} else {
					ShipOutMsg = ("morning");
				}				
			} else {
				ShipOutMsg = ("afternoon");	
			}			
			break;			
		}
	} else {
		switch (TZoffset) {
			case 5:
			if (currHour >= 13) {                                          	// order after 12:00 CT pm in ETZ
				ShippingDaysLeft--;
				if (currDay == "Friday") {
					ShipOutMsg = ("Monday");
				} else {
					ShipOutMsg = ("morning");
				}				
			} else {
				ShipOutMsg = ("afternoon");	
			}			
			break;			
			case 6:
			if (currHour >= 12) {                                          	// order after 12:00 CT pm in CTZ
				ShippingDaysLeft--;
				if (currDay == "Friday") {
					ShipOutMsg = ("Monday");
				} else {
					ShipOutMsg = ("morning");
				}				
			} else {
				ShipOutMsg = ("afternoon");	
			}			
			break;			
			case 7:
			if (currHour >= 11) {                                          	// order after 12:00 CT pm in MTZ
				ShippingDaysLeft--;
				if (currDay == "Friday") {
					ShipOutMsg = ("Monday");
				} else {
					ShipOutMsg = ("morning");
				}				
			} else {
				ShipOutMsg = ("afternoon");	
			}			
			break;			
			case 8:
			if (currHour >= 10) {                                          	// order after 12:00 CT pm in PTZ
				ShippingDaysLeft--;
				if (currDay == "Friday") {
					ShipOutMsg = ("Monday");
				} else {
					ShipOutMsg = ("morning");
				}				
			} else {
				ShipOutMsg = ("afternoon");	
			}			
			break;			
			case 9:
			if (currHour >= 9) {                                          	// order after 12:00 CT pm in ATZ
				ShippingDaysLeft--;
				if (currDay == "Friday") {
					ShipOutMsg = ("Monday");
				} else {
					ShipOutMsg = ("morning");
				}				
			} else {
				ShipOutMsg = ("afternoon");	
			}			
			break;			
			case 10:
			if (currHour >= 8) {                                          	// order after 12:00 CT pm in HTZ
				ShippingDaysLeft--;
				if (currDay == "Friday") {
					ShipOutMsg = ("Monday");
				} else {
					ShipOutMsg = ("morning");
				}				
			} else {
				ShipOutMsg = ("afternoon");	
			}			
			break;			
		}
	}
}

if (ShipOutMsg == "Monday" ) {
	ShipOutMsg = "In-Stock items will ship next Monday (Holidays Excluded).";
} else if (ShipOutMsg == "morning" ) {
	ShipOutMsg = "In-Stock items will ship tomorrow morning (Holidays Excluded).";
} else if (ShipOutMsg == "afternoon" ){
	ShipOutMsg = "In-Stock items will ship this afternoon (Holidays Excluded).";
}

ShipOutMsg = '&nbsp; <font face="sans-serif" size="2px">' + ShipOutMsg + "</font>";
//document.write(ShipOutMsg);

if (ShippingDaysLeft < 0) {
	ShippingDaysLeft = 0;
}

//ShippingDaysLeft = 0;

BowlShippingDaysLeft = ShippingDaysLeft;

if (ShippingDaysLeft < 10) {
	ShippingDaysLeft = pad_dsply(2,ShippingDaysLeft);
}

ShippingMsg = (ShippingDaysLeft + " SHIPPING DAY(S) LEFT");
BowlShippingMsg = (BowlShippingDaysLeft + " SHIPPING DAY(S) LEFT");

XmasShippingDaysLeft = ShippingDaysLeft;   
//XmasShippingDaysLeft = 12;                            // comment this line after last game/conference championship game going into xmas countdown
//document.write("shipping days til xmas " + XmasShippingDaysLeft + "<br>");

//ShippingDaysLeft +=3 ;

$(document).ready (function() {
	$(NextOpp).after(ShippingMsg);
	$('#countdown').after(ShippingDaysLeft);
	$('#home_countdown').after(ShippingDaysLeft);
	$('#xmas_countdown').after(XmasShippingDaysLeft);
	$('#order_shipped').after(ShipOutMsg);	
	//$('#BOWL').after(BowlShippingMsg);	
});






































































