//**********************************************************************
// Common Startup Functionality
//**********************************************************************
$(function ()
{
	// remove chrome's stying of autofill boxes
	if (navigator.userAgent.toLowerCase().indexOf("chrome") >= 0)
	{
		$("input:-webkit-autofill").each(function ()
		{
			var text = $(this).val();
			var name = $(this).attr('name');
			$(this).after(this.outerHTML).remove();
			$('input[name=' + name + ']').val(text);
		});
	}
});

//**********************************************************************
// Control Support Functions
//**********************************************************************   
function hideFinishBox(id, delay)
{
	var box = $("#" + id);
	if (box.length == 0) return;

	// if another action was scheduled, clear it
	if (box.data("timeout") != null) window.clearTimeout(box.data("timeout"));

	// send it off to be hidden after the delay
	var timeout = window.setTimeout("hideFinishBoxEnd('" + id + "');", delay);
	box.data("timeout", timeout);
}

function hideFinishBoxEnd(id)
{
	var box = $("#" + id);
	if (box.length == 0) return;

	box.data("timeout", null);
	box.slideUp("fast");
}

//**********************************************************************
// Cookie Functions
//**********************************************************************   

// store info on cookie. 
function setCookie(name, value, days)
{
	var expire = new Date();
	expire.setTime(expire.getTime() + (24 * 60 * 60 * 1000) * days);
	document.cookie = name + "=" + escape(value) + "; expires=" + expire.toGMTString();
}

// retrieve info on cookie. 
function getCookie(name)
{
	var startIndex = document.cookie.indexOf(name);
	if (startIndex != -1)
	{
		var endIndex = document.cookie.indexOf(";", startIndex);
		if (endIndex == -1) endIndex = document.cookie.length;
		return unescape(document.cookie.substring(startIndex + name.length + 1, endIndex));
	}
	else
	{
		return null;
	}
}

// delete info on cookie. 
function deleteCookie(name)
{
	var expire = new Date();
	expire.setTime(expire.getTime() - (24 * 60 * 60 * 1000));
	document.cookie = name + "=; expires=" + expire.toGMTString();
}

