var openCVV2 = function() {
	OpenWin = this.open(context+"/cvv2.do", "Cvv2Window", 
	"width=640,height=380,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,statusbar=no");
};

var autoTab = function(input, length, e) {
	var filter = /^(0|8|9|16|17|18|37|38|39|40|46)$/;
	if(input.value.length >= length && !filter.test(e.keyCode)) {
		for (i=0; i<input.form.length; i++) {
			if (input.form[i] == input) input.form[i+1].focus();
		}
		return false;
	}
	return true;
};

var click = function(id) {
	dojo.byId(id).click();
};

var ie6 = dojo.render.html.ie50 || dojo.render.html.ie55 || dojo.render.html.ie60;

var webshop = {

	imageover: function(image) {
		if (image.src.indexOf('_focus') < 0)
		image.src = image.src.replace('.png','_hover.png');
	},
	imageout: function(image) {
		image.src = image.src.replace('_hover.png','.png');
		image.src = image.src.replace('_down.png','.png');
		image.className = image.className.replace('noshadow','shadow');
	},
	
	imagedown: function(image) {
		image.src = image.src.replace('_hover.png','_down.png');
		image.className = image.className.replace('shadow','noshadow');
	},
	imageup: function(image) {
		image.src = image.src.replace('_down.png','_hover.png');
		image.className = image.className.replace('noshadow','shadow');
	},
	
	imagefocus: function(id) {
		var image = dojo.byId(id);
		image.src = image.src.replace('.png','_focus.png');
	},
	imageblur: function(id) {
		var image = dojo.byId(id);
		image.src = image.src.replace('_focus.png','.png');
	},
	
	buttonover: function(button, event) {
		if (button.isdisabled) return;
		button.over = button.over + 1;
		if (button.over > 1) return;
		if (ie6) { 
			button.style.backgroundImage = dojo.html.getComputedStyle(button,"background-image");
			button.style.backgroundImage = button.style.backgroundImage.replace(/color=[0-9a-fA-F]{6}/,"color="+button.hoverColor.substring(1)); 
			(event||window.event).cancelBubble = "true"; 
		}
		if (button.anim) button.anim.stop(true);
		button.style.backgroundColor = button.hoverColor;
		button.style.borderColor = button.style.backgroundColor;
	},
	buttonout: function(button, event, test) {
		if (button.isdisabled) return;
		button.over = button.over - 1;
		if (button.over == 0 && !test) {
			if (ie6) { 
				button.style.backgroundImage = button.style.backgroundImage.replace(/color=[0-9a-fA-F]{6}/,"color="+button.color.substring(1));
				button.style.borderColor = button.color;
				(event||window.event).cancelBubble = "true"; 
			} else {
				if (button.anim) { 
					button.anim.stop(true);
				} else {
					button.anim = new dojo.lfx.Animation({
							onAnimate: function(c){
								button.style.backgroundColor = dojo.gfx.color.rgb2hex(coordsAsInts(c));
								button.style.borderColor = button.style.backgroundColor;
							}
						}, 200, new dojo.lfx.Line(coordsAsInts(dojo.html.getBackgroundColor(button)), dojo.gfx.color.hex2rgb(button.color))
					);
				}
				button.anim.play(true);
			}
			this.buttonshadow(button,true);
		}
	},
	
	buttondown: function(button, event) {
		if (button.isdisabled) return;
		if (ie6) button.style.backgroundImage = button.style.backgroundImage.replace(/color=[0-9a-fA-F]{6}/,"color="+button.downColor.substring(1));
		button.style.backgroundColor = button.downColor;
		button.style.borderColor = button.style.backgroundColor;
		this.buttonshadow(button,false);
	},
	buttonup: function(button, event) {
		if (button.isdisabled) return;
		if (ie6) button.style.backgroundImage = button.style.backgroundImage.replace(/color=[0-9a-fA-F]{6}/,"color="+button.hoverColor.substring(1));
		button.style.backgroundColor = button.hoverColor;
		button.style.borderColor = button.style.backgroundColor;
		this.buttonshadow(button,true);
	},
	
	buttonshadow: function(button, show) {
		var div = button.parentNode;
		var table = button.parentNode.parentNode.parentNode.parentNode;
		div.className = div.className.replace((show?"no":"")+"shadow",(show?"":"no")+"shadow");
		table.className = table.className.replace((show?"no":"")+"shadow",(show?"":"no")+"shadow");
	},
	
	enable: function(button) {
		if (button.isdisabled) {
			button.isdisabled = false;
			if (ie6) button.style.backgroundImage = button.style.backgroundImage.replace(/color=[0-9a-fA-F]{6}/,"color="+button.hoverColor.substring(1));
			button.style.backgroundColor = button.hoverColor;
			button.style.borderColor = button.style.backgroundColor;
			button.style.cursor = "";
			button.onclick = button.originalOnclick;
		}
	},
	
	disable: function(button) {
		button.isdisabled = true;
		if (button.anim) button.anim.stop(true);
		if (ie6) button.style.backgroundImage = button.style.backgroundImage.replace(/color=[0-9a-fA-F]{6}/,"color=999999");
		button.style.backgroundColor = this.colors["button.disabled"];
		button.style.borderColor = this.colors["button.disabled"];
		button.style.cursor = "default";
		button.originalOnclick = button.onclick;
		button.onclick = function() { return false; }
	},
	
	blend: function(a, b) {
		var hex = dojo.lang.isString(a);
		if (hex) {
			a = dojo.gfx.color.hex2rgb(a);
			b = dojo.gfx.color.hex2rgb(b);
		}
		if (b[0]+b[1]+b[2] < 384) {
			b = a;
		} else {
			a = dojo.gfx.color.rgb2hsv(a);
			b = dojo.gfx.color.rgb2hsv(b);
			b[0] = a[0];
			b[1] = (a[1] + b[1]) / 2;
			b[2] = (a[2] + b[2]) / 2;
			b = dojo.gfx.color.hsv2rgb(b);
		}
		if (hex) b = dojo.gfx.color.rgb2hex(b);
		return b;
	},
	
	check: function(text) {
		text.className = text.className == "checkbox" ? "checkbox_checked" : "checkbox";
		dojo.dom.prevElement(text).click();
	},
	
	selectTab: function(tabs, index) {
		if (index == undefined) index = tabs.initialTab;
		for (var i=0; i < tabs.rows[0].cells.length; i++) {
			var tab = tabs.rows[0].cells[i];
			var button = dojo.dom.firstElement(tab);
			if (index == i) {
				if (button.anim) button.anim.stop();
				tab.className = "selectedTab";
			} else if (tab.className == "selectedTab") {
				if (button.anim) button.anim.stop();
				tab.className = "";
				if (ie6) button.style.backgroundImage = "url('"+context+"/glass.do?color="+button.color.substring(1)+"')";
				button.style.backgroundColor = button.color;
				button.style.borderColor = button.style.backgroundColor;
			}
		}
		tabs.showTabBody(index);
		return false;
	},
	showTabBody: function(index) {
		for (var i=0; i<this.rows[0].cells.length; i++) {
			var tab = dojo.byId("tab["+i+"]");
			if (tab) tab.className = (i == index) ? "" : "hide";
		}
		//dojo.html.scrollIntoView(this);
	},
	
	ajaxUnavailable: function() {
		if (ajaxEnabled) {
			var xmlhttp = null;
			try { xmlhttp = dojo.hostenv.getXmlhttpObject(); } catch(e) {}
			return xmlhttp == null;
		} else {
			return true;
		}
	},

	toggleTour: function() {
		link    = dojo.byId("tourLink");
		content = dojo.byId("tourContent");
		if (this.ajaxUnavailable) {
			if (content.style.display == "none") {
				link.innerHTML = "Turn guided tour off";
				content.style.display = "block";
			} else {
				link.innerHTML = "Turn guided tour on";
				content.style.display = "none";
			}
		} else {
			ajax.toggleTour(function(data) {
				switch(data) {
					case 1:
						link.innerHTML = "Turn guided tour off";
						content.style.display = "block"; break;
					case 0:
						link.innerHTML = "Turn guided tour on";
						content.style.display = "none"; break;
				}
			});
		}
	}, 
	
	debug: function(msg) {
		setTimeout(function() { throw new Error("[debug] " + msg); }, 0);
	},
	
	validate: function(form,profile,errors,callback) {
		var i = 1;
		if (!errors || dojo.lang.isFunction(errors)) {
			callback = errors;
			errors = error;
		}
		for (var i=0; i<form.elements.length; i++) this.setValid(form.elements[i]);
		var check = dojo.validate.check(form,profile);
		if (check.isSuccessful()) {
			if (callback) callback();
			return true;
		} else if (check.hasMissing()) {
			alertError(errors["missing"]);
			var missing = check.getMissing();
			var components = profile.components ? profile.components[missing[0]] : null;
			if (components) form[components[0]].focus();
			else form[missing[0]].focus();
			for (var i=0; i<missing.length; i++) {
				components = profile.components ? profile.components[missing[i]] : null;
				if (components) for (var j=0; j<components.length; j++) this.setInvalid(form[components[j]]);
				else this.setInvalid(form[missing[i]]);
			}
			return false;
		} else if (check.hasInvalid()) {
			var invalid = check.getInvalid();
			alertError(errors[invalid[0]]);
			var components = profile.components ? profile.components[invalid[0]] : null;
			if (components) form[components[0]].focus();
			else form[invalid[0]].focus();
			for (var i=0; i<invalid.length; i++) {
				components = profile.components ? profile.components[invalid[i]] : null;
				if (components) for (var j=0; j<components.length; j++) this.setInvalid(form[components[j]]);
				else this.setInvalid(form[invalid[i]]);
			}
			return false;
		}
	},
	
	validateField: function(field,constraint) {
		var isValid = true;
		// case 1: constraint value is validation function
		if (dojo.lang.isFunction(constraint)) {
			isValid = constraint(field.value);
		} else if (dojo.lang.isArray(constraint)) {
			// handle nested arrays for multiple constraints
			if (dojo.lang.isArray(constraint[0])) {
				for (var i=0; i<constraint.length; i++) {
					isValid = dojo.validate.evaluateConstraint(null, constraint[i], null, field);
					if (!isValid) break;
				}
			} else {
				// case 2: constraint value is array, first elem is function, tail is parameters
				isValid = dojo.validate.evaluateConstraint(null, constraint, null, field);
			}
		}
		if (isValid) this.setValid(field); else this.setInvalid(field);
	},
	
	setValid: function(field) {
		if (field.type == "hidden") return;
		$($(field.parentNode).hasClass("tabTextField") ? field.parentNode : field).removeClass("invalidField");
	},
	
	setInvalid: function(field) {
		if (field.type == "hidden") return;
		$($(field.parentNode).hasClass("tabTextField") ? field.parentNode : field).addClass("invalidField");
	},
	
	selectMenuZIndex: 1000,
	selectMenusOpen: 0,
	
	toggleSelectMenu: function(select,forceHide,blur) {
		var visible = select.menu.style.display == "block";
		hide = forceHide || visible;
		select.menu.style.display = hide ? "none" : "block";
		if (!hide) {
			if (!select.menu.style.width) select.menu.style.width = dojo.html.getOuterWidth(select) + "px";
			select.menu.style.zIndex = this.selectMenuZIndex++;
			select.drop.style.backgroundImage = select.drop.style.backgroundImage ?
												select.drop.style.backgroundImage.replace("down","up") :
												dojo.html.getComputedStyle(select.drop,"background-image").replace("down","up");
			var selected = dojo.byId(select.id+"["+select.input.value+"]");
			if (!selected)
				selected = dojo.dom.firstElement(dojo.dom.firstElement(dojo.dom.firstElement(select.menu.rows[0].cells[0])).rows[0].cells[0]);
			if (selected) {
				dojo.html.scrollIntoView(selected);
				selected.focus();
			}
			this.selectMenusOpen++;
		} else if (visible) {
			select.drop.style.backgroundImage = select.drop.style.backgroundImage.replace("up","down");
			this.selectMenusOpen--;
			if (this.selectMenusOpen == 0 && !blur) select.drop.focus();
		}
		return hide;
	},
	
	toggleMenu: function(element) {
		window.clearTimeout(element.timer);
		if (dojo.html.hasClass(element,"open"))
			this.closeMenu(element);
		else
			this.openMenu(element);
	},
	
	openMenu: function(element,e,delay) {
		if (e && dojo.dom.isDescendantOf((e ? e : event).relatedTarget,element)) return;
		window.clearTimeout(element.timer);
		dojo.dom.lastElement(element).style.width = dojo.html.getOuterWidth(element)+"px";
		if (delay) {
			element.timer = window.setTimeout(
				function() { dojo.html.addClass(element,"open"); }
			, delay);
		} else {
			dojo.html.addClass(element,"open");
		}
	},
	
	closeMenu: function(element,e,delay) {
		if (e && dojo.dom.isDescendantOf((e ? e : event).relatedTarget,element)) return;
		window.clearTimeout(element.timer);
		if (delay) {
			element.timer = window.setTimeout(
				function() { dojo.html.removeClass(element,"open"); }
			, delay);
		} else {
			dojo.html.removeClass(element,"open");
		}
	}

}

