jQuery(document).ready( function($) {  
     /************************************CONTACT VERIFICATION*****************************************************/
    $("#contact_form input.form_name").focus(function(){  
        $(this).addClass("active");
        if("Как к вам обращаться?"==$(this).val())
            $(this).val("");                      
    })  

    $("#contact_form input.form_name").blur(function(){
        $(this).removeClass("active");          
        if(""==$(this).val())
            $(this).val("Как к вам обращаться?");                      
    })
            
    $("#contact_form input.form_email").focus(function(){
        $(this).addClass("active");
        if("Адрес эл. почты"==$(this).val())
            $(this).val("");                      
    })  

    $("#contact_form input.form_email").blur(function(){
        $(this).removeClass("active");          
        if(""==$(this).val())
            $(this).val("Адрес эл. почты"); 
        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{
        }                                   
    })   
      
    $("#contact_form textarea").focus(function(){
        $(this).addClass("active");
        if("Текст сообщения"==$(this).val())
            $(this).val("");                      
    })  

    $("#contact_form textarea").blur(function(){
        $(this).removeClass("active");          
        if(""==$(this).val())
            $(this).val("Текст сообщения");                      
    })   

    $('#send_contact').click(function(){
        var inner_email, inner_author, inner_comment, inner_return, inner_message, inner_message_a, inner_message_e, inner_message_t, inner_counter;
        inner_message=inner_message_a=inner_message_e=inner_message_t="";                                                           
        inner_return=true;
        inner_counter=0;
        inner_email=$(this).parent().find("input.form_email").val();
        inner_author=$(this).parent().find("input.form_name").val();
        inner_comment=$(this).parent().find("textarea").val();
        
    /*    if(inner_author.length<1 || inner_author== "Как к вам обращаться?"){
            inner_message_a="ваше имя";
            inner_counter++;
            inner_return=false;    
        } */
        
        if(inner_email.length<1 || inner_email== "Адрес эл. почты"){
            inner_message_e="адрес эл.почты";
            inner_counter++;
            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)){
                inner_message_e="корректный адрес эл.почты"; 
                inner_return=false; 
                inner_counter++;
            }     
        }  
                 
        if(inner_comment.length<1 || inner_comment== "Текст сообщения"){
            inner_message_t="текст сообщения";
            inner_return=false;
            inner_counter++;    
        }      
        
        
        $("#contact_warning").empty();
        
        if(inner_return==false){
            switch(inner_counter){
                case 1:
                    inner_message="Вы не ввели "+inner_message_a+inner_message_e+inner_message_t+".";    
                    break;
                case 2:
                    if(inner_message_a == ""){
                        inner_message="Вы не ввели "+inner_message_e+" и "+inner_message_t+".";                            
                    }
                    else{
                        inner_message="Вы не ввели "+inner_message_a+" и "+inner_message_e+inner_message_t+".";                          
                    }
                    break;
                case 3:
                    inner_message="Вы не ввели "+inner_message_a+", "+inner_message_e+" и "+inner_message_t+".";  
                    break;
               default:
                    break;                    
            }
            $("#contact_warning").append(inner_message);        
        }          
        
        return inner_return;
    })      
     /************************************END CONTACT VERIFICATION*****************************************************/
     /************************************CONTACT ROLLDOWN*****************************************************/
              
          //    alert($("#mesto").get()[0].clientWidth);            
            $(window).resize(function(){  
                inner_margin=(($("#header").get()[0].clientWidth - 1050)) ;
                $(".content_bg_position").css("margin-left",inner_margin+"px");
                if($("#header").get()[0].clientWidth <= 1050){  
                    $(".content_bg_position").css("width", "1650px"); 
                }                                   
                else{
                    $(".content_bg_position").css("width", "auto");
                }                
            })                                          
            inner_margin=(($("#header").get()[0].clientWidth - 1050));
            if($("#header").get()[0].clientWidth <= 1050){  
                $(".content_bg_position").css("width", "1650px"); 
            }                                   
            else{
                $(".content_bg_position").css("width", "auto");
            }               
            
            
            $(".content_bg_position").css("margin-left",inner_margin+"px");
        //    alert($(".wrapper_bg_content_second").get()[0].clientWidth+"="+document.documentElement.clientWidth+"+600"); 
        //    alert($(".wrapper_bg_content_second").get()[0].clientWidth+"="+$(".content_bg_position").get()[1].clientWidth+"+"+$(".content_bg_position").css("margin-left")); 
            if($("#header").get()[0].clientWidth <= 1050){
                $(".content_bg_position").css("width", "1650px"); 
            }                                   
            else{
                $(".content_bg_position").css("width", "auto");
            }
            $("#contact_href").click(function(){
                if($(this).hasClass('close_content')){
                    $(".show_contact").fadeIn();                                                                
                    $(".hide_contact").fadeOut();                     
                    $(".wrapper_bg_content").fadeOut(function(){
                        $(".content_contact_block").hide(function(){
                            $("#contact_href").removeClass('close_content');                                                                
                            $(".lang_select_wrapper").css("z-index","1001");                         
                        });     
                    });
                }  
                else{
                    $(".lang_select_wrapper").css("z-index","999");                         
                    $(".content_contact_block").show(function(){
                        $("#contact_href").addClass('close_content');
                        $(".wrapper_bg_content").fadeIn();                                                                
                        $(".show_contact").fadeOut();                                                                
                        $(".hide_contact").fadeIn();                                                                
                    });     
                    
                }    
                $(this).blur();                                                                                               
                return false;
            }) 
     /************************************END CONTACT ROLLDOWN*****************************************************/
    
               
})    