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://" + getServiceDomain("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, debug) {
	poll_skin = skin;
	poll_seqid = seqid;
	
	if (debug == 1) {
		json = {"showInput":false,"poll":{"seqid":"20070509_Favorite playing time_GZ","answers":["12 AM  - 8 AM ","8 AM  - 12 PM ","12 PM  - 3 PM ","3 PM  - 6 PM ","6 PM - 9 PM","9 PM - 12 AM "],"total":62516,"counts":[9020,5428,4609,17597,16921,8941],"rates":[16,8,7,28,27,14],"question":"What time of day do you like to play?"}};
	} else if (debug == 2) {
		json = {"showInput":true,"poll":{"seqid":"20070509_Favorite playing time_GZ","answers":["12 AM  - 8 AM ","8 AM  - 12 PM ","12 PM  - 3 PM ","3 PM  - 6 PM ","6 PM - 9 PM","9 PM - 12 AM "],"total":62516,"counts":[9020,5428,4609,17597,16921,8941],"rates":[16,8,7,28,27,14],"question":"What time of day do you like to play?"}};
	}
	else {
		ajaxHttpRequest("http://" + getServiceDomain("event.ijji.com") + "/poll.nhn?seqid=" + poll_seqid, "drawPoll");
	}
	
	// drawPoll(json);
}

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

function drawResultPoll(json) {
	var pollResultView = "";
	pollResultView +='<table width="140" border="0" cellspacing="0" cellpadding="0" bgcolor="#0C0C0C">';
	pollResultView +='\n\t<tr>';
	pollResultView +='\n\t\t<td align="center">';
	pollResultView +='\n\t\t\t<table width="100%" border="0" cellspacing="0" cellpadding="0">';
	pollResultView +='\n\t\t\t\t<tr>';
	pollResultView +='\n\t\t\t\t\t<td style="padding: 5px 4px 8px 4px;">';
	pollResultView +='\n\t\t\t\t\t\t<div style="background: url(http://images.ijjimax.com/v2/poll/poll_arw01_skid.gif) 0px 4px no-repeat; padding-left: 8px; font-family: verdana, tahoma, sans-serif; font-size: 9px; color: #FFFFFF;">' + json.poll.question + '</div>';
	pollResultView +='\n\t\t\t\t\t</td>';
	pollResultView +='\n\t\t\t\t</tr>';
	pollResultView +='\n\t\t\t\t<tr>';
	pollResultView +='\n\t\t\t\t\t<td style="padding: 9px 5px;">';
	pollResultView +='\n\t\t\t\t\t\t<table width="100%" border="0" cellspacing="0" cellpadding="0"  >';

	for (var i = 0; i < json.poll.answers.length; i++) {
		pollResultView +='\n\t\t\t\t\t\t\t<tr>';
		pollResultView +='\n\t\t\t\t\t\t\t\t<td>';
		pollResultView +='\n\t\t\t\t\t\t\t\t\t<div style="background: url(http://images.ijjimax.com/v2/poll/poll_dot_skid.gif) 0px 4px no-repeat; padding-left: 6px; font-family: verdana, tahoma, sans-serif; font-size: 9px; color: #FFFFFF;">' + json.poll.answers[i] + ' <strong>' + json.poll.rates[i] + '%</strong></div>';
		pollResultView +='\n\t\t\t\t\t\t\t\t</td>';
		pollResultView +='\n\t\t\t\t\t\t\t</tr>';
		pollResultView +='\n\t\t\t\t\t\t\t<tr> ';
		pollResultView +='\n\t\t\t\t\t\t\t\t<td style="padding: 2px 7px;">';
		pollResultView +='\n\t\t\t\t\t\t\t\t\t<table width="' + json.poll.rates[i] + '%" border="0" cellspacing="0" cellpadding="0">';
		pollResultView +='\n\t\t\t\t\t\t\t\t\t\t<tr>';
		pollResultView +='\n\t\t\t\t\t\t\t\t\t\t\t<td height="3" bgcolor="#E3AC0E"></td>';
		pollResultView +='\n\t\t\t\t\t\t\t\t\t\t</tr>';
		pollResultView +='\n\t\t\t\t\t\t\t\t\t</table>';
		pollResultView +='\n\t\t\t\t\t\t\t\t</td>';
		pollResultView +='\n\t\t\t\t\t\t\t</tr>';
	}

	pollResultView +='\n\t\t\t\t\t\t</table>';
	pollResultView +='\n\t\t\t\t\t</td>';
	pollResultView +='\n\t\t\t\t</tr>';
	pollResultView +='\n\t\t\t</table>';
	pollResultView +='\n\t\t</td>';
	pollResultView +='\n\t</tr>';
	pollResultView +='\n\t<tr>';
	pollResultView +='\n\t\t<td height="3" style="background: url(http://images.ijjimax.com/v2/poll/poll_btmimg_' + poll_skin + '.gif) top left repeat-x;"></td>';
	pollResultView +='\n\t</tr>';
	pollResultView +='\n</table>';

	draw(pollResultView);
	
	// document.write ('<textarea style=\"width: 1004px; height: 500px;\">' + pollResultView + '</textarea>');
}

function drawInputPoll(json) {
	var pollInputView = "";
	pollInputView +='<form name="ajax_poll_frm">';
	pollInputView +='<p>' + json.poll.question + '</p>';

	for (var i = 0; i < json.poll.answers.length; i++) {
		pollInputView +='\n\t\t\<div class="chk_choice"><input type="radio" name="ajax_radio_poll" value="' + i + '" /><label for="ajax_radio_poll' + i + '" > ' + json.poll.answers[i] + '</label></div>';
	}
	pollInputView +='          <div class="btns"><a href="javascript:void(submitPoll());"><img src="http://images.ijjimax.com/v3/drift/mainrenewal/btn_ok.jpg" width="25" height="15" border="0" alt="OK"></a></div>';
	pollInputView +='\n</form>';
	
	draw(pollInputView);
	
	//document.write ('<textarea style=\"width: 1004px; height: 500px;\">' + pollInputView + '</textarea>');
}