

var count = "140";   //Example: var count = "175";
function limiter(){
var tex = $('text').value;
var len = tex.length;
if(len > count){
        tex = tex.substring(0,count);
        $('text').value =tex;

        return false;
}
$('limit').value = count-len;
}

function insertEmtocion(emoticon) 
{
  var currentvalue = $('text').value;
  $('text').value = currentvalue + emoticon;
}

function refeshFeed(feed, strDomParent)
{
  var url = "/ajax/"+feed;
  var params = 'page=1';

  new Ajax.Request(url,
  {
    method:'post',
    parameters:params,
    onSuccess: function(resp)
    {
       var p = $(strDomParent);
       var html = resp.responseText;
       p.update(html);  
    }
  });
   
}


function getMore(feed, strDomParent)
{
	var url = "/ajax/"+feed;
	var params = 'page='+(currentPage+1);
	if(feed == "profile")
	{
		  params += "&id=" + twitterUid;
	}
	else if(feed == "mentions")
	{
		  params += "&sname=" + twitterScreenName;
	}
	else if(feed == "group")
	{
		  params += "&id=" + groupId;
	}
	else if(feed == "tag")
	{
		params += "&name=" + name + "&query=" + query;
	}
	$("btnMore").update(new Element('img', {src:"/images/ajax-loader.gif"}));
	new Ajax.Request(url,
  {
    method:'post',
    parameters:params,
    onSuccess: function(resp)
    {
    

       var p = $(strDomParent);
       var html = resp.responseText;
       var posts = html.split(/twitbody/);
       p.insert({bottom: html});
       currentPage++;
       if(posts.length < tweetCount)
       {
       	  $("btnMore").update("");
       }
       else
       {
          $("btnMore").update("<img src=/images/morebutton.png>");
          
          
       }
       
       checkSizeCompareContentToSidebar();

       
    }
  });
  
  


  
}



function waitresize(obj)
{

setTimeout("resizeDivHeight("+obj+")",1000);

}

function resizeDivHeight(obj)
{

var thingy = $(obj);
var gethight = thingy.getHeight()+100;

if (gethight > 500) {

var height = gethight;

} else {

var height = 1000;

}
$('sidebarroll').style.height = ''+height+'px';

}


function resizeMainContent() 
{

var contentheight = $('paddingcontent').getHeight();
//$('themaincontent').style.height = ''+contentheight+'px';

}


function checkSizeCompareContentToSidebar() 
{

var contentheight = $('yui-main').getHeight();
var sidebarheight = $('sidebarroll').getHeight();


if (contentheight < sidebarheight) {

//$('themaincontent').style.height = ''+sidebarheight+'px';

}


}


function resizeContentGoWait() {

setTimeout('checkSizeCompareContentToSidebar()',1000);

}

//Event.observe(window, 'load', function() { resizeContentGoWait(); });


function getFormSecret()
{        
	var re = /oauth_token_secret=[^;]+/;
	var s = re.exec(document.cookie)[0];
	s = s.substr(s.indexOf("=")+1);
  return s;
}

function addLoadEvent(func) 
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {
    window.onload = func;
  } 
  else
  {
    window.onload = function() 
    {
      if (oldonload)
      {
        oldonload();
      }
      func();
    }
  }
}

function limiterTags(){

var tex = $('posttags').value;
var len = tex.length;

$('limit').value = count-len;

}

function OpenWinConnect(link)
{
		window.open(link, "Child",'width=800,height=400,left=150,top=100,scrollbar=no,resize=no');
		
}


function refreshParent() {
  window.opener.location.href = window.opener.location.href;

  if (window.opener.progressWindow)
		
 {
    window.opener.progressWindow.close()
  }
  window.close();
}



function addUserToPost(screename) {

var textvalue = $('text').value;

$('text').value = textvalue + ' @'+screename+' ';
limiter();


}

