var alreadyclicked = false;

function validate(){
	
	if (alreadyclicked){
		return;
	}
	alreadyclicked = true;
	
	// Check for blank fields
	if (document.form.itemnumber.value == ""){
		document.form.itemnumber.focus();
		alert("Agenda Item Number can not be blank.");
		alreadyclicked = false;
		return;
	}
	if (document.form.cfn.value == ""){
		if (confirm("Are you sure you want to leave the Council File Number for this vote blank?")){
			// Continue
		}
		else {
			document.form.cfn.focus();
			alreadyclicked = false;
			return;
		}
	}
	if (document.form.description.value == ""){
		if (confirm("Are you sure you want to leave the description for this vote blank?")){
			// Continue
		}
		else {
			document.form.description.focus();
			alreadyclicked = false;
			return;
		}
	}
	
	// Check for item number duplication
	var duplicate = false;
	for (var i=0; i < itemarray.length; i++){
		if (itemarray[i] == document.form.itemnumber.value){
			duplicate = true;
		}
	}
	if (duplicate){
		document.form.itemnumber.select();
		alert("ERROR!\n\nThe Agenda Item Number you have chosen, " + document.form.itemnumber.value + ", already exists on the agenda and can not be overwritten. \nPlease choose a unique Agenda Item Number or delete the conflicting item.");
		document.form.itemnumber.focus();
		alreadyclicked = false;
		return;
	}
	
	// If removing a vote, did they enter a unique new rollcall
	var remove = false;
	var nonunique = false;
	
	if (document.form.remove){
		if (document.form.remove.checked){
			remove = true;
		}
	}
	
	if ((document.form.newrollcallnum.value == "")&&(remove)){
		document.form.newrollcallnum.focus();
		alert("In order to remove an item from a group you must enter a new, unique roll call number for the item.\nPlease enter a new roll call number for this item.\n\nTo add this item to an existing group delete the item and re-add it.");
		alreadyclicked = false;
		return;
	}
	
	//if ((document.form.newrollcallnum.value != "")&&(remove)){
	//	var newrcnum = document.form.newrollcallnum.value;
	//	var oldrcoptions = document.form.rollcallnum.options;
	//	for (var i=0; i < oldrcoptions.length; i++){
	//	if (oldrcoptions[i] == document.form.itemnumber.value){
	//		duplicate = true;
	//	}
	//}
	
	
	if ((groupcount > 1) && (!remove)){
		var itemstr = "";
		for (var i=0; i < group.length; i++){
			if (i == group.length - 1){
				itemstr = itemstr + group[i];
			}
			else {
				itemstr = itemstr + group[i] + ", ";
			}
		}
		
		if (confirm("*** WARNING ***\n\nThe vote you are updating is part of a group spanning " + groupcount + " separate items.\nUpdating this vote will update the vote specific information for the other " + groupcount + " items as well.\n\nThe items in this group are: " + itemstr + "\n\nAre you sure this is what you want to do?")){
			if (document.all){
				contentlayer.style.visibility = 'hidden';
				busylayer.style.visibility = 'visible';
			}
			document.form.submit();
			alreadyclicked = false;
			return;
		}
		else {
			alreadyclicked = false;
			return;
		}
	}
	
	if (document.all){
		contentlayer.style.visibility = 'hidden';
		busylayer.style.visibility = 'visible';
	}
	document.form.submit();
	alreadyclicked = false;
	return;
}

function openreport(thevote){
	
	if (!confirm("About to generate a report for the current vote.\n\nThis may take a few moments...\n\nPlease note that the report generated is an ANSI text file.  Any text editor such as Microsoft Word, Corel WordPerfect, WordPad or NotePad should be able to open the file.  Some text editors show hidden characters and do not have word wrap enabled by default so you might need to save the file and open it with another editor.")){
		return;
	}
	
	var theoptions = "";
	window.open("votereport.cfm?voteid=" + thevote, "VOTEINFO", theoptions);
}

function newaction (){

	var theoptions = "left=20,top=20,screenX=20,screenY=20,width=414,height=300,scrollbars";
	window.open("newaction.cfm", "NEWACTION", theoptions);
	return;	
}

function to_search(){
	location.href="results.cfm";
}

function closewin(){
	if (window.opener){
		window.close();
		window.opener.focus();
	}
	window.close();
}
