//bypass the IE handling of object within a form
if(document.forms[0]){
	window.cardMain = new Object();
}

function callASPopup(asset){
        var isIE = navigator.appName.indexOf('Microsoft') != -1;
        var flash = (isIE) ? window["cardMain"] : document["cardMain"];
        flash.externalCall('popup', asset, null);
}

function callASPopupFrame(asset, frameNo){
        var isIE = navigator.appName.indexOf('Microsoft') != -1;
        var flash = (isIE) ? window["cardMain"] : document["cardMain"];
        flash.externalCall('popupFrame', asset, frameNo);
}

function startCourse(courseId){
	//determine if we are in the employee experience
	if($('eeview')){
		//call Ajax function to do the database update
		$('eeview').value = courseId;
		$('process').ax_xmlaction.value = 'startCourse';
		processAjax('AHJViewCourses', 'process', 'startCourse');
	}
}

function selectCourse(courseId){
	//determine if we are in the employee experience
	if($('eeview')){
		//call Ajax function to do the database update
		$('eeview').value = courseId;
		$('process').ax_xmlaction.value = 'startCourse';
		processAjax('AHJViewCourses', 'process', 'startCourse,noUpdate');
	}
}

function finishCourse(courseId){
	var currentView = lastRequestedPackage+'Body';
	
	//determine if we are in the employee experience
	//if($('eeview')){
		//determine correct initiation
	//	if(myAccordViewer.showCardToggle == true){
			//only mark as finished if we started the course fresh, or on card 1
	//		if(myAccordViewer.showCardId == '' || myAccordViewer.showCardId == '1'){
				//call Ajax function to do the database update
	//			$('eeview').value = courseId;
	//			$('process').ax_xmlaction.value = 'finishCourse';
	//			processAjax('AHJViewCourses', 'process', 'finishCourse,'+currentView);
	//		}
	//	}
	//}
	
	//determine if we are in the employee experience
	if($('eeview')) {
		//call Ajax function to do the database update
		$('eeview').value = courseId;
		$('process').ax_xmlaction.value = 'finishCourse';
		// Synchronus Ajax Call!
		processAjax('AHJViewCourses', 'process', 'finishCourse,'+currentView,'sync');	
      // Screen must be refreshed when the accordviewer closes
      myAccordViewer.on_deactivate(function() {
		   ahutil.blockui('Please wait while your information is updated...',
                        320, 52);
		   processAjax('AHJViewCourses', 'process',
                     'finishCourseUpdate,'+currentView); });
	}
}

//moved to accordViewer.js for AssetHealth
//function AC_RunActiveContent(xmlId,lessonId,pkgId){
//        var acContent = '<object ';
//        acContent += 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
//        acContent += 'codebase="swflash.cab#version=8,0,0,0" width="730" height="430" ';
//        acContent += 'id="cardMain" align="middle"> ';
//        acContent += '<param name="allowScriptAccess" value="always" /> ';
//        acContent += '<param name="movie" value="apps/cardMain.swf" /> ';
//        acContent += '<param name="quality" value="high" /> ';
//        acContent += '<param name="bgcolor" value="#ffffff" /> ';
//        acContent += '<param name="FlashVars" value="mainData=Lesson'+xmlId+'.xml&LessonId='+lessonId+'&PackageId='+pkgId+'&assetsDir=/apps/" /> ';
//        acContent += '<embed FlashVars="mainData=Lesson'+xmlId+'.xml&LessonId='+lessonId+'&PackageId='+pkgId+'&assetsDir=/apps/" src="apps/cardMain.swf" quality="high" bgcolor="#ffffff" width="730" height="430" ';
//        acContent += 'name="cardMain" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" ';
//        acContent += 'pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>';

//        document.write(acContent);
//        setCardObject();
//}

function AC_RunActiveContent_SSMenu(height, width, xmlFile, appType, version){
	if(version != ''){
		version += '/';
	}

	var acContent = '<object ';
	acContent += 'classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
	acContent += 'codebase="https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ';
	acContent += 'width="'+width+'" height="'+height+'" ';
	acContent += 'id="dynamicMenu" align="middle"> ';
	acContent += '<param name="allowScriptAccess" value="always" /> ';
	acContent += '<param name="movie" value="/apps/resources/'+appType+'/flash/'+version+'dynamicMenu.swf" /> ';
	acContent += '<param name="quality" value="high" /> ';
	acContent += '<param name="salign" value="lt" /> ';
	acContent += '<param name="wmode" value="transparent" /> ';
	acContent += '<param name="bgcolor" value="#ff0000" /> ';
	acContent += '<param name="FlashVars" value="xmlFile='+xmlFile+'" /> ';
	acContent += '<embed FlashVars="xmlFile='+xmlFile+'" src="/apps/resources/'+appType+'/flash/'+version+'dynamicMenu.swf" quality="high" salign="lt" wmode="transparent" bgcolor="#ffffff" width="'+width+'" height="'+height+'" ';
	acContent += 'name="dynamicMenu" id="dynamicMenu" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	acContent += '</object>';

	document.write(acContent);
}

function setCardObject(){
	if(document.forms[0]){
   	window.cardMain = document.forms[0].cardMain;
   }
}

function getCardObject(){
	return window.cardMain;
}

function toggleLayer(id){
	var lyr = $$('div.layer_'+id)
	for(i in lyr){
		Element.toggle(lyr[i]);
	}
}
