var languageLoading = '<img src="'+MainURL+'ajax/loading.gif">';
var languageWallPost = "Type in your thoughts!";
var languageCommentPost = "Write a comment...";

NS4 = (document.layers) ? true : false;
var commentTimer = new Array();

function respondComment(id,per_id,txt_id)
{
	var thandler = 'append_comment_'+ txt_id;
	var box = 'comment_' + txt_id;
	comment_txt = document.getElementById( id );
	comment_box = document.getElementById( box );
	if(comment_box.value != ''){
		CH_AjaxRequest( 'ajax.php?module=activity&act=comment&per_id='+per_id+'&id='+id+'&comment='+ encodeURI(comment_txt.value),thandler ,'bottom' )
	}
	comment_txt.value = '';
	comment_box.style.display = 'none';
	/*alert(Handler);*/
}   

function checktxtEnter(event,id,per_id,txt_id)
{     
	var code = 0;
	if (NS4)
			code = event.which;
	else
			code = event.keyCode;

	if (code == 13){
		var thandler = 'append_comment_'+ txt_id;
		var box = 'comment_' + txt_id;
		comment_txt = document.getElementById( id );
		comment_box = document.getElementById( box );
		if(comment_txt.value != ''){
			CH_AjaxRequest( 'ajax.php?module=activity&act=comment&per_id='+per_id+'&id='+id+'&comment='+ encodeURI(comment_txt.value),thandler ,'bottom' )
		}
		comment_txt.value = '';
		comment_box.style.display = 'none';		
	 }   
}

function checkPostEnter(event,id,per_id)
{     
    var code = 0;
    if (NS4)
        code = event.which;
    else
        code = event.keyCode;
    if (code==13){
			postEnter(id,per_id);
     }   
}

function postEnter(id,per_id)
{  
	post = document.getElementById( id );
	var evn_id = document.getElementById('evn_id');
	var linkText = document.getElementById('lnk_txt');
	var linkName = document.getElementById('lnk_name');
	var linkNameValue =  encodeURI(linkName.value);
	
	if(linkNameValue == "")
	{
		linkNameValue = encodeURI(linkText.value);
	}

	//var twitter = document.getElementById('twitter');
	//var facebook = document.getElementById('facebook');
	var twitter = '';
	var facebook = '';
	var appendTwitter = "";
	var appendFacebook = "";

	if(twitter.checked)
	{
		appendTwitter = "&twitter=yes";
	}
	
	if(facebook.checked)
	{
		appendFacebook = "&facebook=yes";
	}

		CH_AjaxRequest( 'ajax.php?module=activity&act=post&per_id='+per_id+appendTwitter+appendFacebook+'&comment='+ encodeURI(post.value)+'&evn_id='+ encodeURI(evn_id.value)+'&lnk_txt='+ encodeURI(linkText.value)+'&lnk_name='+linkNameValue, 'append_post','yes' )

//	post.value = languageWallPost;
	evn_id.value = 0;
	linkText.value = 'http://';

	document.getElementById('post').value = "";

	document.getElementById('wlink').style.display = "none";
	document.getElementById('wevent').style.display = "none";
	document.getElementById('weventid').innerHTML = "";
	document.getElementById('weventid').style.display = "none";
	document.getElementById('wphoto').style.display = "none";
	document.getElementById('wphotoid').style.display = "none";
	document.getElementById('wphotoid').innerHTML = "";
	document.getElementById('wvideo').style.display = "none";
	document.getElementById('wvideoid').style.display = "none";
	document.getElementById('wvideoid').innerHTML = "";
}

function restoreLanguage( id ){
	comment_box = document.getElementById( id );
		if(comment_box.value == ''){
			if(id == "post"){
					comment_box.value = languageWallPost;
					button = document.getElementById( "Add" );
					button.disabled = true;
			}
			else if(id == "comment"){
				comment_box.value = languageCommentPost;
					button = document.getElementById( "Add" );
					button.disabled = true;
			}
		}
}
function clearComment(id){
	comment_box = document.getElementById( id );
	if(comment_box.value == languageWallPost || comment_box.value == languageCommentPost){
		comment_box.value = '';
	}

		button = document.getElementById( "Add" );
		button.disabled = false;
	
}

