function goLang(id) {
    document.getElementById("sendLang").value = id;
}
function changeSFDesign(design) {
    $('#thDesign').val(design);
}
/**
 * pager
 */
// udalost na spodnim pageru, vyvola stejnou na hornim
function subpager_change(idcko) {
    copy_values(true);
    var new_id = idcko.substr(0, idcko.length - 1);
    if (idcko == "on_page_products2") {
        change_count();
    }
    else if (idcko == "submitak2") {
        pager(document.getElementById('to_page').value);
    }
    else {
        eval(document.getElementById(new_id).href);
    }
}
function subpager_change_sort(direction) {
    copy_values(true);
    if (!direction) { direction = 1; }
    select_object = document.getElementById("sort_select2");
    id = select_object.options[select_object.selectedIndex].value;
    if (parseInt(id) <= 0) return;
    dataSource = url + "inc/ajax/apager.php?sort_method_id=" + id + "&direction=" + direction + "&preurl=" + url;
    getData(dataSource, "products");
    my_blur();
}
// zkopiruje spodni pager na horni, nebo naopak
function copy_values(up) {
    var elemIds = up ? ["on_page_products", "to_page"] : ["on_page_products", "to_page", "product_count", "actual_page_text", "number_of_pages_text", "sort_select"];

    $.each(elemIds, function(i, val) {
        var e = $("#" + val);

        if (e.size() > 0) {
            var el = e[0];
            if (el.tagName == "SELECT") {
                if (up) {
                    el.selectedIndex = $("#" + val + "2")[0].selectedIndex;
                }
                else {
                    $("#" + val + "2")[0].selectedIndex = el.selectedIndex;
                }
            }
            else if (el.tagName == "INPUT") {
                if (up) {
                    $("#" + val + "2").val(e.val());
                }
                else {
                    e.val($("#" + val + "2").val());
                }
            }
            else {
                if (up) {
                    $("#" + val + "2").html(e.html());
                }
                else {
                    e.html($("#" + val + "2").html());
                }
            }
        }
    });
}
function next() {
    pager(parseInt($("#actual_page").val()) + 1);
}
function previous() {
    pager(parseInt($("#actual_page").val()) - 1);
}
function first() {
    pager(1);
}
function last() {
    pager(parseInt($("#number_of_pages").val()));
}
function change_count() {
    refresh_count(parseInt($("#product_count").html()));
    reset_to_first_page();
    my_blur();
    pager(1);
}
function reset_to_first_page() {
    $("#actual_page").val(1);
    $("#actual_page_text").html("1");
}
function my_blur() {
    $("#submitak").focus();
}
function refresh_count(product_count, on_page_products) {
    //throw new Exception();
    if (!on_page_products) {
        poc = document.getElementById("on_page_products");
        on_page_products = poc.options[poc.selectedIndex].value;
    } else {
        select_obj = document.getElementById("on_page_products");
        for (i = 0; i < select_obj.options.length; i++) {
            if (parseInt(select_obj.options[i].innerHTML) == on_page_products) {
                select_obj.options[i].selected = true;
            }
            else {
                select_obj.options[i].selected = false;
            }
        }
    }
    //$("#product_count").html(product_count);
    $("#product_count2").html(product_count);
    pocet_stran = Math.ceil(product_count / on_page_products);
    $("#number_of_pages").val(pocet_stran);
    if (pocet_stran != 0) {
        $("#number_of_pages_text").html(pocet_stran);
        $("#number_of_pages_text2").html(pocet_stran);
    } else {
        $("#number_of_pages_text").html("1");
        $("#number_of_pages_text2").html("1");
    }
}
function pager(page) {

    page = parseInt(!page ? $("#actual_page").val() : page);

    if (isNaN(page)) {
        page = 1;
    }
    if (page > parseInt($("#number_of_pages").val()) || page <= 0) {
        return;
    }

    poc = document.getElementById("on_page_products");
    pocet = poc.options[poc.selectedIndex].value;

    //loading(true);
    $.get(url + "inc/ajax/apager.php",
    {
        actual_page: page,
        count: pocet,
        preurl: url
    }, function (data) {
        $("#products").html(data);
        $("#actual_page_text").html(page);
        $("#actual_page").val(page);
        copy_values(false);
        JPager.init();
        //loading(false);
    });
}
function loading(all) {
    if (all) {
        var mess = $("#loading").html();
        $.blockUI({
            message: '<div id="loadAjx"><p>' + mess + '</p></div>',
            showOverlay: false,
            centerY: 0,
            css: {
                top: '10px', left: '', right: '10px',
                width: '250px', padding: '10px',
                border: '3px solid red', backgroundColor: '#fff',
                opacity: 1, color: '#000'
            }
        });
    } else {
       $.unblockUI();
    }
}
/**
 * search
 */
function request_search(other_form) {
    if (!other_form) {
        other_form = "advSearch";
    } msgBox(window_search);
    dataSource = url + "inc/ajax/asearch.php" + formData2QueryString(document.getElementById(other_form));
    getData(dataSource, "list");
}