function stopFollowing(uid) {

$('followbtn'+uid).innerHTML = '<img src="/images/ajax-loader.gif">';

  var params = "secret="+getFormSecret();
  
  var sr = new Ajax.Request("/stopfollow/"+uid, 
	  {
	     method:'post',
	     parameters:params,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	       
	       	   $('followbtn'+uid).innerHTML = '<a href="javascript:void(0)" onClick="startFollowing('+uid+')"><img src="/images/icons/tick.png"> התחל לעקוב </a>';           
	            
	         } 
	      }.bind(this)
	    });


}



function startFollowing(uid) {

$('followbtn'+uid).innerHTML = '<img src="/images/ajax-loader.gif">';

  var params = "secret="+getFormSecret();
  
  var sr = new Ajax.Request("/startfollow/"+uid, 
	  {
	     method:'post',
	     parameters:params,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	       
	       	   $('followbtn'+uid).innerHTML = '<a href="javascript:void(0)" onClick="stopFollowing('+uid+')"><img src="/images/icons/stop.png"> הפסק לעקוב</a>';           
	            
	         } 
	      }.bind(this)
	    });


}



function startFollowingSms(twitteruid) {

$('followsmsbtn'+twitteruid).innerHTML = '<img src="/images/ajax-loader.gif">';

  var params = "secret="+getFormSecret();
  
  var sr = new Ajax.Request("/startfollowsms/"+twitteruid, 
	  {
	     method:'post',
	     parameters:params,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	       
	       	   $('followsmsbtn'+twitteruid).innerHTML = '<a href="javascript:void(0)" onClick="stopFollowingSms('+twitteruid+')"><img src="/images/icons/phone_delete.png"> הפסק לעקוב בסלולרי </a>';           
	            
	         } 
	      }.bind(this)
	    });


}


function stopFollowingSms(twitteruid) {

$('followsmsbtn'+twitteruid).innerHTML = '<img src="/images/ajax-loader.gif">';
  var params = "secret="+getFormSecret();
  var sr = new Ajax.Request("/stopfollowsms/"+twitteruid, 
	  {
	     method:'post',
	     parameters:params,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	       
	       	   $('followsmsbtn'+twitteruid).innerHTML = '<a href="javascript:void(0)" onClick="startFollowingSms('+twitteruid+')"><img src="/images/icons/phone_add.png"> התחל לעקוב בסלולרי </a>';           
	            
	         } 
	      }.bind(this)
	    });


}


function followTopic(topicid) {

$('followtopicbox').innerHTML = '<img src="/images/ajax-loader.gif">';

  var sr = new Ajax.Request("/followtopic/"+topicid, 
	  {
	     method:'post',
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	       
	       	   $('followtopicbox').innerHTML = '<a href="javascript:void(0)" onClick="UnfollowTopic('+topicid+')"><img src="/images/icons/bell_delete.png"> הפסק עקיבה אחרי נושא </a><Br>';           
	            
	         } 
	      }.bind(this)
	    });

}




function UnfollowTopic(topicid) {

$('followtopicbox').innerHTML = '<img src="/images/ajax-loader.gif">';

  var sr = new Ajax.Request("/unfollowtopic/"+topicid, 
	  {
	     method:'post',
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	       
	          $('followtopicbox').innerHTML = '<a href="javascript:void(0)" onClick="followTopic('+topicid+')"><img src="/images/icons/bell.png"> עקוב אחרי נושא </a><Br>';  
	            
	            
	         } 
	      }.bind(this)
	    });

}



function showConvTwitSearch(statusid) {


//$(statusid+'_convbox').style.display = 'block';

var convbox = $(''+statusid+'_convbox');
convbox.toggle();

$(statusid+'_convbox').innerHTML = '<img src="/images/ajax-loader.gif">';
$(statusid+'_convbtn').innerHTML = ' סגור שיחה ';


  var sr = new Ajax.Request("/post/GetStatusConvSearch/?id="+statusid, 
	  {
	     method:'post',
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	          

	          $(''+statusid+'_convbox').innerHTML = msg;
	          
       		  resizeMainContent();

	            
	         }
	      }.bind(this)
	    });

}

