
ChopStick.prototype.components = new Array();

ChopStick.prototype.windowComponentsMap = new Array();

ChopStick.prototype.windows = new Array();

ChopStick.prototype.debug = true;

ChopStick.prototype.preloadImages = null;

function ChopStick() {

	
	this.preloadImages = new Array();
	
	this.onload = window.onload;
	window.onload = function() {
		chopstick.documentLoaded();
	}
}

ChopStick.prototype.addComponent = function(component, windowId) {
	var set;
	
	this.components[component.getId()] = component;
	set = this.windowComponentsMap[windowId];
	if (set == null) {
		set = new Array();
		this.windowComponentsMap[windowId] = set;
		this.windows[this.windows.length] = windowId;
	}
	set[set.length] = component;
}

ChopStick.prototype.addPreloadImage = function(src) {

	if (!this.preloadImages[src]) {
		this.preloadImages[this.preloadImages.length] = src;
		this.preloadImages[src] = true;
	}
}

ChopStick.prototype.beginModal = function(windowId) {
	var set;

	for (var i = 0; i < this.windows.length; i++) {
		if (this.windows[i] != windowId) {
			set = this.windowComponentsMap[this.windows[i]];
			for (var j = 0; j < set.length; j++) {
				set[j].blocked = true;
			}
		}
	}
}

ChopStick.prototype.documentLoaded = function(e) {
	var src;
	var image;

	
	browserFrame.fireWindowCreatedEvent(e);
	browserFrame.fireWindowOpenEvent(e);
	if (this.onload != null) {
		this.onload();
	}
	for (var i = 0; i < this.windows.length; i++) {
		var win;
		
		win = this.components[this.windows[i]];
		if (win == null || win == browserFrame) continue;
		win.fireWindowCreatedEvent();
		if (win.isVisible()) {
			win.fireWindowOpenedEvent();
		}
	}
	
	for (var i = 0; i < this.preloadImages.length; i++) {
		src = this.preloadImages[i];
		image = new Image();
		image.src = this.preloadImages[i];
		this.preloadImages[i] = image;
	}
}

ChopStick.prototype.endModal = function(windowId) {
	var set;

	for (var i = 0; i < this.windows.length; i++) {
		if (this.windows[i] != windowId) {
			set = this.windowComponentsMap[this.windows[i]];
			for (var j = 0; j < set.length; j++) {
				set[j].blocked = false;
			}
		}
	}
}

ChopStick.prototype.getAction = function(actionName, eventListener) {
	var action;
	
	if (eventListener == null && !this.debug) {
		alert("No event listener for action " + actionName + ".");
		return null;
	}
	if (eventListener.actions == null) {
		eventListener.actions = new Array();
	}
	action = eventListener.actions[actionName];
	if (action == null) {
		action = new ChopStickAction(actionName, eventListener);
		eventListener.actions[actionName] = action;
	}
	return action;
}

ChopStick.prototype.getComponent = function(id) {

	return this.components[id];
}

var chopstick = new ChopStick();

ChopStick.prototype.initialFocusId;

function ChopStickInitialFocus(id) {
	this.initialFocusId = id;
}

ChopStickInitialFocus.prototype.windowOpened = function(e) {
	var c;

	if (this.initialFocusId) {
		c = chopstick.getComponent(this.initialFocusId);
		if (c != null && c.element != null && c.element.focus != null) {
			c.element.focus();
		}
	}
}

function Platform() {

	if (document.all) {
		this.init = this.initMS;
	}
	else if (document.getElementById) {
		this.init = this.initMZ;
	}
	else if (document.layers) {
		this.init = this.initNS;
	}
	else {
		this.init = this.initDefault;
	}	
	this.initCommon();
	this.init();
}

Platform.prototype.initCommon = function() {
}

Platform.prototype.initMS = function() {

	this.getElement = function(id) {
		return document.all[id];
	}
	
    this.getHeight = function(element) {
    	return element.offsetHeight;
    }
    
    this.getVisibility = function(id) {
        var elm = document.all[id];
        if (elm == null) return "";
        return elm.style.visibility;
    }
    
    this.isVisible = function(id) {
        var elm = document.all[id];
        if (elm == null) return false;
        return elm.style.visibility != "hidden";
    }
    
    this.getWidth = function(element) {
    	return element.offsetWidth;
    }
    
    this.getX = function(element) {
    	return element.offsetLeft;
    }
    
    this.getY = function(element) {
    	return element.offsetTop;
    }
    
    this.getWindowHeight = function() {
    	return document.body.clientHeight;
    }
    
    this.getWindowWidth = function() {
    	return document.body.clientWidth;
    }
    
    this.setHeight = function(element, h) {
    	element.style.pixelHeight = h;
    }
    
    this.setX = function(element, x) {
    	element.style.pixelLeft = x;
    }
    
    this.setY = function(element, y) {
    	element.style.pixelTop = y;
    }
    
    this.setVisible = function(id, visible) {
    	var elm = document.all[id];
    	if (elm == null) return;
    	elm.style.visibility = visible ? "" : "hidden";
        elm.style.display = visible ? "" : "none";
    }
    
    this.setWidth = function(element, w) {
    	element.style.setPixelWidth = w;
    }
    
    this.getInnerText = function(element) {
    
    	return element.innerText;
    }
    
    this.setInnerText = function(element, text) {
	   
		element.innerText = text;
    }

    this.getChildWindow = function(element) {
    	var cw;
    	
    	cw = element.contentWindow;
    	return cw;
    }
    	
}

Platform.prototype.initMZ = function() {

	this.getElement = function(id) {
		return document.getElementById(id);
	}
	
    this.getVisibility = function(id) {
        var elm = document.getElementById(id);
        if (elm == null) return "";
        return elm.style.visibility == "collapse" ? "hidden" : elm.style.visibility;
    }
    
    this.isVisible = function(id) {
        var elm = document.getElementById(id);
        if (elm == null) return "";
        return elm.style.visibility == "visible";
    }
    
    this.getX = function(element) {
    	return element.offsetLeft;
    }
    
    this.getY = function(element) {
    	return element.offsetTop;
    }
    
    this.getWidth = function(element) {
    	return element.offsetWidth;
    }
    
    this.getHeight = function(element) {
    	return element.offsetHeight;
    }
    
    this.getWindowHeight = function() {
    	return document.body.clientHeight;
    }
    
    this.getWindowWidth = function() {
    	return document.body.clientWidth;
    }
    
    this.setHeight = function(element, h) {
    	element.style.height = h;
    }
    
    this.setVisible = function(id, visible) {
        var elm = document.getElementById(id);
        if (elm == null) return;
        elm.style.visibility = visible ? "visible" : "hidden";
        elm.style.display = visible ? "" : "none";
    }
    
    this.setWidth = function(element, w) {
    	element.style.width = w;
    }
    
    this.setX = function(element, x) {
    	element.style.left = x + "px";
    }
    
    this.setY = function(element, y) {
    	element.style.top = y + "px";
    }
    
    this.getInnerText = function(element) {
    
    	return element.childNodes[0].nodeValue.toString();
    }
    
    this.setInnerText = function(element, text) {
    	var newNode;
    	var r;
	   
		newNode = document.createTextNode(text);
		element.replaceChild(newNode, element.childNodes[0]);
    }

    this.getChildWindow = function(element) {
    	var cw;
    	
    	cw = element.contentWindow;
    	if (cw == null) {
    		cw = element.contentDocument.defaultView;
    	}
    	return cw;
    }

}

