var ACTION;
document.onclick = function startDownload(e)
{

	if (!e) var elemClicked = window.event.srcElement;
	else var elemClicked = e.target;

	if(elemClicked) {
		switch (elemClicked.tagName) 
		{
			case 'IMG':
			case 'DIV':
			case 'STRONG':
			case 'B':
				if(elemClicked.parentNode) {
					if(elemClicked.parentNode.tagName != 'A') 
						break;
					else
						elemClicked = elemClicked.parentNode;
				}
				else
					break;
			case 'A':
			case 'AREA':

				var anchor = elemClicked; //get reference to anchor
				var href = anchor.href; //get href text

				if(href) {
					var eventId	= anchor.getAttribute('EventId'); //get the event id - coded as an attribute in the link
					var advertId = anchor.getAttribute('a'); //get the ad id - coded as an attribute in the link
                    var promoid = anchor.getAttribute('PromoID'); //get the promo id - coded as an attribute in the link
                    
					//find the double hash
					if(href.indexOf('##') != -1)
					{
					 dodownload(eventId, advertId, promoid); //start download	
					}//if(href.indexOf ...
				} //if(href ...
				break;
		} //end switch(elemClicked ...
	} //end if(elemClicked ...
}

function dodownload(eventId, advertId, promoid) 
{
            
   	if(country == '123456')
	{
		alert('Download Unavailable');
		return false;
	}
	else
	{	
                   
		window.status = 'downloading ... please wait.'; //status message
	
		var qryString = window.location.search;
		var iframe = document.getElementById("dlh");
		var EventId = 0;
	
	    if(!isNaN(eventId))
		        EventId = eventId;
		
		if(arguments.length > 1) {
		    if(!isNaN(arguments[1]))
		        adid = arguments[1];
		    
		    if(arguments.length > 2) {
			    if(!isNaN(arguments[2]))
			        ban = arguments[2];
			}
		}
	
		
		ACTION = '02'; // download tracking index tools
	
	    var downloadPath;
	    
		if(qryString.indexOf('?') == -1) //no querystring
			qryString = '?' + window.location.search
	
	    if (EventId == null)
	    {
	        EventId = 25;
	    }
		
	    if(qryString.length == 1)
	    {
	         downloadPath = '/websys/TrackingDownload.asp?VT='+ vt +'&EventId=' + EventId;
	    }
	    else
	    {
	        downloadPath = '/websys/TrackingDownload.asp'+ qryString +'&EventId=' + EventId;
	    }	    
	    
		var iframeSrc = downloadPath;
		
	
		window.location = 'http://'+dlsource+'&btag1='+vt+'&btag2='+adid+'&btag3='+ban+'&btag4='+src+'&ul='+ul + DwnlPCMGUID
		
		if(iframe == null)  
		{
			//track download- new frame
			iframe = document.createElement('iframe');
			iframe.setAttribute('id', 'dlh'); //set the anchor style to hidden
	
			document.body.insertBefore(iframe, null); //add to DOM - x browser implementation.
			iframe.style.display = 'none'; //hide the iframe
		}
	
		iframe.src = iframeSrc; //tracking	
	}

}

