var t = null;
var s = null;

function confirma() {

if (test2.refeicao.value=="" ) {alert ("Escolha uma refeição.")}
else
if (test2.pto1.value=="" ) {alert ("Inclua alimentos na sua lista.")}
else
if (confirm ("Você irá salvar os registros do dia " + diet.dia.value + "/" + diet.mes.value + "/" + diet.ano.value + " para " + test2.refeicao.value + ". \n" + "Prosseguir?"))
{atualiza(); document.diet.submit(); test.sel.focus();}
else
{return false;test.sel.focus();} }
function atualiza(){
	
        
        diet.alimento.value=test2.alim1.value;
        diet.ponto.value=test2.pto1.value;
		diet.trans.value=test2.trans1.value;
        diet.alimento2.value=test2.alim2.value;
        diet.ponto2.value=test2.pto2.value;
		diet.trans2.value=test2.trans2.value;
        diet.alimento3.value=test2.alim3.value;
        diet.ponto3.value=test2.pto3.value;
		diet.trans3.value=test2.trans3.value;
        diet.alimento4.value=test2.alim4.value;
        diet.ponto4.value=test2.pto4.value;
		diet.trans4.value=test2.trans4.value;
        diet.alimento5.value=test2.alim5.value;
        diet.ponto5.value=test2.pto5.value;
		diet.trans5.value=test2.trans5.value;
        diet.alimento6.value=test2.alim6.value;
        diet.ponto6.value=test2.pto6.value;
		diet.trans6.value=test2.trans6.value;
        diet.alimento7.value=test2.alim7.value;
        diet.ponto7.value=test2.pto7.value;
		diet.trans7.value=test2.trans7.value;
        diet.alimento8.value=test2.alim8.value;
        diet.ponto8.value=test2.pto8.value;
		diet.trans8.value=test2.trans8.value;
        diet.alimento9.value=test2.alim9.value;
        diet.ponto9.value=test2.pto9.value;
		diet.trans9.value=test2.trans9.value;
        diet.alimento10.value=test2.alim10.value;
        diet.ponto10.value=test2.pto10.value;
		diet.trans10.value=test2.trans10.value;
		diet.horarefeicao.value=test2.refeicao.value;
		
}
function calcula_pontos(){

        test2.subtotal.value = Math.round(test2.pontos.value*test2.quantidade.value);
		test2.subtotalT.value = test2.trans.value*test2.quantidade.value;

            }

function calcula_total(){
	
        test2.subtotal.value = Math.round(test2.pontos.value*test2.quantidade.value);
	    test2.subtotalT.value = test2.trans.value*test2.quantidade.value;

    }   

function acumula_pontos(){
        
        if (test2.pto1.value==""){test2.pto1.value=0; test2.alim1.value="--->"}
        if (test2.pto2.value==""){test2.pto2.value=0; test2.alim2.value="--->"}
        if (test2.pto3.value==""){test2.pto3.value=0; test2.alim3.value="--->"}
        if (test2.pto4.value==""){test2.pto4.value=0; test2.alim4.value="--->"}
        if (test2.pto5.value==""){test2.pto5.value=0; test2.alim5.value="--->"}
        if (test2.pto6.value==""){test2.pto6.value=0; test2.alim6.value="--->"}
        if (test2.pto7.value==""){test2.pto7.value=0; test2.alim7.value="--->"}
        if (test2.pto8.value==""){test2.pto8.value=0; test2.alim8.value="--->"}
        if (test2.pto9.value==""){test2.pto9.value=0; test2.alim9.value="--->"}
        if (test2.pto10.value==""){test2.pto10.value=0; test2.alim10.value="--->"}
		
		if (test2.trans1.value==""){test2.trans1.value=0; test2.alim1.value="--->"}
        if (test2.trans2.value==""){test2.trans2.value=0; test2.alim2.value="--->"}
        if (test2.trans3.value==""){test2.trans3.value=0; test2.alim3.value="--->"}
        if (test2.trans4.value==""){test2.trans4.value=0; test2.alim4.value="--->"}
        if (test2.trans5.value==""){test2.trans5.value=0; test2.alim5.value="--->"}
        if (test2.trans6.value==""){test2.trans6.value=0; test2.alim6.value="--->"}
        if (test2.trans7.value==""){test2.trans7.value=0; test2.alim7.value="--->"}
        if (test2.trans8.value==""){test2.trans8.value=0; test2.alim8.value="--->"}
        if (test2.trans9.value==""){test2.trans9.value=0; test2.alim9.value="--->"}
        if (test2.trans10.value==""){test2.trans10.value=0; test2.alim10.value="--->"}
		
        
        test2.total.value = eval(test2.pto1.value) + eval(test2.pto2.value) + eval(test2.pto3.value) + eval(test2.pto4.value) + eval(test2.pto5.value) + eval(test2.pto6.value) + eval(test2.pto7.value) + eval(test2.pto8.value) + eval(test2.pto9.value) + eval(test2.pto10.value);
        test2.totalT.value = eval(test2.trans1.value) + eval(test2.trans2.value) + eval(test2.trans3.value) + eval(test2.trans4.value) + eval(test2.trans5.value) + eval(test2.trans6.value) + eval(test2.trans7.value) + eval(test2.trans8.value) + eval(test2.trans9.value) + eval(test2.trans10.value);    
	    diet.totaldia.value = eval(test2.total.value) 
		diet.totaldiaT.value = eval(test2.totalT.value)
		diet.tot_dia.value = diet.totaldia.value
		diet.tot_diaT.value = diet.totaldiaT.value
    }   

