Jquery script with cookies

Jquery script with cookies

I have a script that open up a fancybox form once browser closed/refreshed/back is pressed (onbeforeunload).
Now I'm trying to make the fancybox pop up only once so i installed the cookies plugin and started to play with it but it doesn't seems to work , maybe you can help me here
  1.  <html dir="ltr"> 
  2. <head> 
  3. <script type="text/javascript" src="jquery14.js"></script>
  4. <script type="text/javascript" src="jquery.cookie.js"></script>
  5. <script src="fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script>
  6. <link rel="stylesheet" href="fancybox/jquery.fancybox-1.3.1.css" type="text/css" media="screen"/>
  7. <script type="text/javascript">
  8. $.cookie('appeal'); // get cookie
  9. $.cookie('appeal', 'the_value'); // set cookie

  10. function PopIt() 
  11. {
  12. if ($.cookie('appeal') == null) 
  13. {
  14. $.cookie('appeal', 'cookieValue', { expires: 7 });
  15. $("a#trigger").trigger('click');
  16. window.onbeforeunload = UnPopIt;
  17. return "Before you leave:\nPlease take a few seconds to answer 2 questions\nso we can better assist you and others in the future. \nThanks!";
  18. }
  19. else { }
  20. }

  21. function UnPopIt()  { /* nothing to return */ } 
  22.  
  23. $(document).ready(function() {
  24. window.onbeforeunload = PopIt;
  25.  
  26. $("a#trigger").fancybox({
  27. 'hideOnContentClick': false,
  28. 'showCloseButton': true
  29. });
  30.  
  31. $("a[id!=trigger]").click(function(){ window.onbeforeunload = UnPopIt; });
  32. });
  33. </script>
  34. </head> 
  35. <body> 
  36. <p>This page is an exit-pop</p>
  37. <div style="display: none;">
  38. <a id="trigger" href="#popup">&nbsp;</a>
  39. <div id="popup" style="width: 250px; height: 400px;">
  40. My Form is here
  41. </div>
  42. </body> 
  43. </html>