﻿// -----------------------------------------------------
//                 Watermark Script
// -----------------------------------------------------

$.fn.watermark = function (opts) {
    return this.each(function () {
        var sValue = 'Text Here';
        if (typeof opts != 'undefined')
            sValue = opts;

        var obj = $(this);

        obj.filter(function () {
            return $(this).val() == ""
        }).addClass("watermarkOn").val(sValue);
        obj.focus(function () {
            $(this).filter(function () {
                return $(this).val() == "" || $(this).val() == sValue;
            }).removeClass("watermarkOn").val("");
        });

        obj.blur(function () {
            $(this).filter(function () {
                return $(this).val() == "";
            }).addClass("watermarkOn").val(sValue);
        });
    });

};




$(document).ready(function () {
    /* Adds phoneUS as validator routine... */
    jQuery.validator.addMethod("phoneUS",
    function (phone_number, element) {
        phone_number = phone_number.replace(/\s+/g, "");
        return this.optional(element) || phone_number.length > 9 && phone_number.match(/^(\(?\d\d\d\)?)?( |-|\.)?\d\d\d( |-|\.)?\d{4,4}(( |-|\.)?[ext\.]+ ?\d+)?$/);
    }, "Invalid phone number<br/>(e.g., (999) 999-9999)");

    /* Adds phoneUS as validator routine... */
    /*jQuery.validator.addMethod("phone",
    function (value, element) {
    value = value.replace(/\s+/g, "");
    return this.optional(element) || value.length > 9 && value.match(/^\d?(?:(?:[\+]?(?:[\d]{1,3}(?:[ ]+|[\-.])))?[(]?(?:[\d]{3})[\-/)]?(?:[ ]+)?)?(?:[a-zA-Z2-9][a-zA-Z0-9 \-.]{6,})(?:(?:[ ]+|[xX]|(i:ext[\.]?)){1,2}(?:[\d]{1,5}))?$/);
    }, "Invalid phone number<br/>");*/

    jQuery.validator.addMethod("requiredropdown", function (value, element) {
        if (element.value == "-1") return false;
        else return true;
    }, "Please select an option.");


    $("#form1").validate({
        // errorPlacement allows custom placement of error. If we do nothing, the error will not get displayed.
        errorPlacement: function (error, element) {
        },
        invalidHandler: function (form, validator) {
            $.scrollTo('#bd', "slow");
        },
        focusInvalid: false,
        // highlight is triggered when an element is invalid.
        highlight: function (element, errorClass) {
            $(element).addClass("errorcontrol");
            $("div[for=" + element.id + "]").addClass("errorcontainer");
            $(element.form).find("label[for=" + element.id + "]").addClass("errorlabel");
            //$.scrollTo("div[for=" + element.id + "]", "slow");
        },
        unhighlight: function (element, errorClass) {
            $(element).removeClass("errorcontrol");
            $("div[for=" + element.id + "]").removeClass("errorcontainer");
            $(element.form).find("label[for=" + element.id + "]").removeClass("errorlabel");
        }

    });
});



