/**
* @ Cos de cumparaturi
* @ Author Dumitru Glavan
* @ Version 1.1
* @ Framework Mootools
*/

window.addEvent( 'domready', function()
{
    Cos = new CosJs();
});


CosJs = new Class ({

    initialize: function ()
    {
        this.initializare = new Request( {
		url: baseUrl + 'Produse/initializeazaCos/',
                onComplete: function(){
			that = this;
			 $( 'continut_cos' ).set( 'html', that.response.text );
		}
       	} );

        this.params = null;
    },

    adaugaProdus : function ( produs_id, nr_bucati )
    {
	var myAjax = new Request( {
		url: baseUrl + 'Produse/adaugaProdus',
		data: 'stocId=' + $( 'StocId' ).value + '&nrBucati=' + $('StocCantitate').options[ $('StocCantitate').selectedIndex ].value,
		onComplete: function(){
			//$( 'continut_cos' ).set( 'html', myAjax.response.text );
  			//var alertDiv = new AlertWindowJs( {mesaj: 'Produsul a fost adăugat în coş.'} ).openAlert();
// 			alert('produsul a fost adaugat');
                        window.location = baseUrl + 'Produse/veziCos/'
		}
	} );
        myAjax.send();
    },

    actualizareCos : function ()
    {
        var thatCos = this;
	var inputuri = $$( '.input_nr_produse' );
	var date = '';
	inputuri.each( function( element ){
		date = date + element.name + '=' + element.value + '&';
	} );
	var myAjax = new Request( {
		url: baseUrl + 'Produse/actualizareCos',
		data: date,
		onComplete: function() {
			var thisAjax = this;
			$( 'formular_cos' ).set( 'html', thisAjax.response.text );
			thatCos.initializare.send();
		}
	} );
	myAjax.send();
        /*$( 'formular_cos' ).send( { 
					url: baseUrl + 'Produse/actualizareCos/',
					method: 'post',
                                    onComplete:
                                        function ()
                                        {
						var thisAjax = this;
						$( 'formular_cos' ).set( 'html', thisAjax.response.text );
                                             thatCos.initializare.send();
                                        }
                                  }
                                );*/
    },

    stergeProdus : function ( stoc_id )
    {
        var that = this;
	var myAjax = new Request( {
		url: baseUrl + 'Produse/stergeProdus/',
		data: 'stocId=' + stoc_id,
		onComplete: function(){
			var thisAjax = this;
			$( 'formular_cos' ).set( 'html', thisAjax.response.text );
			that.initializare.send();
// 			new AlertWindowJs( {mesaj: 'Produsul a fost şters din coş.'} ).openAlert();
		}
	} );
        myAjax.send();
    }

});