var ean,reading = true;
var zboziNaDokladu = '';
var tab = '';
var poleZbozi = new Array();

function DisplayLine(Prefix,Id,Vantity){
    for(i=1;i<=Vantity;i++){
        document.getElementById(Prefix+i).style.display = 'none';
    }
    var isIE = navigator.appName == 'Microsoft Internet Explorer';
    document.getElementById(Prefix+Id).style.display = isIE ? '' : 'table-row';
} 

function ShowRow(Prefix,Id){
    var isIE = navigator.appName == 'Microsoft Internet Explorer';
    document.getElementById(Prefix+Id).style.display = isIE ? '' : 'table-row';
}

function ShowAndHiddenRows(Prefix,Id,Vantity){
    DisplayLine(Prefix,Id,Vantity);
}

function HiddenAll(Id,Vantity){
    for(i=1;i<=Vantity;i++){
        document.getElementById(Prefix+i).style.display = 'none';
    }
}

function DisplayAllLines(Id,S){
    for(i=1;i<=S;i++){
        if(document.getElementById(Id+i).style.display == 'none'){
            var isIE = navigator.appName == 'Microsoft Internet Explorer';
            document.getElementById(Id+i).style.display = isIE ? '' : 'table-row';
        } else {
            document.getElementById(Id+i).style.display = 'none';
        }		
    }
} 

function ShowItem(Id) {
    document.getElementById(Id).style.display='block';
}
function HiddenItem(Id) {
    document.getElementById(Id).style.display='none';
}
function ShowOrHiddenItem(Id) {
    if(document.getElementById(Id).style.display == 'none'){
        var isIE = navigator.appName == 'Microsoft Internet Explorer';
        document.getElementById(Id).style.display = isIE ? 'block' : 'block';
    } else {
        document.getElementById(Id).style.display = 'none';
    }		
}
function ShowOrHiddenRow(Id) {
    if(document.getElementById(Id).style.display == 'none'){
        var isIE = navigator.appName == 'Microsoft Internet Explorer';
        document.getElementById(Id).style.display = isIE ? '' : 'table-row';
    } else {
        document.getElementById(Id).style.display = 'none';
    }		
}

$(document).ready(function(){
    $("#writeForm").submit(function(){
        $.ajax({
            type: "POST",
            url: "http://www.prirodnimydla.cz/ajax/random.php",
            async: false,
            success: function(msg){
                $("#sec").html("<input type='hidden' name='sec' value='"+msg+"' />");
            }
        });
        if($("#sec").html()!= "")return true;
        else{
            return false;
        }
    });

    $("#registrace").validate({
        rules: {
            email: {
                email: true,
                required: true
            },
            heslo2: {
                required: true,
                minlength: 4
            },
            heslo3: {
                required: true,
                minlength: 4,
                equalTo: "#heslo2"
            },
            jmeno: {
                required: true,
                minlength: 2
            },
            prijmeni: {
                required: true,
                minlength: 2
            },
            telefon: {
                required: true,
                minlength: 9,
                maxlength: 14
            },
            ulice: {
                required: true,
                minlength: 3
            },
            mesto: {
                required: true,
                minlength: 2
            },
            psc: {
                required: true,
                minlength: 5,
                maxlength: 6
            },
            dodJmeno: {
                minlength: 2
            },
            dodPrijmeni: {
                minlength: 4
            },
            dodUlice: {
                minlength: 4
            },
            dodMesto: {
                minlength: 4
            },
            dodPsc: {
                minlength: 4
            }
        }
    });
    $("#kosik").validate({
        rules: {
            email: {
                email: true,
                required: true
            },
            jmeno: {
                required: true,
                minlength: 2
            },
            prijmeni: {
                required: true,
                minlength: 2
            },
            telefon: {
                required: true,
                minlength: 9,
                maxlength: 14
            },
            ulice: {
                required: true,
                minlength: 3
            },
            mesto: {
                required: true,
                minlength: 2
            },
            psc: {
                required: true,
                minlength: 5,
                maxlength: 6
            }
        }
    });
    $('#search').autocomplete({
        source: 'ajax.search.php',
        minLength: 2,
        autoFill: true,
        highlight: true,
        delay: 300,
        select: function( event, ui ) {
            $('#search').val(ui.item.value);
            $('#findForm').submit();
        }
    });
    $(".btnKoupit").click(function() {
        var max = 0;
        console.log("KLIK");
        console.log($('input[id^="pocet"]').size());
        $('input[id^="pocet"]').each(function () {
            console.log($(this).id);
            if( parseInt($(this).val()) > 0 ) {
                max = 1;
            }
        });
        if(max == 0) {
            alert(var_344);
            return false;
        }
        return true;
    });
    
     $('a.thickbox').lightBox();
     
	$(".zakladnitext").focus(function(){
		if($(this).val() == $(this).attr("title")) {
			$(this).val("");
			$(this).removeClass("defaulttext");
		}
	});


	$(".zakladnitext").blur(function (){
		if($(this).val() == ''){
			$(this).val($(this).attr("title"));
			$(this).addClass("defaulttext");
		}
	});

	$(".zakladnitext").trigger('blur');

	$("form:has('input.defaulttext')").live("submit", function() {return false;});
	
	$(".zobraz_prihlaseni").click(function() {
		$(".prihl_form").toggle("slow");
	});

});
