/*
 * Ext JS Library 2.2.1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

// Sample desktop configuration
MyDesktop = new Ext.app.App({
	init :function(){
		
		Ext.QuickTips.init();
		
		/*
		Ext.Ajax.request({
			url: window.location.protocol+"/keldaconnect/loginStatus",
			disableCaching:false,
			success: function(response,options) {
				res = eval("("+response.responseText+")");
				Kelda.Info.ObjectMgr.getInstance().get('login-status').login=res.loginStatus;
				Ext.getCmp('sett-depo').disabled=!res.loginStatus;
				Ext.getCmp('sett-overview').disabled=!res.loginStatus;
				if(res.loginStatus) {
					Ext.getCmp('login-form-id').setVisible(false);
					var logoutBtn = new Ext.Button({
			            text: res.name,
			            id: 'logout-button',
			            iconCls:'logout-button-icon',
			            menu: this.startMenu,
			            renderTo: 'ux-taskbar-start',
			            handler: function() {
							Kelda.Info.ObjectMgr.getInstance().get('logoutAction').action.execute();
						},
			            template: new Ext.Template(
							'<table border="0" cellpadding="0" cellspacing="0" class="logout-button-table" style="width:160px"><tbody><tr>',
							'<td style="width:120px"><b><font id="username" color="white">{0}</font></b></td><td><em unselectable="on"><button class="logout-button" type="{1}"></button></em></td>',
			            	'</tr></tbody></table>')
			        });
				}
				
			},
			failure: function() {
				login=false;
			},
			scope:this
		});
		*/
	},

	getModules : function(){
		return [
            new MyDesktop.NewsFeedMenuModule,
            new MyDesktop.MarketsModule,
            //new MyDesktop.IndexModule,
            new MyDesktop.CurrencyModule,
            new MyDesktop.CBIReiborModule,
            new MyDesktop.BankModule,
            //new MyDesktop.RSFModule
            new MyDesktop.TestModule
            
		];
	},
	getStartupDefaults : function() {
		
	},
    // config for the start menu
	getStartConfig : function(){
		
		this.toolSettings = ['-',{
				id:'about-us-tool',
				text:keldan_lang_text('aboutkeldan').toUpperCase(),
				itemCls:'x-menu-item  startmenu-item',
				iconCls:'startmenu-item-icon',
				handler:function() {
					var win = Ext.getCmp('about-us-win');
					if(!win) {
						var desktop = Kelda.Info.ObjectMgr.getInstance().get('main-desktop');
						win = desktop.createWindow({
						id:'about-us-win',
						title:keldan_lang_text('aboutkeldan').toUpperCase(),
						name:keldan_lang_text('aboutkeldan'),
						manager:desktop.windows,
						bodyStyle:{
							'background-color':'white',
							color:'black'
						},
						maximizable:false,
						constrainHeader:true,
						width:520,
						height:410
					});
					win.load({
						url: window.location.protocol+"//"+window.location.hostname+"/"
						+basePath+"keldaconnect/getAboutUs?lang="+keldan_lang ,
						callback:function() {
							
						},
						scope: this, // optional scope for the callback
				        discardUrl: false,
				        nocache: false,
				        timeout: 30,
				        scripts: false
					});
					}
					win.setPosition(100,120);
					win.on('move',function(){
	        			if(this.getPosition()[1] <= 108) {
	        				this.suspendEvents();
	        				this.setPosition(win.getPosition()[0],108);
	        				this.resumeEvents();
	        			}
	        		},win);
					win.show();
					
				},
				scope:this
			},{
	    	id:'sett-overview',
	        text:keldan_lang_text('legalnotice').toUpperCase(),
	        itemCls:'x-menu-item  startmenu-item',
	        iconCls:'startmenu-item-icon',
	        handler:function() {
				var win = Ext.getCmp('legal-win');
				if(!win) {
					var desktop = Kelda.Info.ObjectMgr.getInstance().get('main-desktop');
					win = desktop.createWindow({
					id:'legal-win',
					manager:desktop.windows,
					constrainHeader:true,
					title:keldan_lang_text('legalnotice').toUpperCase(),
					name:keldan_lang_text('legalnotice'),
					bodyStyle:{
						'background-color':'white',
						color:'black'
					},
					maximizable:false,
					autoScroll:true,
					width:520,
					height:530
				});
				win.load({
					url: window.location.protocol+"//"+window.location.hostname+"/"
					+basePath+"keldaconnect/getLegalTxt?lang="+keldan_lang ,
					callback:function() {
						
					},
					scope: this, // optional scope for the callback
			        discardUrl: false,
			        nocache: false,
			        timeout: 30,
			        scripts: false
				});
				}
				win.setPosition(100,120);
				win.on('move',function(){
        			if(this.getPosition()[1] <= 108) {
        				this.suspendEvents();
        				this.setPosition(win.getPosition()[0],108);
        				this.resumeEvents();
        			}
        		},win);
				win.show();
			},
	        scope:this
	    },{
	    	id:'contactus',
	    	text:keldan_lang_text('contactus').toUpperCase(),
	    	itemCls:'x-menu-item  startmenu-item',
	        iconCls:'startmenu-item-icon',
	    	handler:function() {
	    		document.location.href='MailTo:info@keldan.is';
	    	},
	    	scope:this
	    }];
		var set = {
	        	id:'kelda-settings',
	            title: '',
	            toolItems:this.toolSettings
	    };
        return set;
        
    },
    getPortlets : function() {
    	return [
    	    
    	];
    },
    buildToolItems : function() {
    	
    }
});



