$.fn.myToggle = function(visible_display)
{
    return this.each(function()
    {

        if(this.style.display=='none')
        {
            $(this).css('display','block');
 
        }
        else  
        {
            $(this).css('display','none');  

        }
    } )
}

function promo_block_close()
{
    $('#promo_block_t').hide();
    $.ajax({
       url: '/ajax/dig.php',
       data:{type: "close_promo_block"},
       type: 'GET' 
    });
}

function change_load(to)
{
   if(to=='computer')
   {
       $('#preview_radio').val('computer');
       $('#comment_pr').removeClass('input'); 
       $('#comment_pr').css('background','none');
       $('#preview_from_computer').show();
       $('#preview_from_url').hide();
   }else if(to=='url')
   {
       
       $('#preview_radio').val('url');
       $('#comment_pr').addClass('input');  
       $('#comment_pr').css('background','transparent url(images/input_new.gif) no-repeat scroll 0 0');  
       $('#preview_from_computer').hide();
       $('#preview_from_url').show();       
   } 
}

function login_click(e)
{
  e = e || window.event;
  if(e.keyCode==13)
  {
      $('#login_f_f').submit();
  }
}

function isValidEmail (email)
{
 return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}

function isLatinString(str)
{   
 
  return (/^[a-z0-9]*$/i).test(str);  
}


function refresh_menu_links()
{   
usersystem = navigator.platform;                                                  
  x = usersystem.indexOf(' ');
  if(x!=-1) {                                                                   
   l = usersystem.length;                                                       
   usersystem = usersystem.substr(1, x-1); 
  }                                     
if($.browser.opera)
{         
    $('.personals ul li').css('margin-bottom','5px');      
    if(usersystem.indexOf('Mac')!=-1)
    {                           
        $('.menu').css('padding-top','26px');
    }
}else if($.browser.safari&&usersystem.indexOf('Mac')!=-1)
{
   $('.menu').css('padding-top','27px'); 
}
else if($.browser.mozilla&&usersystem.indexOf('Mac')!=-1)
{
    $('.menu').css('padding-top','26px'); 
}

}


function CloseFirstPopup() {
	$("#fbaloon").css("display", "none");
	$.ajax({  
        type: "POST",  
        dataType: "json",
        data: "act=setfirst",  
        url: "/ajax.php",
        success: function (data) {
           
        }
    });	
}

$(function(){
refresh_menu_links();
});

//Freshitems
function ReadAll(){
		$.ajax({type: "get",  
				url: "/ajax.php?act=readall",
				dataType: "text",
				success: function(done)
  		 	 	{					
					if(done)
						window.location.reload();
					else
						alert('Извините, произошла ошибка');					
  		 	 	}
	   	});
}
//New comments
function ReadAllComms(){
		$.ajax({type: "get",  
				url: "/ajax.php?act=readallcomms",
				dataType: "text",
				success: function(done)
  		 	 	{				
					if(done)
						window.location.reload();
					else
						alert('Извините, произошла ошибка');					
  		 	 	}
	   	});
}
//Comments
var add_story_process = false;
function AddCom(storyid, comment, parentid, outlink){
		if(outlink == undefined)outlink = '';
		
		if(!add_story_process)
		{
			add_story_process = true;
			//$('#submitBut').attr('disabled',true);
			if(parentid!=0)
				include = $('#com'+parentid).attr('incl')*1 + 1;
			else
				include = 0;
			
			$.ajax({type: "POST", 
	  		 	 	data: "act=addcom&id="+storyid+"&comment="+encodeURIComponent(comment)+"&parentid="+parentid+"&include="+include,
					dataType: "json",	
					url: "/ajax.php",
	  		 	    success: function(data)
	  		 	 	{			
						switch(data.type)
					    {
					    	case "error":
					            alert(data.text);
					            break;
					        case "done":
					        	if(parentid==0)				        	
					        		$("#commentsDiv").append(data.text);
					        	else{
					        		$("#com"+parentid+'_subcom').append(data.text);
					        		replycancel();
					        	}
					        	$('#storyComments').html( $('#storyComments').html()*1 + 1 );				        	
								$('#comment_textarea_' + parentid).val('Введите текст сообщения...');
								$('#comment_textarea_' + parentid).attr('lang', '1');
							    //$(document).scrollTo('#com'+data.comment_id,400);	
								if(outlink != '')
								{
									document.location.href = outlink;
								}
					        	break;
					        default:
					            alert("Извините, произошла ошибка");
					            break;
					    }
						add_story_process = false;
						//$('#submitBut').attr('disabled',false);
	  		 	 	}
		   	});
		}
}
//Saved Stories
function SaveStory(storyid, act){
		var actPage = '';
		if(act == 'save')
		{
			actPage = 'SaveStory';
			$('#delete_saved_' + storyid).show();
			$('#save_' + storyid).hide();			
		}
		else if(act == 'delete')
		{
			actPage = 'DelSavedStory';
			$('#delete_saved_' + storyid).hide();
			$('#save_' + storyid).show();			
		}
		if(storyid > 0 && actPage != '')
		{
			$.ajax({type: "POST", 
	  		 	 	data: "act=" + actPage + "&story_id=" + storyid,
					dataType: "json",	
					url: "/ajax.php",
	  		 	    success: function(data)
	  		 	 	{			
						return true;
	  		 	 	}
		   	});
		}
}