function search_subcategories(sel, index, id_next) {
    sel.blur();
    document.getElementById("submit_it").focus();
    document.getElementById("tech_parameters").innerHTML = "";
    id_parent = sel.options[index].value; document.getElementById("sc" + id_next).innerHTML = "";
    if (!id_parent || id_parent == 0) {
        if (document.getElementById("id_category" + eval(id_parent - 1))) {
            search_tech_parameters(eval(id_parent - 1));
        }
        else {
            var obj = document.getElementById("id_category");
            search_tech_parameters(obj.options[obj.selectedIndex].value);
        }
        return;
    }

    $.get(url + "inc/ajax/acategories.php",
    {
        id_parent: id_parent
    },
    function (data) {
        var response_options = data.responseText;
        if (response_options) {
            response_options = "<label><span class='descr'>&nbsp;</span><select name='id_sub_category[" + id_next + "]' id='id_category" + id_next + "' class='sizeL' onchange='search_subcategories(this, this.selectedIndex, " + eval(id_next + 1) + ");'><option value='0'>" + sel.options[0].innerHTML + "</option><option value='0'>" + sel.options[1].innerHTML + "</option>" + response_options;
            response_options += "</select></label><div class='sub-category' id='sc" + eval(id_next + 1) + "'></div>";
            $("#sc" + id_next).html(response_options);
        }
    });

    window.setTimeout("search_tech_parameters(" + id_parent + ")", 400);
}
function search_tech_parameters(id_parent) {
    if (!id_parent || id_parent == 0){
        return;
    }

    $.get( url + "inc/ajax/atechparameters.php",
    {
        id_parent: id_parent
    },
    function (data) {
        $("#tech_parameters").html(data.responseText);
    });
}

/**
 * filter
 */
function enabledFilter(index){
    for(i=0;i<=index;i++){
        $("#eFilter"+i).removeAttr("disabled");
    }
}

function setFilterAll(index) {
    var total = $("#eFilterTotal").val() * 1;
    for(i=index;i<total;i++){
        $("#eFilter"+i).val('0');
    }
}

function checkChildFilter(index,param,values) {
    $("#fastFind select").attr("disabled","disabled");
    index += 1;
    enabledFilter(index);
    if (values == 0) {
        $("#eFilter"+index).attr("disabled","disabled");
    }
    setFilterAll(index);

    $.get(url + "inc/ajax/afilterElaborate.php",
    {
        param: param,
        values: values
    },
    function (data) {
        $("#eFilter"+index).html(data.responseText);
    });
}

function change_patron_only(){
    var patron_only = 0;
    if (document.getElementById("patron_only").checked) {
        patron_only = 1;
    }

    $.get(url + "inc/ajax/afilter.php",
    {
        patron_only: patron_only,
        preurl: url
    },
    function (data) {
        $("#products").html(data.responseText);
        reset_to_first_page();
        refresh_count($("#filter_product_count").val());
        my_blur();
    });
}

function change_stored_only(){
    var stored_only = 0;
    if (document.getElementById("stored_only").checked) {
        stored_only = 1;
    }

    $.get(url + "inc/ajax/afilter.php",
    {
        stored_only: stored_only,
        preurl: url
    },
    function (data) {
        $("#products").html(data.responseText);
        reset_to_first_page();
        refresh_count($("#filter_product_count").val());
        my_blur();
    });
}

function change_layout() {
    select_object = document.getElementById("layout_id");
    id = select_object.options[select_object.selectedIndex].value;
    if (parseInt(id) <= 0) {
        return;
    }

    $.get(url + "inc/ajax/apager.php",
    {
        layout_id: id,
        preurl: url
    },
    function (data) {
        $("#products").html(data.responseText);
        reset_to_first_page();
        refresh_count(parseInt($("#product_count").html()), parseInt($("layout_on_page_count").val()));
        //refresh_count($("#filter_product_count").val());
        my_blur();
    });
}

function change_sort(direction) {
    copy_values(true);
    select_object = document.getElementById("sort_select");
    id = select_object.options[select_object.selectedIndex].value;
        copy_values(false);
        JPager.init();
    if (parseInt(id) <= 0) return;
    if (!direction) {
      if (parseInt(id) == 1) direction = 2;
      else direction = 1;
    }
    dataSource = url + "inc/ajax/apager.php?sort_method_id=" + id + "&direction=" + direction + "&preurl=" + url;
    getData(dataSource, "products");
    my_blur();
}

function color_filter() {
	copy_values(true);
	select_object = document.getElementById("colors_products");
	id = select_object.options[select_object.selectedIndex].value;
        copy_values(false);

	$.getJSON(url + "inc/ajax/acolors.php?colors_ids=" + id + "&preurl=" + url + "&pager=true", function(data) {
		$("#actual_page").val(data.actual_page);
		$("#number_of_pages").val(data.number_of_pages);
                $("#product_count, #product_count2").text(data.product_count);
	});
	JPager.toPage(1);

	dataSource = url + "inc/ajax/acolors.php?colors_ids=" + id + "&preurl=" + url;
    getData(dataSource, "products");
    my_blur();
}




