



// Show comments, use showComment()
// flag show is the cooment field mast be vissible or hide
function showCommentBlockNews(id,userId,flag){

	document.getElementById('comCount' + id).style.display = "none";
	comFiled = "comField" + id;
	if(flag=='sh'){document.getElementById(comFiled).style.display = "block";}
	else if(flag=='0'){
		commId = "commentArea" + id;
		document.getElementById(comFiled).style.display = "none";
		document.getElementById(commId).value = '';
		}
	
	divId = "comment" + id;
	elem = document.getElementById(divId);

	if(elem.style.display == 'block'){
		elem.style.display = 'none';
	}
	else {
		obj = 'comCount' + id;
		obj = document.getElementById(obj);
		if(document.getElementById('load').style.display=="none")showLoad(obj);
		elem.style.display = 'block';
		data = "id=" + id + "&user_id=" + userId;
		divId = "listComment" + id;
		showComment("/show_comment_news.php",data,divId);
	}
}

//Insert the comment in DB
function submitCommentNews(strURL,data,id) {

 	   
		var xmlHttpReq = false;
    // Mozilla
    	if (window.XMLHttpRequest) {
        	xmlHttpReq = new XMLHttpRequest();
        	xmlHttpReq.overrideMimeType('text/xml');
    	}
    // IE
    	else if (window.ActiveXObject) {
        	xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    	}
    	
    	xmlHttpReq.open('POST', strURL, true);
    	xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    	xmlHttpReq.onreadystatechange = function() { 
        	if (xmlHttpReq.readyState == 4) {

				if(xmlHttpReq.responseText!=''){
						
						divId = "comment" + id;
						document.getElementById(divId).style.display = 'none';
						showCommentBlockNews(id,'','0');//alert(xmlHttpReq.responseText);
						hideLoad();
						
				}

				else {hideLoad();}
    		}
		}
    	xmlHttpReq.send(data);    	
}



//Use submitComment()
function postCommentNews(id,userId){

	obj = 'comCount' + id;
	obj = document.getElementById(obj);
	showLoad(obj);
	commId = "commentArea" + id;
	comm = document.getElementById(commId).value;
	data = "id=" + id + "&comment=" + comm + "&user_id=" + userId;	
	submitCommentNews("/post_comment_news.php",data,id);
}


function delCommentNews(comId,blockId){

	obj = 'comCount' + blockId;
	obj = document.getElementById(obj);
	showLoad(obj);
	data = "id=" + comId;	
	submitCommentNews("/delete_comment_news.php",data,blockId);
}

