var uploading = 0;
var upload = 0;
function  getNewPosts(){
	var showgroup = "";
	if($('#showgroup').length >0) showgroup = $('#showgroup').val();
	$.post("/getnewposts.php", {last: 0,showgroup:showgroup},
		function(data,textStatus){
			if(textStatus=='success'){
				if(!((/^\s*$/.test(stripTags(data).replace(/\n/g,"").replace(/\r/g,"")))|(/Bad Request/.test(stripTags(data)))))
				$('div.timeline').each(function(){
					var userid=$("input#session_userid").val();
					var post_userid=$(this).attr('title');
					var profile_id=$(data).find('.profile_id').val();
					var tmp = $(this).html();
					if(userid==post_userid || profile_id==post_userid){
						$(this).html(data+tmp);
					}
				});
				$('.new_post').slideDown('slow',function(){$(this).removeClass('new_post')});
				clicker();
			}
		});	
	
}
function  getNewCPosts(){
$.post("/getnewCposts.php", {last: 0},
		function(data,textStatus){
			if(textStatus=='success'){
				if(!((/^\s*$/.test(stripTags(data).replace(/\n/g,"").replace(/\r/g,"")))|(/Bad Request/.test(stripTags(data)))))
				$('div.timeline').each(function(){
					var userid=$("input#session_userid").val();
					var post_userid=$(this).attr('title');
					var tmp = $(this).html();
					$(this).html(data+tmp);
					
				});
				
				$('.new_post').slideDown('slow',function(){$(this).removeClass('new_post')});
				clicker();
			}
		});	
}
function  getJoinedCircles(){
	$.post("/getJoinedCircles.php", {circle_id:''},
		function(data){
				if(!((/^\s*$/.test(stripTags(data).replace(/\n/g,"").replace(/\r/g,"")))|(/Bad Request/.test(stripTags(data)))))
				$("div.my_circles").html(data);
				/*if($("div.my_circles").length>0){
					$('div.my_circles ul').each(function(){
						if($("div.my_circles ul li").length==4){
							$("div.my_circles ul li:last-child").remove();
						}
						$(this).prepend(data);
					});
				}
				else{
					$("div.my_circles").html('<ul>'+data+'</ul>');
					$('.new_circle').show(function(){$(this).removeClass('new_circle')});
				}*/
				clicker();
		});	
}
function  IsUrlValid(url){
	var regexp = /(http|https|ftp|mailto):\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; 
	return regexp.test(url);
}

function  IsUtubeUrlValid(url){
	var regexp = /(http|https|ftp|mailto):\/youtube.com\/watch\?v=([^&]*)/; 
	return regexp.test(url);
}

function check_url(){
	var url=$("#youtube_url_txt").val();
	if(url !='' && url !='http://' && url != null){
		var matches = url.match(/http:\/\/(?:www\.)?youtube.com\/watch\?(?=.*v=\w+)(?:\S+)?/);
		if (!matches) {	
			flash_message("Invalid URL", 'error');
			return false;;
		}
	}
	return true;
}


