﻿function daLabels() {
	var labels = document.getElementsByTagName( "label" );
	daLabelList = [];
	for( var i = 0; i < labels.length; i++ ) {
		var label = labels[i];
		if( ! label.className || ! label.className.match( /\bdaLabel\b/ )
			|| ! label.htmlFor ) continue;
		daLabelList.push( label );
		var input = document.getElementById( label.htmlFor ),
			cont = label.parentNode;
		if( ! input || cont != input.parentNode ) continue;
		var pickCss = [ cont, input ];
		for( var x in pickCss ) {
			var el = pickCss[x];
			el.css = window.getComputedStyle ? getComputedStyle( el, "" ) : el.currentStyle;
		}
		if( ! cont.css.position || cont.css.position == "static" ) cont.style.position = "relative";
		if( ! cont.css ) continue;
		label.style.position = "absolute";
		label.style.top = input.offsetTop + parseInt( input.css.paddingTop ) + "px";
		label.style.left = input.offsetLeft + parseInt( input.css.paddingLeft ) + "px";
		input.label = label;
		label.input = input;
		label.onmousedown = function() { this.input.focus(); }
		input.onfocus = function() { this.label.style.display = "none"; }
		input.onblur = function() { if( ! this.value ) this.label.style.display = ""; }
		if( input.value ) label.style.display = "none";
	}
}
daLabels();

daLabelInt = setInterval( "daLabelTic()", 500 );
function daLabelTic() {
	for( var i = 0; i < daLabelList.length; i++ ) {
		var l = daLabelList[ i ];
		if( l.input.value ) l.style.display = "none";
	}
}
