dsqTimeHide = {};
dsqTimeShow = {};

function dsqShowMenu(id) { document.getElementById('dsq-menu-' + id).style.display = "block"; }
function dsqHideMenu(id) { document.getElementById('dsq-menu-' + id).style.display = "none"; }

function dsqShowTimer(id) {
	// clear the hide timer
	clearTimeout(dsqTimeHide[id]);
	
	// start the timer to show the menu
	dsqTimeShow[id] = setTimeout("dsqShowMenu(\"" + id + "\")", 400);
}

function dsqHideTimer(id) {
	// clear the show timer
	clearTimeout(dsqTimeShow[id]);
	
	// if the menu is shown, start the timer to hide it
	if(document.getElementById('dsq-menu-' + id).style.display == "block") {
		dsqTimeHide[id] = setTimeout("dsqHideMenu(\"" + id + "\")", 400);
	}
}

function dsqSortBy(value) {
	var startIdx = document.URL.indexOf('?dsq_sort=');
	var curUrl = document.URL;
	
	if(startIdx == -1) {
		startIdx = document.URL.indexOf('&dsq_sort=');
		var usesAmp = true;
	}
	
	if(startIdx != -1) {
		var endIdx = document.URL.indexOf('&', startIdx + 1);
		curUrl = document.URL.substring(0, startIdx) + (!usesAmp ? '?' : '');
		
		if(endIdx != -1) {
			curUrl += document.URL.substring(endIdx + (!usesAmp ? 1 : 0));
		}
	}
	
	if(curUrl.indexOf('#') != -1) {
		curUrl = curUrl.substring(0, curUrl.indexOf('#'));
	}
	
	document.location = curUrl + ((curUrl.indexOf('?') != -1) ? '&' : '?') + 'dsq_sort=' + value;
}

(function() {
	if(document.location.hash == '#disqus-approve') {
		document.getElementById('dsq-message').innerHTML = '<strong>Thank you for posting. Your post is waiting to be approved by a moderator.</strong>';
		document.getElementById('dsq-message').style.display = "block";
		document.location.hash = 'dsq-message';
	}
})();