exist=0;poc=0;mat=0;kmen=0;hodnota="";cyklus=1;

zpr2="You cannot select all regions to the heading!";
zpr3="You cannot select all indicators to the heading!";
zpr4="You cannot select all years to the heading!";
zpr5="The selected table has more than the maximum of 10 indicators!";
zpr6="Please, select all needed values!";
O10="<b><img src=../image/t2.gif alt='class'><A class=p href=javascript:help('";
O11="<img src=../image/i.gif><A class=p href=javascript:help('";
slv1="previous";slv2="next";slv3="close";
SOUBOR="../data/frame_eng.html";

function K(ent,odp,dop)
{
T="<tr><td><p>";
C="</td><td class='uvnitr' id=";
CU="</td><td id=";
J="')>";
H="><p><A class='ukz' href=javascript:a('";
O="";
for (o=odp; o<=dop; o++)
{
if (ent=="ukz")
	{
	if((u[o].charAt(3))=="0") 
		{
		if(hodnota.indexOf(" "+u[o]+" ")==-1) O=O+T+O10+u[o]+J+"&nbsp;"+u[o]+CU+u[o]+H+u[o]+J+m0[o];	
		else O=O+T+O10+u[o]+J+"&nbsp;"+u[o]+CU+u[o]+" bgcolor=#CCFFCC"+H+u[o]+J+m0[o];
		}
		else 
		{
		if(hodnota.indexOf(" "+u[o]+" ")==-1) O=O+T+O11+u[o]+J+"&nbsp;"+u[o]+CU+u[o]+H+u[o]+J+m0[o];	
		else O=O+T+O11+u[o]+J+"&nbsp;"+u[o]+CU+u[o]+" bgcolor=#CCFFCC"+H+u[o]+J+m0[o];
		}
	}
else if (ent=="reg")
	{
	if ((o==0)||(o==8)) O=O+"<tr><td class=uvnitr id="+m1[o];
	else if(o==14) O=O+"</td><td class=uvnitr id="+m1[o]+" colspan=2";
	else O=O+C+m1[o];
	if(hodnota.indexOf(" "+m1[o]+" ")==-1) O=O+H+m1[o]+J+"&nbsp;"+m1[o]+"&nbsp;";	
	else O=O+" bgcolor=#CCFFCC"+H+m1[o]+J+"&nbsp;"+m1[o]+"&nbsp;";
	}
else if (ent=="rok")
	{
	if ((o==0)||(o==8)) O=O+"<tr><td class=uvnitr id="+m2[o];
	else O=O+C+m2[o];
	if(hodnota.indexOf(" "+m2[o]+" ")==-1) O=O+H+m2[o]+J+m2[o];	
	else O=O+" bgcolor=#CCFFCC"+H+m2[o]+J+m2[o];
	}
}
return O
}
function aktual ()
{
hodnota0=parent.tabulka.document.frm.T0.value;hodnota1=parent.tabulka.document.frm.T1.value;hodnota2=parent.tabulka.document.frm.T2.value;hodnotaN=parent.tabulka.document.frm.Nadpis.selectedIndex;kmen=parent.tabulka.document.frm.K.value;
s0=parent.tabulka.document.frm.Nadpis.selectedIndex;s1=hodnota1.substring(0,3);s2=hodnota2.substring(0,3);enter=E();
}
function k (kmen, zid)
{
aktual();Hodn="";
if (zid==98) 
	{
	m1=" "+m1.join(" ");
	if (s0==2) window.alert(zpr2);
	else if (s1=="REG") Hodn ="REG"+m1+" ";
	else if (s2=="REG") parent.tabulka.document.frm.T2.value ="REG"+m1+" ";
	}
else if (zid==100) 
	{
	m2=" "+m2.join(" ");
	if (s0==0) window.alert(zpr4);
	else if (s1=="ROK") Hodn ="ROK"+m2+" ";
	else if (s2=="ROK") parent.tabulka.document.frm.T2.value ="ROK"+m2+" ";
	}
if ((zid>96)&&(Hodn!="")) parent.tabulka.document.frm.T1.value=Konverze2(Hodn);
if (matice(mat)==1)
	{
	parent.tabulka.document.frm.K.value=kmen;parent.hlava.document.frm.R.value=2;
	document.location="dpsk.html";
	}
else 
	{
	window.alert(zpr5);
	parent.tabulka.document.frm.T1.value=hodnota1;parent.tabulka.document.frm.T2.value=hodnota2;
	}
}

