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

Ext.onReady(function() {

    //--- CONCERTI ------------------------------------
    var store3 = new Ext.data.Store({
        autoLoad: true,
        storeId: 's3',
        proxy: new Ext.data.HttpProxy({
            url: 'data2.aspx?servizio=9',
            method: 'get'

        }),
        reader: new Ext.data.JsonReader({
            successProperty: 'success',
            root: 'Concerti',
            fields: [
                { name: 'Id', mapping: 'Id' },
                { name: 'Titolo', mapping: 'Titolo' },
				{ name: 'Descrizione', mapping: 'Descrizione' },
                { name: 'Data', mapping: 'Data', type: 'date', dateFormat: 'd/m/Y G.i.s' },
                { name: 'Link', mapping: 'Link' },
                { name: 'Maps', mapping: 'Maps' },
                { name: 'Tipo', mapping: 'Tipo' }
                ]
        }),
        listeners: { 'loadexception': function(event, options, response, error) {
            //var json = Ext.decode(response.responseText);
            //Ext.Msg.alert('Errore', json.error);
Ext.getCmp('concerti').setVisible(false);
        },
            'load': function(t, rec, obj) {
            }
        },
        remoteSort: true
    });

    var tpl3 = new Ext.XTemplate(
    '',
    '<tpl for="."><div class="concerto">',
'<span class="titolo"><span style="color:#ffffff;">{Data:date(\"d\")}</span> {Data:date(\"F  Y\")}</span><br />',
'<tpl if="Data.dateFormat(\'G:i\') == \'0:00\'"><span class="luogo">{Titolo}<br /> {Descrizione}</span><br /></tpl>',
'<tpl if="Data.dateFormat(\'G:i\') != \'0:00\'"><span class="luogo">{Titolo}<br /> {Descrizione}, ore {Data:date(\"G:i\")}</span><br /></tpl>',
'<span class="link">',
'<tpl if="Link != \'\'"><span style="color:#ffffff;">[ </span><a href="{Link}" target="_blank">link</a><span style="color:#ffffff;"> ] ',
'| </span></tpl>',
'<tpl if="Maps != \'\'"><span style="color:#ffffff;">[ </span><a href="{Maps}" target="_blank">mappa</a><span style="color:#ffffff;"> ] </span></tpl>',
'<tpl if="Tipo != 0">| <span style="color:#ffffff;">[ </span><a style="font-weight:bold;" href="http://www.kabarevoltaire.it/lospettacolo.html#listaspettacoli" target="_parent">info & prenotazioni</a><span style="color:#ffffff;"> ] </tpl>',
'</span>',
'</span>',
'</div><br /></tpl>'
    );

    var p2 = new Ext.DataView({
id: 'concerti',
        //width: 300,
        border: false,
        store: store3,
        tpl: tpl3,
        renderTo: 'concerti-dataview',
        itemSelector: 'div.concerti-dataview',
        loadingText: '<font style="font-family:arial;">Caricamento...</font>'

    });

    //--- NEWS ------------------------------------
    var store2 = new Ext.data.Store({
        autoLoad: true,
        storeId: 's3',
        proxy: new Ext.data.HttpProxy({
            url: 'data2.aspx?servizio=1',
            method: 'get'

        }),
        reader: new Ext.data.JsonReader({
            successProperty: 'success',
            root: 'News',
            fields: [
                { name: 'Titolo', mapping: 'Titolo' },
				{ name: 'Descrizione', mapping: 'Descrizione' },
				{ name: 'descBreve', mapping: 'descBreve' },
                { name: 'Data', mapping: 'Data', type: 'date', dateFormat: 'd/m/Y' }
                ]
        }),
        listeners: { 'loadexception': function(event, options, response, error) {
            //var json = Ext.decode(response.responseText);
            //Ext.Msg.alert('Errore', json.error);
        },
            'load': function(t, rec, obj) {
            }
        },
        remoteSort: true
    });

    var tpl2 = new Ext.XTemplate(
    '',
    '<tpl for="."><span class="titolo_blog"><span style="color:#ffffff;">{Titolo}</span></span><br />',
'<span class="data_blog"><span style="color:#ffffff;">{Data:date(\"d\")}</span> {Data:date(\"F  Y\")}</span><br />',
'<span class="contenuto_blog">{descBreve}</span><br />',
'<span class="link"><span style="color:#ffffff;">[ </span><a href="http://kabarevoltaire.wordpress.com/" target="_parent">continua</a><span style="color:#ffffff;"> ]</span></span></tpl><br /><a href="http://kabarevoltaire.wordpress.com/" class="bottone">Leggi tutti ></a>'
    );

    var p1 = new Ext.DataView({
        //width: 300,
        border: false,
        store: store2,
        tpl: tpl2,
        renderTo: 'blog-dataview',
        itemSelector: 'div.blog-dataview'
        //loadingText: 'Caricamento...'

    });

    var homePanel = new Ext.FormPanel({
        id: 'right',
        frame: false,
        autoHeight: true,
        border: false,
        layout: 'fit',
        //height:700,
        buttonAlign: 'right',
        width: 200,
        items: [{
            autoHeight:true,
            border: false,
            frame: false,
            layout: 'table',
            layoutConfig: {
                columns: 1
            },
            style: 'background-color:transparent;',

            items: [{
                xtype: 'label',
                html: '<font style="font-family:arial; font-size:12px; /*font-weight:bold;*/ ">Vuoi sapere quando suoniamo?</font>',
                style: ' color:#EEEEEE;'
                //style:' color:#3e2426;'
            }, {
            xtype: 'textfield',
                cls:'textinput',
                height: 20,
                width: 150,
                allowBlank: false,
                name: 'emailFrom',
                emptyText: 'tuo indirizzo mail...',
                vtype: 'email'
            }],buttons:[{
                xtype: 'button',
                text: 'invia >>',
                id: 'inviamail',
                style: 'margin-top:0px; margin-right:12px;',
                
                handler: function() {
                    Ext.getCmp("right").getForm().submit({
                        url: 'data2.aspx?servizio=8',
                        method: 'post',
                        waitTitle: 'Connessione',
                        waitMsg: 'Invio dati...',
                        failure: function(form, action) {
                            if (action.failureType != 'client') {
                                Ext.Msg.alert('Errore', action.result.error);
                            } else {
                                Ext.Msg.alert('EHI!', 'Devi inserire un indirizzo mail valido');
                            }
                        },
                        success: function(form, action) {
                            Ext.Msg.alert('OK!', 'Indirizzo Email inviato!');
                        }
                    });
                }
}]
            
}]
            });

            homePanel.render('mailing-div');



            //--- VIDEO ------------------------------------
            /*var store4 = new Ext.data.Store({
            autoLoad: true,
            storeId: 's4',
            proxy: new Ext.data.HttpProxy({
            url: 'dataPUBLIC.aspx?servizio=4',
            method: 'get'

        }),
            reader: new Ext.data.JsonReader({
            successProperty: 'success',
            root: 'VIDEO',
            fields: [
            { name: 'Id', mapping: 'Id' },
            { name: 'Idartista', mapping: 'Idartista' },
            { name: 'Idcd', mapping: 'Idcd' },
            { name: 'Idtraccia', mapping: 'Idtraccia' },
            { name: 'Titolo', mapping: 'Titolo' },
            { name: 'Descrizione', mapping: 'Descrizione' },
            { name: 'Link', mapping: 'Link' },
            { name: 'Linkweb', mapping: 'Linkweb' }
            ]
            }),
            listeners: { 'loadexception': function(event, options, response, error) {
            //var json = Ext.decode(response.responseText);
            //Ext.Msg.alert('Errore', json.error);
            },
            'load': function(t, rec, obj) {
            new Ext.ux.Carousel('html-example', {
            itemSelector: 'div.items',
            interval: 5,
            autoPlay: true,
            transitionEasing: 'easeIn'
            });
            }
            },
            remoteSort: true
            });

    var tpl4 = new Ext.XTemplate(
            '<h3>I VIDEO</h3>',
            '<div id="html-example" style="padding: 5px; height: 230px; width: 590px; background-color: #F6F6F0; color: black">',
            '<tpl for=".">',
            '<tpl if="xindex % 2 != 0"><div class="items" style="margin-top:50px;"></tpl>',
            '<tpl if="xindex % 2 != 0"><div style="float:left; width:300px; "></tpl>',
            '<div style="width:250; ">',
            '<a href="{Linkweb}" target="_blank">',
            '<div id="bg_video"><p><img src="public/artisti/{Idartista}/cd/{Idcd}/{Idtraccia}/video/org/{Link}" width="180" height="124" alt="Pic 1" class="video-img" /></p></div>',
            '<p style="text-align:left;">{Titolo}</p>',
            '</a></div>',
            '<tpl if="xindex % 2 != 0"></div></tpl>',
            '<tpl if="xindex % 2 === 0"></div></tpl>',
            '</tpl></div>',
            '<div class="clear"></div>'

    );

    var panel1 = new Ext.Panel({
            id: 'images-view',
            frame: false,
            border: false,
            width: 660,
            autoHeight: true,
            collapsible: false,
            layout: 'fit',
            items: new Ext.DataView({
            //width: 300,
            autoHeight: true,
            border: false,
            store: store4,
            tpl: tpl4,
            itemSelector: 'div.video-clip',
            emptyText: 'Nessun video disponibile'
            //loadingText: 'Caricamento...'

        })
    });

    panel1.render('video');*/


        });