/*
 * Example windows
 */

// for example purposes
var windowIndex = 0;

MyDesktop.BogusModule = Ext.extend(Ext.app.Module, {
    init : function(){
        this.launcher = {
            text: 'Window '+(++windowIndex),
            iconCls:'menu-item-icon',
            handler : this.createWindow,
            scope: this,
            windowId:windowIndex
        }
    },

    createWindow : function(src){
        var desktop = this.app.getDesktop();
        var win = desktop.getWindow('bogus'+src.windowId);
        if(!win){
            win = desktop.createWindow({
                id: 'bogus'+src.windowId,
                title:src.text,
                width:640,
                height:480,
                html : '<p>Something useful would be in here.</p>',
                iconCls: 'bogus',
                shim:false,
                animCollapse:false,
                constrainHeader:true
            });
        }
        win.show();
    }
});



/*------------------ Portals Begin -------------------------------*/



/*------------------ Portals End ---------------------------------*/

MyDesktop.NewsFeedMenuModule = Ext.extend(MyDesktop.BogusModule, {
    init : function(){
        this.launcher = {
            text: keldan_lang_text('news').toUpperCase(),
            itemCls:'x-menu-item  startmenu-item',
            iconCls:'startmenu-item-icon',
            handler: function() {
        		pageTracker._trackEvent('News','Open','Fréttabretti opnað af notanda');
        		this.app.getDesktop().createPortlet(this.app.portlets['news'].name,
    				this.app.portlets['news'].is,
    				this.app.portlets['news'].headerCfg,
    				this.app.portlets['news'].item
    				);
        	},
        	scope:this
        	/*
            menu: {
				cls:'submenu',
                items:[{
                    text: 'ALLAR FRÉTTIR ',
                    //iconCls:'menu-item-icon',
                    handler : function() {
                		
                	},
                    scope: this
                    }]
            }*/
        }
   }
});
MyDesktop.MarketsModule = Ext.extend(MyDesktop.BogusModule,{
	init : function() {
		//var portlets = this.portlets;
		this.launcher = {
				text: keldan_lang_text('markets').toUpperCase(),
				itemCls:'x-menu-item  startmenu-item',
				iconCls:'startmenu-item-icon',
				handler: function() {
					return false;
				},
				menu : {
					cls:'startmenu-submenu',
					items:[{
						text:keldan_lang_text('stocks').toUpperCase(),
						iconCls:'startmenu-item-icon',
						itemCls:'x-menu-item  startmenu-item',
						handler : function() {
						pageTracker._trackEvent('Stocks','Open','Hlutabréfabretti opnað af notanda');
						this.app.getDesktop().createPortlet(this.app.portlets['stocks'].name,
								this.app.portlets['stocks'].is,
								this.app.portlets['stocks'].headerCfg,
								this.app.portlets['stocks'].item);
					},
					scope:this
					},
				{
				text:keldan_lang_text('bonds').toUpperCase(),
				itemCls:'x-menu-item  startmenu-item',
				iconCls:'startmenu-item-icon',
				handler : function() {
				pageTracker._trackEvent('Bonds','Open','Skuldabréfabretti opnað af notanda');
				this.app.getDesktop().createPortlet(this.app.portlets['bonds'].name,
						this.app.portlets['bonds'].is,
						this.app.portlets['bonds'].headerCfg,
						this.app.portlets['bonds'].item);
			    },
			    scope:this
			},{
				text:keldan_lang_text('iceland-abroad').toUpperCase(),
				itemCls:'x-menu-item  startmenu-item',
				iconCls:'startmenu-item-icon',
				handler : function() {
				pageTracker._trackEvent('IcelandAbroad','Open','Island erlendis opnað af notanda');
				this.app.getDesktop().createPortlet(this.app.portlets['iceabroad'].name,
						this.app.portlets['iceabroad'].is,
						this.app.portlets['iceabroad'].headerCfg);
			    },
			    scope:this
			}/*,{
				text:'HRÁVÖRUR',
				iconCls:'menu-item-icon',
				handler : function() {
				this.app.getDesktop().createPortlet(this.app.portlets['commodity'].name,
						this.app.portlets['commodity'].is,
						this.app.portlets['commodity'].headerCfg);
			    },
			    scope:this
			}*/]
		}
	}
}
});
MyDesktop.IndexModule = Ext.extend(MyDesktop.BogusModule,{
	init : function() {
	this.launcher = {
		text: 'VÍSITÖLUR',
		itemCls:'x-menu-item  startmenu-item',
		iconCls:'startmenu-item-icon',
		handler: function() {
			return false;
		},
		menu : {
			cls:'startmenu-submenu',
			items:[{
					text:'SEÐLABANKI ÍSLANDS',
					iconCls:'startmenu-item-icon',
					handler:function() {
						pageTracker._trackEvent('CBICE','Open','Vísitölur opnað af notanda');
						this.app.getDesktop().createPortlet(this.app.portlets['cbi'].name,
								this.app.portlets['cbi'].is,
								this.app.portlets['cbi'].headerCfg);
					},
					scope:this
				}]
		}
	}
}
});

