function zobrazSkryj(idecko){
  el=document.getElementById(idecko).style;
  el.display=(el.display == 'block')?'none':'block';
}


function checkForm_hpSearch(jaz_ver) {
	if (searchform.SearchText.value == '') {
    if ( jaz_ver=='SK' ) { alert('Zadajte prosím hľadaný text.'); }
    else { alert('Zadejte prosím hledaný text.'); }
		return false;
	}
	if (searchform.SearchText.value.length < 3) {
		if ( jaz_ver=='SK' ) { alert('Zadajte prosím hľadaný text o veľkosti alespoň 3 znakoch.'); }
		else { alert('Zadejte prosím hledaný text o velikosti alespoň 3 znaků.'); }
		return false;
	}
	return true;
}
  	
function checkFields() {
	var f = document.Loggin;
	if (f.Login.value == "") { alert("Chybí uživatelské jméno."); return false; };
	if (f.Password.value == "") { alert("Chybí heslo"); return false; };
    return true;
}


function doSearch() {
	var searchText = document.getElementById( "SearchText" ).value;
    window.location = "Search.asp?aid=78&search=" + searchText
    return true;
}


function numbersonly(myfield, e, dec)
{
  var key;
  var keychar;

  if (window.event)
    key = window.event.keyCode;
  else if (e)
    key = e.which;
  else
    return true;

  keychar = String.fromCharCode(key);

  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
    return true;
  else if ((("0123456789").indexOf(keychar) > -1))
    return true;
  else if (dec && (keychar == ".")) {
    myfield.form.elements[dec].focus();
    return false;
  }
  else
   return false;
}

//test na validní e-mail
function validEmail(email) {
  var re = new RegExp();
  re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
  if (!re.test(email)) {return false;}
  else {return true;}
}

//kontrola polí ve formuláři bazaru
function checkForm_bazar() {

	var f = document.getElementById('formBazar');
	f.OnSaleName.value = trim(f.OnSaleName.value);
	f.OnSalePhone.value = trim(f.OnSalePhone.value);
	f.OnSaleEmail.value = trim(f.OnSaleEmail.value);
	f.OnSaleText.value = trim(f.OnSaleText.value);

	if (f.OnSaleName.value == '') {
		alert('Vyplňte prosím pole Název.');
		return(false);
	}
	if (f.OnSaleText.value == '') {
		alert('Vyplňte prosím pole Popis.');
		return(false);
	}
	if ((f.OnSalePhone.value == '') && (f.OnSaleEmail.value == '')) {
		alert('Zadejte prosím Váš telefon nebo e-mail.');
		return(false);
	}
	if ( f.OnSaleEmail.value!='' && !validEmail(f.OnSaleEmail.value) ) {
		alert('Zadejte prosím platný e-mail.');
		return(false);
	}
	return true;
}

