/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Jim Stiles | www.jdstiles.com */
function valorAMult(valor){ 
	var hiddenVal= document.getElementById("hiddenVal"+valor); 
	var cantidad = document.getElementById("cant"+valor); 
	var subtotal = hiddenVal.value*cantidad.value; 
	subtotal = Math.round(subtotal*100)/100;
	document.getElementById("subt"+valor).value=subtotal; 
	return subtotal; 
} 

function descuento(){
	var porcentaje = document.getElementById("hiddenPorcentaje").value * 1; 
	var aplica = document.getElementById("hiddenDesc").value * 1; 
	var valor = document.getElementById("subtotal").value * 1;
	var descuento = (aplica * porcentaje * valor)/100;
	return Math.round(descuento*100)/100;
}

function sumar(){
	var cont=0;
	var campos = pedido.elements.length;

	for (var x=0; x<campos; x++) {
	var campo=pedido.elements[x]
		if (campo.type=="text") {
		for (var y=0;y<campos;y++){
		var nombre = "subt"+y;
			if( campo.name == nombre){
			cont += 1;
			break;
			}
		}
		} 
	} 

	var total = 0;
	for(i=1;i<=cont;i++){
		total+=(document.getElementById("subt"+i).value * 1); 
	}
	return Math.round(total*100)/100;
} 

function baseimp(){
	var subtotal = document.getElementById("subtotal").value * 1; 
	var descuento = document.getElementById("descuento").value * 1;
	var baseimp = (subtotal * 1) - (descuento * 1);
	return Math.round(baseimp*100)/100;
}

function iva(){
	var baseimp = document.getElementById("baseimp").value * 1; 
	var iva = (baseimp * 1) * 0.12;
	return Math.round(iva*100)/100;
}

function total(){
	var baseimp = document.getElementById("baseimp").value * 1; 
	var iva = document.getElementById("iva").value * 1; 
	var total = (baseimp * 1) + (iva * 1);
	return Math.round(total*100)/100;
}

function ponerValor(){ 
	document.getElementById("subtotal").value = sumar(); 
	document.getElementById("descuento").value = descuento(); 
	document.getElementById("baseimp").value = baseimp(); 
	document.getElementById("iva").value = iva(); 
	document.getElementById("total").value = total(); 
}

