function handleHttpRequestCommit(xmlHttp, id, obj1, obj2) {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var xmlDoc = xmlHttp.responseXML;
            if (xmlDoc.documentElement) {
                var getData = xmlDoc.documentElement.childNodes;
                setCount(getData, id, obj1, obj2);
            }
        }
    } else {
    }
}

function handleHttpRequestTop(xmlHttp, obj) {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var xmlDoc = xmlHttp.responseXML;
            if (xmlDoc.documentElement) {
                var getData = xmlDoc.documentElement.childNodes;
                setTopData(getData, obj);
            }
        }
    } else {
    }
}

function handleHttpRequestNew(xmlHttp, obj) {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var xmlDoc = xmlHttp.responseXML;
            if (xmlDoc.documentElement) {
                var getData = xmlDoc.documentElement.childNodes;
                setNewCommitData(getData, obj);
            }
        }
    } else {
    }
}

function handleHttpRequestAllCommit(xmlHttp, id) {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var xmlDoc = xmlHttp.responseXML;
            if (xmlDoc.documentElement) {
                var getData = xmlDoc.documentElement.childNodes;
                setAllCommitData(getData, id);
            }
        }
    } else {
        to_obj = 'all_commit_' + id;
    	setLoading(document.getElementById(to_obj));
    }
}

function handleHttpRequestSetCategory(xmlHttp) {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var xmlDoc = xmlHttp.responseXML;
            if (xmlDoc.documentElement) {
                var getData = xmlDoc.documentElement.childNodes;
                setSetCategory(getData);
            }
        }
    } else {
    }
}

function handleHttpRequestSetCategory(xmlHttp) {
    if (xmlHttp.readyState == 4) {;
        if (xmlHttp.status == 200) {
            var xmlDoc = xmlHttp.responseXML;
            if (xmlDoc.documentElement) {
                var getData = xmlDoc.documentElement.childNodes;
                setSetCategory(getData);
            }
        }
    } else {
    }
}

function handleHttpRequestSetCategory(xmlHttp) {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var xmlDoc = xmlHttp.responseXML;
            if (xmlDoc.documentElement) {
                var getData = xmlDoc.documentElement.childNodes;
                setSetCategory(getData);
            }
        }
    } else {
    }
}

function handleHttpRequestDelCommit(xmlHttp, blog_id, obj1, obj2) {
    if (xmlHttp.readyState == 4) {
        if (xmlHttp.status == 200) {
            var xmlDoc = xmlHttp.responseXML;
            if (xmlDoc.documentElement) {
                var getData = xmlDoc.documentElement.childNodes;
                setCount(getData, blog_id, obj1, obj2);
                setAllCommit(blog_id);
            }
        }
    } else {
    }

}

function setSetCategory(getData) {
    // 返回提示
    alert(getData[0].nodeValue);
    window.location.reload();
}

function setLoading(obj) {
	obj.innerHTML = '<div style="margin:20 0 0 20; font-size:16px; color:#666666;">正在取得数据 </div>';
}

function setCount(getdata, id, obj1, obj2){
	if (getdata[1]) {
		// 隐藏评论框
		document.getElementById('blogId').value = "";
		document.getElementById('text').value = "";
		document.all.full.style.visibility = 'hidden';
		document.all.commit.style.visibility = "hidden";
		
		// 获取评论统计
		var text_conut = getdata[0].childNodes[1].firstChild.nodeValue;
		var level_conut = getdata[1].childNodes[1].firstChild.nodeValue;
        
		// 重写div
		obj1.innerHTML = "(" + text_conut + ")";
		obj2.innerHTML = "(" + level_conut + ")";
		
	} else {
		// 隐藏评论框
		document.getElementById('blogId').value = "";
		document.getElementById('text').value = "";
		document.all.commit.style.visibility = "hidden";
		// 显示错误框
		document.all.alt_message.innerHTML = getdata[0].nodeValue;
		document.all.alertform.style.visibility = 'visible';
	}
	
	// 获取新点评
	setAllCommit(id);
    
	// 设置点评TOP5
	setTop(document.getElementById('top5commit'));
	
	// 设置最新点评
	setNew(document.getElementById('newcommit'));
}

function setTopData(data, obj) {
	var disHTML = "";
	for (var i = 0; i < data.length; i++) {
		var key = data[i].childNodes[0].firstChild.nodeValue;
		var value = data[i].childNodes[1].firstChild.nodeValue;
		disHTML += '<div class="topcontent"><a href="/blog/detail.html?bid=' + key + '">' + value + ' </a></div>';
		disHTML += '<div class="line_2"></div>';
	}
	obj.innerHTML = disHTML;

}