function uploaddata(ptype)
{	
	
	/*if($("#post_circle_id").length > 0)	$("#post_circle").val($("#post_circle_id").val());
	else $("#post_circle").val('0');*/
	upload_initiated = 1;
	if(ptype==1)
	{	
		if(uploading_choice == 1)
		{
			return;	
		}
		$("#post_circle").val('0');
		var content = $("#post_text").val();
		content=content!='undefined'?content:$("#poll_title").val();
		content=content!='undefined'?content:$("#msg_text").val();
		var user_id=$('#uid').val();
		
		var categ=$("#poll_categ").val()
		
		if(content==''||content=="Write on the Wall..." || content=="Start Writing..." ||  content=="Write a message...")
		{
			flash_message("Please enter the message.", 'error');
			uploading = 1;
			
		}
		/*else if(user_id==undefined)
		{
			flash_message("Please login to write on the wall", 'error');
			uploading = 1;
			
		}*/
		else if(categ==0)
		{
			flash_message("Please select a category", 'error');
			uploading = 1;
			
		}else if(!check_url()){
			uploading = 1;
		}
		else {
			uploading = 0;
		}
		if(uploading == 0){
			if($('#attach_url_text').val()=="http://"){
				$("#link_id").val("");
			}else{
				var tmplink = $('#attach_url_text').val();
				if(checkurl(tmplink)){
					$("#link_id").val(tmplink);
				}else{					
					flash_message("Invalid URL", 'error');
					return false;
				}
			};
			var poll_status=$("#poll_status").val();
			if(poll_status==1){
				var title=$("#poll_title").val();
				if(title==''){
					flash_message("Title required", 'error');
					return false;
				}
				else{
					var choices=[];
					var ch_ids=[];
					$(".poll_ch").each(function(){
						var ch=$(this).val();
						if(ch!='' && ch != "eg: red" && ch != "eg: blue"){
							choices.push(ch);
							ch_ids.push($(this).parent().find('.choice_id').val());
						}
					});
					var poll_category=$("select#poll_categ").val();
						var poll_desc=$("#post_desc").val();
						if(poll_desc=="Description"){poll_desc="";}
						var poll_res=$(".poll_res:checked").val();
						var poll_opt=$("select#poll_options").val();
						
												
						var poll_exp=$("#ndatepicker").val();
						
						var poll_hr=$("#poll_hr").val();
						var poll_min=$("#poll_min").val();
						//var content=$("#update").val();
						var follower_id=$("#follower_id").val();
						var is_follow=$("#is_follow").val();
						var uname=$("#uname").val();
						var uid=$("#uid").val();
						var img_id=$("#img_id").val();
						var link_id=$("#link_id").val();
						var posttotw = '';
						var posttofb = '';
						if($("#twit:checked").length > 0)posttotw = 1;
						if($("#fbk:checked").length > 0)posttofb = 1;
						var allow_check= 0;
						if($("#allow:checked").length > 0)allow_check=1;
						$('#ad_loader').show();
						var utubeurl=$("#youtube_url_txt").val();
						
						var anonymous_post= 0;
						if($("#anonym:checked").length > 0)anonymous_post=1;
						
						var friends=0;
						if($(".frnd_select:checked").length > 0)friends=1;
						
						var sgstUsers=[];
						
						$(".frnd_select:checked").each(function(){
							sgstUsers.push($(this).val());
						});
						
					  
						$.post("/submit.php",{poll_status:poll_status,content:title,poll_title:title,poll_category:poll_category,poll_desc:poll_desc,'poll_ch[]':choices,'choice_ids[]':ch_ids,poll_res:poll_res,poll_opt:poll_opt,poll_exp:poll_exp,follower_id:follower_id,is_follow:is_follow,uid:uid,uname:uname,img_id:img_id,link_id:link_id,allow_check:allow_check,anonymous_post:anonymous_post,substory:1,posttotw:posttotw,posttofb:posttofb,utubeurl:utubeurl,friends:friends,sgstUsers:sgstUsers},function(data){
																																																																																																									
			if(data!="")
			if(data.indexOf('Error:')=='0'){
				flash_message(data, 'error');
				$('#ad_loader').hide();
				return false;
			};																																																																			
				$("#title_label").hide();$("#p_img_div").hide();$(".suggest_panel").hide();
				//$("input#poll_title").css('width','404px');
				$("#upload_label").hide();
				$(".dynamic").remove();
				$('.poll_img').each(function(){$(this).attr("src", pollnullimage)});
				$("#img_id").val('');
				$("#user_image").val('');
				$("#img_id").val('');
				$("#user_image").val('');
				$("#video_icon").show();
				$("#link_icon").show();$("#txt").show();
				$("#image_icon1").show();
				$('#add_txt').show();
				$("#vdo_id").val('');
				$("#user_video").val('');
				$("#browseimage").hide();
				$("#browsevideo").hide(); 
				$("#browsevideo").hide();
				$("#pollelimg").hide();
				$("#post_desc_container").hide();
				$("#PrivacySuggestions .group_select").attr('checked',false);
				$("#PrivacySuggestions .frnd_select").attr('checked',false);
				$("#PrivacySuggestions").hide();
				$(".frnds_add").html('Ask Friends');
				
				
				$(".drop_closebutton").hide();
				$("#poll_category").hide();
				$("#poll_string_count").hide();
				$("#p_desc").hide();
				$(".brws_img").hide();
				$("div").removeClass('pop_open');
				$(':text, :password, :file', '#poll_form').val('');  
				$(':input', '#poll_form').removeAttr('checked').removeAttr('selected');
				var cid=$("input#circle").val();
				if(cid!=0){
				$("textarea#update").val("Start Writing...");
				}
				else{
				$("textarea#update").val("Write on the Wall...");
				}									
				$("input#poll_title").val("");
				$("#post_text").val("Write on the Wall...");
				$("#post_text").val("Write a message...");
				$(".hidenfile").hide(); 
				$("#bottom_lnks").hide();$("#sgst_panel").hide();
				$("#polldate").html('');
				$("textarea#update").removeClass('typing');
				$("textarea#update").show();
				$('#ad_loader').hide();
				flash_message(data, 'error');
				uploading =0;
				upload = 0;
				var userid=$("input#session_userid").val();
				$(".buzzcnt").each(function(){
					if($(this).attr("title") == userid){
						$(this).html(parseInt($(this).html())+1)					
					}
				});
				$("#submit").html($("#submit").html());
				show_popups();close_popup();
				});
				}
			}
			else{$('#ad_loader').show();
				var is_message=$("#is_message").val();
				if(is_message=='1'){
					
					document.submitsh.submit();
				}
				else{
					if($('#attach_url_text').val()=="http://"){
						$("#link_id").val("");
					}else{
						var tmplink = $('#attach_url_text').val();
						if(IsUrlValid(tmplink)){
							$("#link_id").val(tmplink);
						}else{					
							flash_message("Invalid URL", 'error');
							return false;
						}
					}
					
					document.submitsh.submit();
					//$('#ad_loader').hide();
					var postadvicetext=$("input#hdnDefultPollmessage").val();//added by pet 20-7-11
					//$("textarea#post_text").val(postadvicetext);//added by pet 20-7-11
					setTimeout("$('#submitsh textarea#post_text').val('"+postadvicetext+"');",4000);
				}
				
			}
		}
		else
		{
			uploading = 1;
			return false
		}
		
	}
	else{
		var cid=$("#post_circle").val();
		var content = $('#circle_text').val();
		var user_id=$('#uid').val();
		
		if(content==''||content=="Join to comment...")
		{
			flash_message("Please enter the message.", 'error');
			uploading = 1;
		}
		else if(user_id==undefined)
		{
			flash_message("Please login to Buzz", 'error');
			uploading = 1;
		}
		else {
			uploading = 0;
		}
		if(uploading == 0){
			$('#ad_loader').show();
			document.csubmitsh.submit();
		}
		else
		{
			uploading = 1;
			return false;
		}
	}	
}
function uploadimage(file,type){	
	var filename=file.value;
	$('#ad_loader').show();
	$(file).parent().parent().find('.upld_img_txt').val(filename);
	/*if($("#post_circle_id").length > 0)	$("#post_circle").val($("#post_circle_id").val());
	else $("#post_circle").val('0');*/
	
	var parent_div=$(".circle_wrap");
	if(type=='0'){
		$('.check_circle').each(function(){$(this).val('1');});
		var cid=$("#post_circle").val()
		
		if(uploading == 0)
		{	
			parent_div.find("#user_image").hide();
			parent_div.find('#brow_but').hide();
			parent_div.find('#link_icon').hide();
			parent_div.find('#attach_url_text').val("http://");
			parent_div.find('#youtube_url_txt').val("http://");
			parent_div.find("#link_id").val("");
			parent_div.find('#imageforms .imageform:first .loadingimage').show();
			document.imageform[2].submit();
			uploading = 1;
			setTimeout('isImageUp(0)',100);
			
		}
		if((parent_div.find('#imageforms .imageform').length + parent_div.find("#showimage img").length) <3){
			var form = parent_div.find('#imageformtpl .imageform:first').clone();
			form.find('#user_image').show();
			form.find('#brow_but').show();
			form.find('#link_icon').show();
			form.find('#attach_url_text').val("http://");
			parent_div.find('#youtube_url_txt').val("http://");
			form.find("#link_id").val("");
			form.find('.loadingimage').hide();
			parent_div.find('#imageforms').append(form);
		}
	}
	else{$('.check_circle').each(function(){$(this).val('0');});
		if(uploading == 0)
		{	
			$("#user_image").hide();
			$('#brow_but').hide();
			$('#link_icon').hide();
			$('#attach_url_text').val("http://");
			parent_div.find('#youtube_url_txt').val("http://");
			$("#link_id").val("");
			$('#imageforms .imageform:first .loadingimage').show();
			document.imageform[1].submit();
			uploading = 1;
			setTimeout('isImageUp(1)',100);
			/*$("#tbimage").hide();*/
		}
		if(($('#imageforms .imageform').length + $("#showimage img").length) <3){
			var form = $('#imageformtpl .imageform:first').clone();
			form.find('#user_image').show();
			form.find('#brow_but').show();
			form.find('#link_icon').show();
			form.find('.loadingimage').hide();
			$('#imageforms').append(form);
		}
	}
}
function isImageUp(type)
{
	/*if($("#post_circle_id").length > 0)	$("#post_circle").val($("#post_circle_id").val());
	else $("#post_circle").val('0');*/
	
	if(type=='0'){
		
		var parent_div=$(".circle_wrap");
		if(parent_div.find("#showimage").html() !=""){
			parent_div.find("#loadingimage").hide();
			parent_div.find("#showimage").show();
		}else{
			setTimeout('isImageUp(0)',1000);
		}
	}
	else{
		if($("#showimage").html() !=""){
			$("#loadingimage").hide();
			$("#showimage").show();
		}else{
			setTimeout('isImageUp(1)',1000);
		}
	}
		
}
function imageuploaded(err, upid, path,type)
{	
/*if($("#post_circle_id").length > 0)	$("#post_circle").val($("#post_circle_id").val());
else $("#post_circle").val('0');*/

//var cid=$("#post_circle").val();

if(type=='0'){
		var parent_div=$(".circle_wrap");
		parent_div.find("#img_id").val(parent_div.find("#img_id").val()+"|"+upid);
		parent_div.find("#showimage").append('<img src="'+path+'" style="padding:3px;" />');
		parent_div.find('#imageforms .imageform:first').remove();	
		
		if(upload == 1 && parent_div.find('#imageforms .imageform').size()<=0)
		{
			uploading = 0;
			uploaddata(0);
		}
		else if(parent_div.find('#imageforms .imageform').size()>0 && parent_div.find('#imageforms .imageform:first .user_image').val() != "")
		{
			parent_div.find('#imageforms .imageform:first').submit();
			parent_div.find('#imageforms .imageform:first .loadingimage').show();
			uploading = 1;
		}
		else
		{
			uploading = 0;
		}
}
else{
	$("#img_id").val($("#img_id").val()+"|"+upid);
	$("#showimage").append('<img src="'+path+'" style="padding:3px;" />');
		$('#imageforms .imageform:first').remove();	
		
		if(upload == 1 && $('#imageforms .imageform').size()<=0)
		{
			uploading = 0;
			uploaddata(1);
		}
		else if($('#imageforms .imageform').size()>0 && $('#imageforms .imageform:first .user_image').val() != "")
		{
			$('#imageforms .imageform:first').submit();
			$('#imageforms .imageform:first .loadingimage').show();
			uploading = 1;
		}
		else
		{
			uploading = 0;
		}
}

		$('#ad_loader').hide();
		
}
function uploadvideo(file,type)
{
	var filename=file.value;
	$(file).parent().parent().find('.upld_img_txt').val(filename);
	/*if($("#post_circle_id").length > 0)	$("#post_circle").val($("#post_circle_id").val());
	else $("#post_circle").val('0');*/
	//var cid=$("#post_circle").val();
	if(type=='0'){
		$('.check_circle').each(function(){$(this).val('1');});
		var parent_div=$(".circle_wrap");
		if(uploading == 0)
		{
			document.cvideoform.submit();
			uploading = 1;
			setTimeout('isVideoUp(0)',100);
			parent_div.find("#loadingvideo").show();
			parent_div.find("#tbvideo").hide();
			progress();
		}
	}
	else{$('.check_circle').each(function(){$(this).val('0');});
		if(uploading == 0)
		{
			document.videoform.submit();
			uploading = 1;
			setTimeout('isVideoUp(1)',100);
			$("#loadingvideo").show();
			$("#tbvideo").hide();
			progress();
		}
	}
}