function showConvTwit(statusid) {

$(statusid+'_convbox').style.display = '';

$(statusid+'_convbox').innerHTML = '<img src="/images/ajax-loader.gif">';

//Effect.toggle(''+statusid+'_convbox', 'appear'); return false;

  var sr = new Ajax.Request("/post/GetStatusConv/?id="+statusid, 
	  {
	     method:'post',
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	          

	          $(''+statusid+'_convbox').innerHTML = msg;  
resizeMainContent();	            
	         }
	      }.bind(this)
	    });

}

function createTiny() 
{
url = $('tinyurl').value;

var urlObj = {"url" : url }
var urlJSON = escape(Object.toJSON(urlObj));	




$('status').innerHTML = '<img src="/images/ajax-loader.gif">';
  var sr = new Ajax.Request("/post/MakeTiny", 
	  {
	     method:'post',
	     parameters:'urlJSON='+urlJSON,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            var existingtext = $('text').value;
			 	//$('tinyurl').value = msg;			
			 	$('text').value = existingtext+' '+msg;
			 	$('tinyurl').value = '';
			 	$('status').innerHTML = '';
			 	limiter();
	         } else {
	         
	         
	         }
	      }.bind(this)
	    });

}

function sendPublicMsg(uname)
{
$('postbox').style.display ='';
$('actiontext').style.display = '';
$('actiontext').innerHTML = 'הודעה כללית ל '+uname;
$('twituname').value = uname;
$('twitaction').value = 'publicmsg';

stringtocount = uname+'@ ';

stringcount = stringtocount.length

count = 140 - stringcount;

limiter();

}

function makeTextRtl()
{


$('text').style.textAlign = 'right';

}

function makeTextLtr()
{


$('text').style.textAlign = 'left';

}

function showTinyUrl()
{

Effect.toggle('tinyurlbox', 'Appear'); return false;

//$('tinyurl').style.display = '';

}

function showEmoticons()
{

Effect.toggle('emoticonbox', 'Appear'); return false;

//$('tinyurl').style.display = '';

}


function showFavUsers(id) 
{
$(id+'_favbox').style.display = '';
$(id+'_favbox').innerHTML = '<img src="/images/ajax-loader.gif">';

new Ajax.Request("/getfavusers", {
    method: 'post',
    parameters:'id='+id,
    onSuccess: function(request) {
	var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            
			$(id+'_favbox').innerHTML = msg;

							            
	         } else {
	         
	         
	         }        
    }.bind(this)
});


}

function closeFavBox(id) {


$(id+'_favbox').style.display = 'none';

}


function showUserDetails(userid,screename,actions)
{

userDetails = {"id" : userid,"screen_name" : screename,"actions" : actions}

var userDetailsJson = escape(Object.toJSON(userDetails));	

//box = $('userdetailsbox'+userid).innerHTML;

//if (box == '<img src="/images/icons/vcard.png"> עקוב אחרי / שלח מסר') {
$('userdetailsaction'+userid).innerHTML = '<img src="/images/ajax-loader.gif">';

new Ajax.Request("/user/GetUserDetails", {
    method: 'post',
    parameters:'userdetails='+userDetailsJson,
    onSuccess: function(request) {
	var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            
			$('userdetailsaction'+userid).innerHTML = msg;

							            
	         } else {
	         
	         
	         }        
    }.bind(this)
});
//}


}

function showFriends()
{

var friendsbox = $('friendsbox').innerHTML;

if (friendsbox == '') {
$('friendsbox').innerHTML = '<img src="/images/ajax-loader.gif">';

new Ajax.Request("/user/getfriendsBox", {
    method: 'get',
    onSuccess: function(request) {
    
	var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            
			$('friendsbox').innerHTML = msg;
							            
	         } else {
	         
	         
	         }        
    }.bind(this)
});
}

Effect.toggle('friendsbox', 'Appear'); return false;


//$('tags').style.display = '';

}

