﻿/// <reference path="../jquery-1.3.2.js" />

/// <reference path="../Global.js" />


// extend the current rules with new groovy ones

// this one requires the text "buga", we define a default message, too
$.validator.addMethod("IsValidPW", function(value) { return tools.alphanumeric(value); }, 'Please enter a valid password');

// this one requires the value to be the same as the first parameter
//$.validator.methods.IsValidPassword = function(value, element, param) {
 //   return true;
//};



$().ready(function() { 

    var validator = $("#SignUpForm").bind("invalid-form.validate", function() {
        $("#Error").html("Oops, there were " + validator.numberOfInvalids() + " problems with the information you entered. <br>Please correct the highlighted fields.").show();
    }).validate({
        debug: true,
        errorElement: "em",
        //errorContainer: $("#warning, #Error"),
        errorPlacement: function(error, element) {
            error.appendTo(element.parent("td").next("td"));
        },
        success: function(label) {
            label.html("&nbsp;").addClass("success");
        },
        submitHandler: function() {
            $("#SignUpForm, #SignUpForm input").unbind();
            $("#SignUpForm").submit();
        },
        rules: {
            zFirstName: {
                required: true,
                minlength: 3,
                maxlength: 20
            },
            zLastName: {
                required: true,
                minlength: 3,
                maxlength: 20
            },
            zEmail: {
                required: true,
                minlength: 6,
                maxlength: 320,
                email: true
            },
            zPassword: {
                required: true,
                minlength: 6,
                maxlength: 20,
                IsValidPW: true

            },
            zConfirmPassword: {
                required: true,
                minlength: 6,
                maxlength: 25,
                equalTo: "#zPassword"
            },
            zCountry: {
                required: true
            },
            zZip: {
                required: true,
                minlength: 5,
                maxlength: 25
            },
            zIndustry: {
                required: true
            },
            zIntrested: {
                required: true
            }
        },
        messages: {
            zFirstName: "First name is required.",
            zLastName: "Last name is required.",
            zEmail: "Please enter a valid email address",
            zPassword: {
                required: "Please provide a password",
                minlength: "Your password must be at least 5 characters long"
            },
            zConfirmPassword: {
                required: "Please provide a password",
                minlength: "Your password must be at least 6 characters long",
                equalTo: "Passwords do not match. Try again."
            },
            zCountry: "Please select a country",
            zZip: "ZIP/Postal code is required.",
            zIndustry: "Please select an industry.",
            zIntrested: "Please select an area of interest."
        }

    });

    $(".input, select").blur(function() {
        $(this).valid();
    });


    $(".input").focus(function() { $(this).addClass("focus"); }).blur(function() { $(this).removeClass("focus"); });

});