$(document).ready(function(){
	
    initAjaxForm();
	
	$('#submit-form').click(function(){
		$('#send-form').submit();
		return false;
	});
	
	$('#reset-form').click(function(){
		document.getElementById('send-form').reset();
		return false;
	});
	
});

function initAjaxForm(){

		$('#send-form').submit(function(){
		var form = $(this);
		var formData = $(this).serialize();
		var error = '';
        
        $('#error').slideUp('normal');
            $.ajax({
                type: 'POST', url: form.attr('action'), data: formData, 
                success: function ( responseData ){
                    if((error = Process(responseData)) != ''){
                        $('#error').html(error);
                        $('#error').css('color','#FF0000');
                        $('#error').slideDown('normal');
                    } else{
                        document.getElementById('send-form').reset();
                        $('#error').html('Thank You for your email!');
                        $('#error').css('color','green');
                        $('#error').slideDown('normal');
						$('#send-form').slideUp('normal');
                        //setTimeout("$('#error').slideUp('normal')", 5000);
                    }
                }
        });		
        
		return false;
	});
}

function Process(str){
	list = str.split(':');
	if(list[0].toLowerCase() != 'done'){
		return list[1];
	} else {
		return '';
	}
}