function setNewCommitData(data, obj) {
	var disHTML = "";
	for (var i = 0; i < data.length; i++) {
		disHTML += '<div class="newcontent_1"><a href="/blog/detail.html?bid=' + data[i].childNodes[0].firstChild.nodeValue + '">' + data[i].childNodes[1].firstChild.nodeValue + ' </a></div>'
		disHTML += '<div class="newcontent_2">by&nbsp;' + data[i].childNodes[3].firstChild.nodeValue + '&nbsp;&nbsp;&nbsp;' + data[i].childNodes[2].firstChild.nodeValue + ' </div>';
		disHTML += '<div class="line_2"></div>';
	}
	obj.innerHTML = disHTML;

}

function setAllCommitData(data, id) {
	var disHTML = "";
    if (data.length == 0) {
        disHTML += '<div style="margin-top:20px;">'
        disHTML += '<span style="margin-left:5px; color:#666666;">暂时没有点评</span>';
        disHTML += '</div>';
    } else {
    	for (var i = 0; i < data.length; i++) {
                 disHTML += '<div style="margin-top:10px; margin-left:10px;padding:0;" align="left">';
			disHTML += '<table border="0" cellspacing="0" cellpadding="0">';
			disHTML += '<tr valign="top">';
			disHTML += '<td width="110" align="center">';
                 disHTML += '<div style="margin-top:5px; padding:0;">'; 
			disHTML +=  '<a href="/profile/index.html?id=' + data[i].childNodes[0].firstChild.nodeValue + '" target="_blank"><img src="'+ data[i].childNodes[6].firstChild.nodeValue+ '" width="50" border="0">' ;
			disHTML += '<div style="margin-top:4px; color:#2970A6;font-weight:bold;">' + '<a class="commit_nick" href="/profile/index.html?id=' + data[i].childNodes[0].firstChild.nodeValue + '" target="_blank">' + data[i].childNodes[1].firstChild.nodeValue + '</a>' + ' </div>';
                disHTML += '</div>';
			disHTML += '</td>';
			disHTML += '<td width="21" align="right" >';
			disHTML += '<div style="margin-top:25px; padding:0;">';
                 disHTML += '<img src="/remote/blog/image/bolg_2.jpg" width="21" height="18" /></div>';
			disHTML += '</td>';
			disHTML += '<td width="515" align="left">  ';  
			disHTML += '<div style="width:515px;">';
			disHTML += '<div style="margin:0 4px; background:#EDEFF0; height:1px; overflow:hidden;"></div>';
			disHTML += '<div style="margin:0 2px; background:#EDEFF0; height:1px; overflow:hidden;"></div>';
			disHTML += '<div style="margin:0 1px; background:#EDEFF0; height:1px; overflow:hidden;"></div>';
			disHTML += '<div style="margin:0 1px; background:#EDEFF0; height:1px; overflow:hidden;"></div>';
			disHTML += '<div style="background:#EDEFF0; padding:5px 10px; line-height:150%; ">';
			disHTML += '<div style="color:#555555; margin-bottom:10px;float:left">' + data[i].childNodes[4].firstChild.nodeValue + '   ' + data[i].childNodes[5].firstChild.nodeValue + '</div>';
			disHTML += '<div style="color:#a7b7d0; font-family:Century Gothic; font-size:16px; font-weight:600; float:right">' + data[i].childNodes[7].firstChild.nodeValue + '</div>';
			disHTML += '<div style="clear:both"></div>';
			disHTML += '<span style="color:#555555;">' + data[i].childNodes[3].firstChild.nodeValue + '</span>';
			disHTML += '</div>';
			disHTML += '<div style="margin:0 1px; background:#EDEFF0; height:1px; overflow:hidden;"></div>';
			disHTML += '<div style="margin:0 1px; background:#EDEFF0; height:1px; overflow:hidden;"></div>';
			disHTML += '<div style="margin:0 2px; background:#EDEFF0; height:1px; overflow:hidden;"></div>';
			disHTML += '<div style="margin:0 4px; background:#EDEFF0; height:1px; overflow:hidden;"></div>';
			disHTML += '</div>';
			disHTML += '</td>';
			disHTML += '</tr>';
			disHTML += '</table>';
			disHTML += '</div>';
    	}
    }
    to_obj1 = 'all_commit_' + id;
    to_obj2 = 'commit_detail_' + id;
    document.getElementById(to_obj1).style.display = "";
    document.getElementById(to_obj1).style.visibility = "visible";
	document.getElementById(to_obj1).innerHTML = disHTML;
}

function sendHttpRequestCommit(xmlHttp, url, id, level, text, obj1, obj2) {
	var postContent = "id=" + id + "&level=" + encodeURIComponent(level) + "&text=" + encodeURIComponent(text);
    xmlHttp.open('POST', url, true);
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.onreadystatechange = function() {
        handleHttpRequestCommit(xmlHttp, id, obj1, obj2)
    }
    xmlHttp.send(postContent);
}

