//To Show MyCart page
function fnAddItemsToCart(compInstID,hdnBoxID,TargetMenuID,alertstmt,treeId)
{
	if(treeId==null || treeId=='')
		var canProceed=fnCheckForSelectedItems(hdnBoxID,alertstmt);
	else
		var canProceed=fnCheckSelectedItemsOfaTree(treeId,hdnBoxID,alertstmt);
	if(canProceed==true)
	{
		var ObjectIDList=document.getElementById(hdnBoxID).value;
		document.getElementById(hdnBoxID).value="";
		AddToCart(compInstID,ObjectIDList,TargetMenuID);
		
	}
	return false;
}
function fnPurchaseItemsToCart(hdnBoxID,TargetMenuID,alertstmt,UserAccountType,treeId)
{
	if(treeId==null || treeId=='')
		var canProceed=fnCheckForSelectedItems(hdnBoxID,alertstmt);
	else
		var canProceed=fnCheckSelectedItemsOfaTree(treeId,hdnBoxID,alertstmt);
	if(canProceed==true)
	{
		var ObjectIDList=document.getElementById(hdnBoxID).value;
		document.getElementById(hdnBoxID).value="";
		PurchaseItem(ObjectIDList,TargetMenuID,UserAccountType);
	}
	return false;
}
function fnSubscribe(hdnBoxID,alertstmt,comInstID,treeId)
{
	if(treeId==null || treeId=='')
			var canProceed=fnCheckForSelectedItems(hdnBoxID,alertstmt);
		else
			var canProceed=fnCheckSelectedItemsOfaTree(treeId,hdnBoxID,alertstmt);
		if(canProceed==true)
		{
		try
		  {
			// suresh
			var RadAjaxObjx = GetAjaxPanelInstance();
			var ET = comInstID+"_subscribe";
			var EA   = document.getElementById(hdnBoxID).value;			
			//	document.forms(0).__EVENTTARGET.value=comInstID+"_subscribe";
			//	document.forms(0).__EVENTARGUMENT.value=document.getElementById(hdnBoxID).value;
			document.getElementById(hdnBoxID).value="";
				//document.forms(0).submit();
			//fnAjaxPostBack(ET,EA,RadAjaxObjx);
			__doPostBack(ET,EA);
		  }
		 catch(err)
		   {
		 
			document.forms[0].__EVENTTARGET.value=comInstID+"_subscribe";
			document.forms[0].__EVENTARGUMENT.value=document.getElementById(hdnBoxID).value;
			document.getElementById(hdnBoxID).value="";
		    document.forms[0].submit();
		   }		
		}
		return false;
}
function AddToCart(compInstID,ContentID,TargetMenuID,FilterID,TrackingComponentId)
{	
	if (TrackingComponentId > 0)
   {    
     fnClickTracking(1,9,ContentID,TrackingComponentId);
   }
	var qs=''
	if(FilterID != '' && FilterID != null)
	{
		qs='&'+compInstID+'_id='+ FilterID+'&'+compInstID+'_mode=list';
	}
	document.forms[0].__EVENTTARGET.value=compInstID+ "_AddToCart";
	document.forms[0].__EVENTARGUMENT.value=ContentID;
	document.forms[0].__VIEWSTATE.disabled=true;
	//alert(document.getElementById("hdnParamCollection").value);
	if(document.location.pathname.toLowerCase().indexOf('start.aspx')>0)
	document.forms[0].action ="start.aspx?menuid=" + TargetMenuID+qs;// + "&" + compInstID + "_mode=list"; 
	else
	document.forms[0].action ="default.aspx?menuid=" + TargetMenuID+qs;// + "&" + compInstID + "_mode=list"; 
	document.forms[0].submit();
}

