var ajaxedCommentForms = new Array();
var myAjaxAddDivs = new Array();
var myAjaxAddDivsFast = new Array();
function ajaxShowAddComment(postid, throbberurl, addcommentpageurl) {
	itemDisplay('show-inline-add-comment-' + postid, 'none');
	if ( ajaxedCommentForms[postid] ) {
		ajaxAddDisplayWhenLoaded(postid);
		return;
	} else {
		myAjaxAddDivs[postid] = new fx.FadeSize('ajax-add-comment-' + postid, {duration: 600});
		myAjaxAddDivs[postid].toggle('height');
		document.getElementById('ajax-add-comment-notification-' + postid).innerHTML = '<p align="center" class="comment-loader"><img src="' + throbberurl + '" alt="loading" /></p>';
		ajaxedCommentForms[postid] = new ajax(correctWWW(addcommentpageurl), {postBody: 'id=' + postid, update: $('ajax-add-comment-' + postid), onComplete: ajaxAddWaitForHide(postid)});
	}
}

function ajaxAddWaitForHide(postid) {
	setTimeout("ajaxAddDisplayWhenLoaded(" + postid + ")", 650);
}

function ajaxHideAddComment(postid) {
	setTimeout("itemDisplay('show-inline-add-comment-" + postid + "', 'inline')", 600);
	myAjaxAddDivs[postid].toggle('height');
}

function itemDisplay(item, display) {
	document.getElementById(item).style.display = display;
}

function ajaxAddDisplayWhenLoaded(postid) {

	if ( document.getElementById('ajax-add-comment-' + postid).innerHTML.length < 100 ) {
		setTimeout("ajaxAddDisplayWhenLoaded(" + postid + ")", 10);
		return;
	} else {
		setTimeout("myAjaxAddDivs[" + postid + "].toggle('height')", 10);
		document.getElementById('ajax-add-comment-notification-' + postid).innerHTML = '';
	}
}function correctWWW(theUrl)
 {
       // The current page has a www address
     // The AJAX requested page has an absolute, not relative, address
     // The AJAX requested page does not have a www address
     if (window.location.href.indexOf("www.") != -1 && 
         theUrl.indexOf("http://") != -1 && 
         theUrl.indexOf("www.") == -1)
     {
        theUrl = theUrl.replace("http://", "http://www.");
    }
    
    // The current page does not have a www address
    // The AJAX requested page has an absolute, not relative, address
    // The AJAX requested page has a www address
   else if (window.location.href.indexOf("www.") == -1 && 
            theUrl.indexOf("http://") != -1 && 
             theUrl.indexOf("www.") != -1)
    {
       theUrl = theUrl.replace("http://www.", "http://");
    }
    
    return theUrl;
}