function multi_filter(other_form) {
    if (!other_form) {
        other_form = "quickMenu";
    }
    reset_to_first_page();

    $.post(url + "inc/ajax/afilter.php" + formData2QueryString(document.getElementById(other_form)) + "&preurl=" + url,
        null,
        function (data) {
            $("#products").html(data.responseText);
            refresh_count($("#filter_product_count").val());
            my_blur();
        });
}

function multi_filter_variants(id_product) {
    var other_form = "quickMenu";

    $.post(url + "inc/ajax/aproduct_group.php" + formData2QueryString(document.getElementById(other_form)) + "&preurl=" + url + "&id_product=" + id_product,
        null,
        function (data) {
            $("#product_group").html(data.responseText);
            my_blur();
        });

    $.post(url + "inc/ajax/aproduct_group.php" + formData2QueryString(document.getElementById(other_form)) + "&preurl=" + url + "&id_product=" + id_product,
        null,
        function (data) {
            $("#product_group").html(data.responseText);
            my_blur();
        });
}

function filter(constrain_name, constrain_object) {
    constrain_id = constrain_object.options[constrain_object.selectedIndex].value;
    if (constrain_id == 0){
        return;
    }
    reset_to_first_page();

    $.get(url + "inc/ajax/afilter.php",
    {
        constrain_name: constrain_name,
        constrain_id: constrain_id,
        preurl: url
    },
    function (data) {
        $("#products").html(data.responseText);
        pocet = document.getElementById("filter_product_count").value;
        refresh_count($("#filter_product_count").val());
        my_blur();
    });
}
/**
 * survey
 */
function vote(id,id_survey) {
    if (readCookie("survey" + id_survey) != null) {
        alert(survey_error); return;
    }
    $.get(url + "inc/ajax/asurvey.php", {
        id: id
    });
    // ajax_call(url + "inc/ajax/asurvey.php?id=" + id);
    document.getElementById("survey" + id).value = parseInt(document.getElementById("survey" + id).value) + 1;
    var i = 0; var total = 0;
    for (i = 0; i < surveys.length; i++) {
        total += parseInt(document.getElementById("survey" + surveys[i]).value);
    }
    for (i = 0; i < surveys.length; i++) {
        var vote = parseInt(document.getElementById("survey" + surveys[i]).value);
        var proc = Math.floor((vote / total) * 100);
        document.getElementById("surveybar" + surveys[i]).style.width = proc + "%";
        document.getElementById("surveyvote" + surveys[i]).innerHTML = " (" + vote + ")";
        document.getElementById("surveyproc" + surveys[i]).innerHTML = proc + " %";
    }
    createCookie("survey" + id_survey, 1, 5);
}
// show msgBox
function msgBox(text) {
    $("body").append('<div id="msgboxText"><p>' + text + '</p></div>');
    $("#msgboxText").css("position", "fixed").css("left", "38%").css("top", "40%");

    setTimeout(function (evt) {
        $("#msgboxText").fadeOut(250, function () {
            $("#msgboxText").remove();
        });
    }, 1000);
}

// check layout setting after page reload
function pageReloadBlock() {
    shop_block = $.cookie('shop_block');
    shop_block = (shop_block == null || shop_block == 'none') ? [] : shop_block.split(',');
    for(i=0;i<shop_block.length;i++){
        if (shop_block[i] != '-'){
            $('#'+shop_block[i]).hide();
        }
    }
}

// save layout setting cookie
function checkHideBlock(id, elem) {
    var aLink = $("a[rel^=" + id + "]");

    if ($.browser.msie && parseInt($.browser.version.substr(0, 1)) < 8)
    {
    //   $("#" + id).toggle(100);
    }


    if (aLink.size() > 0) {
        if ($("#" + id).is(":visible") || $(elem).hasClass("open")) {
            $(aLink).addClass("close");
            $(aLink).removeClass("open");


			if ($.browser.msie) {
				$(aLink.parents("div")[0]).find("> div.hideAlt").show();
				$('#' + id).hide();
			}
			else
				$('#'+id).slideUp('slow',function(){$(aLink.parents("div")[0]).find("> div.hideAlt").show().hide().slideDown('slow');});
        }
        else {

			if ((elem != null && $(elem).hasClass("open"))) {
                return false;
            }
            $(aLink).addClass("open");
            $(aLink).removeClass("close");
			if ($.browser.msie) {
				$('#' + id).show();
				$(aLink.parents("div")[0]).find("> div.hideAlt").hide();
			}
			else
				$(aLink.parents("div")[0]).find("> div.hideAlt").slideUp('slow', function(){$('#' + id).slideDown('slow');});


        }
    }



    if (false && $.browser.msie && parseInt($.browser.version.substr(0, 1)) < 8)
    {
        //$("#" + id).toggle(1);
    }
    else
    {
        //animatedcollapse.toggle(id);
    }

    var date = new Date();
    date.setTime(date.getTime() + (3 * 24 * 60 * 60 * 1000));
    shop_block = $.cookie('shop_block');
    shop_block = (shop_block == null || shop_block == 'none') ? [] : shop_block.split(',');
    found = jQuery.inArray(id, shop_block);
    if (found == -1) {
        shop_block[shop_block.length] = id;
    } else {
        shop_block[found] = '-';
    }
    shop_block = jQuery.unique(shop_block);
    shop_block = shop_block.join(',');
    $.cookie('shop_block', shop_block, {
        path: '/',
        expires: date
    });

    return false;
}

