// JavaScript Document

function fromHTML(html) {
	var root = document.createElement('div');
	root.innerHTML = html;
	return root.firstChild;
}

function closeSearch() { 
	divThing = document.getElementById('searchBox');
	divThing.parentNode.removeChild(divThing); 
}

function search() { 
	var searchPopup = fromHTML('<div id="searchBox">' +
								   '<form action="/blog/results.php" method="post">' +
									   '<h2>Search Tool</h2>' +
									   '<p>Search posts by:</p>' +
									   '<ul>' +
										   '<li><label>Title</label> <input name="title" /></li>' +
										   '<li><label>Body Text</label> <input name="body" /></li>' +
										   '<li><label>Author</label> <input name="author" /></li>' +
										   '<li><label>Tags</label> <input name="tags" /></li>' +
										   '<li class="x"><input type="submit" name="submit" value="Begin Search" /></li>' +
										   '<li class="x"><input type="button" name="close" onclick="closeSearch();" value="Close Search Tool" /></li>' +
									   '</ul>' +
								   '</form>' +
							   '</div>');
	document.getElementById('blogtools').parentNode.appendChild(searchPopup);
	//Search box background image by Thor667. Lol.
}

function deletepost() {
	var agree = confirm("Are you sure you want to permanently delete that?");
	if (agree) return true ;
	else return false ;
}

function toggle_ul(a) {
  // Get parent
  var parent = a.parentNode;
  var children = parent.childNodes;
  for (i=0; i<children.length; i++) {
    if (children[i].nodeName == "UL") { 
      var ul = children[i];
      if (ul.style.display == "none") {
        ul.style.display = "";
      } else {
        ul.style.display = "none";
      }
    }
  }
}

function addpic2blog(image) {
	image = "/assets/images/article/" + image;
	document.blogentry.entry.value += "[img]" + image + "[/img]";
}

function popup(a) {
	window.open(a, '','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600');
}