/*============ SEZNAM FUNKCIONALIT =================
#1 - Vymazání textu v inputu po kliknutí
#2 - Zpřístupnění tlačítka po odsouhlasení podmínek
#3 - Externi odkazy
#4 - Tisk stránek
#5 - Animovaný kalendář
==================================================*/

// #1 - Vymazání textu v inputu po kliknutí
function inputHelpText(selector, defaultValue){
	
	var searchFocusedClass = 'search-focused';

	// Input s heslem - nelze přepisoval attr "value", vytvoříme náhradní input s type="text"
	if($(selector).attr('type') == 'password'){
		var fakePassInput = '<input id="password-clear" class="fi-text" type="text" value="' + defaultValue + '" autocomplete="off">'
		$(selector).hide().after(fakePassInput);
	
		$('#password-clear').focus(function(){
			$(this).hide();									
			$(selector).show().trigger('focus');
		});
		
		$(selector).blur(function(){
			if($(this).val() == ''){
				$(this).hide();
				$('#password-clear').show();
			}
		});
	}
	// Klasický input
	else {
		$(selector).each(function() {
			if($.trim(this.value) == ''){
				this.value = defaultValue;
			}
		});
		
		$(selector).focus(function(){
			if(this.value == defaultValue){
				this.value = '';
				$(this).parent().addClass(searchFocusedClass);
			}
		});
		
		$(selector).blur(function(){
			if($.trim(this.value) == ''){
				this.value = defaultValue;
				$(this).parent().removeClass(searchFocusedClass);
			}
		});
	}
}
	

// #3 - Externi odkazy - cílovou stránku otevře v novém okně/panelu
//	  -	Automaticky se vyberou odkazy s URL začínající http:// a odkazy označené class "newWindow"
var externalLinks = function() {
	$.expr[':'].external = function(obj){	// knihovnu jQuery rozšíříme o selektor "external"
		return !obj.href.match(/^mailto\:/) && (obj.hostname != location.hostname);     //Vybereme pouze externi odkzazy
	};
	
	$('a:external, a.newWindow')
		.addClass('link-external')
		.append('<span class="h1dden"> (externí odkaz)</span>')     // indikator externiho odkazu pro handikepované uživatele
		.click(function(){
			window.open(this.href);
			return false;
		});
}