// pri registraci aby bralo Enter
function Check_Key_Login(e) {
    var $key=0;
    if (document.all){
        $key=window.event.keyCode;
    }else{
        $key=e.which;
    }
    if ($key==13){
        $("#log").submit();
    }
}

// auto refresh na zmenu jazyka v poste
function Change_Lang() {
    selected_lang = document.getElementById("langs"); selected_lang = selected_lang.options[selected_lang.selectedIndex];
    selected_lang = selected_lang.value;
    document.getElementById("lang").value = selected_lang;
    document.getElementById("language").submit();
}
//ShowImage
function ShowImage(filename) {
    window.open(encodeURI(url + "foto.php?img=" + filename), "_blank", "toolbar=no,scrollbars=no,location=no,status=no,width=100,height=100,resizable=1,screenX=150,screenY=150", false);
}

function new_window(url1) {
    window.open(encodeURI(url1), "_blank", "toolbar=no,scrollbars=yes,location=no,status=no,width=800,height=550,resizable=1,screenX=100,screenY=150", false);
}

function createCookie(name,value,days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        expires = "; expires=" + date.toGMTString();
    }
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    } return null;
}

function verify_length(inputName, length, message) {
    var text = $("input[name^='" + inputName + "']").val();
    if (text == null || text.length < length) {
        alert(message);
        $("#" + id).focus();
        return false;
    }

    return true;
}

function valid_email (email) {
    var validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
    return email.search(validRegExp) != -1;
}

/**
 * COMPARE
 */
function add_compare(id, id_category) {
    ajax_call(url + "inc/ajax/acompare.php?id=" + id + "&id_category" + id_category);
}
function show_compare() {
    new_window(url + "compare.php");
}
function send_to_friend(id) {
    window.open(encodeURI(url + "send_to_friend.php?id=" + id), "_blank", "toolbar=no,scrollbars=yes,location=no,status=no,width=480,height=440,resizable=1,screenX=100,screenY=150", false);
}
function remove_from_compare(id){
    ajax_call(url + "inc/ajax/acompare.php?remove_id=" + id);
    location.assign(location.href);
}
/**
 * SCHRANKA
 */
function add_to_repository (id) {
    $.get(url + "inc/ajax/arepository.php",
    {
        id: id
    }, function (data) {
        $("repository_data", data);
        msgBox(window_after_repository);
        window.location.reload();
    });
}
function sel_to_repository() {
    var elems = document.getElementsByTagName("input");
    for(i = 0; i < elems.length; i++){
        if(elems[i].checked == true){
            elems[i].checked = false;
        }
    }
    getData(url + "inc/ajax/arepository.php?sel=true", "repository_count");
    msgBox(window_after_repository);
}

function sel_from_repository() {
    var str = $("input[name*='compare']:checked").serialize();
    //$("input[name*='compare']").removeAttr('checked');
    getData(url + "inc/ajax/arepository.php?sel_from=true&"+str, "repository_count"); // repository_count , demoView
    msgBox(window_repository_remmove);
    window.location.reload();
//reset_to_first_page();
}

function flush_repository() {
    ajax_call(url + "inc/ajax/arepository.php?flush=1");document.getElementById("repository_count").innerHTML = "0";msgBox(window_repository_flush);
}

function select_all_repository() {
//    var	boxs = document.getElementsByName("checkproduct[]");
    var	boxs = $("input[name*='compare']");
    var i = 0;for (i = 0; i < boxs.length; i++) {
        boxs[i].checked = document.getElementById("selectallrepository").checked;//!boxs[i].checked;
    }
}

function remove_from_repository(id) {
    getData(url + "inc/ajax/arepository.php?remove_from=true&compare="+id, "repository_count"); // repository_count , demoView
    msgBox(window_repository_remmove);
    window.location.reload();
//reset_to_first_page();
}

/**
 ** HLIDACI PES
 */
function add_one_to_watchdog (id){
    getData(url + "inc/ajax/awatch_dog.php?id=" + id+"&action=add","watch_dog_count"); msgBox(window_dog_add);
}
function sel_to_watchdog(){
    var elems = document.getElementsByTagName("input");
    for(i = 0; i < elems.length; i++){
        if(elems[i].checked == true){
            elems[i].checked = false;
        }
    } getData(url + "inc/ajax/awatch_dog.php?sel=true","watch_dog_count"); msgBox(window_dog_add);
}
function remove_select_watchdog(){
    var	boxs = document.getElementsByName("checkproduct[]"); var i = 0; var ids = "";
    for (i = 0; i < boxs.length; i++) {
        if (boxs[i].checked == true) {
            ids += boxs[i].value + ';';
        }
    }
    getData(url + "inc/ajax/awatch_dog.php?idsdel=" + ids,"watch_dog_count");
    msgBox(window_dog_rem);window.location.href=window.location.href;
}
function remove_from_watchdog (id){
    getData(url + "inc/ajax/awatch_dog.php?id=" + id+"&action=remove","watch_dog_count"); msgBox(window_dog_rem); window.location.assign(window.location.href);
}
function flush_watchdog() {
    ajax_call(url + "inc/ajax/awatch_dog.php?flush=1");document.getElementById("watch_dog_count").innerHTML = "0";msgBox(window_dog_rem);window.location.href=window.location.href;
}
/**
 * zjisteni hodnoty poukazky
 */