function isVideoUp(type)
{
			$('#ad_loader').hide();
	/*if($("#post_circle_id").length > 0)	$("#post_circle").val($("#post_circle_id").val());
	else $("#post_circle").val('0');*/
	var cid=$("#post_circle").val();
	if(type=='0'){
		var parent_div=$(".circle_wrap");
		if(parent_div.find("#showvideo").html() !=""){
			parent_div.find("#loadingvideo").hide();
			parent_div.find("#showvideo").show();
		}else{
			setTimeout('isVideoUp(0)',1000);
		}
	}
	else{
		if($("#showvideo").html() !=""){
			$("#loadingvideo").hide();
			$("#showvideo").show();
		}else{
			setTimeout('isVideoUp(1)',1000);
		}
	}
}
function videouploaded(err, upid, path,type)
{
	/*if($("#post_circle_id").length > 0)	$("#post_circle").val($("#post_circle_id").val());
	else $("#post_circle").val('0');*/
	
	var cid=$("#post_circle").val();
	if(type=='0'){
		var parent_div=$(".circle_wrap");
		
		
		uploading = 0;
		parent_div.find("#vdo_id").val(upid);
		var videodata ='<div style="clear:both; margin:10px auto">';
			videodata +='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400" height="250" id="FlvPlayer" align="middle">';
			videodata +='<param name="allowScriptAccess" value="sameDomain" />';
			videodata +='<param name="allowFullScreen" value="true" />';
			videodata +='<param name="movie" value="http://flvplayer.com/free-flv-player/FlvPlayer.swf" />';
			videodata +='<param name="quality" value="high" />';
			videodata +='<param name="bgcolor" value="FFFFFF" />';
			videodata +='<param name="wmode" value="transparent" />';
			videodata +='<param name="FlashVars" value="flvpFolderLocation=http://flvplayer.com/free-flv-player/flvplayer/&flvpVideoSource=http://beta.azooca.com/flv/{insertvideo}.flv&flvpWidth=400&flvpHeight=250&flvpInitVolume=50&flvpTurnOnCorners=false&flvpBgColor=FFFFFF&autoplay=false"';
			videodata +='<embed src="http://flvplayer.com/free-flv-player/FlvPlayer.swf" wmode="transparent" flashvars="flvpFolderLocation=http://flvplayer.com/free-flv-player/flvplayer/&flvpVideoSource=http://beta.azooca.com/flv/{insertvideo}.flv&flvpWidth=400&flvpHeight=250&autoplay=false&flvpInitVolume=50&flvpTurnOnCorners=false&flvpBgColor=FFFFFF" quality="high" bgcolor="FFFFFF" width="400" height="250" name="FlvPlayer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />';
			videodata +='</object></div>';
		parent_div.find("#showvideo").html(videodata.replace('{insertvideo}',path).replace('{insertvideo}',path));
		if(upload == 1)
		{
			uploaddata('0');
		}
	}
	else{
		
		uploading = 0;
		$("#vdo_id").val(upid);
		var videodata ='<div style="clear:both; margin:10px auto">';
			videodata +='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="400" height="250" id="FlvPlayer" align="middle">';
			videodata +='<param name="allowScriptAccess" value="sameDomain" />';
			videodata +='<param name="allowFullScreen" value="true" />';
			videodata +='<param name="movie" value="http://flvplayer.com/free-flv-player/FlvPlayer.swf" />';
			videodata +='<param name="quality" value="high" />';
			videodata +='<param name="bgcolor" value="FFFFFF" />';
			videodata +='<param name="wmode" value="transparent" />';
			videodata +='<param name="FlashVars" value="flvpFolderLocation=http://flvplayer.com/free-flv-player/flvplayer/&flvpVideoSource=http://beta.azooca.com/flv/{insertvideo}.flv&flvpWidth=400&flvpHeight=250&flvpInitVolume=50&flvpTurnOnCorners=false&flvpBgColor=FFFFFF&autoplay=false"';
			videodata +='<embed src="http://flvplayer.com/free-flv-player/FlvPlayer.swf" wmode="transparent" flashvars="flvpFolderLocation=http://flvplayer.com/free-flv-player/flvplayer/&flvpVideoSource=http://beta.azooca.com/flv/{insertvideo}.flv&flvpWidth=400&flvpHeight=250&autoplay=false&flvpInitVolume=50&flvpTurnOnCorners=false&flvpBgColor=FFFFFF" quality="high" bgcolor="FFFFFF" width="400" height="250" name="FlvPlayer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />';
			videodata +='</object></div>';
		$("#showvideo").html(videodata.replace('{insertvideo}',path).replace('{insertvideo}',path));
		if(upload == 1)
		{
			uploaddata('1');
		}
	}
}
$('#update').val("Write on the Wall...");
$("textarea#update").removeClass('typing');
$(':text, :password, :file', '#poll_form').val('');  
$(':input', '#poll_form').removeAttr('checked').removeAttr('selected');
$(':text, :password, :file', '#myFormId').val('');  
$(':input', '#myFormId').removeAttr('checked').removeAttr('selected');
$('#circle_text').val("Join to comment...");
function RESIZE() {

	if($("input#poll_title").val()=="" ){
		$("input#poll_title").val('');
	}
	if($("#post_text").val()=="Write on the Wall..." ){
		$("#post_text").val('');
	}
	if($("textarea#msg_text").val()=="Write a message..." ){
		$("textarea#msg_text").val('');
	}
	var follow_check=$("input#is_follow").val();
	var follower_id=$("input#follower_id").val();
	var user_id=$("input#uid").val();
	var cid=$("#circle").val();
	
	if($("textarea#update").val()=="Write on the Wall..." || $("textarea#update").val()=="Start Writing..." ){
		$("textarea#update").val('');
		$("textarea#update").addClass('typing');
	}else if(follow_check==0 &&  user_id !=follower_id){
		$("textarea#update").blur();
		flash_message("To post on a profile you need to follow each other...", 'error');
		$("textarea#update").val('To post on a profile you need to follow each other...');
		return false;
	}
	 
	var reste;
	
	function getInput(e){
	
	//$(e.target).autogrow(this);
		
		var len = $(e.target).val().length;
		
		reste = 200 - len;
            $(".str_cnt b").html(reste);
	}

	$("textarea#update").bind('textchange',function(e){
		getInput(e);
	});
	
}
	

