/**
 * @author chrishenry
 */

var daysofmonth   = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
var daysofmonthLY = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];

function changeDays(elm) {
	
	var month = elm.value;

	var d = new Date();
	var year = LeapYear(d.getYear());
	var thisRay = (year) ? daysofmonthLY : daysofmonth ;
	
	days = thisRay[month-1];
	var options = $A($R(1, days)).collect(function(item) {
		return '<option>' + item + '</option>';
	});
	var optionsR = options.join();

	$('from').update(optionsR);	
	$('to').update(optionsR);
}

function changeTo(elm) {
	$('to').value = elm.value;
}

function LeapYear(year) {
    if ((year/4)   != Math.floor(year/4))   return false;
    if ((year/100) != Math.floor(year/100)) return true;
    if ((year/400) != Math.floor(year/400)) return false;
    return true;
}

function limitText(elm, limitCount, limitNum) {
	if (elm.value.length > limitNum) {
		elm.value = elm.value.substring(0, limitNum);
		$(elm.id + "_error").update("You have reached the character limit.");
	} else {
		$(limitCount).update( limitNum - elm.value.length + " left");
		$(elm.id + "_error").update();
	}
}

function changeType(elm) {
	window.location = "/events.php?type=" + elm.value;
}
