﻿function dynamicContent()
{
	getHttpRequest('inc/images-ASSERPRESS.xml', '', null);
}
if (window.addEventListener)
	window.addEventListener("load", dynamicContent, false);
else if (window.attachEvent)
	window.attachEvent("onload", dynamicContent);

function getHttpRequest(url, container, param, json)
{
	var httpRequest = false;
	if(typeof(json) == 'undefined')
	{
		json = false;
	}

	if (window.XMLHttpRequest) 
	{
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) 
		{
			if (json)
			{
				httpRequest.overrideMimeType('application/json');
			}
			else
			{
				httpRequest.overrideMimeType('text/xml');
			}
		}
	}
	else if (window.ActiveXObject) 
	{
		try 
		{
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch (e)
		{
			try
			{
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) 
			{
			}
		}
	}

	if (!httpRequest)
	{
		alert('Unfortunatelly you browser doesn\'t support this feature.');
		return false;
	}

	httpRequest.onreadystatechange = function()
	{
		if (httpRequest.readyState == 4)
		{
			if (httpRequest.status == 200 || httpRequest.status == 0) 
			{
				document.getElementById("visual-img-holder").innerHTML = "";
				
				if(window.ActiveXObject)
				{
					var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
					xmlDoc.loadXML(httpRequest.responseText);
				}
				else
					var xmlDoc = httpRequest.responseXML;
				
				var items = xmlDoc.getElementsByTagName("item");
				var _random = Math.floor(Math.random() * items.length);
				document.getElementById("visual-img-holder").innerHTML = "<img  src='" + xmlDoc.getElementsByTagName("path")[_random].childNodes[0].nodeValue + "' alt='" + xmlDoc.getElementsByTagName("alt")[_random].childNodes[0].nodeValue  + "' />";
				document.getElementById("logoHold").href = xmlDoc.getElementsByTagName("logohref")[_random].childNodes[0].nodeValue
				document.getElementById("logoHold").innerHTML = "<img  src='" + xmlDoc.getElementsByTagName("logopath")[_random].childNodes[0].nodeValue + "' alt='" + xmlDoc.getElementsByTagName("logoalt")[_random].childNodes[0].nodeValue  + "' />";
			}
		}
	}

	if(param == undefined || param == null)
	{
		httpRequest.open('GET', url, true);
		httpRequest.send(null);
	}
	else
	{
		httpRequest.open('POST', url, true);
		httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		httpRequest.setRequestHeader("Content-length", param.length);
		httpRequest.setRequestHeader("Connection", "close");
		httpRequest.send(param);
	}
}
