var xhtmlTools = {
	make:function(tagname, attributes, children) {
		if(arguments.length == 2 &&
			 (attributes instanceof Array || typeof attributes == "string")) {
			children = attributes;
			attributes = null;
		}
		
		// Create the element
		var e = document.createElement(tagname);
		
		// Set attributes
		if(attributes) {
			for(var name in attributes) {
				switch(name) { 
					case "class": e.className=attributes[name]; break;
					case "onclick": 
//						alert(attributes[name]);
						if(window.addEventListener){ // Mozilla, Netscape, Firefox
							e.addEventListener('click', attributes[name], false);
						} else { // IE
							e.attachEvent('onclick', attributes[name], false);
						} 
						break;
					case "onchange": 
						if(window.addEventListener){ // Mozilla, Netscape, Firefox
							e.addEventListener('change', attributes[name], false);
						} else { // IE
							e.attachEvent('onchange', attributes[name], false);
						} 
						break;
					default: e.setAttribute(name, attributes[name]); break;
				}
			}
		}
		
		// Add children, if any where specified.
		if(children != null) {
			if(children instanceof Array) { // If it really is an array
				for(var i = 0; i < children.length; i++) {
					var child = children[i];
					if(typeof child == "string")
						child = document.createTextNode(child);
					e.appendChild(child);
				}
			} else if(typeof children == "string") { // Handle single text child
				e.appendChild(document.createTextNode(children));
			} else e.appendChild(children);			// Handle any other single child
		}
		
		// Finally, return the element;
		return e;
	},
	
	maker:function(tag) {
		return function(attrs, kids) {
			if(arguments.length == 1) return xhtmlTools.make(tag, attrs);
			else return xhtmlTools.make (tag, attrs, kids);
		}
	}
}


function insertAtCursor(myField, myValue) {
//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}



var html_tags = {"div":xhtmlTools.maker("div"),
				 "textarea":xhtmlTools.maker("textarea"),
				 "p":xhtmlTools.maker("p"),
				 "h4":xhtmlTools.maker("h4"),
				 "span":xhtmlTools.maker("span"),
				 "p":xhtmlTools.maker("p"),
				 "form":xhtmlTools.maker("form"),
				 "input":xhtmlTools.maker("input"),
				 "a":xhtmlTools.maker("a"),
				 "ul":xhtmlTools.maker("ul"),
				 "select":xhtmlTools.maker("select"),
				 "option":xhtmlTools.maker("option"),
				 "li":xhtmlTools.maker("li"),
				 "br":xhtmlTools.maker("br"),
				 "embed":xhtmlTools.maker("embed"),
				 "object":xhtmlTools.maker("object"),
				 "param":xhtmlTools.maker("param")};
