var poll_skin = "default";
var poll_seqid;
function submitPoll() {
	var checkValue = 0;
	for (var i = 0; i < document.ajax_poll_frm.ajax_radio_poll.length; i ++) {
		if (document.ajax_poll_frm.ajax_radio_poll[i].checked) {
			checkValue = document.ajax_poll_frm.ajax_radio_poll[i].value;
			break;
		}
	}

	ajaxHttpRequest("http://event.ijji.com/poll.nhn?seqid=" + poll_seqid + "&answer=" + checkValue, "drawPoll");
}

function drawPoll(json) {
	if (json.showInput) {
		drawInputPoll(json);
	} else {
		drawResultPoll(json);
	}
}

function getPoll(seqid, skin) {
	poll_skin = skin;
	poll_seqid = seqid;
	ajaxHttpRequest("http://event.ijji.com/poll.nhn?seqid=" + poll_seqid, "drawPoll");
}

function draw(view) {
	document.getElementById("ajax_poll").innerHTML = view;
}

function drawResultPoll(json) {
	var pollResultView = "";
	pollResultView +='<div class="section5">';
	pollResultView +='	<h3><img src="http://images.ijji.com/v3/lunia/main/h_poll.gif" width="23" height="7" alt="POLL" /></h3>';
	pollResultView +='	<div class="box_type">';
	pollResultView +='		<p>' + json.poll.question + '</p>';
	pollResultView +='		<ul class="list_type">';

	for (var i = 0; i < json.poll.answers.length; i++) {
		pollResultView +='<li><img src="http://images.ijji.com/v3/lunia/main/num' + (i+1) + '.gif" width="9" height="9" alt="1" />';
		pollResultView +='<span>&nbsp;' + json.poll.answers[i] + ' (' + json.poll.rates[i] + '%)</span>';
		pollResultView +='<div class="progress_bar"><div style="width:' + json.poll.rates[i] + '%;"></div></div>';
		pollResultView +='</li>';
	}

	pollResultView +='		</ul>';
	//pollResultView +='		<div class="btn"><a href="#"><img src="http://images.ijji.com/v3/lunia/main/btn_vote.gif" width="46" height="16" alt="Vote" /></a></div>';
	pollResultView +='	</div>';
	pollResultView +='</div>';

	draw(pollResultView);
}

function drawInputPoll(json) {
	var pollInputView = "";
	pollInputView +='<form name="ajax_poll_frm" style="margin:0;padding:0">';
	pollInputView +='<div class="section5">';
	pollInputView +='	<h3><img src="http://images.ijji.com/v3/lunia/main/h_poll.gif" width="23" height="7" alt="POLL" /></h3>';
	pollInputView +='	<div class="box_type">';
	pollInputView +='		<p>' + json.poll.question + '</p>';
	pollInputView +='		<ul class="list_type2">';

	for (var i = 0; i < json.poll.answers.length; i++) {
		
		pollInputView +='<li><input type="radio" name="ajax_radio_poll" value="' + i + '">';
		pollInputView +='<label for="ajax_radio_poll' + i + '" >' + json.poll.answers[i] + '</label>';
		pollInputView +='</li>';
	}
	
	pollInputView +='		</ul>';
	pollInputView +='		<div class="btn"><a href="javascript:void(submitPoll());"><img src="http://images.ijji.com/v3/lunia/main/btn_vote.gif" width="46" height="16" alt="Vote" /></a></div>';
	pollInputView +='	</div>';
	pollInputView +='</div>';
	pollInputView +='</form>';

	draw(pollInputView);
}