function ScreenSize() {
	if (parseInt(navigator.appVersion)>3) {
		screenW = screen.width;
		screenH = screen.height;
	} else if (navigator.appName == "Netscape" 	&& parseInt(navigator.appVersion)==3 && navigator.javaEnabled()) {
		// stare browsery
		var jToolkit = java.awt.Toolkit.getDefaultToolkit();
		var jScreenSize = jToolkit.getScreenSize();
		screenW = jScreenSize.width;
		screenH = jScreenSize.height;
	}
	
	return Array(screenW, screenH);
}



// otevření okna s kurzem
function openPopup(url) {
	
  var width = 960;
	var height = 650;
	
	// vycentrovani
	var screenSize = ScreenSize();
	var left = (screenSize[0] - width) / 2;
	var top = (screenSize[1] - height) / 2;
	
	window.open(url, 'popup', 'location=no, status=no, toolbar=no, menubar=no, resizable=yes, scrollbars=yes, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left + '');
	
	return false;
}





 function toprefswitch(pole,target,topref_current) {               
    var delka = pole.length;           
    if (topref_current[0] < (delka-1)) {
      topref_current[0]++;
    }
    else {
      topref_current[0] = 0;
    }
    //var nahodny = Math.ceil(Math.random()*delka)-1;
    document.getElementById(target).src = pole[topref_current[0]];
    return true;
 }




// z(ne)viditelneni prvku
function showElement(name1, fields, focus) {
	var obj1 = document.getElementById(name1);
	obj1.style.display = 'block';

	name1=name1+'-tb';
	var obj1 = document.getElementById(name1);
	obj1.className='tab-sel';

	// projdeme vsechny zalozky v poli ktere se maji schovat
	for (var i=0; i<fields.length; i++) {
		field_name=fields[i];
		obj=document.getElementById(field_name);

		if (obj!=null) {
			obj.style.display = 'none';

			name2=field_name+'-tb';
			var obj2 = document.getElementById(name2);
			if (obj2!=null) {
				obj2.className='';
			}
		}
	}

}





	var click_dis = false;

	function roll(item) {
		var pom;
		if (item.classNameRoll) {
			pom = item.classNameRoll;
			item.classNameRoll = item.className;
			item.className = pom;
		} else {
			item.classNameRoll = item.className;
			item.className = 'activ';
		}
	}

	function clickme(item) {
		var pom;
		if (click_dis)
		{
			click_dis = false;
			return;
		}
		if (item.className == item.classNameRoll) {
			item.classNameRoll = item.classNameClick;
			item.className = 'activ';
		} else {
			item.classNameClick = item.classNameRoll
			item.className = 'click';
			item.classNameRoll = 'click';
		}
	}

	function openPage(url, target, width, height) {
		lefti = (window.screen.width / 2) - (width / 2);
		topi = (window.screen.height / 2) - (height / 2);

		options = 'margin=5,scrollbars=yes,toolbar=0,resizable=yes,menubar=0'+(width>0&&height>0?',top=' + topi + ',left=' + lefti + ',width=' + width + ',height=' + height:'');
		win = window.open(url, target, options);
		win.focus();

		//zastaveni pripadneho probublavani
		click_dis = true;

		return (typeof(win) != 'object');
	}




	function openImage3(imgSrc) {
	    var img = new Image();
	    img.src = imgSrc;
	    width = img.width+40;
	    height = img.height+40;
	
		lefti = (window.screen.width / 2) - (width / 2);
		topi = (window.screen.height / 2) - (height / 2);

		options = 'margin=0,scrollbars=yes,toolbar=0,resizable=yes,menubar=0'+(width>0&&height>0?',top=' + topi + ',left=' + lefti + ',width=' + width + ',height=' + height:'');
		
		win = window.open(imgSrc, '', options);
		win.focus();

		//zastaveni pripadneho probublavani
		click_dis = true;

		return (typeof(win) != 'object');
	}






	function openImage2(img_href)
	{
		/*
    if (!img_href) {
			var img = this;
		}
		else {
			var img = img_href;
		}
		*/
		
		var img = this;
		
		var width  = img.width  + 10;
		var height = img.height + 10;

		var lefti = (window.screen.width / 2) - (width / 2);
		var topi = (window.screen.height / 2) - (height / 2);


		options = 'margin=0,scrollbars=yes,toolbar=0,resizable=yes,menubar=0'+(width>0&&height>0?',top=' + topi + ',left=' + lefti + ',width=' + width + ',height=' + height:'');

		html = '<html><body style="margin:0;padding:0;text-align:center;"><a href="javascript:window.close();"><img src="' + img.src + '" width="'+width+'" height="'+height+'" border="0"></a></body></html>';
		//html = '<html><body style="margin:0;padding:0;text-align:center;"><a href="javascript:window.close();"><img src="' + img.src + '" border="0"></a></body></html>';

		win = window.open('', '', options);
		win.document.write(html);
		win.focus();

		//zastaveni pripadneho probublavani
		click_dis = true;

	}


	function openImage(imgSrc) {
	    var img = new Image();
		img.onload = openImage2;
	    img.src = imgSrc;

		return false;
	}


	function validate(prvek,validate)
	{
		var errorName = 'error';
		var className = '';

		value = prvek.value;
		if (validate == 'not-empty')
		{
			if (value=='')
				className = errorName;
		}

		if (validate == 'email')
		{
			var regular = new RegExp("^[a-zA-Z][a-zA-Z0-9\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][a-zA-Z0-9\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$");
			if (!regular.test(value)) className = errorName;

		}

		if (validate.substring(0,4)=='reg:')
		{
			if (value.ereg(validate.substring(4,value.length-4))) className = errorName;
		}

		prvek.className = className;
	}


/* form pro IE */
	var itemfocus = new Array();

	function ramecek(id)
	{
		element = document.getElementById(id);
		
		element.style.borderWidth = '2px';
		element.style.borderStyle = 'solid';
		element.style.borderColor = '#007CC6';
		element.style.margin = '0px';
		
		itemfocus[id] = true;
	}
	
	function ramecekblur(id)
	{
		itemfocus[id] = false;
		ramecekout(id);	
		
	}

	function ramecekover(id)
	{
		if(!itemfocus[id])
		{
			element = document.getElementById(id);
			
			element.style.borderWidth = '2px';
			element.style.borderStyle = 'solid';
			element.style.borderColor = '#B6BF00';
			element.style.margin = '0px';
		}
	}
	
	function ramecekout(id)
	{
		if(!itemfocus[id])
		{
			element = document.getElementById(id);
			
			element.style.borderWidth = '1px';
			element.style.borderStyle = 'solid';
			element.style.borderColor = '#B6BF00';
			element.style.margin = '1px';
		}
	}



/* =================== roztahovani vizualu velky/maly ==================== */

// vyzaduje pole flashes se strukturou - generovane PHP z bacekndu podle flashovych animaci k dispozici
var flashes = new Array();
/*
flashes[1] = {'height': 167, 'file': '1183560560.upl'};
flashes[2] = {'height': 407, 'file': '1183560540.upl', 'background': 'bg-visual-flash-big.gif'};
...
*/

var activeFlash = 0;
var menuHeight = 49; // vyska boxu s menu pod animaci v px
var visualTop = 54; // horni okraj vizualu vuci strance v px

var interval = false;
var i = 0;
var fromHeight = 0;
var toHeight = 0;

// vrati element s vizualem
function getVisual() {
	return document.getElementById('visual-container');
}

// provede animovane zmenu velikosti boxu vizualu
function switchHeight(toHeight) {
	var visual = getVisual();
	
	//visual.style.border = '1px solid red';
	
	fromHeight = parseInt(visual.style.height);
	if (!fromHeight) fromHeight = flashes[activeFlash]['height'];
	
	fromHeight += menuHeight;
	toHeight += menuHeight;
	
	//alert('Puvodni vyska boxu: ' + fromHeight + ', cilova: ' + toHeight);
	
	var dir = 'up';
	if (Math.min(fromHeight, toHeight) == toHeight) dir = 'down';
	/*
	if (dir == 'up') {
		i = fromHeight; 
		interval = setInterval('addHeight()', 100);
	} else {
		i = fromHeight;
		interval = setInterval('subHeight()', 100);
	}
	*/
	
	if (dir == 'up') {
		for (var i = fromHeight; i < toHeight; i++) { 
			setTimeout('setHeight(' + i + ')', 100);
		}
	} else {
		for (var i = fromHeight; i >= toHeight-1; i--) { 
			setTimeout('setHeight(' + i + ')', 100);
		}
	}
	
	//alert('Skutecna cilova vyska boxu: ' + visual.style.height + '(i = ' + i + ', dir = ' + dir + ')');
	
	//visual.style.border = '1px solid green';
}

// zmeni obrazek na pozadi vizualu
function switchBgImage(imageFile) {
	var visual = getVisual();
	
	if (!imageFile) imageFile = 'bg-visual-flash.gif';
	
	visual.style.backgroundImage = 'url(\'../img/' + imageFile + '\')';
	visual.style.backgroundRepeat = 'no-repeat';
	visual.style.backgroundPosition = 'left bottom';
	
	return true;
}

function addHeight() {
	setHeight(i);
	i++; 
	if (i>=toHeight) {clearInterval(interval); alert('Konec roztahovani');}
}
function subHeight() {
	setHeight(i);
	i--; 
	if (i<=toHeight-1) {clearInterval(interval);  alert('Konec smrstovani');}
}

// nastavi pozadovanou vysku vizualu
function setHeight(height) {
	var visual = getVisual();
	var menu = document.getElementById('h-menu');
	
	// vypocet pozice menu
	menuTop = height + visualTop;
	
	visual.style.height = height + 'px';
	menu.style.top = menuTop + 'px';
	return true;
}

// zmeni soubor s flashem v elementu visual
function setFlashFile(flashTo) {
	var flashHolder = document.getElementById('visual');
	
	flashHolder.innerHTML = '' + 
'	<!--[if !IE]> -->' + 
'	<object type="application/x-shockwave-flash"' + 
'		data="/download.php?FNAME=' + flashTo['file'] + '&amp;ANAME=.swf" width="715" height="' + flashTo['height'] + '">' + 
'		' + 
'		<!-- <![endif]-->' + 
'		' + 
'		<!--[if IE]>' + 
'		<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' + 
'			codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"' + 
'			width="715" height="' + flashTo['height'] + '">' + 
'		<param name="movie" value="/download.php?FNAME=' + flashTo['file'] + '&amp;ANAME=.swf" />' + 
'		<!--><!---->' + 
'		<param name="loop" value="true" />' + 
'		<param name="menu" value="false" />' + 
'		' + 
'		<img src="/download.php?FNAME=1176467684.upl&amp;ANAME=bg-flash-alt.gif" alt="Flash player není nainstalovaný" title="" width="715" height="167" />' + 
'	</object>' + 
'	' + 
'	<!-- <![endif]-->' + 
		'';
		
	return true;
}

// prepne flashovou animaci na dalsi
function switchFlash() {
	/*
	if (flashes[activeFlash+1]) {
		flashTo = activeFlash+1;
	} else {
		flashTo = 0;
	}
	*/
	if (activeFlash == 0) {
		flashTo = 1;
	} else {
		flashTo = 0;
	}
	//alert('ActiveFlash: ' + activeFlash);
	
	switchHeight(flashes[flashTo]['height']);
	switchBgImage(flashes[flashTo]['background']);
	setFlashFile(flashes[flashTo]);
	
	activeFlash = flashTo;
}

// prepne flashovou animaci na vybranou
function setFlash(flashNum) {
	flashTo = flashNum;
	
	//alert('ActiveFlash: ' + activeFlash);
	
	switchBgImage(flashes[flashTo]['background']);
	switchHeight(flashes[flashTo]['height']);
	setFlashFile(flashes[flashTo]);
	
	activeFlash = flashTo;
}

