function BoxConfigurator(id, iframeUrl, noscriptUrl, noscriptText) {
	this.formObj = document.getElementById(id);
	this.iframeUrl = iframeUrl;
	this.noscriptUrl = noscriptUrl;
	this.noscriptText = noscriptText;
	this.catEList = new Array();
	this.btEList = new Array();
	for (var i = 0; i < this.formObj.elements.length; i ++) {
		var element = this.formObj.elements[i];
		var l = element.id.split("_");
		if (l.length < 2)
			continue;
		if ( (l.length == 2) && (l[0] == "cat") ) {
			this.catEList.push(element);
		} else if ( (l.length == 3) && (l[0] == "box") && (l[1] == "type") ) {
			this.btEList.push(element);
		}
	}

	this.onChangeSize(this.formObj.boxsize_width);
	Event.observe(this.formObj.boxsize_width, "change", this.onChangeSize.bind(this, this.formObj.boxsize_width, true), false);
	this.onChangeSize(this.formObj.boxsize_height);
	Event.observe(this.formObj.boxsize_height, "change", this.onChangeSize.bind(this, this.formObj.boxsize_height, true), false);
	this.onChangeColor(this.formObj.color_border);
	Event.observe(this.formObj.color_border, "change", this.onChangeColor.bind(this, this.formObj.color_border, true), false);
	this.onChangeColor(this.formObj.color_bg);
	Event.observe(this.formObj.color_bg, "change", this.onChangeColor.bind(this, this.formObj.color_bg, true), false);
	this.onChangeColor(this.formObj.color_fg);
	Event.observe(this.formObj.color_fg, "change", this.onChangeColor.bind(this, this.formObj.color_fg, true), false);
	this.onChangeCatAll();
	Event.observe(this.formObj.category_all_0, "click", this.onChangeCatAll.bind(this, this.formObj.category_all_0, true), false);
	Event.observe(this.formObj.category_all_1, "click", this.onChangeCatAll.bind(this, this.formObj.category_all_1, true), false);

	for (var i = 0; i < this.formObj.elements.length; i ++) {
		var element = this.formObj.elements[i];
		var l = element.id.split("_");
		if (l.length < 2)
			continue;
		if ( (l.length == 2) && (l[0] == "cat") ) {
			this.onChangeElse(element);
			Event.observe(element, "click", this.onChangeElse.bind(this, element, true), false);
		} else if ( (l.length == 3) && (l[0] == "box") && (l[1] == "type") ) {
			this.onChangeElse(element);
			Event.observe(element, "click", this.onChangeElse.bind(this, element, true), false);
		}
	}
	this.onChangeSize(this.formObj.news_limit);
	Event.observe(this.formObj.news_limit, "change", this.onChangeSize.bind(this, this.formObj.news_limit, true), false);
	this.onChangeSize(this.formObj.news_titlechars);
	Event.observe(this.formObj.news_titlechars, "change", this.onChangeSize.bind(this, this.formObj.news_titlechars, true), false);
	this.onChangeElse(this.formObj.box_type);
	//fixme// Event.observe(this.formObj.box_type, "click", this.onChangeElse.bind(this, this.formObj.box_type, true), false);
	this.onChangeElse(this.formObj.box_email);
	Event.observe(this.formObj.email, "change", this.onChangeElse.bind(this, this.formObj.email, true), false);

	Event.observe(this.formObj.code, "click", this.onSubmit.bind(this, this.formObj), false);
	Event.observe(this.formObj, "submit", this.onSubmit.bind(this, this.formObj), false);
	this.update();
	return;
}
BoxConfigurator.prototype.update = function () {
	var a = new Array();
	a.push("wd=" + this.formObj.boxsize_width.value);
	a.push("hg=" + this.formObj.boxsize_height.value);
	a.push("bgc=" + this.formObj.color_bg.value);
	a.push("lc=" + this.formObj.color_fg.value);
	a.push("boc=" + this.formObj.color_border.value);
	if (this.formObj.category_all_1.checked)
		a.push("cat=");
	else {
		var cat_list = new Array();
		for (var i = 0; i < this.catEList.length; i ++) {
			var element = this.catEList[i];
			var l = element.id.split("_");
			if (element.checked)
				cat_list.push(l[1]);
		}
		a.push("cat=" + cat_list.join(","));
	}
	var bt = "";
	for (var i = 0; i < this.btEList.length; i ++) {
		var element = this.btEList[i];
		if (element.checked)
			bt = element.value;
	}
	a.push("typ=" + bt);;
	a.push("cnt=" + this.formObj.news_limit.value);
	a.push("mxt=" + this.formObj.news_titlechars.value);
	a.push("mail=" + this.formObj.email.value);
	var s = a.join("&");
	s = encodeURIComponent(encodeBase64(s));

	var width = this.formObj.boxsize_width.value;
	var height = this.formObj.boxsize_height.value;
	var src = this.iframeUrl + "?code=" + s;

	var a = new Array();
	a.push("<" + "script type=\"text/javascript\"" + ">" + "<" + "!--");
	a.push("document.write('" + "<" + "iframe src=\"" + src + "\" width=\"" + width + "\" height=\"" + height + "\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"" + ">" + "<" + "/iframe" + ">');");
	a.push("//--" + ">" + "<" + "/script" + ">" + "<" + "noscript" + ">" + "<" + "a href=\"" + this.noscriptUrl + "\"" + ">" + this.noscriptText + "<" + "/a" + ">" + "<" + "/noscript" + ">");
	s = a.join("\n");

	this.formObj.code.value = s;

	var iframe = document.getElementById("sample");
	iframe.width = width;
	iframe.height = height;
	iframe.src = src + "&" + new Date().getTime();

	if ( navigator.appVersion.indexOf("MSIE") > -1 ) {
		Try.these(function(){$('footer').hide().show()});
	}

	return;
}
BoxConfigurator.prototype.onChangeElse = function (e, update) {
	if (update == true)
		this.update();
	return;
}
BoxConfigurator.prototype.onChangeCatAll = function (e, update) {
	for (var i = 0; i < this.catEList.length; i ++) {
		var element = this.catEList[i];
		element.disabled = this.formObj.category_all_1.checked ? "disabled" : "";
	}
	if (update == true)
		this.update();
	return;
}
BoxConfigurator.prototype.validateSize = function (s) {
	return (isNaN(parseInt(s)) == false);
}
BoxConfigurator.prototype.setValueSize = function (element, s) {
	element.value = s;
	return;
}
BoxConfigurator.prototype.onChangeSize = function (element, update) {
	var size = element.value;
	if (this.validateSize(size) == false)
		return;
	this.setValueSize(element, parseInt(size));
	if (update == true)
		this.update();
	return;
}
BoxConfigurator.prototype.validateColor = function (s) {
	var regexp = new RegExp("^[0-9A-F]{6}$", "i");
	return regexp.test(s);
}
BoxConfigurator.prototype.setValueColor = function (element, s) {
	element.style["backgroundColor"] = "#" + s;
	return;
}
BoxConfigurator.prototype.onChangeColor = function (element, update) {
	var color = element.value;
	if (!this.validateColor(color))
		return;
	var l = element.id.split("_");
	this.setValueColor(document.getElementById("sample_" + l[1]), color);
	if (update == true)
		this.update();
	return;
}
BoxConfigurator.prototype.onSubmit = function (element) {
	this.update();
	Field.activate(this.formObj.code);
	return false;
}


