

function getLeft(element) {
	xPos = element.offsetLeft;
	tempElement = element.offsetParent;
	
	while (tempElement != null) {
		xPos += tempElement.offsetLeft;
		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 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";
}



createFCK = function(a, div, textareaId, height, toolbarset)
{
	div.removeChild(a);
	textarea = element('textareaId');

	var oFCKeditor = new FCKeditor(textareaId) ;
	oFCKeditor.BasePath	= '/_includes/FCKeditor/';
	oFCKeditor.Height = height ;
	oFCKeditor.ToolbarSet = toolbarset;
	oFCKeditor.ReplaceTextarea() ;
}



function updateFCK()
{
	for ( i = 0; i < parent.frames.length; ++i )
	if ( parent.frames[i].FCK )
		parent.frames[i].FCK.UpdateLinkedField();
}





showErrorMessage = function(errors)
{
	str = '';

	for (i=0; i<errors.length; i++)
		str += '- ' + errors[i] + '<br />';

	Modalbox.alert(str);
}


showMessage = function(response)
{
	if (response.redirect)
		afterHide = function() { location.href = response.redirect };
	else if (response.reload)
		afterHide = function() { location.reload() };
	else
		afterHide = function() {};
	
	Modalbox.alert(response.message, afterHide);
}



var ImageSlideShow = Class.create();

ImageSlideShow.prototype = {

	initialize: function(id, n, count) {
		this.id = id;
		this.selected = n;
		this.count = count;

//		$$('#imageSlideShow_' + this.id + ' .imageSlideShow_window')[0].style.height = $('imageSlideShow_images_' + this.id).getHeight() + 'px';
		
		this.showImage(this.selected);
	},
	
	
	showImage: function(n)
	{
		try {
			$('imageSlideShow_' + this.id + '_number_' + this.selected).removeClassName('on');
		}
		catch(e) {}

		this.selected = n;
		x = -1 * (n-1) * 300;
		duration = 0.2;
		new Effect.Move ('imageSlideShow_images_' + this.id, {x: x, y:0, mode:'absolute', duration: duration});

		$('imageSlideShow_' + this.id + '_number_' + this.selected).addClassName('on');
	}
}



/*
var MyWin = Class.create();

MyWin.prototype = {

	initialize: function(obj) {

		this.id = Math.round(Math.random()*1000000);

		winWidth = obj.width;
		winHeight = obj.height;
		title = obj.title;

		scrollWidth = $$('body')[0].getWidth();
		scrollHeight = $$('body')[0].getHeight();

		wpWidth = document.viewport.getWidth();
		wpHeight = document.viewport.getHeight();

		xOffset = document.viewport.getScrollOffsets()[0];
		yOffset = document.viewport.getScrollOffsets()[1];

		overlay = document.createElement('div');
		overlay.id = 'mywin_overlay_' + this.id;
		overlay.className = 'overlay';
		overlay.style.width = scrollWidth + 'px'
		overlay.style.height = scrollHeight + 'px'
		document.body.appendChild(overlay);

		win = document.createElement('div');
		win.className = 'mywin';
		if (winWidth > wpWidth - 100 || winWidth == 'max')
			winWidth = wpWidth - 100;
		if (winHeight > wpWidth - 50 || winHeight == 'max')
			winHeight = wpHeight - 50;
		winLeft = Math.round((wpWidth - winWidth) / 2) + xOffset;
		winTop = Math.round((wpHeight - winHeight) / 2) + yOffset;
		win.style.width = winWidth + 'px'
		win.style.height = winHeight + 'px'
		win.style.top = winTop + 'px'
		win.style.left = winLeft + 'px'
		win.id = 'mywin_' + this.id;

		if (title)
		{
			h2 = document.createElement('h2');
			h2.innerHTML = title;
			win.appendChild(h2);

			close2 = document.createElement('div');
			close2.className = 'close';
			
			closea = document.createElement('a');
//			closea.onclick = function(){ alert(1) };
			closea.innerHTML = 'Bez&aacute;r&aacute;s';
//			close2.appendChild(closea);

			win.appendChild(close2);
		}

		content = document.createElement('div');
		content.innerHTML = 'Hello';
		content.className = 'content';
		content.id = 'content_' + this.id;

		win.appendChild(content);
		document.body.appendChild(win);

		if (obj.ajaxURL)
		{
			new Ajax.Request(obj.ajaxURL, {
				onComplete: function(ajax){
				}
			});
		}

	},
	
	
	close: function()
	{
		$('mywin_overlay_' + this.id).remove();
		$('mywin_' + this.id).remove();
	},


	hide: function()
	{
		$('mywin_overlay_' + this.id).hide();
		$('mywin_' + this.id).hide();
	},


	show: function()
	{
		$('mywin_overlay_' + this.id).show();
		$('mywin_' + this.id).show();
	}

}
*/
