	function windowBox(instanceName, parentInstanceName, centerOnLoad) {
		// move this to global scope
			if (parentInstanceName == null) eval(instanceName + " = this;");
		// remember instance name
		var _instanceName = instanceName;
		var _parentInstanceName = ((parentInstanceName == null) ? null : parentInstanceName);
		
		var _events = new Array;
		var _windowStyles = new Array;
		var _templateVariables = new Array;
		var _windowId = "window_"+Math.ceil(Math.random()*1000); //Lets make a random number for out window id.
		var _windowElement = null;
		var _windowBackdropElement = null;
		var _windowTemplate = '';
		this._ajaxObject = null;
		var windowStatus = false;
		this.centerOnLoad = ((centerOnLoad == null) ? false : centerOnLoad);

		/*
			Runtime Functions.
		*/
			this.openWindow = function() {
				//Create the window
				this.createWindow();
				//Call on the onOpen events
				this.callEvent('open');
				
					if (this.centerOnLoad) this.autoCenter();
			}
			
			this.closeWindow = function() {
				//Call the onClose events
				this.callEvent('close');
				//Destroy the window
				this.destroyWindow();
			}
			
			this.getWindowStatus = function() {
				return (_windowElement != null);
			}
			
		/*
			Construction Functions.
		*/
			this.createWindow = function() {
					if (_windowElement != null) this.destroyWindow();
				
				this.createWindowBackdrop();
				
				_windowElement = document.createElement('div');
				_windowElement.id = _windowId;
				_windowElement.style.zIndex = '1001';
					for (var styleName in _windowStyles) {
							if (_windowStyles[styleName] != null) this.setStyle(styleName, _windowStyles[styleName]);
					}
				document.body.appendChild(_windowElement);
				this.createWindowHTML();
			}
			
			this.createWindowBackdrop = function() {
				_windowBackdropElement = document.createElement('div');
				_windowBackdropElement.style.height = '100%';
				_windowBackdropElement.style.width = '100%';
				_windowBackdropElement.style.position = 'fixed';
				_windowBackdropElement.style.zIndex = '1000';
				_windowBackdropElement.style.top = '0';
				_windowBackdropElement.style.left = '0';
				_windowBackdropElement.style.backgroundColor = '#FFFFFF';
				_windowBackdropElement.style.backgroundColor = '#FFFFFF';
				_windowBackdropElement.style.opacity = '.60';	
				_windowBackdropElement.style.filter = 'alpha(opacity=60)';
				eventHandlers.addEventListener(_windowBackdropElement, "click", this.closeWindow, this);
				document.body.appendChild(_windowBackdropElement);
			}
			
			this.createWindowHTML = function() {
				//Lets replace the id's with something more appropriate.
				var windowTemplate = this._replaceWindowSections(_windowTemplate);
				
				
				windowTemplate = this._replaceFunctionCalls(windowTemplate);
				
				_windowElement.innerHTML = windowTemplate;
					for (var templateVariableName in _templateVariables) {
							if (_templateVariables[templateVariableName] != null) this.setTemplateVariable(templateVariableName, _templateVariables[templateVariableName]);
					}
				
				//this._addDefaultEvents();
			}
			
			this._replaceWindowSections = function(content) {
				var templateSections = content.match(/id="window[a-zA-Z0-9]+"/g);
					if (templateSections != null) {
							for (var n = 0; n < templateSections.length; n++) {
								var sectionName = templateSections[n].replace('id=', '').replace(/"/g, '');
								content = this._replaceItem(content, sectionName, sectionName.toLowerCase() +'_'+_windowId);
							}
					}
				
				return content;
			}
			
			this._addDefaultEvents = function() {
				this.attachEvent('setElement', 'setValue');
			}
			
			this._replaceFunctionCalls = function(content) {
					if (content == null) content = '';
				var functionCalls = content.match(/callAction[a-zA-Z\-_|0-9\.\/:?&@#=]+/g);
					if (functionCalls!= null) {
							for (var n = 0; n < functionCalls.length; n++) {
								
								var functionCall = functionCalls[n].replace("callAction", '');
								var params = new Array;
									if (functionCall.indexOf('|') != -1) {
										var explode = functionCall.split('|');
										functionCall = explode[0];
											for (var m = 1; m < explode.length; m++) params[params.length] = explode[m];
									}
								var functionCallWindow = _instanceName+'.' + functionCall + 'Window';
								
									if (parentInstanceName != null) functionCallWindow = parentInstanceName + '.'+ functionCallWindow;
									if (typeof(eval(functionCallWindow)) == 'function') {
										functionCall = functionCallWindow;
										//Add any params;
										functionCall += '(';
											if (params.length > 0) functionCall += "'" + params.join("','") + "'";
										functionCall += ');';
										//alert(functionCall);
									} else if ((parentInstanceName != null) && (typeof(eval(parentInstanceName+'.'+functionCall)) == 'function')) {
										functionCall = parentInstanceName+'.'+functionCall;
										//Add any params;
										functionCall += '(';
											if (params.length > 0) functionCall += "'" + params.join("','") + "'";
										functionCall += ');';
										//alert(functionCall);
									} else {
										var function_to_run = functionCall;
											if (params.length > 0) function_to_run += "','" + params.join(',');
										functionCall = _instanceName+".callEvent('"+function_to_run+"');";
											if (parentInstanceName != null) functionCall = parentInstanceName + '.'+ functionCall;
									
									}
								content = this._replaceItem(content, functionCalls[n], functionCall);
							}
					}
				return content;
			}
			
			this._resetContentHeight = function() {
					if (_windowElement == null) return;
					if (this.getStyle('height') == 'auto') {
						this.setStyle('height', 'auto', true);
						this.setStyle('height', _windowElement.offsetHeight, true);
					}
			}
			
			this._replaceItem = function(haystack, needle, replacement) {
				var temp = haystack.split(needle);
				return temp.join(replacement);
			}

			
			this.destroyWindow = function() {
				document.body.removeChild(_windowElement);
				document.body.removeChild(_windowBackdropElement);
				_windowElement = null;
			}
			
			this.getAllElementsInSection = function(sectionName) {
				var returnElements = new Array;
					if (sectionName == null) {
						var section = _windowElement;
					} else {
						var section = (document.getElementById('window' + sectionName + '_' +_windowId) ? document.getElementById('window' + sectionName + '_' +_windowId) : null);
					}
					if (section != null) {
						var allElements = section.getElementsByTagName('*');
							for (var n = 0; n < allElements.length; n++) {
								var tag = section.getElementsByTagName('*').item(n);
								returnElements[returnElements.length] = tag;
							}
					}
				return returnElements;
			}
		/*
			Event Handleing.
		*/
			this.createEventIdentifier = function() {
				var identifer = Math.ceil(Math.random()*100000);	
				
				return identifer;
			}
			
			this.createEvents = function(type) {
					if (_events[type] == null) _events[type] = new Array;
			}
			
			this.attachEvent = function(type, functionName, overwritable, overwriteOld) {
				type = type.toLowerCase();
				this.createEvents(type);
					if (overwriteOld == null) overwriteOld= false;
					if (overwritable == null) overwritable = true;
				var newFunctions = new Array;
				
					for (var eventIdentifier in _events[type]) {
							if (!_events[type][eventIdentifier].overwritable || !overwriteOld) newFunctions[eventIdentifier] = _events[type][eventIdentifier];
					}
					
				var newFunction = new Array;
				newFunction['functionCall'] = functionName;
				newFunction['overwritable'] = overwritable;
				
				var newIdentifier =this.createEventIdentifier();
				
				newFunctions[newIdentifier] = newFunction;
				
				_events[type] = newFunctions;
				
				return newIdentifier; //Return the identifier;
			}
			
			this.unAttachEvent = function(type, identifier) {
				type = type.toLowerCase();
				var newFunctions = new Array;
				
					for (var eventIdentifier in _events[type]) {
							if (eventIdentifier != identifier) newFunctions[eventIdentifier] = _events[type][eventIdentifier];
					}
					
				_events[type] = newFunctions;
			}
			
			this.callEvent = function(type, callString) {
				type = type.toLowerCase();
					if (callString == null) callString = '';
				this.createEvents(type);
				
					for (var eventIdentifier in _events[type]) {
						var string = callString;
						eval(_events[type][eventIdentifier].functionCall);
					}
			}
			
			this.setValue = function(string) {
				
					if ((string ==null) || (string == '') || (string.indexOf('-') == -1)) return false;
				var explode = string.split(',');
				this.setElementValue(explode[0], explode[1]);
			}
		/*
			Public Functions
		*/
		
			this.getTemplateVariableName = function(name) {
				return elementToChange = 'window'+name.toLowerCase()+'_'+_windowId;
			}
			
			this.elementExists = function(element) {
					if (document.getElementById(element)) return true;
				return false;
			}
			
			this.setElementContents = function(element, contents) {
					if (this.elementExists(element)) {
							if (document.getElementById(element).value || (document.getElementById(element).value == '')) {
								document.getElementById(element).value = contents;
							} else {
								document.getElementById(element).innerHTML = this._replaceFunctionCalls(this._replaceWindowSections(contents));
							}
					}
			}
			
			this.setElementStyle = function(element, name, value) {
					if (this.elementExists(element)) 	document.getElementById(element).style[name] = value;
			}
			
			this.getElementStyle = function(element, name) {
					if (this.elementExists(element)) 	return document.getElementById(element).style[name];
			}
					
			this.getTemplateVariable = function(name) {
					if (_templateVariables[name] == null) _templateVariables[name] = false;
				return _templateVariables[name];
			}
			
			this.setTemplateVariable = function(name, value) {
				
				_templateVariables[name] = value;
					if (_windowElement) {
						var elementToChange = this.getTemplateVariableName(name);
						this.setElementContents(elementToChange, value);
							if (value == '') {
								this.hideTemplateVariable(name, true);
							} else {
								this.showTemplateVariable(name, true);
							}
					}
				this._resetContentHeight();
				this.callEvent('set'+name);
			}
			
			this.hideTemplateVariable = function(name, completelyHide) {
					if (completelyHide == null) completelyHide = false;
				var elementToChange = this.getTemplateVariableName(name);
				this.setElementStyle(elementToChange, 'visibility', 'hidden');
					if (completelyHide) this.setElementStyle(elementToChange, 'display', 'none');
			}
			
			this.showTemplateVariable = function(name) {
				var elementToChange = this.getTemplateVariableName(name);
				this.setElementStyle(elementToChange, 'visibility', 'visible');
					if (this.getElementStyle(elementToChange, 'display') == 'none') this.setElementStyle(elementToChange, 'display', 'block');
			}
			
			this.getStyle = function(name) {
					if (_windowStyles[name] == null) _windowStyles[name] = false;
				return _windowStyles[name];
			}
			
			this.getProperty = function(name) {
					if (!_windowElement || (_windowElement[name] == null)) return false;
				return _windowElement[name];
			}
			
		/*
			Function auto center.
			
			Resets the placement to center the popup
		*/
			this.autoCenter = function(){
				//Lets set the width & height to auto.
				this.setStyle('width', 'auto', true);
				this.setStyle('height', 'auto', true);
				//Now lets get the offset width & height;
				var trueWidth = parseInt(this.setStyle('width', this.getProperty('offsetWidth')+'px', true));
				var trueHeight = parseInt(this.setStyle('height', this.getProperty('offsetHeight')+'px', true));
				//Now lets set the left & top to 50%;
				this.setStyle('left', '50%', true);
				this.setStyle('top', '50%', true);
				//Now lets set the margin top & margin left to (height/2)*-1 & (width/2)*-1 respectively.
				this.setStyle('marginLeft', (Math.round(trueWidth/2)*-1)+'px', true);
				this.setStyle('marginTop', (Math.round(trueHeight/2)*-1)+'px', true);
			}
			
			this.setStyle = function(name, value, ignoreCache) {
					if (ignoreCache == null) ignoreCache = false;
					if (!ignoreCache) _windowStyles[name] = value;
					if (_windowElement) _windowElement.style[name] = value;
			//	alert(name + ' - ' + value);
				return value;
			}
			
			this.setWindowTemplate = function(templateString) {
				_windowTemplate = templateString;
					if (_windowElement) this.createWindowHTML();
			}
		
			this.elementIsType = function(element, searchType) {
					if ((element.id == searchType) || (element.name == searchType) || ((element.type == searchType) || ((searchType == 'select') && ((element.type == 'select-one') || (element.type == 'select-multiple'))))) { //((searchType == 'select') && (element.type == 'select-one'))
						if ((element.type == 'checkbox' ) || (element.type == 'radio')) {
								if (element.checked) return true;
						} else {
							return true;
						}
					}
				return false;
			}
			
		//Returns the value of element specified by name.
			this.getElementValue = function(elementName, valueToFind) {
				var returnValue = '';
				var allElements = this.getAllElementsInSection();
					for (var n = 0; n < allElements.length; n++) {
						
							if (this.elementIsType(allElements[n], elementName)) {
									if (valueToFind == null) {
										returnValue = ((allElements[n].value || (allElements[n].value == '')) ? allElements[n].value : allElements[n].innerHTML);
									} else {
										returnValue = allElements[n][valueToFind];
									}
								break;
							}
					}
				return returnValue;
			}

		
		//Returns the value of all the elements given by a type.
			this.getElementValues = function(type) {
				var returnArray = new Array;
				var allElements = this.getAllElementsInSection();
					for (var n = 0; n < allElements.length; n++) {
							if (this.elementIsType(allElements[n], type)) {
								
								var newElement = new Array;
								newElement['name'] = (allElements[n].name ? allElements[n].name : allElements[n].id);
									if (allElements[n].type == 'select-multiple') {
										newElement['value'] = new Array;
											for (var i = 0; i < allElements[n].options.length; i++) {
													if (allElements[n].options[i].selected) newElement['value'][newElement['value'].length] = allElements[n].options[i].value;
											}
										
									} else {
										newElement['value'] = ((allElements[n].value || (allElements[n].value == '')) ? allElements[n].value : allElements[n].innerHTML);
									}
								returnArray[returnArray.length] = newElement;
							}
					}
				return returnArray;
			}
			
			this.setFocus = function(elementName) {
				var allElements = this.getAllElementsInSection();
					for (var n = 0; n < allElements.length; n++) {
							if (this.elementIsType(allElements[n], elementName)) {
								document.getElementById(allElements[n].id).focus();
							}
					}
			}
			
		//Set the value of an element
			this.setElementValue = function(elementName, setValue, valueToSet) {
					if (valueToSet == null) valueToSet = 'value';
				var returnValue = '';
				var allElements = this.getAllElementsInSection();
					for (var n = 0; n < allElements.length; n++) {
							if (this.elementIsType(allElements[n], elementName)) {
									if (valueToSet == 'value') {
											if	(allElements[n].value) {
												document.getElementById(allElements[n].id).value = setValue;
											} else {
												document.getElementById(allElements[n].id).innerHTML = setValue;
											}
									} else {
										document.getElementById(allElements[n].id)[valueToSet] = setValue;
									}
							}
					}
			}
			
		/* Now starts the default for box creation. */
		_windowStyles['position'] = 'fixed';
		_windowStyles['top'] = '50px';
		_windowStyles['left'] = '50%';
		_windowStyles['marginLeft'] = '-300px';
		_windowStyles['width'] = 'auto';
		_windowStyles['height'] = 'auto';
	}
