function checkUncheckAll(theElement) 
{
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++)
	 {
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall')
      {
	  theForm[z].checked = theElement.checked;
	  }
     }
     
}



function showhide(theElement)
{
	
	if (theElement.style.display == 'none')
	{
		theElement.style.display = 'block'
		
	}
	else
	{
		theElement.style.display = 'none'
	}
	
}


function changeBlog(theElement)
{
	var blog_id = theElement.value;	
	var iframe = $('text_ifr');	
	if (blog_id ==0)
	{
		if (iframe.contentDocument.getElementById('tinymce').innerHTML=='')
		iframe.contentDocument.getElementById('tinymce').innerHTML = '<table style="height: 40px;" border="1" width="485"><tbody><tr><td>Įmonės pavadinimas</td><td>Kontaktai</td><td>Paslauga</td><td>Nuolaida LiCS nariams</td></tr><tr><td>-</td><td>-</td><td>-</td><td>-</td></tr></tbody></table>';
		
	}
	else
	{
		iframe.contentDocument.getElementById('tinymce').innerHTML = '';
	}
	new Ajax.Updater('category_list', '/blog/showBlogCategories?blog_id=' + blog_id,
	{
	method: 'post' 
	}); 
	
}

/**/

function showLeaderPage(page,pages)
{
	var i = 1;
	for(i=1;i<=pages;i++)
	{
		if (i == page)
		{
			$('leader_'+i).style.display = 'block';
			//$('leader_page_'+i).style.size = '12px';
			//$('leader_page_'+i).style.display = 'none';
		}
		else
		{
			$('leader_'+i).style.display = 'none';
			//$('leader_page_'+i).style.size = '16px';
			//$('leader_page_'+i).style.display = 'block';				
		}
	}
	
	
}

/*  BLOG POST*/


function catchSelection()
{
  var selection;
  //alert('catchSelection');

  if (window.getSelection)

  {

    selection = window.getSelection().toString();

  }

  else if (document.getSelection)

  {

    selection = document.getSelection();

  }

  else if (document.selection)

  {

    selection = document.selection.createRange().text;

  }

  return selection;
  /*if (selection)

    last_selection = selection;*/
  
}

function ShowQuote(post_id)
{
	
	var div = $('quote_post_' + post_id);
	
	var selection = catchSelection();
	
	if (selection)
	{	
		div.style.display = 'block';
	}
	else
	{
		div.style.display='none'
	}	
}


function SelectedToForm(post_id)
{
	var selection = catchSelection();
	var set_text = '[quote]\n'+selection+'\n[/quote]\n';	
	var comment_form = $('comment_form'+post_id);
	if (selection)
	{
		if($('text'+post_id))
	    {
	
		  if (comment_form.style.display != 'block')
	      {
	
			comment_form.style.display = 'block';
	
	      }	
		  var text = document.getElementById('text'+post_id);
		  if (text)	
	      {
	
	      	text.value+=set_text;
	
	      	text.focus();
	
	      }
	
	    }
	}
	else
	{
		alert('no selection');
	}
}


function addAnswerTag()
{
	var n_obj = $('n_answers');
	/*var div_obj = $('answers_div');*/
	
	n_obj.value++;
	/*div_obj*/
	new Ajax.Updater('answers_div', '/polls/insertAnswer?id='+n_obj.value, {
 		 insertion: Insertion.Bottom
});
	
}

function showComment(comment_id){
	//alert('aaa');
	var comment_obj = 'comment-'+comment_id;
	var hidecomment_obj = 'hidedcomment-'+comment_id;
	document.getElementById(comment_obj).style.display = 'block';
	document.getElementById(hidecomment_obj).style.display = 'none';		
}