//==========satish
function PurchaseItem(ContentID, TargetMenuID, UserAccountType, TrackingComponentId, ecomappurl) 
{		
	document.forms[0].__EVENTTARGET.value="PurchaseItem";
	document.forms[0].__EVENTARGUMENT.value=ContentID;
	document.forms[0].__VIEWSTATE.disabled=true;
	var isUserLoggedIn=false;
	var secureURL=document.location.href.toLowerCase();
	isUserLoggedIn=(secureURL.indexOf('default.aspx')>0?true:false)
	var strPage='default.aspx';
	if(document.location.pathname.toLowerCase().indexOf('start.aspx')>0)
	strPage='start.aspx';
	if (TrackingComponentId > 0)
   {    
     fnClickTracking(1,8,ContentID,TrackingComponentId);
   }

	if(UserAccountType.toLowerCase()!='multilogin')
	{
	    if (isUserLoggedIn) {
	        if (ecomappurl == 'none' || ecomappurl == null) {
	            secureURL = secureURL.replace("http:", "https:");
	            secureURL = secureURL.replace("/" + strPage, "/secure/" + strPage);	
	        }
	        else {
	            secureURL = secureURL.replace("/" + strPage, "/secure/" + strPage);	
	        }			
		}
		var questionLoc=secureURL.indexOf("?");
		secureURL=secureURL.substring(0,questionLoc)	
		document.forms[0].action =secureURL + "?menuid=" + TargetMenuID + "&action=checkout"; 
		document.forms[0].submit();
		return false;	
	}
	else	
	{
		var questionLoc=secureURL.indexOf("?");
		secureURL=secureURL.substring(0,questionLoc)	
		document.forms[0].action =secureURL + "?menuid=" + TargetMenuID + "&action=checkout"; 
		document.forms[0].submit();
	}
}
//==========satish
function fnBookmarkItemsOfTree(hdnBoxID,alertstmt,treeId)
{
	if(treeId==null || treeId=='')
		var canProceed=fnCheckForSelectedItems(hdnBoxID,alertstmt);
	else
		var canProceed=fnCheckSelectedItemsOfaTree(treeId,hdnBoxID,alertstmt);
	if(canProceed==true)
	{
		AddBookMark(document.getElementById(hdnBoxID).value);
		document.getElementById(hdnBoxID).value="";
	}
	return false;
}


//To show add Ratings page		 
function AddRatings(ContentID,ContentTitle,CanRefresh,TrackingComponentId)
{ 
	if (TrackingComponentId > 0)
   {    
     fnClickTracking(1,3,ContentID,TrackingComponentId);
   }
	if(ContentTitle!=null)
		popupwindow=window.open("Modules/AddRatings.aspx?ContentID="+ContentID+"&ContentTitle="+ContentTitle,"AddRatings","height=480,width=600,status=no,toolbar=no,resizable=yes,menubar=no,scrollbars=yes,left=30,top=50");
	else
		popupwindow=window.open("Modules/AddRatings.aspx?ContentID="+ContentID,"AddRatings","height=480,width=600,status=no,toolbar=no,resizable=yes,menubar=no,scrollbars=yes,left=30,top=50");
	popupwindow.focus();
}



//To show Bookmark popup
function fnBookmarkItems(hdnBox)
{
	if(document.getElementById(hdnBox).value=="")
	{
		alert(alrtSelectContent);
		return false;
	}
	AddBookMark(document.getElementById(hdnBox).value);
	return false;
}

//To launch content item from catalog  page without tracking(authoring tools items)
function fnGeneratePreview(ApplicationPath,SCOID,Path,ObjectTypeID,ContentID,WinProperties,mode,track,eventkey,urltype,TrackingComponentId)
{
	if (TrackingComponentId > 0) 
	{
		fnClickTracking(1,1,ContentID,TrackingComponentId);
	}
		if(eventkey==null)	eventkey='';
		if(urltype==null) 	urltype='';
		if(track == null || track == '') fnTrackLinkClicks(SCOID,ApplicationPath);
		var targetURL;
		Path = escape(Path);
		if (WinProperties==null) WinProperties='';
		targetURL=ApplicationPath + '/PublicModules/Preview.aspx?Path=' + Path + '&ObjectTypeID=' + ObjectTypeID+ '&ContentID=' + ContentID+ '&CanTrack=No&eventkey='+eventkey+'&urltype='+ urltype;
		var winid=replaceAll(ContentID,"-","_") + "view" + urltype;
		var chWin=window.open(targetURL,winid,WinProperties); 	
		chWin.focus();		
	
}
		
