// Path to the blank image must point to a valid location on your server
Ext.BLANK_IMAGE_URL = 'js/ext-3.0.0/resources/images/default/s.gif';


Shadowbox.init({
    skipSetup: true
});

//Main application entry point
Ext.onReady( function() {
	/*
	//test youtube
	//www.condivisihome.it
	//	var DEVELOPER_KEY = 'AI39si7_xgHwelaWNI7ufK8u_GQMlIH8DPnNwnF0738CI3zQsFxSiAFG1wwHv_iaG4FU_KiesDPvQyTExWkAJeHze_22Ng_Vvg';
	//localhost
	var DEVELOPER_KEY = 'AI39si4aXbYpmRp7cGOxyQm72SIXhyKmDdJiwnSp2B7VZ9yW4j7fhWP5kJatrV4PUr4OxMZczxj8vOIECSv-GMVIbWXu5pB1yw';
	
	var playerPanel = new Ext.ux.YoutubePlayer({
   		developerKey : DEVELOPER_KEY,	
   		playerId	 : 'myplayer',
   		border		 : false,
   		ratioMode    : 'strict',
   		hideMode     : 'visibility',
   		bgColor 	 : "#000000",
   		bodyStyle 	 : 'background-color:#000000;'
   	});
   
   	playerPanel.on('ready', function(panel, player) {
   		panel.cueVideoById('u1zgFlCw8Aw', 0);
   	}, playerPanel);
   	
   	
   	
   	var w = new Ext.Window({
        title        : 'Ext.ux.YoutubePlayer',
        layout 		 : 'fit',
        maximizable  : true,
        animCollapse : false,
        hideMode 	 : 'visibility',
        collapsible  : true,
        resizable    : true,
        items        : [playerPanel], 
        bbar		 : new Ext.ux.YoutubePlayer.Control({
        	player   : playerPanel,
        	border	 : false,
        	id 		 : 'control', 
        	style	 : 'border:none;'
        }),
        listeners   : {
        	'resize'   		 : function(){this.bottomToolbar.fireEvent('resize')}
    	},
        height      : 400,
        width       : 500
    });   	
   	 
   
    w.show();
    */    

	
	
	//
	
	Ext.get('recuperaPasswordBtn').on('click', function(){
		
		var useremail = Ext.getDom('username').value;
		if(isStringEmpty(useremail)||!validateEmail(useremail)){
			Ext.MessageBox.alert('Attenzione', '<span >Inserire un indirizzo email valido</span>');
			return;
		}
		
		if(!Ext.getCmp('recuperaPasswordWinId')){
			
			var recuperaPasswordWin = new Ext.Window({
				id: 'recuperaPasswordWinId',
				title: 'Recupera la password',
				cntentEl: 'recuperaPasswordWin',
				layout: 'fit',
				width: 400,
				height: 350,
				closable: true,
				resizable: false,
				draggable: false,
				closeAction:'hide',
				modal:true,
				bodyStyle: 'padding:10px; background:#FFFFFF',
				items:[
				       new Ext.Panel({
				    	   layout:'fit',
				    	   cls:'',
				    	   bodyStyle: 'padding:10px; background:#FFFFFF',
				    	   contentEl:'recuperaPasswordPnl'
				       })
				],
				buttons: [
			              {
			            	  text: 'Invia',
			            	  handler: function(){
			            	  		var ok = jcap();
			            	  		if(ok){
			            	  			var email = Ext.getDom('username').value;
			            	  			agenziaManagerDWR.inviaPassword(email, {
				            	  				callback : function(mailInviata) {
			            	  						if(mailInviata){
			            	  							Ext.MessageBox.alert('Conferma invio password', '<span >La tua password &egrave; stata inviata all\'indirizzo di posta specificato</span>');
			            	  						} else {
			            	  							Ext.MessageBox.alert('Attenzione', '<span >L\'Email (Username) inserita non &egrave; stata trovata nella base dati di CondivisiHome</span>');
			            	  						}
			            	  						Ext.getCmp('recuperaPasswordWinId').hide();

				            	  			}
				            	  		});
			            	  			
			            	  			
			            	  			
			            	  		}
			              		}
			              },{
			            	  text: 'Annulla',
			            	  handler: function(){
			            	  	Ext.getCmp('recuperaPasswordWinId').hide();
			            	  }
			              }
			              
			              ]
			});
			recuperaPasswordWin.on('show', function(){
				Ext.getDom('tuaEmail').innerHTML = ''; 
				sjcap();
			});
		}
		Ext.getCmp('recuperaPasswordWinId').show();
		Ext.getDom('tuaEmail').innerHTML = Ext.getDom('username').value; 
//		sjcap();
	});
	
	
	new Ext.form.TextField({
		applyTo:'username',
		listeners: {
            specialkey: function(field, e){
            // e.HOME, e.END, e.PAGE_UP, e.PAGE_DOWN, e.TAB, e.ESC, arrow keys: e.LEFT, e.RIGHT, e.UP, e.DOWN
            if (e.getKey() == e.ENTER)  doLogin();                
        }
	}
	});
	

	new Ext.form.TextField({
		inputType: 'password',
		applyTo:'password',
		listeners: {
	            specialkey: function(field, e){
	            // e.HOME, e.END, e.PAGE_UP, e.PAGE_DOWN, e.TAB, e.ESC, arrow keys: e.LEFT, e.RIGHT, e.UP, e.DOWN
	            if (e.getKey() == e.ENTER)  doLogin();                
	        }
		}
	});
	
	new Ext.Button({
		text:'Accedi',
		applyTo:'loginBtn',
		handler:function(){doLogin();}
	});
	
	var iscrizioneWin;
	Ext.get('iscrizioneBtn').on('click', function(){
		if(!Ext.getCmp('iscrizioneWin')){
			iscrizioneWin = new Ext.Window({
				id: 'iscrizioneWin',
				title: 'Registrazione CondivisiHome',
				layout: 'fit',
				width: 400,
				height: 640,
				closable: true,
				resizable: false,
				draggable: false,
				modal:true,
//				autoScroll: true,
				bodyStyle: 'padding:10px; background:#FFFFFF',
				items: [{
			        // Fieldset
			        xtype:'fieldset',
			        columnWidth: 0.5,
			        title: 'Dati dell\'agenzia*',
			        autoHeight:true,
			        defaults: {
			            anchor: '-20' // leave room for error icon

			        },
			        defaultType: 'textfield',
			        items :[{
			        		id: 'nomeAgenzia',
			                fieldLabel: 'Nome agenzia',
			                autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '255'}

			            }, {
			            	id: 'indirizzo',
			                fieldLabel: 'Indirizzo',
			                autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '255'}
			            }, {
			            	id: 'cap',
			                fieldLabel: 'CAP',
			                autoCreate: {tag: 'input', type: 'text', size: '5', autocomplete: 'off', maxlength: '5'}
			            }, {
			            	id: 'pivaCfiscale',
			                fieldLabel: 'P.Iva o CF',
			                autoCreate: {tag: 'input', type: 'text', size: '16', autocomplete: 'off', maxlength: '16'}
			            }, {
			            	id: 'telefono',
			                fieldLabel: 'Telefono',
			                autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '45'}
			                	
			            }, {
			            	id: 'cellulare',
			                fieldLabel: 'Cellulare',
			                autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '45'}
			                	
			            }, {
			            	id: 'citta',
			                fieldLabel: 'Citt&agrave;',
			                autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '45'}
			                	
			            }, {
			            	id: 'provincia',
			                fieldLabel: 'Provincia',
			                autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '100'}
			            }
			        ]
			    },{
			        // Fieldset
			        xtype:'fieldset',
			        columnWidth: 0.5,
			        title: 'Dati utente*',
			        autoHeight:true,
			        defaults: {
			            anchor: '-20' // leave room for error icon

			        },
			        defaultType: 'textfield',
			        items :[{
		        			id: 'nome',
			                fieldLabel: 'Nome',
			                autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '50'}
		            	},{
			        		id: 'cognome',
			                fieldLabel: 'Cognome',
			                autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '50'}
		            	},{
			        		id: 'email',
			                fieldLabel: 'Email',
			                autoCreate: {tag: 'input', type: 'text', size: '20', autocomplete: 'off', maxlength: '50'}
			            }, {
			            	id: 'utentePwd',
			                fieldLabel: 'Password',
			                autoCreate: {tag: 'input', type: 'password', size: '20', autocomplete: 'off', maxlength: '20'}
			            }, {
			            	id: 'utentePwdConfirm',
			                fieldLabel: 'Ripeti password',
			                autoCreate: {tag: 'input', type: 'password', size: '20', autocomplete: 'off', maxlength: '20'}
			            }
			        ]
			    },{
			        // Fieldset
			        xtype:'fieldset',
			        columnWidth: 0.5,
			        title: 'Condizioni d\'uso e Normativa sulla privacy**',
			        autoHeight:true,
			        defaults: {
			            anchor: '-20' // leave room for error icon

			        },
			        defaultType: 'checkbox',
			        items :[{
			        		id: 'condizioni',
			                fieldLabel: 'Accetto'
			            }
			        ]
			    
			    	
			    },{
					xtype:'panel',
					autoHeight:true,
//					html:'<b><a href=\'javascript:setIscrizione()\'>Tutti i dati sono obbligatori*</a></b><br>Dichiaro di aver letto e accettato le <a href=\'javascript:showContratto()\'><b>Condizioni d\'uso</b></a> e la <a href=\'javascript:showPrivacy()\'><b>Normativa sulla privacy di CondivisiHome**</b></a>',
					html:'<b><a href=\'javascript:setIscrizione()\'>Tutti i dati sono obbligatori*</a></b><br>Dichiaro di aver letto e accettato la <a href=\'javascript:showPrivacy()\'><b>Normativa sulla privacy di CondivisiHome**</b></a>',
					bodyBorder: false,
					border:false
				}],
			    buttons: [
			              {
			            	  text: 'Iscriviti ora',
			            	  handler: function(){
			            	  		saveIscrizione();
			              		}
			              },{
			            	  text: 'Annulla',
			            	  handler: function(){
			            	  	iscrizioneWin.hide();
			            	  	resetIscrizione();
			            	  }
			              }
			              
			              ]
			    
			});
			
		}
		iscrizioneWin.show();
	});
});

