﻿function txtIs18_Validate(source, args)
{
     var monthID = document.getElementById('ctl00_ContentPlaceHolder1_txtMonth');
    var dayID = document.getElementById('ctl00_ContentPlaceHolder1_txtDay');
    var yearID = document.getElementById('ctl00_ContentPlaceHolder1_txtYear');

    var birthMonth = parseInt(monthID.value);
    var birthDay = parseInt(dayID.value);
    var birthYear = parseInt(yearID.value);

    if (!isNaN(birthMonth) && !isNaN(birthDay) && !isNaN(birthYear)) {
        var birth = new Date();
        birth.setFullYear(birthYear, birthMonth - 1, birthDay);

        var current = new Date();

        if (current.getFullYear() - birth.getFullYear() == 18) {
            if (current.getMonth() > birth.getMonth()) {
                args.IsValid = true;
            }

            else if (current.getMonth() == birth.getMonth()) {
                if (current.getDate() >= birth.getDate()) {
                    args.IsValid = true;
                }

                else {
                    args.IsValid = false;
                }
            }

            else {
                args.IsValid = false;
            }
        }

        else if (current.getFullYear() - birth.getFullYear() > 18) {
            args.IsValid = true;
        }

        else {
            args.IsValid = false;
        }
    }

    else {
        args.IsValid = false;
        source.errormessage = "Please re-enter your birth date.";
        
        
    }
    if(yearID.value.length != 4)
    {
        args.IsValid = false;
    }       
    
    if(args.IsValid)
    {
        $("#ctl00_ContentPlaceHolder1_txtMonth").removeClass("error");
        $("#ctl00_ContentPlaceHolder1_txtDay").removeClass("error");
        $("#ctl00_ContentPlaceHolder1_txtYear").removeClass("error");
    }
    else
    {
        $("#ctl00_ContentPlaceHolder1_txtMonth").addClass("error");
        $("#ctl00_ContentPlaceHolder1_txtDay").addClass("error");
        $("#ctl00_ContentPlaceHolder1_txtYear").addClass("error");
    }
    
    
}
function txtDay_Validate(source, args)
{
    args.IsValid = false; 
    
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtDay').value !== "" && document.getElementById('ctl00_ContentPlaceHolder1_txtDay').value != "DD")
    {   
        args.IsValid = true;
        $('#ctl00_ContentPlaceHolder1_txtDay').removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $('#ctl00_ContentPlaceHolder1_txtDay').addClass("error");
    }      

}
function txtMonth_Validate(source, args)
{
           
    args.IsValid = false; 
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtMonth').value !== "" && document.getElementById('ctl00_ContentPlaceHolder1_txtMonth').value != "MM")
    {   
        args.IsValid = true;
        $('#ctl00_ContentPlaceHolder1_txtMonth').removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $('#ctl00_ContentPlaceHolder1_txtMonth').addClass("error");
    }      

}
function txtYear_Validate(source, args)
{
           
    args.IsValid = false; 
    var year = document.getElementById('ctl00_ContentPlaceHolder1_txtYear');
    if(year.value !== "" && year.value !="YYYY" && year.value.length == 4)
    {   
        args.IsValid = true;
        $('#ctl00_ContentPlaceHolder1_txtYear').removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $('#ctl00_ContentPlaceHolder1_txtYear').addClass("error");
    }      

}
function txtEmail_Validate(source, args)
{       
    args.IsValid = false; 
    
    var email = document.getElementById('ctl00_ContentPlaceHolder1_txtEmail');		 
	 var regex = new RegExp('^[A-Za-z0-9._-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$');

    if(regex.test(email.value) == true)
    {
        args.IsValid = true;
    }
    else
    {
        source.errormessage = "Invalid Email Address. Please re-enter using \"name@domain.com\" format";
    }

	if(args.IsValid)
    {   
        args.IsValid = true;
        $(email).removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $(email).addClass("error");
    }
}
function txtConfirmEmail_Validate(source, args)
{
           
    args.IsValid = false;
    var confirmEmail =  document.getElementById('ctl00_ContentPlaceHolder1_txtConfirmEmail');    	 
	 var regex = new RegExp('^[A-Za-z0-9._-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$');
    if(confirmEmail.value !== "" && regex.test(confirmEmail.value))
    {   
        args.IsValid = true;
        $(confirmEmail).removeClass("error");
    }
    else
    {
        $('#ctl00_ContentPlaceHolder1_txtEmail').addClass("error");
        args.IsValid = false;
        $(confirmEmail).addClass("error");
    }      

}
function txtPassword_Validate(source, args)
{       
    args.IsValid = false; 
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtPassword').value !== "")
    {   
        args.IsValid = true;
        $('#ctl00_ContentPlaceHolder1_txtPassword').removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $('#ctl00_ContentPlaceHolder1_txtPassword').addClass("error");
    }      
}
function txtOldPassword_Validate(source, args)
{       
    args.IsValid = false; 
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtOldPassword').value !== "")
    {   
        args.IsValid = true;
        $('#ctl00_ContentPlaceHolder1_txtOldPassword').removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $('#ctl00_ContentPlaceHolder1_txtOldPassword').addClass("error");
    }      
}
function txtConfirmPassword_Validate(source, args)
{       
    args.IsValid = false; 
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtConfirmPassword').value !== "")
    {   
        args.IsValid = true;
        $('#ctl00_ContentPlaceHolder1_txtConfirmPassword').removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $('#ctl00_ContentPlaceHolder1_txtConfirmPassword').addClass("error");
    }      
}
function txtQuestion_Validate(source, args)
{
    args.IsValid = false;
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtQuestion').value !== "")
    {   
        args.IsValid = true;
        $('#ctl00_ContentPlaceHolder1_txtQuestion').removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $('#ctl00_ContentPlaceHolder1_txtQuestion').addClass("error");
    }      
}
function txtAnswer_Validate(source, args)
{
    args.IsValid = false;
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtAnswer').value !== "")
    {   
        args.IsValid = true;
        $('#ctl00_ContentPlaceHolder1_txtAnswer').removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $('#ctl00_ContentPlaceHolder1_txtAnswer').addClass("error");
    }      
}
function txtFirstName_Validate(source, args)
{       
    args.IsValid = false; 
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtFirstName').value !== "")
    {   
        args.IsValid = true;
        $('#ctl00_ContentPlaceHolder1_txtFirstName').removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $('#ctl00_ContentPlaceHolder1_txtFirstName').addClass("error");
    }      
}
function txtLastName_Validate(source, args)
{       
    args.IsValid = false; 
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtLastName').value !== "")
    {   
        args.IsValid = true;
        $('#ctl00_ContentPlaceHolder1_txtLastName').removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $('#ctl00_ContentPlaceHolder1_txtLastName').addClass("error");
    }      
}
function txtAddress_Validate(source, args)
{       
    //args.IsValid = false; 
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtAddress').value !== "")
    {   
        args.IsValid = true;
        $('#ctl00_ContentPlaceHolder1_txtAddress').removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $('#ctl00_ContentPlaceHolder1_txtAddress').addClass("error");
    }      
}
function txtCity_Validate(source, args)
{       
    args.IsValid = false; 
    if(document.getElementById('ctl00_ContentPlaceHolder1_txtCity').value !== "")
    {   
        args.IsValid = true;
        $('#ctl00_ContentPlaceHolder1_txtCity').removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $('#ctl00_ContentPlaceHolder1_txtCity').addClass("error");
    }      
}
function ddlState_Validate(source, args)
{       
    args.IsValid = false; 
    if(document.getElementById('ctl00_ContentPlaceHolder1_ddlState').value !== "" && document.getElementById('ctl00_ContentPlaceHolder1_ddlState').value != "Please select a state...")
    {   
        args.IsValid = true;
        $('#ctl00_ContentPlaceHolder1_ddlState').removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $('#ctl00_ContentPlaceHolder1_ddlState').addClass("error");
    }      
}
function txtZip_Validate(source, args)
{       
    args.IsValid = false;
    var zip= document.getElementById('ctl00_ContentPlaceHolder1_txtZip');
    if(zip.value !== "" && zip.value.length >=4)
    {   
        args.IsValid = true;
        $(zip).removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $(zip).addClass("error");
    }      
}
function txtAreaCode_Validate(source, args)
{       
    args.IsValid = false; 
    var areaCode = document.getElementById('ctl00_ContentPlaceHolder1_txtAreaCode');
    if(areaCode.value !== "" && areaCode.value.length ==3)
    {   
        args.IsValid = true;
        $(areaCode).removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $(areaCode).addClass("error");
    }      
}
function txtPhone1_Validate(source, args)
{       
    args.IsValid = false; 
    var txtPhone1 = document.getElementById('ctl00_ContentPlaceHolder1_txtPhone1');
    if(txtPhone1.value !== "" && txtPhone1.value.length ==3)
    {   
        args.IsValid = true;
        $(txtPhone1).removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $(txtPhone1).addClass("error");
    }      
}
function txtPhone2_Validate(source, args)
{       
    args.IsValid = false; 
    var txtPhone2 = document.getElementById('ctl00_ContentPlaceHolder1_txtPhone2');
    if(txtPhone2.value !== "" && txtPhone2.value.length ==4)
    {   
        args.IsValid = true;
        $(txtPhone2).removeClass("error");
    }
    else
    {
        args.IsValid = false;
        $(txtPhone2).addClass("error");
    }      
}

