(function ($) {
	$(document).ready(function() {
	    $.fn.setCursorPosition = function(pos) {
	        if ($(this).get(0).setSelectionRange) {
	            $(this).get(0).setSelectionRange(pos, pos);
	        } else if ($(this).get(0).createTextRange) {
				var range = $(this).get(0).createTextRange();
				range.collapse(true);
				range.moveEnd('character', pos);
				range.moveStart('character', pos);
				range.select();
	        }
	    }

	    $('.search .hidden, .register .hidden, .quicksearch .hidden, .newsletter .hidden, .mail .hidden').each(function(i) {
			$('#' + $(this).attr('for')).attr('value', $(this).html());
	        $(this).hide();
	    });

	    $('.search .input-text, .register .input-text, .quicksearch .input-text, .newsletter .input-text, .mail .input-text').focus(function() {
	        if ($("label[for='" + $(this).attr('id') + "']").html() == this.value) {
	            $(this).val('').addClass('focus').setCursorPosition(0);
	        }
	    });

	    $('.search .input-text, .register .input-text, .quicksearch .input-text, .newsletter .input-text, .mail .input-text').keypress(function() {
	        if ($("label[for='" + $(this).attr('id') + "']").html() == this.value) {
	            this.value = '';
	            $(this).removeClass('focus');
	        }
	    });

	    $('.search .input-text, .register .input-text, .quicksearch .input-text, .newsletter .input-text, .mail .input-text').blur(function() {
	        $(this).removeClass('focus');
	        if (this.value == '') {
				this.value = $("label[for='" + $(this).attr('id') + "']").html();
	        }
	    });

		$('#from').after('<span id="dash">&mdash;</span>');
		$('#from, #to').css('margin-bottom', '16px');

		$('#ngo-event-register-form #edit-submit').click(function() {
			$('.register .input-text').each(function(i) {
				if ($("label[for='" + $(this).attr('id') + "']").html() == this.value) {
					$(this).attr('value', '');
				}
			});
			return true;
		});
	});
}) (jQuery);

//Ngo left search box dissapearing texts
jQuery().ready(function()
{
	var item = '#left-search-query';
	var orig_color = jQuery(item).attr('style');
	var orig_value = jQuery(item).attr('value');
	jQuery(item).focus(function()
	{
		if(jQuery(this).attr('value')===orig_value)
		{
			jQuery(this).attr('value', '');
			jQuery(this).attr('style', '');
		}
	})
	jQuery(item).blur(function()
	{
		if(jQuery(this).attr('value')==='')
		{
			jQuery(this).attr('value', orig_value);
			jQuery(this).attr('style', orig_color);
		}
	});
//	
	var item2 = '#edit-end-datepicker-popup-0';
	var orig_color2 = jQuery(item2).attr('style');
	var orig_value2 = jQuery(item2).attr('value');
	jQuery(item2).focus(function()
	{
		if(jQuery(this).attr('value')===orig_value2)
		{
			jQuery(this).attr('value', '');
			jQuery(this).attr('style', '');
		}
	})
	jQuery(item2).blur(function()
	{
		if(jQuery(this).attr('value')==='')
		{
			jQuery(this).attr('value', orig_value2);
			jQuery(this).attr('style', orig_color2);
		}
	});
	
	var item3 = '#edit-start-datepicker-popup-0';
	var orig_color3 = jQuery(item3).attr('style');
	var orig_value3 = jQuery(item3).attr('value');
	jQuery(item3).focus(function()
	{
		if(jQuery(this).attr('value')===orig_value3)
		{
			jQuery(this).attr('value', '');
			jQuery(this).attr('style', '');
		}
	})
	jQuery(item3).blur(function()
	{
		if(jQuery(this).attr('value')==='')
		{
			jQuery(this).attr('value', orig_value3);
			jQuery(this).attr('style', orig_color3);
		}
	});
});;