Platform.prototype.initNS = function() {

	this.getElement = function(id) {
		return document.layers[id];
	}
    this.getVisibility = function(id) {
        var l = document.layers[id];
        if (l == null) return "";
        var v = l.visibility;
        return v == "show" ? "visible" : v == "hide" ? "hidden" : v;
    }
    this.isVisible = function(id) {
        var l = document.layers[id];
        if (l == null) return "";
        var v = l.visibility;
        return v == "show";
    }
    this.setVisible = function(id, visible) {
        var l = document.layers[id];
        if (l == null) return "";
        l.visibility = visible ? "show" : "hide";
    }

    this.getX = function(element) {
    	return element.offsetLeft;
    }
    
    this.getY = function(element) {
    	return element.offsetTop;
    }
    
    this.getWidth = function(element) {
    	return element.offsetWidth;
    }
    
    this.getHeight = function(element) {
    	return element.offsetHeight;
    }
    
    this.setX = function(element, x) {
    	element.style.pixelLeft = x;
    }
    
    this.setY = function(element, y) {
    	element.style.pixelTop = y;
    }
    
    this.getWindowHeight = function() {
    	return document.body.clientHeight;
    }
    
    this.getWindowWidth = function() {
    	return document.body.clientWidth;
    }
    
    this.getInnerText = function(element) {
    
    	
    	return "";
    }
    
    this.setInnerText = function(element, text) {
	   
		
    }

    this.getChildWindow = function(element) {
    	var cw;
    	
    	cw = element.contentWindow;
    	if (cw == null) {
    		cw = element.contentDocument.defaultView;
    	}
    	return cw;
    }
    	
}

Platform.prototype.initDefault = function() {

	this.getElement = function(id) {
		return null;
	}
	this.getVisibility = function(id) {
		return "";
	}
	this.isVisible = function(id) {
		return true;
	}
	this.setVisible = function(id, visible) {
	}

    this.getX = function(element) {
    	return -1;
    }
    
    this.getY = function(element) {
    	return -1;
    }
    
    this.getWidth = function(element) {
    	return -1;
    }
    
    this.getHeight = function(element) {
    	return -1;
    }
    
    this.setX = function(element, x) {
    }
    
    this.setY = function(element, y) {
    }
    
    this.getWindowHeight = function() {
    	return -1;
    }
    
    this.getWindowWidth = function() {
    	return -1;
    }
    
    this.getInnerText = function(element) {
    
    	
    	return "";
    }
    
    this.setInnerText = function(element, text) {
	   
		
    }

}

Platform.prototype.isFormChanged = function(form) {
    var elements = form.elements;

    for (var i = 0; i < elements.length; i++) {
        if (elements[i].type == "text") {
            if (elements[i].value != elements[i].defaultValue) return true;
        }
        else if (elements[i].type == "textarea") {
            if (elements[i].value != elements[i].defaultValue) return true;
        }
        else if (elements[i].type == "select-one") {
            var options = elements[i].options;
            for (j = 0; j < options.length; j++) {
                if (options[j].selected != options[j].defaultSelected) return true;
            }
        }
        else if (elements[i].type == "select-multiple") {
            var options = elements[i].options;
            for (j = 0; j < options.length; j++) {
                if (options[j].selected != options[j].defaultSelected) return true;
            }
        }
        else if (form.elements[i].type == "radio") {
            if (form.elements[i].checked != form.elements[i].defaultChecked) return true;
        }
        else if (form.elements[i].type == "checkbox") {
            if (form.elements[i].checked != form.elements[i].defaultChecked) return true;
        }
        else if (form.elements[i].type == "hidden") {
        	
        }
        else {
            
            alert("What is a " + form.elements[i].type + "?");
        }
    }
    return false;
}

var platform = new Platform();

ChopStickEvent.prototype.target;

ChopStickEvent.prototype.source;
 
ChopStickEvent.prototype.shiftKey;
 
ChopStickEvent.prototype.ctrlKey;
 
ChopStickEvent.prototype.altKey;

function ChopStickEvent(target, source) {
	
	this.target = target;
	this.source = source;
	
	this.shiftKey = false;
	this.ctrlKey = false;
	this.altKey = false;

 }

ChopStickAction.prototype.actionListener = null;

ChopStickAction.prototype.components = null;

ChopStickAction.prototype.enabled = true;

ChopStickAction.prototype.name = null;

function ChopStickAction(name, actionListener) {

	this.name = name;
	this.actionListener = actionListener;
	this.components = new Array();
}

ChopStickAction.prototype.addComponent = function(component) {

	this.components[this.components.length] = component;
}

ChopStickAction.prototype.enable = function() {

	this.setEnabled(true);
}

ChopStickAction.prototype.disable = function() {

	this.setEnabled(false);
}

ChopStickAction.prototype.fireActionEvent = function(event) {

	if (this.actionListener != null
	    && this.actionListener.actionPerformed != null) {
		this.actionListener.actionPerformed(this.name, event);
	}
}

ChopStickAction.prototype.setEnabled = function(enabled) {

	if (this.enabled != enabled) {
		this.enabled = enabled;
		for (var i = 0; i < this.components.length; i++) {
			if (this.components[i].setEnabled != null) {
				this.components[i].setEnabled(enabled);
			}
		}
	}
}

ChopStickEvent.prototype.target;

ChopStickEvent.prototype.source;
 
ChopStickEvent.prototype.shiftKey;
 
ChopStickEvent.prototype.ctrlKey;
 
ChopStickEvent.prototype.altKey;

function ChopStickEvent(target, source) {
	
	this.target = target;
	this.source = source;
	
	this.shiftKey = false;
	this.ctrlKey = false;
	this.altKey = false;

 }

ChopStickFocusEvent.prototype = new ChopStickEvent;

function ChopStickFocusEvent(target, source) {
	this.constructor(target, source);
	
}

ChopStickItemEvent.prototype = new ChopStickEvent();

function ChopStickItemEvent(id) {
	this.constructor(id);

}

ChopStickKeyEvent.prototype = new ChopStickEvent;

function ChopStickKeyEvent(id, source) {
	this.constructor(id, source);
	
}

ChopStickMouseEvent.prototype = new ChopStickEvent;

function ChopStickMouseEvent(id, source) {
	this.constructor(id, source);
	
}

ChopStickWindowEvent.prototype = new ChopStickEvent;

function ChopStickWindowEvent(id) {
	this.constructor(id);

}

ChopStickComponent.prototype.action = null;

ChopStickComponent.prototype.actionEventType = null;

ChopStickComponent.prototype.element = null;

ChopStickComponent.prototype.enabled = true;

ChopStickComponent.prototype.focusListeners = null;

ChopStickComponent.prototype.keyListeners = null;

ChopStickComponent.prototype.mouseListeners = null;

ChopStickComponent.prototype.blocked = false;

function ChopStickComponent(id) {

	this.id = id;
	this.focusListeners = new Array();
	this.keyListeners = new Array();
	this.mouseListeners = new Array();
	this.ChopStickComponent = ChopStickComponent;
}	

ChopStickComponent.prototype.addFocusListener = function(listener) {

	this.focusListeners = this.focusListeners.concat(listener);
}

ChopStickComponent.prototype.addKeyListener = function(listener) {

	this.keyListeners = this.keyListeners.concat(listener);
}

ChopStickComponent.prototype.addMouseListener = function(listener) {

	this.mouseListeners = this.mouseListeners.concat(listener);
}

ChopStickComponent.prototype.create = function(windowId) {

	
	chopstick.addComponent(this, windowId);
	
	this.element = platform.getElement(this.id);
	
	
	
	
	
}

ChopStickComponent.prototype.disableEvents = function(eventMask, id) {
	var es;

	
	if (id == null) {
		es = platform.getElement(this.id + ".EventSource");
	}
	else {
		es = platform.getElement(this.id + ".EventSource." + id);
	}
	if (es == null) {
		
		es = platform.getElement(this.id);
	}
	
	if (eventMask & 1) {
        es.onclick = null;
        es.ondblclick = null;
        es.onmouseover = null;
        es.onmouseout = null;
        es.onmousedown = null;
        es.onmouseup = null;
	}
	
	if (eventMask & 2) {
	}
	
	if (eventMask & 4) {
		es.onfocus = null;
		es.onblur = null;
	}
	
	if (eventMask & 8) {
		es.onkeydown = null;
		es.onkeyup = null;
		es.onkeypressed = null;
	}
}

