﻿var xmlHttp;

function getNews(id){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) { 
		alert("Browser does not support HTTP Request");
		return;
	}
	xmlHttp.onreadystatechange=getNewsStateChanged;
	xmlHttp.open("GET","?sub=ajax&func=getNews&id="+id+"&sid="+Math.random(),true);
	xmlHttp.send(null);
}

function previewNews(time, topic, text){
	//topic = addslashes(topic);
	//text = addslashes(text);
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) { 
		alert("Browser does not support HTTP Request");
		return;
	}
	xmlHttp.onreadystatechange=previewNewsStateChanged;
	xmlHttp.open("GET","?sub=ajax&func=previewNews&time="+time+"&topic="+encodeURIComponent(topic)+"&text="+encodeURIComponent(text)+"&sid="+Math.random(),true);
	xmlHttp.send(null);
}

function getNewsStateChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			document.getElementById("getNews").innerHTML=xmlHttp.responseText;
	}
}

function previewNewsStateChanged(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
			document.getElementById("previewNews").innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject(){
	var xmlHttp=null;
	try{
	 // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e){
		//Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e){
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}