﻿// JScript File
// sfolderPopup.js defines a popup window that contains the full content of a smart folder and generate 
// events for click on any item

var g_currentSFPopup = null;   // Current visible popup window
var g_itemID = -1;

// Constructor function
// ---------------------------------------------------------------------------------------------------------------
function sfPopup( targetElement_id, id, title, popupWidth, commentText )
{
	this.m_externalCallback = null;
	this.m_returnSelectedFolder = false;
	this.m_afterAction = "";
	this.m_commentText = commentText;
	this.m_divName = "sfpopup_"+id;
	this.m_divShadoName = "sfpopup_shadow_"+id;
	this.m_div = document.getElementById(this.m_divName);
	this.m_width = popupWidth;
	    
	if ( this.m_div != null )
	    return;
	    

    // Window frame DIV	
	this.m_div = document.createElement("div");
	this.m_div.id = this.m_divName;
	this.m_div.className = "sfpopup_main";


	this.m_divShadow = document.createElement("div");
	this.m_divShadow.id = this.m_divShadoName;
	this.m_divShadow.className = "FoldierPopupShadowFixed";
	


    // Title DIV	
	this.m_titleDiv = document.createElement("div");
	this.m_titleDiv.className = "PopupMessageTitle";
	var closeWinClick = " " + id + ".Hide(event);"
	if ($('m_foldierBar') != null)
	    closeWinClick += "foldierBarResetHeight(\"m_foldierBar\");"
	this.m_titleDiv.innerHTML = "<img class='PopupMessageCloseButton' alt='close window' src='images/ico/CloseIcon 20x20.png' onclick='" + closeWinClick + "'  /><span style='margin-left:4px; margin-top:4px;'>" + title + "</span>";



    // PopupBody DIV
	this.m_bodyDiv = document.createElement("div");
	this.m_bodyDiv.className = "sfpopup_body";
	
    // Window content DIV	
	this.m_contentDiv = document.createElement("div");
	this.m_contentDiv.className = "sfpopup_content";
	this.m_contentDiv.innerHTML = "<center><img src='images/processing.gif' style='margin:30px;'  /></center>";

    // Text DIV	
    if ( this.m_commentText )
    {
	    this.m_commentDiv = document.createElement("div");
	    this.m_commentDiv.className = "sfpopup_comment";
	    this.m_commentDiv.innerHTML = this.m_commentText;
    }
    else
    {
        if ( this.m_contentDiv.style.pixelHeight == null )
	        this.m_contentDiv.style.height = '363px';
	    else
	        this.m_contentDiv.style.pixelHeight = 363;
    }
	
    // Width sizing	
	if ( popupWidth != -1 )
	{
	    //    alert('WIDTH = '+this.m_div.style.pixelWidth);
	    
	    if ( this.m_div.style.pixelWidth == null )
	    {
	        this.m_div.style.width = popupWidth+'px';
	    }
	    else
	    {
	        this.m_div.style.pixelWidth = popupWidth;
	    }
	}

    // Build HTML hirarchy
	this.m_div.appendChild(this.m_titleDiv);
	if ( commentText )
	    this.m_bodyDiv.appendChild(this.m_commentDiv);
	this.m_bodyDiv.appendChild(this.m_contentDiv);
	this.m_div.appendChild(this.m_bodyDiv);

	document.getElementById(targetElement_id).appendChild(this.m_divShadow);
	document.getElementById(targetElement_id).appendChild(this.m_div);
	
	this.EnableDrag(this.m_titleDiv);
	this.Position(0,0);
}



