
function h_sendTwitterPM(to, text){
	
	//alert(text);
	//g_friend_num=friend_num;
	//g_divId= divId;

	var tw_path = 'sendPrivateMsg.php';
	var tw_interface_path = 'ajax/ajax_twitterInterface.php';
	var pars="hictu_id="+g_hictu_id+"&tw_path="+tw_path+"&id="+to+"&text="+text;
	
	var request = YAHOO.util.Connect.asyncRequest('POST', tw_interface_path, twitterPMCallback, pars); 	
}

var twitterPMCallback =
{
  success: twitterPMCallbackResponse,
  failure: TwitterHandleFailure,
  argument: ['f', 'b'],
  cache: false
};

function twitterPMCallbackResponse(o) {
	if(o.responseText == undefined) return;
	var jsonList = o.responseText;
	var parsedJSON = jsonList.parseJSON();
		
	if(parsedJSON.response){
		//alert(parsedJSON.response);
		document.getElementById('buttonSaveChange').style.display = 'none';
		document.getElementById('messageSave').style.display = "inline";
		document.getElementById('messageSave').className = "ok";
		document.getElementById('messageSave').innerHTML = parsedJSON.response;
	}

	
}


var g_friend_num, g_divId, g_noFoundMsg;
function GetTwitterFriends(friend_num, divId,noFoundMsg){
	
	g_friend_num=friend_num;
	g_divId= divId;
	g_noFoundMsg= noFoundMsg;

	var tw_path = 'getFriends.php';
	var tw_interface_path = 'ajax/ajax_twitterInterface.php';
	var pars="hictu_id="+g_hictu_id+"&tw_path="+tw_path;
	
	var request = YAHOO.util.Connect.asyncRequest('POST', tw_interface_path, twitterCallback, pars); 
}

var TwitterHandleFailure = function(o){
// Access the response object's properties in the
// same manner as listed in responseSuccess( ).
// Please see the Failure Case section and
// Communication Error sub-section for more details on the
// response object's properties.
	alert('failure');
}


var GetTwitterFriendsResponse = function(o) {

	if(o.responseText == undefined) return;
	
	var jsonList = o.responseText;

	var parsedJSON = jsonList.parseJSON();
	if(parsedJSON.response == 'KO'){
			div = '<div style="margin-bottom:30px;padding-top:20px;padding-bottom:20px;padding-left:50px;font-size:16px;color:#5C97CF"> Twitter is over capacity</div>';
			document.getElementById(g_divId).innerHTML = div;

			return;
	}
	//alert(parsedJSON.friends);
	//alert(parsedJSON.friends[0].nickname);
	//alert(parsedJSON.friends.length)
	if(g_friend_num > parsedJSON.friends.length) g_friend_num=parsedJSON.friends.length;
	
	if(document.getElementById(g_divId))
	{
		if(parsedJSON.friends.length > 0){
			var div = '';
			for(var i=0; i<g_friend_num; i++){
				var tw_cont_id = parsedJSON.friends[i].id;
				var tw_cont_nickname = parsedJSON.friends[i].nickname;
				var tw_cont_avatar = parsedJSON.friends[i].avatar_url;
	
				div = div+'<div id="tw_'+tw_cont_id+'" class="DivAvatarImage"><div class="twpm"><a href="twitterPmwrite.php?id='+tw_cont_id+'&amp;to='+tw_cont_nickname+'"><img src="images/fumetto.gif" border="0" alt=""></a></div><a href="http://twitter.com/'+tw_cont_nickname+'" target="_blank"><img class="AvatarImage_1" alt="avatar" src="'+tw_cont_avatar+'" /></a><br />'+tw_cont_nickname+'</div>';
			}
			
			if (document.getElementById("allFriends"))
				document.getElementById("allFriends").style.display='block';
			document.getElementById(g_divId).innerHTML = div;
			//return div;
		}
		else{
			//div = '<div style="font-size:10px; padding:6px">No Twitter friends</div>';
			div = '<div style="margin-bottom:30px;padding-top:20px;padding-bottom:20px;padding-left:50px;font-size:16px;color:#5C97CF">'+g_noFoundMsg+'</div>';
			document.getElementById(g_divId).innerHTML = div;
		}
	}
}


var twitterCallback =
{
  success:GetTwitterFriendsResponse,
  failure: TwitterHandleFailure,
  argument: ['f', 'b'],
  cache: false
};

/*var twitterPostCallback =
{
  success:SendTwitterPostResponse,
  failure: TwitterHandleFailure,
  argument: ['f', 'b'],
  cache: false
};
*/

/*function ShowTwFriends(show){
	
	var path = 'modules/twitter/showFriends.php';

	var http_ShowTwFriends = getHTTPObject();
	http_ShowTwFriends.open("POST", path, true);
	http_ShowTwFriends.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
	http_ShowTwFriends.send("hictu_id="+g_hictu_id+"&show="+show);
	var loadingItem = document.getElementById('tw_friend_loading');
	if (loadingItem) loadingItem.style.visibility = 'visible';
	http_ShowTwFriends.onreadystatechange = function() {
		if (http_ShowTwFriends.readyState != 4) return;
		if (loadingItem) loadingItem.innerHTML = '<a href="twitterFriends.php?userProfile='+g_hictu_id+'">done</a>';
	};
}
*/
