
function removeFromSet( resourceId, idOfSet ) {
	jQuery.ajax({
        url: "/AloeView/ajax/removeFromSet",
        type: 'get',  // get is the default type
        data: {
	        resourceId: resourceId,
	        setId: idOfSet
		},
		success: function( data, textStatus, jqXHR ) {
			location.reload();
		},
		error: function( jqXHR, textStatus, errorThrown ) {
			// do nothing
		}
	});
}


function removeFromGroup( resourceId, groupId, followUpUrl ) {
	jQuery.ajax({
        url: "/AloeView/ajax/removeFromGroup",
        type: 'get',  // get is the default type
        data: {
	        resourceId: resourceId,
	        groupId: groupId
		},
		success: function( data, textStatus, jqXHR ) {
			//alert( location.href );
			if ( followUpUrl != null ) {
				location.href = followUpUrl;
			}
			else {
				location.reload();
			}
		},
		error: function( jqXHR, textStatus, errorThrown ) {
			// do nothing
		}
	});
}

function deleteGroupResourceAsAdmin( resourceId, userId, allOccurences ) {
	jQuery.ajax({
        url: "/AloeView/ajax/deleteResource",
        type: 'get',  // get is the default type
        data: {
	        resourceId: resourceId,
	        userId: userId,
	        allOccurences: allOccurences
		},
		success: function( data, textStatus, jqXHR ) {
			document.body.removeChild(document.body.firstChild);
		},
		error: function( jqXHR, textStatus, errorThrown ) {
			// do nothing
		}
	});
}

function removeGroupMemberAsGroupAdmin( groupId, groupName, userId ) {
	jQuery.ajax({
        url: "/AloeView/ajax/removeUserFromGroup",
        type: 'get',  // get is the default type
        data: {
	        groupId: groupId,
	        groupName: groupName,
	        userId: userId
		},
		success: function( data, textStatus, jqXHR ) {
			document.body.removeChild(document.body.firstChild);
			location.reload();
		},
		error: function( jqXHR, textStatus, errorThrown ) {
			// do nothing
		}
	});
}


/*
 Create an HTML subtree like:
	<div id="floatingDeleteResourceAsGroupAdmin"> 
	<h2><fmt:message key="Content_DeleteResource" /></h2>
	<form accept-charset="utf-8" id="delete_resource_form" action="javascriptDisabled" method="post">
	    <div class="alert"><fmt:message key="Content_DoYouReallyWantToDelete" /></div>
	    <div>
	        <span class="grey tiny"><fmt:message key="Content_ThisActionCannotBeUndone" /></span>
	    </div>
	    <div class="clear"></div>
	    <div class="buttons_floating_element">
	        <input class="button" name="delete" type="submit" value="${aloefn:message('Button_Delete')}" id="button_for_resource_deletion"
	         onclick="deleteGroupResourceAsAdmin('resourceId',null,true);return(false);"/>
	        <input class="button" type="submit" value="${aloefn:message('Button_Cancel')}" onclick="document.getElementById('floating_delete_group_resource_as_admin').style.display='none';return(false);"/>
	    </div>
	</form>
	</div>
*/

function createAjaxDeleteGroupResourceAsAdminDiv( event, resourceId, headline, alert, infos, cannotBeUndone, xOffset, yOffset, buttonDelete, buttonCancel ) {
    
    if ( document.getElementById( 'floatingDeleteResourceAsGroupAdmin' ) == null ) {
        
        var geometry = getGeometry();
        var xPos = event.clientX + geometry.getHorizontalScroll() + xOffset;
        var yPos = event.clientY + geometry.getVerticalScroll() + yOffset;
        
        //alert( "x position: " + xPos + ", y position: " + yPos );
                        
        var floatingMessage = document.createElement( "div" );
        //floatingMessage.appendChild( document.createTextNode( " " ) );

        var innerHtml = "<div id=\"floatingDeleteResourceAsGroupAdmin\" class=\"floatingForm\" style=\"top:" + yPos + "px;left:" + xPos + "px;\">\n"
          + "<h2>" + headline + "</h2>\n"          
          + "<form accept-charset=\"utf-8\" class=\"delete_group_resource_as_admin_form\" action=\"javascriptDisabled\" method=\"post\" >\n"
          + "<div class=\"alert\">" + alert + "</div>\n"
          + infos
          + "<div>\n"
          + "   <span class=\"grey tiny\">" + cannotBeUndone + "</span>\n"
          + "</div>\n"
          + "<div class=\"clear\"></div>\n"
          + "<div class=\"buttons_floating_element\">\n"
          + " <a href=\"javascriptDisabled\" class=\"flexible_button\" "
          + "onclick=\"deleteGroupResourceAsAdmin('" + resourceId + "',null,true);return(false);\">\n" 
          + "<span>" + buttonDelete + "</span>\n"
          + "</a>"
          + " <a href=\"javascriptDisabled\" class=\"flexible_button\" "
          + "onclick=\"document.body.removeChild(document.body.firstChild);return(false);\">\n"
          + "<span>" + buttonCancel + "</span>\n"
          + "</a>"
   	      + "</div>\n";
          + "</form>\n"
          + "</div>\n";
                          
        /* Workaround for IE: add empty div as first child of body tag, then
             replace inner HTML of this newly inserted div by our floating
             element, which is positioned by css style specifications */
        var replaceHere = document.body.insertBefore( floatingMessage, document.body.firstChild );
        replaceHere.innerHTML = innerHtml;
    }
}

