/*
@		CONVER v.1.0
@		Noviembre/2010
@		Cointeractivo
@		Ruben Maldonado
@		rbnmm@hotmail.com
*/

function buscar_en () {
   var buscar = $('#buscar').val();
   window.location.href = 'search.php?buscar='+buscar;
}
	
function buscar_es () {
   var buscar = $('#buscar_es').val();
   window.location.href = 'buscar.php?buscar='+buscar;
}


function randomString2() {
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var string_length = 10;
    var randomstring = '';
    for (var i=0; i<string_length; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum,rnum+1);
    }
    return randomstring;
}

function carga_estados(id_pais)
{
	$.ajax({
		url : 'functions/get_estados.php',
		dataType : 'text',
		type: 'post',
		data : 'id_pais='+id_pais,
		success:function(res){
			if(res != ""){
				$('#estadoRegister').html(res);
			}
		},
		error: function(){
			
		}
	});
}



function validaEmail(cadena)

{

	if(/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})/.test(cadena))

		return true;

	else

		return false;

}


function get_distribuidores_filtro(){
	
		var settings = $('.scroll-pane').jScrollPane({
			verticalDragMaxHeight  : 47,
			autoReinitialise: true
		});
		
		var pane = $('.scroll-pane')
		pane.jScrollPane(settings);
		var contentPane = pane.data('jsp').getContentPane();
	
		var opc = $('#distribuidores_filtro').val();
		
		if(opc != -1) {
			$.ajax({
				type:     "post",
				dataType: "text",
				data:     "opc="+opc,
				url:      "functions/distribuidores_filtro.php",
				success:  function(res) {
					if(res != "") {
						contentPane.html(res);
					}
				},
				error:    function() {
					alert("Error:\nEl servidor no responde !");
				}
			});
		}	
	}

