var InviteFriendsOverlay = function (id) {
	this.overlay = new Overlay(id, {	width: '350px',
										draggable: true,
										visible: false,
										zindex: 1000,
										fixedcenter: true,
										constraintoviewport: true
	});

	// Identifica un overlay a pił passi
	this.overlay.stepOverlay = true;
		
	this.show = function (anchorShow, text, anchorHide) {
		this.overlay.show(null, this.overlay.generateOverlay(text), null);
	};
	
	this.stepOne = function (overlay, num_contacts) {		
		var email = YAHOO.util.Dom.get("email").value;
		var password = YAHOO.util.Dom.get('pass').value;
		var disclaimer = YAHOO.util.Dom.get('discl').checked;
		
		this.overlay.scriptUrl = "http://" + conf.baseUrl + "/overlay_manager/invita_amici";
		var actionString = 'email=' + email + '&password=' + password + '&disclaimer=' + disclaimer;
		// definisce cosa fare nello step 2, in realtą chiama step 2
		this.overlay.setContentByAjax(actionString, null, null, this);
	};
	
	this.stepTwo = function (overlay, num_contacts) {
		var contatti = "";
		
		for(i=0; i<num_contacts; i++) {
			if(YAHOO.util.Dom.get("contact_" + i).checked) {
				contatti += "$";
				contatti += YAHOO.util.Dom.get("contact_" + i).value;
			}
		}
		
		this.overlay.scriptUrl = "http://" + conf.baseUrl + "/gui_manager/invita_amici";
		var actionString = "contacts=" + contatti;
		this.show(null, this.overlay.loaderContent.body, null);
		this.overlay.getResultByAjax(actionString, this, this.setBodyByResult);
	};
	
	this.setBodyByResult = function (obj, pResult) {
		var responseText = pResult.header + "<br>" + pResult.body;		
		obj.show(null, responseText, null);		
	};
};

OverlayConfiguration.inviteFriends = new InviteFriendsOverlay('textOverlay');
OverlayManager.inviteFriends = function (args) {
	OverlayConfiguration.inviteFriends.stepOne('inviteFriends', args[0]);
};