function $(id)
{
	return document.getElementById(id);
}

function getOption(sel)
{
	return $(sel).options[$(sel).selectedIndex].value;
}

function setCookie(name, value, expiration)
{
	var exp = new Date();
	exp.setDate(exp.getDate() + expiration);
	document.cookie = name + "=" + value + ((expiration == null) ? "" : ";expires=" + exp.toGMTString());
}

function getCookie(name)
{
	if (document.cookie.length > 0)
	{
		var start = document.cookie.indexOf(name + "=");
		if (start != -1)
		{
			start = start + name.length + 1;
			var end = document.cookie.indexOf(";", start);
			if (end == -1)
				end = document.cookie.length;
			return document.cookie.substring(start, end);
		}	
	}
	return "";
}

function sendAjax(type, page, query, async, target)
{
	if (typeof(target) == "string")
		$(target).innerHTML = "<p style='text-align: center;'><img src='images/ajax-loader.gif' alt='Loading...' /></p>";

	var xmlHttp;
	try
	{
		xmlHttp = new XMLHttpRequest();
	}
	catch (e)
	{
		try
		{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX. You must upgrade to use this site.");
				return false;
			}
		}
	}
	if (query != "")
		query += "&sid=" + new Date().getTime();
		
	xmlHttp.open(type, page + "?" + query, async);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4)
		{
			if (!async && target == "return")
				return xmlHttp.responseText;
			
			if (typeof(target) == 'string')
				document.getElementById(target).innerHTML = xmlHttp.responseText;
			else if (typeof(target) == 'function')
				target(xmlHttp.responseText);
			else if (target)
				target.innerHTML = xmlHttp.responseText;
		}
	};
	
	if (type == "get")
		xmlHttp.send(null);
	else
		xmlHttp.send(query);
}

function makePopup(event, cName, offsetX, offsetY)
{
	var div = document.createElement("div");
	div.style.position = "absolute";
	document.body.appendChild(div);
	if (cName)
		div.className = cName;
	
	var posX = 0;
	var posY = 0;
	if (event.pageX && event.pageY)
	{
		posX = event.pageX;
		posY = event.pageY;
	}
	else if (event.clientX && event.clientY)
	{
		posX = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posY = event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	
	if (!offsetX)
		offsetX = 0;
	if (!offsetY)
		offsetY = 0;
		
	div.style.left = posX + offsetX + "px";
	div.style.top = posY + offsetY + "px";
	
	return div;
}

function closePopup(div)
{
	document.body.removeChild(div);
}

function PopupCalendar(textbox)
{
	this.textbox = textbox;
	this.id = "Popup" + textbox;
}

PopupCalendar.prototype.open = function(event)
{
	this.div = makePopup(event, "popup_calendar", 0, 0);
	this.div.innerHTML = this.getHTML();
}

PopupCalendar.prototype.getHTML = function()
{
	var date = $(this.textbox).value;
	var year = date.substring(0, 4);
	var month = date.substring(5, 7);
	var day = date.substring(8);
	if (date == "" || date == "any")
	{
	
	}
	
	
}

var continuePopup = false;

function popupMenu(id)
{
	$(id).style.display = "";
	continuePopup = true;
}

var popupTimer = null;

function popoutMenu(id)
{
	continuePopup = false;
	popupTimer = setTimeout(function()
						{
							if (!continuePopup)
								$(id).style.display = "none";
						}, 1000);
}

function extendPopup()
{
	continuePopup = true;
	if (popupTimer != null)
		clearTimeout(popupTimer);
}