function excluir_alimALL(){
        
        {test2.pto1.value=0; test2.alim1.value="--->"; 
test2.pto2.value=0; test2.alim2.value="--->";
test2.pto3.value=0; test2.alim3.value="--->";
test2.pto4.value=0; test2.alim4.value="--->";
test2.pto5.value=0; test2.alim5.value="--->";
test2.pto6.value=0; test2.alim6.value="--->";
test2.pto7.value=0; test2.alim7.value="--->";
test2.pto8.value=0; test2.alim8.value="--->";
test2.pto9.value=0; test2.alim9.value="--->";
test2.pto10.value=0; test2.alim10.value="--->"; 
  acumula_pontos();}      
   }    

function excluir_alim1(){
        
        if (test2.pto1.value!="")
		if (test2.trans1.value!="")
        {test2.pto1.value=test2.pto2.value; test2.alim1.value=test2.alim2.value;
		test2.trans1.value=test2.trans2.value; test2.alim1.value=test2.alim2.value;
test2.pto2.value=test2.pto3.value; test2.alim2.value=test2.alim3.value;
        test2.trans2.value=test2.trans3.value; test2.alim2.value=test2.alim3.value;
test2.pto3.value=test2.pto4.value; test2.alim3.value=test2.alim4.value;  
        test2.trans3.value=test2.trans4.value; test2.alim3.value=test2.alim4.value;
test2.pto4.value=test2.pto5.value; test2.alim4.value=test2.alim5.value;  
        test2.trans4.value=test2.trans5.value; test2.alim4.value=test2.alim5.value; 
test2.pto5.value=test2.pto6.value; test2.alim5.value=test2.alim6.value;   
        test2.trans5.value=test2.trans6.value; test2.alim5.value=test2.alim6.value; 
test2.pto6.value=test2.pto7.value; test2.alim6.value=test2.alim7.value;  
        test2.trans6.value=test2.trans7.value; test2.alim6.value=test2.alim7.value; 
test2.pto7.value=test2.pto8.value; test2.alim7.value=test2.alim8.value;
        test2.trans7.value=test2.trans8.value; test2.alim7.value=test2.alim8.value;
test2.pto8.value=test2.pto9.value; test2.alim8.value=test2.alim9.value;
        test2.trans8.value=test2.trans9.value; test2.alim8.value=test2.alim9.value;
test2.pto9.value=test2.pto10.value; test2.alim9.value=test2.alim10.value;
        test2.trans9.value=test2.trans10.value; test2.alim9.value=test2.alim10.value;
test2.pto10.value=0; test2.alim10.value="--->"; 
        test2.trans10.value=0; test2.alim10.value="--->"
 acumula_pontos();}      
   }    