function resetpost() {
	$("#bottom_lnks").hide();$("#sgst_panel").hide();
	var follow_check=$("input#is_follow").val();
	var follower_id=$("input#follower_id").val();
	var user_id=$("input#uid").val();
	var cid=$("input#circle").val();
			if(follow_check==0 && follower_id!=user_id){
				$("textarea#update").val('To post on a profile you need to follow each other...');
			}
			else if(cid!=0){
				$("textarea#update").val("Start Writing...");
			}
			else{
				$("textarea#update").val("Write on the Wall...");
			}
	//$("textarea#update").val("Write me a message!");
	$("textarea#update").removeClass('typing');
	$("textarea#update").attr("rows","2");
	$("textarea#update").show();
	$(".input_auteur").hide();
	$(".input_cat").hide();
	$(".input_sexe").hide();
	$(".input_mail").hide();
	$(".input_privacy").hide();
	$(".ok").hide();
	$(':text, :password, :file', '#poll_form').val('');  
	$(':input', '#poll_form').removeAttr('checked').removeAttr('selected');
	$(".input_img").hide();$("#title_label").hide();
	$("#upload_label").hide();
	$("#p_img_div").hide();
}
function browse_img(){
	uploading = 0;
	$("#img_id").val("");
	$("#vdo_id").val("");
	$("#user_image").val('');
	$("#loadingimage").hide();
	$("#showimage").hide();
	$("#showimage").html("");
	if($("#browseimage").is(":hidden")){
		$("#browseimage").show();
		$("#video_icon").hide();
		$('#add_txt').hide();
		$("#image_icon").show();
		$("#link_icon").show();
		$("#tbimage").show();
		var form = $('#imageformtpl .imageform:first').clone();
		form.html(form.html());
		form.find('.loadingimage').hide();
		$('#imageforms').html(form);
	}
	else{
		$("#browseimage").hide();
		$("#video_icon").show();
		$("#link_icon").show();
		$('#add_txt').show();
		$("#image_icon").show();
		
	}
				
	
}
function browse_video(){
	uploading = 0;
	$("#vdo_id").val('');
	$("#user_video").val('');
	$('#videoprogress').width(0);
	$('#videoprogress').html("");
	$("#loadingvideo").hide();
	$("#showvideo").hide();
	$("#showvideo").html("");
	if($("#browsevideo").is(":hidden")){
		$("#browsevideo").show();
		$("#video_icon").show();
		$("#link_icon").show();
		$('#add_txt').show();
		$("#image_icon").hide();
		$("#tbvideo").show();
		$('#videoprogress').width(0);
		$('#videoprogress').html("");
	}
	else{
		$("#browsevideo").hide();
		$("#video_icon").show();
		$('#add_txt').show();
		$("#image_icon").show();
		$("#link_icon").show();
	}
				
	
}
function displayOptions(){
	if($("#privacy_options").is(":hidden")){
		$("#privacy_options").show();
	}
	else{
		$("#privacy_options").hide();
	}
}
function select_privacy(obj_id){
	var privacy_value=$("li#"+obj_id).attr('id');
	$("input#privacy_value").val(privacy_value);
	$("li").removeClass('active');
	$("li#"+privacy_value).addClass('active');
	$("#privacy_options").hide();
}

