var IE = (navigator.userAgent.indexOf("MSIE") != -1);
var ieMode = (document.documentMode ? parseInt(document.documentMode) : 0);
//var IE8 = (document.documentMode && parseInt(document.documentMode) > 7);
var cookieENABLED = navigator.cookieEnabled;
var ENABLE = false;
var colorVersion = {
"WHITE"		:{"bg":"#ffffff", "border":"#c0c0c0", "color": "#555555", "title": "#555555", "bar_frame":"#777777", "bar":"#eeeeee", "bar_font": "#222222", "max_rgb":"128.128.128"},
"BEIGE"		:{"bg":"#ffebcd", "border":"#ff9966", "color": "#555555", "title": "#555555", "bar_frame":"#ff8032", "bar":"#ffcf43", "bar_font": "#444444", "max_rgb":"255.127.0"},
"YELLOW1"	:{"bg":"#ffff99", "border":"#ffa042", "color": "#555555", "title": "#555555", "bar_frame":"#ff8032", "bar":"#ffcf43", "bar_font": "#444444", "max_rgb":"255.127.0"},
"YELLOW2"	:{"bg":"#ffff77", "border":"#99ee88", "color": "#555555", "title": "#555555", "bar_frame":"#00cc44", "bar":"#c6ff8e", "bar_font": "#444444", "max_rgb":"0.194.96"},
"YELLOW3"	:{"bg":"#ffdf8f", "border":"#ffaf60", "color": "#444444", "title": "#555555", "bar_frame":"#ff8032", "bar":"#ffffb7", "bar_font": "#444444", "max_rgb":"255.95.0"},
"ORANGE1"	:{"bg":"#ffad5b", "border":"#ff6b6b", "color": "#444444", "title": "#555555", "bar_frame":"#f95656", "bar":"#ffe797", "bar_font": "#444444", "max_rgb":"248.48.48"},
"ORANGE2"	:{"bg":"#ff7f00", "border":"#ff3d3d", "color": "#ffffff", "title": "#ffffff", "bar_frame":"#ff3d3d", "bar":"#ffd5c0", "bar_font": "#444444", "max_rgb":"255.158.148"},
"RED1"		:{"bg":"#ff7a7a", "border":"#ff2299", "color": "#ffffff", "title": "#ffffff", "bar_frame":"#f01ff5", "bar":"#ffc1ff", "bar_font": "#444444", "max_rgb":"255.128.255"},
"RED2"		:{"bg":"#ffd8d0", "border":"#ff6b6b", "color": "#555555", "title": "#333333", "bar_frame":"#ff4b4b", "bar":"#ffffd9", "bar_font": "#444444", "max_rgb":"255.191.74"},
"RED3"		:{"bg":"#ffcce7", "border":"#ef829c", "color": "#555555", "title": "#555555", "bar_frame":"#cd5bff", "bar":"#f3e5ff", "bar_font": "#444444", "max_rgb":"255.56.155"},
"PINK"		:{"bg":"#ffe5e5", "border":"#ff9ece", "color": "#555555", "title": "#555555", "bar_frame":"#f57eae", "bar":"#ffffee", "bar_font": "#444444", "max_rgb":"255.56.155"},
"PURPLE1"	:{"bg":"#f3d3ff", "border":"#c489ff", "color": "#555555", "title": "#555555", "bar_frame":"#4439ff", "bar":"#ccccff", "bar_font": "#ffffff", "max_rgb":"128.96.198"},
"PURPLE2"	:{"bg":"#d2d2ff", "border":"#6666ff", "color": "#555555", "title": "#ffffff", "bar_frame":"#6666ff", "bar":"#efeaff", "bar_font": "#ffffff", "max_rgb":"64.64.250"},
"PURPLE3"	:{"bg":"#6666ff", "border":"#d6d6ff", "color": "#ffffff", "title": "#555555", "bar_frame":"#00ffff", "bar":"#e0ffff", "bar_font": "#444444", "max_rgb":"122.188.255"},
"BLUE1"		:{"bg":"#0055ff", "border":"#aacfff", "color": "#ffffff", "title": "#555555", "bar_frame":"#aa88ff", "bar":"#d7dfff", "bar_font": "#444444", "max_rgb":"164.164.255"},
"BLUE2"		:{"bg":"#a5e5ff", "border":"#0055ff", "color": "#555555", "title": "#ffffff", "bar_frame":"#0055ff", "bar":"#eaf4ff", "bar_font": "#ffffff", "max_rgb":"0.81.245"},
"BLUE3"		:{"bg":"#ddeeff", "border":"#2288ff", "color": "#555555", "title": "#ffffff", "bar_frame":"#008888", "bar":"#eaffff", "bar_font": "#ffffff", "max_rgb":"32.96.245"},
"BLUE4"		:{"bg":"#ccffff", "border":"#00dddd", "color": "#555555", "title": "#555555", "bar_frame":"#00a4c6", "bar":"#dfffdf", "bar_font": "#444444", "max_rgb":"0.164.198"},
"GREEN1"	:{"bg":"#ccffdd", "border":"#00ddc5", "color": "#555555", "title": "#555555", "bar_frame":"#00aaaa", "bar":"#ddffff", "bar_font": "#444444", "max_rgb":"0.198.198"},
"GREEN2"	:{"bg":"#beff80", "border":"#68be8d", "color": "#555555", "title": "#555555", "bar_frame":"#00a6c6", "bar":"#bbfff8", "bar_font": "#444444", "max_rgb":"0.198.128"},
"GREEN3"	:{"bg":"#99ffee", "border":"#00cccc", "color": "#555555", "title": "#555555", "bar_frame":"#00b696", "bar":"#ddf9ff", "bar_font": "#ffffff", "max_rgb":"0.128.172"},
"GREEN4"	:{"bg":"#009580", "border":"#a5ffd0", "color": "#ffffff", "title": "#555555", "bar_frame":"#00ffff", "bar":"#e0ffff", "bar_font": "#444444", "max_rgb":"24.198.98"}
};
function spGadgetVote(jsn){
	var gadget = new dataWrite(jsn);
}
function dataWrite(jsn){
	if(!document.getElementById('spGadgetCornerCss')) addCornerCss();
	this.$qid = jsn._vote_id;
	this.$cd = jsn.cd;
	this.$key = jsn.key;
	this.$host = jsn.host;
	this.$cookie_str = jsn.cookie_str;
	this.$setColorType(jsn.colorType);
	this.$piece = (jsn.piece ? jsn.piece : '1');
	this.$edge = jsn.edge;
	this.$lineBold = jsn.lineBold;
	this.$gType = (jsn.gType ? jsn.gType : '0');
	this.$gMove = (jsn.gMove ? true : false);
	this.$w = Number(jsn.w ? jsn.w : '200');
	this.$title = jsn.title;
	this.$question = jsn.question;
	this.$term_from = jsn.term_from;
	this.$term_to = jsn.term_to;
	this.$ans_list = jsn.ans_list;
	this.$total_count = jsn.total_count;
	this.$max_count = jsn.max_count;
	this.$button_value = jsn.button_value.replace(/\\/g, '\\\\').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&').replace(/&quot;/g, '\\"');
	this.$title_link = jsn.title_link;
	this.$question_link = jsn.question_link;
	this.$gOnly = (jsn.gOnly ? true : false);
	this.$test = (jsn.test ? true : false);
	this.$term_stat = Number(jsn.term_stat);
	this.$noRslt = jsn.noRslt;
	this.$endRslt = jsn.endRslt;
	this.$per = (jsn.per == 't');
	this.$SWB = (jsn.SWB == 't');
	if(this.$test && this.$ans_list) this.$total_count = 100 * this.$ans_list.length + (this.$ans_list.length * (this.$ans_list.length - 1) * 10) / 2;
	this.$cssName = ('style' + this.$cd).toLowerCase();
	this.$classAdd();
	this.$parDiv = document.getElementById(this.$cd);
	this.$parDiv.style.width = this.$w + 'px';
	this.$parDiv.style.height = 'auto';
	this.$tblOuter = document.createElement('table');
	this.$tblOuter.id = 'tblOuter' + this.$cd;
	this.$tblOuter.style.width = this.$w + 'px';
	this.$tblOuter.style.height = 'auto';
	this.$parDiv.appendChild(this.$tblOuter);
	var trOuter = this.$tblOuter.insertRow(0);
	var tdOuter = trOuter.insertCell(0);
	trOuter.style.width = this.$w + 'px';
	trOuter.style.height = 'auto';
	tdOuter.style.width = this.$w + 'px';
	tdOuter.style.height = 'auto';
	tdOuter.style.textAlign = 'center';

	this.$cornerWrite( 'head', tdOuter);
	this.$tblMain = this.$createTable(tdOuter);

	if(!jsn.ERR){
		if(document.getElementById(this.$cd + 'b'))
			this.$parDiv.removeChild(document.getElementById(this.$cd + 'b'));
		
		if(this.$title){
			this.$titleWrite(this.$title, this.$title_link);
			this.$questionWrite(this.$question, this.$question_link);
		}else {
			this.$titleWrite(this.$question, this.$question_link);
		}
//termWrite()
		if(!(this.$term_stat == 0 && this.$endRslt) && (jsn.addid || this.$gOnly)){
			this.$totalWrite();
			this.$graphWrite();
			this.$footerWrite2();
		}else {
			this.$anserWrite();
			this.$footerWrite();
		}
	}
	
	this.$cornerWrite('foot', tdOuter);
	this.$parDiv.className = 'txtdef';
	this.$parDiv.style.left = '0px';
	this.$parDiv.style.top = '0px';
	this.$parDiv.style.position = 'relative';
}
dataWrite.prototype.$classAdd = function(){
  var rules = [['.' + this.$cssName , 'font-size: 12px; color: ' + colorVersion[this.$colorType].color + '; background-color: ' + colorVersion[this.$colorType].bg + '; text-align: left; width: auto; height: auto; margin: 0px; padding: 0px;']
							 ,["#tblOuter" + this.$cd, "border-width:0;"]
							 ,["#tblOuter" + this.$cd + " table", "border-width:0;"]
							 ,["#tblOuter" + this.$cd + " td", "border-width:0;"]
  							 ,["#enq" + this.$qid + " table", "border-width:0;"]
  							 ,["#enq" + this.$qid + " td", "border-width:0;"]
  							];
	var styles = document.getElementsByTagName('style');
	var style = null;
	if(styles && styles.length > 0){
		style = styles[styles.length - 1];
	}else{
		style = document.createElement('style');
		style.type = "text/css";
		document.getElementsByTagName('head')[0].appendChild(style);
	}

	if(IE) for(var i=0; i<rules.length; i++) document.styleSheets[document.styleSheets.length -1].addRule(rules[i][0] , rules[i][1] );
	else for(var i=0; i<rules.length; i++) style.sheet.insertRule(rules[i][0] + '{' + rules[i][1] + '}', style.sheet.cssRules.length);
};
dataWrite.prototype.$setColorType = function(type){
	if(type == null || colorVersion[type] == 'undefined' || !colorVersion[type]) this.$colorType = "WHITE";
	else this.$colorType = type;
};
dataWrite.prototype.$cornerWrite = function(mode, tdOuter){
	var rpre;
	if(this.$edge == "t" && this.$lineBold == "t") rpre = 'r1';
	else  rpre = 'r0';
	var corner = document.createElement('b');
	corner.className = 'rtop';
	tdOuter.appendChild(corner);
	
	if( mode == 'head'){
		for(var i=0; i <= 6; i++){
			var r = document.createElement('b');
			corner.appendChild(r);

			r.className = rpre + '0' + i.toString();
			if(this.$piece == '1'){
				if(this.$edge){
					r.style.backgroundColor = colorVersion[this.$colorType].border;
					if(i > 0){
						var rr = document.createElement('b');
						r.appendChild(rr);
						rr.className = rpre + '1' + i.toString();
						rr.style.backgroundColor = colorVersion[this.$colorType].bg;
					}
				}else { r.style.backgroundColor = colorVersion[this.$colorType].bg; }
			}else { r.style.backgroundColor = colorVersion[this.$colorType].border; }
		}
	}else {
		for(var i=6; i >=0; i--){
			var r = document.createElement('b');
			corner.appendChild(r);

			r.className = rpre + '0' + i.toString();
			if(this.$edge){
				r.style.backgroundColor = colorVersion[this.$colorType].border;
				if(i > 0){
					var rr = document.createElement('b');
					r.appendChild(rr);
					rr.className = rpre + '1' + i.toString();
					rr.style.backgroundColor = colorVersion[this.$colorType].bg;
				}
			}else { r.style.backgroundColor = colorVersion[this.$colorType].bg; }
		}
	}
};
dataWrite.prototype.$createTable = function( td ){
	var tbl = document.createElement('table');
	tbl.setAttribute(IE && ieMode < 8 ? 'cellSpacing' : 'cellspacing', '0');
	tbl.className= this.$cssName;
	tbl.style.width = this.$w + 'px';
	tbl.id = 'enq' + this.$qid;
	tbl.align = 'center';
	tbl.style.backgroundColor = colorVersion[this.$colorType].bg;
	tbl.style.color = colorVersion[this.$colorType].color;
	td.appendChild(tbl);
	return tbl;
};
dataWrite.prototype.$titleWrite = function(title, link){
	var line;
	if(this.$edge && this.$lineBold) line = ' 2px '; else line = ' 1px ';
	var tr = this.$tblMain.insertRow(this.$tblMain.rows.length);
	var td = tr.insertCell(0);
	tr.className = this.$cssName;
	td.className = this.$cssName;
	td.style.fontWeight = 'bold';
	td.style.padding = '0.3em 0em 0.3em 0.45em';
	td.style.textAlign = 'left';
	if(link && link.length > 0){
		var a = document.createElement('a');
		a.className = 'ancdef';
		a.href = link;
		a.title = link;
		a.alt = link;
		a.target = '_blanc';
		a.innerHTML = title;
		td.appendChild(a);
	}else{
		td.innerHTML = title;
	}
	
	if(this.$edge) {
		td.style.borderLeft = 'solid' + line + colorVersion[this.$colorType].border;
		td.style.borderRight = 'solid' + line + colorVersion[this.$colorType].border;
	}

	if(this.$piece == '1'){
		td.style.color = colorVersion[this.$colorType].color;
		td.style.backgroundColor = colorVersion[this.$colorType].bg;
		var hr = document.createElement('hr');
		hr.size = '1px';
		hr.align = 'center';
		hr.width = this.$w - 10;
		hr.noshade = false;
		td.appendChild(hr);
	}else{
		td.style.color = colorVersion[this.$colorType].title;
		td.style.backgroundColor = colorVersion[this.$colorType].border;
	}
};
dataWrite.prototype.$questionWrite = function(question, link){
	var line;
	if(this.$edge && this.$lineBold) line = ' 2px ';
	else line = ' 1px ';

	var tr = this.$tblMain.insertRow(this.$tblMain.rows.length);
	var td = tr.insertCell(0);
	tr.className = this.$cssName;
	td.className = this.$cssName;
	td.style.fontWeight = 'bold'
	td.style.paddingLeft = '0.8em';
	td.style.paddingBottom = '0.4em';
	td.style.textAlign = 'left';
	if(this.$piece == '2') td.style.paddingTop = '0.5em';
	if(this.$edge) {
		td.style.borderLeft = 'solid' + line + colorVersion[this.$colorType].border;
		td.style.borderRight = 'solid' + line + colorVersion[this.$colorType].border;
	}
	
	if(link && link.length > 0){
		var a = document.createElement('a');
		a.className = 'ancdef';
		a.href = link;
		a.title = link;
		a.alt = link;
		a.target = '_blanc';
		a.innerHTML = question;
		td.appendChild(a);
	}else{
		td.innerHTML = question;
	}
};
dataWrite.prototype.$anserWrite = function(){
	if(!this.$ans_list) return;

	var line;
	if(this.$edge && this.$lineBold) line = ' 2px ';
	else line = ' 1px ';

	for(i=0;i<this.$ans_list.length;i++){
		var tr = this.$tblMain.insertRow(this.$tblMain.rows.length);
		var td = tr.insertCell(0);
		tr.className = this.$cssName;
		td.className = this.$cssName;
		td.style.padding = '0.2em 0em 0.2em 0.5em';
		td.style.verticalAlign = 'top';
		td.style.textAlign = 'left';
		if(this.$edge) {
			td.style.borderLeft = 'solid' + line + colorVersion[this.$colorType].border;
			td.style.borderRight = 'solid' + line + colorVersion[this.$colorType].border;
		}
		
		if(IE && ieMode < 8) {
			var ans_id = document.createElement('<input type="radio" name="ans_id' + this.$cd + '">');
		}else {
			var ans_id = document.createElement('input');
			ans_id.type = 'radio';
			ans_id.name = 'ans_id' + this.$cd;
		}
		ans_id.className = 'inpdef';
		ans_id.id = 'ans_id' + this.$cd + '_' + this.$ans_list[i]._ans_id;
		ans_id.value = this.$ans_list[i]._ans_id;
		td.appendChild(ans_id);
		
		var a = document.createElement('a');
		a.className = 'ancdef';
		a.style.verticalAlign = 'top';
		a.style.paddingLeft = '0.25em'
		if(this.$ans_list[i].link && this.$ans_list[i].link.length > 0){
			a.href = this.$ans_list[i].link;
			a.title = this.$ans_list[i].link;
			a.alt = this.$ans_list[i].link;
			a.target = '_blanc';
		}
		
		a.innerHTML = this.$ans_list[i].anser;
		td.appendChild(a);
	}
};
dataWrite.prototype.$footerWrite = function(){
	var line;
	if(this.$edge && this.$lineBold) line = ' 2px ';
	else line = ' 1px ';

	var tr = this.$tblMain.insertRow(this.$tblMain.rows.length);
	var td = tr.insertCell(0);
	tr.className = this.$cssName;
	td.className = this.$cssName;
	td.style.textAlign = 'center';
	td.style.paddingTop = '0.8em';
	if(this.$edge) {
		td.style.borderLeft = 'solid' + line + colorVersion[this.$colorType].border;
		td.style.borderRight = 'solid' + line + colorVersion[this.$colorType].border;
	}

	var btn = document.createElement(IE && ieMode < 8 ? '<input name="btn">' : 'input');
	btn.className = 'inpdef';
	btn.style.backgroundColor = '#fafafa';
	var btn_id = 'button_GadgetVote_qid' + this.$qid + this.$cd;
	btn.type = 'button';
	btn.id = btn_id;
	btn.name = btn_id;
	td.appendChild(btn);
	setTimeout('btnStateChange("' +this.$qid + '","' + this.$cd + '",' + this.$test + ',"' + this.$button_value + '","' + this.$term_to + '",' + this.$term_stat + ',"' + this.$cookie_str + '",' + this.$SWB + ')' , 200);
	
	tr = this.$tblMain.insertRow(this.$tblMain.rows.length);
	td = tr.insertCell(0);
	tr.className = this.$cssName;
	td.className = this.$cssName;
	td.style.textAlign = 'center';
	td.style.paddingTop = '0.35em';
	if(this.$edge) {
		td.style.borderLeft = 'solid' + line + colorVersion[this.$colorType].border;
		td.style.borderRight = 'solid' + line + colorVersion[this.$colorType].border;
	}
	
	var dispRslt = 0;
	if(this.$test){
		if(this.$noRslt || this.$endRslt) dispRslt = -1;
	}else if(this.$endRslt || this.$SWB){
		dispRslt = (this.$term_stat > 0 ? 1 : -1);
	}else if(this.$noRslt){
		if(this.$term_stat == 0) dispRslt = (hasVoted(this.$cookie_str) ? 0 : -1);
		else dispRslt = this.$term_stat;
	}else{
		dispRslt = this.$term_stat
	}

	if(dispRslt == 0){
		var anc = document.createElement('a');
		anc.className = 'ancdef';
		anc.href = "javaScript:gOnly('" + this.$cd + "'," + this.$test + ")";
		anc.innerHTML = '途中経過を見る';
		td.appendChild(anc);
	}else if(dispRslt > 0){
		var anc = document.createElement('a');
		anc.className = 'ancdef';
		anc.href = "javaScript:gOnly('" + this.$cd + "'," + this.$test + ")";
		anc.innerHTML = '結果を見る';
		td.appendChild(anc);
	}else{
		this.$tblMain.deleteRow(this.$tblMain.rows.length - 1);
	}
/*	
	if((this.$test && this.$noRslt != 't') || (this.$term_stat == 0 && (hasVoted(this.$cookie_str) && !this.$SWB || this.$noRslt != 't'))){
		var anc = document.createElement('a');
		anc.setAttribute(IE && ieMode < 8 ? 'className' : 'class', 'ancdef');
		anc.href = "javaScript:gOnly('" + this.$cd + "'," + this.$test + ")";
		anc.innerHTML = '途中経過を見る';
		td.appendChild(anc);
	}else if(this.$term_stat > 0){
		var anc = document.createElement('a');
		anc.setAttribute(IE && ieMode < 8 ? 'className' : 'class', 'ancdef');
		anc.href = "javaScript:gOnly('" + this.$cd + "'," + this.$test + ")";
		anc.innerHTML = '結果を見る';
		td.appendChild(anc);
	}else{
		this.$tblMain.deleteRow(this.$tblMain.rows.length - 1);
	}
*/
};
dataWrite.prototype.$footerWrite2 = function(){
	var line;
	if(this.$edge && this.$lineBold) line = ' 2px ';
	else line = ' 1px ';

	tr = this.$tblMain.insertRow(this.$tblMain.rows.length);
	td = tr.insertCell(0);
	tr.className = this.$cssName;
	td.className = this.$cssName;
	td.style.textAlign = 'center';
	td.style.paddingTop = '0.5em';
	if(this.$edge) {
		td.style.borderLeft = 'solid' + line + colorVersion[this.$colorType].border;
		td.style.borderRight = 'solid' + line + colorVersion[this.$colorType].border;
	}
	
	var anc = document.createElement('a');
	anc.className = 'ancdef';
	anc.href = "javaScript:votePage('" + this.$cd + "'," + this.$test + ")";
	anc.innerHTML = '戻る';
	td.appendChild(anc);
};
dataWrite.prototype.$totalWrite = function(){
	var line;
	if(this.$edge && this.$lineBold) line = ' 2px ';
	else line = ' 1px ';

	var tr = this.$tblMain.insertRow(this.$tblMain.rows.length);
	var td = tr.insertCell(0);
	tr.className = this.$cssName;
	td.className = this.$cssName;
	td.style.paddingRight = '0.7em';
	td.style.paddingBottom = '0.2em';
	td.style.textAlign = 'right';
	
	td.style.fontSize = '11px';
	td.innerHTML = '総投票数' + this.$total_count;
	if(this.$edge) {
		td.style.borderLeft = 'solid' + line + colorVersion[this.$colorType].border;
		td.style.borderRight = 'solid' + line + colorVersion[this.$colorType].border;
	}
};
dataWrite.prototype.$termWrite = function(){
	if(this.$term_from && this.$term_to) {
		var line;
		if(this.$edge && this.$lineBold) line = ' 2px ';
		else line = ' 1px ';

		var tr = this.$tblMain.insertRow(this.$tblMain.rows.length);
		var td = tr.insertCell(0);
		td.style.paddingRight = '8px';
		td.setAttribute('align', 'right');
		td.style.fontSize = '11px';
		td.innerHTML = this.$term_from.substr(0,10) + '&#xff5e;' + this.$term_to.substr(0,10) + '&nbsp;';
		if(this.$edge) {
			td.style.borderLeft = 'solid' + line + colorVersion[this.$colorType].border;
			td.style.borderRight = 'solid' + line + colorVersion[this.$colorType].border;
		}
	}
};
dataWrite.prototype.$graphWrite = function(){
	if(!this.$ans_list) return;
	
	if(this.$test){
		for(var i=0; i<this.$ans_list.length; i++) this.$ans_list[i].count = 100 + 10 * i;
		this.$max_count = this.$ans_list[this.$ans_list.length - 1].count;
	}
	var side;
	if(this.$edge && this.$lineBold) side = ' 2px ';
	else side = ' 1px ';
	var gradation = ['ffadad', 'ffa4d0', 'ffadff', 'ee94ff', 'd6adff', 'bbadff', 'a3aaff', '9ec8ff', '99deff', '77ffff', '40ffcf', '7fff7f', '9ff409', 'afff00', 'ffff00', 'ffdf66', 'ffbf34', 'ff9f55', 'ff7f6e', 'ff85a8'];
	var gradation2 = ['ff1919', 'ff0099', 'ff19ff', 'cc00ff', '8c19ff', '6600ff', '4242ff', '0f87ff', '00ccff', '22ffff', '00ffaf', '00ff00', '1fee00', 'afee00', 'f9f900', 'ffcc33', 'ffa500', 'ff7f00', 'ff6347', 'ff6666'];
	var colorShift = Math.round(100/this.$ans_list.length);
	var max_size = this.$per ? this.$w - 15
					: (this.$max_count < 5 ? this.$w / 4 : (this.$max_count < 10 ? this.$w / 3 : (this.$max_count < 20 ? this.$w / 3 * 2 : this.$w)))  - 15;
	for(i=0;i<this.$ans_list.length;i++){
		var tr = this.$tblMain.insertRow(this.$tblMain.rows.length);
		var td = tr.insertCell(0);
		tr.className = this.$cssName;
		td.className = this.$cssName;
		td.style.padding = '0.1em 0em 0.2em 0.5em';
		td.style.textAlign = 'left';
		if(this.$edge) {
			td.style.borderLeft = 'solid' + side + colorVersion[this.$colorType].border;
			td.style.borderRight = 'solid' + side + colorVersion[this.$colorType].border;
		}
		var ans = document.createElement('div');
		ans.className = this.$cssName;
		if(this.$ans_list[i].link && this.$ans_list[i].link.length > 0){
			var a = document.createElement('a');
			a.className = 'ancdef';
			a.href = this.$ans_list[i].link;
			a.title = this.$ans_list[i].link;
			a.alt = this.$ans_list[i].link;
			a.target = '_blanc';
			a.innerHTML = this.$ans_list[i].anser;
			ans.appendChild(a);
		}else{
			ans.innerHTML = this.$ans_list[i].anser;
		}
		td.appendChild(ans);
		
		var ans_id = this.$cd + 'ans' + this.$ans_list[i]._ans_id;
		var size = (this.$max_count == 0 ? 0 : Math.round(this.$ans_list[i].count * max_size /this.$max_count));
		
		var graph = document.createElement('div');
		graph.style.position = 'relative';
		graph.style.height = '14px';
		graph.className = this.$cssName;
		graph.id = ans_id;
		barStyleSet(graph, this.$gType, this.$colorType);

		if(this.$ans_list[i].count != '0'){
//			graph.style.textAlign = 'right';
			switch(this.$gType){
				case '0': /* 箱グラフ */
					graph.style.border = '1px solid ' + colorVersion[this.$colorType].bar_frame;
					graph.style.backgroundColor = colorVersion[this.$colorType].bar;
					break;
				case '1': /* 淡色グラデーショングラフ（濃-->淡） */
					var rgb = colorVersion[this.$colorType].max_rgb.split('.');
					r = Number(rgb[0]) + i * colorShift;
					g = Number(rgb[1]) + i * colorShift;
					b = Number(rgb[2]) + i * colorShift;
					graph.style.backgroundColor = 'rgb(' + r + ', ' + g + ', ' + b + ')';
					break;
				case '2': /* 虹グラデーショングラフ（淡） */
					graph.style.backgroundColor = '#' + gradation[i];
//					graph.style.backgroundColor = '#' + gradation[Math.round(20/this.$ans_list.length * i)];
					graph.style.textAlign = 'right';
					graph.style.color = '#666666';
					graph.style.fontSize = '10px';
					break;
				case '3': /* 虹グラデーショングラフ（淡） */
					graph.style.backgroundColor = '#' + gradation2[i];
//					graph.style.backgroundColor = '#' + gradation2[Math.round(20/this.$ans_list.length * i)];
					graph.style.textAlign = 'right';
					graph.style.color = '#ffffff';
					graph.style.fontSize = '10px';
					break;
				default: break;
			}
		}
		td.appendChild(graph);
		var cap_str = (this.$per ? fomatDigit(Math.round( this.$ans_list[i].count * 1000 / this.$total_count) / 10, -1) + '%' : this.$ans_list[i].count.toString());
		
		if(this.$gMove) drawnGraph(ans_id, size, 0, cap_str);
		else { graph.style.width = (size.toString() + 'px'); setCaption(ans_id, cap_str); }
	}
};
function fomatDigit(num, digit){
	if(isNaN(num)) num = 0;
	var s = num.toString().split('.');
	if(digit > 0) while(s[0].length < digit) s[0] = '0' + s[0];
	else if(digit < 0){
		digit = -1 * digit;
		if(s.length < 2) s[1] = '0';
		while(s[1].length < digit) s[1] = s[1] + '0';
	}
	return s[0] + (s.length > 1 ? '.' + s[1] : '');
}
function setCaption(id, caption){
	var ele = document.getElementById(id);
	var cap = document.createElement('div');
	var ele_w = parseInt(ele.style.width);
	var pad = caption.charAt(caption.length - 1) != '%';
	cap.appendChild( document.createTextNode(caption));
	cap.style.font = 'italic 10px Verdana';
	cap.style.margin = "0";
	cap.style.padding = "0";
	cap.style.position = "absolute";
	cap.style.left = "0px";
	cap.style.top = "0px";
	ele.appendChild(cap);
	var w = parseInt(cap.offsetWidth) + (pad ? 5 : 0);
	if(ele_w > w) cap.style.left = (ele_w - w) + 'px';
}
function barStyleSet(bar, type, colorType){
	if(type == '1') bar.style.color = colorVersion[colorType].bar_font;
	else bar.style.color = '#444444';
}
function drawnGraph(id, max, count, caption) {
	var ele = document.getElementById(id);
	if(ele) ele.style.width = count.toString() + "px";
	count += 2;
	if (count < max) setTimeout("drawnGraph(\"" + id + "\"," + max + "," + count + ",\"" + caption + "\");", 1);
	else setCaption(id, caption);
}
function srcChange(btn, qid, cd, test, expireDate, cookie_str){
	if(test){
		alert('サンプル画面では動作しません。');
		return;
	}

	var div = document.getElementById(cd);
	var script = document.getElementById(cd + 'js');
	var script_src = script.src;
	var ans_ids = document.getElementsByName('ans_id' + cd);
	var addid;
	for(var i=0; i<ans_ids.length; i++){
		if(ans_ids[i].checked) {
			addid = ans_ids[i].value;
			break;
		}
	}
	
	if(!addid){
		alert('回答が選択されていません');
		return;
	}else{
		var parDiv = document.getElementById(cd);
		var script = document.getElementById(cd + 'js');
		var e = script.charset;
		var src = script.src + '&act=post&addid=' + addid;
		var tblOuter = document.getElementById('tblOuter' + cd);
		
		parDiv.removeChild(tblOuter);
		parDiv.removeChild(script);

		script  = document.createElement( 'script' );
		script.type = 'text/javascript';
		if(e) script.charset = e;
		script.src = src;
		script.id = cd + 'js';
		
		cookieSave(cookie_str, expireDate);

		parDiv.appendChild(script);
	}
}
function gOnly(cd, test){
	if(test){
		alert('サンプル画面では動作しません。');
		return;
	}

	var parDiv = document.getElementById(cd);
	var script = document.getElementById(cd + 'js');
	var e = script.charset;
	var src = script.src + '&gOnly=t';
	var tblOuter = document.getElementById('tblOuter' + cd);

	parDiv.removeChild(tblOuter);
	parDiv.removeChild(script);

	script  = document.createElement( 'script' );
	script.type = 'text/javascript';
	if(e) script.charset = e;
	script.src = src;
	script.id = cd + 'js';

	parDiv.appendChild(script);
}
function votePage(cd, test){
	if(test){
		alert('サンプル画面では動作しません。');
		return;
	}

	var parDiv = document.getElementById(cd);
	var script = document.getElementById(cd + 'js');
	var e = script.charset;
	var src = '';
	if(script.src.indexOf('&gOnly=t') > 0) {
		var splt_src = script.src.split('&gOnly=t');
		for(var i=0;i<splt_src.length;i++) src += splt_src[i];
	}else if(script.src.indexOf('&addid=') > 0){
		var splt_src = script.src.split('&addid=');
		src = splt_src[0];
		if(splt_src.length > 1 && splt_src[1].split('&').length > 1) src += ('&' + splt_src[1].split('&')[1]);
	}
	var tblOuter = document.getElementById('tblOuter' + cd);

	parDiv.removeChild(tblOuter);
	parDiv.removeChild(script);

	script  = document.createElement( 'script' );
	script.type = 'text/javascript';
	if(e) script.charset = e;
	script.src = src;
	script.id = cd + 'js';

	parDiv.appendChild(script);
}
function btnStateChange(qid, cd, test, btn_value, expireDate, term_stat, cookie_str, SWB){
	var btn_id = 'button_GadgetVote_qid' + qid + cd;
	var btn = document.getElementById(btn_id);
	
	if(term_stat < 0 && !test){
		btn.value = '準備中';
		btn.disabled = true;
		btn.style.color = '#aaaaaa';
	}else if(term_stat > 0 && !test){
		btn.value = '終了しました';
		btn.disabled = true;
		btn.style.color = '#aaaaaa';
	}else if(hasVoted(cookie_str) && !test && !SWB){
		btn.value = '投票済み';
		btn.disabled = true;
		btn.style.color = '#aaaaaa';
	}else{
		var onclick = 'srcChange(this, \"' + qid  + '\", \"' + cd + '\", ' + test + ',"' + expireDate + '","' + cookie_str +'")';
		btn.value = btn_value;
		if(IE && ieMode < 8) btn.setAttribute('onclick', new Function(onclick));
		else btn.setAttribute('onClick', onclick);
	}
	btn.style.width = (btn.value.length * 16 + 20 ) + 'px';
} 
function hasVoted(cookie_str){
	if(cookieENABLED){ /* クッキーが有効なら */
		var allcookies = document.cookie;
		var data = null;
		var start = allcookies.indexOf(cookie_str);
		if(start != -1) return true;
	}
	return false;
}
function cookieSave(cookie_str, expireDate){
	var expires = (new Date(expireDate.replace("-", "\/").replace("-", "\/"))).toUTCString();
	if(cookieENABLED){
		var cookie = cookie_str + "; expires=" + expires;
		document.cookie = cookie;
	}
}
function entity(txt){
	var rslt = '';
	for(var i=0; i<txt.length; i++) rslt = (rslt + '&#' + txt.charCodeAt(i) + ';');
	if(IE && ieMode < 8) return txt;
	return rslt;
}
function addCornerCss(){
	var rules = [[".txtdef","font-size:12px; background-color: transparent; color: inherit; width: auto; height: auto; margin: 0px; padding: 0px;"]
				, [".ancdef","font-size:12px; background-color: transparent; width: auto; height: auto; margin: 0px; padding: 0px;"]
				, [".inpdef","font-size:12px; background-color: transparent; color: black; width: auto; height: auto; margin: 0px; padding: 0px;"]
				, [".holdiv","position: absolute; z-index: 1000; text-align: left; white-space: nowrap; padding: 2px; margin: 0px; "
							+ "background-color: #eeffee; color: #ff4444; width: auto; height: auto; font-size: 12px; cursor: auto; visibility: hidden;"]
				, [".rtop","display:block; width:100%; height: auto; margin: 0px; padding: 0px;"]
				, [".r000","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 10px; line-height: 1px; font-size: 1px;"]
				, [".r001","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 7px; line-height: 1px; font-size: 1px;"]
				, [".r002","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 5px; line-height: 1px; font-size: 1px;"]
				, [".r003","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 4px; line-height: 1px; font-size: 1px;"]
				, [".r004","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 3px; line-height: 1px; font-size: 1px;"]
				, [".r005","display: block; overflow: hidden; padding: 0px; width: auto; height: 2px; margin: 0 2px; line-height: 1px; font-size: 1px;"]
				, [".r006","display: block; overflow: hidden; padding: 0px; width: auto; height: 2px; margin: 0 1px; line-height: 1px; font-size: 1px;"]
				, [".r011","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 3px; line-height: 1px; font-size: 1px;"]
				, [".r012","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 2px; line-height: 1px; font-size: 1px;"]
				, [".r013","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 1px; line-height: 1px; font-size: 1px;"]
				, [".r014","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 1px; line-height: 1px; font-size: 1px;"]
				, [".r015","display: block; overflow: hidden; padding: 0px; width: auto; height: 2px; margin: 0 1px; line-height: 1px; font-size: 1px;"]
				, [".r016","display: block; overflow: hidden; padding: 0px; width: auto; height: 2px; margin: 0 1px; line-height: 1px; font-size: 1px;"]
				, [".r100","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 9px; line-height: 1px; font-size: 1px;"]
				, [".r101","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 7px; line-height: 1px; font-size: 1px;"]
				, [".r102","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 5px; line-height: 1px; font-size: 1px;"]
				, [".r103","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 4px; line-height: 1px; font-size: 1px;"]
				, [".r104","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 3px; line-height: 1px; font-size: 1px;"]
				, [".r105","display: block; overflow: hidden; padding: 0px; width: auto; height: 2px; margin: 0 2px; line-height: 1px; font-size: 1px;"]
				, [".r106","display: block; overflow: hidden; padding: 0px; width: auto; height: 2px; margin: 0 1px; line-height: 1px; font-size: 1px;"]
				, [".r112","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 5px; line-height: 1px; font-size: 1px;"]
				, [".r113","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 4px; line-height: 1px; font-size: 1px;"]
				, [".r114","display: block; overflow: hidden; padding: 0px; width: auto; height: 1px; margin: 0 3px; line-height: 1px; font-size: 1px;"]
				, [".r115","display: block; overflow: hidden; padding: 0px; width: auto; height: 2px; margin: 0 2px; line-height: 1px; font-size: 1px;"]
				, [".r116","display: block; overflow: hidden; padding: 0px; width: auto; height: 2px; margin: 0 2px; line-height: 1px; font-size: 1px;"]
	];
	var style = document.createElement('style');
	style.type = 'text/css';
	style.id = 'spGadgetCornerCss';
	document.getElementsByTagName('head')[0].appendChild(style);
	if(IE) for(var i=0; i<rules.length; i++) document.styleSheets[document.styleSheets.length - 1].addRule(rules[i][0] , rules[i][1] );
	else for(var i=0; i<rules.length; i++)style.sheet.insertRule(rules[i][0] + '{' + rules[i][1] + '}', style.sheet.cssRules.length);
}
/* 以下未使用 */
function Pobject(name){
	if(!name) {
		name = window.location.pathname;
		var pos = name.lastIndexOf("/");
		if(pos != -1) name = name.substring(pos + 1);
	}
	this.$name = name;
	this.$init();
}