/********************************************************************************************
 * StartDrag(): start dragging this popup .
 *
 * This module defines a single drag() function that is designed to be called
 * from an onmousedown event handler.  Subsequent mousemove events will
 * move the specified element. A mouseup event will terminate the drag.
 * If the element is dragged off the screen, the window does not scroll.
 * This implementation works with both the DOM Level 2 event model and the
 * IE event model.
 * 
 * Arguments:
 *
 *   this.m_mainDiv:  the element that received the mousedown event or
 *     some containing element. It must be absolutely positioned.  Its 
 *     style.left and style.top values will be changed based on the user's
 *     drag.
 *
 *   event: the Event object for the mousedown event.
 *
*********************************************************************************************/
sfPopup.prototype.StartDrag = function(event) 
{
    // The mouse position (in window coordinates)
    // at which the drag begins 
    var startX = event.clientX, startY = event.clientY;    

    // The original position (in document coordinates) of the
    // element that is going to be dragged.  Since elementToDrag is 
    // absolutely positioned, we assume that its offsetParent is the
    // document body.
    var origX = g_currentSFPopup.m_div.offsetLeft, origY = g_currentSFPopup.m_div.offsetTop;
    var s_origX = g_currentSFPopup.m_divShadow.offsetLeft, s_origY = g_currentSFPopup.m_divShadow.offsetTop;

    // Even though the coordinates are computed in different 
    // coordinate systems, we can still compute the difference between them
    // and use it in the moveHandler() function.  This works because
    // the scrollbar position never changes during the drag.
    var deltaX = startX - origX, deltaY = startY - origY;
    var s_deltaX = startX - s_origX, s_deltaY = startY - s_origY;

    // Register the event handlers that will respond to the mousemove events
    // and the mouseup event that follow this mousedown event.  
    if (document.addEventListener) {  // DOM Level 2 event model
        // Register capturing event handlers
        document.addEventListener("mousemove", moveHandler, true);
        document.addEventListener("mouseup", upHandler, true);
    }
    else if (document.attachEvent) {  // IE 5+ Event Model
        // In the IE event model, we capture events by calling
        // setCapture() on the element to capture them.
        g_currentSFPopup.m_div.setCapture();
        g_currentSFPopup.m_div.attachEvent("onmousemove", moveHandler);
        g_currentSFPopup.m_div.attachEvent("onmouseup", upHandler);
        // Treat loss of mouse capture as a mouseup event
        g_currentSFPopup.m_div.attachEvent("onlosecapture", upHandler);
    }
    else {  // IE 4 Event Model
        // In IE 4 we can't use attachEvent() or setCapture(), so we set
        // event handlers directly on the document object and hope that the
        // mouse events we need will bubble up.  
        var oldmovehandler = document.onmousemove; // used by upHandler() 
        var olduphandler = document.onmouseup;
        document.onmousemove = moveHandler;
        document.onmouseup = upHandler;
    }

    // We've handled this event. Don't let anybody else see it.  
    if (event.stopPropagation) event.stopPropagation();  // DOM Level 2
    else event.cancelBubble = true;                      // IE

    // Now prevent any default action.
    if (event.preventDefault) event.preventDefault();   // DOM Level 2
    else event.returnValue = false;                     // IE

    /**
     * This is the handler that captures mousemove events when an element
     * is being dragged. It is responsible for moving the element and its shadow.
     **/
    function moveHandler(e) {
        if (!e) e = window.event;  // IE Event Model

        // Move the element to the current mouse position, adjusted as
        // necessary by the offset of the initial mouse-click.
        g_currentSFPopup.m_div.style.left = (e.clientX - deltaX) + "px";
        g_currentSFPopup.m_div.style.top = (e.clientY - deltaY) + "px";
        g_currentSFPopup.m_divShadow.style.left = (e.clientX - s_deltaX) + "px";
        g_currentSFPopup.m_divShadow.style.top = (e.clientY - s_deltaY) + "px";

        // And don't let anyone else see this event.
        if (e.stopPropagation) e.stopPropagation();  // DOM Level 2
        else e.cancelBubble = true;                  // IE
        
    }

    /**
     * This is the handler that captures the final mouseup event that
     * occurs at the end of a drag.
     **/
    function upHandler(e) {
        if (!e) e = window.event;  // IE Event Model

        // Unregister the capturing event handlers.
        if (document.removeEventListener) {  // DOM event model
            document.removeEventListener("mouseup", upHandler, true);
            document.removeEventListener("mousemove", moveHandler, true);
        }
        else if (document.detachEvent) {  // IE 5+ Event Model
            g_currentSFPopup.m_div.detachEvent("onlosecapture", upHandler);
            g_currentSFPopup.m_div.detachEvent("onmouseup", upHandler);
            g_currentSFPopup.m_div.detachEvent("onmousemove", moveHandler);
            g_currentSFPopup.m_div.releaseCapture();
        }
        else {  // IE 4 Event Model
            // Restore the original handlers, if any
            document.onmouseup = olduphandler;
            document.onmousemove = oldmovehandler;
        }

        // And don't let the event propagate any further.
        if (e.stopPropagation) e.stopPropagation();  // DOM Level 2
        else e.cancelBubble = true;                  // IE
        
    }
}

