
function add_load_event(func)
{
	var old_onload = window.onload;
	if (typeof window.onload != "function")
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			if (old_onload)
			{
				old_onload();
			}

			func();
		}
	}
}

function add_header(s_src, s_charset, el_type, s_type)
{
	if (s_charset == null)
	{
		s_charset = "utf-8";
	}

	if (el_type == null)
	{
		el_type = "script";
	}

	if (s_type == null)
	{
		s_type = "text/javascript";
	}

	var script = document.createElement(el_type);
	script.type = s_type;
	script.charset = s_charset;
	script.src = s_src;

	document.getElementsByTagName("head")[0].appendChild(script);
}

function set_confirm_button(b_id, c_text)
{
	var confirm_button = document.getElementById(b_id);
	if (confirm_button)
	{
		confirm_button.onclick = function ()
		{
			if (!confirm(c_text))
			{
				return false;
			}
			else
			{
				var mhidden = document.createElement("input");
				mhidden.type = "hidden";
				mhidden.name = "co";
				mhidden.value = "1";

				confirm_button.parentNode.appendChild(mhidden);
			}
		};
	}
}

function set_confirm_links(list_id, link_class, c_text)
{
	var list_cont = document.getElementById(list_id);
	if (list_cont)
	{
		var list_links = list_cont.getElementsByTagName("a");
		var num_links = list_links.length;

		if (num_links > 0)
		{
			for (var i = 0; i < num_links; i++)
			{
				if (list_links[i].className == link_class)
				{
					list_links[i].onclick = function ()
					{
						if (confirm(c_text))
						{
							this.href += "&co=1";
						}
						else
						{
							return false;
						}
					};
				}
			}
		}
	}
}

function add_option(the_select, the_text, the_value)
{
  var opt_new = document.createElement("option");
  opt_new.value = the_value;
  opt_new.text = the_text;
  try
  {
    the_select.add(opt_new, null);
  }
  catch(ex)
  {
    the_select.add(opt_new);
  }
}

function remove_options(the_select)
{
	var count = the_select.options.length;
	for (var i = count; i >= 0; i--)
	{
		the_select.remove(i);
	}
}
