function number_format(number, decimals, dec_point, thousands_sep) {
    number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);            return '' + Math.round(n * k) / k;
        };
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');    }
    return s.join(dec);
}

function meter_carrito(id,accion){
	//jQuery('#productos_'+tipo+' .foto_producto').hide();
	jQuery.ajax({
    	type: 'GET',
        url: "ajax_meter_carrito.php",
        cache: false,
        data: {id : id, accion: accion},
        success: function(data) {
        	precio_total=parseFloat(jQuery('div#precio_total').html());
        	cantidad=parseFloat(jQuery('div#carrito_elemento_cantidad_'+id).html());
        	precio=parseFloat(jQuery('div#carrito_elemento_precio_'+id).html());
        	precio_total=parseFloat(precio_total-precio);
        	precio_unidad=parseFloat(precio/cantidad);
        	jQuery('div#carrito_elemento_cantidad_'+id).html(data);
        	cantidad=parseFloat(jQuery('div#carrito_elemento_cantidad_'+id).html());
        	nuevo_precio=precio_unidad*cantidad;
        	precio_total=parseFloat(precio_total+nuevo_precio);
        	//alert("C:"+cantidad+"P:"+precio+"-PU:"+number_format(precio_unidad,2,',','.')+"NP:"+nuevo_precio);
        	jQuery('div#carrito_elemento_precio_'+id).html(number_format(nuevo_precio,2,',','.'));
        	jQuery('div#precio_total').html(number_format(precio_total,2,',','.'));
		}
    });
}

function continuar_compra(){
	jQuery.ajax({
    	type: 'GET',
        url: "ajax_continuar_compra.php",
        cache: false,
        success: function(data){
			if (data=="1"){
				jQuery('p.error_talla_color').fadeIn(150);
			} else self.location='finalizar';
        }
    });
}

function validar_formulario_compra(f){
	forma_pago=jQuery('#forma_pago').val();
	switch (forma_pago){
		case 'transferencia': { url_action='transferencia'; break; }
		case 'tarjeta': { url_action='javascript:cargar_tpv();'; break; }
		case 'paypal': { url_action='javascript:cargar_tpv();'; break; }
	}
	validar_formulario(f,url_action);
}

function cargar_tpv(){
	//alert('por aqu� cargo la tpv');
	//jQuery("#formulario_datos").attr('target','iframe_tpv');
	//jQuery("#formulario_datos").attr('target','_parent');
	//jQuery("#formulario_datos").attr('action','http://pruebas.pagoseguro.com.es/cgi-bin/totalizacion');
	jQuery("#formulario_datos").attr('action','shop_actualizar_compra.php');
	jQuery('#resumen_compra').hide();
	jQuery('#tpv').show();
	setTimeout("jQuery('#formulario_datos').submit();",100);
}
