/* xml http request object. */
var xmlHttp23 = null;

/** load th comments into the page. */
function loadComments(){

    try {
        // Firefox, Opera 8.0+, Safari, IE7
        xmlHttp23 = new XMLHttpRequest();
    } 
    catch (e) {
        // Old IE
        try {
            xmlHttp23 = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (e) {
            return false;
        }
    }
    
    
    var url = "blog/index.php/comments/article/" + title;
    xmlHttp23.onreadystatechange = stateChanged23;
    xmlHttp23.open("GET", url, true);
    xmlHttp23.send(null);
    
}


function stateChanged23(){

    if (xmlHttp23.readyState == 4) {
        document.getElementById("comments").innerHTML = xmlHttp23.responseText;
    }
}



/** the to be commented paragraph. */
var para='';
/** 
 * add a comment. 
 * paragraph: the name of the paragraph to be commented.
 */
function addComment(paragraph){

    para = paragraph;
    document.getElementById('add-form' + paragraph).style.visibility = 'hidden';
    createAddForm();
    document.getElementById('commit-comment').innerHTML = "";
}

/** check the add form. */
function checkAddForm(){
    ret = true;
    if (document.getElementById('title-input').value == "") {
        document.getElementById('empty-title').innerHTML = "Please enter a title for this comment.";
        ret = false;
    }
    else {
        document.getElementById('empty-title').innerHTML = "";
    }
    return ret;
}
xmlHttp5 = null;
/** create add form. */
function createAddForm(){

    try {
        // Firefox, Opera 8.0+, Safari, IE7
        xmlHttp5 = new XMLHttpRequest();
    } 
    catch (e) {
        // Old IE
        try {
            xmlHttp5 = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (e) {
            return false;
        }
    }
    
    var postdata = "paragraph=" + para;
    var url = "blog/index.php/edit/add/" + title;

    xmlHttp5.open("POST", url, true);
    xmlHttp5.onreadystatechange = stateChanged5;
    xmlHttp5.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp5.send(postdata);
    
}


function stateChanged5(){

    if (xmlHttp5.readyState == 4) {
        document.getElementById("addcomment" + para).innerHTML = xmlHttp5.responseText;
		try{ // in IE this probably won't work...
				tinyMCE.init({
					mode : "textareas",
					theme : "advanced",
					theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink",
					theme_advanced_buttons2 : "",
					theme_advanced_buttons3 : "",
					theme_advanced_toolbar_location : "top",
					theme_advanced_toolbar_align : "left",
					theme_advanced_statusbar_location : "bottom",
					theme_advanced_font_sizes : "1,2,3,6,7",
					extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]"
					
					});
				} catch(e) {
					
				}	
    }
}

/** show all comments from a certain paragraph. */
function showParagraphComments(paragraph, articlename){
	if(document.getElementById('commentspara' + paragraph).innerHTML != '') {
		document.getElementById('commentspara' + paragraph).innerHTML = '';
		document.getElementById('showcomments' + paragraph).innerHTML = 'Show comments for ' + paragraph;
	}
	else {
		document.getElementById('showcomments' + paragraph).innerHTML = 'Loading comments for ' + paragraph + '...';
		loadParagraphComments(paragraph, articlename);
	}
}

var xmlHttp6 = null;
var para2 = '';
/** ajax script to load all comments associated to a paragraph. **/
function loadParagraphComments(paragraph, articlename){
    para2 = paragraph;
	try {
        // Firefox, Opera 8.0+, Safari, IE7
        xmlHttp6 = new XMLHttpRequest();
    } 
    catch (e) {
        // Old IE
        try {
            xmlHttp6 = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (e) {
            return false;
        }
    }
    
    var postdata = "paragraph=" + paragraph;
    var url = "blog/index.php/comments/article/" + articlename;

    xmlHttp6.open("POST", url, true);
    xmlHttp6.onreadystatechange = stateChanged6;
    xmlHttp6.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp6.send(postdata);

}

function stateChanged6(){

    if (xmlHttp6.readyState == 4) {
		document.getElementById('commentspara' + para2).innerHTML = xmlHttp6.responseText;
		document.getElementById('showcomments' + para2).innerHTML = 'Hide comments for ' + para2;
	}
}