function GetVoucherValue(use_voucher,uniq_id){
    alert("Deprecated ! - use Order.localGetVoucherValue");
    getData(url + "inc/ajax/avoucher.php?use_voucher=" + use_voucher + "&uniq_id=" + uniq_id,"voucher_value_block") ;
}
/**
 * menova kalkulacka
 */
function Calculate_Currency(code){
    var price = document.curr_calc.in_price.value;
    var index = document.curr_calc.currency.selectedIndex;
    code = document.curr_calc.currency.options[index].value;
    getData(url + "inc/ajax/acurrencies.php?price=" + price + "&code=" + code, "out_price") ;
}
/**
 * zalozky
 */
function zal_menu_select(id) {
    var obal = document.getElementById("zalozkMenu"); var zalozky = obal.getElementsByTagName("A"); var i = 0;
    for (i = 0; i < zalozky.length; i++) {
        if ("zal" + id == zalozky[i].id) {
            zalozky[i].className = "act";
        }else{
            zalozky[i].className = "";
        }
    }
}
/**
 * RATING
 */
function get_sel_rating() {
    var butts = document.getElementsByName("ratingbutton");var i = 0;
    for (i = 0; i < butts.length; i++) {
        if (butts[i].checked == true) return butts[i].value;
    }return null;
}
function rate(id, extend, note) {
    var mark = get_sel_rating();if (mark == null) return;
    var dest = ""; if (extend == 0) dest = "rating_form"; else dest = "product_content";
    getData(url + "inc/ajax/arating.php?id_product=" + id + "&mark=" + mark + "&extend=" + extend + "&note=" + encodeURI(note) + "&preurl=" + url, dest);
    var note_rated_span = document.getElementById("note_rated");
    if (note != "" && note != document.getElementById("def_rating_text").value) note_rated_span.innerHTML = parseInt(note_rated_span.innerHTML) + 1;
}
function show_rating(id) {
    zal_menu_select(3);getData(url + "inc/ajax/arating.php?id_product=" + id + "&extend=1" + "&preurl=" + url, "product_content");
}
function show_product_info(id) {
    zal_menu_select(1);getData(url + "inc/ajax/aproduct.php?id=" + id + "&extend=1" + "&preurl=" + url, "product_content");
}
function show_product_info_immediate(id,status) {
    zal_menu_select(1); getData(url + "inc/ajax/aproduct.php?id=" + id + "&extend=1" + "&preurl=" + url + "&immediately=" + status, "product_content");
}
/**
 * FORUM
 */
function show_forum(id) {
    zal_menu_select(2);getData(url + "inc/ajax/aforum.php?id_product=" + id + "&preurl=" + url, "product_content");
}
function show_forum_news(id) {
    getData(url + "inc/ajax/anewsforum.php?id_news=" + id + "&preurl=" + url, "news_forum");
}
function forum_add(id_product,to_authorize) {
    var subject = document.getElementById("subject").value;	subject = encodeURI(subject);
    var name = encodeURI(document.getElementById("name").value); var email = encodeURI(document.getElementById("email").value);
    var text = encodeURI(document.getElementById("text").value); var id_product_forum = (document.getElementById("id_product_forum").value * 1);
    var require_admin = 0;
    if (document.getElementById("require_admin").checked == true) require_admin = 1;
    getData(url + "inc/ajax/aforum.php?id_product=" + id_product + "&title=" + subject + "&email=" + email + "&name=" + name + "&content=" + text + "&require_admin=" + require_admin + "&id_product_forum=" + id_product_forum, "product_content");
    var forum_count = document.getElementById("forum_count"); forum_count.innerHTML = parseInt(forum_count.innerHTML) + 1;
    if(to_authorize == 0){
        msgBox(window_forum_add);
    }
    else{
        msgBox(window_forum_add_authorize);
    }
}
function forum_news_add(id_product) {
    var subject = encodeURI(document.getElementById("subject").value); var name = encodeURI(document.getElementById("name").value);
    var email = encodeURI(document.getElementById("email").value); var text = encodeURI(document.getElementById("text").value);
    var id_product_forum = document.getElementById("id_product_forum").value;
    getData(url + "inc/ajax/anewsforum.php?id_news=" + id_product + "&title=" + subject + "&email=" + email + "&name=" + name + "&content=" + text + "&id_product_forum=" + id_product_forum, "news_forum");
    msgBox(window_forum_add);
}
function forum_reply(id_product_forum) {
    document.getElementById("id_product_forum").value = id_product_forum;var subj_text = document.getElementById("forum" + id_product_forum + "subject").innerHTML;document.getElementById("subject").value = "Re: " +  subj_text;
}
/**
 * DOWNLOAD
 */
