/**
 * Reunion subscription Javascript functions used for the
 * EuroAlumni web application
 * (c) 2008 Euro-Alumni e.V.
 **/
 
/** The ID of the current executing role **/
var executorRoleID;
 
/**
 * Subscribes the user to one distribution list
 * and calls the function to update the display
 * afterwards 
 *
 * @param distributionListID the ID of the distribution list
 *        the executing user should be subscribed to
 * @return false
 **/
function subscribe( distributionListID ) {
	
	//Switch to working mode
	
	//Get the link clicked 
	var linkClicked = document.getElementById( "subcribeLink_"+distributionListID );
	
	if ( linkClicked ) {

		//Hide the link
		linkClicked.style.display = "none";
	}
	
	//Build the AJAX statement
  var requestParamString = 
    "filter=ajaxDistributionList&ajaxAction=subscribe"+
    "&dlmid="+distributionListID;
 
  //Send it to the server
  postPostRequest( 
    ajaxPage, 
    requestParamString, 
    'updateDisplay' );		
     
  //Return false for the anchor
  return false;
}


/**
 * Unsubscribes the user from one distribution list
 * and calls the function to update the display
 * afterwards 
 *
 * @param distributionListID the ID of the distribution list
 *        the executing user should be unsubscribed from
 * @return false
 **/
function unsubscribe( distributionListID ) {
  
  //Switch to working mode
  
  //Get the link clicked 
  var linkClicked = document.getElementById( "unsubcribeDiv_"+distributionListID );
  
  if ( linkClicked ) {

    //Hide the link
    linkClicked.style.display = "none";
  }
  
  //Build the AJAX statement
  var requestParamString = 
    "filter=ajaxDistributionList&ajaxAction=unsubscribe"+
    "&dlmid="+distributionListID;
 
  //Send it to the server
  postPostRequest( 
    ajaxPage, 
    requestParamString, 
    'updateDisplay' );    
     
  //Return false for the anchor
  return false;
}


/**
 * Updates the permission tr if the change
 * was successful
 **/
function updateDisplay() {

  //Exit immediately if the server response is empty
  if ( serverXmlResponse === null ) {
      return;
  }

  //Get the affected data and return if there is none
  var distributionLists = serverXmlResponse.getElementsByTagName('distributionlist');
  if ( (distributionLists === null) || (distributionLists.length < 1) ) {
      return;
  }
	var distributionList = distributionLists[0];

	//Extract the distributionlist id and action
	var distributionListID = distributionList.getAttribute( "id" );	
	var action = distributionList.getAttribute( "action" );

  //Get references to the 2 divs
  var subscribeDiv = document.getElementById( "subscribeDiv_"+distributionListID );
  var unsubscribeDiv = document.getElementById( "unsubscribeDiv_"+distributionListID );

  //Check on the action which link to show and which not
  if ( action == "subscribe" ) {
    subscribeDiv.style.display = "none";
    unsubscribeDiv.style.display = "inline";
  } else {
    subscribeDiv.style.display = "inline";
    unsubscribeDiv.style.display = "none";
  }
}
 