// JavaScript Document
var xmlHttp = false;

function init()
{
try{
	xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
	try{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){
		xmlHttp = false;
	}
}
if(!xmlHttp && typeof XMLHttpRequest != 'undefined')
{
	xmlHttp = new XMLHttpRequest();
}
}

function makePageRequest(serverPage,objID)
{

	init();
	var obj = document.getElementById(objID);
	xmlHttp.open("GET",serverPage);
	obj.innerHTML = "<div id=\"loading\">Loading...</div>";
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState==4 && xmlHttp.status == 200)
		{
			obj.innerHTML = xmlHttp.responseText;
		}
	};
	xmlHttp.send(null);
}

function saveNews(objIDx,objIDy,objIDz,update,modifier)
{
	if(modifier!=-2)
	{
	init();
	var serverPage = "add_news.php?h="+document.getElementById(objIDx).value+"&b="+document.getElementById(objIDy).value+"&u="+update+"&i="+modifier;
	xmlHttp.open("GET",serverPage);
	document.getElementById(objIDz).innerHTML = "Performing Request.....";
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState==4 && xmlHttp.status == 200)
		{
			if(xmlHttp.responseText == "y")
			{
				alert('The news was updated successfully !');
				makePageRequest('manage-news.php','inner');
			}
			else{
				document.getElementById(objIDz).innerHTML = xmlHttp.responseText;
				document.getElementById(objIDx).value="";
				document.getElementById(objIDy).value="";
			}
		}
	};
	xmlHttp.send(null);
	}else{
		alert('Invalid News to Edit !');
	}
	
}

function editNews(objVal,objID)
{
	if(confirm('Are you sure to Edit the news?'))
	{
		init();
		var serverPage = "edit-news.php?i="+objVal;
		document.getElementById(objID).innerHTML = "<div id=\"loading\">Loading...</div>";
		xmlHttp.open("GET",serverPage);
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState==4 && xmlHttp.status == 200)
			{
				document.getElementById(objID).innerHTML = xmlHttp.responseText;
			}
		};
		xmlHttp.send(null);
	}
}

function deleteNews(objVal,objID)
{
	if(confirm('Are you sure to delete the news?'))
	{
		init();
		var serverPage = "del_news.php?i="+objVal;
		document.getElementById(objID).innerHTML = "Please wait while news being deleted......";
		xmlHttp.open("GET",serverPage);
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState==4 && xmlHttp.status == 200)
			{
				if(xmlHttp.responseText=="y"){
				alert('The news was deleted successfully !');
				makePageRequest('manage-news.php','inner');
				}else{
					document.getElementById(objID).innerHTML = xmlHttp.responseText;
				}
			}
		};
		xmlHttp.send(null);
	}
}