  <!--
	var form		= "document.frm"
	var conditions	= new Array
	var indexes 	= new Array
	var mod			= true
	var parsed		= false
	
	
	//*----- Selecty -----*/
	var sel	= new Array
	sel[0]	= form + ".Zavorky1"
	sel[1]	= form + ".Objekt"
	sel[2]	= form + ".Relace"
	sel[3]	= form + ".Hodnota"
	sel[4]	= form + ".Zavorky2"
	sel[5]	= form + ".Operator"
	
	
	//*----- Hodnoty jednotlivých selectů -----*/
	var selects	= new Array
	for(i=0; i<sel.length; i++)
		{
		if(i!=3) selects[i]	= sel[i] + ".options[" + sel[i] + ".selectedIndex].value"
		else selects[i] = sel[i] + ".value"
		}
		
		
	//*----- Popisky pro jednotlivé hodnoty selectů do výpisu podmínek -----*/
	// zobrazuju sa v priestore pod formularom kde su ulozene jednotlive podmienky, hodnota je nahradena textovou formou
	// to co tu je definovane sa zobrazuje pod formularom
	var popisek = new Array
/*
	popisek["o0"]					= "Název titulu"
	popisek["o1"]					= "Typ média"
	popisek["o2"]					= "Žánr titulu"
	popisek["o3"]					= "Katalogové číslo"
	popisek["o4"]					= "Příjmení autora skladby"
	popisek["o5"]					= "Příjmení interpreta skladby"
	popisek["o6"]					= "Název hudebního tělesa"
	popisek["o7"]					= "Příjmení člena hud. tělesa"
	popisek["o8"]					= "Název skladby"
	popisek["o9"]					= "Název části skladby"
	popisek["Like"]					= "obsahuje"
	popisek["Not like"]				= "neobsahuje"
	popisek["="]					= "je přesně"
	popisek["<>"]					= "není přesně"
*/
	popisek["o0"]					= "Name of Title"
	popisek["o1"]					= "Medium Type"
	popisek["o2"]					= "Genre"
	popisek["o3"]					= "Catalog Number"
	popisek["o4"]					= "Song's Author Surname"
	popisek["o5"]					= "Song's Performer Surname"
	popisek["o6"]					= "Name of the Group"
	popisek["o7"]					= "Group's Member Surname"
	popisek["o8"]					= "Name of the Song"
	popisek["o9"]					= "Song's Part Name"
	popisek["Like"]					= "contains"
	popisek["Not like"]				= "does not contain"
	popisek["="]					= "is exactly"
	popisek["<>"]					= "is not exactly"


	
	//*----- Tabulka pro výpis podmínek -----*/
	var text1 = "<table class='katalog_hledani'>\n"
/*	var text1 = "<table class='katalog_hledani'><tr><td><table style='border:0px;width:100%;'>\n"
	text1 += "<tr>\n"
  text1 += "<td>\n"
	text1 += "<table class='katalog_hledani'>\n"*/

	
/*	var text2 = "</table>\n"				
	text2 += "</td>\n"
	text2 += "</tr>\n"
	text2 += "</table></td></tr><tr><td>\n"

	text2 += "<br><input type='button' value='Hledat' id='formular-submit' style='float:right;' onclick='if(SendRequest()){document.frm.submit()}'>"
	text2 += "</td></tr></table>"*/
	
	var text2 = "</td></tr></table><input type='button' value='Search' id='formular-submit' style='float:right;' onclick='if(SendRequest()){document.frm.submit()}'>"


	
	//*----- Pole s options -----*/
	var opto0 = new Array