function set_img_id(id){
	//img_id=id;
	$('input#img_id').val(id);
	//return id;
}
function upload(fileObj){
	// add image progress
	$("#loadingsubmitsh").show();
}
function progress()
{
	var id=$("#vdouid").attr("value");
	$.getJSON("progress.php",{id:id},update);
}
function update(data)
{
	var perc = getPercentage(data);
	if($('#videoprogress').width() > 0 && perc == 0)
	{
		$('#videoprogress').css("width",'100%');
		$('#videoprogress').html('Generating Thumbnails');
	}
	else if(perc > 0)
	{
		$('#videoprogress').css("width",perc+'%');
		$('#videoprogress').html(perc+'%');
		progress();
	}
	else{
		$('#videoprogress').width(0);
		progress();
	}
}
function getPercentage(data){
	if(data != null){				
				return percentage = Math.floor(100 * parseInt(data.bytes_uploaded) / parseInt(data.bytes_total));
	}	
	return 0;
}
function readablizeBytes(bytes) {
	
	var s = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB'];
	var e = Math.floor(Math.log(bytes)/Math.log(1024));
	return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e];
}
function getTimeRemain(data){
	var ret = '';
	if(data != null){
		var mins = Math.floor((data.est_sec)/60);
		var sec = (data.est_sec)%60;
		ret += mins+' mins : ';
		ret += sec+' sec : ';
	}
	return ret;
}