// Enable dragging for this Popup window. The parameter is an element (within the window) that
// is used as handler for the dragging action.
// -------------------------------------------------------------------------------------------------------
sfPopup.prototype.EnableDrag = function( dragElement )
{
	if ( dragElement == null )
	{
		//alert('Dragging element is null!!');
		return ;
	}
		
    var self = this;
	
	if (document.addEventListener)   // DOM Level 2 event model
	{

		dragElement.addEventListener("mousedown", self.StartDrag, false );
		dragElement.addEventListener("click", stopPropagation, false );
	}
    else if (document.attachEvent)   // IE 5+ Event Model
    {
		dragElement.attachEvent("onmousedown", self.StartDrag );
		dragElement.attachEvent("onclick", stopPropagation );
    }
    else // IE 4 Event Model
    { 
		// Not supported!!
    }
}



// ---------------------------------------------------------------------------------------------------------------
sfPopup.prototype.AfterAction = function( afterActionJS )
{
	this.m_afterAction = afterActionJS;
}

// ---------------------------------------------------------------------------------------------------------------
sfPopup.prototype.SelectionCallback = function( foldername )
{
	if ( this.m_externalCallback != null )
		this.m_externalCallback(foldername);
	else
		alert(foldername);
}

// ---------------------------------------------------------------------------------------------------------------
sfPopup.prototype.ReturnSelectedFolder = function( funcCallback )
{
	this.m_returnSelectedFolder = true;
	this.m_externalCallback = funcCallback;
}

// ---------------------------------------------------------------------------------------------------------------
sfPopup.prototype.ItemInfo = function(itemID, itemName) {
    this.m_itemID = itemID;
    this.m_itemName = itemName;
    if (this.m_commentDiv != null)
        this.m_commentDiv.innerHTML = "<div><strong>" + itemName + "</strong></div>" + this.m_commentText;

    this.m_multipleItems = false;
}

// ---------------------------------------------------------------------------------------------------------------
sfPopup.prototype.FolderInfo = function(folderID, folderName) {
    this.m_folderID = folderID;
    this.m_folderName = folderName;
    if (this.m_commentDiv != null)
        this.m_commentDiv.innerHTML = "<div><strong>Selection in " + folderName + "</strong></div>" + this.m_commentText;

    this.m_multipleItems = true;
}

// ---------------------------------------------------------------------------------------------------------------
sfPopup.prototype.displayShadow = function()
{
    // Resize the shadow to match the main fram window
    var height = 0;
    var width = 0;
    if ( this.m_div.offsetHeight )
    {
        height = this.m_div.offsetHeight;
        width = this.m_div.offsetWidth;
    }
    else if(this.m_div.style.pixelHeight)
    {
        height = this.m_div.style.pixelHeight;
        width = this.m_div.style.pixelWidth;
    }
    
    // alert( "m_div Height = "+height + " Width = "+ width );
    this.m_divShadow.style.height = (height+16)+"px";
    this.m_divShadow.style.width = (width+16)+"px";

    this.m_divShadow.style.display = 'block';
}

