
function newwin(url, width, height, winname)
{
	wleft = (screen.width - width) / 2;
	wtop = (screen.height - height) / 2 - 10;
	props = 'toolbar=0,location=0,directories=0,hotkeys=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,left=' + wleft  + ',top=' + wtop + ',width=' + width + ',height=' + height;
	var uj_b_ablak = window.open(url, winname, props);
	uj_b_ablak.focus();
}


function getLeft(element) {
	xPos = element.offsetLeft;
	tempElement = element.offsetParent;
	
	while (tempElement != null) {
		xPos += tempElement.offsetLeft;
		tempElement = tempElement.offsetParent;
	}
	
	return xPos;
} 


function getRight(element) {
	xPos = element.offsetRight;
	tempElement = element.offsetParent;
	
	while (tempElement != null) {
		xPos += tempElement.offsetRight;
		tempElement = tempElement.offsetParent;
	}
	
	return xPos;
} 


function getTop(element) {
	yPos = element.offsetTop;
	tempElement = element.offsetParent;
	
	while (tempElement != null) {
		yPos += tempElement.offsetTop;
		tempElement = tempElement.offsetParent;
	}
	
	return yPos;
} 


function element(objectID) {
	return document.getElementById ? document.getElementById(objectID) : document.all[objectID];
}



function copyInputData()
{
	for (var i=0; i<arguments.length; i+=2)
		$(arguments[i+1]).value = $(arguments[i]).value;
}



function setcookie(name, value, expires, path, domain, secure) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime(today.getTime());

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if (expires)
	{
		expires = expires * 1000 * 60;
	}
	var expires_date = new Date(today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


function getcookie(name) 
{
	var start = document.cookie.indexOf(name + "=");
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length)))
	{
		return null;
	}
	if (start == -1) return null;
	var end = document.cookie.indexOf(";", len);
	if (end == -1) end = document.cookie.length;
	return unescape( document.cookie.substring(len, end));
}



function deletecookie(name, path, domain) 
{
	if (getcookie(name)) 
		document.cookie = name + "=" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}



function toggle(divname)
{
	var display = element(divname).style.display;
	
	element(divname).style.display = (display == 'none') ? 'block' : 'none';
}



function selectVariant(n)
{
	if (currentlySelectedVariant != null)
		$('variant_' + currentlySelectedVariant).className = '';
	$('variant_' + n).className = 'on';

	currentlySelectedVariant = n;
	
	$('variantIndex').value = currentlySelectedVariant;
	
}


/*

var FloatingDiv = Class.create();

FloatingDiv.prototype = {
	
	initialize: function(width, height)
	{
		this.id = Math.round(1000000 * Math.random());
		this.width  = width;
		this.height = height;
		
		div = document.createElement('div');
		div.style.width = this.width + 'px';
		div.style.height = this.height + 'px';
		div.style.backgroundColor = '#f0f0f0';
		div.style.border = '1px solid red';
		div.style.position = 'absolute';
		div.style.left = '0px';
		div.style.top = '0px';
		div.innerHTML = 'HELLO';
		div.id = 'fd' + this.id;
		document.body.appendChild(div);
	}, 
	
	close: function()
	{
		$('fd' + this.id).remove();
	}

};



*/


/*
var mydiv = function(id, left, top, width, height, title)
{
	if (!$(id))
	{
		this.id = id;
		this.left = left;
		this.top = top;
		this.width = width;
		this.height = height;
		this.title = title;
	
		this.createDiv();
	}
}


mydiv.prototype.createDiv = function()
{
	var div = document.createElement('div');
	div.id = this.id;
	div.className = 'mydiv';
	div.style.top = this.top + 'px';
	div.style.left = this.left + 'px';
	div.style.width = this.width + 'px';
	div.style.minHeight = this.height + 'px';

	if (this.title)
	{
		title = document.createElement('h2');
		title.id = this.id + '_h2';
		title.innerHTML = this.title;
		div.appendChild(title);
	
		span_close = document.createElement('span');
		span_close.className = 'close';
		span_close.innerHTML = "<a onclick=\"document.body.removeChild(document.getElementById('" + div.id + "'))\">[bezárás]</a>";
		div.appendChild(span_close);
	}

	contentDiv = document.createElement('div');
	contentDiv.id = this.id + "_content";
	contentDiv.innerHTML = 'Betöltés...';
	div.appendChild(contentDiv);

	document.body.appendChild(div);

	new Draggable(this.id, {handle:this.id+'_h2'});

	this.div = div;
	this.contentDiv = contentDiv;
}


mydiv.prototype.close = function()
{
	try
	{
		document.body.removeChild(this.div);
	}
	catch(e)
	{
		alert(e);
	}
}


*/



showErrorMessage = function(errors)
{
	str = '';
	for (i=0; i<errors.length; i++)
		str += errors[i] + '\n';

	alert(str);
}


showMessage = function(message, redirect)
{
	alert(message);
	
	if (redirect)
		location.href = redirect;
}






Event.observe(window, 'load', function(){

	$$('.defaultValue').each(function(element){
		element.defaultValue = element.value;
		element.observe('blur', function(){
			if (!this.value)
				this.value = this.defaultValue;
		}.bind(element))
	
		element.observe('focus', function(){
			if (this.value == this.defaultValue)
				this.value = '';
		}.bind(element))
	});

});