Pobject.prototype.$init = function() {
	if(cookieENABLED){ /* クッキーが有効なら */
		Pobject.prototype.$saveCOOKIE = function(s, expireDate) {
			var cookie = this.$name + '=' + s;
			if(expireDate) cookie +="; expires=" + (new Date(expireDate)).toUTCString();
			document.cookie = cookie;
		};
	}

	Pobject.prototype.$save = function(s, expireDate){
		if(s && expireDate){
			if(cookieENABLED) this.$saveCOOKIE(s, expireDate);
		}
	};
};
/* 保存されたプロパティティを読み込む */
Pobject.prototype.$parse = function(s, type){
	if(s){
		var props = s.split('&');
		for(var i=0; i<props.length; i++) {
			var p = props[i].split(':');
			this[p[i][0]] = p[i][1];
		}
	}
};

Pobject.prototype.exists = function(){
	if(cookieENABLED){ /* クッキーが有効なら */
		var allcookies = document.cookie;
		var data = null;
		var start = allcookies.indexOf(this.$name + '=');
		if(start != -1) return true;
	}

};
/* Pobjectのプロパティティ保存 */
Pobject.prototype.save = function(expireDate){
	expireDate = expireDate.replace("-", "\/").replace("-", "\/");
	this.$save(this.$name + ':t', expireDate);
};
/* 保存されたプロパティティを消去する */
Pobject.prototype.forget = function() {
	for(var name in this){
		if(name.charAt(0) == "$") continue;
		var value = this[name];
		var type = typeof value;
		if(type == "function" || type == "object") continue;
		delete this[name];
	}
	this.$save("", 0);
};