// ---------------------------------------------------------------------------------------------------------------
sfPopup.prototype.Position = function( xPos, yPos )
{
    //alert( "m_div Left = "+xPos + " - Top = "+ yPos );
    this.m_div.style.left = xPos+'px';
    this.m_div.style.top = yPos+'px';
    this.m_divShadow.style.left = (xPos-8)+'px';
    this.m_divShadow.style.top = (yPos-8)+'px';
}

// ---------------------------------------------------------------------------------------------------------------
sfPopup.prototype.SetPositionByElement = function( elementName, offX, offY )
{
	var x = 0 ,y = 0;
	var e = document.getElementById(elementName);
	while(e.offsetParent) 
	{
		x += e.offsetLeft;
		y += e.offsetTop;
		e = e.offsetParent;
	}
	
	x += e.offsetLeft;
	y += e.offsetTop;

    this.Position( x+offX, y+offY);
    /*
	this.m_div.style.left = (x+offX)+'px';
    this.m_div.style.top = (y+offY)+'px';
	this.m_divShadow.style.left = (x+offX+4)+'px';
    this.m_divShadow.style.top = (y+offY+4)+'px';*/
    //alert( "XPos = "+x + "    Offset = "+ offX );

}

// ---------------------------------------------------------------------------------------------------------------
sfPopup.prototype.SetPositionCenterdOnElement = function( elementName, offY )
{
	var x = 0 ,y = 0;
	var e = $(elementName);

	while(e.offsetParent) 
	{
		x += e.offsetLeft;
		y += e.offsetTop;
		e = e.offsetParent;
	}
	
	x += e.offsetLeft;
	y += e.offsetTop;

    var h = 0;
    var w = 0;
    var thisw = 0;
    var thish = 0;
    if ( this.m_div.offsetHeight )
    {
        h = e.offsetHeight;
        w = e.offsetWidth;
        
        //this.m_div.style.width = this.m_width+'px';
        thisw = this.m_div.offsetWidth;
        thish = this.m_div.offsetHeight;
    }
    else if(this.m_div.style.pixelHeight)
    {
        h = e.style.pixelHeight;
        w = e.style.pixelWidth;
        thisw = this.m_div.pixelWidth
        thish = this.m_div.pixelHeight;
    }

	//alert("This is "+thisw+" wide");
    var popupX = ( w - thisw ) / 2;
    var popupY = y+offY;

	//alert('Vertical Position: ' + popupY );
    this.Position( popupX, popupY);

	/*
	this.m_div.style.left = (popupX)+'px';
    this.m_div.style.top = (y+offY)+'px';
	this.m_divShadow.style.left = (popupX+4)+'px';
    this.m_divShadow.style.top = (y+offY+4)+'px'; */
    //alert( "XPos = "+x + "    Offset = "+ offX );
    
    // alert('Parent '+elementName+' Width: '+ w + ' -  This Width: ' + thisw +' - Popup Position X = '+popupX);

}



// ---------------------------------------------------------------------------------------------------------------
sfPopup.prototype.Show = function()
{
    if ( g_currentSFPopup!=null )
        g_currentSFPopup.Hide();
    
    this.m_div.style.display = 'block';
    this.displayShadow();
    
    g_currentSFPopup = this;
    
}

// ---------------------------------------------------------------------------------------------------------------
sfPopup.prototype.Hide = function() {
    // if (!e) e = window.event;
    //showFlashIE(); 
    showAllFlash();
    this.m_div.style.display = 'none';
    this.m_divShadow.style.display = 'none';
    if ($('popupScreenBackground') != null)
        $('popupScreenBackground').style.display = 'none';
    g_currentSFPopup = null;

}


// ---------------------------------------------------------------------------------------------------------------
sfPopup.prototype.SetContent = function( content )
{
    this.m_contentDiv.innerHTML = content;
}