//To show user progress report
function ShowProgressReport(url,ContentID,ObjectTypeID,Name)
{
	document.forms[0].action = url;
	document.forms[0].submit();
}
//To show notes
function AddNotes(url,ContentID,TrackingComponentId)
{	 
  if (TrackingComponentId > 0)
   {    
     fnClickTracking(1,4,ContentID,TrackingComponentId);
   }
	document.forms[0].__VIEWSTATE.disabled=true;
	document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
	document.location.href = url;
}	

//To Unassign the content from user mycatalog
function fnUnassignUserContent(ContentID,confirmstmt)
{
	var agree=confirm(confirmstmt);
	if(agree==true)
	{
		document.forms[0].__EVENTTARGET.value='UnassignUserContent';
		document.forms[0].__EVENTARGUMENT.value=ContentID;
		document.forms[0].action=fnRemoveFromURL('page',document.location.href);
		document.forms[0].submit();
	}
}
		

//To launch content item(third party objects) from my catalog page by enabling tracking	
function fnGeneratePreviewForMedia(Path,CourseName,ContentID,ObjectTypeID,SCOID,WinProperties,track,IsMyCatalog,mode,eventkey,eventtype,TrackingComponentId)
{
	if (TrackingComponentId > 0) 
	{
  	fnClickTracking(1,1,ContentID,TrackingComponentId);
	}
	if(eventkey==null) eventkey='';
	if(eventtype==null) eventtype='';
	if (WinProperties==null) WinProperties='';
	if (track==null)
		 CanTrack='Yes';
	else 
		CanTrack=track;
	var targetURL;
	Path = escape(Path);
	if(document.getElementById(clientID + "_hdnAllowTracking") !=null)
	{
		if(IsMyCatalog==1)
		{
			document.getElementById(clientID + "_hdnAllowTracking").value="yes";
		}
		else if(IsMyCatalog==0)
		{
			document.getElementById(clientID + "_hdnAllowTracking").value="no";
		}
	}
	targetURL='Remote/LaunchPage.aspx?Path=' + Path + "&CourseName=" + CourseName + '&ContentID=' + ContentID + '&ObjectTypeID=' + ObjectTypeID+ '&CanTrack='+ CanTrack + '&SCOID=' + SCOID+'&eventkey='+eventkey+'&eventtype='+eventtype;
	
	var winid=replaceAll(ContentID,"-","_") + "view";
	var chwin=window.open(targetURL,winid,WinProperties); 	
	chwin.focus();	
}

//To launch content item(instancy authored contents) from my catalog page by enabling tracking	
function ShowCourse(URL,CourseName,ContentID,ObjectTypeID,SCOID,WinProperties,IsMyCatalog,mode, TrackingComponentId)
{
	 if (TrackingComponentId > 0)
   { 
       fnClickTracking(1,1,ContentID,TrackingComponentId);     
    }
    
	if(WinProperties==null) WinProperties='';
	if(document.getElementById(clientID + "_hdnAllowTracking") !=null)
	{
		if(IsMyCatalog==1)
		{
			document.getElementById(clientID + "_hdnAllowTracking").value="yes";
		}
		else if(IsMyCatalog==0)
		{
			document.getElementById(clientID + "_hdnAllowTracking").value="no";
		}
	}
	var targetUrl = "remote/LaunchPage.aspx?URL="+URL+ "&CourseName=" + CourseName + '&ContentID=' + ContentID + '&CanTrack=Yes&ObjectTypeID='+ ObjectTypeID + '&SCOID=' + SCOID;				
	openWindow(ContentID,"view",targetUrl,WinProperties,"view")
}
	
	
function ShowExternalCourse(URL,ContentID,Action,TrackingComponentId)
{
  if (TrackingComponentId > 0)
   { 
     if (Action=="View")   
        fnClickTracking(1,1,ContentID,TrackingComponentId);
       else
        if (Action=="Subscribe")
          fnClickTracking(1,10,ContentID,TrackingComponentId);
         else
          if (Action=="AddtoCart")
             fnClickTracking(1,9,ContentID,TrackingComponentId); 
           else
            if (Action=="Purchase")
             fnClickTracking(1,8,ContentID,TrackingComponentId); 
          
    }
   window.open(URL);
}	


