// JavaScript Document

function controlsWrapper() {
	
	this.isIE=(navigator.appName=='Microsoft Internet Explorer');

	this.browserIsCapable = function () {
		return (document.getElementById && document.createElement);
	}
	
	this.createControl = function (elementType) {
		if (this.browserIsCapable()) {
			return document.createElement(elementType);
		} else {
			alert('Your browser is not capable to create elements!');
			return null;
		}
	}

	this.createTag = function (elementType) {
		if (arguments.length==0) {
			alert('input type not specified');
			return null;
		} else {
			if (arguments.length>=1) {
				theObj=this.createControl(elementType);
				if (theObj==null) return;
				theObj.type=arguments[0];
			}
			if (arguments.length>=2) {
				for (var attr in arguments[1]) {
					theObj.setAttribute(attr,arguments[1][attr]);
				}
			}
			if (arguments.length==3) {
				for (var evnt in arguments[2]) {
					if (theObj.addEventListener)
						theObj.addEventListener(evnt,eval(arguments[2][evnt]),false);
					else if (this.isIE) {
						theObj.attachEvent('on'+evnt,eval(arguments[2][evnt]));
					}
				}
			}
			return theObj;
		}
	}

	this.createInput = function () {
		if (arguments.length==0) {
			alert('input type not specified');
			return null;
		} else {
			if (arguments.length>=1) {
				theObj=this.createControl('input');
				if (theObj==null) return;
				theObj.type=arguments[0];
			}
			if (arguments.length>=2) {
				for (var attr in arguments[1]) {
					theObj.setAttribute(attr,arguments[1][attr]);
				}
			}
			if (arguments.length==3) {
				for (var evnt in arguments[2]) {
					if (theObj.addEventListener)
						theObj.addEventListener(evnt,eval(arguments[2][evnt]),false);
					else if (this.isIE) {
						theObj.attachEvent('on'+evnt,eval(arguments[2][evnt]));
					}
				}
			}
			return theObj;
		}
	}
	this.createTextBox = function (ctrlAttr,ctrlEvents) {
		if (arguments.length==0)
			return this.createInput('text');
		else if (arguments.length==1)
			return this.createInput('text',ctrlAttr);
		else if (arguments.length==2)
			return this.createInput('text',ctrlAttr,ctrlEvents);
		else
			return null;
	}

	this.createFileBox = function (ctrlAttr,ctrlEvents) {
		if (arguments.length==0)
			return this.createInput('file');
		else if (arguments.length==1)
			return this.createInput('file',ctrlAttr);
		else if (arguments.length==2)
			return this.createInput('file',ctrlAttr,ctrlEvents);
		else
			return null;
	}

	this.createButton = function (ctrlAttr,ctrlEvents) {
		if (arguments.length==0)
			return this.createInput('button');
		else if (arguments.length==1)
			return this.createInput('button',ctrlAttr);
		else if (arguments.length==2)
			return this.createInput('button',ctrlAttr,ctrlEvents);
		else
			return null;
	}

	this.createImg = function (ctrlAttr,ctrlEvents) {
		if (arguments.length==0)
			return this.createTag('img');
		else if (arguments.length==1)
			return this.createTag('img',ctrlAttr);
		else if (arguments.length==2)
			return this.createTag('img',ctrlAttr,ctrlEvents);
		else
			return null;
	}
	
	this.createIframe = function (ctrlAttr,ctrlEvents) {
		if (arguments.length==0)
			return this.createTag('iframe');
		else if (arguments.length==1)
			return this.createTag('iframe',ctrlAttr);
		else if (arguments.length==2)
			return this.createTag('iframe',ctrlAttr,ctrlEvents);
		else
			return null;
	}
	
	this.setEvents = function(theObj,ctrlEvents) {
		if (arguments.length<2)
			alert('You must specify the Object and the Events to be set');		
		else {
			for (var evnt in arguments[1]) {
				if (theObj.addEventListener)
					theObj.addEventListener(evnt,eval(arguments[1][evnt]),false);
				else if (this.isIE) {
					theObj.attachEvent('on'+evnt,eval(arguments[1][evnt]));
				}
			}
			return theObj;
		}
	}
	this.setAttributes = function(theObj,ctrlAttr) {
		if (arguments.length<2)
			alert('You must specify the Object and the Attributes to be set');		
		else {
			for (var attr in arguments[1]) {
				theObj.setAttribute(attr,arguments[1][attr]);
			}
			return theObj;
		}
	}
}
