
	var gNewsURL = "/ajax/fetch_news_items.php";
	var gPatchURL = "/ajax/fetch_patch_notes.php";
	//var gPatchURL2 = "/ajax/fetch_patch_notes2.php";


	var retryCount = 0;
	var requestTimeout;

	//var static_host = '';
	var static_host = 'http://www.bloodlinechampions.com/';
	//var static_host = 'http://static.bloodlinechampions.com/';

	function handleFetchNewsItems()
	{
		switch (http.readyState)
		{
			case 4:		// The request is complete.

				clearTimeout(requestTimeout); 

				if (200 == http.status)
				{
					try
					{
						var htmlText = http.responseText;
						var div = document.getElementById('promo_div_content_left');
						div.innerHTML = htmlText;
						document.getElementById('status').innerHTML = '';
					}
					catch (e)
					{
						document.getElementById('status').innerHTML = 'Something went wrong ...';
					}
				}
	
				retryCount = 0;
				isWorking = false;
	
				break;

			default:
				break;
		}
	}

	function handleFetchPatchNotes_()
	{
		switch (http.readyState)
		{
			case 4:		// The request is complete.

				clearTimeout(requestTimeout); 

				if (200 == http.status)
				{
					try
					{
						var htmlText = http.responseText;
						var div = document.getElementById('promo_div_content_left');
						div.innerHTML = htmlText;
						document.getElementById('status').innerHTML = '';
					}
					catch (e)
					{
						document.getElementById('status').innerHTML = 'Something went wrong ...';
					}
				}

				retryCount = 0;
				isWorking = false;

				break;

			default:
				break;
		}
	}


	function handleNewsItemsTimeout()
	{
		http.abort();
		isWorking = false;
		document.getElementById('status').innerHTML = 'Request timed out. Trying again ... ('+(++retryCount)+')';
		fetchNewsItems();
	}

	function handlePatchNotesTimeout()
	{
		http.abort();
		isWorking = false;
		document.getElementById('status').innerHTML = 'Request timed out. Trying again ... ('+(++retryCount)+')';
		fetchPatchNotes();
	}


	function fetchNewsItems_(start)
	{
		if (!isWorking && http)
		{
			var btn_news = document.getElementById('btn_news');
			btn_news.src = static_host+'web_images/buttons/newsitems_down.png';

			var btn_patch = document.getElementById('btn_patch');
			btn_patch.src = static_host+'web_images/buttons/patchnotes_up.png';

			var count = 10;
			var fields = new Array();
			fields.push("count="+count);
			fields.push("start="+start);

			var sendf = fields.join('&');

			http.open("POST", gNewsURL, true);
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.onreadystatechange = handleFetchNewsItems;
			http.send(sendf);

			requestTimeout = setTimeout(handleNewsItemsTimeout, 5000);

			var status = document.getElementById('status');
			status.innerHTML = 'Fetching news items ...';

			isWorking = true;
		}
	}

	function fetchPatchNotes_()
	{
		if (!isWorking && http)
		{
			var btn_patch = document.getElementById('btn_patch');
			btn_patch.src = static_host+'web_images/buttons/patchnotes_down.png';

			var btn_news = document.getElementById('btn_news');
			btn_news.src = static_host+'web_images/buttons/newsitems_up.png';

			var count = 10;
			var fields = new Array();
			fields.push("count="+count);

			var sendf = fields.join('&');

			http.open("POST", gPatchURL, true);
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.onreadystatechange = handleFetchPatchNotes;
			http.send(sendf);

			requestTimeout = setTimeout(handlePatchNotesTimeout, 5000);

			var status = document.getElementById('status');
			status.innerHTML = 'Fetching patch notes ...';

			isWorking = true;
		}
	}











	function handleFetchPatchNotes()
	{
		//alert('State: '+http.readyState);
		//document.getElementById('status').innerHTML = 'State: '+http.readyState;
		switch (http.readyState)
		{
			case 4:		// The request is complete.

				//clearTimeout(requestTimeout); 
				document.getElementById('status').innerHTML = 'Status: '+http.status;
				if (200 == http.status)
				{
					try
					{
						var htmlText = http.responseText;
						var div = document.getElementById('promo_div_content_left');
						div.innerHTML = htmlText;
						document.getElementById('status').innerHTML = '';
					}
					catch (e)
					{
						document.getElementById('status').innerHTML = 'Something went wrong ...';
					}
				}

				retryCount = 0;
				isWorking = false;

				break;

			default:
				//document.getElementById('status').innerHTML = 'State: '+http.readyState;
				break;
		}
	}

	function fetchPatchNotes__(start)
	{
		if (!isWorking && http)
		{
			var btn_patch = document.getElementById('btn_patch');
			btn_patch.src = static_host+'web_images/buttons/patchnotes_down.png';

			var btn_news = document.getElementById('btn_news');
			btn_news.src = static_host+'web_images/buttons/newsitems_up.png';

			var count = 10;
			var fields = new Array();
			fields.push("count="+count);
			fields.push("start="+start);

			var sendf = fields.join('&');

			http.open("POST", gPatchURL, true);
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.onreadystatechange = handleFetchPatchNotes;
			http.send(sendf);

			//requestTimeout = setTimeout(handlePatchNotesTimeout, 5000);

			var status = document.getElementById('status');
			status.innerHTML = 'Fetching patch notes ...';

			isWorking = true;
		}
	}

