// globalni nastaveni napovedy //
var globalShowHelp = true;

function odkaz( kam, jmeno )
{
	var test = false;
	var odd = "?";
	
	var oddTst = kam.indexOf( "?" );
	if( oddTst > 0 ) odd = "&";
	
	test = ( ! window.open( kam+odd+"setShowerHelp="+globalShowHelp, jmeno ) );
	return test;
}


function novyokno( kam )
{
	return odkaz( kam, '' );
}



function novyoknobez( kam, sirka, vyska )
{
	var test = false;
	vyska = vyska * 1 + 20;
	
	test = ( ! window.open( kam, '_blank', 'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0,width='+sirka+',height='+vyska+',left=100,top=100' ) );
	return test;
}

function SetAsHomepage(){

	try{
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage('http://www.vira.cz');
	} catch(Exception) {
		alert('Váš prohlížeč nepodporuje automatické nastavení této funkce.');
  	}
  return false;
}


// napoveda //
function showHelp( txt )
{
	if( globalShowHelp == true && window.top.obsah ) window.top.obsah.showHelpInFrame( txt );
}

function setGlobalShowHelp( val )
{
	globalShowHelp = val;
	window.top.nadmenu.globalShowHelp = val;
	window.top.menu.globalShowHelp = val;
	window.top.hlavicka.globalShowHelp = val;
	window.top.obsah.globalShowHelp = val;
}


function showHelpInFrame( txt )
{
	if( globalShowHelp == true ) 
	{
		var f;
		
		if( f = getObj( "id-div-help" ) )
		{
			f.innerHTML = txt;
			f.style.display = '';
		}
	}
}


function hideHelp()
{
	if(window.top.obsah) window.top.obsah.hideHelpInFrame();
}


function hideHelpInFrame()
{
	var f;
	
	if( f = getObj( "id-div-help" ) )
	{
		f.innerHTML = '';
		f.style.display = 'none';
	}
}


// filemanager block //
var objectIDForFile = '';
var gInsertObjectIsImage = false;
var urlPrefix = '';

function showFileManager( idReturnObject, insertObjectIsImage, urlPref )
{
	 objectIDForFile = idReturnObject; 
	 
	 if( insertObjectIsImage != true ) insertObjectIsImage = false;
	 gInsertObjectIsImage = insertObjectIsImage;
	 
	 if( !urlPref ) urlPref = '';
	 urlPrefix = urlPref;
	 
	 window.open( '/admin/FileManager/index.php', 'filemanager', 'toolbar=0,location=0,directories=0,menuBar=0,scrollbars=yes,resizable=1,width=780,height=475,left=100,top=100' );
}

function loadFileFromFilemanager( file )
{
	var o;
	var out;
	if( o = getObj( objectIDForFile ) )
	{
		out = file;
		if( gInsertObjectIsImage == true ) out = '<img src="' + file + '" border="0" class="img" />';
			else out = urlPrefix + out;
		
		o.value = out;
		var img = objectIDForFile.replace( "Txt", "IMG" );
		if( o = getObj( img ) )
		{
			out = globalROOT+file;
			if( gInsertObjectIsImage == true ) out = '<img src="' + globalROOT + file + '" border="0" class="img" />';
			
			if( o.src ) o.src = out;
		}
		
		//alert( typeof( OnUrlChange ) );
		if( typeof( OnUrlChange ) == "function" ) OnUrlChange();
		if( typeof( UpdatePreview ) == "function" ) UpdatePreview();
	}
	
	window.focus();
}

function setDisplay( obj, test )
{
	var dis = '';
	if( test != false ) 
	{
		test = true;
		dis = "none";
	}
	
	var o;
	o = getObj( obj )
	
	if( o != false )
	{
		o.style.display = dis;
	}
}


//************ FUNKCE PRO PRACI SE SELEKTEM ***************************************//
function selectSelOpt( obj, val )			
{	
	if( obj == null ) return cnt;
	
	for( var i = 0; i < obj.options.length; i++ )		
	{	
		if( obj.options[i].value == val )
		{
			obj.options[i].selected = true;
			break;
		}	
	}	
}

function selectDeleteOpt( obj )			
{	
	if( obj == null ) return cnt;
	
	for( var i = 0; i < obj.options.length; i++ )		
	{	
		if( obj.options[i].selected == true ) obj.options[i]=null;	
	}	
}
  	
function selectAddOpt( obj, value, text )  
{	
	if( obj == null ) return cnt;
	
	var no = new Option();	
		no.value = value;    
		no.text = text; 
	
	obj.options[obj.options.length] = no; 
}

// hleda shodu podle hodnoty value //
function selectExistsOpt( box, val )
{
	if( box == null ) return true;
	if( box.options == null ) return false;
	if( box.options.length == null ) return false;
	
	for( var i = 0; i < box.options.length; i++ )  	
	{ 
		if( box.options[i].value == val )
		{	
			return true;
			break;
		}    
	}	
	
	return false;
}


function selectCountOpt( box )
{
	var cnt = 0;
	
	if( box == null ) return cnt;
	if( box.options == null ) return cnt;
	if( box.options.length == null ) return cnt;
	
	for( var i = 0; i < box.options.length; i++ )  	
	{ 
		cnt++;  
	}	
	
	return cnt;
}

