/********************************************************************************
 *                                                                              *
 *  (c) Copyright 2009 The Open University UK                                   *
 *                                                                              *
 *  This software is freely distributed in accordance with                      *
 *  the GNU Lesser General Public (LGPL) license, version 3 or later            *
 *  as published by the Free Software Foundation.                               *
 *  For details see LGPL: http://www.fsf.org/licensing/licenses/lgpl.html       *
 *               and GPL: http://www.fsf.org/licensing/licenses/gpl-3.0.html    *
 *                                                                              *
 *  This software is provided by the copyright holders and contributors "as is" *
 *  and any express or implied warranties, including, but not limited to, the   *
 *  implied warranties of merchantability and fitness for a particular purpose  *
 *  are disclaimed. In no event shall the copyright owner or contributors be    *
 *  liable for any direct, indirect, incidental, special, exemplary, or         *
 *  consequential damages (including, but not limited to, procurement of        *
 *  substitute goods or services; loss of use, data, or profits; or business    *
 *  interruption) however caused and on any theory of liability, whether in     *
 *  contract, strict liability, or tort (including negligence or otherwise)     *
 *  arising in any way out of the use of this software, even if advised of the  *
 *  possibility of such damage.                                                 *
 *                                                                              *
 ********************************************************************************/
/**
 * Javascript functions for users
 */
function displayUsers(objDiv,users,start){
	
	var lOL = new Element("ol", {'class':'user-list-ol'});
	for(var i=0; i< users.length; i++){
		if(users[i].user){
			var iUL = new Element("li", {'id':users[i].user.userid, 'class':'user-list-li'});
			lOL.insert(iUL);			
			var blobDiv = new Element("div", {'class':'user-blob'});
			var blobUser = renderUser(users[i].user);
			blobDiv.insert(blobUser);
			iUL.insert(blobDiv);
		}
	}
	objDiv.insert(lOL);
}



function renderUser(user){

	var uDiv = new Element("div",{id:'context'});
	var cI = new Element('div',{'id':'contextimage'});
	
	if(user.isgroup == 'Y'){
		cI.insert("<a href='group.php?groupid="+ user.userid +"'><img src='"+user.photo+"'/></a>");
	} else {
		cI.insert("<a href='user.php?userid="+ user.userid +"'><img src='"+user.photo+"'/></a>")
	}
	
	uDiv.insert(cI);
	
	var uiDiv = new Element("div",{id:'contextinfo'});
	if(user.isgroup == 'Y'){
		uiDiv.insert("<b><a href='group.php?groupid="+ user.userid +"'>" + user.name + "</a></b>");
	} else { 
		uiDiv.insert("<b><a href='user.php?userid="+ user.userid +"'>" + user.name + "</a></b>");		
	}
	if(user.description != ""){
		uiDiv.insert("<p>"+user.description+"</p>");
	}
	if(user.website != ""){
        uiDiv.insert("<p><a href='"+user.website+"' target='_blank'>"+user.website+"</a></p>");
    }
	uDiv.insert(uiDiv);
	uDiv.insert("<div style='clear:both'></div>");
	return uDiv;

}