var et, tr;
var cba = "#FFEBD7";
var cbo = "#FF8000";

function ngo() {document.all.ngo.value = 0; return false;}
function l(l) {
	if (document.all.ngo.value.length == 0) location.href=l;
	else return false;
}
function hide(obj) {obj.style.display='none';}
function hlr(obj,w){
	if (w == 1) {
		obj.style.backgroundColor = cba;
		obj.style.cursor = "pointer";
		document.all.ngo.value = "";
		} 
	else {obj.style.backgroundColor = "";}
}
/*
function ShowFoto(IMI){	var URL; URL='common/bigimg.php?IMI='+IMI; window.open(URL,'','scrollbars,width=1,height=1,left='+(screen.width/2)+',top='+(screen.height/2));}
*/
function ShowFoto(img){ad('img.php?img='+img)}
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_pass(pass0,pass1,mail,out,data) {
	if (pass0.value !== pass1.value) {
		alert("Nesouhlasí zadaná hesla. Prosím, zkontrolujte.");
		pass0.style.backgroundColor=cba;
		pass0.style.borderColor=cbo;
		pass1.style.backgroundColor=cba;
		pass1.style.borderColor=cbo;
		return false;
	}
	return check_fill(out,data,mail);
}
function check_fill(out,data,mail) {
	if (mail!='' && mail!=undefined && mail.value.length > 0) {
		CheckEmail(mail.value)
		if (!tr) {alert("Zkontrolujte zadaný e-mail ..."); mail.style.backgroundColor=cba; mail.style.borderColor=cbo; return false; }
	}
	var et="";
	for (i=0;i<out.length;i++) {
		obj = data[i];
		if (obj.value.length == 0) {
			 et += "\n  - " + out[i];
			 obj.style.backgroundColor=cba;
			 obj.style.borderColor=cbo;
		}
		else {
			 obj.style.backgroundColor="";
			 obj.style.borderColor="";
		}
	}
	if (et) {alert("Vyplňte:" + et); return false;}
}

function CheckEmail(field){
	var str=field
	var filter=/^.+@.+\..{2,3}$/
	if (filter.test(str))	tr=true;
	else{	tr=false;	}
}

function sendTest_friend(){
	et="";
	CheckEmail(document.edit1.mailto.value);
	if (document.edit1.name.value.length == 0)	{
		et = new Array("Jméno","Name","Name","Name");
		et = "\n" + "- " + et[lang-1];
	}	
	if (! tr) {et = et + "\n" + "- E-Mail"	}
	if (et != ""){
		window.alert(check + ": " + et);
		return false;
	}  
}
function sendTest_quicksearch(kde){
	et = new Array("Zadejte, co chcete hledat.","Nichts zu suchen.","Nothing to search.","Nothing to search.");
	et = et[lang-1];
	if (kde==1 && (document.quicksearch.text.value == st || document.quicksearch.text.value.length == 0))	{	window.alert(et);	return false;	}  
	if (kde==2 && document.search_more.text.value.length == 0)	{	window.alert(et);	return false;	}  
}

function chv(obj,nova,old) {if (obj.value==old) obj.value = nova; }


function highlightSearchTerms(searchText,opt) {
	searchText = searchText.replace('>','');
	searchText = searchText.replace('<','');
	searchArray = searchText.split(" ");
	var bodyText = document.getElementById('middle').innerHTML;
	for (var i = 0; i < searchArray.length; i++) { bodyText = doHighlight(bodyText, searchArray[i],opt);  }
	document.getElementById('middle').innerHTML = bodyText;
	return true;
}

function doHighlight(bodyText, searchTerm,opt) {
	if (opt) {
		highlightStartTag = "<a href=http://www.vyberautomorava.cz id=hl>";
		highlightEndTag = "</a>";
	}
	else {
		highlightStartTag = "<span id=hl>";
		highlightEndTag = "</span>";
	}
	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;
}


//MENU
var ab = null;
function bM(button, menuName) {
  if (ab) rB(ab);
}
function bC(button, menuName) {
  if (!button.menu)
    button.menu = document.getElementById(menuName);
  if (ab && ab != button)
    rB(ab);
    dB(button);
  return false;
}
function dB(button) {
  var x = getPageOffsetLeft(button);
  if (button.menu) {
	  button.menu.style.left  = x + "px";
	  button.menu.style.top  = "16px";
	  button.menu.style.visibility = "visible";
  }
  ab = button;
}
function rB(button) {
  if (button.menu) button.menu.style.visibility = "hidden";
  ab = null;
}
function pryc() {
	 if (ab) rB(ab);
}

function getPageOffsetLeft(el) {  return el.offsetLeft + (el.offsetParent ? getPageOffsetLeft(el.offsetParent) : 0);}

// AJAX
function create_types(id_znacky,sel_box_name,sel_box_width,selected_id,path_prefix) { 
	el = document.getElementById('typy_sel_box');
	el.innerHTML = 'Čekejte ...';

	url = path_prefix + 'ajax_create_types.php?sel_box_width=' + sel_box_width + '&znacka=' + escape(id_znacky) + '&sel_box_name=' + escape(sel_box_name) + '&selected_id=' + escape(selected_id);
//	alert(url);
	ajax_do (url);
}

function create_types_only_avail(id_znacky,sel_box_name,sel_box_width,selected_id,path_prefix) { 
// pouze typy dostupne skladem
	el = document.getElementById('typy_sel_box');
	el.innerHTML = 'Čekejte ...';

	url = path_prefix + 'ajax_create_types.php?sel_box_width=' + sel_box_width + '&znacka=' + escape(id_znacky) + '&sel_box_name=' + escape(sel_box_name) + '&selected_id=' + escape(selected_id) + '&only_avail=1';
//	alert(url);
	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 otevri_okno(url,cil) {
    window.open(url, cil, 'width=800,height=600,menubar=no,resizable=yes,toolbar=no,scrollbars=yes');
}

function otevri_okno_mensi(url,cil) {
    window.open(url, cil, 'width=700,height=400,menubar=no,resizable=yes,toolbar=no,scrollbars=yes');
}

