// VKLÁDÁNÍ TEXTU DO TEXTAREA - START

	function insertAtCaret(obj, text) {
		if(document.selection) {
			obj.focus();
			var orig = obj.value.replace(/\r\n/g, "\n");
			var range = document.selection.createRange();

			if(range.parentElement() != obj) {
				return false;
			}

			range.text = text;
			
			var actual = tmp = obj.value.replace(/\r\n/g, "\n");

			for(var diff = 0; diff < orig.length; diff++) {
				if(orig.charAt(diff) != actual.charAt(diff)) break;
			}

			for(var index = 0, start = 0; 
				tmp.match(text) 
					&& (tmp = tmp.replace(text, "")) 
					&& index <= diff; 
				index = start + text.length
			) {
				start = actual.indexOf(text, index);
			}
		} else if(obj.selectionStart) {
			var start = obj.selectionStart;
			var end   = obj.selectionEnd;

			obj.value = obj.value.substr(0, start) 
				+ text 
				+ obj.value.substr(end, obj.value.length);
		}
		
		if(start != null) {
			setCaretTo(obj, start + text.length);
		} else {
			obj.value += text;
		}
	}
	
	function setCaretTo(obj, pos) {
		if(obj.createTextRange) {
			var range = obj.createTextRange();
			range.move('character', pos);
			range.select();
		} else if(obj.selectionStart) {
			obj.focus();
			obj.setSelectionRange(pos, pos);
		}
	}

// VKLÁDÁNÍ TEXTU DO TEXTAREA - END


function zobrazSkryj(idecko){
  el=document.getElementById(idecko).style;
  el.display=(el.display == 'block')?'none':'block';
}

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();
}

function zobrazPrispevek(idecko, typ, obrazek_id) {
    var z = document.getElementById(idecko).style;
    var img = document.getElementById(obrazek_id);

    if (z.display == "none") {
      z.display = typ;
      img.src = "../images/layout/sipky_blue_down.gif";
    } else {
      z.display = "none";
      img.src = "../images/layout/sipky_blue_right.gif";
    }
}

function zobrazFAQ(idecko, typ, obrazek_id) {
    var z = document.getElementById(idecko).style;
    var img = document.getElementById(obrazek_id);

    if (z.display == "none") {
      z.display = typ;
      img.src = "../images/layout/sipky_green_down.gif";
    } else {
      z.display = "none";
      img.src = "../images/layout/sipky_green_right.gif";
    }
}

kn_last = 0;
function ukaz_kn (kn_objekt)
  {
  if (kn_last == kn_objekt)
     {
     document.getElementById("kn_but_"+kn_objekt).className = "button";
     document.getElementById("kn_"+kn_objekt).className = "nevidet";
     document.getElementById("kn_0").className = "";
     kn_last = 0;
     return false;
     }
  else
     {
     document.getElementById("kn_"+kn_last).className = "nevidet";
     if (kn_last != 0)
        document.getElementById("kn_but_"+kn_last).className = "button";
     kn_last = kn_objekt;
     document.getElementById("kn_but_"+kn_objekt).className = "button_hover";
     document.getElementById("kn_"+kn_objekt).className = "";
     return false;
     }
  }
  
function display(id,display) {
  document.getElementById(id).style.display = ( document.getElementById(id).style.display=='none' ) ? display : 'none';
  return false;
}

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+',menubar=no,top='+vyskaOkna+',left='+sirkaOkna+'');
}

/*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;
}

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;
  }
}



var hvezdy_old = new Array();

function hlasovani(img, poradi) {
    var counter = poradi;
    var img_curent = img.parentNode;
    
    while (img_curent != null) {
        counter--;
        hvezdy_old[counter] = img_curent.firstChild.src;
        img_curent.firstChild.src = "../images/hlas_hvezda_plna.gif";
        img_curent = img_curent.previousSibling;
    }

    var img_curent = img.parentNode.nextSibling;
    counter = poradi-1;

    while (img_curent != null) {
        counter++;
        hvezdy_old[counter] = img_curent.firstChild.src;
        img_curent.firstChild.src = "../images/hlas_hvezda_prazdna.gif";
        img_curent = img_curent.nextSibling;
    }


}

function hlasovani_out(img, poradi) {
    var counter = poradi;
    var img_curent = img.parentNode;
    
    while (img_curent != null) {
        counter--;
        img_curent.firstChild.src = hvezdy_old[counter];
        img_curent = img_curent.previousSibling;
    }

    img_curent = img.parentNode.nextSibling;
    var counter = poradi-1;

    while (img_curent != null) {
        counter++;
        img_curent.firstChild.src = hvezdy_old[counter];
        img_curent = img_curent.nextSibling;
    } 
  
    hvezdy_old = new Array();

}





// function hlasovani(span) {
//     var hvezdy = span.getElementsByTagName("img");
// 
//     for (var i = 0; i < hvezdy.length; i++) {
//         hvezdy_old[i] = hvezdy[i].src;
//     }
// 
//     for (var i = 0; i < hvezdy.length; i++) {
//         hvezdy[i].onmouseover = function() {
//             this.src = "../images/hlas_hvezda_plna.gif";
//         
//         }
// //         hvezdy[i].onmouseout = function() {
// //             this.src = "../images/hlas_hvezda_prazdna.gif";
// //         
// //         }
//     }
//     
// }
// 
// function hlasovani_out(span) {
// //     alert("aaa");
//     var hvezdy = span.getElementsByTagName("img");
// 
//     if (hvezdy.length > 0) {
//         for (var i = 0; i < hvezdy.length; i++) {
//             hvezdy[i].src = hvezdy_old[i];
//         }
//         
//         hvezdy_old = new Array();
//     }
// 
// }













