jQuery(document).ready(function(){
    $('#contactForm').submit(function(){


  function Box(){
      this.error = function(el){$(el + 'Error').slideDown('slow');};
      this.hide = function(el){$(el).slideUp('slow');};
      this.sucess = function(){$('#sucess').slideDown('slow');}
      this.fail = function(){$('#error').slideDown('slow')}
    }

  function Validate(){
        this.errors = 0;
        this.Trim = function(str){
            return str.replace(/^\s+|\s+$/g,"");
        }
        this.email = function(str){
            return (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str));
        }
        this.isEmpty = function(str){
            return this.Trim(str).length == 0;
        }
    }

  function Element(){
      this.email = $('#email').val();
      this.name = $('#name').val();
      this.subject = $('#subject').val();
      this.message = $('#message').val();
      /* clear form on sucess */
      this.clean = function(){
          $('#email').val('');
          $('#name').val('');
          $('#subject').val('');
          $('#message').val('');
      }
  }

  var Validate = new Validate();
  var Box = new Box();
  var Element = new Element;

  Box.hide('.warning,.error,.sucess');
     var errors = 0;
     var action = $(this).attr('action');

         if(!Validate.email(Element.email)){
         Box.error('#email')
         errors++

     }
        if(Validate.isEmpty(Element.name)){
            Box.error('#name');
            errors++
        } 
        if(Validate.isEmpty(Element.message)){
         Box.error('#message');
            errors++
        }
        if(!errors){
            $('#ajax_loader').ajaxStart(function(){
                $(this).show();
                $('#send').hide();
            })
            $('#ajax_loader').ajaxStop(function(){
                $(this).hide();
                $('#send').show();
            })

        var data = {
            email: Element.email,
            name: Element.name,
            subject: Element.subject,
            message: Element.message
        };

        var $ajaxCallBack = function(data){
            if(data == 'Sucess!'){
                Box.sucess();
                //Element.clean();
                }
            else 
                Box.fail();           
        }
        $.post(action, data, $ajaxCallBack);
        }
            return false;
    })
})