$(document).ready(function(){

	$("#tabs > ul").tabs();
	
	// search			
	if ($("#search_text").val() == "")
		$("#search_text").val($("#search_text").attr('title'));				
	
	$("#search_text").click(function(){
		if ($(this).hasClass('first')) {					
			$(this).val("");
			$(this).removeClass('first');
		}
	});	
	
	$("#search_text").change(function(){
		if ($("#search_text").val() == "")
		{
			$("#search_text").val($("#search_text").attr('title'));
			$("#search_text").addClass('first');
		}
		
	}).change();
	
	$("#filter_sort").change(function(){
		document.location.href = filter_url+"/?order="+$(this).val();		
	});
	
	$("#list_limit").change(function(){
		document.location.href = filter_url+"/?list_limit="+$(this).val();		
	});
	
	$("#vypis").change(function(){
		document.location.href = filter_url+"/?vypis="+$(this).val();		
	});
	
	$(".radio_img").click(function(){
		$(this).parent().find("input[type=radio]").get(0).checked = true;		
		$(this).parent().find("input[type=radio]").click();
	});
	
	
	
	$(".tooltip").simpletooltip(); 
});

function fulltext()
{/*
	if ($("#search_text").val().length <= 3)
	{
		alert('Zadejte hledaný výraz delší než 3 znaky!');
		return false;
	}*/
	return true;
}

function calouneni(id)
{
	$(".div_calouneni").each(function(){
		if ($(this).attr('id') == id)
		{
			if ($(this).hasClass('hidden'))
			{
				$(this).removeClass('hidden');
			}
		}
		else
		{
			if (!$(this).hasClass('hidden'))
			{
				$(this).addClass('hidden');
			}
		}
	});
}

function addSeparatorsNF(nStr, inD, outD, sep)
{
	nStr += '';
	var dpos = nStr.indexOf(inD);
	var nStrEnd = '';
	if (dpos != -1) {
		nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
		nStr = nStr.substring(0, dpos);
	}
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(nStr)) {
		nStr = nStr.replace(rgx, '$1' + sep + '$2');
	}
	
	if (nStrEnd.length == 0)
	{
		nStr += ",-";
	}
	else
	{
		nStrEnd = nStrEnd.substring(0, 3);
	}
	return nStr + nStrEnd;
}


function change_price(cena, typ)
{
		
	switch(typ)
	{
		case 'sit':
			$(".radio-barva").each(function(){
				$(this).get(0).checked = false;				
			});
			vzornik_sit_price = parseFloat(cena);
			vzornik_barva_price = 0;
			break;
		case 'potah':
			$(".radio-barva").each(function(){
				$(this).get(0).checked = false;				
			});
			vzornik_potah_price = parseFloat(cena);
			vzornik_barva_price = 0;
			break;
		case 'barva':
			$(".radio-sit, .radio-potah").each(function(){
				$(this).get(0).checked = false;
			});			
			vzornik_barva_price = parseFloat(cena);
			vzornik_potah_price = 0;
			vzornik_sit_price = 0;
			break;
	
	}
	
	calc_price();
}

function change_price_doplnek(cena, id)
{	
	if ($("#"+id).get(0).checked)
		doplnek_price += parseFloat(cena);
	else
		doplnek_price -= parseFloat(cena);
	calc_price();
}

function calc_price()
{
	var vzornik_price = vzornik_sit_price + vzornik_potah_price + vzornik_barva_price;
	var bp = base_price + vzornik_price + doplnek_price;
	var bpa = base_price_action + vzornik_price + doplnek_price;
	
	$("#price").text(addSeparatorsNF(bp, ".", ",", " "));
	$("#price_dph").text(addSeparatorsNF(bp+((bp/100)*dph), ".", ",", " "));
	$("#price_action").text(addSeparatorsNF(bpa, ".", ",", " "));
	$("#price_action_dph").text(addSeparatorsNF(bpa+((bpa/100)*dph), ".", ",", " "));
}	

function checkform_dotaz()
{
	if ($("#jmeno").val() == '')
	{
		alert('Vyplňte prosím své jméno');
		return false;
	}
	if ($("#email2").val() == '')
	{
		alert('Vyplňte prosím svůj email');
		return false;
	}
	if ($("#text").val() == '')
	{
		alert('Vyplňte prosím text dotazu');
		return false;
	}
	return true;
}




