function zavrit_poutac()
{
 document.getElementById('poutac_registrace').style.display='none';
 nastav_cookie(1);
}
function readCookie(name) {
 var nameEQ = name + "=";
 var ca = document.cookie.split(';');
 for(var i=0;i < ca.length;i++) {
  var c = ca[i];
  while (c.charAt(0)==' ') c = c.substring(1,c.length);
  if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
 }
 return null;
}
var sql_dotaz;
function edituj(editovan, editovanPrvek,typ)
{
 $(".editovatelnyText").de77_wysiwyg();
 $("#b_uloz").show();
 $("#b_edituj").hide();
 $(".adminEditace").css("height", 150).css("width", "100%");
 if(typ==1)
  sql_dotaz = "SELECT * FROM "+editovan+" WHERE nazev = '" + editovanPrvek + "'";
 else
  sql_dotaz = "SELECT popis,titulek,klice as 'keys', url as 'url-nazev' FROM "+editovan+" WHERE nazev = '" + editovanPrvek + "'";
 $.post('php/edit_gen_stranek.php', {
  sql: sql_dotaz
 }, function(data) {
  $('#editPolozky').html(data);
 });
}

function uloz(editovan, editovanPrvek, typ){
 $("#b_edituj").show();
 $("#b_uloz").hide();
 $(".adminEditace").css("height", 30).css("width", 290);
 $(".editovatelnyText").de77_wysiwyg(false);
 if(typ==1)
  sql_dotaz = "UPDATE " + editovan +
  " SET `keys` ='" + $('textarea[name=klice]').val() +
  "', `text` = '" + $('div[class=editovatelnyText]').html()+
  "', `titulek` = '" + $('input[name=titulek]').val()+
  "', `url-nazev` = '" + $('input[name=url]').val()+
  "', `popis` = '" + $('textarea[name=popis]').val()+ "' WHERE nazev = '"+ editovanPrvek+"'";
 else
  sql_dotaz = "UPDATE " + editovan +
  " SET `klice` ='" + $('textarea[name=klice]').val() +
  "', `text` = '" + $('div[class=editovatelnyText]').html()+
  "', `titulek` = '" + $('input[name=titulek]').val()+
  "', `url` = '" + $('input[name=url]').val()+
  "', `popis` = '" + $('textarea[name=popis]').val()+ "' WHERE nazev = '"+ editovanPrvek+"'";
 $.post('php/sql_edit.php', {
  sql: sql_dotaz
 }, function(data) {
  alert("Uloženo!");
 });
}

function nastav_cookie(dny)
{
 var date = new Date();
 date.setTime(date.getTime()+(dny*24*60*60*1000));
 var expires = "; expires="+date.toGMTString();
 document.cookie = "visit"+"="+"ano"+expires+"; path=/";
}


function kontrola_uzivatele()
{
 if(readCookie("visit")!="ano")
 {
// document.getElementById('poutac_registrace').style.display='block';
}  
}
function info_o_kosiku()
{
 document.getElementById('zprava_kosik').style.display="block";
 setTimeout("document.getElementById('zprava_kosik').style.display='none';", 4000);
}
function locati(loc)
{
 location = "index.php?menu=produkty&dod="+pom+"&p="+kategor+"&k="+loc+"&pod="+pod;
}
function kurz(value)
{
 location = location.href+"&mena="+value;
}
function kategorie(kategorie)
{
 location = "index.php?menu=produkty&dod="+pom+"&p="+kategorie+"&k="+k+"&pod="+pod;
}
function prejdi(url)
{
 location = url;
}
function dodavatel(id)
{
 kontrola_uzivatele();
 document.getElementById('dd1').style.display="none";
 document.getElementById('dd2').style.display="none";
 document.getElementById('dd3').style.display="none";
 document.getElementById('dddod').style.backgroundColor="#FFD077";
 document.getElementById('ddd1').style.backgroundColor="#FFD077";
 document.getElementById('ddd2').style.backgroundColor="#FFD077";
 document.getElementById('ddd3').style.backgroundColor="#FFD077";
 document.getElementById('dd'+id).style.backgroundColor="#E19300";
 document.getElementById('dddod').style.fontWeight="";
 document.getElementById('ddd1').style.fontWeight="";
 document.getElementById('ddd2').style.fontWeight="";
 document.getElementById('ddd3').style.fontWeight="";
 document.getElementById('dd'+id).style.fontWeight="bold";

 pom=id;
 if(id=="dod") document.getElementById('obrazek_vyrobce').innerHTML = '&nbsp;';
 else if(id=="d1") document.getElementById('obrazek_vyrobce').innerHTML = '<img src=\"grafika/dodavatel3.gif\" height=\"160\" width=\"133\" border=\"0\">';
 else if(id=="d2") document.getElementById('obrazek_vyrobce').innerHTML = '<img src=\"grafika/dodavatel1.gif\" height=\"140\" width=\"148\" border=\"0\">';
 else if(id=="d3") document.getElementById('obrazek_vyrobce').innerHTML = '<img src=\"grafika/dodavatel2.gif\" width=\"148\" border=\"0\">';
}
function prep(id,id2)
{
 document.getElementById('pre'+id).style.display="block";
 document.getElementById('pre'+id2).style.display="none";
 document.getElementById('prep'+id).style.backgroundColor="#FFD077";
 document.getElementById('prep'+id2).style.backgroundColor="white";
}
var znacka="";
function znacky(id)
{
 if(znacka==id)
 {
  document.getElementById(id).style.display="none";
  znacka="";
 }
 else
 {
  znacka=id;
  document.getElementById('mediterranean').style.display="none";
  document.getElementById('terme').style.display="none";
  document.getElementById('angel').style.display="none";
  document.getElementById(id).style.display="block";
 }
}
function zobraz2(id)
{
 el=document.getElementById(id).style;
 el.display="block";
}
function skryj2(id)
{
 el=document.getElementById(id).style;
 el.display="none";
}
function ShowDialog() {
 dd=(screen.width-600)/2;
 vv=(screen.height-400)/2-100;
 dialogWindow=window.open("slovnik.php", "Slovník", "dependent=yes,menubar=no,location=no,toolbar=no,width=600,height=400,left="+dd+",top="+vv+"");
}