function hideComment(id){
	comment_box = document.getElementById( id );
	comment_box.style.display = 'none';
	document.getElementById( 'f'+id ).style.display = 'block';
}

function delayHideComment(id){
	commentTimer["comment_"+id] = setTimeout('hideComment("comment_'+id+'")',300);
}

function showComment(id,setf){
	if (typeof commentTimer[id] != 'undefined') {
		clearTimeout(commentTimer[id]);
	}
	comment_box = document.getElementById( id );
	comment_txt = document.getElementById( setf );
	comment_box.style.display = 'block';
	document.getElementById( 'f'+id ).style.display = 'none';
	comment_txt.focus();
	
}

function showAllComments(id){

	$.ajax({
			  url: 'ajax.php?module=activity&act=showComments&id='+id,
			  success: function(data) {
			    $('#CommentArea'+id).html(data);
			  }
			});
	document.getElementById( 'showCommentsDiv'+id ).style.display = 'none';
}

function remove(id){
	CH_AjaxRequest( 'ajax.php?module=activity&act=remove&id='+id, 'rpost_'+id,'no' );
	comment_box = document.getElementById( 'rpost_'+id );
	comment_box.style.display = 'none';
}

function remove_comment(id){
	CH_AjaxRequest( 'ajax.php?module=activity&act=remove&id='+id, 'rcomment_'+id,'no' );
	comment_box = document.getElementById( 'rcomment_'+id );
	comment_box.style.display = 'none';
}

function expandDIV(whichElement)
{
		//remove all current blocks
		document.getElementById(whichElement).style.display = (document.getElementById(whichElement).style.display == "block" ) ? "none" : "block";
		if(whichElement == "wlink"){
			document.getElementById('wevent').style.display = "none";
			document.getElementById('wphoto').style.display = "none";
			document.getElementById('wvideo').style.display = "none";
			document.getElementById('wvideoid').style.display = "none";
			CH_PushContent( '', 'wphotoid' );
		}
		if(whichElement == "wevent"){
			document.getElementById('wlink').style.display = "none";
			document.getElementById('wphoto').style.display = "none";
			document.getElementById('wvideo').style.display = "none";
			document.getElementById('wvideoid').style.display = "none";
			CH_PushContent( '', 'wphotoid' );
		}

		if(whichElement == "wphoto"){
			document.getElementById('wlink').style.display = "none";
			document.getElementById('wevent').style.display = "none";
			document.getElementById('wvideo').style.display = "none";
			document.getElementById('wvideoid').style.display = "none";
		}

		if(whichElement == "wvideo"){
			document.getElementById('wlink').style.display = "none";
			document.getElementById('wevent').style.display = "none";
			document.getElementById('wphoto').style.display = "none";
		}
	}

function enterEvent()
{     
	CH_AjaxRequest( 'ajax.php?module=activity&act=add_event&evn_id='+document.getElementById( 'evn_id' ).value, 'weventid','yes' );
	document.getElementById('wevent').style.display = "none";
	document.getElementById( "Add" ).disabled = false;
	clearComment('post');
}

function getPhotos(p)
{     
	document.getElementById('wphoto').style.display = "block";
  document.getElementById('wlink').style.display = "none";
  document.getElementById('wlinkid').style.display = "none";
	document.getElementById('wevent').style.display = "none";
	document.getElementById('wvideo').style.display = "none";
	document.getElementById('wvideoid').style.display = "none";
  CH_AjaxRequest( 'ajax.php?module=activity&act=get_photos&p='+p, 'wphotoid','no' );
}

