// TexTitle - adding a title to textboxes
// Copyright Jeffrey M. Tackett
// This software is licensed under the GPL.
// http://www.gnu.org/copyleft/gpl.html

function inputTitle(focusCls, blurCls, commonCls, textCls) {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion=parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById || operaVersion < 7) return;
	var inputarr=document.getElementsByTagName('input');
	var searchCls=focusCls + ' ';
	for (i=0; i < inputarr.length; i++){
		if (inputarr[i].className.indexOf(searchCls) != -1){
			inputarr[i].setAttribute('xtitle', ' ' + inputarr[i].getAttribute('title'));
			if (inputarr[i].type != 'password') {
        inputarr[i].setAttribute('value', inputarr[i].getAttribute('xtitle'));
      }
      if (blurCls == null) {
        blurCls=focusCls;
      }
      if (textCls == null) {
        textCls=blurCls;
      }
      if (commonCls) {
        commonCls=' ' + commonCls;
      } else {
        commonCls='';
      }
			inputarr[i].className=blurCls + commonCls;
			inputarr[i].onfocus=function(){
        if (this.getAttribute('xtitle') == this.value){
				  this.value='';
				}
				this.className=focusCls + commonCls;
			}
			inputarr[i].onblur=function(){
        if (this.value == '' && this.type != 'password') {
				  this.className=blurCls + commonCls;
				  this.value=this.getAttribute('xtitle');
				} else {
          this.className=textCls + commonCls;
        }
			}
		}
	}
}