function showPicture()
{
Effect.toggle('twitpicbox', 'Appear'); return false;

//$('tags').style.display = '';

}


function showTags()
{
Effect.toggle('tagsbox', 'Appear'); return false;

//$('tags').style.display = '';

}

function newTopicMsg(slug)
{
$('postbox').style.display ='';
topichash = $('topichash').value;
topicname = $('topicname').value;

$('posttags').value = topicname;
$('actiontext').style.display = '';

$('actiontext').innerHTML = 'הודעה בנושא '+topicname;
$('twitaction').value = 'topicmsg';


limiter();

}



function sendPrivateMsg(uname)
{
$('friendsbutton').style.display = 'none';
$('subjectbutton').style.display = 'none';
$('hd').scrollTo();

$('postbox').style.display ='';
$('actiontext').style.display = '';

$('actiontext').innerHTML = '<span style="color:red">'+'הודעה פרטית ל '+uname+'</span>';
$('twituname').value = uname;
$('twitaction').value = 'privatemsg';


stringtocount = uname+'@ ';

stringcount = stringtocount.length

count = 140 - stringcount;

limiter();

}


function replyTwit(id,uid,uname)
{

$('postbox').style.display ='';
$('hd').scrollTo();
$('actiontext').style.display = '';
$('text').value = '';
$('actiontext').innerHTML = 'תשובה ל '+uname;
$('twituname').value = uname;
$('twitreplyuid').value = uid;
$('twitreplyid').value = id;
$('twitaction').value = 'reply';

//stringtocount = uname+'@ ';

//stringcount = stringtocount.length

//count = 140 - stringcount;

limiter();
}


function uploadPicture() 
{

var file = $('media');
new Ajax.Request("/frontend_dev.php/post/uploadPicture", {
    method: 'post',
    contentType: 'multipart/form-data;',
    encoding: '',
    parameters:'media='+file,
    onSuccess: function(request) {
    
	var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            
				alert(msg);
					            
	         } else {
	         
	         
	         }        
    }.bind(this)
});




}

function uploadPictureSuccess(pictureurl)
{
var currentvalue = $('text').innerHTML;
$('text').innerHTML = currentvalue+' '+pictureurl;

}

function removeMobileFollow(id,twitteruid)
{

$(id+'line').innerHTML = '<img src="/images/ajax-loader.gif">';
 var params = 'twitteruid='+twitteruid+"&secret="+getFormSecret();
 var sr = new Ajax.Request("/stopfollowsms/"+twitteruid, 
	  {
	     method:'post',
	     parameters:params,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            
	            $(id+'line').hide();
	            
	         } else {
	         
	         
	         }
	      }.bind(this)
	    });



}





function removeFeatured(id,twittername)
{

var action = 'remove';

$(id+'line').innerHTML = '<img src="/images/ajax-loader.gif">';
 var params = 'id='+id+"&secret="+getFormSecret();
 var sr = new Ajax.Request("/addceleb?id="+id, 
	  {
	     method:'post',
	     parameters:'do='+action+'&id='+id+'&twittername='+twittername,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            
	            $(id+'line').hide();
	            
	         } else {
	         
	         
	         }
	      }.bind(this)
	    });



}

function favStatus(id) {

$('favbtn'+id).innerHTML = '<img src="/images/ajax-loader.gif">';
 var params = 'id='+id+"&secret="+getFormSecret();
 var sr = new Ajax.Request("/makefav", 
	  {
	     method:'post',
	     parameters:params,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            
	            $('favbtn'+id).innerHTML = '<span onClick="unfavStatus('+id+')"><img height="12" width="12" src="/images/icons/heart_delete.png"></span>';
	            
	         } else {
	         
	         
	         }
	      }.bind(this)
	    });



}



