// Calcular coste del pedido

function calcular_coste(tomo,problemas,programacion,forma_pago,destino_peninsula)
 {
  var total = 0
  var peso = 0
  var iva = 0
  var iva_red = "0"
  var gastos_envio = 0
  var gastos_envio_red
  var total_iva_envio
  var total_iva_envio_red
  var i, j=0
  var detalle_tomo = new Array("","","","")
  var tomo_seleccionado = false
  var num_productos = 0
  var texto
  var resultado = new Array()
  
  for(i=0; i<tomos; i++) 
   if(tomo[i])
    {
	 tomo_seleccionado = true;
	 num_productos++;
	 total += precio_tomo[i];
	 detalle_tomo[i] = " " + "Tomo " + (i+1) + " (" + precio_tomo[i] + "€),";
	 peso += peso_tomo[i];
	} 
  if(problemas) 
   {
    num_productos++;
    total += precio_problemas;
	peso += peso_problemas;
   }	
  if(programacion) 
   {
    num_productos++;
    total += precio_programacion;
	peso += peso_programacion;
   }
  if(num_productos>0) 
   {
	resultado[0] = redondear(total); 
    iva = tanto_iva*total; 
    iva_red = redondear(iva);
    resultado[1] = iva_red;
    peso += peso_embalaje;
	if(destino_peninsula)
	 {
	  if(peso<=1000) gastos_envio = tarifa_1kg_P;
	  else if (peso<=2000) gastos_envio = tarifa_2kg_P;
	  else if (peso<=5000) gastos_envio = tarifa_5kg_P;  
	 }
	else
	 {
	  if(peso<=1000) gastos_envio = tarifa_1kg_C;
	  else if (peso<=2000) gastos_envio = tarifa_2kg_C;
	  else if (peso<=5000) gastos_envio = tarifa_5kg_C; 
	 }
	if(forma_pago==contrareembolso) gastos_envio += precio_embalaje + contrareembolso + fijo_giro + coeficiente_giro*(total+iva+gastos_envio);
	if(forma_pago==ingreso_transferencia) gastos_envio += precio_embalaje + aviso_recibo;
   }	
   
  gastos_envio_red = redondear(gastos_envio);
  resultado[2] = gastos_envio_red; 
  total_iva_envio = total + iva + gastos_envio;
  total_iva_envio_red = redondear(total_iva_envio);
  resultado[3] = total_iva_envio_red;
  
  texto = "<center><b><font size=3 color=blue>Detalles del pedido</font></b></center><br><hr>" ;
  texto += "<table border=0><tr valign=Top><td valign=Top width=1000><b>";
  if(tomo_seleccionado) 
   {
	texto += "<br><br>- Tomos (temario específico): <font color='#330099'>";
	for(i=0; i<tomos; i++) texto += detalle_tomo[i];
	texto += "</font>"; 
   } 
  if(problemas) 
   texto += "<br><br>- Problemas de oposiciones. Nuevas resoluciones: <font color='#330099'>" + precio_problemas + " €</font>";
  if(programacion) 
   texto += "<br><br>- Programación y unidades didácticas: <font color='#330099'>" + precio_programacion + " €</font>";
  texto += "</b></td></tr></table><hr><b><br>";
  texto += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  texto += "<font color=red>Total:</font><font color='#330099'>" + "       " + total + " €</font><br>";
  texto += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  texto += "<font color=red>IVA ("+(tanto_iva*100)+"%):</font><font color='#330099'>" + "       " + iva_red + " €</font><br>";
  texto += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  texto += "<font color=red>(*)Gastos de envío:</font><font color='#330099'>" + "       " + gastos_envio_red + " €</font><br>";
  texto += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  texto += "<font color=red>Coste Total:</font><font color='#330099'>" + "       " + total_iva_envio_red + " €</font></br>";
  texto += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  if(forma_pago==contrareembolso)  texto += "<font size=1>" + conceptos_envio_contrareembolso + "</font></b>";
  if(forma_pago==ingreso_transferencia) texto += "<font size=1>" + conceptos_envio_ingreso + "</font></b>";
  resultado[4] = texto;
  return(resultado);
 }