function openSurvey(url)
{
	window.open(url,'NavteqSurvey','');
}
/*
 * This function monitors the current page and opens a popup survey in a separate window if the user
 * navigates to a different domain either by clicking on the url or typing it in the address bar when
 * the shopping cart contains at least 1 item.  This also happens if the user closes the browser with
 * a filled shopping cart.  
 */
function observeStoreExit(url,allowedDomain,cartStatus)
{		
	//Allow the popup to run during the user session
	var showPopup = getCookie("displayPopupSurvey");
	if(showPopup=='')
	{
		setCookie("displayPopupSurvey","true");
		showPopup='true';
	}
	
	//Flag used for the onbeforeunload handler
	var showSurvey = true;
	var changeCountryClicked = false;
	//Check if user clicks a link to a different domain	
	$$('a').each(function(item){  
	       Event.observe(item, 'click', function(event){	       
	       var href = item.toString();		    
	       var isAllowedExc = href.indexOf('MM_openBrWindow')>=0;	      
	       var isAllowed = href.indexOf(allowedDomain)>0;	
	       
	       //Check for regional selector
	       if(item.id=="change-country")
	       {
	    	   changeCountryClicked = true;	    	  
	       }
	       
	       if(showPopup=='true' && cartStatus=='nempty' && isAllowed==false)
	       {
	    	   if(isAllowedExc==false)
	    	   {   
	    		   showSurvey = true;
	    	   }
	    	   else
	    	   {
	    		   showSurvey = false;
	    	   }
	       }
	       else
	       {
	    	   showSurvey = false;
	       }
	   });                   
	});							
	
	$$('input').each(function(item){
		Event.observe(item,'click',function(e){	
			var el = Event.element(e);			
			if('checkout,update,estimateTaxShipping,estimateShipping,LoginForm_Login'.indexOf(el.name)>=0)
			{
				showSurvey = false;
			}			
		});
	});				
	
	//Used to handle browser close, refresh, and other events		
	Event.observe(window,'unload',function(e){		
		if(changeCountryClicked)
		{
			if($('country-selector').hasClassName('hidden')==false)
			{
				showSurvey = false;
			}
		}		
		if(showPopup=='true' && cartStatus=='nempty' && showSurvey==true)
		{				
			openSurvey(url);
		}
		showSurvey = true;	
		changeCountryClicked = false;
	});	
}