function zamen(z) 
{
aktual();
if (z==0)
	{
	hodn=hodnota2;hodnota2=Konverze2(hodn);hodn=hodnota1;hodnota1=Konverze1(hodn);
	parent.tabulka.document.frm.T1.value=hodnota2;parent.tabulka.document.frm.T2.value=hodnota1;
	}
if (z==2)
	{
	if (s0==0) 
		{
		parent.tabulka.document.frm.T0.value="";parent.tabulka.document.frm.T1.value="UKZ"+enter;parent.tabulka.document.frm.T2.value="REG ";
		}
	if (s0==1) 
		{
		parent.tabulka.document.frm.T0.value="";parent.tabulka.document.frm.T1.value="REG"+enter;parent.tabulka.document.frm.T2.value="ROK ";
		}
	if (s0==2) 
		{
		parent.tabulka.document.frm.T0.value="";parent.tabulka.document.frm.T1.value="UKZ"+enter;parent.tabulka.document.frm.T2.value="ROK ";
		}
	k(kmen,0);
	}
}

function a (i)
{
aktual();
TextArea=0;hodnota="";hl=0;nad=i.charAt(0);
if (isNaN(nad)==false) 
	{
	if (s1=="UKZ") TextArea=1;if (s2=="UKZ") TextArea=2;
	}
else if (nad=="r")
	{
	if (s1=="ROK") TextArea=1;if (s2=="ROK") TextArea=2;
	}
else
	{
	if (s1=="REG") TextArea=1;if (s2=="REG") TextArea=2;
	}
enter=E();
if (TextArea==1)
	{
	x=enter + i + enter; hodnota=parent.tabulka.document.frm.T1.value;
	}
	else x=" " + i + " " ;
if (TextArea==2) hodnota=parent.tabulka.document.frm.T2.value;
if ((TextArea==0) && (hodnota0!="")) 
	{
	hodnota= " " + hodnota0 + " ";Barva(hodnota0,1);
	}
delka=hodnota.length;
pocet=x.length;
cislo= hodnota.indexOf(x);
if (cislo!=-1)
	{		
	pred= hodnota.substring(0,cislo+1);
	za= hodnota.substring(cislo+pocet,delka);
	Barva(i,1);
	hl=1;
	}
else Barva(i,2);	
if (TextArea==0) 
	{
	if (hl==1) parent.tabulka.document.frm.T0.value= "";
	else parent.tabulka.document.frm.T0.value=i;
	}
else
	{
	if (cislo==-1) 
		{
		if (TextArea==1) parent.tabulka.document.frm.T1.value=hodnota + i + enter;
		else parent.tabulka.document.frm.T2.value=hodnota + i + " ";
		}	
	else 
		{
		if (TextArea==1) parent.tabulka.document.frm.T1.value= pred + za;
		else parent.tabulka.document.frm.T2.value= pred + za;
		}
	}
if (matice(mat)==0)
	{
	window.alert(zpr5);
	Barva(i,1);
	parent.tabulka.document.frm.T1.value=hodnota1;parent.tabulka.document.frm.T2.value=hodnota2;
	}
}

function matice (mat)
{
hodn1=parent.tabulka.document.frm.T1.value;hodn2=parent.tabulka.document.frm.T2.value; 
smer1=hodn1.substring(0,3);smer2=hodn2.substring(0,3);
hodn=hodn1;
hodn1=Konverze1(hodn);
hA=hodn1.length-4;hB=hodn2.length-4;
if ((smer1=="UKZ" && hA/5>10) || (smer2=="UKZ" && hB/5>10)) mat=0;
else mat=1;
return mat;
}

