function printWeblogCommentResData(text_data) {
	document.getElementById('commentmsg').innerHTML = text_data;

	if (text_data.indexOf('完了しました') < 0) {
	    document.getElementById('commenttransmit').disabled = false;
	} else {
		var funcRef = function(text_data) {
			document.getElementById('weblogcommentlist').innerHTML = text_data;
		}
	    var thecontent  = document.getElementById('theContent').value;
	    //var theclassify  = document.getElementById('theClassify').value;
		httpRequest('getblogcomment.jspx?theContent='+thecontent+'&theClassify=0', funcRef);
		document.getElementById('theName').value = '';
		document.getElementById('theEmailaddress').value = '';
		if(document.getElementById('theURL') != null){
			document.getElementById('theURL').value = '';
		}
		document.getElementById('theComment').value = '';
	}
}

function postWeblogCommentData(e) {
    document.getElementById('commenttransmit').disabled = true;
	document.getElementById('commentmsg').innerHTML = '';

    var thename = document.getElementById('theName').value;
    var theemailaddress = document.getElementById('theEmailaddress').value;
    var theurl = '';
    if(document.getElementById('theURL') != null){
	    theurl = document.getElementById('theURL').value;
	}
    var thecomment  = document.getElementById('theComment').value;
    var thecontent = document.getElementById('theContent').value;


    var thecapchaid = null;
    if (document.getElementById('theCapchaid')){
        thecapchaid = document.getElementById('theCapchaid').value;
    }
    if(!thecapchaid){
	tmp = "loginstatus=1;";
	tmp += "expires=Tue, 31-Dec-2030 23:59:59; ";
	document.cookie = tmp;
        var capchaimg = document.getElementById('capchaimg');
        capchaimg.src = '/jcapcha.jspx';
	var capchabox = document.getElementById('capchabox');
	capchabox.style.display = 'block';
//        return;
    }

    var post_data;

    post_data = 'theName=' + encodeURI(thename) +
                '&theEmailaddress=' + encodeURI(theemailaddress) +
                '&theURL=' + encodeURI(theurl) +
                '&theComment=' + encodeURI(thecomment) +
                '&theContent=' + encodeURI(thecontent) + 
                '&theCapchaid=' + encodeURI(thecapchaid);

         
    var target_url = 'setblogcomment.jspx';
    httpPostRequest(target_url, post_data, printWeblogCommentResData);
}

function setListenersWeblogComment(e) {
    var evaluation = document.getElementById('commenttransmit');
    addListener(evaluation, 'click', postWeblogCommentData, false);
}

addListener(window, 'load', setListenersWeblogComment, false);