﻿(function ($) {
    $.managementTextValue = function (element, oldValue, newValue, nameFunction) {
        if (nameFunction == 'onfocus' && $("#" + element).val() == oldValue) {
            $("#" + element).val(newValue);
            $("#" + element).css("color", "#CCCCCC");
        }
        else if (nameFunction == 'onblur' && $("#" + element).val() == '') {
            $("#" + element).val(newValue);
            $("#" + element).css("color", "#CCCCCC");
        }
    };
})(jQuery);

(function ($) {
    $.managerSteps = function (step, nextStep, bln_backStep) {

        $('#' + element).show('slow');
        $('#' + element_two).hide('slow');
    }
})(jQuery);

(function ($) {
    $.ShowMessage = function (containerId) {
        $('#' + containerId).slideDown('slow').css("display", "block");
    }
})(jQuery);

(function ($) {
    $.HideMessage = function (containerId) {
        $('#' + containerId).slideUp('slow').css("display", "none");
    }
})(jQuery);

function validateTextBox(source, args) {
    if (!notNull($("#" + source.controltovalidate).val()) || $("#" + source.controltovalidate).val() == source.attributes.chave.nodeValue) {
        $("#" + source.controltovalidate).val(source.attributes.chave.nodeValue);
        $("#" + source.controltovalidate).css("color", "#B1B1B1");
        args.IsValid = false;
    } else {
        args.IsValid = true;
    }
}

function validateTextEmail(source, args) {
    if (!notNull($("#" + source.controltovalidate).val()) || $("#" + source.controltovalidate).val() == source.attributes.chave.nodeValue || !checkMail($("#" + source.controltovalidate).val())) {
        $("#" + source.controltovalidate).val(source.attributes.chave.nodeValue);
        $("#" + source.controltovalidate).css("color", "#B1B1B1");
        args.IsValid = false;
    } else {
        args.IsValid = true;
    }
}

function validateTextURL(source, args) {
    if (!notNull($("#" + source.controltovalidate).val()) || $("#" + source.controltovalidate).val() == source.attributes.chave.nodeValue || !checkURL($("#" + source.controltovalidate).val())) {
        $("#" + source.controltovalidate).val(source.attributes.chave.nodeValue);
        $("#" + source.controltovalidate).css("color", "#B1B1B1");
        args.IsValid = false;
    } else {
        args.IsValid = true;
    }
}

function notNull(string) {
    if (string != "" && !(string.match(/^\s+$/))) {
        return true;
    } else {
        return false;
    }
}

function checkMail(mail) {
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);

    var emailCheck = false;

    if (typeof (mail) == "string") {
        if (er.test(mail)) { emailCheck = true; }
    } else if (typeof (mail) == "object") {
        if (er.test(mail.value)) { emailCheck = true; }
    }

    return emailCheck;
}

function checkURL(url) {
    var er = new RegExp(/^(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/);

    var urlCheck = false;

    if (typeof (url) == "string") {
        if (er.test(url)) { urlCheck = true; }
    } else if (typeof (url) == "object") {
        if (er.test(url.value)) { urlCheck = true; }
    }

    return urlCheck;
}
