var activeClearText="";
var clearTextList=new Array();

function addClearText(obj, submit){
	if(!obj.id){obj.id=clearTextList.length;}
	clearTextList[obj.id]=false;
	obj.setAttribute("defaultValue", obj.value);
	obj.setAttribute("submit", submit.id);
	
	submit.setAttribute("input", obj.id);
	submit.onclick=function(){
		var input=document.getElementById(this.getAttribute("input"));
		if(input.value==input.defaultValue){input.value="";}
		return true;
	}

	obj.onfocus=function(e){
		activeClearText=this.id;
		document.onkeypress=function(e){
			if(!e){e=window.event;}

			var keyCode;
			if(e.keyCode){keyCode=e.keyCode;}
			if(!e.keyCode){keyCode=e.which;}

			if(keyCode==13){
				var submitId=document.getElementById(activeClearText).getAttribute("submit");
				document.getElementById(submitId).click();
				
				return false;
			}

			if((clearTextList[activeClearText]!=true)&&(document.getElementById(activeClearText).value!="")){clearTextList[activeClearText]=true;}

			return true;
		}
		if((this.value==this.getAttribute("defaultValue"))&&(clearTextList[this.id]==false)){
			this.value="";
		}
		return true;
	}

	obj.onblur=function(){
		activeClearText="";
		document.onkeypress=function(){return true;}

		if((this.value=="")&&(clearTextList[this.id]==false)){
			this.value=this.getAttribute("defaultValue");
		}

		return true;
	}
}