function rbDependent_Validate(source, args)
{   
    args.IsValid = false;
    var dependent = document.getElementById('ctl00_ContentPlaceHolder1_rbDependent_0');
    var self = document.getElementById('ctl00_ContentPlaceHolder1_rbDependent_1');
    var value = $("input:radio:checked").val();
    if(value == "no")
    {
        $(".selfQs").css("display", "block");
        $(".dependentQs").css("display", "none");
        args.IsValid = true;
    }
    else if(value == "yes")
    {
        $(".dependentQs").css("display", "block");
        $(".selfQs").css("display", "none");
        args.IsValid = true;
    }

}

function ddlHealthGoals_Validate(source, args)
{
    args.IsValid = false;
    var healthGoalsID = document.getElementById('ctl00_ContentPlaceHolder1_ddlHealthGoals');
    var otherTxtID = document.getElementById('ctl00_ContentPlaceHolder1_txtOtherGoal');
    if(healthGoalsID.value == "Other (specify)." || healthGoalsID.value == "Avoid/prevent the start of any specific illness/disease (specify).")
    {
        $(otherTxtID).css("display", "block");
    }
    else
    {
        $(otherTxtID).css("display", "none");
        args.IsValid = true;
    }    
}

function ddlGoalMotivation_Validate(source, args)
{
    args.IsValid = false;
    var goalMotivationID = document.getElementById('ctl00_ContentPlaceHolder1_ddlGoalMotivation');
    var otherTxtID = document.getElementById('ctl00_ContentPlaceHolder1_txtOtherMotivation');
    if(goalMotivationID.value == "Other (specify).")
    {
        $(otherTxtID).css("display", "block");
    }
    else
    {
        $(otherTxtID).css("display", "none");
        args.IsValid = true;
    }    
}

