
var mouse_x = 0;
var mouse_y = 0;

/* NAVIGATION */

/*
*/
function goTo(url)
{
	document.location.href = url;
}

/*
*/
function refreshWindow()
{
	document.location.href = document.location.href;
}

/*
*/
function submitForm(form_id, action)
{
	document.getElementById(form_id + "_action").value = action;
	
	document.getElementById(form_id).submit();
}


/* GUI */

/*
*/
function rescaleWindow(window_obj, document_obj, id)
{
	var height = document_obj.body.clientHeight + 100;
	
	//make window not to high
	if(height > screen.height)
		height = screen.height;
	
	window_obj.resizeTo((window.screen.width / 2), height);
}

/*
*/
function selectOption(object_id, select_value)
{
	var select_obj        = document.getElementById(object_id);
	
	var available_options = select_obj.options;
	
	for(var o = 0; o < available_options.length; o++)
	{
		if(available_options[o].value == select_value)
		{
			select_obj.selectedIndex = o;
			break;
		}
	}
}

/*
*/
function showElement(id)
{
	(document.getElementById(id)).style.display = "block";
}

/*
*/
function hideElement(id)
{
	(document.getElementById(id)).style.display = "none";
}


/* POSITIONING */

/*
*/
function getElementPosition(obj) 
{
	if(obj != null)
	{
		var curleft = curtop = 0;
		
		if (obj.offsetParent) 
		{
			curleft = obj.offsetLeft
			curtop = obj.offsetTop
			
			while (obj = obj.offsetParent) 
			{
				curleft += obj.offsetLeft
				curtop += obj.offsetTop
			}
		}
		
		return [curleft,curtop];
	}
	else
	{
		return [mouse_x, mouse_y];
	}
}

/*
*/
function getMousePosition(e) 
{
	e = e ? e : window.event;

	return [e.clientX, e.clientY];
}

/*
*/
function setMouseCoordinates(e) 
{
	e = e ? e : window.event;
	
	mouse_x = e.clientX;
	mouse_y = e.clientY;
}


/* WINDOW */

var window_clean_params  = ",directories=0,location=0,menubar=0,minimizable=0,personalbar=0,resizable=1,scrollbars=1,status=0,titlebar=0,toolbar=0";
var window_normal_params = ",directories=0,location=1,menubar=0,minimizable=0,personalbar=0,resizable=1,scrollbars=1,status=1,titlebar=0,toolbar=0";

/*
*/
function openStandardNewWindow(url, clean)
{
	openNewWindow(url, 480, 640, clean);
}

/*
*/
function openNewWindow(url, width, height, clean)
{
	window.open(url, "", "width=" + width + ",height=" + height + (clean ? window_clean_params : window_normal_params));
}

/*
*/
function openNewWindowCentered(url, width, height, clean)
{
	var left = parseInt(((screen.width)  - width)  / 2);
	var top  = parseInt(((screen.height) - height) / 2);
	
	window.open(url, "", "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + (clean ? window_clean_params : window_normal_params));
}

/*
*/
function openNewWindowFullScreen(url, clean)
{
	var left   = 0;
	var top    = 0;
	var width  = screen.width;
	var height = screen.height;
	
	window.open(url, "", "width=" + width + "px,height=" + height + "px,left=" + left + "px,top=" + top + "px" + (clean ? window_clean_params : window_normal_params));
}

/*
*/
function openANewWindow(url, params)
{
	window.open(url, "", params);
}


/* EFFECT(S) */

/*
*/
var current_opacity = -1;
var fade_element;
var fade_from;
var fade_to;
var fade_delay = 100;
var fade_step;

function fadeElement(element, from, to, total_time)
{
	fade_element    = element;
	fade_from       = from;
	fade_to         = to;
	fade_step       = parseInt((fade_to - fade_from) / (total_time / fade_delay));
	current_opacity = from;
	
	current_opacity += fade_step;

	element.style.filter  = "alpha(opacity=" + current_opacity + ")";
	
	element.style.opacity = (current_opacity / 100);

	fade();
}

/*
*/
function fade()
{
	current_opacity += fade_step;

	fade_element.style.filter  = "alpha(opacity=" + current_opacity + ")";
	
	fade_element.style.opacity = (current_opacity / 100);

	if(current_opacity > 0 && current_opacity < 100)
		setTimeout("fade();", fade_delay);
}