function activateForm(){
    $(function(){   
        align_form();   //Line up form fields
        activateWatermarks();
        validateForm(); // set up validation variables
    });
}

function activateForm2(){
    $(function(){   
        align_form();           //Line up form fields
        activateWatermarks();   // set upo watermarks
        validateForm();         // set up validation variables
        setCaptcha();           // setup captcha
    });
}

function setCaptcha(){
    $(".ajax-fc-container").captcha({
        borderColor: "silver",
        captchaDir: "/admin/fancy-captcha/captcha",
        url: "/admin/fancy-captcha/captcha/captcha.php",
        formId: "registration_form",
        text: "To verify that you are human, please drag the <span>scissors</span> into the circle.",
        items: Array("pencil", "scissors", "clock", "heart", "note")
    });

}

function validateForm(){
    $("#registration_form").validate({
    //set the rules for the field names
        rules: {
            name_first: {
                required: true,
                minlength: 2
            },
            name_last: {
                required: true,
                minlength: 2
            },
            address1: {
                required: true,
                minlength: 4
            },
            city: {
                required: true,
                minlength: 2
            },
            state: {
                required: function(element) {
                    return $('select#country:selected').text() == "US";
                }
            },
            zip: {
                required: true,
                minlength: 3
            },
            country: {
                required: true
            },
            email: {
                required: true,
                email: true
            },
            workshop: {
                required: true
            },
            phone: {
                required: true
            }
        },
        //set messages to appear inline
        messages: {
            name_first: "Please enter your first name",
            name_last: "Please enter your last name",
            address1: "Please enter your mailing address",
            email: "Please enter a valid email address",
            city: "Please enter your city of residence",
            state: "Please enter your state of residence (US only)",
            zip: "Please enter your postal or zip code",
            country: "Please enter your country of residence",
            workshop: "Please select the workshop you wish to register for",
            phone: "Please enter your phone number"
        }
    });
}

function activateWatermarks(){      //activate watermarks in fields
    $("#name_first").fieldtag();
    $("#name_last").fieldtag();
    $("#address1").fieldtag();
    $("#city").fieldtag();
    $("#zip").fieldtag();
    $("#website").fieldtag();
    $("#email").fieldtag();
    $("#occupation").fieldtag();
    $("#comments").fieldtag();
    $("#origin").fieldtag();
}

function align_form() {
    var max = 0;    
    $("label").each(function(){
        if ($(this).width() > max)
            max = $(this).width();
    });
    $("label").width(max+5);
    $("p.label").width(max+5);
}