var dlm = [];
function akDLM3(fUrl,onComplete,target,controls){
	
	// init
	var cssStr;
	var id = new Date().getTime();
	
	// verify if a target was defined, is so, write DLM code in the target, if not, write in default container
	target = (target) ? target : document.getElementById("dlmApp");
	
	// if an occurance of DLM is already in the container, hide it since it cannot be canceld or turned off by method
	hideIfExist(target);
	
	// add code to re-enabled controls after download completes
	onCompleteAction = (onComplete) ? function(){ onComplete(); IOControls(controls,false); waLinkClick("download",fUrl); } : function(){ IOControls(controls,false); waLinkClick("download",fUrl); };
	
	// write DLM DIV containers to target area, add associated CSS
	target.innerHTML = "<div style='margin:0px; width: 285px; padding: 7px 7px 7px 28px;  font-family:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; background: url(http://images.autodesk.com/flashassets/staticassets/dlm/download_icon_11x10.gif);  background-repeat: no-repeat;  background-position:9px 9px; background-color: #dadada;'><a href='#' id='dlm" + id + "' style='color:black'>Download Now</a></div><div id='dlm-container" + id + "' style='margin: 0px; padding: 0px; '></div>";
	cssStr = "<style>.DLM{ border: 1px #dadada solid; padding: 10px; background-color: white; width: 298px; font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#232323; font-weight: normal; margin:0px; } " +
	".DLMtitle{ font-weight: normal; color:#232323;  font-size:11px; } " +
	".DLMprogressBar{ border: 1px solid #eaeaea; height: 11px } " +
	".DLMprogress{ background-color: #333333; background: url(http://images.autodesk.com/flashassets/staticassets/dlm/progress_13x13.gif);  } " +
	".DLMpause{ background: url(http://images.autodesk.com/flashassets/staticassets/dlm/pause_button_13x13.gif); width: 13px; height: 19px; background-position: 0px 5px; background-repeat: no-repeat; } " +
	".DLMresume{ background: url(http://images.autodesk.com/flashassets/staticassets/dlm/start_button_13x13.gif); width: 13px; height: 19px; background-position: 0px 5px; background-repeat: no-repeat; } " +
	".DLMpauseclick{ width: 13px; height: 19px;  } " +
	".DLMstatus{ font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMautoStart{ font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMautoStartCB{ font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMautoStartLabel{ font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMcomplete{ font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMcompleteTitle{ font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMcompleteText{ font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMcompleteLink { font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMstart{ font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMstartMsg{ font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMrelaunch{ font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMrelaunchMsgStart{font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMrelaunchLink{ font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMrelaunchMsgEnd{ font-weight: normal; color:#232323; font-size:11px; } " +
	".DLMeulaText{} " +
	".DLMeulaText2{} " +
	".DLMeulaOK{} " +
	".DLMeulaFAIL{} " +
	".DLMeulaDeniedText{} " +
	".DLMeulaDeniedLink{}</style>";
	target.innerHTML = target.innerHTML + cssStr;
	
	// instanciation of DLM
	// Apr 23 2010 - Jonathan D. - changed CP code from 78331 to 18697
	dlm[id] = new DLM(18697, fUrl, {"openOnComplete":false,"downloadPath":"prompt","onComplete":function(){ onCompleteAction(); }}, "dlm-container" + id, "dlm" + id);
	dlm[id].adskTarget = target;
	
	// Add behavior on the "download button" to disable the controls, when clicked.
    if(window.attachEvent){
    	document.getElementById('dlm' + id).attachEvent("onclick", function(){ IOControls(controls,true); }); 
    } else if(window.addEventListener){
    	document.getElementById('dlm' + id).addEventListener("click", function(){ IOControls(controls,true); }, false);
    }

	return dlm[id];
}


// loop throug aan array of DOM references to form fields and set the disabaled state according to passed parameter (bool)
function IOControls(controls,IO){
	if(controls){
		if(controls.length){
			for(var i=0; i<controls.length; i++) {
				controls[i].disabled = IO;
			}
		}
	}
}

// set CSS display property to none on a passed DOM reference element.
function hideIfExist(theTarget){
	for(var dlm1Id in dlm){
		if(dlm[dlm1Id].adskTarget == theTarget){
			//dlm[dlm1Id].pauseResume();
			dlm[dlm1Id].style.display = 'none';
		}
	}
}
