	    function toAbsURL(s) {
				var l = location, h, p, f, i;
				if (/^\w+:/.test(s)) {
					return s;
				}
				
				h = l.protocol + '//' + l.host;
				if (s.indexOf('/') == 0) {
					return h + s;
				}
				
				p = l.pathname.replace(/\/[^\/]*$/, '');
				f = s.match(/\.\.\//g);
				if (f) {
					s = s.substring(f.length * 3);
					for (i = f.length; i--;) {
						p = p.substring(0, p.lastIndexOf('/'));
					}
				}
				return h + p + '/' + s;
			}
			
			 jQuery.expr[':'].regex = function(elem, index, match) {
			    var matchParams = match[3].split(','),
			        validLabels = /^(data|css):/,
			        attr = {
			            method: matchParams[0].match(validLabels) ? 
			                        matchParams[0].split(':')[0] : 'attr',
			            property: matchParams.shift().replace(validLabels,'')
			        },
			        regexFlags = 'ig',
			        regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
			    return regex.test(jQuery(elem)[attr.method](attr.property));
			}   

	/* decaler handler for popup hiding so it can be bind & unbind */
	     var popup_hide = function() {
	      no_to_survey();//save a cookie so popup would not keep popping up
		  parent.jQuery('#popup').jqmHide(); 
		  return false;
		};			
			
      $().ready(function() {
		        $('#popup').
		          jqm({overlay: 50, modal: true, trigger: false}).
		          jqmAddClose('#popup input.close');
		
						
				$('a:regex(href,^:["http://")').click(function() {
					isExit=false;
				});
				$('a[@href^="http://"]').addClass('exitLink');
				$('a[href^="http://www.promensil.ca"]').removeClass('exitLink');
		    $('a[href^="http://promensil.ca"]').removeClass('exitLink');
		    $('a.noPopup').removeClass('exitLink');
		        $('a.exitLink').click(function(e) {
		        	var no_survey = GetCookie('no_to_popup_survey');
					if (no_survey== null) {	
				          e.preventDefault();
				          var href = toAbsURL($(this).attr('href'));
						  $('#popup iframe.survey_pop').contents()
												.find('#content a.no_thanks').bind('click',  function() {
							  no_to_survey();
							});
				          $('#popup iframe.survey_pop').contents()
												.find('#content a.no_thanks').unbind('click', popup_hide);
				
				          $('#popup iframe.survey_pop').contents()
										.find('#content a.no_thanks')
											.attr("href", href);    
				
					          $('#popup').
					            jqmShow();
					}
		     });

      });
      
    isExit = true;
    

      
	function ExitPop(e, exit) {
		if (exit) {
			var version = GetCookie('popup_survey_version');
			//alert(version);
			var no_survey = GetCookie('no_to_popup_survey');
			if (no_survey== null && (version == null || version != '1.0')) {
				isExit=false;
				if (e)
					e.preventDefault();
				/*$('#popup iframe.survey_pop').contents()
						.find('#content a.no_thanks')
				.click(function() { 
					parent.jQuery('#popup').jqmHide(); 
					return false; });*/
				$('#popup iframe.survey_pop').contents()
						.find('#content a.no_thanks')
						.bind('click', popup_hide);
				$('#popup').
				jqmShow();
				return '\n\nAvant de quitter la page, souhaiteriez-vous obtenir un coupon de 5 $ pour les produits Promensil? Si oui, cliquez sur \'Annuler\' pour demeurer sur la page actuelle.\n\n';
			}
		}
    }
    
    var expDays = 30; // number of days the cookie should last
    
    function no_to_survey() {
		var no_survey = GetCookie('no_to_popup_survey');
		if (no_survey == null) {
			var exp = new Date();
			//exp.setTime(exp.getTime() + 60*2*1000);
			exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
			SetCookie('no_to_popup_survey', 'yes', exp);
		}
	}

	function SetCookie (name, value, expires) {
		var argv = SetCookie.arguments;
		var argc = SetCookie.arguments.length;
		var expires = (argc > 2) ? argv[2] : null;
		var path = (argc > 3) ? argv[3] : null;
		var domain = (argc > 4) ? argv[4] : null;
		var secure = (argc > 5) ? argv[5] : false;
		document.cookie = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
	}

    
    function getCookieVal (offset) {
	  var endstr = document.cookie.indexOf (";", offset);
	  if (endstr == -1) { endstr = document.cookie.length; }
	  return unescape(document.cookie.substring(offset, endstr));
	}

	function GetCookie (name) {
	  var arg = name + "=";
	  var alen = arg.length;
	  var clen = document.cookie.length;
	  var i = 0;
	  while (i < clen) {
	    var j = i + alen;
	    if (document.cookie.substring(i, j) == arg) {
	      return getCookieVal (j);
	      }
	    i = document.cookie.indexOf(" ", i) + 1;
	    if (i == 0) break; 
	    }
	  return null;
	}
    
    window.onbeforeunload = function(e){
				return ExitPop(e,isExit);    
    };
