/* Download Helper Client Version 2.2 */
/* Craig Ferndale  May 2006 */
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) {
						if(advertId && advertId != '') {
						    if(promoid && promoid != '')
							    dodownload(eventId, advertId, promoid); //start download
							else
							    dodownload(eventId, advertId); //start download
						}
						else {
							dodownload(eventId); //start download
						} //if(advertId ...
					}//if(href.indexOf ...
				} //if(href ...
				break;
		} //end switch(elemClicked ...
	} //end if(elemClicked ...
}

function dodownload(eventId) 
{


	window.status = 'downloading ... please wait.'; //status message

	var qryString = window.location.search;
	var iframe = document.getElementById("dlh");
	var advertId = 0;
	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

	if(qryString.indexOf('?') == -1) //no querystring
		qryString = '?' + window.location.search

  var iframeSrc = '/websys/TrackingDownload.asp'+qryString+'&EventId='+EventId; 
	
  window.location = 'http://www.jackpotcity.com/exit/Casinodownload/tracking.aspx?VT='+vt+'&pr=10335&s=aff107001'

	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	
	
}