function showContratto(){
	window.open('pdf/contratto.pdf');
	
}
function showPrivacy(){
	window.open('pdf/privacy.pdf');
	
}

function saveIscrizione(){
	var errors = new Array();
	var agenzia = {};
	var utente = {};
	//agenzia
	var nomeAgenzia = Ext.getCmp('nomeAgenzia').getValue();
	var indirizzo = Ext.getCmp('indirizzo').getValue();
	var cap = Ext.getCmp('cap').getValue();
	var pivaCfiscale = Ext.getCmp('pivaCfiscale').getValue();
	var citta = Ext.getCmp('citta').getValue();
	var provincia = Ext.getCmp('provincia').getValue();
	var telefono = Ext.getCmp('telefono').getValue();
	var cellulare = Ext.getCmp('cellulare').getValue();
	agenzia.nomeAgenzia = nomeAgenzia;
	agenzia.indirizzo = indirizzo;
	agenzia.cap = cap;
	agenzia.pivaCfiscale = pivaCfiscale;
	agenzia.citta = citta;
	agenzia.provincia = provincia;
	agenzia.telefono = telefono;
	agenzia.cellulare = cellulare;
	//utente
	var nome = Ext.getCmp('nome').getValue();
	var cognome = Ext.getCmp('cognome').getValue();
	var utenteName = Ext.getCmp('email').getValue();
	var utentePwd = Ext.getCmp('utentePwd').getValue();
	var utentePwdConfirm = Ext.getCmp('utentePwdConfirm').getValue();
	utente.nome = nome;
	utente.cognome = cognome;
	utente.utenteName = utenteName;
	utente.utentePwd = utentePwd;
	//condizioni
	var condizioni = Ext.getCmp('condizioni').getValue();
	
	var nomeAgenziaOk = !isStringEmpty(nomeAgenzia);
	var indirizzoOk = !isStringEmpty(indirizzo);
	var capOk = !isStringEmpty(cap);
	var pivaCfiscaleOk = !isStringEmpty(pivaCfiscale);
	var cittaOk = !isStringEmpty(citta);
	var provinciaOk = !isStringEmpty(provincia);
	
	var telefonoCellulareOk = !isStringEmpty(telefono)||!isStringEmpty(cellulare);
	
	var nomeOk = !isStringEmpty(nome);
	var cognomeOk = !isStringEmpty(cognome);
	var utenteNameOk = !isStringEmpty(utenteName);
	var utentePwdOk = !isStringEmpty(utentePwd);
	var utentePwdConfirmOk = !isStringEmpty(utentePwdConfirm);
	var condizioniOk = condizioni;
	if(!nomeAgenziaOk){
		var error = {};
		error.msg = 'Inserire il Nome dell\'agenzia';
		errors.push(error);
	}
	if(!indirizzoOk){
		var error = {};
		error.msg = 'Inserire l\'indirizzo';
		errors.push(error);
	}
	
	var capIsNum = validateInput('numeric',cap);
	if(!capOk){
		var error = {};
		error.msg = 'Inserire il cap';
		errors.push(error);
	} else if(!capIsNum){
		var error = {};
		error.msg = 'Il cap deve essere un numero';
		errors.push(error);
	}
	var cfOk = controllaCF(pivaCfiscale);
	var pivaOk = controllaPIVA(pivaCfiscale);
	if(!pivaCfiscaleOk){
		var error = {};
		error.msg = 'Inserire la P.Iva o il CF';
		errors.push(error);
	} else if(!(cfOk||pivaOk)){
			var error = {};
			error.msg = 'Inserire una P.Iva o CF validi';
			errors.push(error);
	}
	if(!telefonoCellulareOk){
		var error = {};
		error.msg = 'Inserire almeno un dat fra il Telefono e il Cellulare';
		errors.push(error);
	}
	if(!cittaOk){
		var error = {};
		error.msg = 'Inserire la citt&agrave;';
		errors.push(error);
	}
	if(!provinciaOk){
		var error = {};
		error.msg = 'Inserire la provincia';
		errors.push(error);
	}
	
	if(!nomeOk){
		var error = {};
		error.msg = 'Inserire il nome dell\'utente';
		errors.push(error);
	}
	if(!cognomeOk){
		var error = {};
		error.msg = 'Inserire il cognome dell\'utente';
		errors.push(error);
	}
	if(!utenteNameOk){
		var error = {};
		error.msg = 'Inserire l\'email';
		errors.push(error);
	} else if(!validateEmail(utenteName)){
		var error = {};
		error.msg = 'Inserire un indirizzo email valido';
		errors.push(error);
	}
	if(!utentePwdOk){
		var error = {};
		error.msg = 'Inserire la password'; 
		errors.push(error);
	}
	if(!utentePwdConfirmOk){
		var error = {};
		error.msg = 'Inserire la password di conferma';
		errors.push(error);
	}
	if(utentePwdOk&&utentePwdConfirmOk){
		var eq = utentePwd==utentePwdConfirm
		if(!eq){
			var error = {};
			error.msg = 'La password di conferma non coincide con la password';
			errors.push(error);
		}
	}
	if(!condizioniOk){
		var error = {};
		error.msg = 'Per iscriversi &egrave; necessario accettare "la Normativa sulla privacy di CondivisiHome"';
		errors.push(error);
	}
	
	if(errors.length>0){
//		var msgs = '<b>Per procedere, correggere i seguenti errori</b>: <br>';
		var msgs = '';
		for(var i=0; i<errors.length; i++){
			var msg = errors[i].msg;
			msgs += "&bull; " + msg + "<br>";
		}
		Ext.MessageBox.alert('Attenzione', '<span >' + msgs + '</span>');
	} else {
		agenziaManagerDWR.iscriviAgenzia(agenzia, utente, {
			callback : function(idAgenzia) {
				if(idAgenzia&&idAgenzia>0){
					utente.idAgenzia = idAgenzia;
					Ext.MessageBox.alert('Info', '<span >' + "<b>Agenzia iscritta correttamente, riceverai a breve una email di conferma!</b>" +
							"<br>Adesso puoi accedere all'area privata con l'email e la password scelti in fase di registrazione" + '</span>');
					Ext.getCmp('iscrizioneWin').hide();
            	  	resetIscrizione();
				} else if (idAgenzia&&idAgenzia==-2){
					Ext.MessageBox.alert('Attenzione', "<span >Non &egrave; stato possibile effettuare la registrazione.<br>" +
							"La P.IVA (o CF) inserita &egrave; gi&agrave; presente in archivio.<br>" +
							"Contattare CondivisiHome per maggiori informazioni.</span>");
				}
			
		}
	});
		
	}
	
}

