// javascript for date dropdown for more archives
// needs the array generated by tpl

var monthArray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

function changeDate(v,idNum) {
	if (v != "-") {
		if (idNum != "") {
			window.location.href="archive.jsp?id="+idNum+"&date="+v;
		} else {
			window.location.href="archive.jsp?date="+v;
		}
	}
}

function getDateMenuName(d) {
	var yy = d.substr(0,4);
	var mm = d.substr(4,2);
	return monthArray[eval(mm-1)]+" "+yy;
}

function checkMatch(curValue, thisValue, showThis, showThat) {
	var output = "";
	if (curValue == thisValue) {
		output = showThis;
	} else {
		output = showThat;
	}
	return output;
}

function getURLDate() {
	var loc = window.location+"";
	var splitDate = new Array;
	var theDate = "";
	if (loc.indexOf("date=") >=0) {
		splitDate = loc.split("date=");
		theDate = splitDate[1];
	}
	return theDate;
}

function createDateMenu(idNum) {
	var str = "";
		str +="<form>"
		str +="<select class=\"dateList\" name=\"dateMenu\" id=\"dateMenu\" onChange=\"changeDate(this.value,'"+idNum+"')\">";
		str +="<option value=\"-\">Select a Date Range</option>"
		str +="<option value=\"current\" "+checkMatch("current",getURLDate(),"selected","")+">This Month</option>"
		for (d = 0; d < dateMenuArray.length-1; d++) { // we don't include the last one because in the TPL, it's an 'end' string
				str +=" <option value=\""+dateMenuArray[d]+"\" "+checkMatch(dateMenuArray[d],getURLDate(),"selected","")+">"+getDateMenuName(dateMenuArray[d])+"</option>";
		}
		str +="</select>";
		str +="</form>";
		return str;
}
