﻿
/*
 * Email Validation
 * Source: http://www.reynoldsftw.com/2009/03/live-email-validation-with-jquery/
 */
function isValidEmailAddress(emailAddress) { 
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); 
	return pattern.test(emailAddress); 
}

/*
 * This function should initialize any functions that do form validation
 * on a global scale. Meaning: If you need validation done on a specific
 * input on a form, make it so that the validation is repeated on all
 * other forms that have that same input box if it is a required field.
 * Below is an example:

    $("input").each(function () {
        var IsRequired = new String($(this).attr('IsRequired'));
        if (IsRequired.toLowerCase() == 'true')
        {
            $(this).bind('keyup', function () {
                var ErrorMessage    = new String($(this).attr('ErrorValidationMessage'));
                var DoWin32Popup    = new String($(this).attr('DoErrorPopup'));
                var ErrorPopupFunc  = $(this).attr('ErrorCustomPopup');

                if (DoWin32Popup.toLowerCase() == 'win32')
                {
                    alert(ErrorMessage);
                }
                else
                if (DoWin32Popup.toLowerCase() == 'jquery')
                {
                    eval(ErrorPopupFunc+'();');
                }
                
                // TODO: add validation here
            });
        }
    });
 */
 
$(document).bind('ready', function () {
    $("input").each(function () {
        var IsRequired = new String($(this).attr('IsRequired'));
        if (IsRequired.toLowerCase() == 'true')
        {
            $(this).bind('keyup', function () {
                var ErrorMessage    = new String($(this).attr('ErrorValidationMessage'));
                var DoWin32Popup    = new String($(this).attr('DoErrorPopup'));
                var ErrorPopupFunc  = $(this).attr('ErrorCustomPopup');

                if (DoWin32Popup.toLowerCase() == 'win32')
                {
                    alert(ErrorMessage);
                }
                else
                if (DoWin32Popup.toLowerCase() == 'jquery')
                {
                    eval(ErrorPopupFunc+'();');
                }
                
                // TODO: add validation here
            });
        }
    });
});