ChopStickComponent.prototype.enableItemEvents = function(eventMask, itemCnt) {

	for (var j = 0; j < 10; j++) {
		if (platform.getElement(this.id + ".EventSource." + j + ".0") == null) {
			break;
		}
		for (var i = 0; i < itemCnt; i++) {
			this.enableEvents(eventMask, j + "." + i);
		}
	}
}

ChopStickComponent.prototype.enableEvents = function(eventMask, id) {
	var es;

	
	if (id == null) {
		es = platform.getElement(this.id + ".EventSource");
	}
	else {
		es = platform.getElement(this.id + ".EventSource." + id);
	}
	if (es == null) {
		
		es = platform.getElement(this.id);
	}
	
	es.chopstickEventTarget = this;
	
	
	if (eventMask & 1) {
        es.onclick = function(e) {
        	return this.chopstickEventTarget.fireClickEvent(this, e); 
        };
        es.ondblclick = function(e) {
	        this.chopstickEventTarget.fireDoubleClickEvent(this, e);
        };
        es.onmouseover = function(e) {
        	this.chopstickEventTarget.fireMouseEnterEvent(this, e);
        };
        es.onmouseout = function(e) {
    	    this.chopstickEventTarget.fireMouseExitEvent(this, e);
        };
        es.onmousedown = function(e) {
	        this.chopstickEventTarget.fireMouseDownEvent(this, e);
        };
        es.onmouseup = function(e) {
        	this.chopstickEventTarget.fireMouseUpEvent(this, e);
        };
	}
	
	if (eventMask & 2) {
	}
	
	if (eventMask & 4) {
		es.onfocus = function(e) {
			if (!this.chopstickEventTarget.enabled) 
				return false; 
			this.chopstickEventTarget.fireGainFocusEvent(this, e);
		};
		es.onblur = function(e) {
			this.chopstickEventTarget.fireLooseFocusEvent(this, e);
		};
	}
	
	if (eventMask & 8) {
		es.onkeydown = function(e) {
			this.chopstickEventTarget.fireKeyDownEvent(this, e);
		};
		es.onkeyup = function(e) {
			this.chopstickEventTarget.fireKeyUpEvent(this, e);
		};
		es.onkeypress = function(e) {
			this.chopstickEventTarget.fireKeyPressedEvent(this, e);
		};
	}
}

ChopStickComponent.prototype.fireClickEvent = function(source) {
	var mouseEvent;
	var listener;
	
	
	if (!this.isEnabled()) {
		return false;
	}
	
	mouseEvent = new ChopStickMouseEvent(this, source);
	
	for (var i = 0; i < this.mouseListeners.length; i++) {
		listener = this.mouseListeners[i];
		if (listener.mouseClicked != null) {
			listener.mouseClicked(mouseEvent);
		}
	}
	if (this.enabled && this.actionEventType == "click") {
		this.action.fireActionEvent(mouseEvent);
	}
	
	return source.href == null || source.href.indexOf("#") < source.href.length - 1;
}

ChopStickComponent.prototype.fireDoubleClickEvent = function(source) {
	var mouseEvent;
	var listener;
	
	
	if (!this.isEnabled()) {
		return;
	}
	
	mouseEvent = new ChopStickMouseEvent(this, source);
	
	for (var i = 0; i < this.mouseListeners.length; i++) {
		listener = this.mouseListeners[i];
		if (listener.mouseDoubleClicked != null) {
			listener.mouseDoubleClicked(mouseEvent);
		}
	}
	if (this.enabled && this.actionEventType == "dblclick") {
		this.action.fireActionEvent(mouseEvent);
	}
}

ChopStickComponent.prototype.fireGainFocusEvent = function() {
	var focusEvent;
	var listener;
	
	
	if (!this.isEnabled()) {
		this.element.blur();
		return;
	}
	
	focusEvent = new ChopStickFocusEvent(this);
	
	for (var i = 0; i < this.focusListeners.length; i++) {
		listener = this.focusListeners[i];
		if (listener.focusGained != null) {
			listener.focusGained(focusEvent);
		}
	}
}

ChopStickComponent.prototype.fireLooseFocusEvent = function() {
	var focusEvent;
	var listener;
	
	
	if (!this.isEnabled()) {
		return;
	}
	
	focusEvent = new ChopStickFocusEvent(this);
	
	for (var i = 0; i < this.focusListeners.length; i++) {
		listener = this.focusListeners[i];
		if (listener.focusLost != null) {
			listener.focusLost(focusEvent);
		}
	}
}

ChopStickComponent.prototype.fireKeyDownEvent = function(source) {
	var keyEvent;
	var listener;
	
	
	if (!this.isEnabled()) {
		return;
	}
	
	keyEvent = new ChopStickKeyEvent(this, source);
	
	for (var i = 0; i < this.keyListeners.length; i++) {
		listener = this.keyListeners[i];
		if (listener.keyPressed != null) {
			listener.keyPressed(keyEvent);
		}
	}
}

ChopStickComponent.prototype.fireKeyUpEvent = function(source) {
	var keyEvent;
	var listener;
	
	
	if (!this.isEnabled()) {
		return;
	}
	
	keyEvent = new ChopStickKeyEvent(this, source);
	
	for (var i = 0; i < this.keyListeners.length; i++) {
		listener = this.keyListeners[i];
		if (listener.keyReleased != null) {
			listener.keyReleased(keyEvent);
		}
	}
}

ChopStickComponent.prototype.fireKeyPressedEvent = function(source) {
	var keyEvent;
	var listener;
	
	
	if (!this.isEnabled()) {
		return;
	}
	
	keyEvent = new ChopStickKeyEvent(this, source);
	
	for (var i = 0; i < this.keyListeners.length; i++) {
		listener = this.keyListeners[i];
		if (listener.keyTyped != null) {
			listener.keyTyped(keyEvent);
		}
	}
}

ChopStickComponent.prototype.fireMouseDownEvent = function(source) {
	var mouseEvent;
	var listener;
	
	
	if (!this.isEnabled()) {
		return;
	}
	
	mouseEvent = new ChopStickMouseEvent(this, source);
	
	for (var i = 0; i < this.mouseListeners.length; i++) {
		listener = this.mouseListeners[i];
		if (listener.mousePressed != null) {
			listener.mousePressed(mouseEvent);
		}
	}
}

ChopStickComponent.prototype.fireMouseEnterEvent = function(source) {
	var mouseEvent;
	var listener;
	
	
	
	
	
	if (this.blocked) {
		return;
	}
	
	mouseEvent = new ChopStickMouseEvent(this, source);
	
	for (var i = 0; i < this.mouseListeners.length; i++) {
		listener = this.mouseListeners[i];
		if (listener.mouseEntered != null) {
			listener.mouseEntered(mouseEvent);
		}
	}
}

ChopStickComponent.prototype.fireMouseExitEvent = function(source) {
	var mouseEvent;
	var listener;
	
	
	
	
	
	
	mouseEvent = new ChopStickMouseEvent(this, source);
	
	for (var i = 0; i < this.mouseListeners.length; i++) {
		listener = this.mouseListeners[i];
		if (listener.mouseExited != null) {
			listener.mouseExited(mouseEvent);
		}
	}
}

ChopStickComponent.prototype.fireMouseUpEvent = function(source) {
	var mouseEvent;
	var listener;
	
	
	if (!this.isEnabled()) {
		return;
	}
	
	mouseEvent = new ChopStickMouseEvent(this, source);
	
	for (var i = 0; i < this.mouseListeners.length; i++) {
		listener = this.mouseListeners[i];
		if (listener.mouseReleased != null) {
			listener.mouseReleased(mouseEvent);
		}
	}
}

