/** 
	Skrypty ustawiające i zapaiętujące wielkość czcionki oraz styl prezentacji strony
	@author lbenes
*/	


// Nazwa ciasteczka ze stylem strony
var style_cookie_name = 'page_style_cookie'; 
// Nazwa ciasteczka z rozmiarem czcionki
var font_cookie_name = 'page_font_size_cookie'; 

// Folder ze stylami
var css_directory = 'css'; 

// Nazwy dostępnych styli
var graphic_style = 'style.css';
var graphic_table_style = 'staktablestyle.css';
var graphic_jscalendar_style = 'jscalendar.css'
var text_style = 'text_style.css';
var text_table_style = 'text_staktablestyle.css';
var text_jscalendar_style = 'text_jscalendar.css'

//Domyślny styl strony
var defaultStyle = graphic_style;


//-----------------------------------------------------------------------------
/**
 *	Dodaje do strony wpis o stylu oraz ustawia ciasteczko jeśli nie istnieje
 */
function addStyleToPage()
{
	//bieżący styl strony
	var page_style = getCookie(style_cookie_name);
	if (page_style == null) 
	{
		page_style = defaultStyle;
		setCookie(style_cookie_name, page_style);
	}	
	
		
	//wpis z bieżącym stylem
	document.write('<link rel="stylesheet" type="text/css" href="' + css_directory + '/' + page_style + '" media="all">'); 	
	if (page_style == graphic_style)
	{
		document.write('<link rel="stylesheet" type="text/css" href="' + css_directory + '/' + graphic_table_style + '" media="all">'); 	
		document.write('<link rel="stylesheet" type="text/css" href="' + css_directory + '/' + graphic_jscalendar_style + '" media="all">'); 
		
	}
	else
	{
		document.write('<link rel="stylesheet" type="text/css" href="' + css_directory + '/' + text_table_style + '" media="all">'); 	
		document.write('<link rel="stylesheet" type="text/css" href="' + css_directory + '/' + text_jscalendar_style + '" media="all">'); 
	}
	
	//dodaj styl lokalny z wielkością czcionki w trybie tekstowym

	if(page_style == text_style)
	{
		//bieżący rozmiar czcionki
		var font_size = getCookie(font_cookie_name);
		if(font_size == null)
		{	
			font_size = 16;
			setCookie(font_cookie_name, font_size);
		}
		
		if((font_size-0)>25) font_size = 25;
		if((font_size-0)<10) font_size = 10;
		
		document.write('<style type="text/css">');
		document.write('/* <![CDATA[ */');
		document.write('	body {font-size: ' + font_size + 'px }');
		document.write('/* ]]> */');
		document.write('</style>');
	}	

}

//-----------------------------------------------------------------------------
/**
 *	Zmienia bieżący styl
 */
function switchStyle()
{
	//bieżący styl strony
	var page_style = getCookie(style_cookie_name);
	//zmień styl
	if(page_style == graphic_style)
		page_style = text_style;
	else
		page_style = graphic_style;
	//ustaw nową wartość cookie
		setCookie(style_cookie_name, page_style);
	//i odśwież
	refresh();
}
//-----------------------------------------------------------------------------
/**
 *	Zwraca czy jest ustawiony styl graficzny
 */
function isGraphicStyle()
{
	//bieżący styl strony
	var page_style = getCookie(style_cookie_name);
	//zmień styl
	if(page_style == graphic_style) return true;
	else return false;
}
//-----------------------------------------------------------------------------
/**
 *	Zwiększa font strony
 */
function increaseSize()
{
	//bieżący rozmiar czcionki
	var font_size = getCookie(font_cookie_name);
	//zwiększ czcionkę
	font_size = (font_size-0)+1;

	if(font_size < 26)
	{
		setCookie(font_cookie_name, font_size);
		refresh();
	}
}

//-----------------------------------------------------------------------------
/**
 *	Zmniejsza font strony
 */
function decreaseSize()
{
	//bieżący rozmiar czcionki
	var font_size = getCookie(font_cookie_name);
	//zwiększ czcionkę
	font_size = font_size-1;

	if(font_size > 10)
	{
		setCookie(font_cookie_name, font_size);
		refresh();
	}
}

//-----------------------------------------------------------------------------
/**
 *	Ustawia ciasteczko o podanej nazwie i wartości.
 */