function unfavStatus(id) {

$('favbtn'+id).innerHTML = '<img src="/images/ajax-loader.gif">';
 var params = 'id='+id+"&secret="+getFormSecret();
 var sr = new Ajax.Request("/removefav", 
	  {
	     method:'post',
	     parameters:params,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            
	            $('favbtn'+id).innerHTML = '<span onClick="favStatus('+id+')">אהבתי</span>';
	            
	         } else {
	         
	         
	         }
	      }.bind(this)
	    });



}


function qouteTwit(id,uname)
{

var text = $('twittextinput'+id).value;

$('postbox').style.display ='';
$('hd').scrollTo();
$('actiontext').style.display = '';


$('actiontext').innerHTML = 'ציטוט של '+uname;
$('twituname').value = uname;
$('twitaction').value = 'qoute';
$('text').value = 'RT @'+uname+' '+text+' ';
//stringtocount = 'RT @'+uname+' '+text+' ';

//stringcount = stringtocount.length

//count = 140 - stringcount;

limiter();
}


function showActions(id)
{

$('actions_'+id).style.display = 'block';

}

function hideActions(id)
{

$('actions_'+id).style.display = 'none';

}

function postTweet(uid)
{
	
	  action = $('twitaction').value;
	  reply_touid = $('twitreplyuid').value;
	  reply_toid = $('twitreplyid').value;
	  reply_toname = $('twituname').value;
	  if( $('twitgroupid') != null )
	  {
	  	var iSelect = $('twitgroupid');
	  	if(iSelect.value != null)
	  	{
	  		var group_id = iSelect.value;
	  	}
	  	else
      {
        var group_id = iSelect.options[iSelect.selectedIndex].value;
      }
	  }
	  
	  
	  tags = encodeURI($('posttags').value);
 	  userscreenname = $('twitteruser').value;
	  var text = '';
	  if (action == "privatemsg") {
	  
	  text = 'd '+reply_toname+' ';
	  
	  }
	  
	  if (action == "publicmsg") {
	  
	  text = '@'+reply_toname+' ';
	  
	  }
	  
	  if (action == "reply") {
	  
	  text = '@'+reply_toname+' ';
	  
	  }
	  
	  text += encodeURI($('text').value);

	  
	  /*
	  <input id="twitreplyid" type="hidden" style="width: 150px; font-size: 12px;" value="" name="twitreplyid"/>
	  <input id="twitreplyuid" type="hidden" style="width: 150px; font-size: 12px;" value="" name="twitreplyuid"/>
	  <input id="twitaction" type="hidden" style="width: 150px; font-size: 12px;" value="privatemsg" name="twitaction"/>
      <input id="twituname" type="hidden" style="width: 150px; font-size: 12px;" value="Laylathedog" name="twituname"/>
*/
	  //userimg = $('userimage').value;
	  var twitObj = {"userid" : uid, "text": text, "replytouid": reply_touid, "replytoid": reply_toid, "action": action, "replytoname": reply_toname, "tags": tags, "groupid": group_id}
	  var twitJSON = escape(Object.toJSON(twitObj));	
	 $('submitbtn').innerHTML = '<img src="/images/ajax-loader.gif">';
    var params = 'twitJSON='+twitJSON+"&secret="+getFormSecret();
	  var sr = new Ajax.Request("/post/PostTwit", 
	  {
	     method:'post',
	     parameters:params,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	         
	            $('tagsbox').style.display = 'none';
				$('tinyurlbox').style.display = 'none';
				
				$('friendsbox').style.display = 'none';
				$('twitreplyuid').value = '';
				$('twituname').value = '';
				$('twitreplyid').value = '';
				$('twitaction').value = '';
				$('actiontext').innerHTML = 'היי '+userscreenname+' ! מה את/ה עושה עכשיו?';
				$('status').innerHTML = 'נשלח בהצלחה!';			
				$('text').value = '';
				$('posttags').value = '';
				$('tinyurl').value = '';
				
				$('friendsbutton').style.display = '';
				$('subjectbutton').style.display = '';
				
				
				$('submitbtn').innerHTML = '<img src="/images/submit_twit.png" onClick="postTweet('+uid+')">';
			
				if ($('newpost')) {
	         	$('newpost').style.display = '';
	         	$('newpost').insert({top:msg});
				}
				

	         } else {
	         
	         $('status').innerHTML = 'ריק? בעיות? מה קורה...';			
	         
	         }
	      }.bind(this)
	    });



}