ChopStickComponent.prototype.getBackground = function() {

	
}

ChopStickComponent.prototype.getCursor = function() {

	return this.element.style.cursor;
}

		
ChopStickComponent.prototype.getId = function() {

	return this.id;
}

ChopStickComponent.prototype.getHeight = function() {

	return platform.getHeight(this.element);
}

ChopStickComponent.prototype.getX = function() {

	return platform.getX(this.element);
}

ChopStickComponent.prototype.getY = function() {

	return platform.getY(this.element);
}

ChopStickComponent.prototype.getWidth = function() {

	return platform.getWidth(this.element);
}

ChopStickComponent.prototype.isEnabled = function() {

	return this.enabled && !this.blocked;
}

ChopStickComponent.prototype.isVisible = function() {

	return platform.isVisible(this.id);
}

ChopStickComponent.prototype.setActionListener = function(actionListener, actionName, eventType) {

	
	this.action = chopstick.getAction(actionName, actionListener);
	this.actionEventType = eventType;
	this.action.addComponent(this);
}

ChopStickComponent.prototype.setBackground = function(color) {

	
}

ChopStickComponent.prototype.setCursor = function(cursor) {

	this.element.style.cursor = cursor;
}

ChopStickComponent.prototype.setDimension = function(w, h) {

	platform.setWidth(this.element, w);
	platform.setHeight(this.element, h);
}

ChopStickComponent.prototype.setEnabled = function(enabled) {

	this.enabled = enabled;
}

ChopStickComponent.prototype.setHeight = function(h) {

	platform.setHeight(this.element, h);
}

ChopStickComponent.prototype.setLocation = function(x, y) {

	platform.setX(this.element, x);
	platform.setY(this.element, y);
}

ChopStickComponent.prototype.setWidth = function(w) {

	platform.setWidth(this.element, w);
}

ChopStickComponent.prototype.setX = function(x) {

	platform.setX(this.element, x);
}

ChopStickComponent.prototype.setY = function(y) {

	platform.setY(this.element, y);
}

ChopStickComponent.prototype.setVisible = function(visible) {

	platform.setVisible(this.id, visible);
}

ChopStickFormComponent.prototype = new ChopStickComponent;

ChopStickFormComponent.prototype.label = null;

function ChopStickFormComponent(id) {
	this.constructor(id);
	
}

ChopStickFormComponent.prototype.setEnabled = function(enabled) {

	this.enabled = enabled;
	if (this.label != null) {
		this.label.setEnabled(enabled);
	}
}

ChopStickFormComponent.prototype.setEnabled = function(enabled) {

	this.enabled = enabled;
	this.element.disabled = !enabled;
}

ChopStickFormComponent.prototype.setRelatedLabel = function(label) {

	this.label = label;
}

ChopStickImage.prototype = new ChopStickComponent;

function ChopStickImage(id) {
	this.constructor(id);
	
}

ChopStickWindow.prototype = new ChopStickComponent;

ChopStickWindow.prototype.windowListeners = null;

function ChopStickWindow(id) {
	this.constructor(id);
	
	this.windowListeners = new Array();
}

function ChopStickWindow(id) {
	this.ChopStickWindow = ChopStickWindow;
	this.ChopStickComponent(id);
	this.windowListeners = new Array();
}

ChopStickWindow.prototype.addWindowListener = function(listener) {

	this.windowListeners = this.windowListeners.concat(listener);
}

ChopStickWindow.prototype.fireWindowCreatedEvent = function() {
	var windowEvent;
	var listener;
	
	
	windowEvent = new ChopStickWindowEvent(this);
	
	for (var i = 0; i < this.windowListeners.length; i++) {
		listener = this.windowListeners[i];
		if (listener.windowCreated != null) {
			listener.windowCreated(windowEvent);
		}
	}
}

ChopStickWindow.prototype.fireWindowOpenEvent = function() {
	var windowEvent;
	var listener;
	
	
	windowEvent = new ChopStickWindowEvent(this);
	
	for (var i = 0; i < this.windowListeners.length; i++) {
		listener = this.windowListeners[i];
		if (listener.windowOpened != null) {
			listener.windowOpened(windowEvent);
		}
	}
}

ChopStickWindow.prototype.fireWindowCloseEvent = function() {
	var windowEvent;
	var listener;
	
	
	windowEvent = new ChopStickWindowEvent(this);
	
	for (var i = 0; i < this.windowListeners.length; i++) {
		listener = this.windowListeners[i];
		if (listener.windowClosed != null) {
			listener.windowClosed(windowEvent);
		}
	}
}

ChopStickBrowserFrame.prototype = new ChopStickWindow;

var browserFrame = new ChopStickBrowserFrame();

function ChopStickBrowserFrame(id) {
	this.constructor(id);

	
	browserFrame = this;
	
	window.chopstickEventTarget = this;
}

ChopStickButtonComponent.prototype = new ChopStickFormComponent;

ChopStickButtonComponent.prototype.itemListeners = null;

function ChopStickButtonComponent(id) {
	this.constructor(id);
	
	
	this.itemListeners = new Array();
}

ChopStickButtonComponent.prototype.addItemListener = function(listener) {

	this.itemListeners = this.itemListeners.concat(listener);
}

ChopStickButtonComponent.prototype.fireItemEvent = function() {
	var itemEvent;
	var listener;
	
	
	if (!this.isEnabled()) {
		return;
	}
	
	itemEvent = new ChopStickItemEvent(this.id);
	
	for (var i = 0; i < this.itemListeners.length; i++) {
		listener = this.itemListeners[i];
		if (listener.selectionChanged != null) {
			listener.selectionChanged(itemEvent);
		}
	}
}

ChopStickButtonComponent.prototype.doClick = null;

ChopStickButtonComponent.prototype.mouseClicked = function(event) {

	this.fireItemEvent();
}

ChopStickFileChooser.prototype = new ChopStickFormComponent;

function ChopStickFileChooser(id) {
	this.constructor(id);
	
}

ChopStickForm.prototype = new ChopStickFormComponent;

function ChopStickForm(id) {
	this.constructor(id);
	
}

ChopStickGroupPanel.prototype = new ChopStickComponent;

function ChopStickGroupPanel(id) {
	this.constructor(id);
	
}

ChopStickInternalWindow.prototype = new ChopStickWindow;

function ChopStickInternalWindow(id) {
    this.constructor(id);

}

ChopStickInternalWindow.prototype.open = function() {
    
    
    this.setVisible(true);
    this.fireWindowOpenEvent();
}

ChopStickInternalWindow.prototype.close = function() {
    
    this.setVisible(false);
    this.fireWindowCloseEvent();
}

ChopStickInternalWindow.prototype.center = function() {
    var display;
    var bw;
    var bh;
    var ww;
    var ww;
    var x;
    var y;
    
    
    bw = platform.getWindowWidth();
    bh = platform.getWindowHeight();
    
    
    display = this.element.style.display;
    this.element.style.display = "";
        
    ww = platform.getWidth(this.element);
    wh = platform.getHeight(this.element);
    this.element.style.display = display;
    
    x = (bw - ww) / 2;
    y = (bh - wh) / 2;
    
    platform.setX(this.element, x);
    platform.setY(this.element, y);
}

ChopStickLabel.prototype = new ChopStickFormComponent;

function ChopStickLabel(id) {
	this.constructor(id);
	
}

ChopStickLabel.prototype.setEnabled = function(enabled) {

	this.enabled = enabled;
	this.element.style.color = enabled ? "" : "#999999";
}

ChopStickListComponent.prototype = new ChopStickFormComponent;

ChopStickListComponent.prototype.itemListeners = null;

function ChopStickListComponent(id) {
	this.constructor(id);
	
	this.itemListeners = new Array();
}

ChopStickListComponent.prototype.addItemListener = function(listener) {

	this.itemListeners = this.itemListeners.concat(listener);
}

