/*
Filename : friends.js
Purpose : To Manage the Friends Page ( Including 3 Tabs)
Date Created : 16 Mar 2009
Author : Primoris

Functionalities :
- Ajax Based Pagination for Each of the Tabs
- Ajax Based data Sorting for Tab 2 and 3

Modification History  :

*/



var pager1=initPaging("pager1","pageListTab1",0,0,0,function(vpage,vObject){ showFriendsPage(1,vpage,vObject.show); });
var pager2=initPaging("pager2","pageListTab2",0,0,0,function(vpage,vObject){ showFriendsPage(2,vpage,vObject.show); });
var pager3=initPaging("pager3","pageListTab3",0,0,0,function(vpage,vObject){ showFriendsPage(3,vpage,vObject.show); });
var profilePager=initPaging("profileWallPager","pageList_profileWall",0,0,0,function(vpage,vObject){ showProfileWallPage(vpage,null); });

function toggleLayerBlock(vObject)
{

	if($(vObject).style.display=='none')
	{
		$(vObject).show();
		$(vObject).select();
	}

	else

		$(vObject).hide();


}

function postFriendSubComment(vText,vToUserId,vwall_id)
{	
	showProgress("Posting Comment",true);
	invoke(null,'channel:comment', {value:vText,user_id:vToUserId,comment_id:vwall_id,comment_type:1}, true, function(req){
	hideProgress();
		if(req.responseText=="success")
		{
			
			showFriendsPage(1,0,null);
		}
		
	});
}

function showFriendsList(vtabMode,vsortType)
{
	var resultElement="friend_all";
	if(vtabMode==3)  resultElement="friend_customers";
	$(resultElement).innerHTML='';

	invoke(resultElement,"channel:showFriends",{name:vChannelName,tabMode:vtabMode,sort:vsortType},false);

}

function showFriendsComment(vtxtObject)
{
$(vtxtObject).style.visibility='visible'
	
}

function showFriendsPage(vtabMode,vPage,vshowPerPage)
{

	var resultElement="friend_all";
	if(vtabMode==3)  resultElement="friend_customers";
	if(vtabMode==1)  resultElement="friend_new";
	showLoadingText(resultElement,"Loading friends info...");

	if(vshowPerPage==null) 

		invoke(resultElement,"channel:showFriends",{isAjax:1,name:vChannelName,tabMode:vtabMode,page:vPage},false,function(req){});
	else

		invoke(resultElement,"channel:showFriends",{isAjax:1,name:vChannelName,tabMode:vtabMode,page:vPage,show:vshowPerPage},false,function(req){});
}



function postAuthorComment(vText,vchannelID,vWallID)
{	showProgress("Posting Comment",true);
	invoke(null,'channel:comment', {value:vText,user_id:vchannelID,comment_id:vWallID,comment_type:1}, true, function(req){
		hideProgress();
		showProfileWallPage(0,null);
	});
}

function showProfileWall()
{
	invoke("profile_wall",'channel:profile_wall', {isAjax:1,page:0}, false, function(req){	});
}


function showProfileWallPage(vPage,vshowPerPage)
{

	if(vshowPerPage==null)
		invoke("profile_wall",'channel:profile_wall', {isAjax:1,page:vPage}, false, function(req){});
	else
		invoke("profile_wall",'channel:profile_wall', {isAjax:1,show:vshowPerPage}, false, function(req){});

}


function showProfileComment(vtxtObject,variablecount)
{

$(vtxtObject).show();

}

function showFriendsWall()
{
	 showFriendsPage(1,0,null);
}



function postAuthorStatus(vText,vToUserId,vCommentType)
{	
	showProgress("Updating your status..",true);
	invoke(null,'channel:comment', {value:vText,user_id:vToUserId,comment_type:vCommentType}, true, function(req){
			if(req.responseText=="success"){ hideProgress();location.reload();	}
			
	});
}



function deleteProfileComment(vWallId)
{



	Message.confirm("Are you sure to delete this comment?", function() {
			invoke(null,'channel:delete_comment', {wall_id:vWallId}, true, function(req){
				if(req.responseText=="success")
				{
				
					showProfileWall();
				}
			});
		});



}

function deleteFriendsComment(vWallId)
{

	Message.confirm("Are you sure to delete this comment?", function() {
			invoke(null,'channel:delete_comment', {wall_id:vWallId}, true, function(req){
				if(req.responseText=="success")
				{
					showFriendsWall();
			
				}
			});
		});

}
function  showMoreEffect(vBlockName,vLinkObject)
{


	if($(vBlockName).style.display=='none'){
		if(!Prototype.Browser.IE)
			new Effect.BlindDown(vBlockName, {duration: 0.4, queue: 'end'});
		else
			$(vBlockName).show();
		vLinkObject.innerHTML="Less..";

	}
	else{

		if(!Prototype.Browser.IE)
			new Effect.BlindUp(vBlockName, {duration: 0.4, queue: 'end'});
		else
			$(vBlockName).hide();

		vLinkObject.innerHTML="More..";

		//For Recursive Folding of Childs

		//$(vBlockName).select('[class="msgBlock"]').each(function(vItem){new Effect.BlindUp(vItem, {duration: 0.4, queue: 'end'});});	
		//$(vBlockName).select('[class="more_link"]').each(function(vLinkItem){vLinkItem.innerHTML="More...";});

	}

}
function  showMoreSubComment(vBlockId)
{
	vBlockName="msgBlock_" + vBlockId;
	vMoreSubCommentName="lnkSubComment_" + vBlockId;
	vBlockMoreSubCmt="dvMoreSub_" + vBlockId;

	if($(vMoreSubCommentName).getAttribute("foldsts")==0)
		$(vMoreSubCommentName).setAttribute("foldsts",1);
	else
		$(vMoreSubCommentName).setAttribute("foldsts",0);


	if($(vMoreSubCommentName).getAttribute("foldsts")==1){
		$(vBlockMoreSubCmt).show();
		$(vMoreSubCommentName).update("Show Less");
		$(vBlockName).select('[class="more_sub_comment"]').each(function(vItem){new Effect.SlideDown(vItem, {duration: 0.6, queue: 'end'});});	
	}
	else{
		$(vBlockMoreSubCmt).show();
		$(vMoreSubCommentName).update("Show All");
		$(vBlockName).select('[class="more_sub_comment"]').each(function(vItem){new Effect.SlideUp(vItem, {duration: 0.6,queue: 'end'});});	

	}


}