$(".noclick").click(function(event){
    window.location.reload(window.location+"#");
    return false;
});

function replace(f, r, s) {
	var ra = r instanceof Array, sa = s instanceof Array, l = (f = [].concat(f)).length, r = []
			.concat(r), i = (s = [].concat(s)).length;
	while (j = 0, i--)
		while (s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j < l);
	return sa ? s : s[0];
}

$(document).ready(function() {
    $(".external").click(function(event) {
        window.open(this.href);
        event.preventDefault();
    });
    $(".zavinac").html("@");
    
    $('a[href^="http://www.3it.cz/nas-tym-x31034/-"]').each( function() {
        var href = replace("http://www.3it.cz/nas-tym-x31034/-","mailto:",$(this).attr("href"));
        href = replace("ä","@",href);
        $(this).attr("href",href);
        }
    );


    //$("a").each(function())attr("href",replace("~","@",$(this).attr("href")));
    $("#dod").click(function (){
        if($(this).is(":checked")) {
            $("#dodaci").show();
        }
        else {
            $("#jmeno_dod_reg").attr("value","");
            $("#prijmeni_dod_reg").attr("value","");
            $("#ulice_dod_reg").attr("value","");
            $("#mesto_dod_reg").attr("value","");
            $("#psc_dod_reg").attr("value","");
            $("#dodaci").hide();
        }
    });
	
    $(".hlas").mouseover(function(){
        var kolik = $(this).attr("title");
        kolik = kolik * (-18);
        $("#hlasuj").css("background-position","0 "+kolik+"px");

    });
	
    $(".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')").submit(function (){
        $(".defaulttext").val('');
    });
	
    $("#menu2nd > a").mouseover(function(){
        if(!$(this).hasClass("aktiv")){
            var trida=$(this).attr("class");
            var id=trida.replace("oo","");
            $(this).siblings(".o"+(id-1)).css("background","none");
            $(this).siblings(".o"+id).css("background","none");
            $(this).css("background","url('projekty/p3/img/topmenuhover1.png') top left repeat-x");
        }
		
		
    });
    $("#menu2nd > a").mouseout(function(){
        var trida=$(this).attr("class");
        var id=trida.replace("oo","");
        $(this).siblings(".o"+(id-1)).css("background","url('projekty/p3/img/navigaceoddelovac.png') no-repeat scroll left center transparent");
        $(this).siblings(".o"+id).css("background","url('projekty/p3/img/navigaceoddelovac.png') no-repeat scroll left center transparent");
        if(!$(this).hasClass("aktiv")){
            $(this).css("background","none");
        }
    });
	
	
	
    $("#zalozka1").click(function(){
        $("#zalozka1").addClass("akt");
        $("#zalozka2").removeClass("akt");
        $("#zalozka3").removeClass("akt");
        $("#obsah1").show("blind");
        $("#obsah2").hide();
        $("#obsah3").hide();
        $("#zalozky").css("background","url('projekty/p3/img/zal1akt.png') bottom left no-repeat");
    });
    $("#zalozka2").click(function(){
        $("#zalozka1").removeClass("akt");
        $("#zalozka2").addClass("akt");
        $("#zalozka3").removeClass("akt");
        $("#obsah1").hide();
        $("#obsah2").show("blind");
        $("#obsah3").hide();
        $("#zalozky").css("background","url('projekty/p3/img/zal2akt.png') bottom left no-repeat");
    });
    $("#zalozka3").click(function(){
        $("#zalozka1").removeClass("akt");
        $("#zalozka2").removeClass("akt");
        $("#zalozka3").addClass("akt");
        $("#obsah1").hide();
        $("#obsah2").hide();
        $("#obsah3").show("blind");
        $("#zalozky").css("background","url('projekty/p3/img/zal3akt.png') bottom left no-repeat");
    });

    $("#callback").validate({
        rules: {
            datum: {
                required: true
            },
            hodina: {
                required: true
            },
            jmeno_prijmeni: {
                required: true,
                minlength: 5
            },
            telefon: {
                required: true,
                minlength: 9
            }
        }
    });

    $("#datum").datepicker();
    $("#datum").datepicker("option","dateFormat","d. MM yy");
    $("#datum" ).datepicker("option","showAnim","fold");
            
    $("#datum").datepicker("option", "dayNamesMin", ["Ne", "Po", "Út", "St", "Čt", "Pa", "So"]);
    $("#datum").datepicker("option", "firstDay", 1);
    $("#datum").datepicker("option", "monthNames", ["Leden","Únor","Březen","Duben","Květen","Červen","Červenec","Srpen","Září","Říjen","Listopad","Prosinec"]);


    $( "#slider" ).slider({
        range: true,
        min: 7,
        max: 15,
        values: [ 10, 11 ],
        animate: true,
        slide: function( event, ui ) {
            $( "#hodina" ).val( "mezi " + ui.values[ 0 ] + " - " + ui.values[ 1 ]+" hodinou" );
        }
    });

    $( "#hodina" ).val( "mezi 10 - " + $( "#slider" ).slider( "values", 1 )+" hodinou" );
	
    $("#tabs").tabs({
        fx: {
            opacity: 'toggle'
        }
    });
    $("#tabs").tabs({
        select: function(event, ui) {
            $("#poptavka_submit").attr('name', 'btn-'+ui.panel.id);
        }
    });

    if(window.location.hash != "") {
        document.getElementById('jmeno_prijmeni').focus()
        document.getElementById('top').scrollIntoView(true);
        $("#tabs").tabs("select", window.location.hash); //vybere zalozku dle # v URL
        document.getElementById('jmeno_prijmeni').focus()
        document.getElementById('top').scrollIntoView(true);
        $("#poptavka_submit").attr('name', 'btn-'+window.location.hash);
    }
    $("#poptavka").validate({
        rules: {
            spolecnost: {
                required: true,
                minlength: 3
            },
            jmeno_prijmeni: {
                required: true,
                minlength: 5
            },
            telefon: {
                required: true,
                minlength: 9
            },
            obec: {
                required: true,
                minlength: 2
            },
            email: {
                required: true,
                email: true
            }
        }
    });
    $("#vlastnim-eshop").focus(function() {
        if($(this).val()=="E-shop zatím nemám") {
            $(this).val("www.");
        }
    }).blur(function(){
        if($(this).val()=="www.") {
            $(this).val("E-shop zatím nemám");
        }
    });
         
    $("#vlastnim-web").focus(function() {
        if($(this).val()=="Www stránky zatím nemám") {
            $(this).val("www.");
        }
    }).blur(function(){
        if($(this).val()=="www.") {
            $(this).val("Www stránky zatím nemám");
        }
    });
    $("#marketing-www-stranky").focus(function() {
        if($(this).val()=="Www stránky zatím nemám") {
            $(this).val("www.");
        }
    }).blur(function(){
        if($(this).val()=="www.") {
            $(this).val("Www stránky zatím nemám");
        }
    });
    $('div[class^="detail_"]').hide();

    $("a.show_detail").click(function (event) {
        var cls = ".detail"+$(this).attr('id');
        var lnk = this;
        $(cls).toggle("slow",function(){
            if ($(lnk).html().toString() != 'Skrýt detaily') {
                $(lnk).html('Skrýt detaily');
                return false;
            }
            else {
                $(lnk).html('Zobrazit více');
                return true;
            }
        });
        return false;

    });
    $(".noclick").click(function(event){
        window.location.reload(window.location+"#");
        return false;
    });

    $(".click>h2:not(img)").hover(
        function () {
            $(this).css("text-decoration","underline");
        },
        function () {
            $(this).css("text-decoration","none");
        }
        );
            
});
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
function strip_tags(html){

    //PROCESS STRING
    if(arguments.length < 3) {
        html=html.replace(/<\/?(?!\!)[^>]*>/gi, '');
    } else {
        var allowed = arguments[1];
        var specified = eval("["+arguments[2]+"]");
        if(allowed){
            var regex='</?(?!(' + specified.join('|') + '))\b[^>]*>';
            html=html.replace(new RegExp(regex, 'gi'), '');
        } else{
            var regex='</?(' + specified.join('|') + ')\b[^>]*>';
            html=html.replace(new RegExp(regex, 'gi'), '');
        }
    }

    //CHANGE NAME TO CLEAN JUST BECAUSE
    var clean_string = html;

    //RETURN THE CLEAN STRING
    return clean_string;
}