MyDesktop.CBIReiborModule = Ext.extend(MyDesktop.BogusModule,{
	init : function(){
    this.launcher = {
        text: keldan_lang_text('rates').toUpperCase(),
        handler: function() {
			return false;
		},
		itemCls:'x-menu-item  startmenu-item',
		iconCls:'startmenu-item-icon',
        menu: {
			cls:'startmenu-submenu',
            items:[{
                text: keldan_lang_text('interbankrates').toUpperCase(),
                itemCls:'x-menu-item  startmenu-item',
                iconCls:'startmenu-item-icon',
                handler : function() {
            		pageTracker._trackEvent('CBRates','Open','Millibankavextir opnað af notanda');
            		this.app.getDesktop().createPortlet(this.app.portlets['centralBankRates'].name,
            				this.app.portlets['centralBankRates'].is,
            				this.app.portlets['centralBankRates'].headerCfg);
            	},
                scope: this
                },{
                    text: keldan_lang_text('depositrates').toUpperCase(),
                    itemCls:'x-menu-item  startmenu-item',
                    iconCls:'startmenu-item-icon',
                    handler : function() {
                		pageTracker._trackEvent('BankRates','Open','Vaxtatöflur opnaðar af notanda');
                		this.app.getDesktop().createPortlet(this.app.portlets['bankrates'].name,
                				
                				this.app.portlets['bankrates'].is,
                				this.app.portlets['bankrates'].headerCfg,
                				this.app.portlets['bankrates'].item
                				);
                	},
                    scope: this
               },{
                   text:keldan_lang_text('icecbrates').toUpperCase(),
                   itemCls:'x-menu-item  startmenu-item',
                   iconCls:'startmenu-item-icon',
                   handler : function() {
               		//pageTracker._trackEvent('BankRates','Open','Vaxtatöflur opnaðar af notanda');
               		this.app.getDesktop().createPortlet(this.app.portlets['cbirates'].name,
               				this.app.portlets['cbirates'].is,
               				this.app.portlets['cbirates'].headerCfg
               				);
               	},
                   scope: this
              }]
		}
    }
}
});

