	var puShown = false;

	function doOpen(url, h, w)
   {
           if ( puShown == true )
           {
                   return true;
           }
           var wFeatures = "toolbar=0,statusbar=1,resizable=1,scrollbars=1,menubar=0,location=1,directories=0";
           if(navigator.userAgent.indexOf('Chrome') != -1){
              wFeatures = "scrollbar=yes";
           }
           pu_window=  window.open('about:blank','wmPu',wFeatures +  ',height='+h+',width='+w);

	       var regex = new RegExp(/rv:[2-9]/);
	if (regex.exec(navigator.userAgent)) {
		pu_window.ljPop = function (jsm_url) {

			if (regex.exec(navigator.userAgent)) { // Gecko 2+
	       				this.window.open('about:blank').close();
	       			}
	       			this.document.location.href = url;
	       		};
	       		pu_window.ljPop(url);
	       	}
	       	else {
	       		pu_window.document.location.href = url;
	       	}
	       	setTimeout(window.focus);
	       	window.focus();

	        if(pu_window) {
	            pu_window.blur();
		        puShown = true;
		     }

	       	return pu_window;
   }


   function setCookie(name, value, time)
   {
       var expires = new Date();
       expires.setTime( expires.getTime() + time );
		document.cookie = name + '=' + value + '; expires=' + expires.toGMTString() + '; path=/;domain=.data.bg';
   }


   function getCookie(name) {
       var cookies = document.cookie.toString().split('; ');
       var cookie, c_name, c_value;

       for (var n=0; n<cookies.length; n++) {
           cookie  = cookies[n].split('=');
           c_name  = cookie[0];
           c_value = cookie[1];

           if ( c_name == name ) {
               return c_value;
           }
       }

       return null;
   }


   function initPu()
   {
           if ( document.attachEvent )
           {
                   document.attachEvent( 'onclick', checkTarget );
           }
           else if ( document.addEventListener )
           {
                   document.addEventListener( 'click', checkTarget, false );
           }
   }
   
   

   function checkTarget(e)
   {
	   var h = [
	   	'700',
	   	'640'
	   ];
	   var w = [
	   	'1024',
	   	'780'
	   ];
       if ( !getCookie('popundr') ) {
			setCookie('popundr', 1, 24*60*60*1000);
			var e = e || window.event;
			var win = doOpen(getPoUrl(), h[0], w[0]);
       }
   }
   
    function getPoUrl() {
		
		var	links	=	[
			'http://www.deals.bg/bg/sofia/deal/all?a_aid=databg&utm_source=DataBG&utm_medium=Popunder&utm_campaign=PUalldeals'
		];
		return links[0];
   }

   initPu();  

