function checker(e) {
	var x = e.split(",");
	var pass = true;
	checkerInvalid = new Array;
	for(i=0; i<x.length; i++) {
		if(!eval(x[i])) {
			pass = false; 
			checkerInvalid[checkerInvalid.length] = x[i];
		}
	}
	return pass;
}

function findMonths() {
	var monthList = ["January","February","March","April","May","June","July","August","September","October","November","December"]
	var today = new Date();
	var monthNum = today.getMonth();
	var monthYear = today.getFullYear();
	var months = new Array();
	for(var i=0;i<(12-monthNum);i++) {
		var newMonthNum = (monthNum+i+1).toString();
		if(newMonthNum.length==1) {
			newMonthNum = "0" + newMonthNum;
		}
		months[i] = new Array();
		months[i][0] = (newMonthNum) + "-" + monthYear;
		months[i][1] = monthList[monthNum+i] + " " + monthYear;
	}
	return months;
}

function setMonthList() {
	if (checker("document.getElementById('cal-small-month')")) {
		var monthDiv = document.getElementById("cal-small-month");
		var html = "<form><select name='call-small-months' id='call-small-months' onChange='reloadSmallCal(this.options[selectedIndex].value)'><option value=0>-- Select a Month --</option>"
		var months = findMonths();
		for(var i=0; i<months.length; i++) {
			html = html + "<option value=" + months[i][0] + ">" + months[i][1] + "</option>";
		}
		html = html + "</select>";
		monthDiv.innerHTML = html;
	}
}

function reloadSmallCal(d) {
	if(d == 0) {return false;}
	var newLocation = window.location.toString();
	if(newLocation.search(/cal=\d{1,2}-\d{2,4}/)>0) {
		newLocation = newLocation.replace(/cal=\d{1,2}-\d{2,4}/, "cal=" + d);
	}
	else if(newLocation.search(/\?/)>0) {
		newLocation = newLocation + "&cal=" + d;
	}
	else {
		newLocation = newLocation + "?cal=" + d;
	}
	window.location = newLocation;
}