function obrazek(id){}
function obrazek2(id){}
var leftt=0;
var topp=0;
function zobraz(pommm)
{
 idImg = document.getElementById('pozice'+pommm);
 idImg.style.position = "relative";
 idImg = document.getElementById('obr'+pommm);
 idImg.style.position = "absolute";
 idImg.style.display = "";
}
function skryj(pommm)
{
 idImg = document.getElementById('pozice'+pommm);
 idImg.style.position = "";
 idImg = document.getElementById('obr'+pommm);
 idImg.style.position = "";
 idImg.style.display = "none";
}
function insertAroundSelection(obj,startVal,endVal)
{
 var o = obj;
 o.focus();
 if (document.selection)
 {
  sel = document.selection.createRange();
  var selText = sel.text;
  sel.text = startVal + selText + endVal;
  
 }
 else if (o.selectionStart || o.selectionStart == '0')
 {
  var startPos = o.selectionStart;
  var endPos = o.selectionEnd;
  o.value = o.value.substring(0,startPos) + startVal + o.value.substring(startPos,endPos) + endVal + o.value.substring(endPos,o.value.length);
  setCursorPos (document.formular.text, startPos,startPos);
 }
 else
 {
  o.value += startVal + endVal;
  setCursorPos (document.formular.text, startPos, startPos);
 }
} 

function review() {
 var tmp=document.all.text.value;
 document.all.preview.innerHTML=tmp;
}






function datosServidor() {
};
datosServidor.prototype.iniciar = function() {
 try {
  // Mozilla / Safari
  this._xh = new XMLHttpRequest();
 } catch (e) {
  // Explorer
  var _ieModelos = new Array(
   'MSXML2.XMLHTTP.5.0',
   'MSXML2.XMLHTTP.4.0',
   'MSXML2.XMLHTTP.3.0',
   'MSXML2.XMLHTTP',
   'Microsoft.XMLHTTP'
   );
  var success = false;
  for (var i=0;i < _ieModelos.length && !success; i++) {
   try {
    this._xh = new ActiveXObject(_ieModelos[i]);
    success = true;
   } catch (e) {
   // Implementar manejo de excepciones
   }
  }
  if ( !success ) {
   // Implementar manejo de excepciones, mientras alerta.
   return false;
  }
  return true;
 }
}

datosServidor.prototype.ocupado = function() {
 estadoActual = this._xh.readyState;
 return (estadoActual && (estadoActual < 4));
}

datosServidor.prototype.procesa = function() {
 if (this._xh.readyState == 4 && this._xh.status == 200) {
  this.procesado = true;
 }
}

datosServidor.prototype.enviar = function(urlget,datos) {
 if (!this._xh) {
  this.iniciar();
 }
 if (!this.ocupado()) {
  this._xh.open("GET",urlget,false);
  this._xh.send(datos);
  if (this._xh.readyState == 4 && this._xh.status == 200) {
   return this._xh.responseText;
  }
		
 }
 return false;
}



function rateImg(rating,imgId )  {
 if(readCookie("vyrobek-"+imgId)!="true")
 {

  var date = new Date();
  date.setTime(date.getTime()+(365*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();
  document.cookie = "vyrobek-"+imgId+"="+"true"+expires+"; path=/";
  
  
  remotos = new datosServidor;
  nt = remotos.enviar('include/update-hodnoceni.php?rating='+rating+'&imgId='+imgId );
  //alert ('include/update-hodnoceni.php?rating='+rating+'&imgId='+imgId);
  rating = (rating * 25) - 5;
  document.getElementById('current-rating').style.width = rating+'px';
  document.getElementById('ratingtext').innerHTML = 'Děkujeme za hodnocení!';
 }
 else
  document.getElementById('ratingtext').innerHTML = 'Tento výrobek jste již hodnotil/a!';
}

function scrollWin(elem){
 $('html, body').animate({
  scrollTop: $(elem).offset().top
 },1000, "swing");
}

function smaz_kom(id,cookie){
 remotos = new datosServidor;
 nt = remotos.enviar('include/delete-komentar.php?id='+id+'&cookie='+cookie );
 location.href="";
}