ChopStickListComponent.prototype.fireItemEvent = function() {
	var itemEvent;
	var listener;
	
	
	if (!this.isEnabled()) {
		return;
	}
	
	itemEvent = new ChopStickItemEvent(this);
	
	for (var i = 0; i < this.itemListeners.length; i++) {
		listener = this.itemListeners[i];
		if (listener.selectionChanged != null) {
			listener.selectionChanged(itemEvent);
		}
	}
}

ChopStickListComponent.prototype.getItemId = function(idx) {

	return this.element.options[idx].value;
}

ChopStickListComponent.prototype.getItemLabel = function(idx) {

	return this.element.options[idx].text;
}

ChopStickListComponent.prototype.getSelectedIndex = function() {

	return this.element.selectedIndex;
}

ChopStickMenu.prototype = new ChopStickComponent;
	
ChopStickMenu.prototype.parent = null;

ChopStickMenu.prototype.menuItems = null;

function ChopStickMenu(id) {
	this.constructor(id);
	
	this.menuItems = new Array();
}
	
ChopStickMenu.prototype.addMenuItem = function(menuItem) {

	this.menuItems[this.menuItems.length] = menuItem;
	menuItem.setParent(this);
}

ChopStickMenu.prototype.mouseClicked = function() {
	
	
	if (this.isVisible()) {
		this.closeMenu();
	}
	else {
		this.openMenu();
	}
}

ChopStickMenu.prototype.mouseEntered = function() {

	this.stopMenuTimer();
	if (this.parent.hasOpenMenu && !this.isVisible()) {
		this.openMenu();
	}
}

ChopStickMenu.prototype.mouseExited = function() {

	this.startMenuTimer();
}

ChopStickMenu.prototype.startMenuTimer = function() {

	if (this.isVisible()) {
		
		this.closeTimeout = setTimeout(
			"chopstick.getComponent('" + this.id + "').closeMenu()", 
			2000);
	}
	if (this.parent != null && this.parent.startMenuTimer != null) {
		this.parent.startMenuTimer();
	}
}

ChopStickMenu.prototype.stopMenuTimer = function() {

	if (this.closeTimeout != null) {
		clearTimeout(this.closeTimeout);
		this.closeTimeout = null;
	}
	if (this.parent != null && this.parent.stopMenuTimer != null) {
		this.parent.stopMenuTimer();
	}
}

ChopStickMenu.prototype.openMenu = function() {
	var label;

	
	label = platform.getElement(this.id + ".Label");
	if (label != null) {
		var x = platform.getX(label);
		var y = platform.getY(label);
		var h = platform.getHeight(label);
		platform.setX(this.element, x - 2);
		platform.setY(this.element, y + h + 1);
	}
	es = platform.getElement(this.id + ".EventSource");
	if (es != null) {
		es.focus();
	}
	
	this.setVisible(true);
	
	if (label != null) {
		label.style.backgroundColor = "#000099";
		label.style.color = "#ffffff";
	}
	
	if (this.parent != null) {
		this.parent.menuOpened(this);
	}
}

ChopStickMenu.prototype.closeMenu = function() {

	if (!this.isVisible()) return;
	label = platform.getElement(this.id + ".Label");
	
	if (label != null) {
		label.style.backgroundColor = "";
		label.style.color = "";
	}
	es = platform.getElement(this.id + ".EventSource");
	if (es != null) {
		es.blur();
	}
	
	this.setVisible(false);
	
	if (this.parent != null) {
		this.parent.menuClosed(this);
	}
}

ChopStickMenu.prototype.setParent = function(parent) {

	this.parent = parent;
}

ChopStickMenuBar.prototype = new ChopStickComponent;

ChopStickMenuBar.prototype.hasOpenMenu = false;

ChopStickMenuBar.prototype.menus = null;

	
function ChopStickMenuBar(id) {
	this.constructor(id);
	
	this.menus = new Array();

}
	
ChopStickMenuBar.prototype.addMenu = function(menu) {

	this.menus[this.menus.length] = menu;
	menu.setParent(this);
}

ChopStickMenuBar.prototype.menuOpened = function(menu) {

	
	for (var idx = 0; idx < this.menus.length; idx++) {
		if (this.menus[idx] == menu) continue;
		this.menus[idx].closeMenu();
	}
	this.hasOpenMenu = true;
}

ChopStickMenuBar.prototype.menuClosed = function(menu) {

	this.hasOpenMenu = false;
}

ChopStickMenuItem.prototype = new ChopStickComponent;
	
ChopStickMenuItem.prototype.parent = null;

function ChopStickMenuItem(id) {
	this.constructor(id);

}
	
ChopStickMenuItem.prototype.setParent = function(parent) {

	this.parent = parent;
}

ChopStickMenuItem.prototype.setEnabled = function(enabled) {
	
	this.enabled = enabled;
	if (!enabled) {
		this.element.style.color = "#cccccc";
	}
	else {
		this.element.style.color = "";
	}
}

ChopStickMenuItem.prototype.mouseClicked = function() {
	
	if (!this.enabled) return;
	this.parent.closeMenu();
}

ChopStickMenuItem.prototype.mouseEntered = function(source) {
	var e;
	
	if (this.parent != null) {
		this.parent.stopMenuTimer();
	}
	e = platform.getElement(source.source.id);
	if (e != null) {
		e.style.backgroundColor = "#000099";
		e.style.color = "#ffffff";
	}
}

ChopStickMenuItem.prototype.mouseExited = function(source) {
	var e;
	
	if (this.parent != null) {
		this.parent.startMenuTimer();
	}
	e = platform.getElement(source.source.id);
	if (e != null) {
		e.style.backgroundColor = "";
		e.style.color = "";
	}
}

ChopStickPassword.prototype = new ChopStickFormComponent;

function ChopStickPassword(id) {
	this.constructor(id);
	
}

ChopStickProgressBar.prototype = new ChopStickComponent;

function ChopStickProgressBar(id) {
	this.constructor(id);
	
}

ChopStickSplitPane.prototype = new ChopStickComponent;

ChopStickSplitPane.prototype.HORIZONTAL = 0;

ChopStickSplitPane.prototype.VERTICAL = 1;

ChopStickSplitPane.prototype.direction;

ChopStickSplitPane.prototype.size;

function ChopStickSplitPane(id) {
	var splitTable;
	var splitRows;
	
	this.constructor(id);
	
	splitTable = platform.getElement(id);
	splitRows = splitTable.rows;
	this.direction = splitRows.length > 1 ? this.VERTICAL : this.HORIZONTAL;
	if (this.direction == this.VERTICAL) {
		this.size = splitRows.length;
	}
	else {
		this.size = splitRows[0].cells.length;
	}
}

ChopStickSplitPane.prototype.getSliceCnt = function() {

	return this.size;
}

ChopStickSplitPane.prototype.getSliceSize = function(idx) {
	var splitTable;
	var splitRows;

	if (idx < 0 || idx >= this.size) return -1;
	splitTable = platform.getElement(this.id);
	splitRows = splitTable.rows;
	if (this.direction == this.VERTICAL) {
		return platform.getHeight(splitRows[idx].cells[0]);
	}
	else {
		return platform.getWidth(splitRows[0].cells[idx]);
	}
}

ChopStickSplitPane.prototype.setSliceSize = function(idx, size) {
	var splitTable;
	var splitRows;
	var pane;
	var pane2;

	if (idx < 0 || idx >= this.size) return -1;
	splitTable = platform.getElement(this.id);
	splitRows = splitTable.rows;
	if (this.direction == this.VERTICAL) {
	    pane = splitRows[idx].cells[0];
	    pane2 = splitRows[idx + (idx < this.size - 1 ? 1 : -1)].cells[0];
	    currentSize = platform.getHeight(pane);
	    currentSize2 = platform.getHeight(pane2);
	    size2 = currentSize2 - size + currentSize - 20;
		platform.setHeight(pane2, size2);
		platform.setHeight(pane, size);
	}
	else {
		pane = splitRows[0].cells[idx];
		pane2 = splitRows[0].cells[idx + (idx < this.size - 1 ? 1 : -1)];
	    currentSize = platform.getWidth(pane);
	    currentSize2 = platform.getWidth(pane2);
	    size2 = currentSize2 - size + currentSize - 20;
		platform.setWidth(pane2, size2);
		platform.setWidth(pane, size);
	}
}