function add_photo(id)
{     
	 post = document.getElementById( 'post' );
	 post.value = post.value.replace(languageWallPost,'');
	 post.value = post.value + '[pid]'+id+'[/pid]';
	 button = document.getElementById( "Add" );
	 button.disabled = false;
}

function getVideos(p)
{     
	document.getElementById('wvideo').style.display = "block";
  document.getElementById('wlink').style.display = "none";
	document.getElementById('wevent').style.display = "none";
	document.getElementById('wphoto').style.display = "none";
	document.getElementById('wphotoid').style.display = "none";
  CH_AjaxRequest( 'ajax.php?module=activity&act=get_videos&p='+p, 'wvideoid','no' );
}

function add_video(id)
{     
	 post = document.getElementById( 'post' );
	 post.value = post.value.replace(languageWallPost,'');
	 post.value = post.value + '[vid]'+id+'[/vid]';
	 button = document.getElementById( "Add" );
	 button.disabled = false;
}

function viewWallPhoto (per_id, pho_id)
{
   url = MainURL+"index.php?page=photos&section=album&per_id="+per_id+"&pho_id="+pho_id;
   phowin = window.open(url, "PHOTOALBUM", "width=600,height=660,scrollbars=no,menubar=no,resizable=no,location=no");
   phowin.focus();
}

function filterPosts(mem_id,per_id)
{
	var count = document.getElementById('showOlderPostCount').value;
	$.ajax({
  url: 'ajax.php?module=activity&act=filter&type='+mem_id+'&per_id='+per_id+'&count='+count,
  success: function(data) {
    $('#divShowFilteredPosts').html(data);
  }
});
	//setTimeout('Shadowbox.setup();',2000);
	
}

function filterType(type,per_id)
{
	var count = document.getElementById('showOlderPostCount').value;
	$.ajax({
  url: 'ajax.php?module=activity&act=filter&per_id='+per_id+'&type='+type+'&count='+count,
  success: function(data) {
    $('#divShowFilteredPosts').html(data);
  }
});
	//setTimeout('Shadowbox.setup();',2000);
	
}

function likePosts(per_id,filter)
{
	var count = document.getElementById('showOlderPostCount').value;
	//CH_AjaxRequest( 'ajax.php?module=activity&act=filter&per_id='+mem_id+'&count='+count, "divShowFilteredPosts" ,'yes' )
	$.ajax({
  url: 'ajax.php?module=activity&act=likes&per_id='+per_id+'&filter='+filter+'&count='+count,
  success: function(data) {
    $('#divShowFilteredPosts').html(data);
  }
});
	//setTimeout('Shadowbox.setup();',2000);
	
}

function showAllLikes(feed_id)
{

	CH_AjaxRequest( 'ajax.php?module=activity&act=showlikes&feed_id='+feed_id, "showLikesDiv"+feed_id ,'yes' )
	var show = document.getElementById('showlikesdiv'+feed_id);
	show.style.display = "none";
}

function noenter(e) {
     var key;
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
     if(key == 13)
          return false;
     else
          return true;
}
function ShowDelete(id)
{
	document.getElementById('feedRemove'+id).style.display = 'block';
}

function HideDelete(id)
{
	document.getElementById('feedRemove'+id).style.display = 'none';
}
function ShowDeleteC(id)
{
	document.getElementById('commentRemove'+id).style.display = 'block';
}

function HideDeleteC(id)
{
	document.getElementById('commentRemove'+id).style.display = 'none';
}

function showOlderPosts(mem_id, filter)
{
	var count = document.getElementById('showOlderPostCount').value;
	CH_AjaxRequest( 'ajax.php?module=activity&act=more&per_id='+mem_id+'&filter='+filter+'&count='+count, "showOlderPostsDiv" ,'yes' )
	document.getElementById('showOlderPostCount').value++;
}

function LikeWallStatus(id, mem_id)
{

	CH_AjaxRequest( 'ajax.php?module=activity&act=like&feed_id='+id+'&mem_id='+mem_id, "likestring"+id ,'no' );
	
	
}

