/**
The file contains method the decide whether a cart message has to be displayed.
The method needs to executed on each link. Therefor it is bind to all links.

The external used variables are rendered by template
merck_base_app\staticfiles\cartridge\templates\default\application\GlobalNavigationBarInclude.isml
and detetermined by pipelines
merck_base_app\staticfiles\cartridge\pipelines\IncludeGlobalNavigationBar.xml and
merck_base_app\staticfiles\cartridge\pipelines\ProcessRequisitionMessage.xml
*/
	function alertBasket(URLEvent)
	{
		// is external link?
		var currURL = document.URL;
		var currHost = getCurrHost(currURL);
		var targetHost = getCurrHost(URLEvent.href);
		if (targetHost != currHost)
		{
			// external url -> return URL
			return URLEvent.href;
		}
		
		// do we have an old portal id?
		if (!portalIDPresent)
		{
			return URLEvent.href;
		}
		
		// determine new portal
		var isISHLink = URLEvent.href.indexOf('is-bin') >0;
		var isNewPortalBIO = false;
		
		// inspect link 
		if (isISHLink)
		{
			// no url rewriting
			isNewPortalBIO = URLEvent.href.indexOf('merck4biosciences') >0
						|| URLEvent.href.indexOf(bioPortalUUID) >0
						|| URLEvent.href.indexOf(bioPortalMerckUUID) >0;
		}
		else
		{
			// url rewriting
			isNewPortalBIO = URLEvent.href.indexOf('life-science-research') >0;
		}
		
		// do we have a portal switch?
		var portalSwitchDetected = false;
		//  was non bio and goto bio
		if ((lastPortalID != 'merck4biosciences') && isNewPortalBIO)
		{
			portalSwitchDetected = true;
		}
		// was bio goto any other portal
		if ((lastPortalID == 'merck4biosciences') && !isNewPortalBIO)
		{
			portalSwitchDetected = true;
		}		
		
		// still in the same portal
		if (!portalSwitchDetected)
		{
			return URLEvent.href;
		}
		
		// check basket
		if (!isBasketPresent)
		{
			return URLEvent.href;
		}

		// goto bio and having bio products in cart -- shouldn't happen
		if (isNewPortalBIO && (basketType=='BIO'))
		{
			return URLEvent.href;
		}
		
		// non bio products and moving to a non bio portal
		if (!isNewPortalBIO && (basketType=='NONBIO'))
		{
			return URLEvent.href;
		}
			
		// well now we have to display the message
		showMessageLayer();
		
		// set redirect target into URL
		document.getElementById("RedirectTarget").value = URLEvent.href;
		
		return false;
	} 
	
	function showMessageLayer()
	{
		document.getElementById("shopmessage").style.display =  "block";
		return false;
	}
	
	function hideMessageLayer()
	{
		document.getElementById("shopmessage").style.display =  "none";
		return false;
	}	
	
	
// Bind this function each and every link	
$(document).ready(function(){
$('a').click(function(){return (alertBasket(this));});
});
	
	


