/* #################################################
# Projekt	: Care - Main Javascripts
# Stand		: 26.03.09
# Autor		: Daniel Zander, Source-Media.com
#################################################### */


// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// NORMAL
// ----------------------------------------------------------------------

$.fn.clearDef = function(){
	$(':input',this).each(function(){
		if ($(this).val()==$(this).attr('title'))
			$(this).val('').removeClass('default');
	});	
};



$(function(){//ready


// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Form
// ----------------------------------------------------------------------

// ---------- submit ----------

$('a.btn').click(function(){
	$(this).parent('form').submit();
	return false;
});


// ---------- default ----------

$('input[title]').livequery(function(){
	if (!$(this).val())
		$(this).addClass('default').val($(this).attr('title'));

	$(this).focus(function(){ //clear
		if ($(this).val() == (!$(this).attr('maxlength') ? $(this).attr('title'):
			$(this).attr('title').substr(0,$(this).attr('maxlength')))
		)
			$(this).val('').removeClass('default');
	}).blur(function(){ //restore
		if (!$(this).val())
			$(this).addClass('default').val($(this).attr('title'));
	});
});


// ---------- pass/type ----------

$('input.pw:not(.ready)').focus(function(){
	var p = $('<input class="pw ready" type="password" maxlength="12" />')
		.attr('name',$(this).attr('name'));
	$(this).replaceWith(p);
	p.focus();
});


// ---------- mailadmin ----------

$('input#madm').click(function(){
	var f = $('#webmail');
	
	if ($(this).is(':checked')){
		f.attr('action',f.attr('action').replace(/webmail/,'mailadmin'));
		$('input[type=text]',f).attr('name','loginname');
		$('input.pw',f).attr('name','password');
	} else {
		f.attr('action',f.attr('action').replace(/mailadmin/,'webmail'));
		$('input[type=text]',f).attr('name','_user');
		$('input.pw',f).attr('name','_pass');
	}
});


});//ready