function CheckValid(showErrors, level) {
    if (level == undefined || level == null) {
        level = 2;
    }
    var isValid = true;
    $("#errorRow").hide();
    $(".notEmpty").each(function () {
        if ($(this).parent().parent().is(":visible")) {
            $(this).parent().parent().removeClass('error');
            var currentValue = $(this).val();
            if ($(this).attr("tagName").toLowerCase() == "textarea") {

                if ($(this).parent().parent().is(":visible") && (FCKeditorAPI != undefined && FCKeditorAPI != null)) {
                    try {
                        var inst = FCKeditorAPI.GetInstance($(this).attr('id'));
                        if (inst != null) {
                            var sValue = inst.GetHTML();
                            currentValue = sValue;
                        }
                    } catch (err) { }
                }
            }
            if (currentValue == "") {
                isValid = false;
                if (showErrors) {
                    if (level == 1) {
                        $(this).parent().addClass('error');
                    }
                    else {
                        $(this).parent().parent().addClass('error');
                    }
                }
            }
            else {
                if (level == 1) {
                    $(this).parent().removeClass('error');
                }
                else {
                    $(this).parent().parent().removeClass('error');
                }
            }
        }
    });

    $(".numeric").each(function () {

    });

    $(".numericNotNull").each(function () {

    });

    if (!isValid && showErrors) {
        $(".error").each(function () {
            if (!$(this).parent().parent().is(":visible")) {
                $(this).parent().parent().show();
            }
        });
        $("#errorRow").show();
    }

    return isValid;
}

function checkform(form, checkPhoneOrMail) {

    var currentform = $("#" + form);

    var valid = true;
    var message = "Voor wij contact met u kunnen opnemen, hebben wij minimaal de volgende gegevens van u nodig: \n";
    $(".shortNotEmpty", currentform).each(function () {
        $(this).css("border", "1px solid #bbb");
        if ($(this).val() == "") {
            message += "- Uw " + $(this).attr("name") + "\n";
            $(this).css("border", "1px solid red");
            valid = false;
        }
    });
    if (checkPhoneOrMail) {
        $("input[name='telefoonnummer']", currentform).css("border", "1px solid #bbb");
        $("input[name='emailadres']", currentform).css("border", "1px solid #bbb");
        if ($("input[name='telefoonnummer']", currentform).val() == "" &&
            $("input[name='emailadres']", currentform).val() == "") {
          
            $("input[name='telefoonnummer']", currentform).css("border", "1px solid red");
            $("input[name='emailadres']", currentform).css("border", "1px solid red");
            message += "- Uw telefoonnummer of emailadres";
            valid = false;
        }
    }
    if (!valid) {
        alert(message);
        return false;
    }
    else {
        jQuery.get('/QuickContact.ashx?' + currentform.serialize(), function (data) {
            $("#formContainer", currentform).html("<br /><br /><br /><center><img src=\"/Content/images/ajax-loader.gif\" /></center>");
            if (data == "success") {
                var newContent = '<h2>Verzonden!</h2><p>Uw aanvraag is verzonden. Wij nemen, indien u de juiste contactgegevens hebt ingevoerd, zo spoedig mogelijk contact met u op</p>';
                $("#submitbuttonContainer", currentform).hide();                
                setTimeout(function () { $("#formContainer", currentform).html(newContent); }, 1000);                
            }
            else {
                alert("Uw aanvraag kon niet worden verzonden. Probeert u het alstublieft opnieuw. Mocht het niet werken, neem dan gerust contact met ons op via telefoonnummer 0591 677896");
            }
        });
    }
    return false;
}

