/* CSST 48 - FG Forrest a.s. */

// IE - fix blikajicich backgroundu 
eval("try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}");  

// object handler
function obj(id) {
	return document.getElementById(id);
}

// JS window

function getCenterW(width) {
	return parseInt( eval( (screen.availWidth-parseInt(width))/2 ) );
}

function getCenterH(height) {
	return parseInt( eval( (screen.availHeight-parseInt(height))/2 ) );
}

function openWin( path, name, width, height ) {
	var win = window.open(path, name,'scrollbars=no,resizable=no,resize=no,width='+width+',height='+height+',screenX='+getCenterW(width)+',screenY='+getCenterH(height)+',top='+getCenterH(height)+',left='+getCenterW(width) );
	win.focus();
	return win;
} 

function openWinScroll( path, name, width, height ) {
	var win = window.open(path, name,'scrollbars=yes,resizable=no,resize=no,width='+width+',height='+height+',screenX='+getCenterW(width)+',screenY='+getCenterH(height)+',top='+getCenterH(height)+',left='+getCenterW(width) );
	win.focus();
	return win;
} 

function OpenHintPop( path ) {
	openWinScroll(path, "hint", 450, 240);
}
/*function newImg(imgsrc,imgname,w,h) {
	var newWindow = newWin('', 'newImg', w, h);
	newWindow.document.open();
	newWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n');
	newWindow.document.write('<html>\n');
	newWindow.document.write('	<head>\n');
	newWindow.document.write('		<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">\n');
	newWindow.document.write('		<meta name="Author" content="FG Forrest - Creative Technologies, www.fg.cz, fg@fg.cz, 1996-2007">\n');
	newWindow.document.write('		<meta name="Description" content="">\n');
	newWindow.document.write('		<meta name="keywords" content="">\n');
	newWindow.document.write('		<style type="text/css">\n');
	newWindow.document.write('			@import "/css/u/imgdetail.css";\n');
	newWindow.document.write('		</style>\n');
	newWindow.document.write('		<title>'+imgname+'</title>\n');
	newWindow.document.write('	</head>\n');
	newWindow.document.write('	<body>\n');
	newWindow.document.write('		<img src="'+imgsrc+'" width="'+w+'" height="'+h+'" border="0" title="[kliknutím zavřít]" alt="'+imgname+'" onclick="window.close();">\n');
	newWindow.document.write('	</body>\n');
	newWindow.document.write('</html>\n');
	newWindow.document.close();
	newWindow.focus();
}*/

/*************/
/* bookmarks */
/*************/
function menuItem( title, url )	{
	this.title = title;
	this.url = url;
	
	this.tag = function( domain )	{
		//return "<div><a href=\"http://"+domain+url+"\">"+title+"</div>";
		return "<li><a href=\"http://"+domain+url+"\">"+title+"</a></li>";
	}
}
// get bookmark function .. definition replaced by personalize
var hasBookmarks = false;

function bookmarkStructure() { return [ ]; } 

function writeBookmarks( manageUrl, domain )	{
	
	var bookmarkArray = bookmarkStructure();
	
	if ( bookmarkArray && bookmarkArray.length>0 )	{
		document.writeln("<div id=\"bookmarksCont\">\n");
		document.writeln("<span class=\"separator\"></span>\n");
		document.writeln("<ul>\n");
		for (i=0;i<bookmarkArray.length;i++)	{
			document.writeln(bookmarkArray[i].tag(domain));
		}
		document.writeln("</ul>\n");
		document.writeln("<span class=\"separator\"></span>\n");
		document.writeln("<a href=\""+manageUrl+"\" class=\"ico edit\">úprava záložek</a>\n");
		document.writeln("</div>\n");
	 	hasBookmarks = true;
	} else {
		obj("bookmarksBtn").className += " disabled";
		obj("bookmarksBtn").style.background = "none";
	}
}

var bookmarksOpened = false;
function toggleBM() {
	if (!hasBookmarks) return;
	if (!bookmarksOpened) {
		obj("bookmarksCont").style.display = "block";
		obj("bookmarksBtn").innerHTML = "skrýt";
		obj("bookmarksBtn").style.backgroundPosition = "5px -94px";
		bookmarksOpened = true;
	} else {
		obj("bookmarksCont").style.display = "none";
		obj("bookmarksBtn").innerHTML = "zobrazit";
		obj("bookmarksBtn").style.backgroundPosition = "5px 6px";
		bookmarksOpened = false;
	}
}

function initLogin(username, auto) {
	var loc = document.location;

	if (username == "") {
		document.write('<p id="login" class="fr">\n');
			document.write('<a href="http://'+loc.hostname+'/srv/www/user/status.do" class="icoKey">Přihlásit</a><span> | </span>\n');
			document.write('<a href="http://'+loc.hostname+'/cs/mapa-stranek.shtml" class="icoSitemap">Mapa stránek</a><br>\n');
		document.write('</p>\n');
	}
	
	else {
		var logged = auto ? "Automaticky přihlášen" : "Přihlášen";
		document.write('<p id="login" class="fr">\n');
			document.write(logged+': <a href="http://'+loc.hostname+'/srv/www/user/settings.do"><strong>'+username+'</strong></a><span> | </span>\n');
			document.write('<a href="http://'+loc.hostname+'/cs/mapa-stranek.shtml" class="icoSitemap">Mapa stránek</a><br>\n');
		document.write('</p>\n');
	}
}

/** Toggles text field with specified id if checkbox with specified id is checked. */
function toggleTextFieldWithId(checkBoxId,fieldId)
{
	var elm = document.getElementById(checkBoxId)
	toggleTextField(elm, fieldId);
}

function toggleTextField(checkBox,fieldId)
{
	var elm = document.getElementById(fieldId)
	if (elm==null) return;
	if (checkBox.checked)
	{
		elm.disabled = false;
		elm.className = "text";
	} else {
		elm.className = "text inactive";
		elm.disabled = true;
	}
}

/** Gets spaced number with the "dot" delimiter. */
function getNumberSpaced(inp, maxLength) {
	var formaterLength = 3;
	var result = inp;

	// get non spaced char array
	inp += ''; // get string
	inp = inp.replace(/\.+/g, '');
	inp = inp.replace(/[^0-9\.]/,'');

	if (inp.length>maxLength)
	{
		inp = inp.substr(1, inp.length);			
	}
	var inpArr = inp.split("");
	inpArr.reverse();

	// make spaced string
	result = "";
	var y = 1;
	for (i = 0; i < (inpArr.length); i++) {
		result = inpArr[i] + result;
		if (y == formaterLength&&(i<inpArr.length-1)) {
			y = 0;
			result = "." + result;
		}
		y++;
	}
	return result;
}

