// JavaScript Document
/*var SocialEngine = new SocialEngineAPI.Base();
 // Core
  SocialEngine.Core = new SocialEngineAPI.Core();
 // URL 
  SocialEngine.URL = new SocialEngineAPI.URL();
  // Language
  SocialEngine.Language = new SocialEngineAPI.Language();
  SocialEngine.RegisterModule(SocialEngine.Language);
  // Back
  SELanguage = SocialEngine.Language;
*/    /*window.addEvent('domready', function(){
    var Tips1 = new Tips($$('.Tips1'));
	});*/
	
	function loadframe(){
		var iframeElement728 = parent.document.getElementById('728ad');
		var iframeElement300 = parent.document.getElementById('300ad');
	}
		function logoutOfFacebook() 
		{
			//FB.Facebook.init(api_key, "/xd_receiver.php");
		  	FB.Connect.logout(function() { window.location = '/user_logout.php';  });
		}
		function loginToFacebook(url) 
		{  
			//FB.Facebook.init(api_key, "/xd_receiver.php");
			if(url=="")
			{
				url="?return_url=/indexlive.php";
			}
			FB.Facebook.get_sessionWaitable().waitUntilReady(function()
			{ 
				Set_Cookie("facebookloged","1");
				Set_Cookie("firsttime","1");
				if(url.substr(0,12)=="?return_url=")
				{
					url=url.substr(12);
				}
				if(url.substr(0,7)=="http://")
				{
					url=url.substr(21);
					
				}
			
				window.location = ''+url; 
			});
			FB.Connect.requireSession();
			return false;
		  }
		  
		function loginToFacebook_sponsor(url) 
		{  
			//FB.Facebook.init(api_key, "/xd_receiver.php");
			if(url=="")
			{
				url="?return_url=/points_claims_page_fb.php";
			}
			FB.Facebook.get_sessionWaitable().waitUntilReady(function()
			{ 
				Set_Cookie("facebookloged_sponsor","1");
				Set_Cookie("firsttime_sponsor","1");
				if(url.substr(0,12)=="?return_url=")
				{
					url=url.substr(12);
				}
				if(url.substr(0,7)=="http://")
				{
					url=url.substr(20);
					
				}
				window.location = ''+url; 
			});
			FB.Connect.requireSession();
		  }
		  
		  function loginToFacebook_links_popup(url) 
			{  
				//FB.Facebook.init(api_key, "/xd_receiver.php");
				if(url=="")
				{
					url="?return_url=/indexlive.php";
				}
				FB.Facebook.get_sessionWaitable().waitUntilReady(function()
				{ 
					Set_Cookie("facebookloged","1");
					Set_Cookie("firsttime","1");
					Set_Cookie("direct_link","1");
					if(url.substr(0,12)=="?return_url=")
					{
						url=url.substr(12);
					}
					window.location = ''+"/login_2.php"; 
				});
				FB.Connect.requireSession();
			  }
			 function loginToFacebook_points(url) 
			{  
				//FB.Facebook.init(api_key, "/xd_receiver.php");
				if(url=="")
				{
					url="?return_url=/indexlive.php";
				}
				FB.Facebook.get_sessionWaitable().waitUntilReady(function()
				{ 
					Set_Cookie("facebookloged","1");
					Set_Cookie("firsttime","1");
					Set_Cookie("points_link","1");
					if(url.substr(0,12)=="?return_url=")
					{
						url=url.substr(12);
					}
					window.location = ''+"/user_points_sponsor.php"; 
				});
				FB.Connect.requireSession();
			  }
		    function loginToFacebook_redeem(url) 
			{  
				//FB.Facebook.init(api_key, "/xd_receiver.php");
				if(url=="")
				{
					url="?return_url=/indexlive.php";
				}
				FB.Facebook.get_sessionWaitable().waitUntilReady(function()
				{ 
					Set_Cookie("facebookloged","1");
					Set_Cookie("firsttime","1");
					Set_Cookie("redeem_link","1");
					if(url.substr(0,13)=="?return_url=/")
					{
						url=url.substr(13);
					}
					parent.TB_show2('', url+'&TB_iframe=true&height=590&width=630', true, '', true);	
				});
				FB.Connect.requireSession();
			  }
		function facebook_publish_feed_story(form_bundle_id, template_data) 
		{
			//FB.Facebook.init(api_key, "/xd_receiver.php");
			FB.ensureInit(function()
			{
			  FB.Connect.showFeedDialog(form_bundle_id, template_data, null, null, FB.FeedStorySize.shortStory  , FB.RequireConnect.promptConnect);
		  	});
		}
		function stream_callback (post_id) {
			
			  if (post_id!= null) {
			  
				var url_status = '/update_activity.php';
				$j.ajax({
					type: 'post',
					url: url_status ,
					data: { 'show_id' : 1  },
					success: function(response) {
					//alert('Complete process');
					}
					});
					return false;
			  }
			 
			}

		function facebook_publish_feed_story_new(template_data) 
		{
			FB.ui(template_data,function(response) {
				 if (response && response.post_id) {
				   stream_callback(response.post_id);
				   } 
			   }
			 );
		}
		
		function facebook_publish_feed_story_new_claimpoints(template_data) 
		{
			//FB.Facebook.init(api_key, "/xd_receiver.php");
			FB.ensureInit(function()
			{
				FB.Connect.streamPublish('', template_data, null, null,
                         '',
                         null)
			
			  	//FB.Connect.streamPublish(template_data);
		  	});
		}
		
		function Set_Cookie( name, value)
		{
			// set time, it's in milliseconds
			var today = new Date();
			var expires;
			var path="/";
			expires=1000;
			today.setTime( today.getTime() );
			expires = expires * 1000 * 60 * 60 * 6;
			var expires_date = new Date( today.getTime() + (expires) );
			document.cookie = name + "=" +escape( value ) +
			( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
			( ( path ) ? ";path=" + path : "/" );
		
		}
		
		

function reply_user(username)
    {
    document.getElementById("status_new5").focus();
    document.getElementById("status_new5").value = "@" + username + " ";
    
    }

	function chk_user(uid)
	{
		var user_id=uid;
		if(user_id==0)
		{
			alert("Please sign in first to submit it...");
			return false;
		}
		else 
		{
			document.search_form2.submit();
		document.getElementById("status_new5").value = "What's entertaining you?";
		return false;
		}
		
	}
	var reply_global;
	function chkinitial()
	{
		if(document.getElementById("status_new5").value=="What's entertaining you?")
		     document.getElementById("status_new5").value="";
	}
	function chkinitial2()
	{
		if(document.getElementById("status_new5").value=="")
		     document.getElementById("status_new5").value="What's entertaining you?";
	}	
	 function show_comments(aid)
	   {
	   	$j("#comments_"+aid).slideDown("slow");
	   }
	   function ilikeit(type,feed_type,uid,aid)
	   {
	   		//type 1 for like 2 for dislike
			
	   		var user_id=uid;
			if(user_id==0)
			{
				alert("Please sign in first to do this...");
				return false;
			}
			else 
			{
				var url_status = '/likeit.php';
				$j.ajax({
				type: 'post',
				url: url_status ,
				data: { 'id' : aid , 'type' : type , 'feed_type' : feed_type },
				success: function(response) {status_res=response.split("##");
				document.getElementById('likediv_'+aid).innerHTML = status_res[0];
				document.getElementById('like_count_'+aid).innerHTML = status_res[1];
				$j('#reply_box_'+aid).slideDown("slow");
				$j('#like_count_'+aid).slideDown("slow");
				}
				});
				return false;
			}
	   }
	 function show_reply_box(uid,aid)
	   {
	   		//type 1 for like 2 for dislike
	   		var user_id=uid;
			if(user_id==0)
			{
				alert("Please sign in first to do this...");
				return false;
			} 
			else
			{
				document.getElementById("reply_box_"+aid).style.display="block";
				var show_commentbox = $j("#show_comment_form").html();
				while (show_commentbox.indexOf("#action_id#") != -1)
				{
					show_commentbox = show_commentbox.replace("#action_id#",aid);
				}
				$j("#Show_comment_textfield_"+aid).html(show_commentbox);
				 $j('div.comments textarea').each(function(){
					var _hold = $j(this).parents('div.comments:eq(0)');
					var _text = this.value;
					this.onfocus = function(){
						
						_hold.addClass('active-text');
						_hold.addClass('active-text');
						
						if(this.value == _text) this.value = '';
					}
					this.onblur = function(){
						if(this.value == '') this.value = _text;
					}
			    });
				return false;
			}
			
		}
		function hide_reply(aid)
		{
			document.getElementById("reply_box_"+aid).style.display="none";
			return false;
		}
		function show_reply_box_right(uid,aid)
	   {
			//type 1 for like 2 for dislike
	   		var user_id=uid;
			if(user_id==0)
			{
				alert("Please sign in first to do this...");
				return false;
			} 
			else
			{
				document.getElementById("reply_box_"+aid).style.display="block";
				document.getElementById("reply_sec_"+aid).style.display="block";
				var show_commentbox = $j("#show_comment_form").html();
				while (show_commentbox.indexOf("#action_id#") != -1)
				{
					show_commentbox = show_commentbox.replace("#action_id#",aid);
				}
				$j("#Show_comment_textfield_"+aid).html(show_commentbox);
				 $j('div.comments textarea').each(function(){
					var _hold = $j(this).parents('div.comments:eq(0)');
					var _text = this.value;
					this.onfocus = function(){
						
						_hold.addClass('active-text');
						_hold.addClass('active-text');
						
						if(this.value == _text) this.value = '';
					}
					this.onblur = function(){
						if(this.value == '') this.value = _text;
					}
			    });
				return false;
			}
			
		}
		function hide_reply_right(aid)
		{
			document.getElementById("reply_box_"+aid).style.display="none";
			document.getElementById("reply_sec_"+aid).style.display="none";
			return false;
		}
		
		function chk_twitter()
		{
			TB_show('Twitter user info', '#TB_inline?height=200&width=300&inlineId=confirmtwitter', '', '../images/trans.gif');
			
		}
		function chk_twit(user_name,password)
		{
			if(user_name== "" || password == "")
			{
				alert("Please enter user name and password");
				return false;
			}
			else
			{
				
				var url_status = '/twitter_activity.php';
				$j.ajax({
				type: 'post',
				url: url_status ,
				data: { 'twitter_username' : user_name ,'twitter_password' : password ,'twitter_msg' : reply_global},
				success: function(response) {return false;}
				});
				parent.TB_remove();
				return false;
				
			}
		}
		function delete_user_action(aid,type)
    	{
    			var url_status = '/delete_actions.php';
				$j.ajax({
				type: 'post',
				url: url_status ,
				data: { 'id' : aid , 'type' : type  },
				success: function(response) {
				if(type==1)
				{
					$j('#action_'+aid).slideUp(1000);

					//document.getElementById('action_'+aid).style.display = 'none';
				}
				else
				{
					$j('#comment_'+aid).slideUp(1000);
					//document.getElementById('comment_'+aid).style.display = 'none';	
				}	
				}
				});
				return false;

     	}


	    function replyonit(type,feed_type,aid,fid,tid)
	   {
	   		var reply_text;
			reply_global='';
			var send_twitter; 
			send_twitter=0;
			
			reply_text=document.getElementById('reply_area_'+aid).value;
			if(reply_text!="")
			{
				reply_global=reply_text;
				
				if(document.getElementById('reply_twitter_'+aid).checked ==true)
				{
					if(tid==0)
					{
						chk_twitter();	
					}
					else 
					{
						send_twitter=1;
					}
					
				}
				  
				//document.getElementById("reply_box_"+aid).style.display="none";
				document.getElementById('reply_area_'+aid).value="";
				if(fid>0)
				{
					var attachment = {			
					'description':reply_text
				};
					
				if(document.getElementById('reply_face_'+aid).checked ==true)
					facebook_publish_feed_story_new(attachment);
				}
				//reply_text=encodeURIComponent(reply_text);
				var url_status = '/replyonit.php';
				$j.ajax({
				type: 'post',
				url: url_status ,
				data: { 'id' : aid ,'type' : type ,'feed_type': feed_type , 'reply_text' : reply_text, 'send_twitter' : send_twitter },
				success: function(response) {
					
					status_res=response.split("##");
					
					//document.getElementById('count_reply_'+aid).innerHTML =  status_res[0] + " Comments - ";
					if(status_res[0]>1)
					$j('#reply_sec_'+aid).html($j('#reply_sec_'+aid).html()+ status_res[1]);
					else
					$j('#reply_sec_'+aid).html("<ul>"+ status_res[1]+"</ul>"+$j('#reply_sec_'+aid).html());	
					 $j('#reply_sec_'+aid).slideDown("slow");
					//document.getElementById('reply_sec_'+aid).innerHTML ="<ul>" +  status_res[1] + "</ul>";
					}
				});
				return false;
			
			}
			else
			{
			return false;
			}
	   }
	   
	   function replyonit_right(type,feed_type,aid,fid,uid,tid)
	   {
		   if(uid>0)
		   {
	   		var reply_text;
			reply_global='';
			var send_twitter; 
			send_twitter=0;
			
			reply_text=document.getElementById('reply_area_'+aid).value;
			if(reply_text!="")
			{
				reply_global=reply_text;
				
				if(document.getElementById('reply_twitter_'+aid).checked ==true)
				{
					if(tid==0)
					{
						chk_twitter();	
					}
					else 
					{
						send_twitter=1;
					}
					
				}
				  
				//document.getElementById("reply_box_"+aid).style.display="none";
				document.getElementById('reply_area_'+aid).value="";
				if(fid>0)
				{
					var attachment = {			
					'description':reply_text
				};
					
				if(document.getElementById('reply_face_'+aid).checked ==true)
					facebook_publish_feed_story_new(attachment);
					
				
				}
				//reply_text=encodeURIComponent(reply_text);
				var url_status = '/replyonit_right.php';
				$j.ajax({
				type: 'post',
				url: url_status ,
				data: { 'id' : aid ,'type' : type ,'feed_type': feed_type , 'reply_text' : reply_text, 'send_twitter' : send_twitter },
				success: function(response) {
					
					status_res=response.split("##");
					
					//document.getElementById('count_reply_'+aid).innerHTML =  status_res[0] + " Comments - ";
					if(status_res[0]>1)
					$j('#reply_sec_'+aid).html($j('#reply_sec_'+aid).html()+ status_res[1]);
					else
					$j('#reply_sec_'+aid).html("<ul>"+ status_res[1]+"</ul>"+$j('#reply_sec_'+aid).html());	
					 $j('#reply_sec_'+aid).slideDown("slow");
					}
				});
				return false;
			
			}
			else
			{
			return false;
			}
		   }
		   else
		   {
			   	alert("Please sign in first to do this...");
			   return false;
		   }
	   }
	   

	 	function delete_user_action(aid,type)
		{
					var url_status = '/delete_actions.php';
					$j.ajax({
					type: 'post',
					url: url_status ,
					data: 'id='+aid+'&type='+type,
					success: function(response) {
					if(type==1)
					{
						$j('#action_'+aid).slideUp(1000);
	
						//document.getElementById('action_'+aid).style.display = 'none';
					}
					else
					{
						$j('#comment_'+aid).slideUp(1000);
						//document.getElementById('comment_'+aid).style.display = 'none';	
					}	
					}
					});
					return false;
	
		}

	 /*function show_reply_box_right(uid,aid)
	   {
	   		//type 1 for like 2 for dislike
	   		var user_id=uid;
			if(user_id==0)
			{
				alert("Please sign in first to do this...");
				return false;
			} 
			else
			{
				document.getElementById("reply_box_"+aid).style.display="block";
				document.getElementById("reply_sec_"+aid).style.display="block";
				return false;
			}
			
		}*/
		function show_likes(aid,type)
	   {
	   	var url_status = '/likes_show.php';
				$j.ajax({
				type: 'post',
				url: url_status ,
				data: { 'id' : aid , 'type' : type  },
				success: function(response) {document.getElementById('like_'+aid).innerHTML = response;
				$j("#like_"+aid).slideDown("slow");}
				});
				return false;
	   
	   }
	   function ilikeit(type,feed_type,uid,aid)
	   {
	   		//type 1 for like 2 for dislike
			
	   		var user_id=uid;
		if(user_id==0)
		{
			alert("Please sign in first to do this...");
			return false;
		}
		else 
		{
			
			var url_status = '/likeit.php';
			$j.ajax({
			  type: 'POST',
			  url: url_status,
			  data: { 'id' : aid , 'type' : type , 'feed_type' : feed_type },
			  success: function(response) {
				status_res=response.split("##");
				document.getElementById('likediv_'+aid).innerHTML = status_res[0];
				document.getElementById('like_count_'+aid).innerHTML = status_res[1];
				$j('#reply_box_'+aid).slideDown("slow");
				$j('#like_count_'+aid).slideDown("slow");
			  }
			});
			return false;
		}
	   	
	   }
	   
	    function replyonit_right(type,feed_type,aid,fid,uid,tid)
	   {
		   if(uid>0)
		   {
	   		var reply_text;
			reply_global='';
			var send_twitter; 
			send_twitter=0;
			
			reply_text=document.getElementById('reply_area_'+aid).value;
			if(reply_text!="")
			{
				reply_global=reply_text;
				t=reply_global;
				if(document.getElementById('reply_twitter_'+aid).checked ==true)
				{
					if(tid==0)
					{
						chk_twitter();	
					}
					else 
					{
						send_twitter=1;
					}
					
				}
				  
				//document.getElementById("reply_box_"+aid).style.display="none";
				document.getElementById('reply_area_'+aid).value="";
				if(fid>0)
				{
				var attachment = {			
					'description':reply_text
				};
					
				if(document.getElementById('reply_face_'+aid).checked ==true)
					facebook_publish_feed_story_new(attachment);
				}	
				
				else
				{
					if(document.getElementById('reply_face_'+aid).checked ==true)
					window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
					
				}
				
				//reply_text=encodeURIComponent(reply_text);
				var url_status = '/replyonit_right.php';
				$j.ajax({
			  type: 'POST',
			  url: url_status,
			  data: { 'id' : aid ,'type' : type ,'feed_type': feed_type , 'reply_text' : reply_text, 'send_twitter' : send_twitter },
			  success: function(response) {
					status_res=response.split("##");
					//document.getElementById('count_reply_'+aid).innerHTML =  status_res[0] + " Comments - ";
					if(status_res[0]>1)
					$j('#reply_sec_'+aid).html($j('#reply_sec_'+aid).html()+ status_res[1]);
					else
					$j('#reply_sec_'+aid).html("<ul>"+ status_res[1]+"</ul>"+$j('#reply_sec_'+aid).html());	
					 $j('#reply_sec_'+aid).slideDown("slow");
			  }
			});
				return false;
			}
			else
			{
			return false;
			}
		   }
		   else
		   {
			   	alert("Please sign in first to do this...");
			   return false;
		   }
	   }
	   
	   
	   function TB_show_right(uid_show,username)
	   {
			if(uid_show!==0)
			{
				 tb_show('Add to My Friends', 'user_friends_manage.php?user='+username+'&TB_iframe=true&height=300&width=450','./images/trans.gif');
			}
			else
			{
				alert("Please log in to add friends");
				return false;
			}
		
	   }
	   function changeStatus_submit3(uid) {
		   
		if(uid != 0 )
		{
				var url_status = '/post_activity.php';
				var reply_text_main;
				var twit_id=0;
				var u="http://www.yidio.com";
				var t;
				//var k=$j('status_new2').value;
				reply_text_main = document.getElementById('status_new2').value;
				if(reply_text_main!="" && reply_text_main !='What would you like to say?')
				{	
						//alert(reply_text_main);
						reply_global = reply_text_main;
						t=reply_global;
						
					if(fuid>0)
					{
						
						if(document.getElementById('check-face').checked ==true)
						facebook_publish_feed_story_new({"description":reply_text_main});
					}
					else
					{
						if(document.getElementById('check-face').checked ==true)
						window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
						
					}
					if(document.getElementById('check-twitter').checked ==true)
						twit_id=1;
						if(twit_enable==0 && twit_id==1)
						{
							chk_twitter();
						}
						else 
							{
								send_twitter=1;
							}
							
						$j.ajax({
							   type: "POST",
							   url: url_status ,
							   data: 'status=' + reply_text_main +'&show_id='+show_id+'&show_action_type='+show_action_type+'&send_twitter=' + send_twitter,
							   success: function(msg){
											
										show_hidden_feeds(action_new_id);
								
							   }
							 });  		
							 document.getElementById("status_new2").value = "What would you like to say?";
				}
				else
				{
					alert("The input box can't be left blank. Please insert text and try again");
					 return false;
				}
		}
		else
		{
			alert("Please log in first");
		 return false;
		}
		return false;
	  
	  }
	  function shownew_feeds(action_id)
	  {
	  	var url_status = '/user_home_ajax4.php';
		 $j.ajax({
				   type: "POST",
				   url: url_status ,
				   data: 'aid=' + action_new_id +'&tid=' + action_new_twit+ '&show_action_type='+show_action_type+'&show_id='+show_id+'&show_page='+ show_page+'&show_text='+show_text,
		 		   success: function(msg){
				   			
				 		  $j('#show_count').html(msg);
						 
				   }
				 });
		
	 		setTimeout(function(){shownew_feeds(action_new_id)},12000);
	  }
	   
	  function show_hidden_feeds(action_id){
	  	var url_status = '/user_home_ajax3.php';
			var status=$j('#status_new2').val();
			
			 $j.ajax({
				   type: "POST",
				   url: url_status ,
				    data: 'aid=' + action_new_id +'&tid=' + action_new_twit+ '&show_action_type='+show_action_type+'&show_id='+show_id+'&show_page='+ show_page+'&show_text='+show_text,
				   success: function(msg){
				    status_res=msg.split("##");
					action_new_id = status_res[0];
					 action_new_twit=status_res[2];
					  $j('#all_div').html(  status_res[1]);
					 $j("#show_feeds_" + action_new_id).slideDown("slow");
					  
					  //shownew_feeds(action_new_id);
					  $j('div.comments textarea').each(function(){
					var _hold = $j(this).parents('div.comments:eq(0)');
					var _text = this.value;
					this.onfocus = function(){
						
						_hold.addClass('active-text');
						_hold.addClass('active-text');
						
						if(this.value == _text) this.value = '';
					}
					this.onblur = function(){
						if(this.value == '') this.value = _text;
					}
			    });
					  
				   }
				 });
				// setTimeout(function(){shownew_feeds(action_new_id)},12000);
			  return false;
	  
	  } 	
	var tube_hostname = location.hostname;
	var action_new_id = 0;
	var action_new_twit =0;
	var twit_enable=0;
	var show_page=1;
	var show_text="main";
	var show_id=0;
	var show_action_type=0;
	 var u="http://www.yidio.com";
	 var t;   