function resetIscrizione(){
	var nomeAgenzia = Ext.getCmp('nomeAgenzia').setValue('');
	var indirizzo = Ext.getCmp('indirizzo').setValue('');
	var cap = Ext.getCmp('cap').setValue('');
	var pivaCfiscale = Ext.getCmp('pivaCfiscale').setValue('');
	var citta = Ext.getCmp('citta').setValue('');
	var provincia = Ext.getCmp('provincia').setValue('');
	//utente
	var nome = Ext.getCmp('nome').setValue('');
	var cognome = Ext.getCmp('cognome').setValue('');
	var utenteName = Ext.getCmp('email').setValue('');
	var utentePwd = Ext.getCmp('utentePwd').setValue('');
	var utentePwdConfirm = Ext.getCmp('utentePwdConfirm').setValue('');
	//condizioni
	var condizioni = Ext.getCmp('condizioni').setValue('');
}

function setIscrizione(){
	return;
	var nomeAgenzia = Ext.getCmp('nomeAgenzia').setValue('Agenzia Test');
	var indirizzo = Ext.getCmp('indirizzo').setValue('Via Poli 3');
	var cap = Ext.getCmp('cap').setValue('50100');
	var pivaCfiscale = Ext.getCmp('pivaCfiscale').setValue('DSPDGI72D09A271J');
	var citta = Ext.getCmp('citta').setValue('Firenze');
	var provincia = Ext.getCmp('provincia').setValue('Firenze');
	//utente
	var nome = Ext.getCmp('nome').setValue('Paolo');
	var cognome = Ext.getCmp('cognome').setValue('Rossi');
	var utenteName = Ext.getCmp('email').setValue('paolo@hotmail.it');
	var utentePwd = Ext.getCmp('utentePwd').setValue('aaaa');
	var utentePwdConfirm = Ext.getCmp('utentePwdConfirm').setValue('aaaa');
	//condizioni
	var condizioni = Ext.getCmp('condizioni').setValue('1');
}