ChopStickTabbedPane.prototype = new ChopStickComponent;

ChopStickTabbedPane.prototype.tabs = null;

function ChopStickTabbedPane(id) {
	this.constructor(id);
		
	this.tabs = new Array();
}		

ChopStickTabbedPane.prototype.addTab = function(pos, tabId) {

	if (this.tabs[pos] == null) {
		this.tabs[pos] = new ChopStickTab(tabId);
	}
	else {
		this.tabs[pos].tabId = tabId;
	}
}

ChopStickTabbedPane.prototype.setActionListener = function(pos, actionListener, actionName) {

	if (this.tabs[pos] == null) {
		this.tabs[pos] = new ChopStickTab();
	}
	this.tabs[pos].actionListener = actionListener;
	this.tabs[pos].action = chopstick.getAction(actionName, actionListener);
	this.tabs[pos].action.addComponent(this.tabs[pos]);
}

ChopStickTabbedPane.prototype.setButtonUrl = function(pos, url) {

	this.tabs[pos].tabUrl = url;
	chopstick.addPreloadImage(url);
}

ChopStickTabbedPane.prototype.setButtonRolloverUrl = function(pos, url) {

	this.tabs[pos].tabRolloverUrl = url;
	chopstick.addPreloadImage(url);
}

ChopStickTabbedPane.prototype.getTabIndexFromId = function(id) {
	var pos;
	var idx;
	
	pos = id.lastIndexOf(".");
	if (pos < 0) return;
	idx = parseInt(id.substring(pos+1));
	return idx;
}

ChopStickTabbedPane.prototype.mouseEntered = function(event) {
	var pos;
	var element;
	
	pos = this.getTabIndexFromId(event.source.id);
	if (pos == null) return;
	if (this.tabs[pos].enabled == false) return;
	element = platform.getElement(this.id + "." + pos);
	element.src = this.tabs[pos].tabRolloverUrl;
}

ChopStickTabbedPane.prototype.mouseExited = function(event) {
	var pos;
	var element;
	
	pos = this.getTabIndexFromId(event.source.id);
	if (pos == null) return;
	if (this.tabs[pos].enabled == false) return;
	element = platform.getElement(this.id + "." + pos);
	element.src = this.tabs[pos].tabUrl;
}

ChopStickTabbedPane.prototype.mouseClicked = function(event) {
	var pos;
	var element;
	
	pos = this.getTabIndexFromId(event.source.id);
	if (pos == null) return;
	
	if (this.tabs[pos].action == null) return;
	if (this.tabs[pos].enabled == false) return;
	
	this.tabs[pos].action.fireActionEvent(event);
}

ChopStickTab.prototype.element = null;

ChopStickTab.prototype.tabUrl = "";

ChopStickTab.prototype.tabRolloverUrl = "";

ChopStickTab.prototype.action = null;

ChopStickTab.prototype.actionListener = null;

ChopStickTab.prototype.enabled = true;

function ChopStickTab(tabId) {

	this.tabId = tabId;
	this.element = platform.getElement(tabId);
}

ChopStickTab.prototype.setEnabled = function(enabled) {

	this.enabled = enabled;
}

ChopStickTextComponent.prototype = new ChopStickFormComponent;

function ChopStickTextComponent(id) {
	this.constructor(id);
	
}

ChopStickToolBar.prototype = new ChopStickComponent;
ChopStickToolBar.prototype.ChopStickToolBar = ChopStickToolBar;

function ChopStickToolBar(id) {
	this.constructor(id);
	
}

ChopStickTreeView.prototype = new ChopStickComponent;

ChopStickTreeView.prototype.itemIds = null;

ChopStickTreeView.prototype.itemListeners = null;

ChopStickTreeView.prototype.itemState = null;

	
ChopStickTreeView.prototype.selectionForeground = "#ffffff";

ChopStickTreeView.prototype.selectionBackground = "#000099";

ChopStickTreeView.prototype.selection = null;

	
function ChopStickTreeView(id) {
	this.constructor(id);
	
	this.itemIds = new Array();
	this.itemListeners = new Array();
	this.itemState = new Array();
	this.selection = new Array();
}

ChopStickTreeView.prototype.addItemListener = function(listener) {

	this.itemListeners = this.itemListeners.concat(listener);
}

ChopStickTreeView.prototype.clearSelection = function() {
	
	for (var i = 0; i < this.selection.length; i++) {
		this.unselectLabel(this.selection[i]);
	}
	this.selection.length = 0;
}

ChopStickTreeView.prototype.enableItemEvents0 = ChopStickComponent.prototype.enableItemEvents;

ChopStickTreeView.prototype.enableItemEvents = function(eventMask, itemCnt) {
	var i;
	
	
	this.enableItemEvents0(eventMask, itemCnt);
	
	for (i = 0; i < itemCnt; i++) {
		var itemId = this.id + ".treeeventsource." + i;
		var element = platform.getElement(itemId);
		if (element != null) {
			element.onclick = function(event) {this.chopstickTreeEventTarget.toggleNode(this.chopstickItemId); return false;};
			element.chopstickTreeEventTarget = this;
			element.chopstickItemId = i;
		}
	}
}

ChopStickTreeView.prototype.fireItemEvent = function() {
	var itemEvent;
	var listener;
	
	
	if (!this.isEnabled()) {
		return;
	}
	
	itemEvent = new ChopStickItemEvent(this);
	
	for (var i = 0; i < this.itemListeners.length; i++) {
		listener = this.itemListeners[i];
		if (listener.selectionChanged != null) {
			listener.selectionChanged(itemEvent);
		}
	}
}

ChopStickTreeView.prototype.getItemId = function(idx) {

	return this.itemIds[idx];
}

ChopStickTreeView.prototype.getItemLabel = function(idx) {
	var elm;
	var label;
	
	elm = platform.getElement(this.id + ".label." + idx);
	if (elm == null) return "";
	label = platform.getInnerText(elm); 
	return label;
}

ChopStickTreeView.prototype.getSelectedIndex = function() {

	return this.selection.length > 0 ? this.selection[0] : -1;
}

ChopStickTreeView.prototype.getSelectionBackground = function() {

	return this.selectionBackground;
}

ChopStickTreeView.prototype.getSelectionForeground = function() {

	return this.selectionForeGround;
}

ChopStickTreeView.prototype.getSize = function() {

	return this.itemIds.length;
}

ChopStickTreeView.prototype.isSelectionEmpty = function() {

	return this.selection.length <= 0;
}

ChopStickTreeView.prototype.isSelectedIndex = function(idx) {

	for (var i = 0; i < this.selection.length; i++) {
		if (this.selection[i] == idx) return true;
	}
	return false;
}

ChopStickTreeView.prototype.selectIndex = function(idx) {

	if (this.selection.length == 1 && this.selection[0] == idx) {
		return;
	}
	if (this.singleSelection && this.selection.length > 0) {
		this.clearSelection();
	}
	this.selection[this.selection.length] = idx;
	this.selectLabel(idx);
	this.fireItemEvent();
}

ChopStickTreeView.prototype.setActionListener = function(actionListener, actionName, eventType) {

	this.action = chopstick.getAction(actionName, actionListener);
	this.actionEventType = eventType;
	
	
}