// compatibility
var trim = dojo.string.trim;

var coordsAsInts = function(coords){
	var cints = [];
	dojo.lang.forEach(coords, function(c){ 
		cints.push(Math.round(c));
	});
	return cints;
};

// Glass Widgets (buttons,paging,tabs,etc)
var parseGlassWidgets = function(parent) {
	if (parent) parent = "#" + (parent instanceof String ? parent : parent.id) + " ";
	if (!parent) {
		query(".navigation a.glass", function(button) {
			button.noanimate = true;
		});
		query(".navigation .menuitem a.glass", function(button) {
			if (document.location.href.indexOf(button.href) > -1)
				dojo.html.addClass(button.parentNode,"currentMenuitem");
		});
	}
	query("h1,h2,.HeadingLabel", parent, function(element) {
		element = $(element);
		element.setStyles({
			'position': 'relative',
			'z-index': 2,
			'width': window.ie6 ? element.getWidth() + 'px' : 'auto'
		});
		element.clone(false).setStyles({
			'z-index': 1,
			'color': '#000000',
			'opacity': 0.2,
			'margin-top': (2 + element.getStyle('margin-top').toInt()) + 'px',
			'margin-bottom': '-' + (2 + element.getHeight()) + 'px'
		}).setHTML(element.getText()).injectBefore(element);
	});
	query("a.glass", parent, function(button) {
		if (!button.href) {
			button.href = "#"+button.textContent;
			if (button.onclick) {
				var onclick = button.onclick.toString();
				var begin = onclick.substring(0,onclick.indexOf("{")+1);
				var end = onclick.substring(onclick.indexOf("{")+1,onclick.length);
				eval("button.onclick = "+begin+" try {"+end+" catch(e) { alert(e.message); } this.blur(); return false; }");
			} else button.onclick = function(e) { this.blur(); return false; };
		}
		if (button.noanimate) return;
		if (!button.onmouseover) button.onmouseover = function(e) { webshop.buttonover(this,e); };
		if (!button.onmouseout) button.onmouseout = function(e) { webshop.buttonout(this,e,dojo.dom.isDescendantOf(e ? e.relatedTarget : event.toElement,this)); };
		if (!button.onmousedown) button.onmousedown = function(e) { webshop.buttondown(this,e); };
		if (!button.onmouseup) button.onmouseup = function(e) { webshop.buttonup(this,e); };
		if (!button.onfocus) button.onfocus = function(e) { webshop.buttonover(this,e); };
		if (!button.onblur) button.onblur = function(e) { webshop.buttonout(this,e); };
		if (!button.onkeydown) button.onkeydown = function(e) { if (/^(0|13|32)$/.test(e ? e.keyCode : event.keyCode)) webshop.buttondown(this,e); };
		if (!button.onkeyup) button.onkeyup = function(e) { if (/^(0|13|32)$/.test(e ? e.keyCode : event.keyCode)) webshop.buttonup(this,e); };
		if (!button.onkeypress) button.onkeypress = function(e) { if (/^(0|32)$/.test(e ? e.keyCode : event.keyCode)) { if (!this.onclick || this.onclick(e)) window.location.href = this.href; return false; } };
		button.onselectstart = function(e) { return false; };
		button.unselectable = "on";
		button.over = 0;
		button.color = dojo.gfx.color.rgb2hex(dojo.html.getBackgroundColor(button)).toUpperCase();
		button.hoverColor = webshop.colors["button.hover["+button.color+"]"];
		button.downColor = webshop.colors["button.active["+button.color+"]"];
		if (!button.hoverColor) {
			button.hoverColor = webshop.blend(webshop.colors["button.hover"],button.color);
			webshop.colors["button.hover["+button.color+"]"] = button.hoverColor;
			button.downColor = webshop.blend(webshop.colors["button.active"],button.color);
			webshop.colors["button.active["+button.color+"]"] = button.downColor;
		}
	});
	query(".tabs", parent, function(tabs) {
		if (tabs.rows[0].className != "tabrow") return;
		for (var i=0; i<tabs.rows[0].cells.length; i++) {
			var button = dojo.dom.firstElement(tabs.rows[0].cells[i]);
			button.onmousedown = function(e) { webshop.selectTab(this.parentNode.parentNode.parentNode.parentNode,this.parentNode.cellIndex); return false; };
			button.onmouseup = function(e) { return false; };
			button.onclick = button.onmouseup;
			button.onkeydown = function(e) { if (/(0|13|32)/.test(e ? e.keyCode : event.keyCode)) { this.onmousedown(e); return false; } };
			if (webshop.colors["tab.hover"] != "") button.hoverColor = webshop.colors["tab.hover"];
			if (webshop.colors["tab.active"] != "") button.downColor = webshop.colors["tab.active"];
		}
		if (!tabs.initialTab) tabs.initialTab = 0;
		if (!tabs.showTabBody) tabs.showTabBody = webshop.showTabBody;
		webshop.selectTab(tabs);
	});
	query(".paging a.glass", parent, function(page) {
		if (page.name) {
			page.onclick = null;
			var i = page.name;
			page.href = document.location.href;
			page.href = page.href.indexOf("page=") > 0 ? page.href.replace(/page=[\d]*/,"page="+i) : 
														 page.href+(page.href.indexOf("?") > 0 ? "&" : "?")+"page="+i;
		} else if (page.getAttribute("onclick") == null) {
			page.onclick = null;
			var i = page.name ? page.name : page.innerHTML;
			page.href = document.location.href;
			page.href = page.href.indexOf("page=") > 0 ? page.href.replace(/page=[\d]*/,"page="+i) : 
														 page.href+(page.href.indexOf("?") > 0 ? "&" : "?")+"page="+i;
		} else if (page.innerHTML.match(/^\d\d$/)) {
			var i = page.name;
			page.href = document.location.href;
			page.href = page.href.indexOf("page=") > 0 ? page.href.replace(/page=[\d]*/,"page="+i) : 
														 page.href+(page.href.indexOf("?") > 0 ? "&" : "?")+"page="+i;
		} else {
			page.href = "#";
		}
		if (webshop.colors["page.hover"] != "") page.hoverColor = webshop.colors["page.hover"];
		if (webshop.colors["page.active"] != "") page.downColor = webshop.colors["page.active"];
	});
	query(".menu", parent, function(td) {
		td.onmousedown = function(e) { webshop.openMenu(this); };
		td.onmouseover = function(e) { webshop.openMenu(this,e,250); };
		td.onmouseout = function(e) { webshop.closeMenu(this,e,250); };
	});
	query("table.select", parent, function(select) {
		select.value = dojo.byId(select.id+"Value");
		select.menu = dojo.byId(select.id+"Menu");
		select.input = dojo.byId(select.id+"Input");
		select.drop = dojo.dom.firstElement(select.rows[0].cells[1]);
		select.drop.onmouseover = select.drop.onmouseout = select.drop.onmousedown = select.drop.onmouseup = null;
		//select.onmouseout  = function(e) { var descendant = dojo.dom.isDescendantOf(e ? e.relatedTarget : event.toElement,this);
		//								   webshop.buttonout(this.drop,e,descendant); if (!descendant) { var select = this; this.timer = window.setTimeout(function() { webshop.toggleSelectMenu(select,true); }, 500); } };
		//select.onmouseover = function(e) { webshop.buttonover(this.drop,e); window.clearTimeout(this.timer); };
		select.onmouseout  = function(e) { var descendant = dojo.dom.isDescendantOf(e ? e.relatedTarget : event.toElement,this); webshop.buttonout(this.drop,e,descendant); };
		select.onmouseover = function(e) { webshop.buttonover(this.drop,e); };
		select.onmousedown = function(e) { webshop.buttondown(this.drop,e); };
		select.onmouseup   = function(e) { webshop.buttonup(this.drop,e); };
		select.onclick     = function(e) { webshop.toggleSelectMenu(this); };
		select.setValue = function(value) {
			dojo.byId(this.id+"["+value+"]").onclick();
		};
		if (webshop.colors["select.hover"] != "") select.drop.hoverColor = webshop.colors["select.hover"];
		if (webshop.colors["select.active"] != "") select.drop.downColor = webshop.colors["select.active"];
		var rows = dojo.dom.firstElement(dojo.dom.firstElement(select.menu.rows[0].cells[0])).rows;
		for (var i=0; i<rows.length; i++) {
			var button = $(rows[i].cells[0]).getFirst();
				button.select = select;
				button.addEvent('keydown',function(e) { 
					try { switch(e.key) {
						case 'esc':  e.preventDefault();
						case 'tab':  webshop.toggleSelectMenu(this.select,true); break;
						case 'right':
						case 'down': this.getParent().getParent().getNext().getFirst().getFirst().focus(); e.preventDefault(); break;
						case 'left':
						case 'up':   this.getParent().getParent().getPrevious().getFirst().getFirst().focus(); e.preventDefault(); break;
					} } catch(e) {}
				}.bindWithEvent(button));
		};
		(window.ie ? document : window).addEvent('mousedown', function(e) {
			if (window.ie) e.target = e.srcElement;
			if (this === e.target || this.hasChild(e.target)) return;
			webshop.toggleSelectMenu(this,true,true);
		}.bind(select));
	});
};