// Remove the userID from as share target of the given folderID
// --------------------------------------------------------------------------------------------------------------
sfPopup.prototype.actionUnshare = function ( folderID, recipientID, recipientName, folderName )
{
	if ( ! confirm('Are you sure you want to unshare "'+folderName+'" from '+ recipientName + '?' ) )
	{
		return;
	}
    this.Hide();
	actionItemUnshareFolder( folderID, recipientID );
}

// --------------------------------------------------------------------------------------------------------------
function actionBlackListCompleted( oExecutor, oEventArgs )
{
	var objPopup = g_currentSFPopup;
	
	objPopup.Hide();
	
    if ( objPopup.updateFolderList != null )
        updateFolderList(this.m_itemName);
	
	if ( objPopup.m_afterAction.length > 0 )
	{
		eval( objPopup.m_afterAction );
	}
}

// --------------------------------------------------------------------------------------------------------------
sfPopup.prototype.actionBlacklist = function ( targetFolderID, clickedElement  )
{
    var self = this;
	if ( clickedElement != null )
		clickedElement.style.backgroundColor = "#ffa0a0";
	//alert('Blacklisting ITem '+this.m_itemID+' from folder '+targetFolderID);
	//return;
	actionItemBlacklisting( this.m_itemID, targetFolderID,  function( oExecutor, oEventArgs) 
															{ 
																self.Hide(); 
																actionCompleteFading(oExecutor, oEventArgs); 
															} );
    if ( self.updateFolderList != null )
        updateFolderList(this.m_itemName);
}

// --------------------------------------------------------------------------------------------------------------
sfPopup.prototype.actionSpress = function(targetESpressionID, clickedElement, contextSiteID) {
    var self = this;
    if (contextSiteID == null)
        siteID = -1;
    else
        siteID = contextSiteID;
    if (clickedElement != null)
        clickedElement.style.backgroundColor = "#80f080";

    if (targetESpressionID == null || targetESpressionID <= 0) {
        displayFadingBoxText("<div class='messageInvalid'><strong>Failed</strong><br/>Target sPression is invalid</div>");
        return;
    }
    self.Hide();
    if (this.m_folderID > 0) {
        actionSPressSelected(targetESpressionID, this.m_folderID, siteID);
    }
    else {
        actionSPress(this.m_itemID, targetESpressionID, "", "", "");
    }

    //invoke the js function written in SmartFolderView.RenderContents to deselect the published items:
    selectNone(); 
    /*setTimeout( function(){ document.location.href = "browse.aspx?ID="+this.m_folderID; }, 1000 ); */
}

// --------------------------------------------------------------------------------------------------------------
sfPopup.prototype.actionWhitelist = function(targetFolderID, clickedElement) 
{
    var self = this;

    if (clickedElement != null) {
        clickedElement.style.backgroundColor = "#ccc";
        clickedElement.style.fontWeight = "bold";
    }
    setTimeout(function() { self.Hide(); }, 1000);
    // Here we act differently if the subject is a single item or a set of selected items within a folder
    if (!this.m_multipleItems) {
    //if (this.m_itemID) {
        actionItemWhitelisting(this.m_itemID, targetFolderID);
        if (self.updateFolderList != null)
            updateFolderList();
    }
    else {
        actionSelectedWhitelisting(this.m_folderID, targetFolderID
                                  , function(oExecutor, oEventArgs) {
                                      actionCompleteFading(oExecutor, oEventArgs);
                                      setTimeout(function() { document.location.href = "browse.aspx"; }, 1000);
                                  });
    }
}