// Month and Day Mask: Translates single digits into 2, e.g. "3" becomes "03"
$(document).ready(function() {
    var regex = new RegExp('^[0-9]{1}$');
    $(".mask-month-day").each(function() {
        $(this).blur(function() {
            var text = $(this).get(0).value;
            if (regex.test(text)) {
                $(this).get(0).value = '0' + text;
            }
        });
    });
});

// Year Mask: Translates a 2-digit year into a 4-digit year.
// Because this is for a birthdate field, and a user must be
// 18 to register, this mask assumes a prefix of "19".
$(document).ready(function() {
    var regex = new RegExp('^[0-9]{2}$');
    $(".mask-year").each(function() {
        $(this).blur(function() {
            var text = $(this).get(0).value;
            if (regex.test(text)) {
                $(this).get(0).value = '19' + text;
            }
        });
    });
});
// Text Mask: Only allows letters, space, apostrophe, hyphen, period.
// ASCII Values:
//  65-90 = A-Z
//  97-122 = a-z
//  32 = space
//  39 = apostrophe
//  45 = hyphen
//  46 = period
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
$(document).ready(function() {
    $(".mask-text").each(function() {
        $(this).keypress(function(e) {
        if (e.which == 0 || e.which == 8 || e.which == 9 || e.which == 127 || e.which == 32 || e.which == 39 || e.which == 45 || 
            e.which == 46 || (e.which > 64 && e.which < 91) || (e.which > 96 && e.which < 123)) {
                return true;
            }
            else {
                return false;
            }
        });
    });
});


