var et, st, check, tr;
st = new Array("vyhledat","suchen","search","search");
check = new Array("Zkontrolujte","Kontrolieren Sie","Check","Check");
st = st[lang-1];
check = check[lang-1];
var mark="#DAECC1";
var cba = "#EEF7E1";
var cbo = "navy";

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 = mark;
		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 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_contact(){
	CheckEmail(document.edit_contact.mail.value);
	if (document.edit_contact.notes.value.length == 0)	{window.alert(check + ": \n" + "- Text");	return 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) {
	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]);  }
	document.getElementById('middle').innerHTML = bodyText;
	return true;
}
function doHighlight(bodyText, searchTerm) {
	highlightStartTag = "<font style='background-color:#6AC335;'>";
	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;
}
