var dbWebPollPath = 'http://www.lotusrockstar.com/blog/robblog.nsf';
var pollid ='';
function getWebPolls(){
$(".BlogPollContents").each(function(){
		$(this).html('<img src="'+dbWebPollPath+'/indicator.gif">');
		if(readCookie(this.id) == "Vote Accepted"){
			view(this.id);
		}else{
			var ajaxurl = dbWebPollPath+'/webpoll?OpenPage&rdm='+Math.random()+'&survey=' + this.id;
			var myAjax = $.ajax({url : ajaxurl,type: 'get',dataType: 'xml',success: showWebPoll});
		}
		});
}
function showWebPoll(responseXML){
	var root = $(responseXML).find('Pollid').text();
	var Poll = $(responseXML).find('PollContents').text();
	$(".BlogPollContents").each(function(){
		if (this.id = root) 
			{
			$(this).html(Poll);
			}
		});
}
function vote(currPoll){
	if (getRB(document.forms[currPoll],'PollOption').value) {}else{
		alert('Please Select An Option');
		return;}
	createCookie(currPoll, "Vote Accepted", 999);
	$(currPoll).html('<img src="'+dbWebPollPath+'/indicator.gif">');
	var form = document.forms[currPoll];
	var ajaxdata = $(form).serialize();
	pollid = currPoll;
	var ajaxurl = dbWebPollPath+'/sys_WebPollVote?createdocument';
	var myAjax = $.ajax( {url:ajaxurl, method:'get',data:ajaxdata,success:viewResult});
} 
function viewResult(responseXML){
	view(pollid);
}
function view(p_pollid){
	$(p_pollid).html('<img src="'+dbWebPollPath+'/indicator.gif">');
	var ajaxurl = dbWebPollPath+'/webpollresult?OpenPage&rdm='+Math.random()+'&survey=' + p_pollid;
	var myAjax = $.ajax({url : ajaxurl,type: 'get',dataType: 'xml',success: showWebPoll});
}
function getRB(form,rbName) {
	rbFld=eval('form.'+rbName);
	for (var i = 0; i < rbFld.length; i++) {
		if (rbFld[i].checked == true) {
			return rbFld[i];
		}
	}
	return rbFld
}
$(document).ready(getWebPolls);
