/*
.---------------------------------------------------------------------------.
|  Software: Web CMS                                                        |
|   Version: $Id:: vyhledavani.js 1317 2010-01-17 22:50:11Z jakub.boucek  $ |
|   Contact: info@koldasoft.cz                                              |
|      Info: http://www.koldasoft.cz/                                       |
|   Support: http://www.koldasoft.cz/kontakt/                               |
| ------------------------------------------------------------------------- |
|    Author: Koldasoft, s.r.o.                                              |
|    Author: Jakub Bouček, Jiří Kolařík and someone others                  |
| Copyright (c) 2007-2010, Koldasoft, s.r.o., Rights Reserved.              |
| ------------------------------------------------------------------------- |
|   License: Distributed under the Koldasoft Private/Individual License     |
|            == licence provided determined only, no for free use ==        |
| This program is distributed in the hope that it will be useful - WITHOUT  |
| ANY WARRANTY where is not defined by approved contract                    |
'---------------------------------------------------------------------------'

/**
 * Web CMS
 * NOTE: Designed for use with PHP version 5.2 and up
 * @package Web CMS
 * @author Koldasoft, s.r.o.
 * @copyright 2007 - 2010 Koldasoft, s.r.o.
 * @version $Id: vyhledavani.js 1317 2010-01-17 22:50:11Z jakub.boucek $
 */

var searchUpdateTriggerTimeout=null;var initTimeout=0;var triggerTimeout=500;var katalogUrlBase="/katalog/";var podnikUrlBase="/podnik/";var imgTypeUrlPrefix="/img/search_ilust_";var imgTypeUrlPostfix=".gif";var imgFlagUrlPrefix="/img/flags/";var imgFlagUrlPostfix=".gif";var searchGUID=null;$(document).ready(function(){var form=$("#search_form");$("#form_fulltext",form).attr('autocomplete','off');form.find(":checkbox").click(function(){searchUpdateTrigger(form,triggerTimeout)});form.find("select").change(function(){searchUpdateTrigger(form,triggerTimeout)});form.find(":text").keyup(function(){if(this.lastValue!=this.value){searchUpdateTrigger(form,triggerTimeout);this.lastValue=this.value;}});form.find("#form_property_vouchers,#form_tail_property_vouchers").click(function(){val=this.checked;form.find("#form_property_vouchers,#form_tail_property_vouchers").each(function(){this.checked=val;});SwitchFlagButton($('#form_property_vouchers').parent());});form.find("#form_property_payment,#form_tail_property_payment").click(function(){val=this.checked;form.find("#form_property_payment,#form_tail_property_payment").each(function(){this.checked=val;});SwitchFlagButton($('#form_property_payment').parent());});$(".sorry").text('Čekejte, prosím…');searchUpdateTrigger(form,initTimeout);$('#form_send_box').hide();$('.icons_vyber').each(function(){var vyber=$(this);var check=$(':checkbox',vyber);check.click(function(){SwitchFlagButton(vyber)});});var more_box_value_sum=0;more_box_value_sum+=$(':checked','#form_more_box').size();$('select','#form_more_box').each(function(){more_box_value_sum+=parseInt($(this).val());});if(!more_box_value_sum){$('#form_more_box').hide();$('#form_show_more').show().click(function(){$('#form_more_box').slideDown('slow');$(this).slideUp('fast');});}
$.post("/ajax.php",{action:'getSearchGiud'},function(data){$('#form_searchGIUD').val(data.searchGUID);},'json');});function SwitchFlagButton(vyber){var check=$(':checkbox',vyber);var img=$('img',vyber);if(keyPartName=check.attr('id').match(/^form_(.+)$/)){if(check.is(':checked')){imgUrlGrayTag="_dark";}
else{imgUrlGrayTag="";}
img.attr('src',imgFlagUrlPrefix+keyPartName[1]+imgUrlGrayTag+imgFlagUrlPostfix);}}
function searchUpdateTrigger(form,triggerTimeout){if(searchUpdateTriggerTimeout){window.clearTimeout(searchUpdateTriggerTimeout);}
else{$(".best_links",form).empty().append($(document.createElement('p')).addClass('sorry').text('Čekejte, prosím...'));$(".number a").fadeOut('fast');}
searchUpdateTriggerTimeout=window.setTimeout(function(){searchUpdateGo(form);},triggerTimeout);}
function searchUpdateGo(form){var data=new Object();data['datatype']='json';form.find(':input').each(function(){if(this.tagName=='INPUT'){if(!this.name)
return
if((this.type=='checkbox'||this.type=='radio')&&!this.checked)
return;}
id=this.name;value=this.value;data[id]=value;});$.post("/ajax.php",data,function(data){searchUpdateTriggerTimeout=null;$('#form_searchGIUD').val(data.searchGUID);if(data.dummyText)
$("#searchDummyText").html(data.dummyText);else
$("#searchDummyText").html("V levé části vyberte hledané položky.");if(data.shop_count)
$('#fulltype_box').empty().append($(document.createElement('a')).attr('href',data.url).text("Zobrazit podniky ve všech kategoriích"));else
$('#fulltype_box').text("Litujeme, ale žádný podnik nebyl nalezen.");if(data.groups)
for(groupid in data.groups){groupData=data.groups[groupid];groupDom=$('#type_group_'+groupid);if(parseInt(groupData.shop_count)){groupDom.removeClass('disabled');imgUrlGrayTag="";$(".katalog_link.hideable",groupDom).show();list=$(document.createElement('ul'));for(i=0;i<Math.min(3,parseInt(groupData.shop_count));i++){shopitem=groupData.shops[i];shopvoteOutput="";if(parseFloat(shopitem.vote)){shopvoteOutput=" ("+Math.round(parseFloat(shopitem.vote)*100)+"%)";}
query="";if(data.params)
query="?"+data.params;listlink=$(document.createElement('a'));listlink.text(shorttext(shopitem.short_name,20,5,3)+shopvoteOutput);listlink.attr('href',podnikUrlBase+shopitem.keyword+'/'+query);listlink.attr('title','Zobrazit detail podniku „'+shopitem.name+'“');list.append($(document.createElement('li')).append(listlink));}
$(".best_links",groupDom).empty().append(list);}
else{groupDom.addClass('disabled');imgUrlGrayTag=".gray";$(".katalog_link.hideable",groupDom).hide();$(".best_links",groupDom).empty().append($(document.createElement('p')).addClass('sorry').text('Litujeme, ale žádný podnik nebyl nalezen.'));}
$(".number a",groupDom).text(groupData.shop_count).fadeIn('fast');$('img.illust',groupDom).attr('src',imgTypeUrlPrefix+groupData.key+imgUrlGrayTag+imgTypeUrlPostfix);$("a.katalog_link",groupDom).attr('href',katalogUrlBase+groupData.url);}},'json');}
function shorttext(text,limit,treshold,uncutwordlimit){limit=parseInt(limit);if(typeof treshold==='undefined')treshold=5;treshold=parseInt(treshold);if(typeof uncutwordlimit==='undefined')uncutwordlimit=0;uncutwordlimit=parseInt(uncutwordlimit);if(limit&&text.length>(limit+treshold)){if(uncutwordlimit){var pos=text.indexOf(' ',limit);if(pos>=0&&pos<=(limit+uncutwordlimit))
limit=pos;}
return text.substring(0,limit)+'...';}
return text;}