ChopStickTreeView.prototype.toggleNode = function(idx) {
	var state;
	var toggleButtonId;
	var toggleButton;
	var toggleButtonUrl;
	var pos;
	var childId;
	
	state = ~this.itemState[idx];
	this.itemState[idx] = state;
	toggleButtonId = this.id + "_" + idx + "_ToggleButton";
	toggleButton = document.images[toggleButtonId];
	childId = this.id + "_" + idx + "_Child";
	if (state) {
		if (toggleButton != null) {
			toggleButtonUrl = toggleButton.src;
			pos = toggleButtonUrl.indexOf("collapse");
			toggleButton.src = toggleButtonUrl.substring(0, pos) 
				+ "expand" 
				+ toggleButtonUrl.substring(pos + 8);
		}
	}
	else {
		if (toggleButton != null) {
			toggleButtonUrl = toggleButton.src;
			pos = toggleButtonUrl.indexOf("expand");
			toggleButton.src = toggleButtonUrl.substring(0, pos) 
				+ "collapse" 
				+ toggleButtonUrl.substring(pos + 6);
		}
	}
	platform.setVisible(childId, !state);
	
}

ChopStickTreeView.prototype.mouseClicked = function(event) {
	var idx;
	var pos;
	var labelId;
	var label;

	
	pos = event.source.id.lastIndexOf(".");
	if (pos <= 0) return;
	idx = event.source.id.substring(pos+1);
	
	if (this.singleSelection || !event.shiftKey && !event.ctrlKey) {
		this.clearSelection();
	}
	this.selectIndex(idx);
}	

ChopStickTreeView.prototype.selectLabel = function(idx) {

	labelId = this.id + ".item." + idx;
	label = platform.getElement(labelId);
	if (label != null) {
		label.style.backgroundColor = this.selectionBackground;
		label.style.color = this.selectionForeground;
	}
	labelId = this.id + ".label." + idx;
	label = platform.getElement(labelId);
	if (label != null) {
		label.style.backgroundColor = this.selectionBackground;
		label.style.color = this.selectionForeground;
	}
}

ChopStickTreeView.prototype.unselectLabel = function(idx) {

	labelId = this.id + ".item." + idx;
	label = platform.getElement(labelId);
	if (label != null) {
		label.style.backgroundColor = "";
		label.style.color = "";
	}
	labelId = this.id + ".label." + idx;
	label = platform.getElement(labelId);
	if (label != null) {
		label.style.backgroundColor = "";
		label.style.color = "";
	}
}

ChopStickButton.prototype = new ChopStickButtonComponent;

ChopStickButton.prototype.buttonUrl = "";

ChopStickButton.prototype.buttonRolloverUrl = "";

ChopStickButton.prototype.buttonSelectedUrl = "";

ChopStickButton.prototype.buttonRolloverSelectedUrl = "";

ChopStickButton.prototype.buttonDisabledUrl = "";

ChopStickButton.prototype.buttonDisabledSelectedUrl = "";

function ChopStickButton(id) {
	this.constructor(id);

}

ChopStickButton.prototype.setButtonUrl = function(url) {

	this.buttonUrl = url;
	chopstick.addPreloadImage(url);
}

ChopStickButton.prototype.setButtonDisabledUrl = function(url) {

	this.buttonDisabledUrl = url;
	chopstick.addPreloadImage(url);
}

ChopStickButton.prototype.setButtonDisabledSelectedUrl = function(url) {

	this.buttonDisabledSelectedUrl = url;
	chopstick.addPreloadImage(url);
}

ChopStickButton.prototype.setButtonRolloverUrl = function(url) {

	this.buttonRolloverUrl = url;
	chopstick.addPreloadImage(url);
}

ChopStickButton.prototype.setButtonRolloverSelectedUrl = function(url) {

	this.buttonRolloverSelectedUrl = url;
	chopstick.addPreloadImage(url);
}

ChopStickButton.prototype.setButtonSelectedUrl = function(url) {

	this.buttonSelectedUrl = url;
	chopstick.addPreloadImage(url);
}

ChopStickButton.prototype.setEnabled0 = ChopStickComponent.prototype.setEnabled;

ChopStickButton.prototype.setEnabled = function(enabled) {

	this.setEnabled0(enabled);
	this.updateButton(false, false, !this.enabled);
}

ChopStickButton.prototype.mousePressed = function(event) {

	this.updateButton(true, true, !this.enabled);
}

ChopStickButton.prototype.mouseReleased = function(event) {

	this.updateButton(true, false, !this.enabled);
}

ChopStickButton.prototype.mouseEntered = function(event) {

	this.updateButton(true, false, !this.enabled);
}

ChopStickButton.prototype.mouseExited = function(event) {

	this.updateButton(false, false, !this.enabled);
}

ChopStickButton.prototype.updateButton = function(rollover, selected, disabled) {

	if (disabled) {
		if (selected) {
			this.element.src = this.buttonDisabledSelectedUrl;
		}
		else {
			this.element.src = this.buttonDisabledUrl;
		}
	}
	else {
		if (!rollover && !selected) {
			this.element.src = this.buttonUrl;
		}
		else if (rollover && !selected) {
			this.element.src = this.buttonRolloverUrl;
		}
		else if (!rollover && selected) {
			this.element.src = this.buttonSelectedUrl;
		}
		else {
			this.element.src = this.buttonRolloverSelectedUrl;
		}
	}
}

ChopStickCheckBox.prototype = new ChopStickButtonComponent;

function ChopStickCheckBox(id) {
	this.constructor(id);
	
}

ChopStickCheckBox.prototype.isChecked = function() {

	return this.element.checked;
}

ChopStickCheckBox.prototype.doClick = function() {

	
	if (!this.isEnabled()) {
		return;
	}
	
	this.element.checked = !this.element.checked;
	
	this.fireItemEvent();
}

ChopStickDropDownList.prototype = new ChopStickListComponent;

function ChopStickDropDownList(id) {
	this.constructor(id);
	
}

ChopStickList.prototype.setActionListener = function(actionListener, actionName, eventType) {

	this.action = chopstick.getAction(actionName, actionListener);
	this.actionEventType = eventType;
	
	
}

ChopStickDropDownList.prototype.mouseClicked = function(event) {

	this.fireItemEvent();
}

ChopStickIcon.prototype = new ChopStickImage;

function ChopStickIcon(id) {
	this.constructor(id);
	
}

ChopStickInternalFrame.prototype = new ChopStickInternalWindow;

function ChopStickInternalFrame(id) {
	this.constructor(id);
	
}

ChopStickInternalFrame.prototype.getTitle = function() {
	var titleElm;
	
	titleElm = platform.getElement(this.id + ".title");
	return titleElm.innerHTML;
}

ChopStickInternalFrame.prototype.setTitle = function(title) {
	var titleElm;
	
	titleElm = platform.getElement(this.id + ".title");
	titleElm.innerHTML = title;
}

ChopStickList.prototype = new ChopStickListComponent;

function ChopStickList(id) {
	this.constructor(id);
	
}

ChopStickList.prototype.setActionListener = function(actionListener, actionName, eventType) {

	this.action = chopstick.getAction(actionName, actionListener);
	this.actionEventType = eventType;
	
	
}

ChopStickList.prototype.mouseClicked = function(event) {

	this.fireItemEvent();
}

ChopStickListView.prototype = new ChopStickFormComponent;

	
ChopStickListView.prototype.selectionForeground = "#ffffff";

ChopStickListView.prototype.selectionBackground = "#000099";

ChopStickListView.prototype.selection = null;

ChopStickListView.prototype.singleSelection = false;

ChopStickListView.prototype.values = null;

ChopStickListView.prototype.itemListeners = null;

ChopStickListView.prototype.itemIds = null;

function ChopStickListView(id) {
	this.constructor(id);
	
	this.selection = new Array();
	this.itemIds = new Array();
	this.values = new Array();
	this.itemListeners = new Array();
}