function polluploaded(err, pollid)
{	
$("#poll_id").val(pollid);
	if(err==''){
		uploading='0';
	}
}

function upld_pollimg(file){
	//document.poll_form.submit();
	$("#poll_form").submit();
}
function upld_chimg(file){
	document.poll_form.action='/uploadch_img.php';
	$("#poll_form").submit();
}

function submit_poll(){/*
	var poll_status=$("#poll_status").val();
	if(poll_status==1){
		var title=$("#poll_title").val();
		if(title==''){
			flash_message("Title required", 'error');
			return false;
		}
		else{
			var choices='';
			$(".poll_ch").each(function(){
				var ch=$(this).val();
				if(ch!=''){
					if(choices!=''){
						choices=choices+","+ch;
					}
					else{
						choices=ch;
					}
				}
			});
			if(choices==''){
				flash_message("Choice required", 'error');
				return false;
			}
			else{
				var poll_desc=$("#poll_desc").val();
				var poll_res=$(".poll_res:checked").val();
				var poll_opt=$("select#poll_options").val();
				
				var poll_exp=$("#polldate").html();
				//var poll_hr=$("#poll_hr").val();
				//var poll_min=$("#poll_min").val();
				var content=$("#update").val();
				var follower_id=$("#follower_id").val();
				var is_follow=$("#is_follow").val();
				var uname=$("#uname").val();
				var uid=$("#uid").val();
				var img_id=$("#img_id").val();
				$.post("/submit.php",{poll_status:poll_status,content:title,poll_title:title,poll_desc:poll_desc,poll_ch:choices,poll_res:poll_res,poll_opt:poll_opt,poll_exp:poll_exp,follower_id:follower_id,is_follow:is_follow,uid:uid,uname:uname,img_id:img_id,substory:1},function(data){
					flash_message(data, 'message');
							
					$("#img_id").val('');
					$("#user_image").val('');
					$("#img_id").val('');
					$("#user_image").val('');
					$("#video_icon").show();
					$("#link_icon").show();
					$("#image_icon1").show();
					$("#poll_icon").show();
					$('#add_txt').show();
					$("#vdo_id").val('');
					$("#user_video").val('');
					$("#browseimage").hide();
					$("#browsevideo").hide(); 
					$("#browsevideo").hide();
					$(".brws_img").hide();
					$("#polldate").html('');
					$("div").removeClass('pop_open');
					$(':text, :password, :file', '#poll_form').val('');  
					$(':input', '#poll_form').removeAttr('checked').removeAttr('selected');
					var cid=$("input#circle").val();
					if(cid!=0){
						$("textarea#update").val("Start Writing...");
					}
					else{
					$("textarea#update").val("Write on the Wall...");
					}
					$("textarea#update").removeClass('typing');
					$("textarea#update").show();
					uploading =0;
					upload = 0;
					var userid=$("input#session_userid").val();
						$(".buzzcnt").each(function(){
							if($(this).attr("title") == userid){
								$(this).html(parseInt($(this).html())+1)					
							}
						});
					//getNewPosts();
				});
			}
		}
	}*/
}

