function populateDaysInMonth(daysElement, monthElement, yearsElement) {
	var i;
	var leadingZero;
	var numElements = monthElement.length;

	var year = yearsElement.options[yearsElement.selectedIndex].value;
			
	var currentDaySelection = daysElement.selectedIndex;

	var numDays = (32 - new Date(year, monthElement.options[monthElement.selectedIndex].value-1, 32).getDate());
	for (i=0; i < numElements; i++) {
		daysElement.options[i] = null;
	}

	for(i=0 ; i < numDays ;i++) {
		if(i<9) {
			leadingZero = '0';
		} else {
			leadingZero = '';
		}
		daysElement.options[i] = new Option(String(leadingZero+(i+1)), i+1);
	}
	
	if(currentDaySelection > (numDays -1)){
		currentDaySelection = numDays - 1;
	}
	daysElement.selectedIndex = currentDaySelection;
}


function openMinimalWindow(url){
	window.open(url,"mywindow","resizable=1");
}


function openRNSMinimalWindow(url){
	window.open(url,"mywindow","resizable=1, width=800, height=600, toolbar=false, menubar=false, scrollbars=yes");
}

function checkEmailsMatch(inputOne, inputTwo, outputBox){
	var textOne = inputOne.value;
	var textTwo = inputTwo.value;
	var message = "";
	
	if(textOne != textTwo){
		message = "The E-mail addresses you have entered do not match.";
	}
	
	outputBox.innerHTML = message;
	
}

function redirectToSelected(boxRef, baseURL, logAsSearch){
	var selectedValue = boxRef.options[boxRef.selectedIndex].value;
	var url = baseURL + "/" + selectedValue + "/";
	
	if(selectedValue != ""){
		if(logAsSearch){
			logSearch(selectedValue);	
		} else {
			window.location = url;
		}
	}
}

function toggleElementState(elem, animation){
	if ($(elem) == 'undefined'){
		// elem doesnt exist
	} else {
		if($(elem).getStyle('display')=='none'){
			// $(elem).appear({ duration: 1.0 });
			new Effect.BlindDown(elem);
			$(elem).addClassName('toggle_state_open')
		} else {
			//$(elem).fade({ duration: 1.0 });
			new Effect.BlindUp(elem);
			$(elem).removeClassName('toggle_state_open')		
		}
	}
}

function toggleClassState(toggleClass){
		var narrativeChildren = $('narrativeContent').childElements();
		for(i=0;i<narrativeChildren.length;i++){
			if(narrativeChildren[i].hasClassName(toggleClass)){
				if(narrativeChildren[i].getStyle('display')=='none'){
					//narrativeChildren[i].setStyle({ display: 'block'});
					new Effect.BlindDown(narrativeChildren[i]);
				} else {
					//narrativeChildren[i].setStyle({ display: 'none'});
					new Effect.BlindUp(narrativeChildren[i]);
				}
			}
		}
}

function toggleSitemapState(){
		var sitemapControl = $('sitemapControl');
		if(sitemapControl.hasClassName('sitemap_open')){
			sitemapControl.removeClassName('sitemap_open');
			sitemapControl.addClassName('sitemap_closed');
		} else {
			sitemapControl.removeClassName('sitemap_closed');
			sitemapControl.addClassName('sitemap_open');
		}
}

function toggleSearchDefault(elem){
	if(elem.value=='Site Search...'){
		elem.value = '';
	}else if (elem.value==''){
		elem.value = 'Site Search...';
	}
}