ChopStickListView.prototype.addItemListener = function(listener) {

	this.itemListeners = this.itemListeners.concat(listener);
}

ChopStickListView.prototype.clearSelection = function() {
	
	for (var i = 0; i < this.selection.length; i++) {
		this.unselectLabel(this.selection[i]);
	}
	this.selection.length = 0;
}

ChopStickListView.prototype.fireItemEvent = function() {
	var itemEvent;
	var listener;
	
	
	if (!this.isEnabled()) {
		return;
	}
	
	itemEvent = new ChopStickItemEvent(this);
	
	for (var i = 0; i < this.itemListeners.length; i++) {
		listener = this.itemListeners[i];
		if (listener.selectionChanged != null) {
			listener.selectionChanged(itemEvent);
		}
	}
}

ChopStickListView.prototype.getItemId = function(idx) {

	return this.itemIds[idx];
}

ChopStickListView.prototype.getItemLabel = function(idx) {
	var elm;
	var label;
	
	elm = platform.getElement(this.id + ".label." + idx);
	if (elm == null) return "";
	label = platform.getInnerText(elm); 
	return label;
}

ChopStickListView.prototype.getSelectedIndex = function() {

	return this.selection.length > 0 ? this.selection[0] : -1;
}

ChopStickListView.prototype.getSelectedIndices = function() {

	return this.selection;
}

ChopStickListView.prototype.getSelectedValue = function() {

	if (this.selection.length <= 0) return null;
	return this.values[this.selection[0]];
}

ChopStickListView.prototype.getSelectedValues = function() {
	var values;
	
	values = new Array(this.selection.length);
	for (var i = 0; i < this.selection.length; i++) {
		values[i] = this.values[this.selection[i]];
	}
	return values;
}

ChopStickListView.prototype.getSelectionBackground = function() {

	return this.selectionBackground;
}

ChopStickListView.prototype.getSelectionForeground = function() {

	return this.selectionForeGround;
}

ChopStickListView.prototype.getSize = function() {

	return this.itemIds.length;
}

ChopStickListView.prototype.isSelectionEmpty = function() {

	return this.selection.length <= 0;
}

ChopStickListView.prototype.isSelectedIndex = function(idx) {

	for (var i = 0; i < this.selection.length; i++) {
		if (this.selection[i] == idx) return true;
	}
	return false;
}

ChopStickListView.prototype.isSingleSelection = function() {

	return this.singleSelection;
}

ChopStickListView.prototype.selectIndex = function(idx) {

	if (this.selection.length == 1 && this.selection[0] == idx) {
		return;
	}
	if (this.singleSelection && this.selection.length > 0) {
		this.clearSelection();
	}
	this.selection[this.selection.length] = idx;
	this.selectLabel(idx);
	this.fireItemEvent();
}

 
ChopStickListView.prototype.selectIndexes = function(idxs) {

	
	if (this.singleSelection) return;
	
	for (var i = 0; i < idxs.length; i++) {
		this.selection[this.selection.length] = idxs[i];
		this.selectLabel(idxs[i]);
	}
	this.fireItemEvent();
}

ChopStickListView.prototype.selectRange = function(from, to) {

	
	if (this.singleSelection) return;
	
	for (var idx = from; idx < to; idx++) {
		this.selection[this.selection.length] = idx;
		this.selectLabel(idx);
	}
	this.fireItemEvent();
}

ChopStickListView.prototype.setActionListener = function(actionListener, actionName, eventType) {

	this.action = chopstick.getAction(actionName, actionListener);
	this.actionEventType = eventType;
	
	
}

ChopStickListView.prototype.mouseClicked = function(event) {
	var idx;
	var pos;
	var labelId;
	var label;

	
	pos = event.source.id.lastIndexOf(".");
	if (pos <= 0) return;
	idx = event.source.id.substring(pos+1);
	
	if (this.singleSelection || !event.shiftKey && !event.ctrlKey) {
		this.clearSelection();
	}
	this.selectIndex(idx);
}	

ChopStickListView.prototype.selectLabel = function(idx) {

	labelId = this.id + ".item." + idx;
	label = platform.getElement(labelId);
	if (label != null) {
		label.style.backgroundColor = this.selectionBackground;
		label.style.color = this.selectionForeground;
	}
	labelId = this.id + ".label." + idx;
	label = platform.getElement(labelId);
	if (label != null) {
		label.style.backgroundColor = this.selectionBackground;
		label.style.color = this.selectionForeground;
	}
}

ChopStickListView.prototype.unselectLabel = function(idx) {

	labelId = this.id + ".item." + idx;
	label = platform.getElement(labelId);
	if (label != null) {
		label.style.backgroundColor = "";
		label.style.color = "";
	}
	labelId = this.id + ".label." + idx;
	label = platform.getElement(labelId);
	if (label != null) {
		label.style.backgroundColor = "";
		label.style.color = "";
	}
}

ChopStickRadioButton.prototype = new ChopStickButtonComponent;

function ChopStickRadioButton(id) {
	this.constructor(id);
	
}

ChopStickCheckBox.prototype.isChecked = function() {

	return this.element.checked;
}

ChopStickRadioButton.prototype.doClick = function() {

	
	if (!this.isEnabled()) {
		return;
	}
	
	this.element.checked = true;
	
	this.fireItemEvent();
}

ChopStickSimpleButton.prototype = new ChopStickFormComponent;

function ChopStickSimpleButton(id) {
	this.constructor(id);
	
}

ChopStickTextArea.prototype = new ChopStickTextComponent;

	
function ChopStickTextArea(id) {
	this.constructor(id);
	
}

ChopStickTextField.prototype = new ChopStickTextComponent;

function ChopStickTextField(id) {
	this.constructor(id);
	
}

ChopStickToggleButton.prototype = new ChopStickButton;

ChopStickToggleButton.prototype.selected = false;

function ChopStickToggleButton(id) {
	this.constructor(id);

}

ChopStickToggleButton.prototype.mouseClicked = function(event) {

	this.fireItemEvent();
	if (this.selected) {
		this.selected = false;
	}
	else {
		this.selected = true;
	}
	this.updateButton(true, this.selected, false);
}
	
ChopStickToggleButton.prototype.mouseEntered = function(event) {

	this.updateButton(true, this.selected, !this.enabled);
}
	
ChopStickToggleButton.prototype.mouseExited = function(event) {

	this.updateButton(false, this.selected, !this.enabled);
}

ChopStickToggleButton.prototype.isSelected = function() {

	return this.selected;
}
	
ChopStickToggleButton.prototype.setSelected = function(selected) {

	this.selected = selected;
	this.updateButton(false, this.selected, !this.enabled);
}

ChopStickIncludePane.prototype = new ChopStickComponent;

function ChopStickIncludePane(id) {
	this.constructor(id);
	
}

ChopStickIncludePane.prototype.open = function(src) {

	if (src != null) {
		this.element.src = src;
	}
	this.setVisible(true);
}

ChopStickIncludePane.prototype.close = function() {

	this.setVisible(false);
	this.element.src = null;
}

ChopStickIncludePane.prototype.getChildWindow = function() {

    return platform.getChildWindow(this.element);
}

ChopStickInternalDialog.prototype = new ChopStickInternalFrame;

ChopStickInternalDialog.prototype.modal;

function ChopStickInternalDialog(id) {
	this.constructor(id);
	
}

ChopStickInternalDialog.prototype.close = function() {

	if (this.modal) {
		
		chopstick.endModal(this.id);
	}
	
	this.setVisible(false);
	this.fireWindowCloseEvent();
}

ChopStickInternalDialog.prototype.open = function() {

	if (this.modal) {
		
		chopstick.beginModal(this.id);
	}
	
	this.setVisible(true);
	this.fireWindowOpenEvent();
}

ChopStickInternalDialog.prototype.setModal = function(modal) {

	this.modal = modal || modal == null;
}
