makePreview = function (_formId) {
	var cookie = new HTTP.Cookies();
	this.formId = _formId;
	this.elem = $(this.formId);
	this.icon_color   = cookie.read('tbw_icon_color')   || 'orange';
	this.station      = cookie.read('tbw_station')      || 1;
	this.onair_time   = cookie.read('tbw_onair_time')   || 1;
	this.target       = cookie.read('tbw_target')       || '_self';
	this.float        = cookie.read('tbw_float')        || 'none';
	this.text_align   = cookie.read('tbw_text_align')   || 'left';
	this.margin       = cookie.read('tbw_margin')       || '0px';
	this.padding      = cookie.read('tbw_padding')      || '0px';
	this.width        = cookie.read('tbw_width')        || 'auto';
	this.height       = cookie.read('tbw_height')       || 'auto';
	this.border_style = cookie.read('tbw_border_style') || 'none';
	this.border_width = cookie.read('tbw_border_width') || 1;
	this.border_color = cookie.read('tbw_border_color') || '000000';
	this.bgcolor      = cookie.read('tbw_bgcolor')      || 'ffffff';
	this.linkcolor    = cookie.read('tbw_linkcolor')    || '0000ff';
	this.textcolor    = cookie.read('tbw_textcolor')    || '000000';
	this.link         = Form.Element.getValue('link');
	this.title        = Form.Element.getValue('title');
	this.startTime    = Form.Element.getValue('startTime');
	this.stationName  = Form.Element.getValue('stationName');
	/*
	this.entry_id     = this.parseString('entry_id')    || '';
	this.link         = this.parseString('link')        || 'http://www.tvblog.jp/';
	this.title        = this.parseString('title')       || 'テレビブログ';
	this.startTime    = this.parseString('startTime')   || '';
	this.stationName  = this.parseString('stationName') || '';
	*/
	return this;
};
makePreview.prototype.openTBW = function (ev) {
	if (!ev) ev = window.event;
	var tbw = $('tbw');
	tbw.style.position = 'absolute';
	tbw.style.display = 'block';
	tbw.style.width = '40em';
	tbw.style.left = ev.clientX + 'px';
	tbw.style.top = ev.clientY + 'px';
}
makePreview.prototype.closeTBW = function () {
	var tbw = $('tbw');
	tbw.style.display = 'none';
}
makePreview.prototype.parseString = function (key) {
	var string = location.search + '&';
	key += '=';
	var from = string.indexOf(key);
	if (from != -1) {
		var to = string.indexOf('&', from);
		var value = this.UnescapeUTF8(string.substring(from + key.length, to));
		return value;
	}
	return false;
}
makePreview.prototype.setForm = function () {
	this.setRadio('icon_color');
	this.setRadio('station');
	this.setRadio('onair_time');
	this.setRadio('target');
	this.setRadio('float');
	this.setRadio('text_align');
	this.setSelect('margin');
	this.setSelect('padding');
	this.setSelect('width');
	this.setSelect('height');
	this.setSelect('border_style');
	this.setSelect('border_width');
	$('border_color').value = this.border_color;
	$('bgcolor').value = this.bgcolor;
	$('linkcolor').value = this.linkcolor;
	$('textcolor').value = this.textcolor;
}
makePreview.prototype.setRadio = function (elemName) {
	var elem = Form.getInputs(this.elem, 'radio', elemName);
	for (var i = 0; i < elem.length; ++i) {
		if (elem[i].value == eval('this.\1'.replace('\1', elemName))) {
			elem[i].checked = true;
			break;
		}
	}
}
makePreview.prototype.setSelect = function (elemName) {
	var elem = $(elemName);
	for (var i = 0; i < elem.length; ++i) {
		if (elem[i].value == eval('this.\1'.replace('\1', elemName))) {
			elem[i].selected = true;
			break;
		}
	}
}
makePreview.prototype.getForm = function () {
	this.icon_color   = Form.Element.getValue('icon_color_orange') || Form.Element.getValue('icon_color_pink') || Form.Element.getValue('icon_color_black') || Form.Element.getValue('icon_color_blue') || Form.Element.getValue('icon_color_red');
	this.station      = Form.Element.getValue('station_on') || Form.Element.getValue('station_off');
	this.onair_time   = Form.Element.getValue('onair_time_on') || Form.Element.getValue('onair_time_off');
	this.target       = Form.Element.getValue('target_self') || Form.Element.getValue('target_blank');
	this.float        = Form.Element.getValue('float_none') || Form.Element.getValue('float_left') || Form.Element.getValue('float_right');
	this.text_align   = Form.Element.getValue('text_align_left') || Form.Element.getValue('text_align_center') || Form.Element.getValue('text_align_right');
	this.margin       = Form.Element.getValue('margin');
	this.padding      = Form.Element.getValue('padding');
	this.width        = Form.Element.getValue('width');
	this.height       = Form.Element.getValue('height');
	this.border_style = Form.Element.getValue('border_style');
	this.border_width = Form.Element.getValue('border_width');
	this.border_color = Form.Element.getValue('border_color');
	this.bgcolor      = Form.Element.getValue('bgcolor');
	this.linkcolor    = Form.Element.getValue('linkcolor');
	this.textcolor    = Form.Element.getValue('textcolor');
}
makePreview.prototype.makeHTML = function (nowElem) {
	this.getForm();
	var html = this.createHTML();
	$('copyarea').value = html;
	$('preview').innerHTML = html + 'あなたの文章。あなたの文章。あなたの文章。あなたの文章。あなたの文章。あなたの文章。あなたの文章。あなたの文章。あなたの文章。あなたの文章。あなたの文章。あなたの文章。';
	//new Insertion.Top('preview', html);
	this.setCookie(nowElem);
}
makePreview.prototype.setCookie = function (nowElem) {
	if (typeof(nowElem) == 'undefined') return;
	var name = nowElem.name.replace(/_pl$/, '');
	var cookie = new HTTP.Cookies();
	cookie.write('tbw_' + name, eval('this.\1'.replace('\1', name)), '+1M');
}
makePreview.prototype.pl2box = function (nowElem) {
	nowElem.nextSibling.value = nowElem.value;
}
makePreview.prototype.createHTML = function () {
	var html =
		'<div style="width:%1; height:%2; color:%3; background-color:%4; float:%5; border:%6 %7 %8; margin:%9; padding:%10; text-align:%11;">' +
		'<a href="http://www.tvblog.jp/" target="%12"><img src="http://www.tvblog.jp/img/tb2tvblog/icon_%13.gif" alt="tvblog_icon" width="24" height="33" border="0" style="margin:1ex; float:left;" /></a>' +
		'<p style="margin:0px;"><a href="%14" target="%12" style="color:%15; text-decoration:none;">%16</a></p>' +
		'<p style="margin:0px;">%17 %18</p>' +
		'<p style="margin:0px;"><a href="http://www.tvblog.jp/" target="%12" style="color:#666666; text-decoration:none;">Trackbacked to テレビブログ http://www.tvblog.jp/</a></p>' +
		'</div>';
	return html
		.replace('%1', this.height)
		.replace('%2', this.width)
		.replace('%3', '#' + this.textcolor)
		.replace('%4', '#' + this.bgcolor)
		.replace('%5', this.float)
		.replace('%6', this.border_style)
		.replace('%7', this.border_width + 'px')
		.replace('%8', '#' + this.border_color)
		.replace('%9', this.margin)
		.replace('%10', this.padding)
		.replace('%11', this.text_align)
		.replace(/%12/g, this.target)
		.replace('%13', this.icon_color)
		.replace('%14', this.link)
		.replace('%15', '#' + this.linkcolor)
		.replace('%16', this.title)
		.replace('%17', (this.station == 1) ? this.stationName : '')
		.replace('%18', (this.onair_time == 1) ? this.startTime : '');
}
makePreview.prototype.UnescapeUTF8 = function (str) {
	return str.replace(/%(E(0%[AB]|[1-CEF]%[89AB]|D%[89])[0-9A-F]|C[2-9A-F]|D[0-9A-F])%[89AB][0-9A-F]|%[0-7][0-9A-F]/ig,function(s){
		var c=parseInt(s.substring(1),16);
		return String.fromCharCode(c<128?c:c<224?(c&31)<<6|parseInt(s.substring(4),16)&63:((c&15)<<6|parseInt(s.substring(4),16)&63)<<6|parseInt(s.substring(7),16)&63)
	})
};
toggleTBW = function () {
	var tbw = $('tbw');
	tbw.style.display = (tbw.style.display == 'none') ? 'block' : 'none';
}
toggleSetup = function () {
	var setup = $('setup');
	setup.style.display = (setup.style.display == 'none') ? 'block' : 'none';
}