function showCondivisiHomeVideo(video){
	
//	return;
	
	var generale = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/Qv01UZgKL2s?fs=1&amp;hl=it_IT"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Qv01UZgKL2s?fs=1&amp;hl=it_IT" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
	
	var semplice = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/3YzKqx4NrRE?fs=1&amp;hl=it_IT"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/3YzKqx4NrRE?fs=1&amp;hl=it_IT" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
	var prezzo = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/AmlteX0nvQ4?fs=1&amp;hl=it_IT"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/AmlteX0nvQ4?fs=1&amp;hl=it_IT" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
	var portali = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/8zCBxGQtiEk?fs=1&amp;hl=it_IT"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/8zCBxGQtiEk?fs=1&amp;hl=it_IT" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
	var dati = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/wdlRJMXjaSI?fs=1&amp;hl=it_IT"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/wdlRJMXjaSI?fs=1&amp;hl=it_IT" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
	var importazione = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/N1xTVmBRHVY?fs=1&amp;hl=it_IT"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/N1xTVmBRHVY?fs=1&amp;hl=it_IT" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
	var condividere = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/BDsr6MrBX5g?fs=1&amp;hl=it_IT"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/BDsr6MrBX5g?fs=1&amp;hl=it_IT" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
	var sito = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/7qZomIEYOjc?fs=1&amp;hl=it_IT"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/7qZomIEYOjc?fs=1&amp;hl=it_IT" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
	var assistenza = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/YI3_p4ZJmWY?fs=1&amp;hl=it_IT"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/YI3_p4ZJmWY?fs=1&amp;hl=it_IT" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
	var ascolta = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/vNqu7jvsYlU?fs=1&amp;hl=it_IT"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/vNqu7jvsYlU?fs=1&amp;hl=it_IT" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
	var gestire = '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/RGtVepYS7So?fs=1&amp;hl=it_IT"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/RGtVepYS7So?fs=1&amp;hl=it_IT" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>';
	var html = eval(video);
	if(html){
		Shadowbox.open({
	        content:    html,
	        player:     "html",
	        title:      ""
	        ,width:      480
	        ,height:     385
	        ,autoplayMovies:true
	        ,showMovieControls:true

	    });
	}

	
}

