function format_it(the_tag, the_box) {
	the_area = document.getElementById(the_box);
	if (the_tag == "quote") { bef = "\n"; aft = "\n"; }
	else { bef = ""; aft = ""; }
	if (document.selection) {
		str = document.selection.createRange().text;
		document.selection.createRange().text = bef + "<" + the_tag + ">" + str + "</" + the_tag + ">" + aft;
	}
	else {
		var startPos = the_area.selectionStart;
		var endPos = the_area.selectionEnd;
		var str = the_area.value.substring(startPos, endPos);
		the_area.value = the_area.value.substring(0, startPos) + bef + "<" + the_tag + ">" + str + "</" + the_tag + ">" + aft + the_area.value.substring(endPos, the_area.value.length);
		the_area.selectionStart = startPos + the_tag.length + bef.length + 2;
		the_area.selectionEnd = endPos + the_tag.length + bef.length + 2;
	}
}
	
function preview() {
	a = document.getElementById("theform");
	a.target = "prevar";
	a.action = "previewvars.php";
	a.submit();
	a.target = "";
	a.action = "http://music-nerds.com/process.php";
}

function quote_comment(id) {
	quotedtext = document.getElementById('commenttext-' + id).innerHTML;
	quotedauth = document.getElementById('commentauthorname-' + id).innerHTML;
	
	quotedtext = quotedtext.replace(/<\/p><p class="comment\-text">/g, '\n\n');
	quotedtext = quotedtext.replace(/(<([^>]+)>)/gi, '');
	
	newbox = document.getElementById('comtext');
	
	newvalue = '<quote><b>' + quotedauth + '</b> wrote:\n' + quotedtext + '</quote>\n\n';
	if (newbox.value) newvalue += newbox.value;
	newbox.value = newvalue;
}

function d2h(d) {
	h = d.toString(16);
	if (h < 10 || (isNaN(h) && h.length == 1)) h = "0" + h;
	return h;
}

function change() {
	inc++;
	if (inc >= coms.length) inc = 0;
	document.getElementById('rec_comments').innerHTML = coms[inc];
	document.getElementById('rc_link').style.color = "#ffffff";
}

function fade() {
	thediv = document.getElementById('rec_comments');
	thelink = document.getElementById('rc_link');
	if (dir == 1) now = now + 2; else now = now - 2;
	hx = d2h(now);
	thelink.style.color = "#" + hx + hx + hx;
	wait = 8;
	if (now <= 2) {
		dir = 1;
		wait = 4000;
	}
	if (now >= 253) {
		dir = -1;
		change();
		wait = 500;
	}
	setTimeout("fade();", wait);
}

function toggle (id) {
	thediv = document.getElementById(id);
	if (thediv.style.display == "block") thediv.style.display = "none";
	else thediv.style.display = "block";
}

function love_hate(id, idtype, action) {
	var dataString = action+'=1&idtype='+idtype+'&id='+id;
	$.ajax({
		type: "POST",
		url: ajaxurl + "/quickedit.php",
		data: dataString,
		success: function(response) {
			$("#lovehate_tools").html(response);
		}
	});
}

function get_preview(inputdiv) {
	var dataString = 'getpreview=1&text=' + encodeURIComponent(document.getElementById(inputdiv).value);
	$.ajax({
		type: "POST",
		url: ajaxurl + "/quickedit.php",
		data: dataString,
		success: function(response) {
			$("#preview_text").html(response);
		}
	});
}