// *********************************************** //
// Fonction externalisée pour rappel expiration    //
// @author JBA - 12/12/2007                        //
// *********************************************** //
// Define various event handlers for Dialog 
var dialog = false;

// Handle boutons Expiration
var handleYesExpiration = function() {
	dialog = false;
	this.hide();
};

var handleNoExpiration = function() {
	dialog = false;
	this.hide();

	document.location.href = "index.php?todo=abonnement_form_1";
};

// Handle boutons Expiration identification gratuite
var mailTo = null;

var handleYesIdentGratuit = function() {
	dialog = false;
	this.hide();
};

var handleNoIdentGratuit = function() {
	dialog = false;
	document.location.href = "mailto:"+mailTo;
};

function SimpleDialogInit() {
	YAHOO.widget.SimpleDialog.prototype.configModal = function(type,args,obj) {
		var modal = args[0];

		if (modal) {
			this.buildMask();

			if (typeof this.maskOpacity=='undefined') {
				this.mask.style.visibility = "hidden";
				this.mask.style.display = "block";
				this.maskOpacity = YAHOO.util.Dom.getStyle(this.mask,"opacity");
				this.mask.style.display = "none";
				this.mask.style.visibility = "visible";
			}

			if (!YAHOO.util.Config.alreadySubscribed(this.beforeShowEvent,this.showMask,this)) {
				this.beforeShowEvent.subscribe(this.showMask,this,true);
			}
			if (!YAHOO.util.Config.alreadySubscribed(this.hideEvent,this.hideMask,this)) {
				this.hideEvent.subscribe(this.hideMask,this,true);
			}
			if (!YAHOO.util.Config.alreadySubscribed(YAHOO.widget.Overlay.windowResizeEvent,this.sizeMask,this)) {
				YAHOO.widget.Overlay.windowResizeEvent.subscribe(this.sizeMask,this,true);
			}
			if (!YAHOO.util.Config.alreadySubscribed(this.destroyEvent,this.removeMask,this)) {
				this.destroyEvent.subscribe(this.removeMask,this,true);
			}
			this.cfg.refireEvent("zIndex");
		} else {
			this.beforeShowEvent.unsubscribe(this.showMask,this);
			this.beforeHideEvent.unsubscribe(this.hideMask,this);
			YAHOO.widget.Overlay.windowResizeEvent.unsubscribe(this.sizeMask);
		}
	};

	YAHOO.widget.SimpleDialog.prototype.showMask = function() {
		if (this.cfg.getProperty("modal")&&this.mask) {
			YAHOO.util.Dom.addClass(document.body,"masked");
			this.sizeMask();

			var o = this.maskOpacity;

			if (!this.maskAnimIn) {
				this.maskAnimIn = new YAHOO.util.Anim(this.mask,{
					        opacity : {
						        to : o
					        }
				        },0.5)
				YAHOO.util.Dom.setStyle(this.mask,"opacity",0);
			}

			if (!this.maskAnimOut) {
				this.maskAnimOut = new YAHOO.util.Anim(this.mask,{
					        opacity : {
						        to : 0
					        }
				        },0.5)
				this.maskAnimOut.onComplete.subscribe(function() {
					        this.mask.tabIndex = -1;
					        this.mask.style.display = "none";
					        this.hideMaskEvent.fire();
					        YAHOO.util.Dom.removeClass(document.body,"masked");
				        },this,true);

			}
			this.mask.style.display = "block";
			this.maskAnimIn.animate();
			this.mask.tabIndex = 0;
			this.showMaskEvent.fire();
		}
	};

	// Overrides the showMask function to allow for fade-out animation
	YAHOO.widget.SimpleDialog.prototype.hideMask = function() {
		if (this.cfg.getProperty("modal")&&this.mask) {
			this.maskAnimOut.animate();
		}
	};
}

function affiche_expiration(txt_header,txt_body,txt_btn1,txt_btn2) {
	SimpleDialogInit();
	var mySimpleDialog = new YAHOO.widget.SimpleDialog("simpledialog1",{
		        effect : {
			        effect : YAHOO.widget.ContainerEffect.FADE,
			        duration : 0.5
		        },
		        fixedcenter : true,
		        visible : false,
		        draggable : false,
		        close : true,
		        modal : true,
		        constraintoviewport : true
	        });
	txt_header = '<img src="../../include/themes/" + design_theme + "/img/global/logo_member.jpg" /><br />'+txt_header;
	mySimpleDialog.setHeader(txt_header);
	mySimpleDialog.setBody(txt_body);
	var myButtons = [{
		        text : txt_btn1,
		        handler : handleYesExpiration
	        },{
		        text : txt_btn2,
		        handler : handleNoExpiration,
		        isDefault : true
	        }];
	mySimpleDialog.cfg.queueProperty("buttons",myButtons);
	mySimpleDialog.render(document.body);
	mySimpleDialog.show();
}

function affiche_ident_gratuit(txt_header,txt_body,txt_btn1,txt_btn2,lang,expiration) {

	SimpleDialogInit();

	var mySimpleDialog = new YAHOO.widget.SimpleDialog("simpledialog1",{
		        effect : {
			        effect : YAHOO.widget.ContainerEffect.FADE,
			        duration : 0.5
		        },
		        fixedcenter : true,
		        visible : false,
		        draggable : false,
		        close : true,
		        modal : true,
		        constraintoviewport : true
	        });
	txt_header = '<img src="../../include/themes/" + design_theme + "/img/global/logo_member.jpg" /><br />'+txt_header;
	mySimpleDialog.setHeader(txt_header);
	mySimpleDialog.setBody(txt_body);

	if (expiration) {
		mailTo = 'info@europeansourcing.com';
	} else {

		// on définit les mails en fonction de la langue
		mailTo = 'france@europeansourcing.com';
		if (lang=='en')
			mailTo = 'info@europeansourcing.com?subject=Demande de code gratuit';
		if (lang=='de')
			mailTo = 'magali@europeansourcing.com?subject=Demande de code gratuit';
		if (lang=='es')
			mailTo = 'magali@europeansourcing.com?subject=Demande de code gratuit';
		if (lang=='it')
			mailTo = 'stefania@europeansourcing.com?subject=Demande de code gratuit';
	}

	var myButtons = [{
		        text : txt_btn1,
		        handler : handleYesIdentGratuit
	        },{
		        text : txt_btn2,
		        handler : handleNoIdentGratuit,
		        isDefault : true
	        }];
	mySimpleDialog.cfg.queueProperty("buttons",myButtons);

	mySimpleDialog.render(document.body);

	mySimpleDialog.show();
}