function vynuluj (ROK,UKZ,REG)
{
aktual();
if (UKZ==1) 
	{
	if (s0==1) parent.tabulka.document.frm.T0.value="";if (s1=="UKZ") parent.tabulka.document.frm.T1.value="UKZ"+enter;if (s2=="UKZ") parent.tabulka.document.frm.T2.value="UKZ ";
	}
if (REG==1) 
	{
	if (s0==2) parent.tabulka.document.frm.T0.value="";if (s1=="REG") parent.tabulka.document.frm.T1.value="REG"+enter;if (s2=="REG") parent.tabulka.document.frm.T2.value="REG ";
	}
if (ROK==1) 
	{
	if (s0==0) parent.tabulka.document.frm.T0.value="";if (s1=="ROK") parent.tabulka.document.frm.T1.value="ROK"+enter;if (s2=="ROK") parent.tabulka.document.frm.T2.value="ROK ";
	}
k(kmen,0);
}

function help(typ)
{
if (typ.charAt(0)=="n"||typ.charAt(0)=="k") 
	{
	he=window.open("help/"+typ,"help","width=600,height=350,history=yes,toolbar=yes,scrollbars=yes,status=yes,menubar=yes,resizable=yes");
	he.focus();
	}
else 
	{
	parent.hlava.document.frm.R.value=typ;
	typ="ukz"+typ.substring(0,2)+".html";parent.menu.document.location="help/"+typ;
	parent.tabulka.document.frm.K.value=kmen;
	}
}

function send ()
{
aktual();
if ((hodnota0!="") && (hodnota1.length>7) && (hodnota2.length>4)) 
	{
	hodn=hodnota1;
	hodnota1=Konverze1(hodn);
	adresa=SOUBOR+"?T0="+hodnota0+"+&T1="+hodnota1+"&T2="+hodnota2;
	cyklus=adresa.length;
	for(x=0;x<=cyklus;x++)
		{
		if (adresa.charAt(x)==" ") adresa= adresa.substring(0,x) + "+" + adresa.substring(x+1,cyklus);
		}
	no=window.open(adresa,"output","left=5,top=5,width=1024,height=575,menubar=yes,scrollbars=yes,resizable=yes,status=yes");
	no.focus();
	}
else window.alert(zpr6);
}

function Konverze1 (hodn)
{
hodn=hodn.replace(/\r\n/g," ");
hodn=hodn.replace(/\n/g," ");
return hodn;
}

function Konverze2 (hodn)
{
hodn=hodn.replace(/\s/g,enter);
return hodn;
}

function E ()
{
if (navigator.appVersion.lastIndexOf('Win') != -1) enter="\r\n";
else enter="\n";
return enter
}

function Barva(hodnota,color)
{
ie4=false;
with (navigator)
{
nazev=appName; verze=parseInt(appVersion);
}
with (window)
{
if (nazev=="Microsoft Internet Explorer"&&verze>=4) ie4=true;
}
if ((ie4) && (document.all.item(hodnota)))
 	{
	if (color==1) document.all.item(hodnota).bgColor=""; 
	if (color==2) document.all.item(hodnota).bgColor="#CCFFCC";
	}
}

function Ukazatele()
{
X="<table width=100% height=70%>";
hodnotaR=parent.hlava.document.frm.R.value;
if (hodnotaR.length==1) hodnotaR="000"+hodnotaR;
else if (hodnotaR.length==2) hodnotaR="00"+hodnotaR;
else if(hodnotaR.length==3) hodnotaR="0"+hodnotaR;
aktual ();
hodn=hodnota1;hodnota1=Konverze1(hodn);
if (hodnota0=="") hodnota=" "+hodnota1+hodnota2;
else hodnota=" "+hodnota0+" "+hodnota1+hodnota2;
index=u.toString();index=index.indexOf(hodnotaR)/5;nazev=m0[index];cislo=u[index];
if(hodnota.indexOf(" "+u[index]+" ")==-1) X=X+"<tr><td id="+cislo;
else X=X+"<tr><td id="+cislo+" bgcolor=#CCFFCC";
X=X+" valign=top><a href=javascript:a(\""+cislo+"\")><p><b>"+cislo+" "+nazev+"</b><br>"+h[parseFloat(hodnotaR)]+"</table><p align=right><a href=javascript:Pred("+index+");><b> "+slv1+" </a>|<a href=javascript:Dalsi("+index+");><b> "+slv2+" </a>|<a href=../dpsk.html> "+slv3+" </table>";
document.open();document.write(X);document.close();
}