/********* TO update the status of the contentitem in the parent page ,when the course is closed(my catalog) *********/
var ContentID;
function updateDatalistAfterLaunch()
{ 
	var strVal='';
	strVal=API.GetStatus("");
	var status=strVal.split(";")[0];
	var datecompleted=strVal.split(";")[1];
	if(datecompleted != '')
	{
		if(document.getElementById(ContentID + "_datecompleted") !=null)
		{
			document.getElementById(ContentID + "_datecompleted").innerHTML='&nbsp;'+ datecompleted;
		}
		else if(document.getElementById(ContentID.toLowerCase() + "_datecompleted") !=null)
		{
			document.getElementById(ContentID.toLowerCase() + "_datecompleted").innerHTML='&nbsp;'+ datecompleted;
		}
	}
	if(document.getElementById(ContentID + "_corelessonstatus") !=null)
	{
		document.getElementById(ContentID+ "_corelessonstatus").innerHTML='&nbsp;'+ status;
	}
	else if(document.getElementById(ContentID.toLowerCase() + "_corelessonstatus") !=null)
	{
		document.getElementById(ContentID.toLowerCase() + "_corelessonstatus").innerHTML='&nbsp;'+ status;
	}
	var actualstatus=strVal.split(";")[2];
	if( actualstatus=='completed' || actualstatus=='passed'|| actualstatus=='failed' || actualstatus=='attended' || actualstatus=='notattended' )
	{
		if(document.getElementById("remove_" + ContentID.toLowerCase()) !=null)
		{
			var parentstr=document.getElementById("remove_" + ContentID.toLowerCase()).parentNode.innerHTML;
			var lengthOfStr=document.getElementById("remove_" + ContentID.toLowerCase()).outerHTML.length
			var index=parentstr.indexOf(document.getElementById("remove_" + ContentID.toLowerCase()).outerHTML);
			var firstpart=parentstr.substring(0,index-2);
			var secondpart='';
			if(parentstr.charAt(index + 1 + lengthOfStr)=='|')
				secondpart=parentstr.substring(index + 1 + lengthOfStr);
			document.getElementById("remove_" + ContentID.toLowerCase()).parentNode.innerHTML=firstpart+secondpart;
		}	
		if(document.getElementById("certificate_" + ContentID.toLowerCase()) !=null)
		{
			var certificateSpan=document.getElementById("certificate_" + ContentID.toLowerCase());
			certificateSpan.style.display="";			
		}
		if (certificateSpan!=null)
		{		
			if (status == 'Completed (Failed)' || status == 'Completed (Not Attended)')
			{
				certificateSpan.style.display='none'
			}
			else if(status == 'Completed (Passed)' || status == 'Completed (Attended)')
			{
				certificateSpan.style.display='inline';
			}
		}
			try
			{
				fnAjaxSubmit(document.location.href,GetAjaxPanelInstance());				
			}
			catch(ex)
			{
				document.forms[0].submit();
			}			
	}
	document.forms[0].submit();
}



/******************** Hide Complete items function ****************/
function fnHideCompletItems(url,chkobj)
{
	try{
		if (chkobj.checked)
			url=url.replace('hidecompletevalue','true');
		else
			url=url.replace('hidecompletevalue','false');
		fnAjaxSubmit(url.substring(url.indexOf("?")+1),GetAjaxPanelInstance());
	}
	catch(ex){
		if (chkobj.checked)
			document.forms[0].action =url.replace('hidecompletevalue','true');
		else
			document.forms[0].action =url.replace('hidecompletevalue','false');
		document.forms[0].submit();
	}	
}