Pobject.prototype.test = function(){
	var s = "";
	for(var name in this){
		if(name.charAt(0) == "$") continue;
		var value = this[name];
		var type = typeof value;
		//オブジェクト型や関数型のプロパティティは保存対象外
		if(type == "function" || type == "object") continue;
		if(s.length > 0) s += "\n";		//プロパティティを\nで区切
		s += (this.$name + ':' + value + "(" + type + ")");
	}
};
spGadgetVote({"_vote_id":"319","button_type":"1","button_value":"投票","question":"下記より一つお選びください。","term_stat":"0","key":"mdn-nbt","host":"reg34.smp.ne.jp","term_from":"2017-04-28 16:00","term_to":"2017-06-07 23:30","title":"口座に振り込まれたお給料、どのように確認しますか？","cd":"1HHT9Epdo-l-mdn-nbt","colorType":"","w":"180","piece":"1","gType":"2","encode":"Shift_JIS","cookie_str":"smp_gadget_vote_key_mdn-nbt=1493624602878_72f5ca9d4a99a53765a0eb833cb3fe32","spgk":"1HHT9Epdo-l-mdn-nbt","vote_status":"0","ans_list":[{"_ans_id":"4869","anser":"給料日当日にインターネットバンキングで確認する","count":"121","link":""},{"_ans_id":"4870","anser":"給料日から1週間以内にインターネットバンキングで確認する","count":"80","link":""},{"_ans_id":"4871","anser":"給料日当日にATMで確認する","count":"41","link":""},{"_ans_id":"4872","anser":"給料日から1週間以内にATMで確認する","count":"47","link":""},{"_ans_id":"4873","anser":"給料日当日にアグリゲーションサービスで確認する","count":"5","link":""},{"_ans_id":"4874","anser":"給料日から1週間以内にアグリゲーションサービスで確認する","count":"3","link":""},{"_ans_id":"4875","anser":"確認をしたことがない","count":"72","link":""}],"max_count":"121","total_count":"369"})