﻿<!--

var focuscontrol;
var hiddencontrol;
var informationcontrol;

function addValidationControls()
{
    $('input[type=text][title],input[type=password][title],textarea[title]').each(function(i){
        id = this.id;
        pid = id + "_prompt";
        vid = id + "_valid";
        $(this).addClass(pid);
        var promptSpan = $('<span class="input-prompt"/>');
        $(promptSpan).attr('id', pid);
        $(promptSpan).append($(this).attr('title'));
        $(promptSpan).click(function(){
            $(this).hide();
            $('.' + $(this).attr('id')).focus();
        });
        if($(this).val() != ''){
            $(promptSpan).hide();
        }
        $(this).before(promptSpan);
        $(this).focus(function(){
            $('#' + $(this).attr('class')).hide();
        });
        $(this).blur(function(){
            if($(this).val() == ''){
            $('#' + $(this).attr('class')).show();
            }
        });

        var validationImage = $('<img src="14.png" class="input-valid" />');
        $(validationImage).attr('id', vid);
        $(this).after(validationImage);
    });
}

function addValidationEvents()
{
    $('input[type=text][title],input[type=password][title],textarea[title]').each(function(i){
        $(this).keyup(function() { validateAll(); });
    });
}

function updatePrompt(control)
{
    if(control.val() == '')
        $('#' + control.attr('class')).show();
    else
        $('#' + control.attr('class')).hide();
}

function isValidEmailAddress(emailAddress) {
    if (emailAddress == 0)
        return false;
	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);
}

function isValidText(text, min, max)
{
    if (text == null || text == "")
    {
        if (min > 0)
            return false;
        return true;
    }
    else
    {
        if (text.length >= min && text.length <= max)
            return true;
        return false;
    }
}

function validateEmail(controlName, required)
{
    var controlElement = $(controlName);
    var spanElement = $(controlName + "_prompt");
    var imageControl = $(controlName + "_valid");
    var email = controlElement.val();

    if (email == 0 && !required)
    {
	    imageControl.css({ "display": "none" });
	    controlElement.css({ "color": "#717171" });
        spanElement.css({ "color": "#BFBFBF" });
	    return 1;
	}
    else
    {
        var submitted = isSubmitted();
        var v = isValidEmailAddress(email);
        var sdm = isSubmissionDuplicateMatch(email);
        if (sdm)
            v = false;
		
        var image;
        if (submitted)
            image = (v ? "valid.png" : "question.png");
        else
            image = (v ? "valid.png" : "14.png");
		imageControl.attr('src', BasePath + image);
        
        var disp;
        if (submitted) 
            disp = "inline";
        else
            disp = v ? "inline" : "none";
        imageControl.css({ "display" : disp });

        if (submitted)
        {
            var t;
            if (sdm) t = "This email address already exists.<br />Please log in or enter a new email address.";
            else if (v == false || isSubmissionInvalid()) t = "Please enter a valid email address.";
            else t = "";
            imageControl.attr('title', (v ? "" : t));
            imageControl.tooltip({showURL:false});
        }

        if (submitted)
        {
            c = v ? "#31b8e7" : "#FF0000";
            cs = v ? "#BFBFBF" : "#FF0000";
        }
        else
        {
            c = v ? "#31b8e7" : "#717171";
            cs = v ? "#BFBFBF" : "#BFBFBF";
        }
	    controlElement.css({ "color": c });
        spanElement.css({ "color": cs });

		return v ? 1 : 0;
    }
}

function validateText(controlName, min, max, required)
{
    var controlElement = $(controlName);
    var spanElement = $(controlName + "_prompt");
    var imageControl = $(controlName + "_valid");
    var text = controlElement.val();

    if (text == 0 && !required)
    {
	    imageControl.css({ "display": "none" });
	    controlElement.css({ "color": "#717171" });
        spanElement.css({ "color": "#BFBFBF" });
	    return 1;
	}
    else
    {
        var submitted = isSubmitted();
        var v = isValidText(text, min, max);
		
        var image;
        if (submitted)
            image = (v ? "valid.png" : "question.png");
        else
            image = (v ? "valid.png" : "14.png");
		imageControl.attr('src', BasePath + image);
        
        var disp;
        if (submitted) 
            disp = "inline";
        else
            disp = v ? "inline" : "none";
        imageControl.css({ "display" : disp });

        if (submitted)
        {
            imageControl.attr('title', (v ? "" : "Please enter a valid " + spanElement.html() + "."));
            imageControl.tooltip({showURL:false});
        }

        if (submitted)
        {
            c = v ? "#31b8e7" : "#FF0000";
            cs = v ? "#BFBFBF" : "#FF0000";
        }
        else
        {
            c = v ? "#31b8e7" : "#717171";
            cs = v ? "#BFBFBF" : "#BFBFBF";
        }
	    controlElement.css({ "color": c });
        spanElement.css({ "color": cs });

		return v ? 1 : 0;
    }
}

