
	$.ajaxSetup({ 
		scriptCharset: "utf-8" ,
		contentType: "application/x-www-form-urlencoded; charset=UTF-8" 
	});


	// function update mini cart count
	
	function update_mini_cart()
	{
	// hide actual cart count
	
		$('#cesta_cantidad').fadeOut(function(){
			
		// show loading image
		
			$('#cesta_loading_image').fadeIn(function(){

				$('#cesta_cantidad').load($('#cesta_cantidad').attr('url'),null,function(){
					
				// hide loading image
				
					$('#cesta_loading_image').fadeOut(function(){
						
					// show cart count
					
						$('#cesta_cantidad').fadeIn();
					});
				});
			});
		});
	}
	
	
// formulario cesta
	
	$('.ajax_form_cesta_submit').live('click',function(){
	
		var formulario = $('#FormListCesta');
	
	// hide actual ajax_content
	
		$('#ajax_content').fadeOut(function(){
			
		// show loading image
		
			$('#ajax_content_loading_image').fadeIn(function(){

				// ajax call
				$.ajax({
					type: 'post',
					url: formulario.attr('action'),
					data: getAjaxInputs(formulario),
					success: function(data) {
							
					// hide loading image
					
						$('#ajax_content_loading_image').fadeOut(function(){
							
						// show content
						
							$('#ajax_content').html(data).fadeIn();
						});
						
					// update mini cart count
						
						update_mini_cart();
					}
				});
					
			});
		});
		
		return false;
	});


// delete cart element

	$('.ajax_delete_cart_element').live('click',function(){
		
		var link = $(this);
		
		var confirm_ok = true;
		
		if( $(this).attr('confirm') )
		{
			confirm_ok = confirm($(this).attr('confirm'));
		}
		
		if( confirm_ok )
		{
		// hide popup board
		
			$('#popup_window,#popup_board').hide();
			
		// hide actual ajax_content
		
			$('#ajax_content').fadeOut(function(){
				
			// show loading image
			
				$('#ajax_content_loading_image').fadeIn(function(){

					$('#ajax_content').load(link.attr('href'),null,function(){
						
					// hide loading image
					
						$('#ajax_content_loading_image').fadeOut(function(){
							
						// show content
						
							$('#ajax_content').fadeIn();
						});
					});
					
				// update mini cart count
					
					update_mini_cart();
				});
			});
		}
		
		return false;
	});
	
// cesta: enlaces incrementar cantidad

	$('.cesta_cantidad_mas').live('click',function(){
		
		var input = $(this).parent().find(':text');

		if( input.val() <= 999) {
			input.val( parseInt(input.val()) + 1 );
		}
		
		return false;
	});

// cesta: enlaces decrementar cantidad

	$('.cesta_cantidad_menos').live('click',function(){
		
		var input = $(this).parent().find(':text');
		
		if( input.val() > 0 ) {
			input.val( parseInt(input.val()) - 1 );
		}
		
		return false;
	});

	
// formulario pago/envio
	
	$('.ajax_pago_envio').live('click',function(){
	
		var formulario = $('#FormPagoEnvio');
		
	// comprobamos el campo 'igual que los datos de envio'

		if( formulario.find('#payment_same_as_ship').is(':checked') )
		{		
			$('[name=payment_name]').val( $('[name=ship_name]').val() );
			$('[name=payment_dni]').val( $('[name=ship_dni]').val() );
			$('[name=payment_address]').val( $('[name=ship_address]').val() );
			$('[name=payment_urbanization]').val( $('[name=ship_urbanization]').val() );
			$('[name=payment_city]').val( $('[name=ship_city]').val() );
			$('[name=payment_country]').val( $('[name=ship_country]').val() );
			$('[name=payment_zip]').val( $('[name=ship_zip]').val() );
			$('[name=payment_province]').val( $('[name=ship_province]').val() );
			$('[name=payment_phone_1]').val( $('[name=ship_phone_1]').val() );
			$('[name=payment_phone_2]').val( $('[name=ship_phone_2]').val() );
		}
		
	// check campos obligatorios

		if( checkCamposObligatorios(formulario.attr('id'), formulario.find('#msg_campos_obligatorios').val()) )
		{
		// hide actual ajax_content

			$('#ajax_content').fadeOut(function(){
				
			// show loading image
			
				$('#ajax_content_loading_image').fadeIn(function(){

					// ajax call
					$.ajax({
						type: 'post',
						url: formulario.attr('action'),
						data: getAjaxInputs(formulario),
						success: function(data) {
								
						// hide loading image
						
							$('#ajax_content_loading_image').fadeOut(function(){
								
							// show content
							
								$('#ajax_content').html(data).fadeIn();
							});
						}
					});
						
				});
			});
		}
		
		return false;
	});

// copiar los datos de envio a los de pago

	$('#payment_same_as_ship').live('click',function(){
		
		check_payment_same_as_ship();
	});
	
	
	function check_payment_same_as_ship()
	{
		if( $('#payment_same_as_ship').is(':checked') ) {
			
		// empty and disable all fields but this
		
			$('#FormPagoEnvio [name^=payment_]').not('#payment_same_as_ship').val('').attr('disabled','disabled');
			
		} else {
			
		// enable fields
		
			$('#FormPagoEnvio [name^=payment_][disabled]').removeAttr('disabled');
		}
	}