// --------------------------------------------------------------------------------------------------------------
sfPopup.prototype.getItemFoldersCompleted = function ( oExecutor, oEventArgs )
{
    if ( oExecutor.get_responseAvailable() )
    {
        var jsonData = oExecutor.get_responseData();

        var item = eval("("+jsonData+")");
        
        //alert("JSON parsed: " + smartFolder.items.length + " items");
        
        var actionClick = "";
        var htmlOut = "<div style='text-align:left;'>";
        for( var t=0; t<item.folders.length; t++ )
        {
			actionClick = "onclick='g_currentSFPopup.actionBlacklist("+item.folders[t].ID+");'";
            //htmlOut += "<div style='clear:left; width:200px; border-bottom: dotted 1px #dedeab; height:28px; margin-top:2px;'>";
			htmlOut += "<div style='clear:left; height:28px; margin-top:1px;' title='Remove item from " + item.folders[t].FullName + "' " + actionClick + " >";
            htmlOut += "<img src='images/delete_16x16.png' style='cursor:pointer; float:right; margin:5px;' alt='x' border='0'  />";
            htmlOut += "<img src='itemDownload.aspx?THUMBID="+item.folders[t].ID+"' border='0' style='float:left; max-width:24px; max-height:24px; margin:1px;' />";
            htmlOut += "<div class='sfpopupItem'>"; // title='Remove item from " + item.folders[t].FullName + "' " + actionClick + " >";
            htmlOut += "<div style='white-space:nowrap;'>" + item.folders[t].Name + "</div>";
            htmlOut += "</div>";
        }
        htmlOut += "</div>";

        g_currentSFPopup.SetContent ( htmlOut );
    }
    else
    {
        if ( oExecutor.get_timedOut() )
            g_personalFolderOutputWindow.SetContent( "Request Timed Out" );
        else if ( oExecutor.get_aborted() )
            g_personalFolderOutputWindow.SetContent( "Request Aborted" );
        else
            g_personalFolderOutputWindow.SetContent( "HTTP Error: " );
    }
}

// --------------------------------------------------------------------------------------------------------------
sfPopup.prototype.getSPressionsCompleted = function ( oExecutor, oEventArgs )
{
    if ( oExecutor.get_responseAvailable() )
    {
		var self = this;
        var jsonData = oExecutor.get_responseData();

        var smartFolder = eval("("+jsonData+")");
        
        //alert("JSON parsed: " + smartFolder.items.length + " items");
        var actionClick = "";
        var htmlOut = "<div style='text-align:left;'>";
        
        for( var t=0; t<smartFolder.items.length; t++ )
        {
            actionClick = "g_currentSFPopup.actionSpress(" + smartFolder.items[t].ID + ",$(\"sfp" + smartFolder.items[t].ID + "\") ); ";
            if ($('m_foldierBar') != null)
                actionClick += "foldierBarResetHeight(\"m_foldierBar\");"
				
            htmlOut += "<div style='height:40px; margin-top:1px; clear:left;' onclick='"+actionClick+"'>";
			htmlOut += "  <img src='images/add 16x16.png' style='cursor:pointer; float:right; margin:5px; margin-top:10px;' alt='+' title='Add to "+smartFolder.items[t].FullName +"' border='0'  />";
            htmlOut += "  <div style='float:left; width:40px; height:32px; margin:2px;'><center><img src='itemDownload.aspx?THUMBID="+smartFolder.items[t].ID+"' border='0' style='max-width:38px; max-height:30px; margin:1px;' /></center></div>";
            htmlOut += "  <div class='sfpopupItem' style='margin-left:44px; padding:0px 4px; height:32px;' title='" + smartFolder.items[t].FullName + "' id='sfp" + smartFolder.items[t].ID + "' ><div style='white-space:nowrap;'>" + smartFolder.items[t].Name + "</div></div>";
			htmlOut += "</div>";
        }
        htmlOut += "</div>";

        g_currentSFPopup.SetContent ( htmlOut );
    }
    else
    {
        if ( oExecutor.get_timedOut() )
            g_personalFolderOutputWindow.SetContent( "Request Timed Out" );
        else if ( oExecutor.get_aborted() )
            g_personalFolderOutputWindow.SetContent( "Request Aborted" );
        else
            g_personalFolderOutputWindow.SetContent( "HTTP Error: " );
    }
}