//funkce pro odstranění "bílých" znaků ze začátku a konce řetězce. Je používaná v kontrolních funkcích fomulářů.
function trim(string) {
  return string.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

//funkce pro zobrazení a skrytí prvku identifikovaného parametrem id
function display(id,display) {
  document.getElementById(id).style.display = ( document.getElementById(id).style.display=='none' ) ? display : 'none';
  return false;
}

//otevře okno o daných rozměrech vycentrované na stránce a načte do něj odkaz daný parametrem href
function wopen(href,width,height){

   var sirkaOkna;
   var vyskaOkna;

   with(screen) {
     sirkaOkna=availWidth;
     vyskaOkna=availHeight;
    }

     sirkaOkna -= width;
     sirkaOkna -= 25; //scrollbar
     sirkaOkna /= 2;

     vyskaOkna -= height;
     vyskaOkna /= 2;

     window.open(href,'klip','width='+width+',height='+height+',scrollbars=1,menubar=no,top='+vyskaOkna+',left='+sirkaOkna+'');
}


function array_search(hodnota,pole) {
  var key = false;
  for ( i=0;i<pole.length;i++ ) {
    if ( pole[i] == hodnota ) { key = i; break; }
  }
  return key;
}

function in_array(hodnota,pole) {
  var i;
  var existuje = false;
  for ( i=0;i<pole.length;i++ ) {
    if ( pole[i] == hodnota ) { existuje = true; break; }
  }

  return existuje;
}

function add_classname(item_id,classname) {

  var aktClassNames = new Array();
  var newClassName = '';

  if ( document.getElementById(item_id).className.length>0 ) {
    aktClassNames = aktClassNames.concat(document.getElementById(item_id).className.split(' '));
  }

  if ( classname && !in_array(classname,aktClassNames) ) {
    aktClassNames.push(classname);
  }
  newClassName = aktClassNames.join(' ');
  if ( newClassName!=document.getElementById(item_id).className ) {
    document.getElementById(item_id).className = newClassName;
  }
}

function remove_classname(item_id,classname) {

  var aktClassNames = new Array();
  var newClassName = '';

  if ( document.getElementById(item_id).className.length>0 ) {
    aktClassNames = aktClassNames.concat(document.getElementById(item_id).className.split(' '));
  }

  if ( in_array(classname,aktClassNames) ) {
    aktClassNames.splice(array_search(classname,aktClassNames),1);
  }
  newClassName = aktClassNames.join(' ');
  if ( newClassName!=document.getElementById(item_id).className ) {
    document.getElementById(item_id).className = newClassName;
  }
}


//funkce pro kontrolu údajů v přihlašovacím formuláři
function checkFields_login_form(login_form_id) {
  var form_id = (login_form_id) ? login_form_id : 'login_form_sekce';
	var f = document.getElementById(form_id);
	if (f.login.value == "") { alert('Zadejte prosím přihlašovací jméno.'); return false; }
	if (f.password.value == "") { alert("Zadejte prosím heslo."); return false; }
  return true;
}

//funkce pro kontrolu údajů ve vyhledávacím formuláři
function checkForm_hledat(id_formulare,jaz_ver) {
	var f = document.getElementById(id_formulare);
	f.hledanytext.value = trim(f.hledanytext.value)

	if (f.hledanytext.value == '') {
	  if ( jaz_ver=='SK' ) { alert('Zadajte prosím hľadaný text.'); }
	  else { alert('Zadejte prosím hledaný text.'); }
		return false;
	}
	if (f.hledanytext.value.length<3) {
		if ( jaz_ver=='SK' ) { alert('Hľadaný text musí byť minimálne 3 znaky dlhý.'); }
		else { alert('Hledaný text musí být minimálně 3 znaky dlouhý.'); }
		return false;
	}
	return true;
}

//funkce pro zobrazení potvrzeni
function confirmation(message) {
  return window.confirm(message);
}

//funkce pro ošetření zadání maximálního počtu znaků ve formulářovém poli (zejména textarea)
function maximum_text(object_field, maxlimit, countfield_id) {
	if (object_field.value.length > maxlimit) {
		object_field.value = object_field.value.substring(0, maxlimit);
	}
  else {
		document.getElementById(countfield_id).innerHTML = maxlimit - object_field.value.length;
	}
}


function NewWindow( url, width, height ) {
  	var s

  	s = ""
  	if (width != "" && height != "") {
  		s = ",width=" + width + ",height=" + height
  	}
  	window.open( url, 'productpicture', 'toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,menubar=no,copyhistory=no' + s );
}


/*miminka*/

function zobraz_obrazek(url,window_name,sirka,vyska) {
  okno_fotka = window.open(url,window_name,"width=" + (sirka+100) + ",height=" + (vyska+180) + ",menubar=no,directories=no,toolbar=no,location=no,status=no,scrollbars=yes,resizable=no");
  okno_fotka.focus();
}


//kontrola polí ve formuláři přidání fotky miminka
function checkForm_miminka() {

	var f = document.getElementById('formMiminka');
	f.nazev.value = trim(f.nazev.value);
	f.popis.value = trim(f.popis.value);
	f.datum_foceni.value = trim(f.datum_foceni.value);
	f.fotografie.value = trim(f.fotografie.value);

	if (f.nazev.value == '') {
		alert('Vyplňte prosím pole Název.');
		return(false);
	}
	if (f.fotografie.value == '') {
		alert('Vložte prosím soubor s fotografií.');
		return(false);
	}

  extArray = new Array(".jpeg", ".jpg");

  file = f.fotografie.value
  allowSubmit = false;
  while (file.indexOf("\\") != -1) file = file.slice(file.indexOf("\\") + 1);
  ext = file.slice(file.indexOf('.')).toLowerCase();
  for (var i = 0; i < extArray.length; i++) {
    if (extArray[i] == ext) { allowSubmit = true; break; }
  }

  if ( !allowSubmit ) {
		alert('Fotografie musí být formátu JPG.');
		return(false);
  }


	return true;
}


//otestuje, je-li hodnota celé číslo
function is_int(retezec) {
  var tmp;
  tmp = parseInt(retezec) + "";
  if ( retezec.length==0 ) { return false; }
  else if ( tmp.length!=retezec.length || isNaN(tmp) ) { return false; }
  else { return true; }

}

function is_date(retezec) {

  date_arr = retezec.split('.');
  if ( date_arr.length!=3 ) { return false; }
  
  day = date_arr[0].replace(/^0+/g, ''); //odstranění vedoucích nul
  month = date_arr[1].replace(/^0+/g, ''); //odstranění vedoucích nul
  year = date_arr[2];
  
  if ( !is_int(day) || day<1 || day>31 ) { return false; }
  if ( !is_int(month) || month<1 || month>12 ) { return false; }
  if ( !is_int(year) || year<1 ) { return false; }

  month = month - 1;  // javascript month range : 0- 11

  var tempDate = new Date(year,month,day);
  if ( tempDate.getFullYear()==year && month==tempDate.getMonth() && day==tempDate.getDate() ) { return true; }
  else { return false }
}

function is_time(retezec,are_seconds) {

  time_arr = retezec.split(':');
  if ( are_seconds && time_arr.length!=3 ) { return false; }
  else if ( !are_seconds && time_arr.length!=2 ) { return false; }

  hour = time_arr[0].replace(/^0?/g, ''); //odstranění vedoucí nuly
  minute = time_arr[1].replace(/^0?/g, ''); //odstranění vedoucí nuly
  second = (are_seconds) ? time_arr[2] : '0';

  if ( !is_int(hour) || hour<0 || hour>23 ) { return false; }
  if ( !is_int(minute) || minute<0 || minute>59 ) { return false; }
  if ( !is_int(second) || second<0 || second>59 ) { return false; }

  return true;
}


//kontrola polí ve formuláři editace deníčku
function checkForm_denicek(pocet_fotek) {

	var f = document.getElementById('formDenicek');
	f.datum.value = trim(f.datum.value);
	f.cas.value = trim(f.cas.value);
	f.nadpis.value = trim(f.nadpis.value);
	f.text.value = trim(f.text.value);

	if ( !is_date(f.datum.value) ) {
		alert('Zadejte prosím platný Datum.');
		return(false);
	}
	if ( !is_time(f.cas.value,0) ) {
		alert('Zadejte prosím platný Čas.');
		return(false);
	}
	if (f.nadpis.value == '') {
		alert('Vyplňte prosím pole Nadpis.');
		return(false);
	}

  extArray = new Array(".jpeg", ".jpg");
  allowSubmit = true;

  for ( i=1;i<=pocet_fotek;i++ ) {
    file = f.elements['fotografie_'+i].value;
    if ( !file.length ) { continue; }
    je_pripona = false;
    while (file.indexOf("\\") != -1) file = file.slice(file.indexOf("\\") + 1);
    ext = file.slice(file.indexOf('.')).toLowerCase();
    for (var j = 0; j < extArray.length; j++) {
      if (extArray[j] == ext) { je_pripona = true; break; }
    }
    
    if ( !je_pripona ) { allowSubmit = false; break; }
  }

  if ( !allowSubmit ) {
		alert('Fotografie musí být formátu JPG.');
		return(false);
  }

	return true;
}

/*zobrazování popisů období v kalendáři nenarozených miminek*/
function kal_nenar_display_tyden(id,zobrazit) {
  if ( zobrazit ) {
    document.getElementById('kn_uv_txt').style.display = 'none';
    document.getElementById(id).style.display = 'block';
  }
  else {
    document.getElementById(id).style.display = 'none';
    document.getElementById('kn_uv_txt').style.display = 'block';
  }
  return false;
}


function pt_display_sekce(id) {

  var pt_sekce_ids = new Array('pt_u_lekare','pt_na_uradech','pt_vase_rodina');
  
  for ( i=0;i<=pt_sekce_ids.length-1;i++ ) {
    if ( pt_sekce_ids[i]==id ) {
      display(pt_sekce_ids[i],'block');
    }
    else {
      document.getElementById(pt_sekce_ids[i]).style.display = 'none';
    }
  }

  return false;
}


/*porodnice*/
var por_mapa_bcg_pos = '0px 313px';
var por_mapa_onmouse_counter = 0;

function porodnice_mapa(kolik) {
  if ( !por_mapa_onmouse_counter && document.getElementById('mapa').style.backgroundPosition ) {
    por_mapa_bcg_pos = document.getElementById('mapa').style.backgroundPosition;
  }
  if ( kolik ) {
    document.getElementById('mapa').style.backgroundPosition = "0px -" + ( (kolik*314)-314 ) + "px";
  } else {
    document.getElementById('mapa').style.backgroundPosition = por_mapa_bcg_pos;
  }
  por_mapa_onmouse_counter++;
}
        
function porodnice(ico) {

  var aktClassNames = new Array();

  if ( document.getElementById('por_nazev_tr_' + ico).className.length>0 ) {
    aktClassNames = aktClassNames.concat(document.getElementById('por_nazev_tr_' + ico).className.split(' '));
  }

  if ( in_array('active',aktClassNames) ) {
    remove_classname('por_nazev_tr_' + ico,'active');
    add_classname('por_info_' + ico,'skryte');
    remove_classname('por_nazev_' + ico,'active');
  }
  else {
    add_classname('por_nazev_tr_' + ico,'active');
    remove_classname('por_info_' + ico,'skryte');
    add_classname('por_nazev_' + ico,'active');
  }
}

function checkForm_porodnice_diskuse() {
  var datum = new Date();

	if (trim(document.getElementById('pd_nadpis').value) == '') {
		alert('Zadejte prosím nadpis příspěvku.');
		return false;
	}
	if (trim(document.getElementById('pd_text').value) == '') {
		alert('Zadejte prosím text příspěvku.');
		return false;
	}

	document.getElementById('pd_datetime').value = datum.getFullYear() + "-" + (datum.getMonth()+1) + "-" + datum.getDate() + "-" + datum.getHours() + "-" + datum.getMinutes() + "-" + datum.getSeconds();
	return true;
}

function porodnice_diskuze_re_fill(pd_id,text) {
  document.getElementById('pd_nadpis').value = 'Re: ' + text;
  document.getElementById('pd_answer').innerHTML = 'Odpověď na příspěvěk: "' + text + '"';
  document.getElementById('pd_parent_id').value = pd_id;
  return true;
}


/* bazénová centra */
var baz_mapa_bcg_pos = '0px 313px';
var baz_mapa_onmouse_counter = 0;

function bazeny_mapa(kolik) {
  if ( !baz_mapa_onmouse_counter && document.getElementById('mapa').style.backgroundPosition ) {
    baz_mapa_bcg_pos = document.getElementById('mapa').style.backgroundPosition;
  }
  if ( kolik ) {
    document.getElementById('mapa').style.backgroundPosition = "0px -" + ( (kolik*314)-314 ) + "px";
  } else {
    document.getElementById('mapa').style.backgroundPosition = baz_mapa_bcg_pos;
  }
  baz_mapa_onmouse_counter++;
}

function bazeny(ico) {

  var aktClassNames = new Array();

  if ( document.getElementById('baz_nazev_tr_' + ico).className.length>0 ) {
    aktClassNames = aktClassNames.concat(document.getElementById('baz_nazev_tr_' + ico).className.split(' '));
  }

  if ( in_array('active',aktClassNames) ) {
    remove_classname('baz_nazev_tr_' + ico,'active');
    add_classname('baz_info_' + ico,'skryte');
    remove_classname('baz_nazev_' + ico,'active');
  }
  else {
    add_classname('baz_nazev_tr_' + ico,'active');
    remove_classname('baz_info_' + ico,'skryte');
    add_classname('baz_nazev_' + ico,'active');
  }
}

function checkForm_bazeny_diskuse() {
  var datum = new Date();

	if (trim(document.getElementById('pd_nadpis').value) == '') {
		alert('Zadejte prosím nadpis příspěvku.');
		return false;
	}
	if (trim(document.getElementById('pd_text').value) == '') {
		alert('Zadejte prosím text příspěvku.');
		return false;
	}

	document.getElementById('pd_datetime').value = datum.getFullYear() + "-" + (datum.getMonth()+1) + "-" + datum.getDate() + "-" + datum.getHours() + "-" + datum.getMinutes() + "-" + datum.getSeconds();
	return true;
}

function bazeny_diskuze_re_fill(pd_id,text) {
  document.getElementById('pd_nadpis').value = 'Re: ' + text;
  document.getElementById('pd_answer').innerHTML = 'Odpověď na příspěvěk: "' + text + '"';
  document.getElementById('pd_parent_id').value = pd_id;
  return true;
}
