function expandDiv(div){
	document.getElementById(div).style.display = "block";
}

function collapseDiv(div){
	document.getElementById(div).style.display = "none";

}

function replaceURL(year){
	var location = window.location.href;
	var link = location;
	if(location.indexOf("?") == -1){
		link = location + "?election_yr=" + year;
	}else{
		var startIndex = location.indexOf("election_yr");
		var endIndex = location.indexOf("&", startIndex+1);
		if(endIndex == -1){
			endIndex = location.length;
		}
		var electionYear = location.substring(startIndex, endIndex);
		
		var newElectionYear = "election_yr=" + year;
		link = location.replace(electionYear, newElectionYear);
	}
	
	window.location.replace(link);
}

function setElectionCycleChecked(){
	var radioList = document.changeElectionCycle.electionCycle;
	if(!radioList) return;
	
	var radioLen = radioList.length;
	for(var i=0; i<radioLen; i++){
		radioList[i].checked = false;
		if(radioList[i].value == getElectionYear()){
			radioList[i].checked = true;
		}
	}
	
	
}



function checkMouseClick(e){
	var workElement = (e && e.target) || (event && event.srcElement); 
	
	if(document.getElementById("selectElectionCycle") != workElement){
		var parent = workElement;
		while(parent = parent.parentNode){
			if(parent.id == "selectElectionCycle"){
				collapseDiv("selectElectionCycle");
				expandDiv("mapSelElectionYear");
			}else if(parent.id == "mapSelElectionYear"){
				collapseDiv("mapSelElectionYear");
				expandDiv("selectElectionCycle");
			}
			
		}
		
		
	}
}
//document.onclick = checkMouseClick; // collapse the