//////////

function P1compra(numero){document.frmpedido.P1.value = produto[numero];}
function P2compra(numero){document.frmpedido.P2.value = produto[numero];}
function P3compra(numero){document.frmpedido.P3.value = produto[numero];}
function P4compra(numero){document.frmpedido.P4.value = produto[numero];}
function P5compra(numero){document.frmpedido.P5.value = produto[numero];}

function Valor(item){
	
	if(isNaN(item) || item ==""){
	return 0;
	} else {
	return eval(item);
	}
	
}

function P1_SomaLinha(){

	P1_n1 = Valor(document.frmpedido.P1N33.value);
	P1_n2 = Valor(document.frmpedido.P1N34.value);
	P1_n3 = Valor(document.frmpedido.P1N35.value);
	P1_n4 = Valor(document.frmpedido.P1N36.value);
	P1_n5 = Valor(document.frmpedido.P1N37.value);
	P1_n6 = Valor(document.frmpedido.P1N38.value);
	P1_n7 = Valor(document.frmpedido.P1N39.value);	
	P1_n8 = Valor(document.frmpedido.P1N40.value);
	P1_n9 = Valor(document.frmpedido.P1N41.value);
	P1_n10 = Valor(document.frmpedido.P1N42.value);
	P1_n11 = Valor(document.frmpedido.P1N43.value);
	P1_n12 = Valor(document.frmpedido.P1N44.value);
	P1_n13 = Valor(document.frmpedido.P1N45.value);
							
	P1_total = (P1_n1)+ (P1_n2)+ (P1_n3)+ (P1_n4)+ (P1_n5)+ (P1_n6)+ (P1_n7)+ (P1_n8)+ (P1_n9)+ (P1_n10)+ (P1_n11)+ (P1_n12)+ (P1_n13);
	
	return P1_total;
}

function P1_SomaTudo(){
	var precoP1, quantidadeP1;
	precoP1 = Valor(document.frmpedido.P1_T2.value);
	quantidadeP1 = P1_SomaLinha();
	document.frmpedido.P1_T.value = (P1_SomaLinha());
	document.frmpedido.P1_T2.value = (document.frmpedido.P1_T2.value);	
	document.frmpedido.P1_T2.value = (document.frmpedido.P1_T2.value);
	document.frmpedido.P1_T3.value = (precoP1*quantidadeP1);
	document.frmpedido.PARES.value = (TotalDePares());		
	document.frmpedido.TOTAL.value = (SomaTotal());
	Formata();
}

/// P2

function P2_SomaLinha(){

	P2_n1 = Valor(document.frmpedido.P2N33.value);
	P2_n2 = Valor(document.frmpedido.P2N34.value);
	P2_n3 = Valor(document.frmpedido.P2N35.value);
	P2_n4 = Valor(document.frmpedido.P2N36.value);
	P2_n5 = Valor(document.frmpedido.P2N37.value);
	P2_n6 = Valor(document.frmpedido.P2N38.value);
	P2_n7 = Valor(document.frmpedido.P2N39.value);	
	P2_n8 = Valor(document.frmpedido.P2N40.value);
	P2_n9 = Valor(document.frmpedido.P2N41.value);
	P2_n10 = Valor(document.frmpedido.P2N42.value);
	P2_n11 = Valor(document.frmpedido.P2N43.value);
	P2_n12 = Valor(document.frmpedido.P2N44.value);
	P2_n13 = Valor(document.frmpedido.P2N45.value);
							
	P2_total = (P2_n1)+ (P2_n2)+ (P2_n3)+ (P2_n4)+ (P2_n5)+ (P2_n6)+ (P2_n7)+ (P2_n8)+ (P2_n9)+ (P2_n10)+ (P2_n11)+ (P2_n12)+ (P2_n13);
	
	return P2_total;
}

function P2_SomaTudo(){
	var precoP2, quantidadeP2;
	precoP2 = Valor(document.frmpedido.P2_T2.value);
	quantidadeP2 = P2_SomaLinha();
	document.frmpedido.P2_T.value = (P2_SomaLinha());
	document.frmpedido.P2_T2.value = (document.frmpedido.P2_T2.value);
	document.frmpedido.P2_T3.value = (precoP2*quantidadeP2);
	document.frmpedido.PARES.value = (TotalDePares());		
	document.frmpedido.TOTAL.value = (SomaTotal());
	Formata();
}