function closeActiveMobile() {


$('activatephone').style.display = 'none';

}

function deleteTwit(statusid)
{

		var params = "id="+statusid+"&secret="+getFormSecret();
	  var sr = new Ajax.Request("/post/DeleteStatus", 
	  {
	     method:'post',
	     parameters:params,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	  
			$(statusid+'line').fade();
	
	         }
	      }.bind(this)
	    });
}

function deletePrivate(id)
{

		var params = "id="+id+"&secret="+getFormSecret();
	  var sr = new Ajax.Request("/post/DeletePrivate", 
	  {
	     method:'post',
	     parameters:params,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	  
			$(id+'line').fade();
	
	         }
	      }.bind(this)
	    });
}



function addActivatePhone()
{

		phonenumber = $('phonenumber').value;
		$('status').innerHTML = '<img src="/images/ajax-loader.gif">';


	  var topicObj = {"newtopictitle": newtopictitle}
	  var topicJSON = escape(Object.toJSON(topicObj));	
		
	  var sr = new Ajax.Request("/activephone", 
	  {
	     method:'post',
	     parameters:'phonenumber='+phonenumber,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            

				  $('status').innerHTML = '';
	  
			      window.location = "/topic/"+msg;

	
	         }
	      }.bind(this)
	    });
}







function createTopic()
{

		newtopictitle = encodeURI($('newtopictitle').value);
		$('status').innerHTML = '<img src="/images/ajax-loader.gif">';


	  var topicObj = {"newtopictitle": newtopictitle}
	  var topicJSON = escape(Object.toJSON(topicObj));	
		
	  var sr = new Ajax.Request("/newtopic", 
	  {
	     method:'post',
	     parameters:'topicObj='+topicJSON,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            
			 					 

				  $('newtopictitle').value = '';
				  
				  		$('status').innerHTML = '';

				  
			      window.location = "/topic/"+msg;

	
	         }
	      }.bind(this)
	    });
}




function createTopicTags()
{

		newtags = encodeURI($('posttags').value);
		
		$('status').innerHTML = '<img src="/images/ajax-loader.gif">';


	 var topicObj = {"newtags": newtags}
	  var topicJSON = escape(Object.toJSON(topicObj));	
		
	  var sr = new Ajax.Request("/newtopictags", 
	  {
	     method:'post',
	     parameters:'topicObj='+topicJSON,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            
				 // $('tags').style.display = 'none';

				  //$('posttags').value = '';
				  
				  //$('status').innerHTML = 'נושאים: נושא,נושא,נושא';

				  
			      //window.location = "/topic/"+msg;

	
	         }
	      }.bind(this)
	    });
	    
}





function comment(id,uid)
{
	
		body = $('commentbody').value;
		privacy = $('privacy').value;


	  var commentObj = {"id": id, "userid" : uid, "body": body, "privacy": privacy}
	  var commentJSON = escape(Object.toJSON(commentObj));	
		
	  var sr = new Ajax.Request("/post/CommentAjax/id/"+id, 
	  {
	     method:'post',
	     parameters:'commentObj='+commentJSON,
	     onSuccess:function(request) 
	     {
	         var msg = request.responseText.evalJSON();
	         if(msg)
	         {
	            
			 	 //var structure = '<div id="shout_'+msg.id+'"><a href="/user/showProfile/id/'+msg.AuthorId+'">'+msg.AuthorName+'</a>: '+msg.body+'<br></div>';
			
				 if (msg.Privacy == '1') {
				 
			 	 var structure = '<div style="padding:10px;border:1px solid #ccc;background-color:#EFE0E0" id="'+msg.id+'">';
				 structure += '<span style="font-size:16px;color:#5f5f5f">';
				 structure += ''+msg.AuthorName+':<br>';
				 structure += ''+msg.Body+'<BR>';
				 structure += '</span>';
				 structure += '</div>';
				 structure += '<br>';
				 
				 } else {
				 
				 var structure = '<div style="padding:10px;border:1px solid #ccc" id="'+msg.id+'">';
				 structure += '<span style="font-size:16px;color:#5f5f5f">';
				 structure += ''+msg.AuthorName+':<br>';
				 structure += ''+msg.Body+'<BR>';
				 structure += '</span>';
				 structure += '</div>';
				 structure += '<br>';
				 
				 }
				 
	  			$('comments').insert({bottom:structure});

				  $('commentbody').value = '';
			
	
	         }
	      }.bind(this)
	    });
}



