
function returnDocument() {
        var file_name = document.location.href;
        var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
        return file_name.substring(file_name.lastIndexOf("/")+1, end);
    }
    
function returnPath() {
   var path = document.location.href.toString();
   return path.replace(returnDocument(), '');
    }
    
function ContentPath(contentid) {
   return returnPath() + 'packs/' + contentid.toString() + '.mct';
}


function InstallContent(contentId, promoId)
{
    var fullPath = ContentPath(contentId);
    try
    {
	    if (document.MessengerContentObj != null && document.MessengerContentObj.object != null) 
	    {
		    MessengerContentObj.InstallContent( fullPath );
		    CountDownload(promoId);
	    }
	    else
	    {
          //alert('Install Failure [-1]');  
	    }
    }
    catch(exception)
    {
      //alert('Install Failure [' + exception.number + ']');  
    }
}

function CountDownload(promoId)
{

    var xmlhttp=false;
    try 
    {
	    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) 
    {
	    try 
	    {
		    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	    } 
	    catch (E) 
	    {
		    xmlhttp = false;
	    }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
    {
	    xmlhttp = new XMLHttpRequest();
    }
	
    var newpage = "/friendmagnet/download/create.aspx?t=2&packid=" + promoId;
    xmlhttp.open("POST", newpage, true);
    xmlhttp.send(null);
}