// P3

function P3_SomaLinha(){

	P3_n1 = Valor(document.frmpedido.P3N33.value);
	P3_n2 = Valor(document.frmpedido.P3N34.value);
	P3_n3 = Valor(document.frmpedido.P3N35.value);
	P3_n4 = Valor(document.frmpedido.P3N36.value);
	P3_n5 = Valor(document.frmpedido.P3N37.value);
	P3_n6 = Valor(document.frmpedido.P3N38.value);
	P3_n7 = Valor(document.frmpedido.P3N39.value);	
	P3_n8 = Valor(document.frmpedido.P3N40.value);
	P3_n9 = Valor(document.frmpedido.P3N41.value);
	P3_n10 = Valor(document.frmpedido.P3N42.value);
	P3_n11 = Valor(document.frmpedido.P3N43.value);
	P3_n12 = Valor(document.frmpedido.P3N44.value);
	P3_n13 = Valor(document.frmpedido.P3N45.value);
							
	P3_total = (P3_n1)+ (P3_n2)+ (P3_n3)+ (P3_n4)+ (P3_n5)+ (P3_n6)+ (P3_n7)+ (P3_n8)+ (P3_n9)+ (P3_n10)+ (P3_n11)+ (P3_n12)+ (P3_n13);
	
	return P3_total;
}

function P3_SomaTudo(){
	var precoP3, quantidadeP3;
	precoP3 = Valor(document.frmpedido.P3_T2.value);
	quantidadeP3 = P3_SomaLinha();
	document.frmpedido.P3_T.value = (P3_SomaLinha());
	document.frmpedido.P3_T2.value = (document.frmpedido.P3_T2.value);
	document.frmpedido.P3_T3.value = (precoP3*quantidadeP3);
	document.frmpedido.PARES.value = (TotalDePares());		
	document.frmpedido.TOTAL.value = (SomaTotal());
	Formata();
}

// P4

function P4_SomaLinha(){

	P4_n1 = Valor(document.frmpedido.P4N33.value);
	P4_n2 = Valor(document.frmpedido.P4N34.value);
	P4_n3 = Valor(document.frmpedido.P4N35.value);
	P4_n4 = Valor(document.frmpedido.P4N36.value);
	P4_n5 = Valor(document.frmpedido.P4N37.value);
	P4_n6 = Valor(document.frmpedido.P4N38.value);
	P4_n7 = Valor(document.frmpedido.P4N39.value);	
	P4_n8 = Valor(document.frmpedido.P4N40.value);
	P4_n9 = Valor(document.frmpedido.P4N41.value);
	P4_n10 = Valor(document.frmpedido.P4N42.value);
	P4_n11 = Valor(document.frmpedido.P4N43.value);
	P4_n12 = Valor(document.frmpedido.P4N44.value);
	P4_n13 = Valor(document.frmpedido.P4N45.value);
							
	P4_total = (P4_n1)+ (P4_n2)+ (P4_n3)+ (P4_n4)+ (P4_n5)+ (P4_n6)+ (P4_n7)+ (P4_n8)+ (P4_n9)+ (P4_n10)+ (P4_n11)+ (P4_n12)+ (P4_n13);
	
	return P4_total;
}

function P4_SomaTudo(){
	var precoP4, quantidadeP4;
	precoP4 = Valor(document.frmpedido.P4_T2.value);
	quantidadeP4 = P4_SomaLinha();
	document.frmpedido.P4_T.value = (P4_SomaLinha());
	document.frmpedido.P4_T2.value = (document.frmpedido.P4_T2.value);
	document.frmpedido.P4_T3.value = (precoP4*quantidadeP4);
	document.frmpedido.PARES.value = (TotalDePares());		
	document.frmpedido.TOTAL.value = (SomaTotal());
	Formata();
}

// P5