function createDeleteGroupResourceAsAdminDiv( event, resourceId, headline, alert, infos, cannotBeUndone, xOffset, yOffset, buttonDelete, buttonCancel ) {
    
    if ( document.getElementById( 'floatingDeleteResourceAsGroupAdmin' ) == null ) {
        
        var geometry = getGeometry();
        var xPos = event.clientX + geometry.getHorizontalScroll() + xOffset;
        var yPos = event.clientY + geometry.getVerticalScroll() + yOffset;
        
        //alert( "x position: " + xPos + ", y position: " + yPos );
                        
        var floatingMessage = document.createElement( "div" );
        //floatingMessage.appendChild( document.createTextNode( " " ) );

        var innerHtml = "<div id=\"floatingDeleteResourceAsGroupAdmin\" class=\"floatingForm\" style=\"top:" + yPos + "px;left:" + xPos + "px;\">\n"
          + "<h2>" + headline + "</h2>\n"          
          + "<form accept-charset=\"utf-8\" class=\"delete_group_resource_as_admin_form\" action=\"deleteResource\" method=\"post\" >\n"
          + "<div class=\"alert\">" + alert + "</div>\n"
          + "<div>\n"
          +  infos
          + "   <span class=\"grey tiny\">" + cannotBeUndone + "</span>\n"
          + "</div>\n"
          + "<div class=\"clear\"></div>\n"
          + "<div class=\"buttons_floating_element\">\n"
          + "<input type=\"hidden\" name=\"resourceId\" value=\"" + resourceId + "\" />\n"
          + "<input type=\"hidden\" name=\"allOccurences\" value=\"true\" />\n"

          + " <a href=\"javascriptDisabled\" class=\"flexible_button\" "
   	      + "onclick=\"submitFirstFormBelowReferenceElement('floatingDeleteResourceAsGroupAdmin');return(false);\"/>\n"
          + "<span>" + buttonDelete + "</span>\n"
          + "</a>"
          + " <a href=\"javascriptDisabled\" class=\"flexible_button\" "
   	      + "onclick=\"document.body.removeChild(document.body.firstChild);return(false);\"/>\n"
          + "<span>" + buttonCancel + "</span>\n"
          + "</a>"
   	      + "</div>\n"
          + "</form>\n"
          + "</div>\n";
                                           
        /* Workaround for IE: add empty div as first child of body tag, then
             replace inner HTML of this newly inserted div by our floating
             element, which is positioned by css style specifications */
        var replaceHere = document.body.insertBefore( floatingMessage, document.body.firstChild );
        replaceHere.innerHTML = innerHtml;
    }
}


