	function updateDays() {
		var monthSelect = document.getElementById('month');
		var month = parseInt( monthSelect.options[ monthSelect.selectedIndex ].value );
		var days = 31;
		
		if( month == 2 ) {
			var yearSelect = document.getElementById('year');
			var year = parseInt( yearSelect.options[ yearSelect.selectedIndex ].value );
			if( (year%4) == 0 )
				days = 29; //leap year
			else
				days = 28
		}
		else if( (month == 4) || (month == 6) || (month == 9) || (month == 11) )
			days = 30;
			
		var daySelect = document.getElementById('day');
		var selectedIndex = daySelect.selectedIndex;
		
		var i;
		var length = daySelect.options.length;
		for(i = length-1; i >= 0; i--) {
			daySelect.remove(i);
		}

		var j;
		for( j=0; j<days; j++) {
			var d = j + 1;
			var thisSelected = false;
			if( j == selectedIndex )
				thisSelected = true;

			daySelect.options[j] = new Option( d, d, thisSelected );
		}
	}
	
	function searchSubmit() {
		var href = '/library/code/event-calendar-ajax.aspx';
		var monthSelect = document.getElementById('month');
		var month = parseInt( monthSelect.options[ monthSelect.selectedIndex ].value );
		var daySelect = document.getElementById('day');
		var day = parseInt( daySelect.options[ daySelect.selectedIndex ].value );
		var yearSelect = document.getElementById('year');
		var year = parseInt( yearSelect.options[ yearSelect.selectedIndex ].value );
	
		var categorySelect = document.getElementById('categories');
		var category = encodeURIComponent( categorySelect.options[ categorySelect.selectedIndex ].value );
		
		var dt = "";
		if( !month || ! day || !yearSelect.selectedIndex ) {
			var nowDT = new Date();
			var m = nowDT.getMonth() + 1;
			var d = nowDT.getDate();
			var y = nowDT.getYear();
			if( y < 1000 )
				y += 1900;
			dt = m + "/" + d + "/" + y;
		}
		else
			dt = month + "/" + day + "/" + year;
		
		var cat = "";
		if( !categorySelect.selectedIndex )
			cat = 'ALL';
		else
			cat = category;
		
		href += "?dt=" + dt + "&category=" + cat + "&region=" + getRegionFromQuerystring();
		ajaxLink( href, null );
	}
	
	function startSubmit() {
	    calendarControl.iniated = true;
	    var querystring = location.href.match(/\?(.+)$/);
		var href = '/library/code/event-calendar-ajax.aspx';
		if ( (querystring != null) && (querystring != "") )
		    href += querystring[0];
		else
		{
		    var nowDT = new Date();
		    var m = nowDT.getMonth() + 1;
		    var d = nowDT.getDate();
		    var y = nowDT.getYear();
		    if( y < 1000 )
			    y += 1900;
		    dt = m + "/" + d + "/" + y;
    		
		    var cat = "ALL";
		    href += "?dt=" + dt + "&category=" + cat + "&region=" + getRegionFromQuerystring() + "&sitecode=nhparks";
		}
		
		ajaxLink(href, null);
	}
	
	function ajaxLink( href, popupURL ) {
	    if( href != null ) {
		    var strCode = "&code=" + Math.random() + Math.random();
		    url = href + strCode;
    		
		    http = getHTTPObject();
		    http.onreadystatechange = processCalendar;
		    http.open("GET", url, true);
		    http.setRequestHeader("Cache-Control", "no-cache");
		    http.send(null);
		}
		if( popupURL != null )
			GB_showCenter('Event Information', popupURL, 600, 600);
	}

	function Popup(url,windowname,w,h,x,y) {
		window.open(url,windowname,"resizable=yes,toolbar=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+w+",height="+h+",left="+x+",top="+y+"");
	}

	processCalendar = function() {
		var calendarBlock = document.getElementById('blockCalendar');
	
		if (http.readyState == 4) {
			if (http.status == 200)
				calendarBlock.innerHTML = http.responseText;
			else
				calendarBlock.innerHTML = "<center><font color='red'><strong>Could not load calendar!!!</strong></font></center>";
		}
	}

	getHTTPObject = function() {
		if (typeof XMLHttpRequest != 'undefined') {
			return new XMLHttpRequest();
		} 
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
		return false;
	}

	function getRegionFromQuerystring() {
		var url = window.location.toString();
		
		url.match(/\?(.+)$/);
		var params = RegExp.$1;
		
		if( params ) {
		    var paramsArray = params.split("&");
    	
		    for(var i=0;i<paramsArray.length;i++)
		    {
			    if( paramsArray[i].split("=")[0] == "region" )
				    return paramsArray[i].split("=")[1];
		    }
		}

		return "";
	}
    
    function calendarOnLoad() {
	    if( calendarControl.iniated == false )
		    startSubmit();
	}
	
	var calendarControl = new Object();
    calendarControl.iniated = false;
	calendarOnLoad();
	
    function __doPostBack(eventTarget, eventArgument) {
        var theForm = document.forms['calendarForm'];
        if (!theForm) {
            theForm = document.calendarForm;
        }

        if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
            theForm.__EVENTTARGET.value = eventTarget;
            theForm.__EVENTARGUMENT.value = eventArgument;
            theForm.submit();
        }
    }
    
    	grabCategories = function( siteCode ) {
			var strCode = "code=" + Math.random() + Math.random();
			var strSiteCode = "&sitecode=" + siteCode;
			url = "/library/code/get-calendar-dropdown.aspx?" +strCode + strSiteCode;
			
			http = getHTTPObject();
			http.onreadystatechange = processCategories;
			http.open("GET", url, true);
			http.setRequestHeader("Cache-Control", "no-cache");
			http.send(null);
	}

	processCategories = function() {
		var categoryDisplay = document.getElementById('categorySelect');
	
		if (http.readyState == 4) {
			if (http.status == 200)
				categoryDisplay.innerHTML = http.responseText;
			else
				categoryDisplay.innerHTML = "Could not load type display!!";
		}
	}
