﻿var errors = new Array();
var validEmail = false;
var validDOB = false;

function validateInput(containerID) {
    var formComplete = true;

    $(containerID + " :input").each(function(e) {
        if (!$(this).hasClass("optional")) {
            if (this.tagName == "SELECT") {
                if ($(this).val() == null || $(this).val().length == 0) {
                    formComplete = false;
                    $(this).parent().addClass("divVal");
                }
            }
            else {
                if (this.value.length == 0) {
                    formComplete = false;
                    $(this).addClass("val");
                }
                else
                    $(this).removeClass("val");
            }
        }
    });

    if (!formComplete)
        errors[errors.length] = "Complete the above to continue";

    return formComplete;
}

function Submitting(hide) {
    if (hide) {
        $(".pSubmitting").show();
        $(".btn").hide();
    }
    else {
        $(".pSubmitting").hide();
        $(".btn").show();
    }
}

function updateDisplay($control, type) {
    if (!$control.hasClass("optional")) {
        if ($control.val().length > 0) {
            if (type == undefined || (type == "pass" && $control.val().length >= 6)) {
                $control.removeClass("val");
                $control.parent().removeClass("divVal");
                if ($control[0].id.indexOf("ddlBirth") > -1) {
                    $control.parent().addClass("dob");

                }
            }
        }
    }
}
function emailValidationResult(result) {
    var emailResult = result.split(';')[0].split(':')[1];
    var dobResult = result.split(';')[1].split(':')[1];
    if (emailResult == "true") {
        validEmail = true;
    }
    else {
        validEmail = false;
        document.getElementById(txtEmailID).className = 'val';
    }

    if (dobResult == "true") {
        validDOB = true;
    }
    else {
        validDOB = false;
    }

    validateRegistrationPart2();
}



function DisplayErrors() {
    if (errors.length > 0) {
        var containingDiv = document.getElementById('container');
        var erContainer = document.getElementById('errors');

        if (erContainer != undefined) {
            //delete then rebuild
            containingDiv.removeChild(erContainer);
        }
        erContainer = document.createElement('ul');
        erContainer.setAttribute('id', 'errors');
        erContainer.setAttribute('class', 'errorList');

        for (var i = 0; i < errors.length; i++) {
            var li = document.createElement('li');
            var text = document.createTextNode('! ' + errors[i]);
            li.appendChild(text);
            erContainer.appendChild(li);
        }
        containingDiv.appendChild(erContainer);
    }
    else {
        //remove if exists
        var containingDiv = document.getElementById('id1');
        var errorList = document.getElementById('erContainer');

        if (errorList != undefined)
            containingDiv.removeChild(errorList);
    }
    errors.splice(0, errors.length);
}

function passwordsMatch($pass1, $pass2) {
    var valid = $pass1.val() == $pass2.val();

    if (!valid) {
        $pass1.addClass("val");
        $pass2.addClass("val");
    }

    return valid;
}
try {
    $(document).ready(function() {
        if ($("#divBackground").length > 0) {
            var bg = $("#divBackground");
            var image = "";
            var hour = new Date().getHours();

            //night
            if (hour > 20 || hour < 6) {
                image = "night.jpg";
            }
            //dawn
            else if (hour > 6 && hour < 10) {
                image = "dawn.jpg";
            }
            //day
            else if (hour > 10 && hour < 17) {
                image = "day.jpg";
            }
            else {
                image = "dusk.jpg";
            }
            bg.css("background", "url('" + path + "im/register/v2/" + image + "') no-repeat");
        }
    });
}
catch (ex) { }
