jQuery(document).ready( function($) {  
    if(location.hash.length>0){
        if(location.hash=="#success"){
            alert('Ваше сообщение было увпешно доставлено на сервер. Ну, и собственно говоря спасибо вам за это =)');
        }  
    }

    $("#contact_comment_form input[name='author']").focus(function(){  
        $(this).removeClass("warning");
        $(this).addClass("active");
        if("Ваше имя"==$(this).val() || "Введите ваше имя"==$(this).val())
            $(this).val("");                      
    })  

    $("#contact_comment_form input[name='author']").blur(function(){
        $(this).removeClass("active");          
        if(""==$(this).val())
            $(this).val("Ваше имя");                      
    })     
    $("#contact_comment_form input[name='email']").focus(function(){
        $(this).removeClass("warning");          
        $(this).addClass("active");
        if("Ваш e-mail"==$(this).val() || "Введите e-mail"==$(this).val())
            $(this).val("");                      
    })  

    $("#contact_comment_form input[name='email']").blur(function(){
        $(this).removeClass("active");          
        if(""==$(this).val())
            $(this).val("Ваш e-mail"); 
        if(!/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test($(this).val())){
        }else{
            $(this).parents('#contact_comment_form').find(".incorrect_email").hide();           
        }                                   
    })    
    $("#contact_comment_form textarea").focus(function(){
        $(this).removeClass("warning");          
        $(this).addClass("active");
        if("Текст сообщения"==$(this).val() || "Введите текст сообщения"==$(this).val())
            $(this).val("");                      
    })  

    $("#contact_comment_form textarea").blur(function(){
        $(this).removeClass("active");          
        if(""==$(this).val())
            $(this).val("Текст сообщения");                      
    })   
    
    $('button.send_comment_form').click(function(){
        var inner_email, inner_author, inner_comment, inner_return;
        inner_return=true;
        inner_email=$(this).parents("#contact_comment_form").find("input[name='email']").val();
        inner_author=$(this).parents("#contact_comment_form").find("input[name='author']").val();
        inner_comment=$(this).parents("#contact_comment_form").find("textarea[name='comment']").val();
        
        if(inner_author.length<1 || inner_author== "Ваше имя" || "Введите ваше имя"==inner_author){
            $(this).parents("#contact_comment_form").find("input[name='author']").val("Введите ваше имя");
            $(this).parents("#contact_comment_form").find("input[name='author']").addClass("warning");
            inner_return=false;    
        }
        
        if(inner_email.length<1 || inner_email== "Ваш e-mail" || "Введите e-mail"==inner_email){
            $(this).parents("#contact_comment_form").find("input[name='email']").val("Введите e-mail");
            $(this).parents("#contact_comment_form").find("input[name='email']").addClass("warning");
            inner_return=false;    
        }else{
            if(!/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(inner_email)){
                $(this).parents("#contact_comment_form").find(".incorrect_email").show();
                inner_return=false; 
            }     
        }  
                 
        if(inner_email.length<1 || inner_comment== "Текст сообщения" || "Введите текст сообщения"==inner_comment){
            $(this).parents("#contact_comment_form").find("textarea[name='comment']").val("Введите текст сообщения");
            $(this).parents("#contact_comment_form").find("textarea[name='comment']").addClass("warning");
            inner_return=false;    
        }        
        
        return inner_return;
    })       
               
})    