
Ext.ns('blablar');
Ext.QuickTips.init();
var today = new Date();


function crearRecordatorio()
{
   var calendario = new Ext.FormPanel(
   {
      labelWidth : 110,
      url : './recordatorio.aspx',  // en ejemplo
      iconCls : 'sched-icon',
      frame : true,
      title : 'Recordatorio',
      // monitorValid : true,
      // ENTRADA
      items : [
      {
         xtype : 'datefield',
         fieldLabel : '&iquest;Cuando quieres que te avisemos?',
         format : 'd/m/Y',
         //minValue : new Date(today.getYear(), today.getMonth(), today.getDate() - 0 + 1),
         name : 'fechaRecordar'
      }
      ,
      {
         xtype : 'textarea',
         fieldLabel : '&iquest;Que quieres que te recordemos?',
         name : 'mensaje',
         width : 220,
         height : 80,
         maxLength : 100,
         maxLengthText : 'El numero de caracteres máximo es de 100',
         allowBlank : false
      }
      ,
      {
         xtype : 'checkbox',
         fieldLabel : '&iquest;Le avisamos a alguien mas?',
         name : 'avisar',
         allowBlank : true
      }
      ,
      {
         xtype : 'numberfield',
         fieldLabel : '&iquest;Celular',
         name : 'destinatario',
         width : 100,
         // vtype : 'alphanum',
         maxLength : 10,
         // minLength : 10,
         maxLengthText : 'El numero de caracteres m&iacute;nimo es  10',
         minLengthText : 'El numero de caracteres m&aacute;ximo es  10',
         allowBlank : true
      }
      ]
   }
   );


   // VENTANA PRINCIPAL
   var sched_win = new Ext.Window(
   {
      title : 'Programar Recordatorio',
      layout : 'fit',
      width : 410,
      height : 320,
      iconCls : 'sched-icon',
      // closable : true,
      resizable : false,
      plain : true,
      // border : true,
      draggable : true
      , modal : false
      , closeAction : 'hide'
      , resizable : false
      , shadow : true
      , items : [
      {
         xtype : 'tabpanel'
         , activeTab : 0
         , defaults :
         {
            autoScroll : true, bodyStyle : 'padding:8px'
         }
         , region : 'center'
         , deferredRender : false
         , autoScroll : true
         , items : [calendario,
         {
            title : '&iquest;Necesitas ayuda?'
            , iconCls : 'help-icon'
            , autoLoad :
            {
               url : 'sms-faq.html'
            }
            , width : 300
            , height : 200
         }
         ]
      }
      ],
      buttons : [
      {
         text : 'Enviar',
         // formBind : true,
         // FUNCION DE BOTON PARA ENVIAR MENSAJE
         handler : function()
         {
            calendario.getForm().submit(
            {
               method : 'POST',
               waitTitle : 'Espere',
               waitMsg : 'Grabando...',

               // FUNCION PARA ENVIO DE MENSAJE

               success : function()
               {
                  Ext.Msg.alert('Aviso', 'Recordatorio agendado.', function(btn, text)
                  {
                     Ext.Msg.alert('Aviso', 'Se guardo el recordatorio.');
                     sched_win.close();
                  }
                  );
               }
               ,

               // VALIDACIONES

               failure : function(form, action)
               {
                  if(action.failureType == 'server')
                  {
                     obj = Ext.util.JSON.decode(action.response.responseText);
                     Ext.Msg.alert('No se pudo guardar tu recordatorio.', obj.errors.reason);
                  }
                  else
                  {
                     Ext.Msg.alert('Warning!', 'Authentication server is unreachable : ' + action.response.responseText);
                  }
                  calendario.getForm().reset();
               }
            }
            );
         }
      }
      ]
   }
   );

   sched_win.show();
}

