function reportThread(threadid) {
        var reportMessage = document.getElementById('ReportConfirm').innerHTML;
	if(confirm(reportMessage)) {
  	  getURL("/?a=ajax-thread-report&threadid="+threadid);
        }
	return false;
}

function reportThreadOK(threadid) {
	document.getElementById("t"+threadid).className+=" reportedthread";
        var reportSuccess = document.getElementById('ReportThankYou').innerHTML;
	alert(reportSuccess);
	return false;
}

function voteThread(threadid,type) {
	getURL("/?a=ajax-thread-vote&threadid="+threadid+"&type="+type);
	return false;
}

function voteThreadOK(threadid) {
	document.getElementById("t"+threadid).className+=" votedthread";
	return false;
}

function replyToThread(threadid,author,parentid) {
	var replyInd = document.getElementById("replyindicator");
        if (document.getElementById('replyToText')) { var replyToText = document.getElementById('replyToText').value; } else { var replyToText = "replying to"; }
        if (document.getElementById('replyToUndo')) { var replyToUndo = document.getElementById('replyToUndo').value; } else { var replyToUndo = "Undo"; }
	replyInd.innerHTML = (replyToText+' <a href="#t'+threadid+'">'+author+'</a> [<a href="#" onclick="wipeReply(\''+threadid+'\'); return false;">'+replyToUndo+'</a>]');
	document.getElementById("sourceID").value=threadid;
        if (parentid) {
          document.getElementById("parentID").value=parentid;
        }
}

function quoteThread(threadid, authorname) {

        var TagRx = /<(?:.|\s)*?>/g;

	var sel;
        var quoteThread = document.getElementById("ct"+threadid).innerHTML;
        if (window.getSelection) { sel = window.getSelection(); } else if (document.getSelection) { sel = document.getSelection(); } else if (document.selection) { sel = document.selection.createRange().text; }

        var cleanSel = String(sel).replace(/[\W]/g,"");
	if (!cleanSel) { alert('Please highlight the text from this thread you wish to quote to continue.'); return false; }

        var cleanThread = quoteThread.replace(TagRx, "");
            cleanThread = cleanThread.replace(/[\W]/g,"");
        var match = cleanThread.indexOf(cleanSel,0);
        if (match < 0) { alert('Please highlight the text from this thread you wish to quote to continue.'); return false; }

        var quote = String(sel);
        TagRx = /<(?:.|\s)*?>/g;
        QuoteRx = /\"...(.+?)...\"\s?--\s?(.*?)<br>/g;
        quote = quote.replace(QuoteRx, "");
        quote = quote.replace(TagRx, "");
        quote = quote.replace(/\.\./g,".", quote);
        quote = "\"... "+quote+" ...\" -- "+authorname+"\r\n\r\n";

        var thread = document.getElementById("Thread");
        thread.value = thread.value + quote;
	thread.focus();
        return true;
}

function wipeReply(threadid) {
	var replyInd = document.getElementById("replyindicator");
	replyInd.innerHTML = "";
	
	document.getElementById("sourceID").value = "";
	return false;
}

function showReplies(postid,threadid) {
	getURL("/?a=ajax-thread-show-replies&threadid="+threadid+"&postid="+postid);
	return false;
}

function showRepliesOK(threadid, data) {
	var replyDiv = document.getElementById(threadid+"_replies");
	replyDiv.innerHTML = data;
	return false;
}

function submitThread() {
        var postCall = '';
        document.getElementById('ThreadProcessing').style.display = "";
        document.getElementById('ThreadForm').style.display = "None";
	for(i=0; i<document.ThreadForm.elements.length; i++) {
          postCall += "&"+document.ThreadForm.elements[i].name + '=' + document.ThreadForm.elements[i].value;
        }
        if (document.getElementById('newth_title')) {
		document.getElementById('newth_title').value = '';
        }
        document.getElementById('Thread').value = '';
        postURL('?a=ajax-submit-thread', postCall);
	return false;
}

function submitThreadOK(url) {
       if (url != '') {
		 window.location.href = url;
       } else {
        	document.getElementById('ThreadProcessing').style.display = "none";
	        document.getElementById('ThreadProcessed').style.display = "";
       }

return false;
}


function bp_hidethread(id) {
        if (id.style) {
                item = id;
        } else {
                var item = document.getElementById(id);
        }
        if (item) {
                item.style.display = 'none';
        }
        return false;
}

function bp_showthread(id) {
        if (id.style) {
                item = id;
        } else {
                var item = document.getElementById(id);
        }
        if (item) {
                item.style.display = '';
        }
        return false;
}

function bp_showhide_thread(id) {
        if (document.getElementById(id) && document.getElementById(id).style.display == 'none') { bp_showthread(id); } else { bp_hidethread(id); }
        return false;
}

function bp_showall_thread(id) {
        var children = document.getElementById(id).getElementsByTagName('div');
	document.getElementById(id).style.display = '';
        for(var i=0;i<children.length;i++) {
               children[i].style.display = '';
        }
	return false;
}
