/*
===============================
DotControl copyright 2010
===============================
*/

function ApplyFixes() {

    /* ====== Wrapping for figure container ====== */

    $(".FigureContainer").wrap(
        '<div class="FigureLineRight">'+
        '<div class="FigureLineBottom">'+
        '<div class="FigureCornerTopLeft">'+
        '<div class="FigureCornerTopRight">'+
        '<div class="FigureCornerBottomLeft">'+
        '<div class="FigureCornerBottomRight">'+
        '</div>'+
        '</div>'+
        '</div>'+
        '</div>'+
        '</div>'+
        '</div>');

    /* ====== Changing image with fade effect ====== */

    $(".ImageRotatorThumb1").click(function () {
        $(".ImageRotator").fadeOut(500, function() {
            $(this).attr({ "src": "/Portals/3/images/Photos/Photo1.jpg" });
            if (this.complete) $(this).fadeIn(500);
        });
    });

    $(".ImageRotatorThumb2").click(function () {
        $(".ImageRotator").fadeOut(500, function () {
            $(this).attr({ "src": "/Portals/3/images/Photos/Photo2.jpg" });
            if (this.complete) $(this).fadeIn(500);
        });
    });

    $(".ImageRotatorThumb3").click(function () {
        $(".ImageRotator").fadeOut(500, function () {
            $(this).attr({ "src": "/Portals/3/images/Photos/Photo3.jpg" });
            if (this.complete) $(this).fadeIn(500);
        });
    });

    $(".ImageRotatorThumb4").click(function () {
        $(".ImageRotator").fadeOut(500, function () {
            $(this).attr({ "src": "/Portals/3/images/Photos/Photo4.jpg" });
            if (this.complete) $(this).fadeIn(500);
        });
    });

    $(".ImageRotatorThumb5").click(function () {
        $(".ImageRotator").fadeOut(500, function () {
            $(this).attr({ "src": "/Portals/3/images/Photos/Photo5.jpg" });
            if (this.complete) $(this).fadeIn(500);
        });
    });
	
	/* ===== Removing Reacties shadow block if content is empty === */
	
	if ($('.DNNEmptyPane').length)
	{
		$('.DNNEmptyPane').parents('.ShoutBoxWrapper').css('display','none');
	}
	
	
}

/* VALIDATORS */

function ValidateRequired(sender, args) {
    var $val = args.Value;
    args.IsValid = requiredValidate($val, sender);
}

function ValidateEmail(sender, args) {
    var $val = args.Value;
    args.IsValid = validateEmail($val, sender);
}

function requiredValidate(value, sender) {
    isValid = !(value == "" || value == false);
    highlightError($(sender).siblings('input, textarea'), isValid);
    return isValid;
}

function validateEmail(value, sender) {
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    var isValid = emailPattern.test(value);
    highlightError($(sender).siblings('input, textarea'), isValid);
    return isValid;
}

function highlightError(object, isValid) {
    if (!isValid) {
        $(object).addClass('invalid');
    } else {
        $(object).removeClass('invalid');
    }
    $('.invalid').first().focus();
}