function excluir_alim2(){
        
       if (test2.pto2.value!="")
		if (test2.trans2.value!="")
        {test2.pto2.value=test2.pto3.value; test2.alim2.value=test2.alim3.value;
        test2.trans2.value=test2.trans3.value; test2.alim2.value=test2.alim3.value;
test2.pto3.value=test2.pto4.value; test2.alim3.value=test2.alim4.value;  
        test2.trans3.value=test2.trans4.value; test2.alim3.value=test2.alim4.value;
test2.pto4.value=test2.pto5.value; test2.alim4.value=test2.alim5.value;  
        test2.trans4.value=test2.trans5.value; test2.alim4.value=test2.alim5.value; 
test2.pto5.value=test2.pto6.value; test2.alim5.value=test2.alim6.value;   
        test2.trans5.value=test2.trans6.value; test2.alim5.value=test2.alim6.value; 
test2.pto6.value=test2.pto7.value; test2.alim6.value=test2.alim7.value;  
        test2.trans6.value=test2.trans7.value; test2.alim6.value=test2.alim7.value; 
test2.pto7.value=test2.pto8.value; test2.alim7.value=test2.alim8.value;
        test2.trans7.value=test2.trans8.value; test2.alim7.value=test2.alim8.value;
test2.pto8.value=test2.pto9.value; test2.alim8.value=test2.alim9.value;
        test2.trans8.value=test2.trans9.value; test2.alim8.value=test2.alim9.value;
test2.pto9.value=test2.pto10.value; test2.alim9.value=test2.alim10.value;
        test2.trans9.value=test2.trans10.value; test2.alim9.value=test2.alim10.value;
test2.pto10.value=0; test2.alim10.value="--->"; 
        test2.trans10.value=0; test2.alim10.value="--->"
 acumula_pontos();}      
   }    


function excluir_alim3(){
        
        if (test2.pto3.value!="")
		if (test2.trans3.value!="")
        {test2.pto3.value=test2.pto4.value; test2.alim3.value=test2.alim4.value;  
        test2.trans3.value=test2.trans4.value; test2.alim3.value=test2.alim4.value;
test2.pto4.value=test2.pto5.value; test2.alim4.value=test2.alim5.value;  
        test2.trans4.value=test2.trans5.value; test2.alim4.value=test2.alim5.value; 
test2.pto5.value=test2.pto6.value; test2.alim5.value=test2.alim6.value;   
        test2.trans5.value=test2.trans6.value; test2.alim5.value=test2.alim6.value; 
test2.pto6.value=test2.pto7.value; test2.alim6.value=test2.alim7.value;  
        test2.trans6.value=test2.trans7.value; test2.alim6.value=test2.alim7.value; 
test2.pto7.value=test2.pto8.value; test2.alim7.value=test2.alim8.value;
        test2.trans7.value=test2.trans8.value; test2.alim7.value=test2.alim8.value;
test2.pto8.value=test2.pto9.value; test2.alim8.value=test2.alim9.value;
        test2.trans8.value=test2.trans9.value; test2.alim8.value=test2.alim9.value;
test2.pto9.value=test2.pto10.value; test2.alim9.value=test2.alim10.value;
        test2.trans9.value=test2.trans10.value; test2.alim9.value=test2.alim10.value;
test2.pto10.value=0; test2.alim10.value="--->"; 
        test2.trans10.value=0; test2.alim10.value="--->"
 acumula_pontos();}      
   }    


function excluir_alim4(){
        
       if (test2.pto4.value!="")
		if (test2.trans4.value!="")
        {test2.pto4.value=test2.pto5.value; test2.alim4.value=test2.alim5.value;  
        test2.trans4.value=test2.trans5.value; test2.alim4.value=test2.alim5.value; 
test2.pto5.value=test2.pto6.value; test2.alim5.value=test2.alim6.value;   
        test2.trans5.value=test2.trans6.value; test2.alim5.value=test2.alim6.value; 
test2.pto6.value=test2.pto7.value; test2.alim6.value=test2.alim7.value;  
        test2.trans6.value=test2.trans7.value; test2.alim6.value=test2.alim7.value; 
test2.pto7.value=test2.pto8.value; test2.alim7.value=test2.alim8.value;
        test2.trans7.value=test2.trans8.value; test2.alim7.value=test2.alim8.value;
test2.pto8.value=test2.pto9.value; test2.alim8.value=test2.alim9.value;
        test2.trans8.value=test2.trans9.value; test2.alim8.value=test2.alim9.value;
test2.pto9.value=test2.pto10.value; test2.alim9.value=test2.alim10.value;
        test2.trans9.value=test2.trans10.value; test2.alim9.value=test2.alim10.value;
test2.pto10.value=0; test2.alim10.value="--->"; 
        test2.trans10.value=0; test2.alim10.value="--->"
 acumula_pontos();}      
   }    


