$(document).ready(function(){
    $('#shilohform').submit(function(){
        var error = 0;
        $(".error").remove();
        $('#shilohform input[type="text"]').each(function(){
            $(this).css("border","");
            if($.trim($(this).val())==""){
                var first = false;
                if(error==0)
                    first=true;
                error=1;
                $(this).before(
                
                    $("<div></div>").css({
                        "color" : "red",
                        "font-size" : "10px"
                    }).attr({
                        "class" : "error"
                    }).html("This field is required.")

                );
                $(this).css("border", "red solid 1px");
                if(first){
                     $(this).focus();
                }
            }
        });
        if(!validateOption("gender")){error=1;}
        if(!validateOption("previous_camper")){error=1;}
        if(!validateOption("choosen_session")){error=1;}
        if(!validateOption("full_participation")){error=1;}
        if(!validateOption("condition_medical_allergies")){error=1;}
        if(!validateOption("condition_food_allergies")){error = 1;}
        if(error==0){
            $.post("wp-content/uploads/2010/05/shilohform.php", $("#shilohform").serialize(), function(data){
            }, "html");
        }
        else{
            return false;
        }
    });
});

function validateOption(name){
    var option_checked = false;
    $('input[name="'+name+'"]').css("border","");
    $('input[name="'+name+'"]').each(function(){
        if($(this).is(":checked")){
            option_checked = true;
        }
    });
    if(!option_checked){
        $('input[name="'+name+'"]').css("border","red solid 1px");
        $('input[name="'+name+'"]').eq(0).before(
            $("<div></div>").css({
                "color" : "red",
                "font-size" : "10px"
            }).attr({
                "class" : "error"
            }).html("This field is required."));
            return false;
    }
    return true;
}