function selectMove( fbox, tbox )  
{	
	if( fbox == null ) return false;
	if( tbox == null ) return false;
	if( fbox.options == null ) return false;
	if( fbox.options.length == null ) return false;
	
	for( var i=0; i < fbox.options.length; i++ )  	
	{  
		if( fbox.options[i].selected && fbox.options[i].value != "" )  
		{   
			if( fbox.options[i].value == "0" ) continue;	
			
			if( selectExistsOpt( tbox, fbox.options[i].value ) == false )
			{
				var no = new Option();	
				no.value = fbox.options[i].value;    
				no.text = fbox.options[i].text; 
				tbox.options[tbox.options.length] = no; 
			}
		} 
	} 
}


function selectClear( box ) 
{ 	
	if( box == null ) return false;
	if( box.options == null ) return false;
	if( box.options.length == null ) return false;
	
	for( var i=0; i < box.options.length; i++ )  	
	{ 
		box.options[i]=null;	
		i--;    
	}	
}


function selectMove2( box ) 
{ 	
	if( box == null ) return false;
	if( box.options == null ) return false;
	if( box.options.length == null ) return false;
	
	for( var i=0; i < box.options.length; i++ )  	
	{ 
		if( box.options[i].selected && box.options[i].value != "" )  
		{	
			box.options[i]=null;	
			i--; 
		}   
	}	
}


function selectFind( box )  		
{ 	
	if( box == null ) return false;
	if( box.options == null ) return false;
	if( box.options.length == null ) return false;
	
	for( i=0; i < box.options.length; i++ )
	{		
		box.options[i].selected = true;
	} 
}


function selectUnFind( box )  		
{ 	
	if( box == null ) return false;
	if( box.options == null ) return false;
	if( box.options.length == null ) return false;
	
	for( i=0; i < box.options.length; i++ )
	{		
		box.options[i].selected = '';
	} 
}


function selectReturnOptionsAsString( box, odd )
{
	if( odd == null ) odd = ",";
	
	var out = "";
	var tmpodd = "";
	
	if( box == null ) return false;
	if( box.options == null ) return false;
	if( box.options.length == null ) return false;
	
	for( var i = 0; i < box.options.length; i++ )  	
	{ 
		out+= tmpodd+box.options[i].value;  
		tmpodd = odd;
	}	
	
	return out;
}


function selectIstEmpty( box )
{
	if( box == null ) return true;
	if( box.options == null ) return true;
	if( box.options.length == null ) return true;
	
	for( i=0; i<box.options.length; i++ )
	{		
		return false;
		break;
	} 
	
	return true;
}

function selectIsNotEmpty( box )
{
	return ! selectIstEmpty( box );
}
//************ KONEC FUNKCI PRO PRACI SE SELEKTEM *********************************//





var m2t=null;
var m3t=null;
var lastMenu2Def=true;
var a1def=0;
var a2def=0;
var a3def=0;

function zobrazMenu(idmenu, uroven) {
	var divy=document.getElementById('menu').getElementsByTagName('div');
	if(uroven==2) {
		a1def=idmenu;
		lastMenu2Def=false;
		for(var i=0;i<divy.length;i++) {
			if(divy[i].className.indexOf('submenu')>-1 && divy[i].className.indexOf('submenu2')==-1) {
				if(divy[i].id=='menu2_'+idmenu) {
					divy[i].style.display='block';
					if(divy[i].className.indexOf('defShow')>-1) {
						lastMenu2Def=true;	
					}
				} else if(idmenu==0 && divy[i].className.indexOf('defShow')>-1) {
					divy[i].style.display='block';	
					lastMenu2Def=true;
				} else {
					divy[i].style.display='none';						
				}
			}	
		}
		n3();
		m3t=setTimeout(function() {zobrazMenu(0,3);},100);
	} else if(uroven==3) {
		a2def=idmenu;
		for(var i=0;i<divy.length;i++) {
			if(divy[i].className.indexOf('submenu2')>-1) {
				if(divy[i].id=='menu3_'+idmenu) {
					divy[i].style.display='block';
				} else if(idmenu==0 && divy[i].className.indexOf('defShow')>-1 && lastMenu2Def) {
					divy[i].style.display='block';
				} else {
					divy[i].style.display='none';						
				}
			}	
		}
	}
	oznacA();
}

function n2() {
	if(m2t) clearTimeout(m2t);
}

function n3() {
	if(m3t) clearTimeout(m3t);
}
function null2() {
	n2();
	m2t=setTimeout(function() {zobrazMenu(0,2);}, 300);	
}
function null3() {
	m3t=setTimeout(function() {zobrazMenu(0,3);}, 300);	
}
function oznacA() {
	var ay=document.getElementById('menu').getElementsByTagName('a');
	for(var i=0;i<ay.length;i++) {
		ay[i].className="";	
	}
	x1=a1def>0 ? a1def : def1;
	x2=a2def>0 ? a2def : def2;
	x3=a3def>0 ? a3def : def3;
	if(x1>0) { 
		document.getElementById('ah_'+x1).className='active';
	}
	if(x2>0) {
			document.getElementById('ah_'+x2).className='active';
	}
	if(x3>0) {
			document.getElementById('ah_'+x3).className='active';
	}
}