MyDesktop.CurrencyModule = Ext.extend(MyDesktop.BogusModule,{
	init : function() {
	this.launcher = {
			text : keldan_lang_text('currencies').toUpperCase(),
			itemCls:'x-menu-item  startmenu-item',
			iconCls:'startmenu-item-icon',
			handler: function() {
				pageTracker._trackEvent('Currency','Open','Gjaldmiðlabretti opnað af notanda');
				this.app.getDesktop().createPortlet(this.app.portlets['currency'].name,
				this.app.portlets['currency'].is,
				this.app.portlets['currency'].headerCfg,
				this.app.portlets['currency'].item
				);
			},
			scope:this
	};
	}
});
MyDesktop.RSFModule = Ext.extend(MyDesktop.BogusModule,{
	init : function() {
	this.launcher = {
			text : keldan_lang_text('fishmarket').toUpperCase(),
			itemCls:'x-menu-item  startmenu-item',
			iconCls:'startmenu-item-icon',
			handler: function() {
				pageTracker._trackEvent('RSFAF','Open','RSFAF opnað af notanda');
				this.app.getDesktop().createPortlet(this.app.portlets['rsfaf'].name,
				this.app.portlets['rsfaf'].is,
				this.app.portlets['rsfaf'].headerCfg,
				this.app.portlets['rsfaf'].item
				);
			},
			scope:this
			/*
			menu: {
				cls:'submenu',
				items: [{
					text: 'GENGI GJALDMIÐLA',
					iconCls:'menu-item-icon',
					handler: function() {
						this.app.getDesktop().createPortlet(this.app.portlets['currency'].name,
								this.app.portlets['currency'].is,
								this.app.portlets['currency'].headerCfg);
					},
					scope: this
				},{
					text: 'GJALDEYRISKROSSAR',
					iconCls:'menu-item-icon',
					handler: function() {
						this.app.getDesktop().createPortlet(this.app.portlets['fx'].name,
								this.app.portlets['fx'].is,
								this.app.portlets['fx'].headerCfg);
					},
					scope:this
				}]
			}*/
	}
	}
});

MyDesktop.BankModule = Ext.extend(MyDesktop.BogusModule,{
	init : function() {
	this.launcher = {
			text : keldan_lang_text('onlinebanking').toUpperCase(),
			itemCls:'x-menu-item  startmenu-item',
			iconCls:'startmenu-item-icon',
			//style:'color:#57b7df',
			handler: function() {
				return false;
			},
			menu: {
				cls:'startmenu-submenu',
				items: [{
					text: 'ARION BANKI',
					iconCls:'kaup-icon',
					itemCls:'x-menu-item  startmenu-item',
					handler: function() {
						pageTracker._trackEvent('OnlineBank','Open','Kaupþing opnaður af notanda');
						window.open('https://www.kaupthing.is/netbanki4/Sidur/Innskraning.aspx?ReturnUrl=%2fNetbanki4%2fDefault.aspx');
					},
					scope: this
				},{
					text: 'BYR',
					iconCls:'byr-icon',
					itemCls:'x-menu-item  startmenu-item',
					handler:function() {
						pageTracker._trackEvent('OnlineBank','Open','Byr opnaður af notanda');	
						window.open('https://heimabanki.byr.is/','');
	                 },
	                 scope:this
				},{
					text: 'ÍSLANDSBANKI',
					iconCls:'isl-icon',
					itemCls:'x-menu-item  startmenu-item',
					handler: function() {
						pageTracker._trackEvent('OnlineBank','Open','ISB opnaður af notanda');
						window.open('https://www.isb.is/login/','');
					},
					scope:this
				},{
					text: 'LANDSBANKI',
					iconCls:'lans-icon',
					itemCls:'x-menu-item  startmenu-item',
					handler:function() {
						pageTracker._trackEvent('OnlineBank','Open','Landsbanki opnaður af notanda');
						window.open('https://www.einkabanki.is','');
	                 },
	                 scope:this
				},{
					text: 'MP BANKI',
					iconCls:'mp-icon',
					itemCls:'x-menu-item  startmenu-item',
					handler:function() {	
						pageTracker._trackEvent('OnlineBank','Open','MP Banki opnaður af notanda');
						window.open('https://netbanki.mp.is/','');
	                 },
	                 scope:this
				},{
					text: 'S24',
					iconCls:'s24-icon',
					itemCls:'x-menu-item  startmenu-item',
					handler:function() {	
						pageTracker._trackEvent('OnlineBank','Open','S24 opnaður af notanda');
						window.open('https://heimabanki.s24.is/','');
	                 },
	                 scope:this
				},{
					text: 'SPARISJÓÐURINN',
					iconCls:'spar-icon',
					itemCls:'x-menu-item  startmenu-item',
					handler:function() {	
						pageTracker._trackEvent('OnlineBank','Open','Spar opnaður af notanda');
						window.open('https://heimabanki.spar.is/','');
	                 },
	                 scope:this
				}]
			}
	}
	}
});

