/*
    Document   : layout
    Created on : 02-Aug-2009, 13:08:30
    Author     : Andreas Hadjigeorgiou
    Description: This js creates the Extjs layout of the map application
                 from the layout XML, the application and company settings
                 and the mapcomponenet of GeoExt javascript
*/
lbgm.layout = {

    //Public
//    return {
        // Properties
        layoutid: 0,
        xmlfile: '',

        // Methods
        loadLayout: function() {
            // AJAX to load layout
           var conn = new Ext.data.Connection();

           conn.request({
                url: 'src/php/conn/layoutparser.conn.php',
                method: 'POST',
                params: {"request": "loadLayout", layoutid: this.layoutid, xmlfile: this.xmlfile},
                success: function(responseObject) {

                   lbgm.layout.initializing = true;
                   
                   obj = Ext.util.JSON.decode(responseObject.responseText);
                   //alert('Doing Layout ' + this.layoutid);

                   lbgm.maplets.mapobject.init();

                   // Check Login
                   obj.results += "lbgm.login.checkloggedin();";
                   eval(obj.results);

                   // Initialize Point Object and try to show initial point (if applicaple)
                   lbgm.point.init();

                   /*var getParams = document.URL.split("?");
                    if(getParams.length > 1 ) {
                       var urlparams = Ext.urlDecode(getParams[1]);

                       if(urlparams['lon']!=undefined || urlparams['p']!=undefined || urlparams['a']!=undefined)
                           lbgm.point.showInitPoint();
                       
                    }*/
                   
                },
                failure: function() {
                   //Ext.Msg.alert(lbgm.options.appname, 'Unable to load layout.');
                },
                scope: this
            });
            //On response
            //alert('Doing Layout ' + this.layoutid);
        },
        
        init: function() {
            /*TODO: AJAX call layoutparser.conn.php and the javasacript code
             *      result output it in the gmapp id div */
            this.loadLayout();

            
        },

        initCont: function() {
            var getParams = document.URL.split("?");
            if(getParams.length > 1 ) {
               var urlparams = Ext.urlDecode(getParams[1]);

               if(urlparams['nvf_lat']!=undefined && urlparams['nvf_lon']!=undefined && urlparams['nvt_lat']!=undefined && urlparams['nvt_lon']!=undefined) {
                    lbgm.navigation.showInitNavigation(urlparams['nvf_lat'], urlparams['nvf_lon'], urlparams['nvt_lat'], urlparams['nvt_lon']);
               }
               else  if(urlparams['lon']!=undefined || urlparams['p']!=undefined || urlparams['a']!=undefined) {
                    lbgm.point.showInitPoint();
               }
            }
            
            // Load Point
            //lbgm.point.showInitPoint();
            //lbgm.maplets.mapobject.init = false;

            //lbgm.maplets.mapobject.centerMap();
        }
    }; // end of layout
//} // end of file