function isSubmitted()
{
    if (hiddencontrol == null)
        return false;
    return (hiddencontrol.val() != "None");
}

function isSubmissionInvalid()
{
    if (informationcontrol == null)
        return false;
    return (informationcontrol.val() == "Invalid");
}

function isSubmissionDuplicate()
{
    if (informationcontrol == null)
        return false;
    return (informationcontrol.val().indexOf("Duplicate") != -1);
}

function isSubmissionDuplicateMatch(value)
{
    if (informationcontrol == null)
        return false;
    var submissionstate = informationcontrol.val();
    if (submissionstate && submissionstate.indexOf("Duplicate") != -1 && value == submissionstate.substring(("Duplicate:").length))
        return true;
    return false;
}

function addHelperEvents()
{
    $("#helpertip").hover(
        function() { $("#helperbox").stop().show().fadeTo(250, 1); },
        function() { $("#helperbox").stop().fadeTo(900, 0, function() { $(this).hide(); }); }
    );

    $("#helperbox").hover( function() { $(this).stop().show().fadeTo(250, 1); }, function() { $(this).stop().fadeTo(900, 0, function() { $(this).hide(); }); }); 
}

function addDontForgetEvents()
{
    $("#dontforget1").hover(
        function() { $("#dontforgetbox1").stop().show().fadeTo(250, 1); },
        function() { $("#dontforgetbox1").stop().fadeTo(800, 0, function() { $(this).hide(); }); }
    );
    $("#dontforget2").hover(
        function() { $("#dontforgetbox2").stop().show().fadeTo(250, 1); },
        function() { $("#dontforgetbox2").stop().fadeTo(800, 0, function() { $(this).hide(); }); }
    );
    $("#dontforget3").hover(
        function() { $("#dontforgetbox3").stop().show().fadeTo(250, 1); },
        function() { $("#dontforgetbox3").stop().fadeTo(800, 0, function() { $(this).hide(); }); }
    );
    $("#dontforget4").hover(
        function() { $("#dontforgetbox4").stop().show().fadeTo(250, 1); },
        function() { $("#dontforgetbox4").stop().fadeTo(800, 0, function() { $(this).hide(); }); }
    );

    $("#dontforgetbox1").hover( function() { $(this).stop().show().fadeTo(250, 1); }, function() { $(this).stop().fadeTo(200, 0, function() { $(this).hide(); }); }); 
    $("#dontforgetbox2").hover( function() { $(this).stop().show().fadeTo(250, 1); }, function() { $(this).stop().fadeTo(200, 0, function() { $(this).hide(); }); }); 
    $("#dontforgetbox3").hover( function() { $(this).stop().show().fadeTo(250, 1); }, function() { $(this).stop().fadeTo(200, 0, function() { $(this).hide(); }); }); 
    $("#dontforgetbox4").hover( function() { $(this).stop().show().fadeTo(250, 1); }, function() { $(this).stop().fadeTo(200, 0, function() { $(this).hide(); }); }); 
}

/*function validateEmail(email, imageControl, required)
{
    if (email == 0 && !required)
    {
	    imageControl.css({ "background-image": "none" });
	    return 1;
	}
    else
    {
        var v = isValidEmailAddress(email);
		var image = v ? "valid.png" : "invalid.png";
		imageControl.attr('src', BasePath + "images/" + image);
		return v ? 1 : 0;
    }
}

function validateText(text, imageControl, min, max, required)
{
    if (text == 0 && !required)
    {
	    imageControl.css({ "background-image": "none" });
	    return 1;
	}
    else
    {
        var v = isTextValid(text, min, max);
		var image = v ? "valid.png" : "invalid.png";
		imageControl.attr('src', BasePath + "images/" + image);
		return v ? 1 : 0;
    }
}

function hideImage(imageControl)
{
    //imageControl.css({ "background-image": "none" });
	imageControl.attr('src', "");
}

function setImage(imageControl, valid)
{
	var image = valid ? "valid.png" : "invalid.png";
	imageControl.attr('src', BasePath + "images/" + image);
}*/

//-->