MyDesktop.TestModule = Ext.extend(MyDesktop.BogusModule,{
	init : function(){
    this.launcher = {
        text: 'AÐGERÐIR',
        handler: function() {
			return false;
		},
        menu: {
			cls:'startmenu-submenu',
            items:[{
                text: 'Login ',
                iconCls:'menu-item-icon',
                handler : function() {
            		var loginForm = {
            			xtype : 'form',
            			id:'login-form',
            			bodyStyle:'padding:15px;background:transparent',
            			border:'false',
            			url:window.location.protocol+"//"+window.location.hostname+"/"+basePath+"node?destination=node",
            			items : [{
            				xtype:'box',
            				autoEl: {
            					tag:'div',
            					html:'<div class="login-msg">'+
            					//'<div class="login-img">'+
            					'Log in to Keldan</div>'
            						
            				}
            			},{
            				xtype:'hidden',
            				hidden:true,
            				id:'form_id',
            				value:'user_login_block'
            			},{
            				xtype:'textfield',
            				id:'name',
            				fieldLabel:'Username',
            				allowBlank:false
            			},{
            				xtype:'textfield',
            				id:'pass',
            				fieldLabel:'Password',
            				inputType:'password',
            				allowBlank:false
            			},{
            				xtype:'hidden',
            				hidden:true,
            				id:'op',
            				value:'Log in'
            			},{
            				xtype:'hidden',
            				hidden:true,
            				id:'type',
            				value:'ajax'
            			}],
            			buttons:[{
            				id:'loginbtn',
            				text:'Login',
            				handler:function() {
            					Ext.getCmp('login-form').getForm().submit({
            						success:function(form,action) {
            							Ext.Msg.show({
            								title:'Innskráning',
            								msg:'Innskráning tókst',
            								buttons:Ext.Msg.OK,
            								icon:Ext.Msg.INFO
            							});
            							win.destroy();
            							// after login action ?
            						},
            						failure : function(form,action) {
            							Ext.Msg.show({
            								title:'Innskráning',
            								msg:'Innskráning mistókst. Hugsanlega vitlaust notendanafn og/eða lykilorð',
            								buttons:Ext.Msg.OK,
            								icon:Ext.Msg.WARNING
            							});
            							win.destroy();
            						}
            					});
            				}
            			},{
            				text:'Cancel',
            				handler:function() {
            					win.destroy();
            				}
            			}],
            			listeners : {
            				'render' : {
            					fn : function() {
            						//if(Ext.getCmp('name'))console.log('got form');
            						Ext.getCmp('name').focus(false,500);
            					}
            				}
            			}
            		};
            		//attach enter button to fields.
            		
            		var win = new Ext.Window({
            			layout:'form',
            			width:340,
            			autoHeight:true,
            			closeAction:'close',
            			items:[loginForm]
            		});
            		win.on('render',function(){
            			var kmap = new Ext.KeyMap(this.getEl(),[{
            				key:Ext.EventObject.ENTER,
            				fn:function() {
            			    	Ext.getCmp('loginbtn').handler();
            			   	}
            			}]);
            		},win);
            		win.show();

            	},
                scope: this
                },{
                   text: 'Logout',
                   iconCls:'menu-item-icon',
                   handler : function() {
                		Ext.Ajax.request({
                			url:window.location.protocol+"//"+window.location.hostname+"/"+basePath+"logout",
                			success : function() {
                			  Ext.Msg.show({
								title:'Útskráning',
								msg:'Útskráning tókst',
								buttons:Ext.Msg.OK,
								icon:Ext.Msg.INFO
							  });
                			},
                			failure : function() {
                			  Ext.Msg.show({
    							title:'Útskráning',
    							msg:'Útskráning mistókst, vinsamlegast endurhlaðið síðu.',
    							buttons:Ext.Msg.OK,
    							icon:Ext.Msg.INFO
                			  });
                			}
                		});
                	},
                    scope: this
                },{
                    text: 'Register ',
                    iconCls:'menu-item-icon',
                    handler : function() {
                		
                		var desktop = Kelda.Info.ObjectMgr.getInstance().get('main-desktop');
                		var win = desktop.createWindow({
                			id:'keldan-user-register',
                			title:'User register',
                			name:'userreg',
                			manager:desktop.windows,	
                			/*
                			listeners: {
                				'render' : {
                					fn : function() {
                						var sbtn = Ext.get('edit-submit');
                						sbtn.on('click',function(){
                							alert('submitted');
                							return false;
                						});
                					}
                				}
                			},
                			*/
                			bodyStyle:{
                				'background-color':'white',
                				color:'black'
                			},
                			maximizable:false,
                			constrainHeader:true,
                			width:540,
                			autoHeight:true
                		});
                		
                		win.load({
                			url : window.location.protocol+"//"+window.location.hostname+"/"+basePath+"registerUser",
                			callback: function() {
        						var sform = Ext.get('kelda-info-newuser-multiform');
        						//disable form post , will submit via ajax.
        						sform.set({'onSubmit':'return false'});
        						sform.on('submit',function(){
        							Ext.Ajax.request({
        								form : 'kelda-info-newuser-multiform',
        								success : function(res,opts) {
        									console.log(res.responseText);
        									var newEl = Ext.DomHelper.overwrite(Ext.get('kelda-info-newuser-multiform'),res.responseText,true);
        									/*var formErr = Ext.get('user_register_error');
        									if(formErr) {
        										formErr.setVisible(false);
        										
        									}*/
        									
        									var submitbtn = Ext.get('edit-submit');
    	                					submitbtn.on('click',function(ev) {
    	                						console.log('clicked submit');
    	                						var back = Ext.get('edit-back');
    	                						if(back)
    	                							back.set({type:'button'});
    	                					});
        									var backbtn = Ext.get('edit-back');
        									if(backbtn)
        										backbtn.on('click',function(ev) {
        											console.log('clicked back');
        		        							submitbtn.set({type:'button'});
        		        						});
        									
        								}
        							});
        							
        						});
        						
        						
        					}
                		});
                		
                		win.show();
                	},
                    scope: this
                }/*,{
                	text:'Prufa graf',
                	handler:function() {
                	  var d = [[1196463600000, 0], [1196550000000, 0], [1196636400000, 0], [1196722800000, 77], [1196809200000, 3636], [1196895600000, 3575], [1196982000000, 2736], [1197068400000, 1086], [1197154800000, 676], [1197241200000, 1205], [1197327600000, 906], [1197414000000, 710], [1197500400000, 639], [1197586800000, 540], [1197673200000, 435], [1197759600000, 301], [1197846000000, 575], [1197932400000, 481], [1198018800000, 591], [1198105200000, 608], [1198191600000, 459], [1198278000000, 234], [1198364400000, 1352], [1198450800000, 686], [1198537200000, 279], [1198623600000, 449], [1198710000000, 468], [1198796400000, 392], [1198882800000, 282], [1198969200000, 208], [1199055600000, 229], [1199142000000, 177], [1199228400000, 374], [1199314800000, 436], [1199401200000, 404], [1199487600000, 253], [1199574000000, 218], [1199660400000, 476], [1199746800000, 462], [1199833200000, 448], [1199919600000, 442], [1200006000000, 403], [1200092400000, 204], [1200178800000, 194], [1200265200000, 327], [1200351600000, 374], [1200438000000, 507], [1200524400000, 546], [1200610800000, 482], [1200697200000, 283], [1200783600000, 221], [1200870000000, 483], [1200956400000, 523], [1201042800000, 528], [1201129200000, 483], [1201215600000, 452], [1201302000000, 270], [1201388400000, 222], [1201474800000, 439], [1201561200000, 559], [1201647600000, 521], [1201734000000, 477], [1201820400000, 442], [1201906800000, 252], [1201993200000, 236], [1202079600000, 525], [1202166000000, 477], [1202252400000, 386], [1202338800000, 409], [1202425200000, 408], [1202511600000, 237], [1202598000000, 193], [1202684400000, 357], [1202770800000, 414], [1202857200000, 393], [1202943600000, 353], [1203030000000, 364], [1203116400000, 215], [1203202800000, 214], [1203289200000, 356], [1203375600000, 399], [1203462000000, 334], [1203548400000, 348], [1203634800000, 243], [1203721200000, 126], [1203807600000, 157], [1203894000000, 288]];
                	  // first correct the timestamps - they are recorded as the daily
                	  // midnights in UTC+0100, but Flot always displays dates in UTC
                	  // so we have to add one hour to hit the midnights in the plot
                	  for (var i = 0; i < d.length; ++i) { d[i][0] += 60 * 60 * 1000; }
                	  var series = [{data: d}];
                	  var win = new Ext.Window({
                		    title: 'Visitors',
                		    id: 'visitors',
                		    layout: 'column',
                		    width: 500,
                		    defaults: {
                		      cls: 'x-panel-body'
                		    },
                		    items: [{
                		      id: 'flot-visitors',
                		      xtype: 'flot',
                		      height: 300,
                		      xaxis: { mode: "time" },
                		      selection: { mode: "x" },
                		      grid: { markings: Ext.ux.Flot.grid.weekendMarkings },
                		      crosshair: { mode: "x" },
                		      series: series
                		    },{
                		      id: 'flot-visitors-birdview',
                		      xtype: 'flot',
                		      height: 50,
                		      lines: { show: true, lineWidth: 1 },
                		      shadowSize: 0,
                		      xaxis: { ticks: [], mode: "time" },
                		      yaxis: { ticks: [], min: 0, max: 4000 },
                		      selection: { mode: "x" },
                		      tooltip: false,
                		      grid: { hoverable: false, clickable: false },
                		      baseSeries: {selectable: false},
                		      series: series,
                		      listeners: {
                		        plotselected: function(flot, event, ranges, item) {
                		          var main_view = Ext.getCmp('flot-visitors');
                		          main_view.zoom(ranges);
                		        }
                		      }
                		    }]
                		  });
                		  win.show();
                	  
                	}
                }*/,{
                    text: 'Register2',
                    iconCls:'menu-item-icon',
                    handler : function() {
                		console.log('ManagedIFRame');
                		
                	
                		var desktop = Kelda.Info.ObjectMgr.getInstance().get('main-desktop');
                		var win = desktop.createWindow({
                			id:'keldan-user-register',
                			title:'User register',
                			name:'userreg',
                			manager:desktop.windows,	
                			layout:'fit',
                			width:Ext.get('main-portal').getComputedWidth(),
                			height:Ext.get('main-portal').getComputedHeight(),
                			//autoHeight:false,
                			items :[{
                				xtype:'iframepanel',
                				id: 'user_register_panel',
                                header:false,
                                defaultSrc :'http://keldanpremiumlocal/registerUser'
                			}]
                		});
                		win.show();
                 		/*
                		Ext.Ajax.request({
                 			url:window.location.protocol+"//"+window.location.hostname+"/"+basePath+"logout",
                 			success : function() {
                 			  Ext.Msg.show({
 								title:'Útskráning',
 								msg:'Útskráning tókst',
 								buttons:Ext.Msg.OK,
 								icon:Ext.Msg.INFO
 							  });
                 			},
                 			failure : function() {
                 			  Ext.Msg.show({
     							title:'Útskráning',
     							msg:'Útskráning mistókst, vinsamlegast endurhlaðið síðu.',
     							buttons:Ext.Msg.OK,
     							icon:Ext.Msg.INFO
                 			  });
                 			}
                 		});*/
                 	},
                     scope: this
                 }]
		}
    }
}
});

