if ('undefined' == typeof SWA) {
	var SWA = {};
}

SWA.Form = {
	
	_tipColor: '#89919D',
	_valueColor: '#626671',
	
	_labelValues: {},
	
	labelValue: function() {
		
		var $inputs = $('input[type=text].lv, textarea.lv');
		
		$inputs.each(function() {				
			var el = $(this), 
			    elId = el.attr('id'), 
			    labelValue = $('label[for=' + elId + ']').eq(0).text();
			
			if (labelValue) {
				SWA.Form._labelValues[elId] = labelValue;
				SWA.Form.setValue.apply(this, arguments);
			}
		})
		.focus(SWA.Form.unsetValue)
		.blur(SWA.Form.setValue);
			
		// naprawienie submitowania pustych pól
		var $form = $inputs.eq(0).parents('form').eq(0).submit(function(event) {			
			$inputs.each(SWA.Form.unsetValue);
		});
	},
	
	setValue: function() {
		var el = $(this);
		if (el.val() == '') {
			el.css({color: SWA.Form._tipColor}).val(SWA.Form._labelValues[el.attr('id')]);
		}
	},
	
	unsetValue: function() {
		var el = $(this).css({color: SWA.Form._valueColor});
		if (el.val() == SWA.Form._labelValues[el.attr('id')]) {
			el.val('');
		}
	}
};
