// JavaScript Document

/* Clase carro */
var globo;
function Carro() {
    this.agregar = function(id) {
    	if($('carroCenter')){
        cantidad = document.getElementById('cantidad' + id).value;
        if(cantidad > 0){
            if(globo)globo.close(0);
            agregarAjax = nuevoAjax();


            //alert('cantidad es '+cantidad); //para rutear los campos
            agregarAjax.open("GET", SITE_URL + "/carro.php?op=agregar&cant=" + cantidad + "&id="
                + id);
            agregarAjax.onreadystatechange = function() {
                if (agregarAjax.readyState == 4) {
				
                    if(!globo)globo = new GloboTexto(document.getElementById('carroTop'),
                        agregarAjax.responseText);
                    else globo.text = agregarAjax.responseText;
                    globo.mostrar();
                    contenedor = document.getElementById('carroCenter');
                    carro.actualizarLado(contenedor);
                    /* Hacer desaparecer el globo */
                    var i =0;
                    var intervalo = setInterval(function(){
                        globo.close(1);
                        i++;
                        if(i==1)clearInterval(intervalo);

                    },3000);


                }
            }
            agregarAjax.send(null);
        }
    	}
    	else{
    		mensaje('No puede agregar productos desde este lugar. \nCierre esta Haga click en el enlace "productos", ubicado en el menú superior');
    	}
    }
    var id;
    this.actualizarLado = function(id){
        ajax = nuevoAjax();
        ajax.open("GET",SITE_URL + "/carro.php?op=mostrarAjax",true);
        ajax.onreadystatechange = function(){
            if(ajax.readyState == 4){
                id.innerHTML = ajax.responseText;
            }
        }
        ajax.send(null);
    }
    
}