MyDesktop.AboutModule = Ext.extend(MyDesktop.BogusModule,{
	init : function() {
	this.launcher = {
			text : 'UM KELDUNA',
			handler: function() {
		var win = Ext.getCmp('about-us-win');
		if(!win) {
			var desktop = Kelda.Info.ObjectMgr.getInstance().get('main-desktop');
			win = desktop.createWindow({
			id:'about-us-win',
			title:'UM KELDUNA',
			manager:desktop.windows,
			bodyStyle:{
				'background-color':'white',
				color:'black'
			},
			maximizable:false,
			width:520,
			height:348
		});
		win.load({
			url: window.location.protocol+basePath+"/keldaconnect/getAboutUs" ,
			callback:function() {
				
			},
			scope: this, // optional scope for the callback
	        discardUrl: false,
	        nocache: false,
	        timeout: 30,
	        scripts: false
		});
		}
		win.show();
			},
			menu: {
				
			}
	}
	}
});

/*
var newDom = Ext.DomHelper.insertHtml('beforeEnd',Ext.getBody().dom,"<ul class=\"menu\"><li class=\"leaf first\"><a href=\"/kelda-home\" title=\"Starting page\">My page</a></li>"+
		"<li class=\"leaf\"><a href=\"/kelda-tradeing/depo-end-main\" title=\"Offer deposits\">Deposits</a></li>"+
		"<li class=\"collapsed\"><a href=\"/kelda-info\" title=\"Settings\">Information</a></li>"+
		"<li class=\"collapsed\"><a href=\"/kelda-overview\" title=\"Overviews\">Overviews</a></li>"+
		"<li class=\"collapsed\"><a href=\"/kelda-trading\" title=\"Trading functions\">Trading</a></li>"+
		"<li class=\"leaf last\"><a href=\"/kelda-logout\" title=\"Logout\">Logout</a></li>"+
		"</ul>");

MyDesktop.Kelda =  Ext.extend(MyDesktop.BogusModule,{
	init : function(){
    this.launcher = {
        text: 'Kelda',
        style:'color:black',
        handler: function() {
			return false;
		},
        menu:{
			items:constructMenu(newDom)
		}
    }
 }
});

initComponent:function() {
    Ext.Ajax.request({
    url:window.location.protocol+"/feedconnect/getFeed?feedName=getBondGraphData",
    callback:function(options,success,response) {
    var res = eval("("+response.responseText+")");
    alert(res.response[0].label);
            										
            									}
            									scope:this
            								});
            								
            							},



initComponent:function() {
            								this.addListener('beforedraw',function(){
            									Ext.Ajax.request({
                								    url:window.location.protocol+"/feedconnect/getFeed?feedName=getBondGraphData",
                								    callback:function(options,success,response) {
                								    var res = eval("("+response.responseText+")");
                								    for(i = 0; i < res.response.length; i++) {
                								    	this.series.push(res.response[i]);
                								    }
                								    this.draw();
                								 },
                								 scope:this
                								 });
            								});
            								
            							},

*/