function show_download(id) {
    zal_menu_select(4);getData(url + "inc/ajax/adownload.php?id=" + id + "&preurl=" + url, "product_content");
}
/**
 *  PRODUCT VISIT
 */
var call_product_visits = false;
/**
 * ON MOUSE OVER IMAGE
 **/
var timerT = false;

Thumbnail = {
    enableShowThumbnails: true,

    goToLocation: function(location) {
        this.disable();
        window.location = location;
    },

    disable: function(){
        this.enableShowThumbnails = false;

        return false;
    }
};

function show_small(element, filename, title, url) {
    var baseElem = $(element);
    if (show_small_image == false) return;
    if (timerT) clearTimeout(timerT);
    var posl_lomitko = filename.lastIndexOf("/") + 1;
    if (!filename || filename.substring(posl_lomitko) == "none.gif") return;

    var path = filename.substring(0, posl_lomitko);
    var small_div = document.getElementById("smallDiv");

    if (filename.charAt(posl_lomitko + 3) == '_') {
        var old_filename = filename.substring(posl_lomitko + 3);
        var new_filename = "sm_" + old_filename;
    }
    else {
        var new_filename = filename.substring(posl_lomitko);
    }
    small_div.innerHTML = "<a href='" + url + "'><img src='" + path + new_filename + "' alt='" + title + "' title='" + title + "' /></a>";
    $("#smallDiv").positionBy({
        target: baseElem,
        targetPos: 0,
        elementPos: 0
    });
    var cmd = "del_show()";
    timerT = setTimeout(cmd, 600);
}
function show_design(element, filename) {
    var baseElem = $(element);
    if (show_small_image == false) return;
    if (timerT) clearTimeout(timerT);
    var small_div = document.getElementById("smallDiv");
    small_div.innerHTML = "<img src='" + url + 'images/' + filename + "'/>";
    $("#smallDiv").positionBy({
        target: baseElem,
        targetPos: 0,
        elementPos: 0
    });
    var cmd = "del_show()";
    timerT = setTimeout(cmd, 600);
}
function show_matters(element, filename) {
    var baseElem = $(element);
    if (show_small_image == false) return;
    if (timerT) clearTimeout(timerT);
    var small_div = document.getElementById("smallDiv");
    small_div.innerHTML = "<img src='" + filename + "'/>";
    $("#smallDiv").positionBy({
        target: baseElem,
        targetPos: 10,
        elementPos: 10
    });
    var cmd = "del_show()";
    timerT = setTimeout(cmd, 600);
}
function del_show() {
    clearTimeout(timerT);
    if (Thumbnail.enableShowThumbnails) {
        var small_div = document.getElementById("smallDiv");
        small_div.style.visibility = "visible";
    }

}
function image_hide() {
    var small_div = document.getElementById("smallDiv");small_div.style.visibility = "hidden";
}
var ttXpos = 0, ttYpos = 0;
var ttXadd = 10, ttYadd = -10;
var ttDisplay = 0, ttHoldIt = 0;
function intrigue(text){
    getData(url + "inc/ajax/aintriguer.php?inp=" + text,"intriguer") ;
}
function selectItem(pos)
{
    $("#search_keyword").val($("#resultList"+pos+" option:selected").val());
    $("#intriguer").html('');
}
function intrigue_club(text)
{
    getData(url + "inc/ajax/aintriguer_club.php?inp=" + text,"intriguer2") ;
    var t = setTimeout('getClubIntrigValue()',250);
}
function getClubIntrigValue()
{
    var sel=document.getElementById("resultList2");
    if(sel != null && sel.length == 1)
    {
        document.getElementById("search_club_keyword").value=sel.options[0].text;
        document.getElementById("id_club").value=sel.options[0].value;
        document.getElementById("intriguer2").innerHTML="";
    }
}
function select_icon()
{
    var iconSelection = document.getElementById('icon_selection');
    var selIcon = iconSelection.options[iconSelection.selectedIndex].value;
    if(selIcon > 0)
    {
        $.get(url + "inc/ajax/aprintingimage.php",
        {
            printing_icon: selIcon
        },
        function (data) {
            $("#printing_own_image_preview").html(data.responseText);
        });
    }
    else
    {
        $("#printing_own_image_preview").html("");
    }
}
function display_printing_image(){
    var preview =   document.getElementById('printing_own_image_preview');
    var uplTarget = document.getElementById('uplTarget');
    iframeContent = uplTarget.contentDocument.getElementById('uploaded_image').innerHTML;
    preview.innerHTML = iframeContent;
    return true;
}
function copy_printing_content(){
    window.parent.display_printing_image();
}
function change_printing_text(line){
    var printingTextInput = document.getElementById('printing_text_' + line);
    var printingTextDiv = document.getElementById('printing_text_preview_' +line);
    printingTextDiv.innerHTML = printingTextInput.value;
}
function changeForm(type) {
    var asel='step'+type;
    document.getElementById(asel+'_select').disabled=false;
    obj= listAndReturnElem('step'+type+'_butt','input');
    if(obj)
        obj.setAttribute('style','');
    obj= listAndReturnElem('step'+type+'_change','a');
    if(obj)
        obj.setAttribute('style','display:none');
    var i=type+1;
    do{
        div=listAndReturnElem('step'+i,'div');

        if(div){
            div.setAttribute('style','display:none');
        }
        i++;
    }while(i<=3);
}
function listAndReturnElem(name,type){
    var1=document.getElementsByTagName(type);
    for(i=0;i<var1.length;i++){
        var2=var1.item(i);
        if(name==var2.getAttribute('id')){
            return var2;
        }
    }
    return null;
}
function autorapr_search(nodeid, nodename){
    var input = document.getElementById('assemblyGroupNodeId');
    var inputName = document.getElementById('assemblyGroupName');
    input.value=nodeid;
    inputName.value=nodename;
    document.getElementById('autorapr_search').submit();
}
function autorapr_article_details(articleid,articlelink){
    var aid = document.getElementById('articleId');
    var alid = document.getElementById('articleLinkId');
    aid.value=articleid;
    alid.value=articlelink;
    document.getElementById('autorapr_details').submit();
}
function autorapr_article_ddetails(darticleid){
    var aid = document.getElementById('darticleId');
    aid.value=darticleid;
    document.getElementById('autorapr_direct_details').submit();
}