function sendHttpRequestTop(xmlHttp, url, obj) {
    xmlHttp.open('GET', url, true);
    xmlHttp.onreadystatechange = function() {
        handleHttpRequestTop(xmlHttp, obj)
    }
    xmlHttp.send(null);
}

function sendHttpRequestNew(xmlHttp, url, obj) {
    xmlHttp.open('GET', url, true);
    xmlHttp.onreadystatechange = function() {
        handleHttpRequestNew(xmlHttp, obj)
    }
    xmlHttp.send(null);
}

function sendHttpRequestAllCommit(xmlHttp, url, id) {
    xmlHttp.open('GET', url + "?bid=" + id, true);
    xmlHttp.onreadystatechange = function() {
        handleHttpRequestAllCommit(xmlHttp, id)
    }
    xmlHttp.send(null);
}

function sendHttpRequestSetCategory(xmlHttp, url, name, parent) {
    var postContent = "name=" + encodeURIComponent(name) + "&parent=" + encodeURIComponent(parent);
    xmlHttp.open('POST', url, true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.onreadystatechange = function() {
        handleHttpRequestSetCategory(xmlHttp)
    }
    xmlHttp.send(postContent);
}

function sendHttpRequestGetCategory(xmlHttp, url) {
    xmlHttp.open('GET', url , true);
    xmlHttp.onreadystatechange = function() {
        handleHttpRequestGetCategory(xmlHttp)
    }
    xmlHttp.send(null);
}

function sendHttpRequestSetEditCategory(xmlHttp, url, id, name, parent) {
    var postContent = "id=" + id + "&name=" + encodeURIComponent(name) + "&parent=" + encodeURIComponent(parent);
    xmlHttp.open('POST', url, true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.onreadystatechange = function() {
        handleHttpRequestSetCategory(xmlHttp)
    }
    xmlHttp.send(postContent);
}

function sendHttpRequestSetDelCategory(xmlHttp, url, id, name) {
    xmlHttp.open('GET', url + "?id=" + id + "&name=" + name, true);
    xmlHttp.onreadystatechange = function() {
        handleHttpRequestSetCategory(xmlHttp)
    }
    xmlHttp.send(null);
}

function sendHttpRequestDelCommit(xmlHttp, url, commit_id, blog_id, member_id, obj1, obj2){
    xmlHttp.open('GET', url + "?commit_id=" + commit_id + "&blog_id=" + blog_id + "&member_id=" + member_id, true);
    xmlHttp.onreadystatechange = function() {
        handleHttpRequestDelCommit(xmlHttp, blog_id, obj1, obj2)
    }
    xmlHttp.send(null);
}

function setCommit(obj1, obj2) {
	for(i=0;i<document.all.level.length;i++) {
		if(document.all.level[i].checked) {
			var level = document.all.level[i].value;
		}
	}
	var id = document.all.blogId.value;
	var text = document.all.text.value;
    var xmlHttp = getXmlHttpObject();
    sendHttpRequestCommit(xmlHttp, '/blog/set_commit.html', id, level, text, obj1, obj2);
}

function setTop(obj) {
    var xmlHttp = getXmlHttpObject();
    sendHttpRequestTop(xmlHttp, '/blog/get_top.html', obj);
}

function setNew(obj) {
    var xmlHttp = getXmlHttpObject();
    sendHttpRequestNew(xmlHttp, '/blog/get_new_commit.html', obj);
}

function setAllCommit(id) {
    var xmlHttp = getXmlHttpObject();
    sendHttpRequestAllCommit(xmlHttp, '/blog/get_all_commit.html', id);
}
function setCategory(name, parent) {
    var xmlHttp = getXmlHttpObject();
    sendHttpRequestSetCategory(xmlHttp, '/blog/set_category.html', name, parent);
}
function getCategory() {
    var xmlHttp = getXmlHttpObject();
    sendHttpRequestGetCategory(xmlHttp, '/blog/get_category.html');
}
function setEditCategory(id, name, parent) {
    var xmlHttp = getXmlHttpObject();
    sendHttpRequestSetEditCategory(xmlHttp, '/blog/set_edit_category.html', id, name, parent);
}
function setDelCategory(id, name, parent) {
    var xmlHttp = getXmlHttpObject();
    sendHttpRequestSetDelCategory(xmlHttp, '/blog/set_del_category.html', id, name);
}
function delCommit(commit_id, blog_id, member_id, obj1, obj2) {
    var xmlHttp = getXmlHttpObject();
    sendHttpRequestDelCommit(xmlHttp, '/blog/del_commit.html', commit_id, blog_id, member_id, obj1, obj2);
}