// --------------------------------------------------------------------------------------------------------------
sfPopup.prototype.getPersonalFoldersCompleted = function ( oExecutor, oEventArgs )
{
    if ( oExecutor.get_responseAvailable() )
    {
        var jsonData = oExecutor.get_responseData();

        var smartFolder = eval("("+jsonData+")");

        //alert("JSON parsed: " + smartFolder.items.length + " items");
        var actionClick = "";
        var htmlOut = "<div style='text-align:left;'>";
        
        for( var t=0; t<smartFolder.items.length; t++ )
        {
			if ( g_currentSFPopup.m_returnSelectedFolder )
				actionClick = "onclick='g_currentSFPopup.SelectionCallback(\""+smartFolder.items[t].FullName+"\");'";
			else
				actionClick = "onclick='g_currentSFPopup.actionWhitelist("+smartFolder.items[t].ID+",$(\"sfp"+smartFolder.items[t].ID+"\"));'";
				
            //htmlOut += "<div style='clear:left; width:200px; border-bottom: dotted 1px #dedeab; height:28px; margin-top:2px;'>";
            htmlOut += "<div style='clear:left; height:28px; margin-top:1px;'>";
            if ( g_currentSFPopup.m_returnSelectedFolder )
				htmlOut += "<img src='images/add 16x16.png' style='cursor:pointer; float:right; margin:5px;' alt='+' title='Select' border='0' "+actionClick+" />";
            else
				htmlOut += "<img src='images/add 16x16.png' style='cursor:pointer; float:right; margin:5px;' alt='+' title='Add to "+smartFolder.items[t].FullName +"' border='0' "+actionClick+" />";
            htmlOut += "<img src='itemDownload.aspx?THUMBID="+smartFolder.items[t].ID+"' border='0' style='float:left; max-width:24px; max-height:24px; margin:1px;' />";
            htmlOut += "<div class='sfpopupItem' title='"+smartFolder.items[t].FullName +"' "+actionClick+" id='sfp"+smartFolder.items[t].ID+"' >";
            htmlOut += "<div style='white-space:nowrap;'>" + smartFolder.items[t].Name + "</div>";
            /*
            if ( g_currentSFPopup.m_returnSelectedFolder )
				htmlOut += "<a href='javascript:g_currentSFPopup.SelectionCallback(\""+smartFolder.items[t].FullName+"\");' class='DarkLink' >"+smartFolder.items[t].Name +"</a></div>"
            else
				htmlOut += "<a href='browse.aspx?ID="+smartFolder.items[t].ID+"' class='DarkLink' >"+smartFolder.items[t].Name +"</a></div>";
			*/
            htmlOut += "</div>";
        }
        htmlOut += "</div>";

        g_currentSFPopup.SetContent ( htmlOut );
    }
    else
    {
        if ( oExecutor.get_timedOut() )
            g_personalFolderOutputWindow.SetContent( "Request Timed Out" );
        else if ( oExecutor.get_aborted() )
            g_personalFolderOutputWindow.SetContent( "Request Aborted" );
        else
            g_personalFolderOutputWindow.SetContent( "HTTP Error: " );
    }
}