function print_order(){
    var form = document.getElementById("order");
    form.setAttribute("target", "new");
    document.getElementById("print_order_input").value=1;
    form.submit();
    document.getElementById("print_order_input").value=0;
    form.setAttribute("target", "");
}

JPager = {
    around: 3,
    pagingFunc: null,

    init: function() {
        $(".jcPager").each(function (i, elem) {
            JPager.create(elem);
        });
    },

    create: function(elem) {
        var currentPage = parseInt($("#actual_page").val());
        var totalPages = parseInt($("#number_of_pages").val());
        var prevPage = parseInt($("#actual_page").val()) - 1;
        var nextPage = parseInt($("#actual_page").val()) + 1;

        var html = "";

        html += "<a href=\"javascript:JPager.toPage(1);\" class=\"list-ll" + (currentPage == 1 ? " disabled" : "") + "\">&nbsp;</a>";
        html += "<a href=\"javascript:JPager.toPage(" + prevPage + ");\" class=\"list-l" + (currentPage == 1 ? " disabled" : "") + "\">&nbsp;</a>";
        html += "<span class=\"jPager\">";

        if (currentPage > this.around + 1) {
            // Render primary 1
            html += "<span class=\"pnum\" onclick=\"JPager.toPage(1)\">1</span>" + (currentPage > this.around + 2 ? "<span>...</span>" : "");
        }

        for (var i = currentPage - this.around > 0 ? currentPage - this.around : 1 ; i < currentPage + this.around + 1 && i <= totalPages; i++) {
            html += "<span class=\"pnum" + (i == currentPage ? " act" : "") + "\" onclick=\"JPager.toPage(" + i + ")\">" + i + "</span>";
        }

        if (currentPage < totalPages - this.around) {
            // Render last
            html += (currentPage < totalPages - this.around - 1 ? "<span>...</span>" : "") + "<span class=\"pnum\" onclick=\"JPager.toPage(" + totalPages +")\">" + totalPages + "</span>";
        }
        html += "</span>";
        html += "<a href=\"javascript:JPager.toPage(" + nextPage + ");\" class=\"list-r" + (currentPage >= totalPages ? " disabled" : "") + "\">&nbsp;</a>";
        html += "<a href=\"javascript:JPager.toPage(" + totalPages + ")\" class=\"list-rr" + (currentPage >= totalPages ? " disabled" : "") + "\">&nbsp;</a>";
        $(elem).html(html);
    },

    toPage: function (page) {
        if (JPager.pagingFunc == null)
        {
            pager(page);
        }
        else
        {
            JPager.pagingFunc(page);
        }
    }
};

Array.prototype.inArray = function (value) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] === value) {
            return true;
        }
    }
    return false;
};

