
function getParams()
	{
	var idx = document.URL.indexOf('?');
	var params = new Array();

	if (idx != -1) {var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
					for (var i=0; i<pairs.length; i++) {
						nameVal = pairs[i].split('=');
						params[nameVal[0]] = nameVal[1];
   														}
					}
	return params;}

	outputa = getParams();
	action = outputa["setVote"]


var expDays = 30;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	var j = i + alen;
	if (document.cookie.substring(i, j) == arg)
	return getCookieVal (j);
	i = document.cookie.indexOf(" ", i) + 1;
	if (i == 0) break;
	}
	return null;
}


function SetCookie (name, value) {

	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}




function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}


if (action == vote_name){
SetCookie (vote_name, "showResult")
}
if (action == "delete"){
DeleteCookie (vote_name)
}

var cookieValue = "showResult";


   
   var urlSpacer = ""
   var locationHREF = location.href
   if (locationHREF.indexOf("?") == -1){
   	urlSpacer = "?"
   } else {
   	urlSpacer = "&"
   }
    var submitTo = location.href + urlSpacer + "setVote=" + vote_name

			if (GetCookie(vote_name)!=cookieValue){

//<!-- The folowwing HTML is to show the options and the vote button. -->
document.writeln('<form name="voting" method="post" action="/vote/submit_APvote.jsp">')
		
	//	<!-- start of the vote code -->
		


document.writeln('<table cellpadding="0" cellspacing="1" border="0" class="rhcoutline1" width="168" align="center">')
document.writeln('<tr>')
document.writeln('<td>')
document.writeln('<table cellpadding="4" cellspacing="0" border="0" class="rhcouterbg1"width="100%">')
document.writeln('	<tr>')
document.writeln('		<td class="vote1"><strong>Vote</strong></td>')
document.writeln('	</tr>')
document.writeln('	<tr>')
document.writeln('		<td class="rhcinnerbg1">')
document.writeln('			<table cellpadding="2" cellspacing="0" border="0" width="100%">')
document.writeln('				<tr>')
document.writeln('					<td colspan="2" class="vote2"><b>' + voteQuestion + '</b></td>')
document.writeln('				</tr>')

    for (var i = 0; i<options.length; i++){


document.writeln('				<tr>')
document.writeln('					<td colspan="2" class="vote2">' + options[i] + '</td>')
document.writeln('				</tr>	')	
}
document.writeln('				<tr>')
document.writeln('					<td><input type="hidden" name="source" value="' + submitTo + '"/></td>')
document.writeln('					<td align="right"><a href="javascript:document.voting.submit()" class="vote2"><strong>Vote Now</strong></a></td>')
document.writeln('				</tr>')
document.writeln('			</table>')
document.writeln('		</td>')
document.writeln('	</form>')
document.writeln('	<tr>')
document.writeln('</table>')
document.writeln('</td>')
document.writeln('</tr>')
document.writeln('</table>')


}

		
//	<!-- The following HTML is to display the result -->
//	<!-- This is the result box -->



		if (GetCookie(vote_name)==cookieValue){
document.writeln('<table cellpadding="0" cellspacing="1" border="0" class="rhcoutline1" width="168" align="center">')
document.writeln('<tr>')
document.writeln('<td>')
document.writeln('<table cellpadding="4" cellspacing="0" border="0" class="rhcouterbg1" width="100%">')
document.writeln('	<tr>')
document.writeln('		<td class="vote1"><strong>Results</strong></td>')
document.writeln('	</tr>')
document.writeln('	<tr>')
document.writeln('		<td class="rhcinnerbg1">')
document.writeln('			<table cellpadding="2" cellspacing="0" border="0" width="100%">')
document.writeln('				<tr>')
document.writeln('					<td colspan="2" class="vote2"><b>' + voteQuestion + '</b></td>')
document.writeln('				</tr>')
document.writeln('				<tr>')
document.writeln('					<td class="rhcinnerbg1">')
document.writeln('						<table cellpadding="2" cellspacing="0" border="0" width="100%">')

        for (i=0;i<optionText.length;i++){

document.writeln('							<tr>')
document.writeln('								<td colspan="2" class="vote2">' + optionText[i] + '</td>')
document.writeln('							</tr>')
document.writeln('							<tr>')
document.writeln('									<td><img class="voteline" src="images/blank.gif" width="' + optionValue[i] + '" height="8" alt="" border="0"></td>')
document.writeln('									<td class="vote2" align="right">' + optionValue[i] + '%</td>					')
document.writeln('							</tr>')
         }
			
document.writeln('						</table>')
document.writeln('					</td>')
document.writeln('				</tr>')
document.writeln('			</table>')
document.writeln('		</td>')
document.writeln('	</tr>')
document.writeln('</table>')
document.writeln('</td>')
document.writeln('</tr>')
document.writeln('</table>')


         }

