/**
 * @author hollmann
 */

function loadCatalogOrderForm(){
	$.ajax( {url: '/scripts/fh/catalog_order.php', 
			type: 'GET',
			async: false,
			success: 
				function(resp){ 
					$('#catalog_order_wraper').html(resp);
					$('#catalog_order_wraper form').submit( submitCatalogForm );
				}
	});
}

function submitCatalogForm(){
	$('#catalog_order_wraper form #submit').attr('disabled', 'disabled');	
	$('#catalog').block({
			message: '<img src="/fileadmin/fha/template/img/icon_loaderLarge.gif" height="66" width="66" />',
			centerY: false,		
			overlayCSS: {
			backgroundColor: '#FFF',
			fadeIn: 350,
			fadeOut: 100
		},
		css: {
			top: '325px',
			border: '1px solid #AAA'
		}
	}); 
	
	$.post('/scripts/fh/catalog_order.php', 
			$('#catalog_order_wraper form').serialize(),
			function(resp){				
				$('label.error').removeClass('error');
				$('#catalog').unblock();
				if( resp.highlightErrors ){
					$.each( resp.highlightErrors, 
							function(i, tag){
								$('label[for="'+ tag +'"]').addClass('error')
							});
				}
				if( resp.error ){
					//$.fancybox({content: resp.error});
					alert(resp.error);
				}
				else{
					if( resp.redirect_location ){
						window.location = resp.redirect_location;
						return false;
					}
					
					if( resp.success && resp.success == true){
						alert('Vielen Dank für Ihre Bestellung.')
					}
					
					$('#catalog_order_wraper form')[0].reset();
				}
				
				$('#catalog_order_wraper form #submit').attr('disabled', '');
			},
			'json');
	
	return false;
}

$(document).ready(function() {
	if( $('body#page_1573').length > 0 || $('body#page_402').length > 0 )
	{
		loadCatalogOrderForm();
	}
});