function connectFbUserFront() {

new Ajax.Request('/user/connectFbUser',
			  {
			    method:'post',

			    onSuccess: function(request)
			    {
			    window.location = "/";
				
			    }
			  });	

}

function connectFbUser() {

    
	new Ajax.Request('/user/connectFbUser',
		  {
		    method:'post',

		    onSuccess: function(request)
		    {
		    
		  

		    
			    window.location = "/";
			
		    }
		  });	

}


function update_user_box() { 

		var user_box = document.getElementById("user"); 
		var logoutlink = document.getElementById("logoutlink"); 
		
 		//var uid = FB.Facebook.apiClient.get_session().uid;
 		
 		var fbuser = FB.Connect.get_loggedInUser();
 		var uid = fbuser;

		//fbuidinput.value = uid;

		// add in some XFBML. note that we set useyou=false so it doesn't display "you" 
		user_box.innerHTML = "<span>" 
		+ "Welcome, <fb:name uid=loggedinuser useyou=false></fb:name>. You are signed in with your Facebook account for workforoptions.<br>"
		+ '<span style="font-size:18px;color:#4C67A1">Click <fb:login-button class="FB_ElementReady fb_login_not_authorized" onlogin="connectFbUser()" length="short" background="white" size="medium">'
		+ '<a id="RES_ID_fb_login" class="fbconnect_login_button">'
		+ '<img id="fb_login_image" src="http://static.ak.fbcdn.net/images/fbconnect/login-buttons/connect_white_large_short.gif?7:121638" alt="Connect"/>'
		+ '</a>'
		+ '</fb:login-button>'
		+ " to login</span></span>";
		
		
		logoutlink.innerHTML = '<a href=\"#\" onClick=\"FB.Connect.logout()\">[logout]</a>';
		
		user_box.style.display = '';
		// because this is XFBML, we need to tell Facebook to re-process the document 
		FB.XFBML.Host.parseDomTree();


} 

function logoutFbUser() {

	FB.Connect.logout();
	window.location = "/";

}

function FBConnectFront() {

 
 FB.Bootstrap.requireFeatures(["Connect"], function() { 
 //Prod
 FB.init("d8e8e7f3873dcc631dfe72df510e97f2","/fbconnect/xd_receiver.htm");
 //Debug app
 //FB.init("25987af3dce906e42c93b131a52e2dad","/fbconnect/xd_receiver.htm");
 //FB.Connect.requireSession(false);

 //FB.Connect.showPermissionDialog("email"); 
 
 });
  

}


function FBConnect() { 
 

 
 FB.Bootstrap.requireFeatures(["Connect"], function() { 
 //Prod
 FB.init("d8e8e7f3873dcc631dfe72df510e97f2","/fbconnect/xd_receiver.htm");
  //Debug app
  //FB.init("25987af3dce906e42c93b131a52e2dad","/fbconnect/xd_receiver.htm");

 //FB.Connect.showPermissionDialog("email"); 
  FB.Connect.ifUserConnected(update_user_box);

 
 });
 
 
 
 
}