/*
                 	var loadCfg = {
                		       url: window.location.protocol+basePath+"/feedconnect/getFeed",
                		       params:{feedName:'getTestBondGraphData'},
                		       method : 'POST'
                		};

                		var chartwindow = Ext.getCmp( 'chart_win' ) ||   //re-use it, don't lose it 
                		  new Ext.ux.Chart.OFC.Window ({
    						id:'isb-flot-parent',
    						//header:true,
    						//style:'border:none',
    						//region:'south',
    						//frame:false,
    						//collapsible:true,
    						width:400,
    						//autoWidth:true,
    						//height:170,
    						//autoHeight:true,
    						height:400,
    						
    						chartURL:'open-flash-chart.swf',
    						
    						autoLoad:{url:window.location.protocol+basePath+"/feedconnect/getFeed",
    							params:{feedName:'getTestBondGraphData'},
    							disableCaching:false
    						},
    						
    						dataUrl:"",
    						chartData:"",
    						dataFn:Ext.emptyFn,
    						
    						listeners :{
    					           show  : function(p){if(p.floating)p.setPosition(p.x||10,p.y||10);}
    					          ,chartload : function(p,obj){
    					        	  console.log('chart '+obj.id+' loaded.')
    					          }
    					          ,chartrender : function(p,obj){console.log('chart '+obj.id+' rendered.')}
    					    },
    					    tools     : [{id:'gear', handler:function(e,t,p){ p.refreshMedia();},qtip: {text:'Refresh the Chart'}  },
    					                  {id:'print', handler:function(e,t,p){ p.print();},qtip: {text:'Print the Chart'}  }
    					    ]

    						//layout:'border'
    						
                		  });
                		chartwindow.on('render',function(){
                			var chart = Ext.getCmp('isb-flot-parent'); 
                			chart.setChartDataURL(window.location.protocol+basePath+"/feedconnect/getFeed?feedName=getTestBondGraphData");
                		});
                		//chartwindow.rendered && chartwindow.load(loadCfg);
                		chartwindow.show();
 */

