var com = com || {};
com.as = com.as || {};

com.as.SendAMail = function(){
    this.init();
};
com.as.SendAMail.prototype = {
    init:function(){
        this.sendMail();    
    },
    sendMail:function(){
        
        $('label.error').hide();
		$("input.button").hover(
		  function () {
			$(this).css('background','url(/wp-content/themes/corinaTheme/image/send.gif) top left');
		  }, 
		  function () {
			$(this).css('background','url(/wp-content/themes/corinaTheme/image/send.gif) bottom left');
		  }
		);
		
        $('input.button').click(function(e){
            $('label.error').hide();
            var name    = $("input#name").val();
                if( name == '' ){
                    $('label.error').show();
                    $('input#name').focus();
                    return false;
                }         		      		
            var email   = $("input#email").val();
                if( email == '' ){
                    $('label.error').show();
                    $('input#email').focus();
                    return false;
                }      		
            var message = $("textarea#message").val();
                if( message == '' ){
                    $('label.error').show();
                    $('textarea#message').focus();
                    return false;
                }
        
            var dataString = $('#form_contact :input:not(input[type=submit])').serialize();
            $.ajax({
                type   : "POST",
                url    : "/wp-content/themes/corinaTheme/js/contact/bin/process.php",
                data   : dataString,
                success : function(date){
                    //$('#result_send_mail').html(date);
                    $('#container_contact #result_send_mail').html("<div id='message'></div>");
                    $('#message').html("<h2>Formulário enviado com sucesso.</h2>")
                       .append("<p>Agradecemos o contato!</p>")
                       .hide().fadeIn(1500);
                },
                error  : function(){
                    $('#container_contact #result_send_mail').html("<div id='message'></div>");
                    $('#message').html("<h2>Contato!</h2>")
                       .append("<p>Tente novamente mais tarde.</p>")
                       .hide().fadeIn(1500);
                }
            });
            
            return false;
        });    
    }
};

