/**
 * @name highlightFields
 */
function highlightFields()
{
	if(fieldnames.length > 0)
	{
		for(i = 0; i < fieldnames.length; i++) 
		{
			$('input[name=' + fieldnames[i] + ']').css('backgroundColor', '#FFEFEF').focus(function() {
				this.style.backgroundColor = '#FFFFFF';
			});
			
			$('textarea[name=' + fieldnames[i] + ']').css('backgroundColor', '#FFEFEF').focus(function() {
				this.style.backgroundColor = '#FFFFFF';
			});
		}
	}
}

/**
 * @name selectByCaption
 * @desc custom label element
 */
function selectByCaption()
{
	$('.capt-select').each(function()
	{
		$(this).click(function()
		{
			if($(this).prev().attr('type') == 'checkbox')
			{
				if($(this).prev().is(':checked'))
					$(this).prev().attr('checked', false);
				else $(this).prev().attr('checked', true);
				
				// call the event
				$(this).prev().change();
			}
			else if($(this).prev().attr('type') == 'radio')
			{
				$(this).prev().attr('checked', true);
				
				// call the event
				$(this).prev().change();
			}
		});
	});
}

/**
 * @name animateButton
 */
function animateButton()
{
	$('.button').mousedown(function() {
		$(this).css('background-color', '#474747');
	});
	
	$('.button').mouseup(function() {
		$(this).css('background-color', '#018D9C');
	});
}

/**
 * @name clearOnFocus
 */
function clearOnFocus()
{
	$('input.clearOnFocus').css('font-style', 'italic');
	$('input.clearOnFocus').css('color', '#919191');
	$('input.clearOnFocus').bind('focus change', function() {
		$(this).css('font-style', 'normal');
		$(this).css('color', '#4F4F4F');
		if (!$(this).data('originalValue')) {
			$(this).data('originalValue', $(this).val());
		}
		if ($(this).val() != '' && $(this).val() == $(this).data('originalValue')) {
			$(this).val('');
		}
	}).blur(function() {
		if ($(this).val() == '') {
			$(this).css('font-style', 'italic');
			$(this).css('color', '#919191');
			$(this).val($(this).data('originalValue'));
		}
	});
}

/**
 * @name onLoad
 */
$(function() {
	highlightFields();
	selectByCaption();
	animateButton();
	clearOnFocus();
});