// --------------------------------------------------------------------------------------------------------------
sfPopup.prototype.getSharedFoldersCompleted = function ( oExecutor, oEventArgs )
{
	
    if ( oExecutor.get_responseAvailable() )
    {
    
        var jsonData = oExecutor.get_responseData();


        var res = eval("("+jsonData+")");
        
		//alert('Eval Complete for '+ res.shareList.userName );
        
        var userID = res.shareList.userID;
		var userName = '"'+res.shareList.userName+'"';
        
        var htmlOut = "<div style='text-align:left;'>";
        for( var t=0; t<res.shareList.folders.length; t++ )
        {
			var folderNamePar = '"'+res.shareList.folders[t].Name+'"';
            //htmlOut += "<div style='clear:left; width:200px; border-bottom: dotted 1px #dedeab; height:28px; margin-top:2px;'>";
            htmlOut += "<div style='clear:left; border-bottom: dotted 1px #dedeab; height:28px; margin-top:2px;'>";
            htmlOut += "<img src='images/delete_16x16.png' style='cursor:pointer; float:right; margin-top:4px;' alt='+' title='Remove&nbsp;this&nbsp;contact from the share list of "+res.shareList.folders[t].FullName +"' border='0' onclick='g_currentSFPopup.actionUnshare("+res.shareList.folders[t].ID+","+userID+","+userName+","+folderNamePar+");' />";
            htmlOut += "<img src='images/ico/folderIco 24x24.png' border='0' align='left' />";
            htmlOut += "<div style='padding-top:4px; white-space:nowrap; overflow:hidden;' title='"+res.shareList.folders[t].FullName +"'>";
            htmlOut += "<a href='browse.aspx?ID="+res.shareList.folders[t].ID+"' class='DarkLink' >"+res.shareList.folders[t].Name +"</a></div>";
            htmlOut += "</div>";
        }
        htmlOut += "</div>";

        g_currentSFPopup.SetContent ( htmlOut );
    }
    else
    {
        if ( oExecutor.get_timedOut() )
            g_personalFolderOutputWindow.SetContent( "Request Timed Out" );
        else if ( oExecutor.get_aborted() )
            g_personalFolderOutputWindow.SetContent( "Request Aborted" );
        else
            g_personalFolderOutputWindow.SetContent( "HTTP Error: " );
    }
}

// --------------------------------------------------------------------------------------------------------------
sfPopup.prototype.getSPression = function( userID  )
{
    var rnd = Math.floor(Math.random() * 100); // ramdom # between 0 and 99
	var oRequest = new Sys.Net.WebRequest();
	oRequest.set_httpVerb("GET");
	oRequest.set_url("itemAction.aspx?Action=DisplaySPressions&UserID=" + userID + "&Format=JSON&Filter=sPression&RND=" + rnd);
   	oRequest.add_completed( sfPopup.prototype.getSPressionsCompleted );
	oRequest.invoke();
}

// --------------------------------------------------------------------------------------------------------------
sfPopup.prototype.getPersonalFolders = function( userID, folderID  )
{
    var rnd = Math.floor(Math.random() * 100); // ramdom # between 0 and 99
    var oRequest = new Sys.Net.WebRequest();
	oRequest.set_httpVerb("GET");
	oRequest.set_url("itemAction.aspx?Action=DisplayFolder&FolderID=" + folderID + "&Format=JSON&Filter=foldersContentSaved&RND=" + rnd);
   	oRequest.add_completed( sfPopup.prototype.getPersonalFoldersCompleted );
	oRequest.invoke();
}

// retrieves all the folders containing the given item owned by userID
// --------------------------------------------------------------------------------------------------------------
sfPopup.prototype.getItemFolders = function( userID, itemID  )
{
    var rnd = Math.floor(Math.random() * 100); // ramdom # between 0 and 99
    var oRequest = new Sys.Net.WebRequest();
	oRequest.set_httpVerb("GET");
	oRequest.set_url("itemAction.aspx?Action=DisplayItemFolder&ID=" + itemID + "&Format=JSON&Filter=foldersContentSaved&RND=" + rnd);
   	oRequest.add_completed( sfPopup.prototype.getItemFoldersCompleted );
	oRequest.invoke();
}

// retrieves all the folders shared to the given contact owned by userID
// --------------------------------------------------------------------------------------------------------------
sfPopup.prototype.getSharedFolders = function( userID, contactID  )
{
    var rnd = Math.floor(Math.random() * 100); // ramdom # between 0 and 99
    var oRequest = new Sys.Net.WebRequest();
	oRequest.set_httpVerb("GET");
	oRequest.set_url("itemAction.aspx?Action=DisplaySharedFolder&ContactID=" + contactID + "&Format=JSON&Filter=foldersContentSaved&RND=" + rnd);
   	oRequest.add_completed( sfPopup.prototype.getSharedFoldersCompleted );
	oRequest.invoke();
}
