if (navigator.userAgent.indexOf("MSIE")>=0) window.attachEvent("onload",fieldsCaption);
else window.addEventListener("load",fieldsCaption,false);

function fieldsCaption() {
	var inputs=document.getElementsByTagName('input'),
		txtareas=document.getElementsByTagName('textarea'),
		labels=new Array(),
		colors=new Array(),
		order=0;
	for (var i=0, l=inputs.length;i<l;i++) {
		var input=inputs[i];
		if (input.getAttribute('type')=='text' && input.value!='') {
			input.setAttribute('order',order);
			labels[order]=input.value;
			colors[order]=input.style.color;
			order++;
			input.onfocus=function(){
				this.value=this.value==labels[this.getAttribute('order')]?'':this.value;
				this.style.color='#333333';
			}
			input.onblur=function(){
				if (this.value=='') {
					this.value=labels[this.getAttribute('order')];
					this.style.color=colors[this.getAttribute('order')];
				}
				else this.value=this.value;
			}
		}
	}
	for (var i=0, l=txtareas.length;i<l;i++) {
		var txtarea=txtareas[i];
		if (txtarea.value!='') {
			txtarea.setAttribute('order',order);
			labels[order]=txtarea.value;
			colors[order]=txtarea.style.color;
			order++;
			txtarea.onfocus=function(){
				this.value=this.value==labels[this.getAttribute('order')]?'':this.value;
				this.style.color='#333333';
			}
			txtarea.onblur=function(){
				if (this.value=='') {
					this.value=labels[this.getAttribute('order')];
					this.style.color=colors[this.getAttribute('order')];
				}
				else this.value=this.value;
			}
		}
	}
}
