var save_message;

function showOverlayOfSorts(open_url)
{	
	var div_overlay  = $('overlay_of_sorts');
	div_overlay.style.display = 'block';
	div_overlay.style.position = 'absolute';
	div_overlay.style.left = '0';
	div_overlay.style.top = '0';
	
	if ( document.viewport.getWidth()<$('mainHolder').getWidth() )
		div_overlay.style.width = $('mainHolder').getWidth()+'px';
	else
		div_overlay.style.width = document.viewport.getWidth()+'px';
		
	if ( document.viewport.getHeight()<$('mainHolder').getHeight() )
		div_overlay.style.height = $('mainHolder').getHeight()+'px';
	else
		div_overlay.style.height = document.viewport.getHeight()+'px';
		
	div_overlay.style.backgroundColor = '#000000';
	div_overlay.style.opacity = '0.5';
	div_overlay.style.filter = 'alpha(opacity=50)';
	div_overlay.observe('click', stopOverlayOfSorts);
	
	new Ajax.Updater(document.body, open_url, {method: 'get', evalScripts: true, insertion: Insertion.Bottom});
}
		
function stopOverlayOfSorts(event)
{
	el = $('overlay_of_sorts_screen');
	if ( el!=null )
		el.parentNode.removeChild(el);
	
	$('overlay_of_sorts').style.display = 'none';
	$('overlay_of_sorts').stopObserving('click');
	$('overlay_of_sorts').innerHTML = '';
}

function doSave()
{
	if ( save_message!=null )
	{
		if ( confirm(save_message) )
			document.forms[0].submit();
	}
	else
	{
		document.forms[0].submit();
	}
}

function popupWindow(url, width, height)
{
	if ( url==null )
		return;
	if ( width==null )
		width = 800; // width in px
	if ( height==null )
		height = 600; // height in px
		
	var chasm = screen.availWidth;
	var mount = screen.availHeight;
		
	var print_window = window.open(url,"print_window","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width="+width+", height="+height+",left="+((chasm - width - 10) * .5)+",top="+((mount - height - 30) * .5));
	if ( print_window!=false )
		print_window.focus();
}

function popupWindowNormal(url, width, height)
{
	if ( url==null )
		return;
	if ( width==null )
		width = 800; // width in px
	if ( height==null )
		height = 600; // height in px
		
	var chasm = screen.availWidth;
	var mount = screen.availHeight;
		
	var print_window = window.open(url,"print_window","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=yes, width="+width+", height="+height+",left="+((chasm - width - 10) * .5)+",top="+((mount - height - 30) * .5));
	if ( print_window!=false )
		print_window.focus();
}

function goTo(url)
{
	document.location.href=url;
}

function selectAll(el_id, to_checked_state)
{
	el = $(el_id);
	if ( el==null )
		return;
		
	for (i=0;i<el.length;i++)
		el.options[i].selected = to_checked_state;
}


function setCookie(c_name,value,expiredays, path)
{
	var exdate=new Date();
	exdate.setDate( exdate.getDate() + expiredays );
	
	var string = c_name + "=" +escape(value);
	string = string + ((expiredays==null) ? "" : ";expires="+exdate);
	string = string + ((path==null) ? ";path=/" : ";path="+path);

	document.cookie=string;
}


function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{ 
			c_start = c_start + c_name.length+1 ;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end==-1) 
				c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return null;
}


function unCheckOther(el)
{
	var frmElements;
	
	frmElements = el.form.getElements();
	
	frmElements.each(function(item) {
	  if ( item.name==el.name && item.value!=el.value )
	  	item.checked = false;
	});
}