function checkValidBlogg()
{
  formTrim(document.new_blogg_form.blogg_title);
  formTrim(document.new_blogg_form.message);

  if (document.new_blogg_form.blogg_title.value.length == 0)
  {
		alert("Din text måste ha en rubrik (på max 80 tecken).");
		document.new_blogg_form.blogg_title.focus();
		return false;
	}
  else if (document.new_blogg_form.message.value.length == 0)
  {
		alert("Du måste skriva något i ditt meddelande.");
		document.new_blogg_form.message.focus();
		return false;
	}
  else
  {
		return true;
	}
}


function validateAddCategory()
{
	formTrim(document.cat_form.cat_name);
	
	if (document.cat_form.cat_name.value == '')
	{
		alert('Namn på kategorin måste anges.');
		return false;
	}

	return true;
}


function validateDeleteCategories()
{
	cat_selected = false;
	num_elem = document.curr_cat_form.elements.length;
	
	// Make sure any checkbox is checked
	for(i=0; i<num_elem; i++)
	{
		elem = document.curr_cat_form.elements[i];
		if(elem.type == 'checkbox')
		{
			if (elem.checked)
			{
				cat_selected = true;
				break;
			}
		}
	}
	
	if (!cat_selected)
	{
		alert('Ingen kategori har valts.');
		return false;
	}
	
	return true;
}


function onValidComment()
{
	formTrim(document.new_comment.blogg_comment);
	
	if (document.new_comment.blogg_comment.value.length < 1)
  {
		alert("Du måste skriva något i ditt meddelande.");
		document.new_comment.blogg_comment.focus();
		return false;
	}

	return true;
}


function doUpdateComment(uid, bid, cid)
{
	window.location='blogg.php?user_id=' + uid + '&blogg_id=' + bid + '&comment_id=' + cid + '&action=update_comment#comment';
}


function doRemoveBlogg(uid, bid)
{
	if (window.confirm('Är du säker på att du vill ta bort bloggen?'))
  {
    window.location='blogg.php?user_id=' + uid  + '&blogg_id=' + bid + '&action=remove_entry';
  }
}


function doRemoveComment(uid, bid, cid)
{
	if (window.confirm('Är du säker på att du vill ta bort kommenteren?'))
  {
    window.location='blogg.php?user_id=' + uid  + '&blogg_id=' + bid + '&comment_id=' + cid + '&action=remove_comment';
  }
}