function createAjaxRemoveGroupMemberAsGroupAdminDiv( event, groupId, groupName, userId, headline, alert, infos, xOffset, yOffset, buttonRemove, buttonCancel ) {
    
    if ( document.getElementById( 'floatingRemoveGroupMemberAsGroupAdmin' ) == null ) {
        
        var geometry = getGeometry();
        var xPos = event.clientX + geometry.getHorizontalScroll() + xOffset;
        var yPos = event.clientY + geometry.getVerticalScroll() + yOffset;
        
        //alert( "x position: " + xPos + ", y position: " + yPos );
                        
        var floatingMessage = document.createElement( "div" );
        //floatingMessage.appendChild( document.createTextNode( " " ) );

        var innerHtml = "<div id=\"floatingRemoveGroupMemberAsGroupAdmin\" class=\"floatingForm\" style=\"top:" + yPos + "px;left:" + xPos + "px;\">\n"
          + "<h2>" + headline + "</h2>\n"          
          + "<form accept-charset=\"utf-8\" class=\"remove_group_member_as_group_admin_form\" action=\"javascriptDisabled\" method=\"post\" >\n"
          + "<div class=\"alert\">" + alert + "</div>\n"
          + "<div>\n"
          +  infos
          + "</div>\n"
          + "<div class=\"clear\"></div>\n"         
          + "<div class=\"buttons_floating_element\">\n"
          + " <a href=\"javascriptDisabled\" class=\"flexible_button\" "
   	      + "onclick=\"removeGroupMemberAsGroupAdmin('" + groupId + "','" + groupName + "','" + userId + "');return(false);\"/>\n"
          + "<span>" + buttonRemove + "</span>\n"
          + "</a>"
          + " <a href=\"javascriptDisabled\" class=\"flexible_button\" "
   	      + "onclick=\"document.body.removeChild(document.body.firstChild);return(false);\"/>\n"
          + "<span>" + buttonCancel + "</span>\n"
          + "</a>"
   	      + "</div>\n";
          + "</form>\n"
          + "</div>\n";
                                           
        /* Workaround for IE: add empty div as first child of body tag, then
             replace inner HTML of this newly inserted div by our floating
             element, which is positioned by css style specifications */
        var replaceHere = document.body.insertBefore( floatingMessage, document.body.firstChild );
        replaceHere.innerHTML = innerHtml;
    }
}

function createAjaxRemoveAssociatedResourceDiv( event, resourceId, resourceType, associatedResourceId, associatedResourceContributor, followUpUrl, headline, alert, infos, xOffset, yOffset, buttonRemove, buttonCancel ) {
    
    if ( document.getElementById( 'floatingRemoveAssociatedResource' ) == null ) {
        
        var geometry = getGeometry();
        var xPos = event.clientX + geometry.getHorizontalScroll() + xOffset;
        var yPos = event.clientY + geometry.getVerticalScroll() + yOffset;
        
        //alert( "x position: " + xPos + ", y position: " + yPos );
                        
        var floatingMessage = document.createElement( "div" );
        //floatingMessage.appendChild( document.createTextNode( " " ) );

        var innerHtml = "<div id=\"floatingRemoveAssociatedResource\" class=\"floatingForm floatingSimpleForm\" style=\"top:" + yPos + "px;left:" + xPos + "px;\">\n"
          + "<h2>" + headline + "</h2>\n"          
          + "<form accept-charset=\"utf-8\" class=\"remove_associated_resource_form\" action=\"javascriptDisabled\" method=\"post\" >\n"
          + "<div class=\"alert\">" + alert + "</div>\n"
          + "<div>\n"
          +  infos
          + "</div>\n"
          + "<div class=\"clear\"></div>\n"         
          + "<div class=\"buttons_floating_element\">\n"
          + " <a href=\"javascriptDisabled\" class=\"flexible_button\" "
          + "onclick=\"removeAssociatedResource('" + resourceId + "','" + resourceType + "','" + associatedResourceId + "','" + associatedResourceContributor + "','" + followUpUrl + "');return(false);\">\n" 
          + "<span>" + buttonRemove + "</span>\n"
          + "</a>"
          + " <a href=\"javascriptDisabled\" class=\"flexible_button\" "
          + "onclick=\"document.body.removeChild(document.body.firstChild);return(false);\">\n"
          + "<span>" + buttonCancel + "</span>\n"
          + "</a>"
    	  + "</div>\n";
          + "</form>\n"
          + "</div>\n";
                                              
          
          /* Workaround for IE: add empty div as first child of body tag, then
             replace inner HTML of this newly inserted div by our floating
             element, which is positioned by css style specifications */
        var replaceHere = document.body.insertBefore( floatingMessage, document.body.firstChild );
        replaceHere.innerHTML = innerHtml;
    }
}


function removeAssociatedResource( resourceId, resourceType, associatedResourceId, associatedResourceContributor, followUpUrl ) {
	jQuery.ajax({
        url: "/AloeView/ajax/removeAssociatedResource",
        type: 'get',  // get is the default type
        data: {
			resourceId: resourceId,
			resourceType: resourceType,
			associatedResourceId: associatedResourceId,
			userId: associatedResourceContributor
		},
		success: function( data, textStatus, jqXHR ) {
			document.body.removeChild(document.body.firstChild);
			if ( followUpUrl != null ) {
				location.href = followUpUrl;
			}
			else {
				location.reload();
			}
		},
		error: function( jqXHR, textStatus, errorThrown ) {
			// do nothing
		}
	});
}



		      
