/**
 * @author Thomas Layh <thomas@layh.com>
 */

var phonecalc = {
	
	ajaxLoadingGif: '#ajaxLoadingGif',
	submitButton: '#phoneCalcSubmit',
	formData: '#phonecalcform',
	resultContainer: '#resultContainer',
	
	init: function () {
		if($(phonecalc.submitButton)) {
			$(phonecalc.submitButton).click(
				function () {
					phonecalc.submitForm();
					return false;
				}
			);
		}
	},
	
	submitForm: function () {
		var data = $(phonecalc.formData).serialize();
		
		$(phonecalc.ajaxLoadingGif).attr('style', '');
		
		$.ajax({
			type: "POST",
			data: data,
			url: tx_tlphonecalc_default_ajaxCalcPhone,
			success: function(msg){
				$(phonecalc.resultContainer).replaceWith(msg);
				$(phonecalc.resultContainer).attr('style', '');
				$(phonecalc.ajaxLoadingGif).attr('style', 'display:none;');
			}
		});
		
	}
	
}

$(document).ready(function() {
	phonecalc.init();
});