// Number-Mask: Allows only numbers to be entered into a text field.
// ASCII Values:
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
//  48-57 = 0-9
$(document).ready(function() {
    $(".mask-numbers").each(function() {
        $(this).keypress(function(e) {
            if (e.which == 0 || e.which == 8 || e.which == 9 || e.which == 127 || (e.which > 47 && e.which < 58)) {
                return true;
            }
            else {
                return false;
            }
        });
    });
});

// Zip-Mask: Allows only numbers and hyphens to be entered into a text field.
// ASCII Values:
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
//  48-57 = 0-9
//  45 = "-"
$(document).ready(function() {
    $(".mask-zip").each(function() {
        $(this).keypress(function(e) {
            if (e.which == 0 || e.which == 8 || e.which == 9 || e.which == 127 || e.which == 45 || (e.which > 47 && e.which < 58)) {
                return true;
            }
            else {
                return false;
            }
        });
    });
});

// Password-Mask: Does not allow "<" or ">" or "/" or "\" to be entered in the password field.
// ASCII Values:
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
//  48-57 = 0-9
//  45 = "-"
$(document).ready(function() 
{
    $(".mask-password").each(function() 
    {
        $(this).keypress(function(e) 
        {
            if ((e.which != 47) && (e.which != 60) && (e.which != 61) && (e.which != 62) && (e.which != 92))
            {
                return true;
            }
            else 
            {
                return false;
            }
        });
    });
});


// Email-Mask: Does not allow "<" or ">" or "/" or "\" to be entered in the password field.
// ASCII Values:
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
//  48-57 = 0-9
//  45 = "-"
$(document).ready(function() 
{
    $(".mask-email").each(function() 
    {
        $(this).keypress(function(e) 
        {
            if ((e.which != 47) && (e.which != 60) && (e.which != 61) && (e.which != 62) && (e.which != 92))
            {
                return true;
            }
            else 
            {
                return false;
            }
        });
    });
});


// Script-Mask: General use mask for text fields to not allow "<" or ">" or "/" or "\" to be entered in the password field.
// ASCII Values:
//  8 = Backspace
//  0 = Null
//  9 = Tab
//  127 = Delete
//  48-57 = 0-9
//  45 = "-"
$(document).ready(function() 
{
    $(".mask-script").each(function() 
    {
        $(this).keypress(function(e) 
        {
            if ((e.which != 47) && (e.which != 60) && (e.which != 61) && (e.which != 62) && (e.which != 92))
            {
                return true;
            }
            else 
            {
                return false;
            }
        });
    });
});


$(document).ready(function(){
    var healthGoalsID = document.getElementById('ctl00_ContentPlaceHolder1_ddlHealthGoals');
    var otherTxtID = document.getElementById('ctl00_ContentPlaceHolder1_txtOtherGoal');
    if(healthGoalsID != null)
    {
        if(healthGoalsID.value == "Other (specify)." || healthGoalsID.value == "Avoid/prevent the start of any specific illness/disease (specify).")
        {
            $(otherTxtID).css("display", "block");
        }
        else
        {
            $(otherTxtID).css("display", "none");
        }   
    }
    
    
    var dependent = document.getElementById('ctl00_ContentPlaceHolder1_rbDependent_0');
    var self = document.getElementById('ctl00_ContentPlaceHolder1_rbDependent_1');    
    var value = $("input:radio:checked").val();
    if(value != null)
    {
        if(value == "no")
        {
            $(".selfQs").css("display", "block");
            $(".dependentQs").css("display", "none");
        }
        else if(value == "yes")
        {
            $(".dependentQs").css("display", "block");
            $(".selfQs").css("display", "none");
        }
    }
    
    var healthGoalsID = document.getElementById('ctl00_ContentPlaceHolder1_ddlGoalMotivation');
    var otherTxtID = document.getElementById('ctl00_ContentPlaceHolder1_txtOtherMotivation');
    if(healthGoalsID != null)
    {
        if(healthGoalsID.value == "Other (specify).")
        {
            $(otherTxtID).css("display", "block");
        }
        else
        {
            $(otherTxtID).css("display", "none");
        }    
    }
});