function excluir_alim5(){
        
      if (test2.pto5.value!="")
		if (test2.trans5.value!="")
        {test2.pto5.value=test2.pto6.value; test2.alim5.value=test2.alim6.value;   
        test2.trans5.value=test2.trans6.value; test2.alim5.value=test2.alim6.value; 
test2.pto6.value=test2.pto7.value; test2.alim6.value=test2.alim7.value;  
        test2.trans6.value=test2.trans7.value; test2.alim6.value=test2.alim7.value; 
test2.pto7.value=test2.pto8.value; test2.alim7.value=test2.alim8.value;
        test2.trans7.value=test2.trans8.value; test2.alim7.value=test2.alim8.value;
test2.pto8.value=test2.pto9.value; test2.alim8.value=test2.alim9.value;
        test2.trans8.value=test2.trans9.value; test2.alim8.value=test2.alim9.value;
test2.pto9.value=test2.pto10.value; test2.alim9.value=test2.alim10.value;
        test2.trans9.value=test2.trans10.value; test2.alim9.value=test2.alim10.value;
test2.pto10.value=0; test2.alim10.value="--->"; 
        test2.trans10.value=0; test2.alim10.value="--->"
 acumula_pontos();}      
   }    


function excluir_alim6(){
        if (test2.pto6.value!="")
		if (test2.trans6.value!="")
        {test2.pto6.value=test2.pto7.value; test2.alim6.value=test2.alim7.value;  
        test2.trans6.value=test2.trans7.value; test2.alim6.value=test2.alim7.value; 
test2.pto7.value=test2.pto8.value; test2.alim7.value=test2.alim8.value;
        test2.trans7.value=test2.trans8.value; test2.alim7.value=test2.alim8.value;
test2.pto8.value=test2.pto9.value; test2.alim8.value=test2.alim9.value;
        test2.trans8.value=test2.trans9.value; test2.alim8.value=test2.alim9.value;
test2.pto9.value=test2.pto10.value; test2.alim9.value=test2.alim10.value;
        test2.trans9.value=test2.trans10.value; test2.alim9.value=test2.alim10.value;
test2.pto10.value=0; test2.alim10.value="--->"; 
        test2.trans10.value=0; test2.alim10.value="--->"
 acumula_pontos();}      
   }    


function excluir_alim7(){
        
        if (test2.pto7.value!="")
		if (test2.trans7.value!="")
        {test2.pto7.value=test2.pto8.value; test2.alim7.value=test2.alim8.value;
        test2.trans7.value=test2.trans8.value; test2.alim7.value=test2.alim8.value;
test2.pto8.value=test2.pto9.value; test2.alim8.value=test2.alim9.value;
        test2.trans8.value=test2.trans9.value; test2.alim8.value=test2.alim9.value;
test2.pto9.value=test2.pto10.value; test2.alim9.value=test2.alim10.value;
        test2.trans9.value=test2.trans10.value; test2.alim9.value=test2.alim10.value;
test2.pto10.value=0; test2.alim10.value="--->"; 
        test2.trans10.value=0; test2.alim10.value="--->"
 acumula_pontos();}      
   }    


function excluir_alim8(){
        
        if (test2.pto8.value!="")
		if (test2.trans8.value!="")
        {test2.pto8.value=test2.pto9.value; test2.alim8.value=test2.alim9.value;
        test2.trans8.value=test2.trans9.value; test2.alim8.value=test2.alim9.value;
test2.pto9.value=test2.pto10.value; test2.alim9.value=test2.alim10.value;
        test2.trans9.value=test2.trans10.value; test2.alim9.value=test2.alim10.value;
test2.pto10.value=0; test2.alim10.value="--->"; 
        test2.trans10.value=0; test2.alim10.value="--->"
 acumula_pontos();}      
   }    


