/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

$(document).ready(main);

var contador = 1;


function main(){
$('.menu_bar').click(function(){
//$('nav').toggle();
if(contador==1){
	$('nav').show(800);
	contador=0;
}else{
	contador=1;
	$('nav').hide(800);
}

});

$('.submenu').click(function(){
	$(this).children('.children').slideToggle();
});

}

function setInputDate(_id){
    var _dat = document.querySelector(_id);
    var hoy = new Date(),
        d = hoy.getDate(),
        m = hoy.getMonth()+1, 
        y = hoy.getFullYear(),
        data;

    if(d < 10){
        d = "0"+d;
    };
    if(m < 10){
        m = "0"+m;
    };

    data = y+"-"+m+"-"+d;
    console.log(data);
    _dat.value = data;
};

function multiplicar() {
m1 = document.getElementById("Cantidad").value;
m2 = document.getElementById("Valor").value;
Subtotal = m1*m2;
document.getElementById("Subtotal").value = Subtotal;
}
function multiplicar2() {
m1 = document.getElementById("Cantidad2").value;
m2 = document.getElementById("Valor2").value;
Subtotal = m1*m2;
document.getElementById("Subtotal2").value = Subtotal;
}

function sumar(){
    V1 = parseInt(document.getElementById('Subtotal').value);
    V2 = parseInt(document.getElementById('ValorTotal').value);
    Suma = V1 + V2;
    document.getElementById('ValorTotal').value = Suma;
}

var cont=1;
function addRowX()  //Esta la funcion que agrega las filas :
{

cont++;
var indiceFila=1;
myNewRow = document.getElementById('tabla').insertRow(-1);
myNewRow.id=indiceFila;
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<td><input type="text" disabled="disabled" value="" name="producto'+cont+'" autofocus="autofocus" required="required" class="required" style="width:150px; height:30px;"></td>';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<input type="number" id="Cantidad'+cont+'" value="0" name="cantidad'+cont+'" autofocus="autofocus" min="0" required="required" class="required" style="width:50px; height:30px;" onChange="multiplicar'+cont+'();">';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<input type="text" disabled="disabled" value="5" name="valor'+cont+'" autofocus="autofocus" min="0" required="required" id="Valor'+cont+'" class="required" style="width:100px; height:30px;">';
myNewCell=myNewRow.insertCell(-1);
myNewCell.innerHTML='<input type="number" disabled="disabled" value="0" id="Subtotal'+cont+'" name="subtotal'+cont+'" autofocus="autofocus" min="0" required="required" class="required" style="width:100px; height:30px;">';


indiceFila++;

}
//////////////Borrar() ///////////
function borrar() {
var table = document.getElementById('tabla');
if(table.rows.length > 3)
    {
    table.deleteRow(table.rows.length -1);
cont--;
    }
}

////////////FUNCION ASIGNA VALOR DE CONT PARA EL FOR DE MOSTRAR DATOS MP-MOD-TT////////
function asigna()
{
valor=document.form.var_cont.value=cont;
}

setInputDate("#dateDefault");




