function calc_cantelem(ope,num_elem){
	valor_act=document.form.elements["cant_compra["+num_elem+"]"].value;
	max_cant=document.form.elements["max_cant["+num_elem+"]"].value;

	if(ope=="+"){
		valor_act++
		}else{
			valor_act--;		
			}
	if(valor_act>=0){	
		if(valor_act>max_cant){
			alert("Lo sentimos, no disponemos de tanto stock.\nEste es el número máximo que podemos garantizar.");
			}else{	
				document.form.elements["cant_compra["+num_elem+"]"].value=valor_act;	
				document.getElementById("cant_ped["+num_elem+"]").innerHTML=valor_act;
				if(document.form.elements["coste["+num_elem+"]"]){
					precio=document.form.elements["coste["+num_elem+"]"].value;
					coste=precio*valor_act;
					coste=Math.round(coste*Math.pow(10,2))/Math.pow(10,2);
					coste=Decimales(coste);
					coste_imp=coste+'';
					coste_imp=coste_imp.replace(".",",");
					document.getElementById("span_coste["+num_elem+"]").innerHTML=coste_imp;
					act_coste();
					}
				}
		}
	}
	
function act_coste(){
	coste_total=0;
	
	tabla_pedido=document.getElementById("t_pedido");
	tabla_filas=tabla_pedido.childNodes;	
	for(i=0;i<tabla_filas.length;i++){
		if(tabla_filas[i].tagName=="TBODY")
			tbody_pedido=tabla_filas[i];
		}
		
	tabla_filas=tbody_pedido.childNodes;	
	for(i=0;i<tabla_filas.length;i++){
		if(tabla_filas[i].tagName=="TR"){
			spans=tabla_filas[i].getElementsByTagName("SPAN");
			if(spans.length>1){
				num=spans.length-1;
				coste_fila=spans[num].innerHTML;
				coste_fila=coste_fila.replace(",",".");
				coste_fila=parseFloat(coste_fila);
				coste_total+=coste_fila;
				}
			}
		}
	
	coste_total=Math.round(coste_total*Math.pow(10,2))/Math.pow(10,2);
	coste_total=Decimales(coste_total);
	coste_total=coste_total+'';
	coste_total=coste_total.replace(".",",");
	document.getElementById("coste_tot").innerHTML=coste_total;
	}
	
function borrar_elem(num_elem){
	document.form.elements["cant_compra["+num_elem+"]"].value=0;
	var ref_padre_div=document.getElementById("fila_elem["+num_elem+"]").parentNode;
	ref_padre_div.removeChild(document.getElementById("fila_elem["+num_elem+"]"));

	act_coste();
	}
	
function Decimales(mnt) { 
	mnt -= 0; 
	mnt = (Math.round(mnt*100))/100; 
	return (mnt == Math.floor(mnt))? mnt + '.00' 
	: ( (mnt*10 == Math.floor(mnt*10))? 
	mnt + '0' : mnt); 
	}	