function FBConnectAppReg() {
 
 FB.Bootstrap.requireFeatures(["Connect"], function() { 
 //Prod
 FB.init("d8e8e7f3873dcc631dfe72df510e97f2","/fbconnect/xd_receiver.htm");
  //Debug app
 //FB.init("25987af3dce906e42c93b131a52e2dad","/fbconnect/xd_receiver.htm");

 //FB.Connect.showPermissionDialog("email"); 
 FB.Connect.ifUserConnected(updateAppRegTable);

 
 });
 
 
 
}


function updateAppRegTable() { 

		var user_box = document.getElementById("user"); 
		var firstrow = document.getElementById("firstnamerow");
		var lastrow = document.getElementById("lastnamerow");
		var passwordrow = document.getElementById("passwordrow");
		var emailrow = document.getElementById("emailrow");
		var invitekeyrow = document.getElementById("fbinvitekeyrow");
 		//var uid = FB.Facebook.apiClient.get_session().uid;
 		
 		
 		FB.Bootstrap.requireFeatures(["Connect"], function() { 
		 //Prod
		 FB.init("d8e8e7f3873dcc631dfe72df510e97f2","/fbconnect/xd_receiver.htm");
		  //Debug app
		 //FB.init("25987af3dce906e42c93b131a52e2dad","/fbconnect/xd_receiver.htm");
		
		 //FB.Connect.showPermissionDialog("email"); 
		// FB.Connect.ifUserConnected(updateAppRegTable);
		 		var fbuser = FB.Connect.get_loggedInUser();

		 
		 });
 		
 		
 		var uid = fbuser;
		firstrow.style.display = 'none';
		lastrow.style.display = 'none';
		emailrow.style.display = 'none';
		passwordrow.style.display = 'none';
		invitekeyrow.style.display = 'none';
		$('fbflag').value = 'true';
		//invitekeyrow.style.display = 'none';
		//fbuidinput.value = uid;

		// add in some XFBML. note that we set useyou=false so it doesn't display "you" 
		user_box.innerHTML = "<span style='font-size:18px;color:#4C67A1'>" 
		+ "Welcome, <fb:name uid=loggedinuser useyou=false></fb:name>. You are signed in with your Facebook account for workforoptions.<br>"
		+ '<span style="font-size:18px;color:#4C67A1">'
		+ "</span></span>";
		
		user_box.style.display = '';
		// because this is XFBML, we need to tell Facebook to re-process the document 
		FB.XFBML.Host.parseDomTree();


} 

function sendInvite(postid) {

		email = $('inviteemail').value;

new Ajax.Request('/user/inviteUser',
			  {
			    method:'post',
	   			parameters:'email='+email+'&postid='+postid,
			    onSuccess: function(request)
			    {
 		  var msg = request.responseText.evalJSON();
	         if(msg) {
	         
				$('inviteemail').value = 'Invited!';
	         
	         }
	         
	         
	         				
			    }
			  });	

}


function featuredSelect()
			{
			//var c_value = $('followedusers').value;
			c_value = '';
			for (var i=0; i < document.follows.follow.length; i++)
			   {
			   if (document.follows.follow[i].checked)
			      {
			      c_value = c_value + document.follows.follow[i].value + ",";
			      }
			   }

				$('followedusers').value = c_value;

			}
			
function featuredSelectNow()
			{
			var c_value = $('followedusers').value;
			//c_value = '';
			for (var i=0; i < document.follows.follow.length; i++)
			   {
			   document.follows.follow[i].checked;
			   
			     }

				$('followedusers').value = c_value;

			}
			
function checkAll()
{

			var c_value = $('followedusers').value;


for (var i=0; i < document.follows.follow.length; i++)
			   {
			   
			   c_value = c_value + document.follows.follow[i].value + ","
			   
			   document.follows.follow[i].checked = true;
			     
			   }
			   
			   $('followedusers').value = c_value;


}

function uncheckAll()
{
for (var i=0; i < document.follows.follow.length; i++)
			   {
			   document.follows.follow[i].checked = false;
			     
			   }
			   
			   			   $('followedusers').value = '';


}