// Rozsireni validace
ValidatorExtensions = {
    // Pridani extension methods
    addExtendedMethods: function () {
        // Shoda kontrolniho hesla
        $.validator.addMethod("password2", function(value, element) {
            return value == $("#password").val();
        }, Dict.diffPassword);
        // Obchodni podminky
        $.validator.addMethod("requiredTerms", function(value, element) {
            return $(element).is(":checked");
        }, Dict.agreeRequired);
        // Minimalni delka hesla
        $.validator.addMethod("minlength", function(value, element) {
            return value.length >= 5;
        }, Dict.usernameInvalidLength);
        // IC
        $.validator.addMethod("ico", function(value, element) {
            return value == "" || value.match(/^([0-9]){8}$/);
        }, $.validator.messages.remote);
        // DIC
        $.validator.addMethod("dic", function(value, element) {
            return value == "" || value.length >= 5;
        }, $.validator.messages.remote);
        // Telefon
        $.validator.addMethod("phone", function(value, element) {
            return value == "" || value.match(/^([+0-9\s]){9,}$/);
        }, $.validator.messages.remote);
        // PS�
        $.validator.addMethod("zipcode", function(value, element) {
            return value == "" || value.match(/^([+0-9]){3} ?([+0-9]){2}$/);
        }, $.validator.messages.remote);
        // Ulice + cp
        $.validator.addMethod("streetNum", function(value, element) {
            return value == "" || value.match(/^(.*[^0-9]+) (([1-9][0-9]*)\/)?([1-9][0-9]*[a-eA-E]?)$/);

        }, Dict.invalidStreetNum);


        $.validator.addClassRules({
/*            zipcode: {
                required: false,
                remote: url + "inc/ajax/avalidate.php?op=zipcode"
            },
*/
            oldPassword: {
                required: {
                    depends: function (element) {
                        return $("#password").val() != "";
                    }
                },
                remote: url + "inc/ajax/avalidate.php?op=oldpass"
            },
            isUniqueUsername: {
                required: true,
                remote: url + "inc/ajax/afreeusername.php?oldusername="+(typeof(oldusername) == 'undefined' ? '' : oldusername)
//                minlength: 5
            }
        });

    },

    // Oznaceni povinnych poli hvezdickou
    markRequiredFields: function(query) {
        $(query).each(function (i, elem) {
            $(elem).prev().append("<span class=\"req\">*</span>");
        });
    }
};

// Guestbook
Guestbook = {
    init: function() {
        ValidatorExtensions.addExtendedMethods();
        ValidatorExtensions.markRequiredFields("input.required, select.required, textarea.required");
        $("#vref").val("valid");
        $("#guestbookForm").validate({
            errorContainer: $(".errorContainer"),
            errorElement: "span"
        });

        JPager.pagingFunc = function (page) {
            Guestbook.toPage(page);
        }
        JPager.init();
    },

    toPage: function(page) {
        if (isNaN(page)) {
            page = 1;
        }
        if (page > parseInt($("#number_of_pages").val()) || page <= 0) {
            return;
        }

        $.get(url + "inc/ajax/aguestbook.php",
        {
            page: page
        }, function (data) {
            $("#guestbookContainer").html(data);
            $("#actual_page").val(page);
            JPager.init();
        });
    }
};

// Order list
OrderList = {
    init: function () {
        JPager.pagingFunc = function (page) {
            OrderList.toPage(page);
        }
        JPager.init();
    },

    toPage: function(page) {
        if (isNaN(page)) {
            page = 1;
        }
        if (page > parseInt($("#number_of_pages").val()) || page <= 0) {
            return;
        }

        $.get(url + "inc/ajax/aorderlist.php",
        {
            orderspage: page
        },
        function (data) {
            $("#ordersContainer").html(data);
            $("#actual_page").val(page);
            JPager.init();
        });
    }
};

// Flash
Flash = {
    template: "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0\" width=\"{1}\" height=\"{2}\" title=\"odlesk\">"
    + "<param name=\"movie\" value=\"{0}\" />"
    + "<param name=\"quality\" value=\"high\" />"
    + " {4} "
    + "<embed src=\"{0}\" quality=\"high\" {3} pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"{1}\" height=\"{2}\"></embed>"
    + "</object>",

    insert: function(divId, filename, width, height, transparent) {
        var tpl = Flash.template;
        tpl = tpl.replace("{0}", filename);
        tpl = tpl.replace("{0}", filename);
        tpl = tpl.replace("{1}", width);
        tpl = tpl.replace("{2}", height);
        tpl = tpl.replace("{1}", width);
        tpl = tpl.replace("{2}", height);
        if (transparent) {
            tpl = tpl.replace("{3}","wmode=\"transparent\"");
            tpl = tpl.replace("{4}","<param name=\"wmode\" value=\"transparent\" />");
        }
        else {
            tpl = tpl.replace("{3}","");
            tpl = tpl.replace("{4}","");
        }

        $("#" + divId).html(tpl);
    }
};

// Sprava kontaktniho formulare (na strance Kontakty)
ContactForm = {
    start: function() {
        this.setValidation();

        // Oznaceni povinnych poli hvezdickou
        ValidatorExtensions.markRequiredFields("input.required, select.required, textarea.required");
    },

    // Nastaveni validace
    setValidation: function() {
        $("#contactForm").validate({
            errorContainer: $(".errorContainer"),
            errorElement: "span"
        });
    }
};

function modalMsgBox(message, closeFunc) {
    $("#modalconfirm").modal({
        close: false,
        position: ["20%",],
        overlayId:'confirmModalOverlay',
        containerId:'confirmModalContainer',
        minHeight: "auto",
        autoResize: true,
        onShow: function (dialog) {
            dialog.data.find('.message').append(message);
            dialog.data.find('.yesNo').hide();
            dialog.data.find('.yes').click(function () {
                $.modal.close();
                if (closeFunc != null) {
                    closeFunc();
                }
            });
        }
    });
};

function showPWHelper()
{
	$('#loginpassword_helper').removeClass('hide');
	$('#loginpassword').addClass('hide');
}

function hidePWHelper(focus)
{
	$('#loginpassword_helper').addClass('hide');
	$('#loginpassword').removeClass('hide');
	if(focus)
		$('#loginpassword').focus();
}
