
	
/* form_values
---------------------------------------------------------------------------- */
function set_form_values(form_values) {

//volani fce
//	set_form_values(<?= json_encode($f); ?>);

	$('input[type="text"], select').each(function() {
		fld_name = $(this).attr('name') ;
		if (form_values[fld_name])
			$(this).val(form_values[fld_name]) ;
	}) ;
	$('textarea').each(function() {
		fld_name = $(this).attr('name') ;
		if (form_values[fld_name])
			$(this).html(form_values[fld_name]) ;
	}) ;
	$('input[type="checkbox"]').each(function() {
		fld_name = $(this).attr('name') ;
		if (form_values[fld_name] && form_values[fld_name] != "0")
			$(this).attr('checked', 'checked') ;
	}) ;
	$('input[type="radio"]').each(function() {
		fld_name = $(this).attr('name') ;
		if ($(this).val() == form_values[fld_name])
			$(this).attr('checked', 'checked') ;
	}) ;
	
}





/* jquery
---------------------------------------------------------------------------- */

$(document).ready(function() {

	var base = $('base').attr('href');
	
	function goToUrl(loc) {
		loc = base + loc ;
		window.location.assign( loc );
	}


/* ext links
---------------------------------------------------------------------------- */
	$("a[rel*=ext]")
		.addClass("ext")
		.click( function() {
			 window.open( $(this).attr('href') ); 
			 return false;
		}) ;


/* emails
---------------------------------------------------------------------------- */
	$("a[rel=email]").each( function(){
		var e = $(this).text() ;
		e = e.replace('/','@');
		$(this).attr('href', 'mailto:' + e);
		$(this).text(e);
	});
		
/* lightboxes
---------------------------------------------------------------------------- */
	$("a[rel*=box]").fancybox({
		/*	
		'overlayOpacity'	: 0.7,
		'overlayColor'		: '#000000',
		*/
		'titlePosition'		: 'inside',
		'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
			$counter = (currentIndex + 1) + ' / ' + currentArray.length ;
			return '<div class="fancybox-multititle">' + ($.trim(title).length ? '<span class="fr">' + $counter + '</span>' + title.replace(/\n/g,"<br/>") : '<span>' + $counter + '</span>' ) + '</div>';
		}
	});
	
/* ajax prepocitat/kosik
---------------------------------------------------------------------------- */

	$('#kosik_mini').click( function() {
		goToUrl('shop/kosik') ;
	}) ;
	
	
	$('.koupit').submit(function() {
		var formdata = $(this).serialize() ;
		var btn_do_kosiku = $('.btn_do_kosiku', this) ;
		
		btn_do_kosiku.attr('src', '_images/preloader.gif');
		//alert(formdata);
		$.ajax({
			url: '_modul/shop/prepocitat',
			data: formdata,
			dataType: 'json',
			success: function(json) {
				//$('#kosik_mini_sum').html(json.obj_sum).format({format:"#,###.00 Kč", locale:"cz"});
				//$('#kosik_mini_sum_dph').html(json.obj_sum_dph).format({format:"#,###.00 Kč s DPH", locale:"cz"});
				btn_do_kosiku.attr('src', '_images/true.png') ;
			},
			error: function(data) {
				alert('ajax error');
			}
		});
		return false ;
	});
	

}); // jquery
