

	function GetXmlHttpObject(){
		var xmlHttp=null;
		
		try { //Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e) {
			try {//Internet Explorer
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e) {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
		
		return xmlHttp;
	}
	

	var http_request = false;
		   
	function makePOSTRequest(url, parameters) {
		
		http_request = GetXmlHttpObject()

		if(http_request == null) {
			alert('Cannot create XMLHTTP instance');
			return false;
		}

		http_request.onreadystatechange = alertContents;
		http_request.open('POST', url, true);
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
		http_request.setRequestHeader("Content-length", parameters.length);
		http_request.setRequestHeader("Connection", "close");
		http_request.send(parameters);
	}

	function alertContents() {
		
		if (http_request.readyState == 0 || http_request.readyState == 1 || http_request.readyState == 2 || http_request.readyState == 3) {
			document.getElementById("videoComments").innerHTML='<div id="loading"><img src="images/loading.gif" /></div>';
		}
		
		if(http_request.readyState ==4) {
			
			if(http_request.status ==200) {
				
				var xmldoc = http_request.responseXML;
					    
				var status = xmldoc.getElementsByTagName("status");
				
				var response_text = xmldoc.getElementsByTagName("response_text");
				
									
				if(status[0].firstChild.nodeValue == 'posted') {
					document.getElementById('add-comment-error').style.display = 'none';
					document.getElementById('commentFormDiv').innerHTML = '<p>Сэтгэгдэл амжилттай нэмэгдлээ.</p>';
					document.getElementById('videoComments').innerHTML = response_text[0].firstChild.nodeValue;
				}
				else {
					var error = xmldoc.getElementsByTagName("error");
					document.getElementById('add-comment-error').style.display = 'block';
					document.getElementById('add-comment-error').innerHTML = error[0].firstChild.nodeValue;
					document.getElementById('videoComments').innerHTML = response_text[0].firstChild.nodeValue;
				}
			}
			else {
				document.getElementById('add-comment-error').innerHTML = 'Алдаа гарлаа дахин оролдоно уу.';
			}
		}
	}

	function bjFunVideoPostComment(content_id, comment_type, comment_text) {
		
		var poststr =	'_cc_id=' + content_id +
						'&_cc_type=' + comment_type +
						'&_c_text=' + encodeURI(comment_text);
						
		
		var url = 'includes/ajax/comment_poster.php';
		//var url = 'http://localhost/bjn/fun/includes/ajax/comment_poster.php';
		
		makePOSTRequest(url, poststr);
		
	}
	
