$(document).ready(function(){
    $("#nav li").each(function(){
        $(this).mouseenter(function(){
            $(this).addClass('sfhover');
        })
        $(this).mouseleave(function(){
            $(this).removeClass('sfhover');
        })
    });
    var fields = ['fname','lname','address','city','province','postal','phone','email'];
    $("#driver").append(' <a href=\"\">same as entrant</a>');
    $("#driver a").click(function(e){
        e.preventDefault();
        for (var field in fields){
            $("#driver_"+fields[field]).get(0).value = $("#entrant_"+fields[field]).get(0).value;
        }
    });
    $("#codriver").append(' <a href=\"\">same as entrant</a>');
    $("#codriver a").click(function(e){
        e.preventDefault();
        for (var field in fields){
            $("#codriver_"+fields[field]).get(0).value = $("#entrant_"+fields[field]).get(0).value;
        }
    });
    $("#comp_edit input[type=text]").each(function(){
        var id = $(this).get(0).id;
        $(this).after(' <a href=\"\" class="ac" title=\"'+ id +'\">AC</a>');
        $(this).after(' <a href=\"\" class="fc" title=\"'+ id +'\">FC</a>');
    });
    $("#comp_edit a.fc").each(function(){
        $(this).click(function(e){
            var id = $(this).get(0).title;
            e.preventDefault();
            var lol = $("#"+id);
            lol.get(0).value = lol.get(0).value.toLowerCase().replace(/\b(\w)/g, function (s, c) {
                return c.toUpperCase();
            });
        })
    });
    $("#comp_edit a.ac").each(function(){
        $(this).click(function(e){
            var id = $(this).get(0).title;
            e.preventDefault();
            var lol = $("#"+id);
            lol.get(0).value = lol.get(0).value.toUpperCase();
        })
    });
    $("th#start_order").each(function(){
        $(this).click(function(e){
            var count = 1;
            $("input.start_order").each(function(){
                this.value = count++;
            })
        })
    });
});