function navTo(pageId){
	$('#home-content').hide();
	$('#chi-siamo-content').hide();
	$('#faq-content').hide();

	$('#'+pageId).fadeIn();
}

function showFaq(){
	if(!Ext.getCmp('faqWinId')){
		var faqWin = new Ext.Window({
			id: 'faqWinId',
			title: 'F.A.Q. (Frequently Asked Questions)',
			cntentEl: 'faqWin',
			layout: 'fit',
			width: 600,
			height: 450,
			closable: true,
			resizable: false,
			draggable: false,
			closeAction:'hide',
			modal:true,
			items:[
			       new Ext.Panel({
			    	   height: 450,
			    	   layout:'fit',
			    	   id:'faqPanelId',
			    	   autoScroll:true,
			    	   bodyStyle: 'padding:10px; background:#FFFFFF',
			    	   contentEl:'faqPnl',
			    	   bodyBorder:false
			       })
			],
			buttons: [
		             {
		            	  text: 'Chiudi',
		            	  handler: function(){
		            	  	Ext.getCmp('faqWinId').hide();
		            	  }
		              }
		              
		              ]
		});
		
	}
	Ext.getCmp('faqWinId').show();
	
}

function scrollToFaq(idFaq){
	var topPanel = Ext.get('faqPnl').getY();
	var topFaq = Ext.get(idFaq).getY();
	Ext.getCmp('faqPanelId').body.scrollTo('top', topFaq-topPanel, true);
}

function doLogin(){
	var username = Ext.getDom('username').value;
	var password = Ext.getDom('password').value;
	utenteManagerDWR.userExists(username, password, {
		callback: function(exists){
			if(exists){
				window.location = 'desktop.htm';
			} else {
				Ext.MessageBox.alert('Attenzione', '<span >' + 'Email o password errate' + '</span>');
			}
		},
		errorHandler: function(errorString, exception){
			Ext.MessageBox.alert('Error', '<span >' + 'Email o password errate' + '</span>');
		}
		
	});
	
}



