function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

    function addCommas(nStr)
	{
	  nStr += '';
	  x = nStr.split('.');
	  x1 = x[0];
	  x2 = x.length > 1 ? '.' + x[1] : '';
	  var rgx = /(\d+)(\d{3})/;
	  while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	  }
	  return x1 + x2;
	}

    function calcularEnvioPared(costoenvio){
		var div_gastos2    = document.getElementById("gastos2");
		var gastos2    	  = costoenvio * parseInt(document.f1.destino.value);
		if(gastos2 == 0)
			div_gastos2.innerHTML = "No Incluye";
		else
			div_gastos2.innerHTML = addCommas(gastos2.toFixed(0));
    }
	
    function calcularEnvioTirolesa(subtotal, costokm, visita, iva, costoenvio){
		
		var div_subtotal1 = document.getElementById("subtotal1");
		var div_gastos1    = document.getElementById("gastos1");
		var div_gastos2    = document.getElementById("gastos2");
		var div_subtotal2 = document.getElementById("subtotal2");
		var div_iva       = document.getElementById("iva");
		var div_total     = document.getElementById("total");

		var subtotal1 	  = subtotal;  
		var gastos1    	  = (costokm * parseInt(document.f1.destino.value))+ visita;
		if(gastos1 == visita)
			gastos1 = 0;
		var gastos2    	  = costoenvio * parseInt(document.f1.destino.value);
		var subtotal2	  = (subtotal + gastos1 + gastos2);  
		var total	  	  = subtotal2 * iva;
		var iva	  	  	  = total - subtotal2;

		div_subtotal1.innerHTML  = addCommas(subtotal1.toFixed(0));

		if(gastos1 == 0)
			div_gastos1.innerHTML = "No Incluye";
		else
			div_gastos1.innerHTML = addCommas(gastos1.toFixed(0));

		if(gastos2 == 0)
			div_gastos2.innerHTML = "No Incluye";
		else
			div_gastos2.innerHTML = addCommas(gastos2.toFixed(0));

		div_subtotal2.innerHTML  = addCommas(subtotal2.toFixed(0));
		div_iva.innerHTML        = addCommas(iva.toFixed(0));
		div_total.innerHTML      = addCommas(total.toFixed(0));
    }
