function getElementsByClassName(clName, tag, elm){
	var testClass = new RegExp("(^|\\s)" + clName + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;						
	for(var i=0; i<length; i++){
		current = elements[i];				
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

function loadConfirmDelete4Profile(){
	var lnk = getElementsByClassName('delete', 'a', document.getElementById('profile'));
	for(var i=0; i<lnk.length; i++) {
		lnk[i].onclick = function() {
			var str ='';
			if(this.getAttribute('rev')) {
				str = this.getAttribute('rev');		    	
			}
			var doaction = 'act=deletecommentprofile&'+this.getAttribute('rel');
			if(confirm("Are you sure you want to delete "+str+"?")) {
				//alert(doaction);
				window.location.href= '/forum-manageprofile.php?'+doaction;				
			}
			else{
				return false
			}
		}
	}
}

function addFriendList(obj){
	var lnk = getElementsByClassName('friend', 'a', document.getElementById(obj));
	for(var i=0; i<lnk.length; i++) {
		lnk[i].onclick = function() {
			var str ='';
			if(this.getAttribute('rev')) {
				str = this.getAttribute('rev');		    	
			}
			var str = 'act=add_friend&'+this.getAttribute('rel');
			request('/forum-manageprofile.php?'+str , updateResult);
			contentID = this.parentNode.id;			
		}
	}
}

function savegroup() {
	request('/forum-manageprofile.php?act=add_group&gname='+encodeURIComponent(get('gname').value) , updateGroupList);
} 

function move_friend_init(){
	var moveObj = getElementsByClassName('move_box', 'div', document.getElementById('friendBox'));	
	for(var i=0; i<moveObj.length; i++) {		
		new Draggable(moveObj[i].parentNode, {revert:true});
	}
	
	var destObj = getElementsByClassName('destinationBox', 'li', document.getElementById('grouplist'));	
	for(var i=0; i<destObj.length; i++) {
		//alert(destObj[i].id);	
		
		Droppables.add(destObj[i].id, {
			accept:'imageBoxS', hoverclass:'destinationBoxOver', onDrop:function(element){
				Element.hide(element); 
				new Ajax.Request('/forum-manageprofile.php?act=move_friend&gid='+this.element.id+'&id='+encodeURIComponent(element.id), {
					asynchronous:true, evalScripts:true, onComplete:function(request){window.location.reload()/*function(request){Element.hide('indicator')*/}, onLoading:function(request){Element.show('indicator')} 
					
				})
			}
		})
	}
}


