
	function TextBox()
	{
	    this.x = 0;
	    this.y = 0;
		this.width = 0;
		this.height = 0;
		this.position = "relative";
		this.fontsize = 12;
		this.font = "Arial";
		this.fontcolor = "#000000";
		this.bordercolor = "#000000";
		this.name = "";
		this.htmlname = "";
		this.inputtype = "textbox";
		this.defaulttext = "";
		this.limit = 0;
		this.numbersonly = 0;
		this.limitarray=new Array();
		this.index = 0;
		this.parentDiv = 'myDiv';
	}
	
	TextBox.prototype.BuildMe = function(){

		var txt = document.createElement("div");
		this.htmlelement = txt;
		document.getElementById(this.parentDiv).appendChild(txt);
		this.PaintMe();
	}
	
	TextBox.prototype.PaintMe = function(){
		var buildHTML;
		buildHTML="";
		switch (this.inputtype) {
			case "textbox":
				buildHTML += "<input type=\"text\" ";
				break;
			case "password":
				buildHTML += "<input type=\"password\" ";
				break;			
			case "textarea":
				buildHTML += "<textarea ";
				break;
			case "select":
				buildHTML += "<select ";
				break;
		}
		
		buildHTML += "id='TextBox" + this.index + "' ";
		buildHTML += "onfocus='myArray[" + this.index + "].OnGotFocus();' ";
		buildHTML += "onkeyup='myArray[" + this.index + "].OnKeyUp(event);' ";
		buildHTML += "name=\"" + this.htmlname + "\" value=\"" + this.defaulttext + "\" style=\"";
		buildHTML += "position:absolute; ";
		buildHTML += "left:" + this.x + "px; ";
		buildHTML += "top:" + this.y + "px; ";
		buildHTML += "width:" + this.width + "px; ";
		buildHTML += "height:" + this.height + "px; ";
		buildHTML += "color:" + this.fontcolor + "; ";
		buildHTML += "background-color:transparent; ";
		buildHTML += "border-style: solid;";
		buildHTML += "border-color:" + this.bordercolor + "; ";
		buildHTML += "font-family:" + this.font + ";";
		buildHTML += "font-size:" + this.fontsize + "px;";
		buildHTML += "OverFlow:auto;";
		
		buildHTML += "\">\n";
		
		switch (this.inputtype) {
			case "textarea":
				buildHTML += this.defaulttext;
				buildHTML += "</textarea>\n";
				break;
			case "select":
				for(i=0;i<setSelection.length;i++){
					buildHTML += "<option value='" + setSelection[i] + "'";
					if(setSelection[i]==this.defaulttext){
						buildHTML += " SELECTED ";
					}
					buildHTML += ">" + setSelection[i] + "</option>";
				}
				buildHTML += "</select>\n";
				break;
		}
		
		this.htmlelement.innerHTML = buildHTML;
	}
	
	TextBox.prototype.GetValue = function(){
		return document.getElementById("TextBox" + this.index).value;
	}
	
	TextBox.prototype.SetValue = function(sValue){
		document.getElementById("TextBox" + this.index).value = sValue;
	}
	
	TextBox.prototype.OnGotFocus = function(){
		eventHandler(this.name,"gotfocus");
	}
	
	TextBox.prototype.OnKeyUp = function(e){
		var textValue;
		if(this.limit>0){
			textValue = document.getElementById("TextBox" + this.index).value;
			if(textValue.length>this.limit){
				document.getElementById("TextBox" + this.index).value = textValue.substring(0,this.limit);
			}
		}
		if(this.numbersonly>0){
			textValue = document.getElementById("TextBox" + this.index).value;
			var cCode;
			var newText;
			newText = "";
			for(i=0;i<textValue.length;i++){
				cCode = textValue.charCodeAt(i);
				if (cCode > 45 && cCode < 58) {
					newText += String.fromCharCode(cCode);
				}
			}
			document.getElementById("TextBox" + this.index).value = newText;
		}
		if(this.limitarray.length>0){
			textValue = document.getElementById("TextBox" + this.index).value;
			textLength = textValue.length;
			if(e.keyCode>64 && e.keyCode<91){
				if(textLength>0){
					foundMatch = 0;
					for(i=0;i<this.limitarray.length;i++){
						if(this.limitarray[i].length >= textLength){
							testString = this.limitarray[i].substr(0,textLength);
							if(testString.toLowerCase()==textValue.toLowerCase()){
								document.getElementById("TextBox" + this.index).value = this.limitarray[i];
								this.SetSelection(textLength,this.limitarray[i].length-textLength);
								foundMatch = 1;
								break;
							}
						}
					}
					if(foundMatch!=1){
						document.getElementById("TextBox" + this.index).value = "";
					}
				}
			}
		}
		eventHandler(this.name,"keyup");
	}
	
	TextBox.prototype.SetSelection = function(start, len){
	    var textarea = document.getElementById("TextBox" + this.index);
	    if(textarea.setSelectionRange){
	        textarea.setSelectionRange(parseInt(start), (parseInt(start)+parseInt(len)));
	    }
	    else{
	        var range = textarea.createTextRange();
	        range.collapse(true);
	        
	        range.moveStart('character',parseInt(start) );
	        range.moveEnd('character',parseInt(len));
	        range.select();
	    }
	}
