var xmlHttp;
function showU(str,id,usn,avt,user,recver, url)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	 //alert ("Browser");
	var url= url+ "&q="+id+"&r="+usn+"&u="+user+"&s="+avt+"&rec_m="+recver;
	//url=url+"&p="+str+"&q="+str2;
	url=url+"&sid="+Math.random();
	
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");	
	xmlHttp.send('p='+encodeURIComponent(str));
}
function showUser(str,id,usn,avt,user,did,rec_m, reciever_un,is_pm, url)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request");
		 return;
	 }
	//var url="components/com_hello/views/hello/tmpl/default.php";
	// index2.php is used to get back to the same page in joomla
	
	//document.getElementById('divR'+id).value=document.getElementById('message_wall').value;
	document.getElementById('divR'+did).value =  str;
	
	document.getElementById('divR'+did).innerHMTL =str;
	document.getElementById('div_comment_id_value').value = did;
	var url= url + "&q="+id+"&r="+usn+"&u="+user+"&s="+avt+"&did="+did+"&rec_m="+rec_m+'&is_pm=' + is_pm;
	//url=url+"&p="+str+"&q="+str2;
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp.onreadystatechange=stateChangedComment;
	xmlHttp.open("POST",url,true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");	
	xmlHttp.send('p='+encodeURIComponent(str));
	// Huy's modification
	document.getElementById('div_comment_' + did).style.display = 'none';
	jQuery('#div9999' + did).slideToggle("normal");
}

function stateChangedComment()
{	
	var id = document.getElementById('div_comment_id_value').value;
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		//$('#div9999' + id).slideToggle("fast");
	}
}

function delUser(del_id, url)
{ 
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	 {
		 alert ("Browser does not support HTTP Request");
		 return;
	 }
	
	
	//alert(del_id);
	var answer = confirm ("Do you want to delete this message?");
	
	if (answer){
		var url = url + "index2.php?option=com_awdwall&view=awdwall&del="+del_id;
		document.getElementById('dd'+del_id).style.display='none';
	}else{
		var url="#";
	}
	
	
	//url=url+"&p="+str+"&q="+str2;
	url=url+"&sid="+Math.random();
	//alert(url);
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{	
		document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
	}
}
function GetXmlHttpObject() 
{
	var xmlHttp=null;
	try
	 {
		 // Firefox, Opera 8.0+, Safari
		 xmlHttp=new XMLHttpRequest();
	 }
	catch (e)
	 {
	 //Internet Explorer
	 try
	  {
	  	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	  }
	 catch (e)
	  {
	 	 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	 }
	return xmlHttp;
}

//Huy's modification
function likeComment(userId, commentId, url)
{
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp == null){
		 alert ("Browser does not support HTTP Request");
		 return;
	}
	
	document.getElementById('div_like_value').value = commentId;
	
	var url = url + "&user_id=" + userId + '&comment_id=' + commentId;	
	url = url+ "&sid=" + Math.random();
	
	xmlHttp.onreadystatechange = getCommentLike;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	
}

function getCommentLike()
{	
	var commentId = document.getElementById('div_like_value').value;
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		alert('You liked this');
		//document.getElementById("same_like_" + commentId).innerHTML = xmlHttp.responseText;		
		//$('#div_like_' + commentId).toggle("slow");
	}
}

function savePM(postedId, userId, toId, url)
{
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp == null){
		 alert ("Browser does not support HTTP Request");
		 return;
	}
	document.getElementById('div_pm_value').value = postedId;
	var url = url + "&user_id=" + userId + '&posted_id=' + postedId + '&to_id=' + toId;	
	url = url+ "&sid=" + Math.random();
	
	xmlHttp.onreadystatechange = getPM;
	xmlHttp.open("POST", url, true);
	var msg = document.getElementById('wall_pm_' + postedId).value;
	document.getElementById('div_pm_display_value_'  + postedId).value = msg;
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send('msg=' + encodeURIComponent(msg));
}

function getPM()
{		
	var postedId = document.getElementById('div_pm_value').value;
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){ 
		jQuery('#div_pm_' + postedId).slideToggle('slow');
		//jQuery('#div_pm_display_' + postedId).slideToggle('slow');
		document.getElementById('div_pm_display_' + postedId).style.display = 'block';
	}
}

function savePMReply(postedId, userId, toId)
{
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp == null){
		 alert ("Browser does not support HTTP Request");
		 return;
	}
	var pmId = document.getElementById('div_pm_reply_id').value;
	
	var url = "index2.php?option=com_awdwall&view=awdwall&task=pm_reply&user_id=" + userId + '&posted_id=' + postedId + '&to_id=' + toId + '&pm_id=' + pmId;	
	url = url+ "&sid=" + Math.random();
	
	xmlHttp.onreadystatechange = getPMReply;
	xmlHttp.open("POST", url, true);
	var msg = document.getElementById('wall_pm_reply_' + postedId).value;
	
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.send('msg=' + msg);
}

function getPMReply()
{		
	var postedId = document.getElementById('div_pm_value').value;
	var pmId = document.getElementById('div_pm_reply_id').value;
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){  
		jQuery('#div_pm_top_reply_' + postedId).slideToggle('slow');
		document.getElementById("div_reply_value_" + pmId).innerHTML = xmlHttp.responseText;	
	}
}

function getLike(commentId, url)
{
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp == null){
		 alert ("Browser does not support HTTP Request");
		 return;
	}
	
	document.getElementById('div_like_value').value = commentId;
	
	var url = url + '&comment_id=' + commentId;
	url = url+ "&sid=" + Math.random();
	
	xmlHttp.onreadystatechange = showLike;
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
	
}

function showLike()
{	
	var commentId = document.getElementById('div_like_value').value;
	if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		document.getElementById("same_like_" + commentId).innerHTML = xmlHttp.responseText;		
		jQuery('#div_like_' + commentId).slideToggle("normal");
		jQuery('#same_like_' + commentId).slideToggle("normal");
	}
}