// JavaScript Document

//while loading the given html page into Microsoft.XMLDOM, we are loading the given html page in //"url" of  "makeXMLHttpRequest(url)"

//define function to call The events
//Define xmlHTTP object
var xmlHttp
function showDefault()
{

	getUrlAsync("../templates/menu.htm",replaceDivContents,"mymenu");
	getUrlAsync("../templates/left.htm",replaceDivContents,"left");
	getUrlAsync("../templates/right.htm",replaceDivContents,"right");
	getUrlAsync("../templates/footer.htm",replaceDivContents,"bottom");
	getUrlAsync("../templates/news.txt",replaceDivContents,"news");
	
}

function showHindi()
{
	
	getUrlAsync("hindiheader.htm",replaceDivContents,"header");
	getUrlAsync("hindileft.htm",replaceDivContents,"left");
	getUrlAsync("hindiright.htm",replaceDivContents,"right");
	getUrlAsync("hindifooter.htm",replaceDivContents,"bottom");
//	getUrlAsync("news.txt",replaceDivContents,"news");
}



function showAll()
{
	
	getUrlAsync("header.htm",replaceDivContents,"mymenu");
	getUrlAsync("left.htm",replaceDivContents,"left");
	getUrlAsync("right.htm",replaceDivContents,"right");
	getUrlAsync("footer.htm",replaceDivContents,"bottom");
	/*getUrlAsync("news.txt",replaceDivContents,"news");*/
}
function getXmlHttpRequest()
{
	var httpRequest = null;
	try
	{
		httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		try
		{
			httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e)
		{
			httpRequest = null;
		}
	}

	if (!httpRequest && typeof XMLHttpRequest != "undefined")
	{
		httpRequest = new XMLHttpRequest();
	}

	return httpRequest;
}
/*************GET URL***************************************/
//Wrapper for get url no call back function
function getUrlSync(url,targetdiv)
{
	return getUrl(url, false, null,targetdiv);
}
//Wrapper for get url with call back function
function getUrlAsync(url, handleStateChange,targetdiv)
{
	//alert(url+targetdiv);
	//document.getElementById(targetdiv).innerHTML=url;
	return getUrl(url, true, handleStateChange,targetdiv);
}
function replaceDivContents(xmlHttpRequest, dstDivId)
{
		if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200)
		{	
		var dstDiv = document.getElementById(dstDivId);
			dstDiv.innerHTML = xmlHttpRequest.responseText;	
			
		}
}

// call a url
function getUrl(url, async, handleStateChange,targetdiv) {
	var xmlHttpReq = getXmlHttpRequest();

	if (!xmlHttpReq)
	{
		document.getElementById(targetdiv).innerHTML='<b>Enable Javascript in your browser</b>';
		return;
	}

	if (handleStateChange)
	{
		xmlHttpReq.onreadystatechange = function()
		{
			handleStateChange(xmlHttpReq,targetdiv);
		};
	}
	else
	{
		xmlHttpReq.onreadystatechange = function() {;}
	}

	xmlHttpReq.open("GET", url, async);
	xmlHttpReq.send(null);
}
/*


END GET URL


*/

/*************POST URL***************************************/
function postUrl(url, data, async, stateChangeCallback)
{
	var xmlHttpReq = getXmlHttpRequest();

	if (!xmlHttpReq)
	return;

	xmlHttpReq.open("POST", url, async);
	xmlHttpReq.onreadystatechange = function()
	{
		stateChangeCallback(xmlHttpReq);
	};
	xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	xmlHttpReq.send(data);
	//alert ('url: ' + url + '\ndata: ' + data);
}
/*************END POST URL***************************************/

if (window.attachEvent) window.attachEvent("onload", showAll);