/*
	opto0[0] 	= new Option('je přesně', '=')
	opto0[1] 	= new Option('není přesně', '<>')
	opto0[2] 	= new Option('obsahuje', 'Like')
	opto0[3] 	= new Option('neobsahuje', 'Not like')
*/
	opto0[0] 	= new Option('is exactly', '=')
	opto0[1] 	= new Option('is not exactly', '<>')
	opto0[2] 	= new Option('contains', 'Like')
	opto0[3] 	= new Option('does not contain', 'Not Like')
	
	opto1 = opto2 = opto3 = opto4 = opto5 = opto6 = opto7 = opto8 = opto9 = opto0
	
	var optRok_alba = new Array
	optRok_alba[0]  = new Option('=', '=')
	optRok_alba[1]  = new Option('<>', '<>')
	optRok_alba[2]  = new Option('>', '>')
	optRok_alba[3]  = new Option('<', '<')
	optRok_alba[4]  = new Option('<=', '<=')
	optRok_alba[5]  = new Option('>=', '>=')
	
	optRok_skladby = optRok_alba
			
	
	//*----- Vycentruj vrstvy kvuli NN4 suck -----*/		

	function centerElement (id,elTop)
		{
  	var el, windowWidth, cx
		var elWidth = 650
  	if (document.layers)
			{
    	el = document[id]
    	windowWidth = window.innerWidth
  		}
  	else if (document.all)
			{
    	el = document.all[id]
    	windowWidth = document.body.clientWidth
 		 	}
  	else if (document.getElementById)
			{
    	el = document.getElementById(id)
    	windowWidth = window.innerWidth
		  }
  	cx = Math.floor((windowWidth - elWidth) / 2);
  	if (document.layers)
			{
    	el.left = cx
    	el.top = elTop
    	el.visibility = 'show'
  		}
  	else if (document.all || document.getElementById)
			{
   		el.style.left = cx + 'px';
    	el.style.top = elTop + 'px';
    	el.style.visibility = 'visible';
  		}
		}



	function Init()
		{
/*  	centerElement("condorDiv",150)
		centerElement("sqlDiv",100)*/
		}

		
	
	//*----- Změna selectu -----*/
	function ChangeSelect(ovladaci,ovladany)
		{
		var selMaster 	= eval("document.frm." + ovladaci)  //ovládací select
		var selSlave 	= eval("document.frm." + ovladany)  //měněný select
		var optPole		= eval("opt" + selMaster.options[selMaster.selectedIndex].value)	//pole s options								 
		for(i=0; i<selSlave.options.length; i++) selSlave.options[i] = null  // vyčistit
		for(i=0; i<optPole.length; i++) selSlave.options[i] = optPole[i]     // zapsat nové
			selSlave.selectedIndex = 2  //nastavit na první
/*		if ((selMaster.selectedIndex == 3) || (selMaster.selectedIndex == 5)) {
			selSlave.selectedIndex = 0  //nastavit na první
		} else {
			selSlave.selectedIndex = 2  //nastavit na první
		}*/
		
		if (selMaster.selectedIndex == 1) {
/*			alert('Možné hodnoty: CD, MC, DVD, VHS')*/
			alert('Possible values: CD, MC, DVD, VHS')
		}
		
		if (selMaster.selectedIndex == 2) {
/*			alert('Možné hodnoty: komorní hudba, vok. nejev. hudba (mše, oratoria, písně, žalmy), populární hudba, dechová hudba, jazz, vokální jevištní hudba (opery, operety, melodramy na jevišti atd.), folklór, mluvené slovo, mluvené slovo pro děti, mluvené slovo pro dospělé, mluvené slovo  kurzy, nezařaditelné')*/
			alert('Possible values: chamber music, vocal non-scenic music (mass, oratorio, songs, psalm), pop music, brass music, jazz, vocal scenic music (opera, operetta, melodrama on the stage etc.), folklore, spoken word, spoken word for children, spoken word for adults, spoken word  courses, uncategorized')
		}
		}
		
	
	//*----- Přepiš vrstvu s podmínkama -----*/
	function WriteCondition()
		{

    if ( document.frm.Hodnota.value == '' )
    {
      alert('Value is empty. Please write what you search.');
      return;
    }


		var td_width_array = new Array
		td_width_array[0] = 60
		td_width_array[1] = 181 //155
		td_width_array[2] = 95
		td_width_array[3] = 121
		td_width_array[4] = 61
		td_width_array[5] = 51
		
		var str = ""		
		m = parseInt(document.frm.id_m.value)
		if(m!=-1)
			{
			l = m	
			document.frm.id_m.value = -1	
			}
		else
			{
			l = (conditions.length==0) ? 0 : conditions.length 
			}
		//alert (l);
		indexes[l] = new Array
		for(i=0; i<selects.length; i++)
			{
			val = (eval(selects[i])=="") ? "&nbsp;" : (!popisek[eval(selects[i])]) ? eval(selects[i]) : popisek[eval(selects[i])]
			str += "<td>" + val + "</td>\n"
			if(i!=3) indexes[l][i] = eval(sel[i] + ".selectedIndex")
			else indexes[l][i] = eval(sel[i] + ".value")
			}			   						


		conditions[l] = str
		WriteText(conditions)
		//MakeSpace(indexes)
		}	
	
	//--- [[  ]] ---
	function _Write(_values_array) {
		var _trans_array = new Array
		// lave zatvorky
		_trans_array[0]		= new Array
		_trans_array[0][0]	= ""
		_trans_array[0][1]	= "("
		_trans_array[0][2]	= "(("
		_trans_array[0][3]	= "((("
		_trans_array[0][4]	= "(((("
		_trans_array[0][5]	= "((((("
		// objekt
		_trans_array[1]		= new Array
/*		_trans_array[1][0]	= "Název titulu"
		_trans_array[1][1]	= "Typ média"
		_trans_array[1][2]	= "Žánr titulu"
		_trans_array[1][3]	= "Katalogové číslo"
		_trans_array[1][4]	= "Příjmení autora skladby"
		_trans_array[1][5]	= "Příjmení interpreta skladby"
		_trans_array[1][6]	= "Název hudebního tělesa"
		_trans_array[1][7]	= "Příjmení člena hud. tělesa"
		_trans_array[1][8]	= "Název skladby"
		_trans_array[1][9]	= "Název části skladby"*/
		_trans_array[1][0]	= "Name of Title"
		_trans_array[1][1]	= "Medium Type"
		_trans_array[1][2]	= "Genre"
		_trans_array[1][3]	= "Catalog Number"
		_trans_array[1][4]	= "Song's Author Surname"
		_trans_array[1][5]	= "Song's Performer Surname"
		_trans_array[1][6]	= "Name of the Group"
		_trans_array[1][7]	= "Group's Member Surname"
		_trans_array[1][8]	= "Name of the Song"
		_trans_array[1][9]	= "Song's Part Name"
		// relace
		_trans_array[2]		= new Array
/*
		_trans_array[2][0]	= "je přesně"
		_trans_array[2][1]	= "není přesně"
		_trans_array[2][2]	= "obsahuje"
		_trans_array[2][3]	= "neobsahuje"*/
		_trans_array[2]		= new Array
		_trans_array[2][0]	= "is exactly"
		_trans_array[2][1]	= "is not exactly"
		_trans_array[2][2]	= "contains"
		_trans_array[2][3]	= "does not contain"

		
		// prave zatvorky
		_trans_array[4]		= new Array
		_trans_array[4][0]	= ""
		_trans_array[4][1]	= ")"
		_trans_array[4][2]	= "))"
		_trans_array[4][3]	= ")))"
		_trans_array[4][4]	= "))))"
		_trans_array[4][5]	= ")))))"
		// operator
		_trans_array[5]		= new Array
		_trans_array[5][0]	= ""
		_trans_array[5][1]	= "OR"
		_trans_array[5][2]	= "AND"
		
		
		
		
	
		var td_width_array = new Array
		td_width_array[0] = 60
		td_width_array[1] = 181 //155
		td_width_array[2] = 95
		td_width_array[3] = 121
		td_width_array[4] = 61
		td_width_array[5] = 51

		
		
		var str = ""		
		m = parseInt(document.frm.id_m.value)
		if(m!=-1)
			{
			l = m
			document.frm.id_m.value = -1	
			}
		else
			{
			l = (conditions.length==0) ? 0 : conditions.length 
			}
		indexes[l] = new Array
		for(i=0; i<_values_array.length; i++)
			{
//			val = (eval(selects[i])=="") ? "&nbsp;" : (!popisek[eval(selects[i])]) ? eval(selects[i]) : popisek[eval(selects[i])]
//			val = (_values_array[i]=="") ? "&nbsp;" : ( (!popisek[eval(_values_array[i])]) ? eval(_values_array[i]) : popisek[eval(_values_array[i])] )
			if (i != 3) {
				val = eval('_trans_array['+i+']['+_values_array[i]+']')
			} else {
				val = (_values_array[i]=="" ? "&nbsp;" : _values_array[i])
			}
			str += "<td>" + val + "</td>\n"
//			if(i!=3) indexes[l][i] = eval(sel[i] + ".selectedIndex")
//			else indexes[l][i] = eval(sel[i] + ".value")
			
			indexes[l][i] = _values_array[i];
			}			   						
		conditions[l] = str
		WriteText(conditions)
	}
	
	//*----- Umaž vybranou podmínku -----*/
	function DelCondition(j)
		{
		var con	= new Array
		var ind	= new Array
		var k = 0
		for(i=0; i<conditions.length; i++)
			{
			if(j!=i)
				{					
				con[k] = conditions[i]
				ind[k] = indexes[i]
				k++
				}
			}
		conditions = con	
		indexes = ind		
		WriteText(conditions)
		//MakeSpace(indexes)
		}
		
		
	function SetupRelace() {
		// po novom uz niesu numericke opt
		var optPole		= eval("opto0")	//pole s options

/*		if ((document.frm.Objekt.selectedIndex == 3) || (document.frm.Objekt.selectedIndex == 5))  {
			// relace na rovnasa
			var optPole		= eval("optRok_alba")	//pole s options
		} else {
			// relace na likes
			var optPole		= eval("optJmeno_interpreta")	//pole s options								 
		}*/
		var _rel_sel	= document.frm.Relace;

		_rel_sel.options.length = optPole.length;
		for (i=0; i<optPole.length; i++) {
			_rel_sel.options[i] = optPole[i]
		}
	}
	
	//*----- Modifikuj vybranou položku -----*/
	function ModifyCondition(j)
		{		
//		alert(indexes[j].length)
/*		for(i=0; i<sel.length; i++)
			{
			if(i!=3) eval(sel[i]).selectedIndex = indexes[j][i]
			else eval(sel[i]).value = indexes[j][i]
			if (i == 1) { SetupRelace() }// nastav relace na spravne hodnoty podla hodnoty objekt
			}*/
		
		// indexes
		document.frm.Zavorky1.selectedIndex	= indexes[j][0]
		document.frm.Objekt.selectedIndex	= indexes[j][1]
		document.frm.Hodnota.value			= indexes[j][3]
		document.frm.Zavorky2.selectedIndex = indexes[j][4]
		document.frm.Operator.selectedIndex = indexes[j][5]
		
		// setup values
		SetupRelace();

		// value select
		document.frm.Relace.selectedIndex	= indexes[j][2]
		
		document.frm.id_m.value = j
		WriteText(conditions,j)


/*		if(mod)
			{
			document.frm.id_m.value = j
			WriteText(conditions,j)
			mod = false
			}
		else
			{
			document.frm.id_m.value = -1
			WriteText(conditions)
			mod = true
			}*/
		}
				
	
	//*----- Obsah pro vrstvu -----*/	
	function WriteText(c,j)
		{		
		var text = text1
		for(i=0; i<c.length; i++)
			{
			if(j==i)
				{
				b = "3F739C"
//				bol1 = "<b>"
//				bol2 = "</b>"
				bol1 = ""
				bol2 = ""
				}
			else
				{
				b = "21679C"
				bol1 = ""
				bol2 = ""
				}			
			text += "<tr>\n" + c[i] + "<td><a href='#' onclick=\"DelCondition(" + i + ")\">delete</a></td><td>" + bol1 + "<a href=\"#\" onclick=\"ModifyCondition(" + i + ")\">modify</a>" + bol2 + "</td>\n</tr>\n"
			}
		text += text2	
		if(c.length==0)
			{
			text = ""
			parsed = false
			FillDiv("","sqlDiv")
			}
		FillDiv(text,"condorDiv")
		if(parsed) ParseCondition()
		}
		
		
	//*----- Výpis do vrstvy -----*/	
	function FillDiv(t,div)
		{
		if(document.all)
			{
			document.all[div].innerHTML ="";
			document.all[div].innerHTML = t;
			}
		else if(document.layers)
			{/*-
			var l = document[div]
    	if (!l.ol)
				{
      	var ol = l.ol = new Layer (l.clip.width, l)
      	ol.clip.width = l.clip.width
      	ol.clip.height = l.clip.height
      	ol.bgColor = l.bgColor
      	l.visibility = 'hide'
      	ol.visibility = 'show'
				alert(ol.clip.width + " : " + ol.clip.height)
    		}
    	var ol = l.ol-*/
    	document[div].document.open()
    	document[div].document.write(t)
    	document[div].document.close()
			}
		else if(document.getElementById)
			{
			var l = document.getElementById(div)
      var r = document.createRange()
      r.setStartAfter(l)
      var docFrag = r.createContextualFragment(t)
      while (l.hasChildNodes()) l.removeChild(l.firstChild)
      l.appendChild(docFrag)
			}
		}
		
	//*----- Výpis podmínek pro databázi -----*/
	function ParseCondition()
		{
		window.status = 'count of conditions:' + conditions.length;
		
		text = "SELECT ... FROM ... WHERE "
		for(i=0; i<conditions.length; i++)
			{
			window.status = window.status + 'i=' + i + ':';//
			
			for(j=0; j<sel.length; j++)
				{
				window.status = window.status + j + ',' + indexes[i][j] + ';';//

				if(j!=3) text += eval(sel[j]).options[indexes[i][j]].value + " "
				else text += "'" + indexes[i][j] + "' "
				}
			}		
		FillDiv(text,"sqlDiv")
		parsed = true
		}

		
	function ParseRequest() {
		if (indexes.length) {
			//--- [[ check ci su vsade pouzite operatory ]] --- 
			if (indexes.length > 1) {
				for (i=0; i<indexes.length-1; i++) {
					if (indexes[i][5] == 0) {
/*						alert('Chybějící logický operátor!');*/
						alert('Missing logical operator!');
						ModifyCondition(i);
						eval(sel[5]).focus();
						return false;
					}
				}
			}

			//--- [[ check for last operator ]] ---
			if (indexes[indexes.length - 1][5] != 0) {
				alert('Too many operators!');
/*				alert('Přebytečný operátor!');*/
				ModifyCondition(indexes.length - 1);
				eval(sel[5]).focus();
				return false;
			}
			
			
			//--- [[ check for brackets ]] ---
			var br_lev = 0;
			var br_pos = -1;
			var br_cur = 0;
			
			for (i=0; i<indexes.length; i++) {
				br_cur = indexes[i][0] - indexes[i][4]
				if (br_cur != 0) {
					if ((br_lev + br_cur) < 0) {		// viac zavretych - throw error ihned
/*						alert('Přebytečný počet závorek!');*/
						alert('Too many Brackets!');
						ModifyCondition(i);
						eval(sel[4]).focus();
						return false;
					} else if ((br_lev + br_cur) > 0) {	// viac otvorenych - logni si info
						if (br_lev == 0) {	// vznik prebytku - zapametaj pre neskorsie problemy
							br_pos = i;
						}
						br_lev += br_cur;
					} else {							// 
						br_lev += br_cur;
					}
				}
			}

			if (br_lev > 0) {
/*				alert('Přebytečný počet závorek!');*/
				alert('Too many Brackets!');
				ModifyCondition(br_pos);
				eval(sel[0]).focus();
				return false;
			} else if (br_lev < 0) {
/*				alert('Nedostatečný počet závorek!');*/
				alert('Missing Brackets!');
				ModifyCondition(br_pos);
				eval(sel[4]).focus();
				return false;
			} else {
				// ok
			}
			
			
			
			//--- [[ all looks fine, ask for submit ]] ---
//			return confirm('Odeslat dotaz?');
			return true;
		}		
	}
	
	function ShowRequest() {
		text = "";
		
		for (i=0; i<indexes.length; i++) {
			for (j=0; j<indexes[i].length; j++) {
				text += "&lt;input type='Hidden' name='indexes["+ i +"][" + j + "]' value='" + indexes[i][j] + "'&gt;<br>";
			}
			text += "<br>";
		}
		FillDiv(text,"showDiv")
	}

	

	function BuildRequest() {
		text = "";
		
		for (i=0; i<indexes.length; i++) {
			for (j=0; j<indexes[i].length; j++) {
				text += "<input type='hidden' name='indexes["+ i +"][" + j + "]' value='" + indexes[i][j] + "'>";
			}
		}
		FillDiv(text,"frmDiv")
	}

	function SendRequest() {
		if (ParseRequest()) {
			BuildRequest()
			return true;
			//document.frm.submit();
//			eval(form).submit();
//			return true;
		} else {
			return false;
//			return false;
		}
	}
	
	
  //-->
