// aktualne otvorene okno
var _popname = null;
// zdrojove okno
var _source = null;
var height = 0;
var width = 0;
var language = 'en';

function setposition(){
	var x=0;
	x=x+1;
}

/*
 * workaround for IE to set max-width: style property to 80% this is hook
 * function call from CSS width property
 */
function calculateMaxWidth(obj, k){
	var parentWidth = obj.offsetParent.clientWidth;
	var width = obj.offsetWidth;
	var maxWidth = Math.min(width, parentWidth*k);
	return maxWidth;
}

function child_iframe_resize() {
	// koli IE6 ????
	// return;
	if (_popname) {
		var popup = document.getElementById(_popname);
		var width = popup.clientWidth;
		var height = popup.clientHeight;
		var iframe = popup.getElementsByTagName("iframe")[0];
		if (iframe) {
			iframe.style.width = width;
			iframe.style.height = height;
		}
	}
}

function action(popname, source) {
	_source = source;
	_popname = popname;
	if (source != null) {
		document.getElementById(source).style.visibility = "hidden";
	}

	if (document.body.className == "color") {
		document.body.className = "gray";
		document.getElementById("popup_frame").style.visibility = "visible";
		document.getElementById("main_menu").style.visibility = "hidden";
		document.getElementById("colsel").style.visibility = "hidden";
	}

	window.onresize = child_iframe_resize;

	document.getElementById(popname).style.visibility = "visible";
	var popup = document.getElementById(popname);
	child_iframe_resize();
	var okno;
	okno = document.getElementById('gmap');
	if (popname == "gmap") {
		okno.getElementsByTagName('iframe')[0].src = "http://maps.google.com/maps?f=q&source=s_q&hl="+language+"&geocode=&q=Bubensk%C3%A1+47+170+00+Praha+7&sll=50.106515,14.435563&sspn=0.006661,0.017831&ie=UTF8&hq=&hnear=Bubensk%C3%A1+113%2F47,+170+00+Praha+7-Hole%C5%A1ovice,+Czech+Republic&view=map&ll=50.106515,14.435563&spn=0.026417,0.054932&z=14&iwloc=A&output=embed";
	}
	
	okno = document.getElementById('welcome');
	if (popname == "welcome") {
		//okno.getElementsByTagName('iframe')[0].src = "common/welcome.php"; 
		//okno.getElementsByTagName('iframe')[0].src = "common/welcome_galery/welcome.php";
		okno.getElementsByTagName('iframe')[0].contentWindow.location.reload(true);
	}
	
	okno = document.getElementById('eumetsat');
	if (popname == "eumetsat") {
		
		//okno.getElementsByTagName('iframe')[0].contentWindow.location = "eumetsat/eumetsat_page.php";
		okno.getElementsByTagName('iframe')[0].contentWindow.location.reload(true);
		
	}
	okno = document.getElementById('range');
	if (popname == "range") {
		
		//okno.getElementsByTagName('iframe')[0].contentWindow.location = "eumetsat/eumetsat_page.php";
		okno.getElementsByTagName('iframe')[0].contentWindow.location.reload(true);
		
	}
	okno = document.getElementById('foto');
	if (popname == "foto") {
		
		//okno.getElementsByTagName('iframe')[0].contentWindow.location = "eumetsat/eumetsat_page.php";
		okno.getElementsByTagName('iframe')[0].contentWindow.location.reload(true);
		
	}
}

function pop_close() { // 10/02/2010
	try {
		document.getElementById(_popname).style.visibility = "hidden";

		var okno;
		okno = document.getElementById('gmap');
		if (_popname == "gmap") {
			okno.getElementsByTagName('iframe')[0].src = "wait.html";// "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Bubensk%C3%A1+47+170+00+Praha+7&sll=50.106515,14.435563&sspn=0.006661,0.017831&ie=UTF8&hq=&hnear=Bubensk%C3%A1+113%2F47,+170+00+Praha+7-Hole%C5%A1ovice,+Czech+Republic&view=map&ll=50.106515,14.435563&spn=0.026417,0.054932&z=14&iwloc=A&output=embed";
		}
		/*
		okno = document.getElementById('welcome');
		if (_popname == "welcome") {
			okno.getElementsByTagName('iframe')[0].src = "wait.html";// "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Bubensk%C3%A1+47+170+00+Praha+7&sll=50.106515,14.435563&sspn=0.006661,0.017831&ie=UTF8&hq=&hnear=Bubensk%C3%A1+113%2F47,+170+00+Praha+7-Hole%C5%A1ovice,+Czech+Republic&view=map&ll=50.106515,14.435563&spn=0.026417,0.054932&z=14&iwloc=A&output=embed";
		}
		
		if (_popname == "eumetsat") {
			//okno.getElementsByTagName('iframe')[0].src = "wait.html";// "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=Bubensk%C3%A1+47+170+00+Praha+7&sll=50.106515,14.435563&sspn=0.006661,0.017831&ie=UTF8&hq=&hnear=Bubensk%C3%A1+113%2F47,+170+00+Praha+7-Hole%C5%A1ovice,+Czech+Republic&view=map&ll=50.106515,14.435563&spn=0.026417,0.054932&z=14&iwloc=A&output=embed";
			okno.getElementsByTagName('iframe')[0].contentWindow.location = "wait.html";
			okno.getElementsByTagName('iframe')[0].contentWindow.location.reload(true);
		}
		*/
		if (_source == null) {
			document.body.className = "color";
			document.getElementById("popup_frame").style.visibility = "hidden";
			document.getElementById("main_menu").style.visibility = "visible";
			document.getElementById("colsel").style.visibility = "visible";
		} else {
			_popname = _source;
			child_iframe_resize();
			document.getElementById(_popname).style.visibility = "visible";
			_source = null;
		}
	} catch (e) {
		// TODO: handle exception
	}
}

function cc(_class, element, value) {

	// Last Updated on June 23, 2009
	// documentation for this script at
	// http://www.shawnolson.net/a/503/altering-css-class-attributes-with-javascript.html
	var cssRules;

	var added = false;
	for ( var S = 0; S < document.styleSheets.length; S++) {

		if (document.styleSheets[S]['rules']) {
			cssRules = 'rules';
		} else if (document.styleSheets[S]['cssRules']) {
			cssRules = 'cssRules';
		} else {
			// no rules found... browser unknown
		}

		for ( var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
			if (document.styleSheets[S][cssRules][R].selectorText == _class) {
				if (document.styleSheets[S][cssRules][R].style[element]) {
					document.styleSheets[S][cssRules][R].style[element] = value;
					added = true;
					break;
				}
			}
		}
		if (!added) {
			if (document.styleSheets[S].insertRule) {
				document.styleSheets[S].insertRule(_class + ' { ' + element
						+ ': ' + value + '; }',
						document.styleSheets[S][cssRules].length);
			} else if (document.styleSheets[S].addRule) {
				document.styleSheets[S].addRule(_class, element + ': '
						+ value + ';');
			}
		}
	}
}



function setimgsrc(src, id){
	var img = document.getElementById(id);
	if( img ){
		img.src = src;
	}
}
function showpdf(id){
	var img = document.getElementById(id);
	if( img ){
		var src = img.src;
		if( src ){
			src = src.replace('.png', '.pdf');
			window.open(src, '_new');
		}
	}
}
