function validEmail(email) { var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ return email.match(re) } $(document).ready(function(){ /* $('.info').each(function() { $(this).show(); }); */ function ErrorState(obj) { if (!$(obj).hasClass('error')) $(obj).addClass('error'); var id = obj.attr("id"); $('#blockMainOuter #' + id + '-info').removeClass('success').removeClass('info').addClass('info-error'); } function RemoveErrorState(obj) { $(obj).removeClass('error'); var id = obj.attr("id"); $('#' + id + '-info').removeClass('info-error').addClass('info'); } function AddSuccessState(obj) { var id = obj.attr("id"); $('#blockMainOuter #' + id + '-info').removeClass('info-error').addClass('success'); } function ShowTip(obj, bError) { var $this = obj; var id = $this.attr("id"); var xOffset = 0; var yOffset = 0; xOffset = $this.width() + 5; var top = $this.position().top + yOffset; var left = $this.position().left + xOffset; var error = '-error'; var bgColor = '#ffe1e1'; var border = '1px solid #fe0000'; if (bError == false) { error = ''; bgColor = '#f8f8f8'; border = '1px solid #eeeeee'; } $('#blockMainOuter #' + id + '-text' + error).css("top", top+"px").css("left", left+"px").css("background", bgColor).css("border", border).fadeIn("slow"); } function HideTip(obj, bError) { var $this = obj; var id = $this.attr("id"); var error = '-error'; if (bError == false) error = ''; $('#' + id + '-text' + error).hide(); } $('#blockMainOuter .info').live('mouseenter', function() { ShowTip($(this), false); }); $('#blockMainOuter .info').live('mouseleave', function() { HideTip($(this), false); }); $('#blockMainOuter .info-error').live('mouseenter', function() { ShowTip($(this), true); }); $('#blockMainOuter .info-error').live('mouseleave', function() { HideTip($(this), true); }); $('#blockMainOuter .required').focusin(function() { if ($(this).hasClass('error')) { RemoveErrorState($(this)); } }); $('#blockMainOuter .required').focusout(function() { // hide tip $('#' + $(this).attr('id') + '-info-text').hide(); if ($(this).val() == '') { ErrorState($(this)); } else { AddSuccessState($(this)); } }); $('#blockMainOuter .textfeld').focusin(function() { $(this).addClass('focus'); }); $('#blockMainOuter .textarea').focusout(function() { $(this).removeClass('focus'); }); $('#blockMainOuter .textarea').focusin(function() { $(this).addClass('focus'); }); $('#blockMainOuter .textfeld').focusout(function() { $(this).removeClass('focus'); }); $('#blockMainOuter .email').focusout(function() { if(!validEmail($(this).val())) ErrorState($(this)); }); var form = $("#blockMainOuter .customForm"); form.submit(function(){ var error = 0; $('#blockMainOuter .required').each(function() { if (!$(this).val()) { ErrorState($(this)); error++; } else { $(this).removeClass('error'); } }); $('#blockMainOuter .email').each(function() { if(!validEmail($(this).val())) { ErrorState($(this)); error++; } }); if (error > 0) { return false; } else { return true; } }); });