// ajax stuff
function doAjaxReport(commentid, commentnum) {
	if (!confirm('Report this comment to the administrator?'))	{return false;}
	if (window.XMLHttpRequest) {ajaxrep = new XMLHttpRequest();}
	else if (window.ActiveXObject) {
		try {ajaxrep = new ActiveXObject("Msxml2.XMLHTTP");}
		catch(e) {try {ajaxrep = new ActiveXObject("Microsoft.XMLHTTP");} 
		catch(e) {ajaxrep = false;}
		}
	}
	if (!ajaxrep) {return false;}
	var params = 'commentid=' + escape(commentid) + '&commentnum=' + escape(commentnum);
	ajaxrep.onreadystatechange = processReport;
	ajaxrep.open("POST", "/articles/ajax_report.asp", true);
	ajaxrep.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	if (ajaxrep.overrideMimeType) {ajaxrep.setRequestHeader("Connection", "close");}
	ajaxrep.send(params);
	return false;
}

function processReport() {
	if (ajaxrep.readyState == 4) {
		if (ajaxrep.status == 200 || ajaxrep.status == 304) {
			var theResponse = ajaxrep.responseText;
			if (theResponse.substr(0,9) == 'while(1);') {
				theResponse = theResponse.substring(9);
			}
			var report = eval('('+theResponse+')');
			alert(report.status);
			ajaxrep = null;
		}
	}
}
// not ajax
function $ () {
	var elements=new Array();
	for (var i=0;i < arguments.length;i++){
		var element=arguments[i];
		if (typeof element=='string')
			element=document.getElementById(element);
		if (arguments.length==1)
			return element;
		elements.push(element);

	}
	return elements;
}

// show qty characters remaining in a textarea
// modified from smartwebby.com
// ex. in textarea - onKeyPress=" return charLimit(this)" onKeyUp="return charCount(this,'charsleft',4096);"
// plus - <span id=charsleft>4000</span> remaining
var commentLimit=4000;
function charLimit(obj){
	if (obj.value.length==commentLimit) return false;
	return true;
}
function charCount(Objfield,target,limit){
	objTarget=getObject(target);
	objValue=Objfield.value;
	if (objValue.length>limit) objValue=ObjValue.substring(0,limit);
	if (objTarget){
		if (objTarget.innerText) {objTarget.innerText=limit-objValue.length;}
		else {objTarget.textContent=limit-objValue.length;}
	}
	return true;
}
function getObject(id){
	if (document.getElementById) return document.getElementById(id);
	else if (document.layers) return eval("document."+id);
	else if (document.all) return eval("document.all."+id);
	else return eval("document."+id);
}

function insertReply(lft, rgt, thecommentdiv) {
	objDiv=getObject(thecommentdiv);
	var txtarea = document.form_blog.comment_desc;
	var theText = '';
	if (arguments.length == 3) {
		if (objDiv.innerText) {theText=objDiv.innerText;}
		else {theText=objDiv.textContent;}
		theText = theText.replace(/\n/ig, '');
		theText = theText.replace(/%u201C/ig, '&ldquo;');
		theText = theText.replace(/%u201D/ig, '&rdquo;');
		theText = theText.replace(/%u2019/ig, '&rsquo;');
		theText = theText.replace(/%uFFFD/ig, '&copy;');
		theText = theText.replace(/\n/ig, '');
		theText = theText.replace(/<P>/ig, '');
		theText = theText.replace(/<\/P>/ig, '\n\n');
		theText = theText.replace(/<BR>/ig, '\n');
		theText=theText.replace(/^\s+|\s+$/g,'');// from nicklettleton.com/zine/javascript/trim-a-string-in-javascript
		theText = '<blockquote>' + theText + '</blockquote>\n\n';
	}
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2) {
		selEnd = selLength;
	}
	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd);
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + lft + theText + s2 + rgt + s3;
	txtarea.focus();
	txtarea.selectionEnd = txtarea.value.length;
	txtarea.selectionStart = txtarea.value.length;
	return false;
}