function fnShowCertificate(CertID,CertPage,CID)
{
	var chwin = window.open("Modules/LogoPage.aspx?CertID=" + CertID + "&CertPage=" + CertPage + "&CID=" + CID,"Certificate","height=585,width=690,toolbar=no,menubar=no,resizable=no,scrollbars=no,left=30,top=50"); 					
}

function LaunchWebpages(applicationurl,ContentID,AddToCartMenuID,LaunchWindowSettings,CanTrack,TrackingComponentId)
{
	if (TrackingComponentId > 0)
    { 
        fnClickTracking(1,1,ContentID,TrackingComponentId);     
    }
	//popWin=window.open(applicationurl + '/LaunchContent.aspx?CID=' + ContentID + '&addtocartmenu=' + AddToCartMenuID ,'', LaunchWindowSettings );
	var winid=replaceAll(ContentID,"-","_") + "view";
	if (CanTrack!=null)
	{
		var chwin=window.open(applicationurl + '/LaunchContent.aspx?CID=' + ContentID + '&addtocartmenu=' + AddToCartMenuID + '&cantrack=' + CanTrack,winid,LaunchWindowSettings); 	
		chwin.focus();
	}
	else
	{
		var chwin=window.open(applicationurl + '/LaunchContent.aspx?CID=' + ContentID + '&addtocartmenu=' + AddToCartMenuID,winid,LaunchWindowSettings); 	
		chwin.focus();
	}
}

/********* TO update the stars of the contentitem in the parent page ,when the rating has been changed *********/
function UpdateRatings(ContentID,ImageStr)
{ 
	if(document.getElementById(ContentID + "_rating") !=null)
	{
		document.getElementById(ContentID + "_rating").innerHTML=ImageStr;
	}
	else if(document.getElementById(ContentID.toLowerCase() + "_rating") !=null)
	{
		document.getElementById(ContentID.toLowerCase() + "_rating").innerHTML=ImageStr;
	}
}


function fnDownloadContent(ContentID,TrackingComponentId )
{
  if (TrackingComponentId > 0)
   {    
     fnClickTracking(1,11,ContentID,TrackingComponentId);
   }

	popWin = window.open("Modules/Download_Latest.aspx?ContentID=" + ContentID ,'DownloadPackage','statusbar=no,resizable=yes,scrollbars=yes,width=370,height=170,left=500,top=350');
	//popWin = window.open("Modules/Download.aspx?FileName=" + FileName + "&DownloadPath=" + Path,'DownloadPackage','statusbar=no,resizable=yes,scrollbars=yes,width=570,height=270');
	popWin.focus();
}

function fnTagFiltering(targetname,keyword)
{

		document.forms[0].__EVENTTARGET.value = targetname;
		document.forms[0].__EVENTARGUMENT.value = keyword;
		document.forms[0].submit();
}
/*function CatalogItemSendToFriend(ContentID)
{   
      fnClickTracking(1,5,ContentID);
  
	popupwindow=window.open("PublicModules/SendMail.aspx?ContentID="+ContentID,"SendToFriend","height=450,width=750,status=no,toolbar=no,resizable=yes,menubar=no,scrollbars=yes,left=30,top=50");
	popupwindow.focus();
}
function CatalogItemSendToFriendExternalSite(ContentID,SiteID,AppUrl)
{
	fnClickTracking(1,5,ContentID);
	popupwindow=window.open("PublicModules/SendMail.aspx?ContentID="+ContentID+"&SiteID="+SiteID+"&AppUrl="+AppUrl ,"SendToFriend","height=450,width=750,status=no,toolbar=no,resizable=yes,menubar=no,scrollbars=yes,left=30,top=50");
	popupwindow.focus();
}*/
function fnGeneratePreviewforSample(Path, ContentType, ContentID, appPath) {
    var targetURL;
    Path = escape(Path);
    targetURL = appPath + '/PublicModules/Preview.aspx?Path=' + Path + '&ObjectTypeID=' + ContentType + '&ContentID=' + ContentID;
    openWindow(ContentID, 'preview', targetURL, 'fullscreen=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600,left=0,top=0', 'preview');
}
