
/**
 * Open window popup
 * @param string u - url
 * @param string h - height
 * @param string w - width
 */
function openpopup(u, h, w) {
	// default values for width/height
	if (h == 'undefined') h = 600;
	if (w == 'undefined') w = 600;

	// default params, no menubar, nonresizable, noscrollbars ...
	var l = 'no';
	var s = ',menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no,directories=no';

	// position popup to center of screen
	var cH = (screen.height / 2) - (h / 2);
	var cW = (screen.width / 2) - (w / 2);

	// open popup
	window.open(u, "","height="+h+",width="+w+",top="+cH+",left="+cW+",location="+l+s);

	return false;
}

/**
 * toogle style class and position of HTML element
 * @param string id - element ID
 * @param string class_name - element style classname
 * @param {Object} e - relative element to snap
 * @param string delta_x - delta x from relative element
 * @param string delta_y - delta y from relative element
 */
function toogle(id, class_name, e, delta_x, delta_y) {
	var el = document.getElementById(id);

	if (el != null) {
		// assign class name, or remove if class assigned
		if (el.className == class_name){
			el.className = '';
		} else {
			el.className = class_name;
		}

		// position element
		if (typeof(e) != 'undefined') {
			if (e.x && e.y) {
				el.style.top = e.y - delta_y;
				el.style.left = e.x - delta_x;
			}

			if (e.pageX && e.pageY) {
				el.style.top = (e.pageY - delta_y) + 'px';
				el.style.left = (e.pageX -delta_x) + 'px';
			}
		}
	}
}


/**
 * Utilities class
 *
 */
Utils = Class.create();
Object.extend(Utils.prototype, {
    
    /**
     * Reset form with timeout. Use when client click back button in opera or gchrome
     * 
     * @return void
     */
    resetFormOnload: function(f) {
        Event.observe(window, 'load', function() {
            setTimeout("$('"+f+"').reset();", 100);
        });
    }
});

