var et, tr;
var cba = "#E7EBF5";

function topsearch(oid,named) {
	for (var i=0; i<=4; i++)document.getElementById('book'+i).style.backgroundColor="#F1F3FA";
	document.getElementById('book'+oid).style.backgroundColor="#DCE2F1";
	document.getElementById('searchname').innerHTML=named;
	document.indexsearch.area.value=oid;
	document.indexsearch.q.focus();
}
function hide(obj) {obj.style.display='none';}
/*
function ShowFoto(IMI){var URL; URL=root+ '/common/bigimg.php?IMI='+IMI+'&root='+root; window.open(URL,'','scrollbars,width=1,height=1,left='+(screen.width/2)+',top='+(screen.height/2));}
*/
function ShowFoto(img){	if (!root) root='';	ad(root+'/img.php?img='+img+'&root='+root)}
function ad(url) {
	if (document.getElementById('ax111')) document.body.removeChild(document.getElementById('ax111'));
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.id = 'ax111';
	jsel.src = url;
	document.body.appendChild(jsel);
}

function check_fill(obj,mail) {
	if (mail!='' && mail!=undefined && mail.value.length > 0) {
		CheckEmail(mail.value)
		if (!tr) {
			mail.style.backgroundColor=cba; 
			return false;
		}
	}
	et=0;
	for (i=0;i<obj.length;i++) {
		o = obj[i];
		if (o.value.length == 0) {
			 et=1;
			 o.style.backgroundColor=cba;
		}
		else 
			 o.style.backgroundColor="";
	}
	if (et) return false;
}

function CheckEmail(field){
	var str=field
	var filter=/^.+@.+\..{2,3}$/
	if (filter.test(str))	tr=true;
	else{	tr=false;	}
}
function chv(obj,nova,old) {if (obj.value==old) obj.value = nova; }

function highlightSearchTerms(searchText) {
	searchText = searchText.replace('>','');
	searchText = searchText.replace('<','');
	searchArray = searchText.split(" ");
	var bodyText = document.getElementById('content').innerHTML;
	for (var i = 0; i < searchArray.length; i++) { bodyText = doHighlight(bodyText, searchArray[i]);  }
	document.getElementById('content').innerHTML = bodyText;
	return true;
}
function doHighlight(bodyText, searchTerm) {
	highlightStartTag = "<font style='background-color:"+cba+";'>";
	highlightEndTag = "</font>";
	var newText = "";
	var i = -1;
	var lcSearchTerm = searchTerm.toLowerCase();
	var lcBodyText = bodyText.toLowerCase();
	
	while (bodyText.length > 0) {
	i = lcBodyText.indexOf(lcSearchTerm, i+1);
		if (i < 0) {
		  newText += bodyText;
		  bodyText = "";
		} else {
		  if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) {
			if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) {
			  newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag;
			  bodyText = bodyText.substr(i + searchTerm.length);
			  lcBodyText = bodyText.toLowerCase();
			  i = -1;
			}
		  }
		}
	}
  
  return newText;
}

function  mark_checks(me,id,start,konec) {
	what = me.checked;
	for (var i=start; i<=konec; i++) {if (document.getElementById(id+i)) document.getElementById(id+i).checked=what;}
}

// Tigra
function tigra_tables (
		str_tableid, 
		num_header_offset, 
		num_footer_offset,
		str_odd_color, 
		str_even_color, 
		str_mover_color 
	) {

	// validate required parameters
	if (!str_tableid) return alert ("No table(s) ID specified in parameters");
	var obj_tables = (document.all ? document.all[str_tableid] : document.getElementById(str_tableid));
	if (!obj_tables) return alert ("Can't find table(s) with specified ID (" + str_tableid + ")");

	// set defaults for optional parameters
	var col_config = [];
	col_config.header_offset = (num_header_offset ? num_header_offset : 0);
	col_config.footer_offset = (num_footer_offset ? num_footer_offset : 0);
	col_config.odd_color = (str_odd_color ? str_odd_color : '#E7EBF5');
	col_config.even_color = (str_even_color ? str_even_color : '#FFF');
	col_config.mover_color = (str_mover_color ? str_mover_color : '#D7DDEE');
	
	// init multiple tables with same ID
	if (obj_tables.length)
		for (var i = 0; i < obj_tables.length; i++)
			tt_init_table(obj_tables[i], col_config);
	// init single table
	else
		tt_init_table(obj_tables, col_config);
}

function tt_init_table (obj_table, col_config) {
	var col_lconfig = [],
		col_trs = obj_table.rows;
	if (!col_trs) return;
	for (var i = col_config.header_offset; i < col_trs.length - col_config.footer_offset; i++) {
		col_trs[i].config = col_config;
		col_trs[i].lconfig = col_lconfig;
		col_trs[i].set_color = tt_set_color;
		col_trs[i].onmouseover = tt_mover; 
		col_trs[i].onmouseout = tt_mout;
		col_trs[i].order = (i - col_config.header_offset) % 2;
		col_trs[i].onmouseout();
	}
}
function tt_set_color(str_color) {
	this.style.backgroundColor = str_color;
	this.style.cursor = "pointer";
}

// event handlers
function tt_mover () {
	if (this.lconfig.clicked != this)
		this.set_color(this.config.mover_color);
}
function tt_mout () {
	if (this.lconfig.clicked != this)
		this.set_color(this.order ? this.config.odd_color : this.config.even_color);
}
// END Tigra
// AJAX
function statis(txt) { 
	url = root + '/ajax/statis.php?statis=' + txt;
	ajax_do (url);
}
function ajax_do (url) { // JS SQL operations
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;
	document.body.appendChild (jsel); 	// Append JS element (therefore executing the 'AJAX' call)
	return true;
}
function cat(ids,type) {
	if (type==1 && document.getElementById(ids).innerHTML) document.getElementById(ids).style.visibility='visible';
	else document.getElementById(ids).style.visibility='hidden';
}