//UTF8 string: ěščřžýáíéů

function ChangePicture(obrazek,novy)
{
	document.images[obrazek].src=novy.src;
}

function GetElement(name)
{
	if (window.self.document.getElementById)
		return window.self.document.getElementById(name);
	else if (window.self.document.all)
		return window.self.document.all[name];
	else if (window.self.document.layers)
		return window.self.document.layers[name];
}

function GetStyle(name)
{
	var elem;
	
	if(window.self.document.getElementById || window.self.document.all)
	{
		elem = GetElement(name);
		if (elem != null)
			return elem.style;
		else
			return "";
	}
	else if(window.self.document.layers)
		return window.self.document.layers[name];
}

function open_win(url,name,win_width,win_height)
{
    var x = screen.width/2 - win_width/2;
    var y = screen.height/2 - win_height/2;
    if (x <= 0) x = 20;
    if (y <= 0) y = 20;
	var myRef = window.open(url,name,'left='+x+',top='+y+',width='+win_width+',height='+win_height+',toolbar=no,resizable=yes,status=no,scrollbars=no');
	myRef.focus();
}

//------------------------------------------------------
// MAIL GENERATION FOR ROBOTS
//

function robophobicMail(roboText, linkText)
{
	roboHref = unescape("%6d%61%69%6c%74%6f%3a") + roboText;
	document.write('<a href="" onClick="this.href=\'' + roboHref + 
		'\'" onMouseOver="window.status=\'' + roboHref + '\'; return true" ' + 
		'onMouseOut="window.status=window.defaultStatus">' + linkText + '</a>');
}

function robophobicMail2(roboText)
{
	robophobicMail(roboText, roboText);
}

function composeM(user, domain)
{
	return user + unescape("%" + "40") + domain;
}

//------------------------------------------------------
// USERBOX HANDLING
//

//UTF8 string: ěščřžýáíéů
// params: event, af ID, 0: do not change checked 1: change checked
// uses CountInBox variable set in main script
function ToBoxClicked(e, id, changeChecked)
{
	var checkbox = GetElement('tobox'+id);
	var ok=true;

	if (changeChecked == 1)
		checkbox.checked = !checkbox.checked;
	
	var url=loc+'adds/userbox.php?id='+id+'&change=';
	if (checkbox.checked)
	{
		if (CountInBox>=10) //10==$GLOBALS['Nastaveni']['MaxAFCountInBox']
		{
			if (lang=='cz')
				alert('Ve schránce můžete mít maximálně 10 ubytovacích zařízení.');
			else
				alert('You can only have 10 accommodation facilities in the box.');
			ok=false;
		}
		else
		{		
			url=url+'add';
			CountInBox++;
		}
	}
	else
	{
		url=url+'delete';
		CountInBox--;
	}
	
	if (ok)
	{
		GetElement('numberinbox').innerHTML='('+CountInBox+')';
		var win=window.open(url,'userboxchange','left=1,top=1,width=20,height=20,toolbar=no,resizable=no,status=no');
	}
	else
	{
		if (changeChecked == 1)
			checkbox.checked = !checkbox.checked;
	}
}

function ShowToBoxCheckboxes()
{
	var i;
	var el=document.getElementsByName('toboxdiv');
	for (i=0; i<el.length; i++)
		el[i].style.visibility='visible';
}

//------------------------------------------------------
// GETTING WINDOW SIZE AND SCROLLING
//

function GetWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [ myWidth, myHeight ];
}

function GetScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

//------------------------------------------------------
// MOVING ELEMENTS TO THE CENTER
//

function FloatElementCenterInternal(id, lastWidth, lastHeight, lastScrollX, lastScrollY)
{
	var size = GetWindowSize();
	var width = size[0];
	var height = size[1];
	
	var scroll = GetScrollXY();
	var scrollX = scroll[0];
	var scrollY = scroll[1];
	
	if (width != lastWidth || height != lastHeight || scrollX != lastScrollX || scrollY != lastScrollY)
	{
		var el = GetElement('global-popup-info');
		var st = GetStyle('global-popup-info');
		
		var el_width = 250;
		if (el.offsetWidth) el_width = el.offsetWidth;
		var el_height = 100;
		if (el.offsetHeight) el_height = el.offsetHeight;
	
		st.left = ( (width - el_width) / 2 + scrollX )+'px';
		st.top = ( (height - el_height) / 2 + scrollY )+'px';
	}

	setTimeout('FloatElementCenterInternal(\''+id+'\','+width+','+height+','+scrollX+','+scrollY+')',100);
}

function FloatElementCenter(id)
{
	FloatElementCenterInternal(id, 0, 0, 0, 0);
}

//------------------------------------------------------
// GLOBAL POPUP
//

function ShowGlobalPopup(text, progress)
{
	var st = GetStyle('global-popup-info');

	GetElement('global-popup-info-text').innerHTML = text;

	if (progress)
		GetStyle('global-popup-info-progress').visibility = 'visible';
	else
		GetStyle('global-popup-info-progress').visibility = 'hidden';

	FloatElementCenter('global-popup-info');	
	st.visibility = 'visible';
}

function HideGlobalPopup()
{
	GetStyle('global-popup-info').visibility = 'hidden';
}

//------------------------------------------------------
// FAVORITES
//

// http://interval.cz/clanky/umoznete-pridat-stranku-k-oblibenym-odkazum/
function AddFavorite(linkObj, addUrl, addTitle)
{
	if (document.all && !window.opera)
	{
		window.external.AddFavorite(addUrl,addTitle);
		return false;
	}
	else if (window.opera && window.print)
	{
		linkObj.title = addTitle;
		return true;
	}
//	else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))
//	{
//		if (window.confirm('Přidat oblíbenou stránku jako nový panel?'))
//		{
//			window.sidebar.addPanel(addTitle,addUrl,'');
//			return false;
//		}
//	}
	window.alert('Po potvrzení stiskněte CTRL-D,\nstránka bude přidána k vašim oblíbeným odkazům.');
	return false;
}


