// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function auto_clear_field(field_id, text) {
	if (field_id == 'password') {
		$('#'+field_id).hide();
		cls = $('#'+field_id).attr('class');
		val = text;
		$('#'+field_id).after("<input type='text' class='"+cls+" grey' value='"+val+"' id='tmp_" + field_id + "'/>");
		$('#tmp_'+field_id).focus( 
			function () {
				$(this).hide();
				$('#'+field_id).show();
					$('#'+field_id).focus();
			}
		);
		$('#tmp_'+field_id).click( 
			function () {
				$(this).hide();
				$('#'+field_id).show();
				$('#'+field_id).focus();
			}
			);
	} else {
		$('#'+field_id).addClass('grey');
		$('#'+field_id).focus(
			function () {
				if( $(this).val() == text) {
					$(this).val('');
					$(this).removeClass('grey');
				}
			}	
		);
		$('#'+field_id).click(	
			function () {
				if( $(this).val() == text) {
					$(this).val('');
					$(this).removeClass('grey');
				}
			}
		);
	}
	$('#'+field_id).blur(
		function () {
			if ($(this).val() == '') {
				if( $(this).hasClass('password') ) {
					$(this).hide();
					$('#tmp_'+$(this).attr('id')).show();
				} else {
					$(this).val(text);
					$(this).addClass('grey');
				}
			}
		}
	);
}

function change_tab(id) {
	$('.tab').removeClass('selected');
	$('#'+id).addClass('selected');
}

function fill_in_field(price, qty) {
	$('#price_field').val(price);
	$('#qty_field').val(qty);
	return false;
}

function update_profile_photo(user_id) {
	$.getScript('users/update_profile_photo/' + user_id );
}

function load_site_page(id, title) {
	window.open('/sites/'+id, title);
}

function load_user_page(id, title) {
	window.open('/users/'+id, title);
}