/*

	Lost Boys 2005.
	
	De inhoud van dit bestand is in opdracht vervaardigd en eigendom van onze opdrachtgever.
	Niet hergebruiken zonder toestemming.
	Neem voor vragen contact op met Lost Boys, www.lostboys.nl.

	The contents of this file have been produced for and are the property of our client.
	Do not reuse without permission.
	Any questions? Please contact Lost Boys, www.lostboys.nl.

*/

function TransformSelects() {
	var selects = document.getElementsByTagName("select");
	var statics = new Array(selects.length);
	for (var i=0; i < selects.length; i++) statics[i] = selects[i];

	for (var i=0; i < statics.length; i++) {
		if (statics[i].className && (statics[i].className.indexOf("DS") != -1)) {
//			if (statics[i].id) new DesignSelect(statics[i].id);
			new DesignSelect(statics[i]);
		}
	}
}
function DesignSelect(DOMselect) {
//	this.id = id;
	this.transform(DOMselect);
	this.status.onclick = this.toggle;
}
DesignSelect.prototype.toggle = function (e) {
	if (window.document.onclick) window.document.onclick();
	this.parent.options.style.display = (this.parent.options.style.display == "block") ? "none" : "block";
	var opened = this.parent.options;
	window.document.onclick = function () {
		opened.style.display = "none";
		window.document.onclick = null;
	}
	var e = (e) ? e : window.event;
	e.cancelBubble = true;
	return false;
}
DesignSelect.prototype.select = function () {
	this.parent.statusText.innerHTML = this.innerHTML;
	this.parent.value.value = this.value;
	this.parent.options.style.display = "none";
	this.className = "";
	if (this.parent.from.onchange) this.parent.from.onchange();
}
DesignSelect.prototype.transform = function (from) {
	this.selector = document.createElement("div");
	this.selector.className = from.className;

	this.status = document.createElement("div");
	this.status.className = "status";
	this.status.parent = this;

	this.statusText = document.createElement("span");
	this.statusText = this.status.appendChild(this.statusText);

	this.value = document.createElement("input");

	if (from.id) this.value.id = from.id;
	this.value.type = "hidden";
	this.value.name = from.name;

	this.options = document.createElement("div");
	this.options.className = "options";
	this.options.parent = this;

	var elements = from.getElementsByTagName("option");
	for (var i=0; i<elements.length; i++) {
		var span = document.createElement("span");
		span.innerHTML = elements[i].innerHTML;
		span.value = elements[i].value;
		span.parent = this;
		span.onclick = this.select;
		span.onmouseover = function () {this.className = "hover";}
		span.onmouseout  = function () {this.className = "";}
		span.Validators = from.Validators;
		this.options.appendChild(span);

		if (i==0 || elements[i].selected) {
			this.statusText.innerHTML = elements[i].innerHTML;
			this.value.value = elements[i].value;
		}
	}

	this.status = this.selector.appendChild(this.status);
	this.options = this.selector.appendChild(this.options);
	this.value = this.selector.appendChild(this.value);
	this.from = from.parentNode.replaceChild(this.selector, from);
}