function start_poll(){
	
	close_popup();
	//$("input#poll_title").css('width','340px');
	if($("#poll_title").val()==""){
			$("#poll_title").val('');
			$("#poll_category").show();	
			$("#poll_string_count").show();		
			$("#p_desc").show();
			$("#post_desc_container").show();		
			$("#PrivacySuggestions").hide();
			$("#poll_uploadview").show();
			$("#title_label").show();
			$("#upload_label").show();$("#sgst_panel").show();
			$("#bottom_lnks").show();
			$("#pollelimg").show();
			$(".hiddenupload").show();
			//$(".poll_choice:eq(4)").hide();
			$("#p_img_div").show();$(".add_sugst").show();$(".allow_chk").hide();
			//$("#p_img_lnk").show();
			$(".drop_closebutton").show();
			
			close_popup();selectPostRec();
			
			
	}
}

function start_post(){
	
		$("#post_text").val('');
		
		$("#poll_uploadview").show();
		$("#title_label").show();
		$("#upload_label").show();
		$("#bottom_lnks").show();
		$("#pollelimg").show();
		$(".hiddenupload").show();
		//$(".poll_choice:eq(4)").hide();
		$("#p_img_div").show();
		//$("#p_img_lnk").show();
		$(".drop_closebutton").show();close_popup();
	
	if($("textarea#msg_text").val()=="Write a message..." ){
		$("textarea#msg_text").val('');
		
		
		$("#bottom_lnks").show();
		
		$(".drop_closebutton").show();close_popup();
	}
}

function start_msg(){close_popup();
	
	if($("textarea#msg_text").val()=="Write a message..." ){
		$("textarea#msg_text").val('');
		
		$(".msg_closebutton").show();
	}
}

function submit_msg()
{	
	var content=$("#msg_text").val();
	var user_id=$('#uid').val();
		
	if(content==''||content=="Write a message...")
	{
		flash_message("Please enter the message.", 'error');
		uploading = 1;
	}
	else if(user_id==undefined)
	{
		flash_message("Please login to post a message", 'error');
		uploading = 1;
	}
	else {
		uploading = 0;
	}
	if(uploading == 0){
		
		var is_message=$("#is_message").val();
		document.submitmsg.submit();
	}
	else{
		return false;
	}
}

function select_cat(){
	
	var i=document.getElementById("poll_categ").selectedIndex;
	var cat=document.getElementById("poll_categ").options[i].text;
	$("#catid_txt").val(cat);
}