$(function() {
	
	
	$('#password').focus(function(){
		$(this).css('background','none');
	});
	
	$('#password').blur(function(){
		if($(this).val() == "")
			$('#password').css('background','url(images/input-password.png) no-repeat -1px 0px');
	});
	
	/************  SELECT   ******************/
	
	$('.custom-select').toggle(function(){
		$('ul.custom-options').remove();
		var $this = $(this);
		var rel   = $this.attr('rel');
		
		var pos   = $this.offset();
		var ul    = '<ul class="custom-options">';
		
			$($this.prev().find('option')).each(function(index){
				//alert($(this).text());
				ul += "<li><a href='#' rel='"+rel+"' title=''>"+$(this).text()+"</a></li>";
			});
			
			ul 	+= '</ul>';
		
		$(ul).appendTo('body').css({
			top: (pos.top+20)+'px',
			left: (pos.left+3)+'px'
		}).css('z-index',20016).show();
		
		if(rel == "numero-paginacion" || rel == "distribuidores_filtro"){
			$('ul.custom-options li a').addClass('background-blue');
		}
		
	},function(){
		$('ul.custom-options').remove();	
	});
	
	$('ul.custom-options li a').live('click',function(){
			var texto   = $(this).text();
			var rel 	= $(this).attr('rel');
			var index 	= $(this).parent().index();
			$('#'+rel+' option:eq('+index+')').attr('selected',true);
			$('#'+rel+'-trigger').text(texto);
			$('ul.custom-options').remove();	
			
			if(rel == "paisRegister"){
				$('#estadoRegister-trigger').text("Estado");
				if($('#paisRegister').val() != -1)
					carga_estados($('#paisRegister').val());
				else {
					$('#estadoRegister').html("<option value='-1'>Estado</option>");					
				}
			}
			else if(rel == "numero-paginacion"){
				genera_paginacion();
			}else if(rel == "distribuidores_filtro"){
				get_distribuidores_filtro();	
			}
				
			
			return false;
	});
	
	
	/****************************************/
	
	
	$('#pedido-table tbody tr td.celda-productos p').hover(function(e){
			var pos = $(this).parent().offset();
			
			$(this).prev().css('margin-top',(pos.top)+'px').stop(true, true).fadeIn();		
		
	},function(e){
		$(this).prev().fadeOut();
	});
	
	$('#header-slides').cycle({
		fx: 'fade' 
	});
	
	///////////// CARGA INFO- ONCHANGE TAMAÑOS - DETALLE-PRODUCTO.PHP
	/*
	$('#tamanioProducto').change(function(){
		var $this = $(this); //objeto
		var id_size     = $this.val(); //valor de tamaño
		var id_producto = $('#idProductoH').val(); //id de producto
		
		if(id_size > 0){
			$.ajax({
				url : 'functions/get_info_product.php',
				data : 'id_size='+id_size+'&id_producto='+id_producto,
				type : 'post',
				dataType : 'json',
				success: function(res){
					$('#idSizeActual').val(id_size);		
					$('#fila1-detalle-producto div.fila1-cdp h5 span').html(res[0].codigo);
					$('.precio-dp').html("$"+res[0].precio);
					$('#btn-agregar-pedido-dp').attr('rel',id_producto+'-'+id_size);
					$('#agregar-pedido-dp-imagen').attr('rel',id_producto+'-'+id_size);
					$('#minimo-ordenar').html("<option value='"+res[0].minimoOrdenar+"'>"+res[0].minimoOrdenar+"</option>");
				},
				error : function(){
					
				}
			});
		}
		
	});
	*/
	////////////
	
	$('#distribuidores_buscar').keyup(function(e) {
		if(e.keyCode == 13) {
			$('#preloader-busqueda').html("<img src='images/loader.gif' alt='' />").show();
			var buscar = $(this).val();
			
			if(buscar != "") {
				$.ajax({
					type:     "post",
					dataType: "text",
					data:     "buscar="+buscar,
					url:      "functions/distribuidores_buscar.php",
					success:  function(res) {
						if(res != "") {
							$('#distribuidores-content').html(res);
							$('#preloader-busqueda').html("");
						}else{
							$('#preloader-busqueda').html("");	
						}
					},
					error:    function() {
						alert("Error:\nEL servidor no responde!");
						$('#preloader-busqueda').html("");
					}
				});
			}
		}
	});
	
	$('#buscar').keyup(function(e) {
		if(e.keyCode == 13) {
		   var buscar = $(this).val();
		   window.location.href = 'search.php?buscar='+buscar;
		}
	});
	$('#buscar_es').keyup(function(e) {
		if(e.keyCode == 13) {
		   var buscar = $(this).val();
		   window.location.href = 'buscar.php?buscar='+buscar;
		}
	});
	/*
	$('#corporativo-menu a').click(function() {
		$('#corporativo-menu a').removeClass('selected');
		
		if($(this).hasClass('children')){
			$('#ul-children').toggle('normal');	
		}else if($(this).hasClass('no-move')){
			var n = 0;
		}else{
			$('#ul-children').slideUp('normal');	
		}
		var archivo =  $(this).attr('href');
		$('#corporativo-content').load('functions/'+archivo);
		$(this).addClass('selected');
		
		return false;
	});
	*/
	
	$('#registrar_mail_oferta').click(function(){
		
		var email = $('#mail_oferta').val();
		if(validaEmail(email)){
			$.ajax({
			url : 'functions/verifcia_correo_repetido2.php',
			type : 'post',
			dataType : 'text',
			data : 'email='+email,
			success: function(res){
				if(parseInt(res) == 1){
					//alert('El email ya ha sido registrado, elige uno diferente');
					alert('Registrado Correctamente');
					$('#mail_oferta').val("@");
				}
				else if(parseInt(res) == 0){
					$.ajax({
						url : 'functions/mail_registro_oferta.php',
						type: 'post',
						dataType: 'text',
						data : 'email='+email,
						success: function(res2){
							if(parseInt(res2) == 1){
							$('#mail_oferta').val("@");
							alert('Registrado Correctamente');
							
							}else{
							alert('Registrado Correctamente');
							}
						}, error: function(){
						alert('Registrado Correctamente');
						}
				   });
					
				}else if(parseInt(res) == 2)
				{
					$('#mail_oferta').val("@");
					alert('Registrado Correctamente');
				}
			},error:function(){
				alert('Registrado Correctamente');	
			}
			});//fin del primer ajax
				
		}else{
			alert('Ingresa un E-mail v\u00E1lido');	
		}
		return false;
	});
	
	$('#contacto-enviar').click(function(){
       
	   $('#warning').html("<img src='images/loader2.gif' alt='' />&nbsp;&nbsp;Enviando Mensaje...");
	   
	   var nombre   = $('#nombre').val();
       var apellido = $('#apellidos').val();
       var email    = $('#email').val();
       var empresa  = $('#empresa').val();
       var mensaje  = $('#mensaje').val();
	   var tel      = $('#tel').val();
	   var lada     = $('#lada').val();
	   var tema		= $('#tema').val();

       var bandera = false;
		
       if(nombre == "" || apellido == "" || validaEmail(email) == false || mensaje == "" || empresa == "" || tel == "" ){
           bandera = false;
       }else{
			bandera = true;   
	   }
	   

       if(bandera){
		  	
           $.ajax({
			   url : 'functions/contacto_send.php',
			   dataType : 'text',
			   type : 'post',
			   data : 'nombre='+nombre+'&apellidos='+apellido+'&email='+email+'&empresa='+empresa+'&mensaje='+mensaje+'&tel='+tel+'&lada='+lada+'&tema='+tema,
			   success : function(res){
				   if(res == 1){
					   $('#warning').html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mensaje Enviado");
					   $('#mensaje').val("Preguntas y/o comentarios");
//					   $('#mensaje').attr("title","");
					   $('#apellido').val("Apellido");
//					   $('#apellido').attr("title","Apellido");
					   $('#email').val("Email");
//					   $('#email').attr("title","Email");
					   $('#nombre').val("Nombre");
//					   $('#nombre').attr("title","Nombre");
						$('#empresa').val("Empresa");
						$('#tel').val("Número");
					   //$('#ciudad option[value=-1]').attr('selected',true); 
				   }
			   },
			   error: function(){
				   $('#warning').html("Error en el servidor");
			   }
		   });
       }else{
           $('#warning').html("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* Debes llenar todos los campos");
       }
       setTimeout("$('#warning').html('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* Debes llenar todos los campos');",15000);
       return false;
    });
	
	$('#contacto-borrar').live('click',function(){
		$('#nombre').val("Nombre");
		$('#apellidos').val("Apellido");
		$('#empresa').val("Empresa");
		$('#email').val("Email");
		$('#tel').val("Número");
		$('#mensaje').val("Preguntas y/o comentarios");
		
		//$('#estador option[value=-1]').attr('selected',true);
		
		return false;
	});
	
	/****************************************************************************************************/
	
	$(window).resize(function(){
		var alto_header = $('#header-padre').height();
		var alto_main = $('#main').height();
		var alto_footer = ($(document).height() - alto_header - alto_main);
		$('#footer').css('height',alto_footer+'px'); 
	});
	
	
	
	//LOGIN
 	$('#show-login-form').click(function(){
		
		//objeto
		var $this = $(this);
		
		//agrega clase de seleccionado al boton
		$this.addClass('selected');
		
		//posiciono el div
		var anchoVentana = $(window).width();
		var altoVentana  = $(window).height();
		var anchoHeader  = $('#header').width();
		
		
		var posicionX = (((anchoVentana - anchoHeader) / 2) + 8);
			
		
		//creo el contenedor del div form login
		$('#form-login-container').css({
			right: posicionX+'px'
		}).slideDown();
		
		//setTimeout('$("#form-login-container").slideUp();',12000);
		
		return false;
	});
	
	/*$("#form-login-container").mouseout(function(){
		$(this).slideUp();
	})*/
	
	$('#close-form-login').click(function(){
		$('#show-login-form').removeClass('selected');
		$("#form-login-container").slideUp();
		return false;
	});
	
	$('#show-register-form, .show-form-register-detail').live('click',function(){
			
			//carga el lightbox
			$('<div class="overlay"></div').appendTo('body').show();
			var docHeight = $(document).height();
			$('.overlay').css('height',docHeight+'px');
			//ancho del navegador
			var anchoVentana = $(window).width();
			var altoVentana  = $(window).height();
			
			//ancho de el formulario
			var anchoForma = $('#form-registro').width();
			var altoForma  = $('#form-registro').height();
			
			//posicion en el body
			var posicionX = ((anchoVentana - anchoForma) / 2);
			var posicionY = ((altoVentana - altoForma) / 2);
			
			$('#form-registro').css({
				marginTop: posicionY+'px',
				marginLeft: posicionX+'px'
			}).show();
			
			
			
			return false;
	});
	
	/*$(window).scroll(function(){
		 $('.overlay').css('top',$(this).scrollTop()+'px');
		//$('#contenedor-registro').css('top',$(this).scrollTop()+'px');
	});*/ 
	
	$('#rememberme').click(function(){
		
			$('#rememberme span').toggle(function(){
				$('#rememberme span').addClass('selected');
				$('#recordarSesion').val("si");
			},function(){
				$('#rememberme span').removeClass('selected');
				$('#recordarSesion').val("no");
			});
			return false;
	});
	
	$('#registrarRegister').live('click',function(){
 //$('#mensaje-registro').html('<img alt="" src="images/loader.gif" />&nbsp;Enviando informaci&oacute;n');

 var bandera = true;
 var mensaje = "";
 
 var cat = $('#categoriaRegister').val();//
 var nom = $('#nombreRegister').val();//
 var ape = $('#apellidoRegister').val();//
 var comp = $('#companyRegister').val();//
 var dir = $('#direccionRegister').val();//
 var em = $('#emailRegister').val();//
 var pa = $('#paisRegister').val();//
 var es = $('#estadoRegister').val();//
 var ci = $('#ciudadRegister').val();//
 var cp = $('#cpRegister').val();//
 var te = $('#telRegister').val();//
 var fa = $('#faxRegister').val();//

 var inte = $('#intereses').val();//
 var pro = $('#productos').val();//
 var men = $('#mensajeRegister').val();//

 if( cat == -1 ){
	 bandera = false;
	mensaje = "Selecciona una categor\u00EDa"; 
 }else if(nom == "" || nom == "Nombre"){
	 mensaje = "Ingresa tu nombre";
	 bandera = false;
 }else if(ape == "" || ape == "Apellido"){
	 mensaje = "Ingresa tu apellido";
	 bandera = false;
 }else if(comp == "" || comp == "Compañia"){
	 bandera = false;
	 mensaje = "Ingresa la compa\u00F1ia";
 }else if(dir == "" || dir == "Dirección"){
	 mensaje = "Ingresa tu direcci\u00F3n";
	 bandera = false;
 }else if(pa == -1){
	 mensaje = "Selecciona un pa\u00EDs";
	 bandera = false;
 }else if(es == -1){
	 mensaje = "Selecciona un estado";
	 bandera = false;
 }else if(ci == "" || ci == "Ciudad"){
	 mensaje = "Ingresa tu ciudad";
	 bandera = false;
 }else if(cp == "" || cp == "C.P."){
	 bandera = false;
	 mensaje = "Ingresa tu c\u00F3digo postal";
 }
 else if(te == "" || te == "Tel."){
	 bandera = false;
	 mensaje = "Ingresa tu Tel\u00E9fono";
 }
 else if(!validaEmail(em)){
	 bandera = false;
	 mensaje = "Ingresa un email v\u00E1lido";
 }
 else if(pro == -1){
	 mensaje = "Selecciona un producto";
	 bandera = false;
 }else if(inte == -1){
 	bandera = false;
// $('#mensaje-registro').html('*Es necesario llenar todos los campos');
	mensaje = "Selecciona un int\u00E9res";
 }
 
 var banderaCorreo = true;
 
$.ajax({
	url :'functions/verifcia_correo_repetido.php',
	dataType : 'text',
	data : 'email='+em,
	type:'post',
	success:function(res){
		if(parseInt(res) == 1)
		{
			//si uno es que existe
			banderaCorreo =  true;
			mensaje = "El correo ya est\u00E1 registrado, ingresa uno diferente";
			alert(mensaje);
		}else
		{//no existe
			banderaCorreo = false;
			if(bandera){
				var verificacion = randomString2();

 $.ajax({
 url:'functions/registrar_us.php',
 type : 'post',
 dataType:'text',
 data: 'categoria='+cat+'&nombre='+nom+'&apellido='+ape+'&company='+comp+'&email='+em+'&direccion='+dir+'&pais='+pa+'&cp='+cp+'&ciudad='+ci+'&estado='+es+'&telefono='+te+'&fax='+fa+'&intereses='+inte+'&productos='+pro+'&mensaje='+men+'&vf='+verificacion,
 success: function(res){
 if(parseInt(res) == 1){
 mensaje = "Registrado Correctamente";
 alert(mensaje);
$('#categoriaRegister option[value=-1]').attr('selected',true);
$('#nombreRegister').val("Nombre");//
$('#apellidoRegister').val("Apellido");//
$('#companyRegister').val("Compa\u00F1ia");//
$('#direccionRegister').val("Dirección");//
$('#emailRegister').val("Email");//
$('#paisRegister option[value=-1]').attr('selected',true);
$('#estadoRegister option[value=-1]').attr('selected',true);
$('#ciudadRegister').val("Ciudad");//
$('#cpRegister').val("C.P.");//
$('#telRegister').val("Tel.");//
$('#faxRegister').val("Fax");//
$('#intereses option[value=-1]').attr('selected',true);
$('#productos option[value=-1]').attr('selected',true);
$('#mensajeRegister').val("Preguntas y/o comentarios");//
 $('.overlay').remove();
 $('#form-registro').css('display','none');
 }
 },
 error: function(){
  mensaje = "Error conectando al servidor";
 }
 });
			}
		}
		
	},error:function(){
		alert('Error conectando al servidor');	
	}
});
 

 /*if(bandera && banderaCorreo == false){
	 
	 

	
 }*/
 if(mensaje != "")
 alert(mensaje);
 return false;
 }); 
	


$('#cerrar-register-form').click(function(){
	$('.overlay').remove();
 	$('#form-registro').css('display','none');
	return false;
});

$('#start-session').click(function(){
	$('#start-session-loader').show();
	var usuario = $('#idUsuario').val();
	var pass    = $('#password').val();
	var recordarSesion = $('#recordarSesion').val();
	
	if(usuario != "" && pass != ""){
		$.ajax({
			url : 'functions/valida.php',
			type : 'post',
			dataType : 'text',
			data : 'u='+usuario+'&p='+pass+'&r='+recordarSesion,
			success: function(res){
					if(res != 0 && res != 2){
						$('#start-session-loader').hide();
						//alert('logueado');	
						$('#form-login-container').slideUp();
						var t = res.split('}');
						$('#login').html("Usuario: <span><b> "+res+"</b></span>");
						$('#nombre-usuario-logueado').html("<span><b> "+res+"</b></span>");
						//objeto
						var $this = $(this);
		
						//posiciono el div
						var anchoVentana = $(window).width();
						var altoVentana  = $(window).height();
						var anchoHeader  = $('#header').width();
		
		
						var posicionX = (((anchoVentana - anchoHeader) / 2) + 8);
			
		
						//creo el contenedor del div form login
						$('#user-panel-container').css({
							right: posicionX+'px'
						}).slideDown('slow');
						
						
						setTimeout('$("#user-panel-container").slideUp();',12000);
					}else if(res == 2){
						$('#start-session-loader').hide();
						//$('<div id="msg-no-autorizado">El ID de Usuario y/o password son incorrectos</div>').appendTo('body').hide.slideDown();
						alert('usuario no autorizado');
					}else {
						$('#start-session-loader').hide();
						alert('El ID de Usuario y/o Password es incorrecto');	
					}
			},
			error: function(){
				$('#start-session-loader').hide();
				alert('Error conectando al servidor');
			}
		});
	}
	else {
		$('#start-session-loader').hide();
		alert('Ingresa los datos correctamente');	
	}
	
	return false;
});

$('#forgot-pasword').click(function(){
	$('#forgot-pasword').slideUp();
	$('#divEmailRec').css('display','bock').slideDown();
	return false;
});

$('#emailRec').keyup(function(e){
	if(e.keyCode == 13) {
		var email = $(this).val();
		if(validaEmail(email)){
			$.ajax({
				url : 'functions/envia_clave.php',
				type : 'post',
				dataType: 'text',
				data : 'email='+email,
				success: function(res){
					if(parseInt(res) == 1){
						alert('La contrase\u00F1a se ha enviado correctamente');
					}else{
						alert('El correo no est\u00E1 registrado');	
					}
				},error: function(){
					alert('Error conectando el servidor');
				}
					
			});
		}else{
			
		}
	}
});


$('#login span').live('click',function(){
	//posiciono el div
	var anchoVentana = $(window).width();
	var altoVentana  = $(window).height();
	var anchoHeader  = $('#header').width();
		
		
	var posicionX = (((anchoVentana - anchoHeader) / 2) + 8);
			
		
	//creo el contenedor del div form login
	$('#user-panel-container').css({
		right: posicionX+'px'
	}).slideDown('slow');
	
	setTimeout('$("#user-panel-container").slideUp();',12000);
	return false;
});
	
	
	/////////// AGREGAR  A PEDIDO
	$('#btn-agregar-pedido-dp').click(function(){
		var button         = $(this);
		$('#msg-add-pedido').remove();
		var id_size        = $('#idSizeActual').val();
		var id_producto    = $('#idProductoH').val();
		var minimo_ordenar = $('#minimo-ordenar').val();
		
		if(/^[0-9]+$/.test(id_size) && /^[0-9]+$/.test(id_producto) && /^[0-9]+$/.test(minimo_ordenar))
		{
			button.hide();
			$('<div id="msg-add-pedido"><img src="images/loader4.gif" alt="" />&nbsp;&nbsp;&nbsp;Guardando...</div>').appendTo('#fila3-detalle-producto:last-child').hide().fadeIn('normal');
			
			
			$.ajax({
				url : './functions/carrito/agregar_producto.php',
				type : 'post',
				dataType : 'text',
				data : 'idProducto='+id_producto+'&idSize='+id_size+'&qtyOrder='+minimo_ordenar,
				success: function(res)
				{
					
					if(res == 1){
						$('#msg-add-pedido').html("<img style='position:relative;top:7px;' src='images/icon_palomita.gif' alt='' />&nbsp;&nbsp;&nbsp;Producto a\u00F1adido al pedido").show();
						button.show();
						setTimeout('$("#msg-add-pedido").remove();',4000);
						
					}else{
						button.show();
					}
					
					
				},
				error : function()
				{
					alert('Error conectando al servidor ...');
					button.show();
				}
			});
		}
		else
		{
			
		}
		
		return false;
	});
	
	
	$('.cantidadOrdenar').keyup(function(){
		var $this 			= $(this);
		var cantidadOrdenar = $this.val();
		var minimoOrdenar   = $this.next().val();
		
		
		
		if(parseInt(cantidadOrdenar) < parseInt(minimoOrdenar))
		{
			
			alert('Cantidad minima a ordenar es de : '+minimoOrdenar);
			
			//$this.val(minimoOrdenar);
		}else if(!(/^[0-9]+$/.test(cantidadOrdenar)))
		{
			$this.val(minimoOrdenar);
		}
	});
	
	$('.delete-producto-pedido').live('click',function(){
		var $this 		= $(this);
		var id    		= $this.attr('rel');
		var total 		= $('#total-productos-pedido').html();
		var totalProSel = $('#filaPP-'+id+' td.subtotal-producto span.subprecio-fp').text();
		if(confirm("Deseas eliminar este producto del pedido ?")){
		$.ajax({
			url : './functions/carrito/eliminar_producto.php',
			type : 'post',
			dataType : 'text',
			data : 'linea='+id,
			success : function(res){
				if(res == 1)
				{
					$('#filaPP-'+id).fadeOut('fast',function(){
						$(this).remove();
					});
					var nTotal = (total - totalProSel);
					$('#total-productos-pedido').html(nTotal);
				}
				else
				{
					alert('Error al eliminar el producto');
				}
			},
			error : function(){
				alert("Error conectando al servidor");
			}
		});
		}
		
		return false;
	});
	
	$('.refrescar-subProPed').click(function(){
		$('#msg-act-pedido').css('display','block');
		var $this  			= $(this);
		var idFila 			= $this.attr('rel');
		var cantidadOrdenar = $('#filaPP-'+idFila+' td input.cantidadOrdenar').val();
		var precioUnitario  = $('#filaPP-'+idFila+' td.precio-PP span.precio-fp').html();
		
		var calculo         = (cantidadOrdenar * precioUnitario);
		
		$('#filaPP-'+idFila+' td.subtotal-producto span.subprecio-fp').html(calculo);
		
		var totalFinal = 0;
		
		//recalculo el total final
		$('td.subtotal-producto span.subprecio-fp').each(function(index){
			totalFinal += parseFloat($(this).html());	
		});
		
		$('#total-productos-pedido').html(totalFinal);
		
		$.ajax({
			url : './functions/carrito/actualizar_producto.php',
			type : 'post',
			dataType : 'text',
			data : 'linea='+idFila+'&cantidad='+cantidadOrdenar,
			success: function(res){
				if(res == 1)
				{
					$('#msg-act-pedido').css('display','none');
				}
				else {
					$('#msg-act-pedido').css('display','none');
					alert('Error al actualizar el pedido');
				}
			},
			error : function(){
				$('#msg-act-pedido').css('display','none');
				alert('Error conectando al servidor');
			}
		});
		
		return false;
	});
	
	
	
	
});


