var updateProfileOverlay = function (id) {
	this.overlay = new Overlay(id, {	width: '350px',
										draggable: true,
										visible: false,
										zindex: 1000,
										fixedcenter: true,
										constraintoviewport: true
	});

	// Imposta la modalità debug
	// this.overlay.debugMode = true;
	
	// Stabilisce per quanto tempo resta visibile la finestra prima di essere chiusa
	// this.overlay.visibleFor = 3;
	
	
	
	// Metodo di connessione
	this.overlay.connectionMethod = 'POST';
	
	// Identifica un overlay a più passi
	//this.overlay.stepOverlay = true;
	
	// Se true nasconde il terzo passo della finestra, default false
	// this.hideAfterLoad = false;
		
	this.show = function (anchorShow, text, anchorHide) {
		this.overlay.show(null, this.overlay.generateOverlay(text), null);
	};
	
	this.stepOne = function (overlay, params, terzo) {
		// this.show è il text che viene richiamato nell'html
		this.overlay.scriptUrl = 'http://'+ location.hostname +'/gui_manager/update_profile';
		
		// passo in post il t_profile_id a this.overlay.scriptUrl
		// var actionString = '' // 'params_post=' + params;
		
		
		var actionString = '';//'response='+params+'&';
		
		//definisce cosa fare nello step 2, in realtà chiama step 2
		this.overlay.setContentByAjax(actionString, null, null, this); 
		
	};
	
	/****************************************************************************/
	// overlay per il completamento dei dati di profilo per utneti con status < 4
	/****************************************************************************/
	this.complete1 = function(profile_id){
		this.overlay = new Overlay(id, {	width: '350px',
											draggable: true,
											visible: false,
											modal : true,
											//close : false,
											zindex: 1000,
											fixedcenter: true,
											constraintoviewport: true
										});
		
		this.overlay.scriptUrl = "http://" +  location.hostname + "/overlay_manager/complete_profile";
		var  actionString = 'profile_id=' + profile_id;	
		this.overlay.setContentByAjax(actionString, null, null, this);
	}
	
	this.complete2 = function(form){
		
		var callback = {
		    success : function (o) {
			
				try{
					var data = YAHOO.lang.JSON.parse(o.responseText);
			    	
		    		if(data.result == 'KO'){
		    			OverlayManager.show('genericMessage', 'Attenzione', 'Si è verificato un errore, riprova più tardi', 'rosso');
		    		}
		    		else if(data.result == 'OK'){
		    			
		    			if(data.params['upgrade_type'] == 'upgrade20web'){
		    				OverlayManager.show('genericMessage', 'Congratulazioni', 'Dati aggiornati correttamente.<br> Hai 20 crediti per chattare con i tuoi amici', 'blu');
		    			}
		    			else{
		    				OverlayManager.show('genericMessage', 'Congratulazioni', 'Dati aggiornati correttamente', 'blu');
		    			}
		    		}
				}
				catch(e){
					OverlayManager.show('genericMessage', 'Attenzione', 'Si è verificato un errore, riprova più tardi', 'rosso');
				}
			},
			failure : function (o) { 
				    	alert(o);
			},
		    upload: function (o) {
			
				OverlayConfiguration.updateProfile.overlay.hide();
				try{
					var data = YAHOO.lang.JSON.parse(o.responseText);
			    	
		    		if(data.result == 'KO'){
		    			OverlayManager.show('genericMessage', 'Attenzione', 'Si è verificato un errore, riprova più tardi', 'rosso');
		    		}
		    		else if(data.result == 'OK'){
		    			
		    			if(data.params['upgrade_type'] == 'upgrade20web'){
		    				OverlayManager.show('genericMessage', 'Congratulazioni', 'Dati aggiornati correttamente.<br> Hai 20 crediti per chattare con i tuoi amici', 'blu');
		    			}
		    			else{
		    				OverlayManager.show('genericMessage', 'Congratulazioni', 'Dati aggiornati correttamente', 'blu');
		    			}
		    		}
				}
				catch(e){
					OverlayManager.show('genericMessage', 'Attenzione', 'Si è verificato un errore, riprova più tardi', 'rosso');
				}
			}
		};
		
		// controllo errori input
		var errors = false;
		
		if(document.getElementById('day').value == 'gg' || document.getElementById('month').value == 'mm' || document.getElementById('year').value == 'year'){
			document.getElementById('dateError').innerHTML = 'data non valida';
			errors = true;
		}
		
		var description = YAHOO.util.Dom.get('description').value; //YAHOO.util.Dom.getAttribute('description', 'value');
		if(description.length > 255){
			document.getElementById('descriptionError').innerHTML = 'descrizione non valida';
			errors = true;
		}
		
		if(document.getElementById('terms').checked == false){
			document.getElementById('termsError').innerHTML = 'devi accettare i termini e condizioni';
			errors = true;
		}
		
		if(!errors){	
			YAHOO.util.Connect.setForm(form, true);
			var scriptURL = "http://" +  location.hostname + "/gui_manager/complete_profile";
			var conn = YAHOO.util.Connect.asyncRequest("POST", scriptURL, callback);
		}
	}

};