var postid = 0;
function quicked(postid) {
    var phide;
    var eshow;
    if (document.getElementById("post"+postid).style.display != 'none') {
        phide = 'none';
        eshow = 'block';
    } else {
        phide = 'block';
        eshow = 'none';
    }
    document.getElementById("post"+postid).style.display = phide;
    document.getElementById("edit"+postid).style.display = eshow;
    //setTimeout("post"+postid+".style.visibility = none; edit"+postid+".style.visibility = block", 0);
}
function quickquote(postid,uname) {
    postdata = document.getElementById("postdata"+postid).value;
    postdata = "[quote="+uname+"]\n"+postdata+"\n[/quote]\n\n";
    document.getElementById("quickedit").value = document.getElementById("quickedit").value+postdata;
    document.location.hash='#quickedit';
    document.getElementById("quickedit").focus();
}

function getxmlhttp() {
	xmlhttp=false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  xmlhttp = new XMLHttpRequest();
	}

	return xmlhttp;
}

function rate(postid, dir) { 
    /*i = new Image();
    i.onload = rateDone(postid);
	i.onload = alert('2');
    i.src = '/forum/forumratepost.php?p='+postid+'&dir='+dir;
	alert('1');*/

 xmlhttp = getxmlhttp();
 xmlhttp.open("GET", '/forum/forumratepost.php?nooutput=true&p='+postid+'&dir='+dir, true);
 xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState==4) {
   alert(xmlhttp.responseText)
	if (xmlhttp.responseText.match(/Post Rated/)) {
 		document.getElementById("topstuff").innerHTML
		rateBox = document.getElementById("rate_"+postid);
		rateBox.innerHTML = parseInt(rateBox.innerHTML) + dir;
	}
  }
 }
 xmlhttp.send(null)
}


function subscribe(threadid, img) {
	xmlhttp = getxmlhttp();

	if (!xmlhttp) {
		alert("Your browser does not apear to support xml http requests. If you are using Internet Explorer, this is an ActiveX control.\n"+
		"You must allow ActiveX for this site in order to use the quick subscribe feature.");
		return false;
	}

	subtype = "";
	if (img.src.indexOf("subscribed") != -1) {
		subtype = "un";
	}

	xmlhttp.open("GET", "http://www.blamethepixel.com/forum/forumsubscribe.php?js=true&subtype="+subtype+"&t="+threadid+"&r="+ Math.random());
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState == 4) {
			subInProgress = false;
			//alert(xmlhttp.responseText);
			if (xmlhttp.responseText.length != 2) {
				alert("There was an error subscribing to the thread :(");
				return false;
			}

			newClass = "threadrow-sub";
			if (xmlhttp.responseText.charAt(0) == "1")  {
				img.src = "/images/subscribed.png";
				img.alt = "unsubscribe";
				img.title= "unsubscribe";
			} else {
				img.src = "/images/subscribe.png";
				img.alt = "subscribe";
				img.title = "subscribe";
				newClass = "threadrow";
			}

	
			//change the thread's class in forum index - for backgrounds etc.
			curEl = img;
			while (curEl.tagName != "TR") {
				curEl = curEl.parentNode;
				/*if (!prompt(curEl.tagName)) {
					return;
				}*/
			}
			curEl.className = newClass;
		}
	}
	
	xmlhttp.send(null);
}

function marksplit(pid, link) {
	xmlhttp = getxmlhttp();

	if (!xmlhttp) {
		alert("You don't have XMLHttp (ActiveX?) enabled");
		return false;
	}

	xmlhttp.open("GET", "/forum/forummarksplit.php?p="+pid+"&r="+Math.random());
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState == 4) {
			if (xmlhttp.responseText.length != 1) {
				alert(xmlhttp.responseText);
				return false;
			}
			if (xmlhttp.responseText == "1") {
				link.style.fontWeight = "bold";
			} else {
				link.style.fontWeight = "";
			}
		}
	}
	xmlhttp.send(null);
}

function lock(threadid, img) {
	xmlhttp = getxmlhttp();
	if (!xmlhttp) {
		alert("Your browser does not apear to support xml http requests. If you are using Internet Explorer, this is an ActiveX control.\n"+
		"You must allow ActiveX for this site in order to use the quick lock feature.");
		return false;
	}

	locktype = "1";
	if (img.src.indexOf("locked") != -1) {
		locktype = "0";
	}

	xmlhttp.open("GET", "/forum/forumlockthread.php?js=true&action="+locktype+"&id="+threadid+"&r="+ Math.random());
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState == 4) {
			subInProgress = false;
			if (xmlhttp.responseText.length != 1) {
				alert(xmlhttp.responseText);
				return false;
			}

			if (xmlhttp.responseText == "1")  {
				img.src = "/images/lockedsmall.png";
				img.alt = "unlock";
				img.title= "unlock";
			} else {
				img.src = "/images/locksmall.png";
				img.alt = "lock";
				img.title = "lock";
			}

		}
	}
	
	xmlhttp.send(null);

}

/*function rateDone(postid) {
    rateBox = document.getElementById('rate_'+postid);
    rateBox.innerHtml = ':)';
}*/
