// ==========================================================
var poll;
function submitResults(){
	var pollID = (window.poll.replace(/\D/g,""));
	if(getRadioValue(window.poll) == null){ 
		alert("Please make a selection to vote"); 
	} else {
		if(getCookie(window.poll) == null){
			var oVote = new XHConn();
			if (!oVote) alert("We are unable to register your vote. Try a newer/better browser.");
			var voteSuccess = function (oXML) {
				setCookie(window.poll,pollID,365);
				showResults(oXML);
			};
			oVote.connect("Poll_Processor.asp", "POST", "action=write&poll="+pollID+"&vote="+getRadioValue(window.poll), voteSuccess);
		}
	}
}
function showResults(oXML){
	$("votingPoll").style.display = "none";
	$("votingResults").innerHTML = oXML.responseText;
}
function getResults(oXML){
	var pollID = (getCookie(window.poll).replace(/\D/g,""));
	$("votingPoll").style.display = "none";
	var oResults = new XHConn();
	var voteResults = function (oXML) {
		$("votingResults").innerHTML = oXML.responseText;
	};
	oResults.connect("Poll_Processor.asp", "POST", "action=read&poll="+pollID, voteResults);
}
// ==========================================================
function checkVotingPoll(){
	window.poll = document.forms["pollQuestion"].elements[0].name;
	//delCookie(window.poll);
	var hasVoted = (getCookie(window.poll) != null)? true : false;
	if(hasVoted){ getResults() };
}
// ==========================================================
// 		Get Radio Value
// ==========================================================
function getRadioValue(field){
	var radio = document.forms["pollQuestion"].elements[field];
	if(radio == undefined) return null;
	for(var i=0,rl=radio.length; i<rl; i++) {
		if(radio[i].checked){ return radio[i].value; }
	}
	return null;
}
// ==========================================================
// 		COOKIEs
// ==========================================================
function getCookie(NameOfCookie){
	if (document.cookie.length > 0) {              
		begin = document.cookie.indexOf(NameOfCookie+"=");       
		if (begin != -1) {           
			begin += NameOfCookie.length+1;       
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(begin, end));
			} 
		}
	return null;
}
function setCookie(NameOfCookie, value, expiredays) {
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	
	document.cookie = NameOfCookie + "=" + escape(value) + 
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}
function delCookie (NameOfCookie) {
	if (getCookie(NameOfCookie)) {
		document.cookie = NameOfCookie + "=" +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}
// ==========================================================
//		Browser Check
// ==========================================================
var agent 	= navigator.appName.toLowerCase();
if(agent == "opera"){
	var version = navigator.appVersion.substring(0,4);
	if(version < 8.5){
		alert("Please upgrade your browser. You will not be able to submit your vote with an Opera browser less than version 8.5. We apologize for any inconvience");
	}
}
// ==========================================================