
// Visa/Göm Username/password
function input(selector) {
	var default_value = $(selector).val();
	var is_password = $(selector).attr('type') == 'password';

	if (is_password) {
		$(selector).after('<input type="text" name="' + $(selector).attr('name') + '_tmp" value="' + default_value + '">');
		
		$(selector).val('').hide();

		// $(selector) = INPUT TYPE="PASSWORD"
		$(selector)
		.mouseleave(function() {
			if ($(this).val() == '' && !$(this).is('.focus')) {
				$(this).hide();
				$(this).next().show();
				$(this).removeClass('focus');
			}
		})
		.focus(function() {
			$(this).addClass('focus');
		})
		.blur(function() {
			if ($(this).val() == '') {
				$(this).hide();
				$(this).next().show();
			}
		});
		
		// $(selector).next() = INPUT TYPE="TEXT"
		$(selector).next()
		.mouseenter(function() {
			$(this).hide();
			$(selector).show();
		})
		.focus(function() {
			$(this).hide();
			$(selector).show().focus();
		});
	}
	else {
		$(selector)
		.focus(function() {
			$(this).addClass('focus');
			if($(selector).val() == default_value) {
				$(this).val('');
			}
		})	
		.blur(function() {
			$(this).removeClass('focus');
			if ($(this).val() == '') {
				$(this).val(default_value);
			}
		})
		.mouseenter(function() {
			if($(selector).val() == default_value) {
				$(selector).val('');
			}
		})
		.mouseleave(function() {
			if ($(this).val() == '' && !$(this).is('.focus')) {
				$(this).val(default_value);
			}
		});
	}
}


$(function(e) {

	$('button').each(function() {
        var cls = $(this).attr('class') ? " " + $(this).attr('class') : ""
		$(this).after('<a class="button' + cls + '" href="#" onclick="this.blur();"><span>' + $(this).val() + '</span></a>').remove();
	});

	$("a.submit").click(function(e){
		e.preventDefault();
		$(this).parents('form').submit();
	});
	
	$('input').keypress(function(e){
		if (e.which == 13) {
			$(this).parentsUntil('form').parent().submit();
		}
	});


});

