if (!window.XMLHttpRequest && window.ActiveXObject)
	window.XMLHttpRequest = function ()
	{
		return new ActiveXObject(navigator.userAgent.indexOf("MSIE 5") != -1 ? "Microsoft.XMLHTTP" : "MSXML2.XMLHTTP");
	};

function http_get(uri, cb, fail)
{
	if (!fail)
		fail = function (reason)
		{
		}
	if (!window.XMLHttpRequest)
		fail(false);

	var request = new XMLHttpRequest();
	request.open("GET", uri);

	request.onreadystatechange = function ()
	{
		if (request.readyState != 4)
			return;

		if (request.status == 200)
			cb(request);
		else
			fail(request);
	}

	request.send(null);
}

function http_post(uri, data, cb, fail)
{
	if (!fail)
		fail = function (reason)
		{
		}
	if (!window.XMLHttpRequest)
		fail(false);

	var request = new XMLHttpRequest();

	request.open("POST", uri);
	if (typeof(request.setRequestHeader) != "undefined")
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

	request.onreadystatechange = function ()
	{
		if (request.readyState != 4)
			return;

		if (request.status == 200)
			cb(request);
		else
			fail(request);
	}

	request.send(data);
}

function xml_text_content(node)
{
	if (node.nodeType == 3)
		return node.nodeValue;

	var val = "";

	for (var i = 0; i < node.childNodes.length; i++)
	{
		if (node.childNodes[i].nodeType == 3)
			val += node.childNodes[i].nodeValue;
		else if (node.childNodes[i].nodeType == 1)
			val += xml_text_content(node.childNodes[i]);
	}

	return val;
}

function xml_first_child(xml, name)
{
	for (var i = 0; i < xml.childNodes.length; i++)
	{
		if (xml.childNodes[i].nodeName == name)
			return xml.childNodes[i];
	}

	return false;
}

function xml_find_children(xml, name)
{
	var list = [];

	for (var i = 0; i < xml.childNodes.length; i++)
	{
		if (xml.childNodes[i].nodeName == name)
			list[list.length] = xml.childNodes[i];
	}

	return list;
}

function html_escape(text)
{
	text = text.replace(/"/g, '&quot;');
	text = text.replace(/&/g, '&amp;');
	text = text.replace(/</g, '&lt;');
	text = text.replace(/>/g, '&gt;');

	return text;
}

function event_queue(type, f)
{
	obj_event_queue(window, type, f);
}

function obj_event_queue(o, type, f)
{
	var typeQueue = type + "Queue";

	if (typeof(o[typeQueue]) == "undefined")
	{
		o[typeQueue] = [];
		if (o[type])
			obj_event_queue(o, type, o[type]);

		o[type] = function()
		{
			for (var i = o[typeQueue].length - 1; i >= 0; i--)
			{
				o.eventQueueCurrent = o[typeQueue][i];
				if (o.eventQueueCurrent)
					o.eventQueueCurrent();
			}

			delete o.eventQueueCurrent;
		}
	}

	o[typeQueue][o[typeQueue].length] = f;
}

window.set_opacity = function (el, f)
{
	if (typeof(el.style.MozOpacity) != "undefined")
		return el.style.MozOpacity = f;
	else if (typeof(el.style.KhtmlOpacity) != "undefined")
		return el.style.KhtmlOpacity = f;
	else if (typeof(el.style.filter) != "undefined")
		return el.style.filter = "alpha(opacity=" + Math.round(f * 100) + ");"
	else
		return el.style.opacity = f;
}

window.get_opacity = function (el)
{
	if (typeof(el.style.MozOpacity) != "undefined")
		return el.style.MozOpacity;
	else if (typeof(el.style.KhtmlOpacity) != "undefined")
		return el.style.KhtmlOpacity;
	else if (typeof(el.filters) != "undefined" && typeof(el.filters.alpha) != "undefined")
		return el.filters.alpha.opacity / 100;
	else if (typeof(el.style.opacity) != "undefined")
		return el.style.opacity;
	else
		return "";
}

function openPressPDF(id)
{
	var w = window.open(site_url + "/press-pdfs/" + id + ".pdf", "pdf", 'resizable=yes,scrollbars=yes');

	if (w)
		w.focus();
}

function openClientAccess()
{
	var w = window.open(site_url + "/uploads.html", "client_access", "height=356,width=700,scrollbars=no,resizable=no");

	if (w)
		w.focus();
}

function openOtherServices()
{
	var w = window.open(site_url + "/other-services.html", "other_services");

	if (w)
		w.focus();
}

function openQuicktime(href)
{
	var w = window.open(site_url + "/empty.html", "video", "height=260,width=364,scrollbars=no,resizable=no");

	if (w)
	{
		try
		{
			w.focus();

			w.document.open();
			w.document.write('\
<html>\
	<head>\
		<title>Quicktime Video</title>\
		<link rel="stylesheet" type="text/css" href="' + site_url + '/default/css/index.css" />\
	</head>\
	<body style="background: black !important;">\
		<div id="video-container"></div>\
	</body>\
</html>\
		');
			w.document.close();

			function finish()
			{
				writeQuickTime("video-container", href, w.document);
			}

			window.setTimeout(finish, 0);
		}
		catch (e)
		{
			return false;
		}
	}

	return false;
}

function writeQuickTime(el_id, video, doc)
{
	if (!doc)
		doc = document;

	doc.getElementById(el_id).innerHTML = '<embed id="popup-video" src="' + video + '" width="360" height="256" autoplay="true" controller="true" loop="false" bgcolor="000000" enablejavascript="true" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/indext.html"></embed>';
}