//-------------------------------------------------------------//
// The Drawing Board                                           //
// Sketch Javascript Library                                   //
// Version 1.0 - 080829 - jjo                                  //
// Copyright 2008 The Drawing Board                            //
// Unauthorised use of this library is not permitted           //
//-------------------------------------------------------------//

var Sketch = new Class();

Sketch.Placeholder = new Class({
	Implements: [Events, Options],
	
	options: {
		InputSelector: null,
		OverClass: null
	},
	
	initialize: function(options){
		
		this.setOptions(options);
		
		var InputSelector = this.options.InputSelector;
		var OverClass = this.options.OverClass;
		var ParentForm = null;
		
		$$(InputSelector).each(function(item, index) {
			item.setProperty('value','');
			item.addEvents({
				focus: function(){
					thisOne = item;
					val = thisOne.getProperty('value');
					if (val == thisOne.getProperty('title')) {
						thisOne.setProperty('value', '');
						thisOne.removeClass(OverClass);
					}
				},
				
				blur: function(){
					thisOne = item;
					if (thisOne.getProperty('value').length) {
						thisOne.removeClass(OverClass);
					}
					else {
						thisOne.setProperty('value', thisOne.getProperty('title'));
						thisOne.addClass(OverClass);
					}
				}
			});
			item.fireEvent('blur');
		});
		
		$$(InputSelector)[0].form.addEvent('submit', function() {
			$$(InputSelector).each(function(item, index) {
				if (item.getProperty('value') == item.getProperty('title')) {
					item.setProperty('value', '');
				}
			});
		return true;
		});
	}
});

Sketch.AutoComplete = new Class({
	Implements: [Events, Options],
	
	options: {
		InputId: null,
		LookupService: null
	},
	
	initialize: function(options){
		
		this.setOptions(options);

		var InputId = this.options.InputId;
		var LookupService = this.options.LookupService;
		
		$(InputId).addEvent('keyup', function(e) {
			var keycode = window.event ? e.keycode : e.which;
			this.value = this.value + keycode;
		});
	}
});