var query = function(queries,root,callback) {
	if (dojo.lang.isFunction(root)) {
		callback = root;
		root = null;
	}
	if (!root) root = "";
	dojo.lang.forEach(queries.split(","), function(query) {
		if (!query) return;
		dojo.lang.forEach(dojo.query(root+query), function(element) {
			if (!element) return;
			callback(element);
		});
	});
};

dojo.addOnLoad(function() {
	parseGlassWidgets();
	$$(".rating .picker").each(function(picker) {
		//new CozFX.RatingPicker(picker);
		picker.stars = 0;
		picker.rating = picker.getPrevious();
		picker.fillStars = function(stars) {
			if (!stars) stars = this.stars || 0;
			if (this.rating) this.rating.setStyle("display", stars == 0 ? "" : "none");
			this.getChildren().each(function(star) {
				star.className = star.i <= stars ? "hover" : "";
			});
		};
		picker.setStars = function(stars) {
			this.stars = stars;
			if (this.input) 
				this.input.value = stars;
			else if (this.no) 
				ajax.checkLogin(function(data){
					if (data) ajax.addRating(this.no, stars, function(data) {
						if (data[0]) alertMessage(data[1]); else alertError(data[1]);
					});
					else alertError("You must be logged in to use this feature.");
				}.bind(this));
		};
		if (picker.rating) 
			picker.getParent().addEvent("mouseenter", picker.rating.setStyle.pass(["display","none"],picker.rating));
		picker.addEvent("mouseleave", picker.fillStars.pass(0,picker));
		picker.getChildren().each(function(star) {
			star.i = picker.getChildren().indexOf(star) + 1;
			star.addEvent("mouseover", picker.fillStars.pass(star.i,picker));
			star.addEvent("click", picker.setStars.pass(star.i,picker));
		});
		var uFormats = picker.uFormats();
		picker.no = uFormats.no;
		picker.stars = uFormats.stars;
		var form = document[uFormats.form];
		picker.input = form ? form[uFormats.input] : null;
		picker.fillStars();
	});
	$$('.dateField').each(function(dateField){
		var options = dateField.uFormats();
		var input = dateField.getFirst();
		var button = input.getNext();
		if (!options.id) options.id = input.name;
		input.id = 'dateValue['+options.id+']';
		input.readOnly = true;
		input.addEvents({
			'focus': function(e) { webshop.buttonover(button,e); },
			'blur': function(e) { webshop.buttonout(button,e); },
			'click': function(e) { showDatePicker(options.id,input,options.date,options.allowWeekends); }
		});
		button.addEvents({
			'click': function(e) { showDatePicker(options.id,input,options.date,options.allowWeekends); }
		});
	});
	/*
	$$("span.select").each(function(select) {
		new CozFX.Select(select);
	});
		select.value = $(select.id+"Value");
		select.menu = $(select.id+"Menu");
		select.input = $(select.id+"Input");
		select.drop = select.rows[0].cells[1].getFirst();
		select.drop.onmouseover = select.drop.onmouseout = select.drop.onmousedown = select.drop.onmouseup = null;
		select.addEvent('mouseenter', webshop.buttonover.create([this.drop,e]));
		select.addEvent('mouseleave', webshop.buttonout.create([this.drop,e]));
		select.addEvent('mousedown',  webshop.buttondown.create([this.drop,e]));
		select.addEvent('mouseup',    webshop.buttonup.create([this.drop,e]));
		select.addEvent('mouseenter', window.clearTimeout.create(this.timer));
		select.addEvent('mouseleave', function(e) {
			this.timer = window.setTimeout(function() { webshop.toggleSelectMenu(this,true); }.bind(this), 500);
		}.bind(select));
		select.addEvent('click', webshop.toggleSelectMenu.create(this));
		select.setValue = function(value) {
			select.input.value
			$(select.id+"["+value+"]").onclick();
		};
		if (webshop.colors["select.hover"] != "") select.drop.hoverColor = webshop.colors["select.hover"];
		if (webshop.colors["select.active"] != "") select.drop.downColor = webshop.colors["select.active"];
		var rows = dojo.dom.firstElement(dojo.dom.firstElement(select.menu.rows[0].cells[0])).rows;
		for (var i=0; i<rows.length; i++) {
			var button = dojo.dom.firstElement(rows[i].cells[0]);
				button.select = select;
				button.onkeydown = function(e) { if ((e ? e.keyCode : event.keyCode) == 9) webshop.toggleSelectMenu(this.select,true); };
				button.onkeypress = function(e) {
					try { switch(e ? e.keyCode : event.keyCode) {
						case 32: this.onclick(e); return false; break;
						case 40: dojo.dom.firstElement(dojo.dom.nextElement(this.parentNode.parentNode).cells[0]).focus(); return false; break;
						case 38: dojo.dom.firstElement(dojo.dom.prevElement(this.parentNode.parentNode).cells[0]).focus(); return false; break;
					} } catch(e) {}
				};
		};
	});
	*/
});

//window.onclick = function(e) {
//	if (openPicker && openPicker.style.display != "none") {
//		dojo.lfx.html.fadeHide(openPicker,100).play();
//		openPicker = null;
//	}
//};