function P5_SomaLinha(){

	P5_n1 = Valor(document.frmpedido.P5N33.value);
	P5_n2 = Valor(document.frmpedido.P5N34.value);
	P5_n3 = Valor(document.frmpedido.P5N35.value);
	P5_n4 = Valor(document.frmpedido.P5N36.value);
	P5_n5 = Valor(document.frmpedido.P5N37.value);
	P5_n6 = Valor(document.frmpedido.P5N38.value);
	P5_n7 = Valor(document.frmpedido.P5N39.value);	
	P5_n8 = Valor(document.frmpedido.P5N40.value);
	P5_n9 = Valor(document.frmpedido.P5N41.value);
	P5_n10 = Valor(document.frmpedido.P5N42.value);
	P5_n11 = Valor(document.frmpedido.P5N43.value);
	P5_n12 = Valor(document.frmpedido.P5N44.value);
	P5_n13 = Valor(document.frmpedido.P5N45.value);
							
	P5_total = (P5_n1)+ (P5_n2)+ (P5_n3)+ (P5_n4)+ (P5_n5)+ (P5_n6)+ (P5_n7)+ (P5_n8)+ (P5_n9)+ (P5_n10)+ (P5_n11)+ (P5_n12)+ (P5_n13);
	
	return P5_total;
}

function P5_SomaTudo(){
	var precoP5, quantidadeP5;
	precoP5 = Valor(document.frmpedido.P5_T2.value);
	quantidadeP5 = P5_SomaLinha();
	t5 = precoP5*quantidadeP5;
	document.frmpedido.P5_T.value = (P5_SomaLinha());
	document.frmpedido.P5_T2.value = (document.frmpedido.P5_T2.value);
	document.frmpedido.P5_T3.value = (precoP5*quantidadeP5);
	document.frmpedido.PARES.value = (TotalDePares());	
	document.frmpedido.TOTAL.value = (SomaTotal());
	Formata();
}
function somaP1(){
	precoP1 = Valor(document.frmpedido.P1_T2.value);
	quantidadeP1 = P1_SomaLinha();
	t1 = precoP1*quantidadeP1;
	return t1;
}
function somaP2(){
	precoP2 = Valor(document.frmpedido.P2_T2.value);
	quantidadeP2 = P2_SomaLinha();
	t2 = precoP2*quantidadeP2;
	return t2;
}
function somaP3(){
	precoP3 = Valor(document.frmpedido.P3_T2.value);
	quantidadeP3 = P3_SomaLinha();
	t3 = precoP3*quantidadeP3;
	return t3;
}
function somaP4(){
	precoP4 = Valor(document.frmpedido.P4_T2.value);
	quantidadeP4 = P4_SomaLinha();
	t4 = precoP4*quantidadeP4;
	return t4;
}
function somaP5(){
	precoP5 = Valor(document.frmpedido.P5_T2.value);
	quantidadeP5 = P5_SomaLinha();
	t5 = precoP5*quantidadeP5;
	return t5;
}
function SomaTotal(){
	return (somaP1() + somaP2() + somaP3() + somaP4() + somaP5());
}
function TotalDePares(){
	return (Valor(P1_SomaLinha())+ Valor(P2_SomaLinha())+Valor(P3_SomaLinha())+Valor(P4_SomaLinha())+ Valor(P5_SomaLinha()));
}
function Formata(){
	
	document.frmpedido.P1_T2.value = formatCurrency(document.frmpedido.P1_T2.value)	;		
	document.frmpedido.P1_T3.value = formatCurrency(document.frmpedido.P1_T3.value)	;		

	document.frmpedido.P2_T2.value = formatCurrency(document.frmpedido.P2_T2.value)	;		
	document.frmpedido.P2_T3.value = formatCurrency(document.frmpedido.P2_T3.value)	;		

	document.frmpedido.P3_T2.value = formatCurrency(document.frmpedido.P3_T2.value)	;		
	document.frmpedido.P3_T3.value = formatCurrency(document.frmpedido.P3_T3.value)	;		

	document.frmpedido.P4_T2.value = formatCurrency(document.frmpedido.P4_T2.value)	;		
	document.frmpedido.P4_T3.value = formatCurrency(document.frmpedido.P4_T3.value)	;		

	document.frmpedido.P5_T2.value = formatCurrency(document.frmpedido.P5_T2.value)	;		
	document.frmpedido.P5_T3.value = formatCurrency(document.frmpedido.P5_T3.value)	;
	
	document.frmpedido.TOTAL.value = formatCurrency(document.frmpedido.TOTAL.value)	;
}

