/*
 * Ext JS Library 2.2.1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

var feedback_win;

Ext.onReady(function(){
    var button = Ext.get('signup_button');

    button.on('click', function(){
    	var name = {
		    xtype: 'textfield',
            fieldLabel: 'שם',
            name: 'mem_first',
            id: 'mem_first',
            width: 165
	    };
	    var email = {
		    xtype: 'textfield',
            fieldLabel: 'מייל',
            name: 'mem_email',
            id: 'mem_email',
            vtype: 'email',
            width: 165
	    };
    	var height = 180;

        if (feedback_win)
        	feedback_win.destroy();
        feedback_win = new Ext.Window({
			title: 'הרשמה לניוזלטר',
			cls: 'feedback',
			id: 'feedback-popup',
			border: false,
			bodyBorder: false,
			bodyStyle: 'padding-left: 13px; padding-right:13px;',
			shadow: false,
			resizable: false,
            width       : 280,
            height      : height,
            closeAction :'hide',
			layout: 'fit',
			items: {
				xtype: 'form',
				cls: 'feedback-form',
				bodyStyle: 'background: #DFE8F6',
				border: false,
				labelAlign: 'left',
				labelWidth:40,
				bodyBorder: false,
				autoHeight: true,
				defaults: {hideMode: 'offsets'},
				items: [{
			    	border: false,
	        		html:'הכנס את שמך וכתובת המייל להצטרפות לרשימת הדיוור.',
	        		bodyStyle: 'margin-top:10px;margin-bottom:10px;background:transparent;'
	        	}
		        ,name,email],
				buttonAlign: 'center',
				buttons: [{
                	text: 'בטל',
					//icon: g_params["static_media_domain"]+'/public/global/popup/btn-cancel.jpg',
					cls: "cancel-btn",
                    handler  : function(){
                        feedback_win.hide();
                    }
                }, {
					text: 'הצטרף לרשימה',
					//icon: g_params["static_media_domain"]+'/public/global/popup/btn-send-message.png',
					cls: "send-btn",
					handler: function() {
						Ext.Ajax.request({
							url: '/',
							method: 'post',
							params: { 
								'can_newsletter': 1,
								'mem_first': Ext.getCmp("mem_first").getValue(),
								'mem_email': Ext.getCmp("mem_email").getValue()
							},
							callback: function(options, success, response){
									if (success==true){
				                        feedback_win.hide();
										Ext.MessageBox.show({
						   					title:'תודה!',
						   					msg: 'תודה על הרשמתך.',
											buttons: Ext.MessageBox.OK,
										   width: 200
										});
									}
								}
						}); 
			        }
                }]
			}
        });
        feedback_win.show(button);
	});
});