function excluir_alim9(){
        
        if (test2.pto1.value!="")
		if (test2.trans1.value!="")
        {test2.pto9.value=test2.pto10.value; test2.alim9.value=test2.alim10.value;
        test2.trans9.value=test2.trans10.value; test2.alim9.value=test2.alim10.value;
test2.pto10.value=0; test2.alim10.value="--->"; 
        test2.trans10.value=0; test2.alim10.value="--->"
 acumula_pontos();}      
   }    


function excluir_alim10(){
       if (test2.pto1.value!="")
		if (test2.trans1.value!="")
        {test2.pto10.value=0; test2.alim10.value="--->"; 
        test2.trans10.value=0; test2.alim10.value="--->"
 acumula_pontos();}      
   }      

function aceita(){

    if(s.value=="")
       {alert ("Escolha um alimento da lista de alimentos.");}
    else
        if(test2.refeicao.value=="")
       {alert ("Informe a refeição.");}
    
    else

        if (test2.alim1.value=="" || test2.alim1.value=="--->")
        {test2.alim1.value =s.value+" x "+test2.quantidade.value;
        len = test2.alim1.value.length;
        test2.pto1.value =test2.subtotal.value;
		test2.trans1.value =test2.subtotalT.value;}
    else
        if (test2.alim2.value=="" || test2.alim2.value=="--->")
        {test2.alim2.value =s.value+" x "+test2.quantidade.value;
        len = test2.alim2.value.length;
        test2.pto2.value =test2.subtotal.value;
		test2.trans2.value =test2.subtotalT.value;}
    else
        if (test2.alim3.value=="" || test2.alim3.value=="--->")
        {test2.alim3.value =s.value+" x "+test2.quantidade.value;
        len = test2.alim3.value.length;
        test2.pto3.value =test2.subtotal.value;
		test2.trans3.value =test2.subtotalT.value;}
    else
        if (test2.alim4.value=="" || test2.alim4.value=="--->")
        {test2.alim4.value =s.value+" x "+test2.quantidade.value;
        len = test2.alim4.value.length;
        test2.pto4.value =test2.subtotal.value;
		test2.trans4.value =test2.subtotalT.value;}
    else
        if (test2.alim5.value=="" || test2.alim5.value=="--->")
        {test2.alim5.value =s.value+" x "+test2.quantidade.value;
        len = test2.alim5.value.length;
        test2.pto5.value =test2.subtotal.value;
		test2.trans5.value =test2.subtotalT.value;}
    else
        if (test2.alim6.value=="" || test2.alim6.value=="--->")
        {test2.alim6.value =s.value+" x "+test2.quantidade.value;
        len = test2.alim6.value.length;
        test2.pto6.value =test2.subtotal.value;
		test2.trans6.value =test2.subtotalT.value;}
    else
        if (test2.alim7.value=="" || test2.alim7.value=="--->")
        {test2.alim7.value =s.value+" x "+test2.quantidade.value;
        len = test2.alim7.value.length;
        test2.pto7.value =test2.subtotal.value;
		test2.trans7.value =test2.subtotalT.value;}
    else
        if (test2.alim8.value=="" || test2.alim8.value=="--->")
        {test2.alim8.value =s.value+" x "+test2.quantidade.value;
        len = test2.alim8.value.length;
        test2.pto8.value =test2.subtotal.value;
		test2.trans8.value =test2.subtotalT.value;}
    else
        if (test2.alim9.value=="" || test2.alim9.value=="--->")
        {test2.alim9.value =s.value+" x "+test2.quantidade.value;
        len = test2.alim9.value.length;
        test2.pto9.value =test2.subtotal.value;
		test2.trans9.value =test2.subtotalT.value;}
    else
        if (test2.alim10.value=="" || test2.alim10.value=="--->")
        {test2.alim10.value =s.value+" x "+test2.quantidade.value;
        len = test2.alim10.value.length;
        test2.pto10.value =test2.subtotal.value;
		test2.trans10.value =test2.subtotalT.value;}

        acumula_pontos();
    }   


function Left(str, n){
    var n;
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0,n);
}
function Right(str, n){
    var n;
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function init1()
{
        s = document.getElementById("alimentos");
        for(var i = 0;i < s.options.length;i++)
document.submit();
} 
            
