/*
 * SimpleModal Confirm Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2010 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: confirm.js 238 2010-03-11 05:56:57Z emartin24 $
 *
 */

jQuery(function ($) {
	$('#confirm-dialog input.confirm, #confirm-dialog a.confirm').click(function (e) {
		e.preventDefault();

                if ($.cookie('acces')== 'oui') {
                   //alert($.cookie('acces'));
                   window.location.href = 'http://www.gref-bretagne.com/Groups/publication_gref/publications_2011/observatoire/barometre_7.pdf';
                }
                else {
                  //alert('pas de cookie');
                  $.cookie('acces', 'oui');
		  // example of calling the confirm function
		  // you must use a callback function to perform the "yes" action
		  confirm("<br>Votre avis nous intéresse !<br><br>Nous vous proposons de répondre à une dizaine de questions concernant la publication que vous consultez sur notre site. <br> Nous vous remercions de votre participation.", function () {
			window.location.href = 'http://www.intranet.gref-bretagne.com/limesurvey2/index.php?sid=81288&lang=fr';
		});
                }
	});
});

function confirm(message, callback) {
	$('#confirm').modal({
		closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
		position: ["20%",],
		overlayId: 'confirm-overlay',
		containerId: 'confirm-container',
		onShow: function (dialog) {
			$('.message', dialog.data[0]).append(message);

			// if the user clicks "yes"
			$('.yes', dialog.data[0]).click(function () {
				// call the callback
				if ($.isFunction(callback)) {
					callback.apply();
				}
				// close the dialog
				$.modal.close();
			});
			$('.no', dialog.data[0]).click(function () {
				window.location.href = 'http://www.gref-bretagne.com/Groups/publication_gref/publications_2011/observatoire/barometre_7.pdf';
			});

		}
	});
}


