
function newwin(url, width, height, winname)
{
	wleft = (screen.width - width) / 2;
	wtop = (screen.height - height) / 2 - 10;
	resizable = (arguments[4] == true) ? 1 : 0;
	props = 'toolbar=0,location=0,directories=0,hotkeys=0,status=0,menubar=0,scrollbars=' + resizable + ',resizable=' + resizable + ',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 getTop(element) {
	yPos = element.offsetTop;
	tempElement = element.offsetParent;
	
	while (tempElement != null) {
		yPos += tempElement.offsetTop;
		tempElement = tempElement.offsetParent;
	}
	
	return yPos;
} 


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 updateFCK()
{
	for ( i = 0; i < parent.frames.length; ++i )
	if ( parent.frames[i].FCK )
		parent.frames[i].FCK.UpdateLinkedField();
}




createFCK = function(a, div, textareaId, height, toolbarset)
{
	div.removeChild(a);
	textarea = $('textareaId');

	var oFCKeditor = new FCKeditor(textareaId) ;
	oFCKeditor.BasePath	= '/_includes/FCKeditor/';
	oFCKeditor.Height = height ;
	oFCKeditor.ToolbarSet = toolbarset;
	oFCKeditor.ReplaceTextarea() ;
}



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);
}


Event.observe(window, 'load', function(){

	$$('.innewwin').each(function(element){
		element.onclick = function(){return false};
		element.observe('click', function(){
			width = 700;
			height = screen.height - 200;
			wleft = (screen.width - width) / 2;
			wtop = 50;
			resizable = 1;
			props = 'toolbar=0,location=0,directories=0,hotkeys=0,status=0,menubar=0,scrollbars=' + resizable + ',resizable=' + resizable + ',copyhistory=0,left=' + wleft  + ',top=' + wtop + ',width=' + width + ',height=' + height;
			winname = 'newwin';
			var uj_b_ablak = window.open(element.href, winname, props);
			uj_b_ablak.focus();
		});
	});

	$$('.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))
	});

	$$('a.ajaxURL').each(function(element){
		element.onclick = function(){return false};
		element.observe('click', function(){
			//ajax_submitForm(element.href);
			alert(element.href);
		});
	});

});



displayInfoBox = function(anchor)
{
	anchor = $(anchor);
	anchorH = anchor.getHeight();
	
	offsetX = anchor.cumulativeOffset()[0];
	offsetY = anchor.cumulativeOffset()[1];
	var dv = new Element('div', { 'class': 'divOnClick' });

	new Ajax.Request(anchor.href, {
		onComplete: function(ajax) {
			dv.update(ajax.responseText);
			document.body.appendChild(dv);

			dvH = dv.getHeight();
			dvW = dv.getWidth();

			if (offsetX + dvW > document.viewport.getWidth() - 10)
				dvX = document.viewport.getWidth() - dvW - 10;
			else
				dvX = offsetX;

			dvY = offsetY;

			dv.setStyle({
				left: dvX + 'px',
				top: dvY + 'px', 
				visibility: 'visible'
			});
	
			dv.observe('click', function(){
				setTimeout(function(){
					this.hide();
				}.bind(this), 200); 
			}.bind(dv));
		}
	});
}

