/**
* www.supergadget.ro
*
*
*/

window.addEvent( 'domready', function()
{
//     Clienti = new ClientiJs();
//     Produse = new ProduseJs();
    Plata = new PlataJs();
});


/*ClientiJs = new Class ({

    initialize: function ()
    {
        this.ajaxUsername = new Ajax( baseUrl + 'Clienti/valideazaUsername/',
                                      {
                                        method: 'post'
//                                         async: false
                                      }
                                    );
    },

    verificaUsername : function ( input_id, result_id, bt_submit )
    {
        this.ajaxUsername.options.update = $( result_id );
        this.ajaxUsername.options.data = Object.toQueryString({ username : input_id.value });
        that = this;
        this.ajaxUsername.addEvent( 'onComplete', function () 
                                             {
                                                if ( that.ajaxUsername.response.text.indexOf( 'ex' ) != -1 )
                                                {
                                                    $( bt_submit ).setProperty( 'disabled', 'disabled');
                                                }
                                                else
                                                {
                                                    $( bt_submit ).removeProperty( 'disabled' );
                                                }
                                              }
                             );
        this.ajaxUsername.request();
    },

    trimiteFormular : function ( form_id )
    {
        $( form_id ).send(
                            {
                                update: $( 'continut' ),
                                onRequest: function () { $( 'continut' ).setOpacity( 0.3 ); },
                                onComplete: function() { $( 'continut' ).setOpacity( 1 ); },
				evalScripts: true
                            }
                         );
    },

    stergeDate : function ( id, url, result_id, mesaj )
    {
        if ( confirm( mesaj ) )
        {
            new Ajax( baseUrl + url,
                                      {
                                        update: $( result_id ),
                                        method: 'post',
//                                         async: false,
                                        data: Object.toQueryString({ id : id }),
                                        onRequest: function () { $( 'continut' ).setOpacity( 0.3 ); },
                                        onComplete: function() { $( 'continut' ).setOpacity( 1 ); },
                                        evalScripts: true
                                      }
                                    ).request();
        }
    },

    recupereazaParola: function() {
            $( 'formRecuperareParola' ).send( {
                onComplete:
                    function()
                    {
                        new AlertWindowJs( {mesaj: 'Cererea dumneavostră a fost procesată.'} ).openAlert();
                    }
            } );
    }

});*/

AndruxJs = new Class( {

	/**
	* trimite formularul cu id-ul formId
	*
	* butonul care a fost apasat - va fi ascuns in caz ca nu au existat erori in procesarea cererii
	*
	* updateCnt - optional : containerul care va contine raspunsul primit
	*
	*/
	trimiteFormular: function( buton, formId, updateCnt )
	{
		var formular = $( formId );
		formular.set( 'send', {
			onRequest: function()
			{
				formular.setStyle( 'opacity', 0.5 );
			},
			onComplete: function()
			{
				if ( updateCnt )
				{
					var txt = this.response.text;
					$( updateCnt ).set( 'html', txt );
					if ( ( txt.indexOf('<!--succes-->') != -1 ) && ( buton ) )
					{
						buton.setStyle( 'display', 'none' );
					}
				}
				formular.setStyle( 'opacity', 1 );
			}
		} );
		formular.send();
	},
	/**
	*
	* sterge o inregistrare din baza de date apeland urlStergere
	*
	* el - linkul care a fost apasat
	*
	* sterge un rand dintr-un tabel - elementul <tr> care contine linkul el
	*
	*/
	stergeRandTabel: function( el, urlStergere )
	{
		var confirmare = confirm( 'Confirmati stergerea!' );
		if ( confirmare )
		{
			var parent = el.getParent( "tr" );
			var myAjax = new Request( {
				url: urlStergere,
				onComplete: function()
				{
					parent.setStyle( 'display', 'none' );
				}
			} );
			myAjax.send();
		}
	}

} );

PlataJs = new Class ({

    initialize: function ()
    {
    },

    plateste : function ( logat )
    {
        if ( logat )
        {
            window.location = baseUrl + 'Clienti/plateste/';
        }
        else
        {
            new AlertWindowJs( { mesaj: 'Trebuie să vă logaţi pentru a merge mai departe.', autoHide: false } ).openAlert();
        }
    },

    finalizeaza: function() {
        $( 'formFinalizareComanda' ).set( 'send', {
            onRequest: function(){
                $( 'divFinalizareComanda' ).setStyle( 'opacity', 0.3 );
            },
            onComplete: function(){
                var that = this;
                $( 'divFinalizareComanda' ).setStyle( 'opacity', 1 );
                if ( this.response.text.indexOf( '<!--succes-->' ) != -1 ) {
                    $( 'divFinalizareComanda' ).set( 'html', that.response.text );
                }
                else {
                    $( 'cntCampuriComanda' ).set( 'html', that.response.text );
                }
            }
	} );
	$( 'formFinalizareComanda' ).send();
    }

} );

function noSpam( user, domain ) {
    document.location = 'mailto:' + user + '@' + domain;
}