function setCookie(cookie_name, cookie_value)
{
	var exDate=new Date();
	exDate.setDate(exDate.getDate()+365);
	document.cookie=cookie_name+ "=" +escape(cookie_value);
}

//-----------------------------------------------------------------------------
/**
 *	Pobiera wartość ciasteczka o podanej nazwie
 */
function getCookie(cookie_name)
{
	if (document.cookie.length>0)
	{	
		cookie_start=document.cookie.indexOf(cookie_name + "=");
		if (cookie_start!=-1)
		{ 
			cookie_start=cookie_start + cookie_name.length+1; 
			cookie_end=document.cookie.indexOf(";",cookie_start);
			if (cookie_end==-1) cookie_end=document.cookie.length;
			return unescape(document.cookie.substring(cookie_start,cookie_end));
		} 
	}
		
	return null;
}

function openModifyPopup(value) 
{
	window.open( "modyfikacja_text.html#input_text:"+value, "Modyfikacja", 'height=150, width=600, resizableno=no' );
}
function openModifyAreaPopup(value) 
{
	window.open( "modyfikacja_text.html#input_area:"+value, "Modyfikacja", 'width=600, height=300, resizableno=no');
}
function openAddModifyPopup(page) 
{
	window.open( page, "Dodawanie", 'height=300, width=600, resizable=no');
}
function openAddModifyPopupSmall(page) 
{
	window.open( page, "Dodawanie", 'height=200, width=600, resizable=no');
}
function openCommentPopup() 
{
	window.open( "zglos_uwage.html", "Modyfikacja", 'width=490, height=490, resizableno=no');
}

function windowOpen(action,title,width,height)
{
	if(window.top.childWindow == null || window.top.childWindow.closed)
	{
		window.top.childWindow = window.open(action,title,'width='+width+'px,height='+height+'px'+',menubar=no,toolbar=no,location=no,scrollbars=yes,resizable=yes,status=no');
	}
	else
	{
		window.top.childWindow.location.replace(action);
		window.top.childWindow.resizeTo(width,height);			
	}
	window.top.childWindow.focus();
}

function imageWindowOpen(action)
{
	if(window.top.childWindow == null || window.top.childWindow.closed)
	{
		window.top.childWindow = window.open(action,'Schemat','width=800px,height=600px,menubar=no,toolbar=no,location=no,scrollbars=yes,resizable=yes,status=no');
	}
	else
	{
		window.top.childWindow.location.replace(action);		
	}
	window.top.childWindow.focus();
}

function uploadWindowOpen(action, title, width, height)
{
	if(window.top.childWindow == null || window.top.childWindow.closed)
	{
		window.top.childWindow = window.open(action,title,'width='+width+'px,height='+height+'px'+',menubar=no,toolbar=no,location=no,scrollbars=no,resizable=no,status=no');
	}
	else
	{
		/*
		window.top.childWindow.location.replace(action);
		window.top.childWindow.resizeTo(width,height);
		*/
		window.top.childWindow.close();
		window.top.childWindow = window.open(action,title,'width='+width+'px,height='+height+'px'+',menubar=no,toolbar=no,location=no,scrollbars=no,resizable=no,status=no');
	}
	window.top.childWindow.focus();
}

//-----------------------------------------------------------------------------
/**
 *	Odświeża stronę po zmianie stylu
 */
function refresh()
{
	location.reload();
}

//-----------------------------------------------------------------------------
/**
 *	Odczytywanie tekstu
 */
function readText() 
{ 
	alert ("Odczytywanie nie zaimplementowane");
}

//-----------------------------------------------------------------------------
/**
 *	Niezaimplementowane
 */
function notImplemented() 
{ 
	alert ("Podstrona nie zaimplementowana.");
}
//-----------------------------------------------------------------------------
/**
 * 	Usuwanie
 */
function deleteRecord()
{
	confirm ("Czy na pewno chcesz usunąć wskazany element ?");
}
//-----------------------------------------------------------------------------


		function checkFilters(node)
		{
			var node = document.getElementById("danestandardow");			
			var re = new RegExp('\\b'+'text' + '\\b');
			var els = node.getElementsByTagName("INPUT");
			
			for(var i=0,j=els.length; i<j; i++)
			{ 
				if(els[i].type=='text') 
				{
					if(els[i].value!=null && els[i].value!= '') return true; 
				}
			}	
			
			return false;
		}

//dodaje wpis o bieżącym stylu
addStyleToPage();


