<!--//
// variables for popups
	var popWin = null;

// ============================================================
// closes a window
// ============================================================
	function closePop() {
		try {
			popWin.close()
		} catch(er) {}
	}

// ============================================================
// returns the parent object by the name
// ============================================================
	function getParentObject(obj, tName) {
		// get upper case of the tagName
			var tNameUC = tName.toUpperCase();
		// recurse until object is found
			if (obj) {
				while (obj) {
					if (obj.nodeName.toUpperCase() == tNameUC) {
						return obj;
					} else {
						obj = obj.parentNode;
					}
				}
			}
	}

// ============================================================
// validates the form
// ============================================================
	function ValidateForm() {
		switch (document.getElementById("pagename").value.toLowerCase()) {
			case "zip_entry_general":
				// zip code
					var pFourVal = document.getElementById("plusfour").value;
					if (isNaN(document.getElementById("zip").value)) {
						document.getElementById("zip").select();
						alert("Please provide a valid zip code.");
						return false;
					} else if (parseInt(document.getElementById("zip").value).toString().length != document.getElementById("zip").value.length) {
						document.getElementById("zip").select();
						alert("Please provide a valid zip code.");
						return false;
					} else if (document.getElementById("zip").value.length != 5) {
						document.getElementById("zip").select();
						alert("Zip code must contain 5 characters.");
						return false;
				// plusfour extension
					} else if (isNaN(document.getElementById("plusfour").value)) {
						document.getElementById("plusfour").select();
						alert("Please enter a valid extension for this zip code.");
						return false;
					} else if (document.getElementById("plusfour").value.length < 4) {
						document.getElementById("plusfour").select();
						alert("Zip code extension must contain 4 characters.");
						return false;
					} else if (pFourVal.substr(0,1) != "0" && parseInt(document.getElementById("plusfour").value).toString().length != document.getElementById("plusfour").value.length) {
						document.getElementById("plusfour").select();
						alert("Please enter a valid extension for this zip code.");
						return false;
					} else {
						return true;
					}
				break;
			case "zip_entry":
				// zip code
					var pFourVal = document.getElementById("plusfour").value;
					if (isNaN(document.getElementById("zip").value)) {
						document.getElementById("zip").select();
						alert("Please provide a valid zip code.");
						return false;
					} else if (parseInt(document.getElementById("zip").value).toString().length != document.getElementById("zip").value.length) {
						document.getElementById("zip").select();
						alert("Please provide a valid zip code.");
						return false;
					} else if (document.getElementById("zip").value.length != 5) {
						document.getElementById("zip").select();
						alert("Zip code must contain 5 characters.");
						return false;
				// plusfour extension
					} else if (isNaN(document.getElementById("plusfour").value)) {
						document.getElementById("plusfour").select();
						alert("Please enter a valid extension for this zip code.");
						return false;
					} else if (document.getElementById("plusfour").value.length < 4) {
						document.getElementById("plusfour").select();
						alert("Zip code extension must contain 4 characters.");
						return false;
					} else if (pFourVal.substr(0,1) != "0" && parseInt(document.getElementById("plusfour").value).toString().length != document.getElementById("plusfour").value.length) {
						document.getElementById("plusfour").select();
						alert("Please enter a valid extension for this zip code.");
						return false;
				// party affiliation
					} else if (document.getElementById("party").selectedIndex == 0) {
						document.getElementById("party").focus();
						alert("Please select a political party.");
						return false;
					} else {
						return true;
					}
				break;
			case "zip_candidate_lookup":
				// zip code
					if (document.getElementById("lastname").value.length == 0) {
						document.getElementById("lastname").select();
						alert("Candidate Last Name cannot be blank.");
						return false;
				// type of candidate
					} else if (document.getElementById("candidatetype").selectedIndex == 0) {
						document.getElementById("candidatetype").focus();
						alert("Please indicate whether this is a judicial candidate.");
						return false;
					} else {
						return true;
					}
			//case "zip_candidate_edit":
			//	// validate only for Judicial candidates
			//		if (document.getElementById("candidatetype").value == "J") {
			//			// Q1
			//				if (document.getElementById("Q1Other").value.length == 0 && (document.getElementById("Q1").selectedIndex == document.getElementById("Q1").options.length - 1)) {
			//					document.getElementById("Q1Other").select();
			//					alert("Please indicate the users presidential philosophy.");
			//					return false;
			//			// Q2
			//				} else if (document.getElementById("Q2Other").value.length == 0 && (document.getElementById("Q2").selectedIndex == document.getElementById("Q2").options.length - 1)) {
			//					document.getElementById("Q2Other").select();
			//					alert("Please indicate the users supreme court philosophy.");
			//					return false;
			//				} else {
			//					return true;
			//				}
			//		}
			//	break;
		}
		return true;
	}

	function checkOther(theSelect) {
		theID = theSelect.id
		if (theSelect.selectedIndex == theSelect.options.length - 1) {
			document.getElementById(theID + "Other").style.display = "";
			document.getElementById(theID + "Other").focus();
		} else {
			document.getElementById(theID + "Other").style.display = "none";
			document.getElementById(theID + "Other").value = "";
		}
	}
	function ShowHideRace(theLink) {
		//get parent table
			var pTable = getParentObject(getParentObject(theLink,"TABLE").parentNode,"TABLE")
			if (theLink.value == "Hide") {
				theLink.value = "Show";
			} else {
				theLink.value = "Hide";
			}
			with (pTable.rows) {
				for (var counter=1;counter<length;counter++) {
					if (item(counter).style.display != "none") {
						item(counter).style.display = "none";
					} else {
						item(counter).style.display = "";
					}
				}
			}
	}
	function popOpen(raceType,candidateID) {
		try {
			popWin.focus();
			//alert(popWin.document.location);
			popWin.document.location="zip_candidate_info.asp?racetype=" + raceType + "&ID=" + candidateID;
		} catch(er) {
			popWin = window.open('zip_candidate_info.asp?racetype=' + raceType + '&ID=' + candidateID,'','scrollbars=yes,menubar=yes,height=600,width=800,resizable=yes,toolbar=yes,location=no,status=no');
		}
	}
	function popOpenComments(raceType,candidateID,QID,theParty) {
		try {
			popWin.focus();
			//alert(popWin.document.location);
			popWin.document.location="zip_candidate_comments.asp?racetype=" + raceType + "&ID=" + candidateID + "&QID=" + QID + "&Party=" + theParty;
		} catch(er) {
			popWin = window.open('zip_candidate_comments.asp?racetype=' + raceType + '&ID=' + candidateID + "&QID=" + QID + "&Party=" + theParty,'','scrollbars=yes,menubar=yes,height=600,width=800,resizable=yes,toolbar=yes,location=no,status=no');
		}
	}

//-->