// JavaScript Document

var noaction = 0;

// ******************************************************************************************************************************

function pulseHeader() {
	
	noaction++;
	if (noaction > 30) {
		new Effect.Pulsate('hadicev', { pulses: 3, duration: 2 });
		noaction = 0;
	}
	
}

// ******************************************************************************************************************************

function gotoHomepage() {
	window.location = '/';
}

// ******************************************************************************************************************************

function gotoBasket() {
	window.location = '/cz/kosik';
}

// ******************************************************************************************************************************

function clearSearchText(id) {
	
	if ($(id).value == TEXT_ZADEJTE_HLEDANY_TEXT) {
		$(id).value = "";
	}
	$(id).setStyle( { color: '#111', fontStyle: 'normal' } );
	
}

// ******************************************************************************************************************************

function setSearchText(id) {

	if (!$(id).value) {
  		$(id).setStyle( { color: '#aaa', fontStyle: 'italic' } );
		$(id).value = TEXT_ZADEJTE_HLEDANY_TEXT;
	}
	
}

// ******************************************************************************************************************************

function checkSearchSubmit(id) {
	if (($(id).value == TEXT_ZADEJTE_HLEDANY_TEXT) || ($(id).value == '')) {
		alert(ERROR_ZADEJTE_HLEDANY_TEXT);
		return false;
	} else {
		return true;
	}
}

// ******************************************************************************************************************************
/*
function ajaxLoadTitulFoto() {
	new Ajax.Request('/ajax/titulfoto.php', {
			onSuccess: function(t) {
				$('titulfoto').update(t.responseText);
				}
			}
		);	
}
*/
// ******************************************************************************************************************************

function ajaxSetView(view) {
	new Ajax.Request('/ajax/setView.php?view=' + encodeURIComponent(view), {
			onSuccess: function(t) {
				window.location.reload();
				}
			}
		);	
}

// ******************************************************************************************************************************

function ajaxSetCPP(cpp) {
	new Ajax.Request('/ajax/setView.php?cpp=' + encodeURIComponent(cpp), {
			onSuccess: function(t) {
				window.location.reload();
				}
			}
		);	
}

// ******************************************************************************************************************************

function ajaxGetParamValues(id) {
//	$(id).update("<option>" + TEXT_NAHRAVAM + "</option>");
	new Ajax.Request('/ajax/getParamValues.php?id=' + encodeURIComponent(id), {
			onSuccess: function(t) {
				$(id).update(t.responseText);
				}
			}
		);	
}

// ******************************************************************************************************************************

function setVisible(id) {
	if ($(id)) {
		if ($(id).visible()) { 
			$(id).hide(); 
		} else { 
			$(id).show(); 
			ajaxGetParamValues(id);
		}
		
	}
}

// ******************************************************************************************************************************

function selectPage(sel,cou) {
	
	for(i=1; i<=cou; i++) {
		$('page' + i).hide();
		$('pager' + i).removeClassName('selectedPager');
	}
	
	$('page' + sel).show();
	$('pager' + sel).addClassName('selectedPager');
}

// ******************************************************************************************************************************

function checkNullOnSubmit() {
	
	ret = true;
	$$('input[rel="notnull"]').each(function(e) { 
		if (!e.value) {
			new Effect.Highlight(e, { startcolor: '#EEEEEE', endcolor: '#FF0000' });
			ret = false;
		}
	});
	return ret;
		
}

// ******************************************************************************************************************************
// ******************************************************************************************************************************
// ******************************************************************************************************************************

Event.observe(window, 'load', function() { 

	setSearchText('hledany_text');
	setSearchText('hledani_vlevo');

	if ($('hadicev')) {
		if (Prototype.Browser.IE) {
			$('hadicev').show();
		} else {
			new Effect.Appear('hadicev', { duration: 2.0, queue: 'end' });
			new PeriodicalExecuter(function() { pulseHeader(); }, 1);
		}
	}
/*	
	if ($('titulfoto')) {
		new PeriodicalExecuter(function() { ajaxLoadTitulFoto(); }, 5);
	}
*/	
}
);


