function ajax_popup_close() {
	$('#popup_backdrop').fadeOut(function() { $(this).remove(); });
	$('#popup_foreground').fadeOut(function() { $(this).remove(); });
}
function ajax_popup_open(content) {
	if ($('#popup_backdrop').size())
		return;
	$('body').append('<div id="popup_backdrop"></div><div id="popup_foreground"></div>');
	$('#popup_foreground').html(content);
	$('#popup_backdrop').fadeTo('normal', 0.4);
	$('#popup_foreground').fadeTo('normal', 1);
}

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
function $() {
  var elements = new Array();
  for (var i=0; i<arguments.length; i++) {
	  var element = arguments[i];
	  if (typeof element=='string')
		  element = document.getElementById(element);
	  if (arguments.length==1)
		  return element;
	  elements.push(element);
  }
  return elements;
}
function toggle_display(id,callback) {
	object = $(id);
	status = true;
	if (object.style.display == 'none') {
		object.style.display = '';
		status = false;
	}	else {
		object.style.display = 'none';
	}
	if (typeof(callback) != 'undefined')
		callback(status);
}
function opacity(id, start, end, millisec) {
  var speed = Math.round(millisec / 100);
  var timer = 0;
  if (start > end) {
  	for(i = start; i >= end; i--) {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer++ * speed));
    }
  } else if(start < end) {
    for(i = start; i <= end; i++) {
      setTimeout("changeOpac(" + i + ",'" + id + "')",(timer++ * speed));
    }
  }
}
function changeOpac(opacity, id) {
  var object = document.getElementById(id).style;
  object.opacity = (opacity / 100);
  object.MozOpacity = (opacity / 100);
  object.KhtmlOpacity = (opacity / 100);
  object.filter = "alpha(opacity=" + opacity + ")";
	if (opacity > 0)
  	object.display = '';
  else
  	object.display = 'none';    
} 
function resize(id, new_width, new_height, millisec) {
	var object = $(id);
	speed = Math.round(millisec / 100);
	w = object.offsetWidth;
	h = object.offsetHeight;
	w_diff = (new_width-w)/100;
	h_diff = (new_height-h)/100;
	for (i=0; i<100; i++) {
		if (new_width == null)
			new_w = -1;
		else
			new_w = Math.floor(w+(w_diff*i));
		if (new_height == null)
			new_h = -1;
		else
			new_h = Math.floor(h+(h_diff*i));
		setTimeout('changeSize(\'' + id + '\',' + new_w + ',' + new_h + ')', i*speed);
	}
}
function changeSize(id, new_width, new_height) {
	var object = $(id);
	if (new_width != -1)
		object.style.width = new_width + 'px';
	if (new_height != -1)
		object.style.height = new_height + 'px';
}
function chr(code) {
	return String.fromCharCode(code);
}

