if (top!=self){
        alert('The URL '+self.location.href+' cannot be viewed inside a frame ('+top.location.href+').  You will be redirected.');
        top.location.href=self.location.href;
}

function okno(page)
{
  if(window.open(page,"Administrace","width=500,height=500,menubar=no,directories=no,toolbar=no,location=no,status=no,scrollbars=yes,resizable=no")) return false;
  else return true;
}

function stranka(page) {
  return window.open(page);
}

function num()
{
  with (event)
    if (keyCode<48 || keyCode>57) returnValue=false;
}


function HideIt()
{
  document.getElementById('required').style.visibility= "hidden";
  document.getElementById('requiredtext').style.visibility= "hidden";
}


function ShowIt(theField,theMessage)
{
  if(document.getElementById) {
    document.getElementById('required').style.visibility= "visible";
    document.getElementById('requiredtext').innerHTML= theMessage;
    document.getElementById('requiredtext').style.visibility= "visible";
    setTimeout( "HideIt()",1500);
  } else {
    alert(theMessage);
  }
  theField.focus();
}


function kontrola(f)
{

  if (f.login.value == "") {
    ShowIt(f.login,"Vyplňte pole <b>login</b>!");
    return false;
  }

  if (f.passwd.value == "") {
    ShowIt(f.passwd,"Vyplňte pole <b>Heslo</b>!");
    return false;
  }

  if (f.passwd2.value == "") {
    ShowIt(f.passwd2,"Vyplňte pole <b>Potvrzení hesla</b>!");
    return false;
  }

  if (f.passwd.value != f.passwd2.value) {
    ShowIt(f.passwd,"Zadaná hesla se <b>neshodují</b>!");
    return false;
  }

  if (f.email.value == "") {
    ShowIt(f.email,"Vyplňte pole <b>Email</b>!");
    return false;
  }
}


function fon(prvek)
{
  document.getElementById(prvek).style.fontWeight="bold";
}

function foff(prvek)
{
  document.getElementById(prvek).style.fontWeight="normal";
}


function time()
{
  dnes = new Date();
  
  with (dnes)
  {
    den = getDate();
    mesic = getMonth() + 1;
    rok = getFullYear();
    hodina = getHours();
    minuta = getMinutes();
  }
  
  window.document.getElementById('date').value = den + '.' + mesic + '.' + rok;
  window.document.getElementById('time').value = hodina + (minuta < 10 ? ":0" : ":") + minuta;

//  window.setTimeout("time();",1000);
}





/** odeslání XMLHttp požadavku 
@param function obsluha funkce zajišťující obsluhu při změně stavu požadavku, dostane parametr s XMLHttp objektem 
@param string method GET|POST|... 
@param string url URL požadavku 
@param string [content] tělo zprávy 
@param array [headers] pole předaných hlaviček ve tvaru { 'hlavička': 'obsah' } 
@return bool true v případě úspěchu, false jinak 
*/ 
function send_xmlhttprequest(obsluha, method, url, content, headers) { 
  var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false)); 
  if (!xmlhttp) { 
    return false; 
  } 
  xmlhttp.open(method, url); 
  xmlhttp.onreadystatechange = function() { 
    obsluha(xmlhttp); 
  }; 
  if (headers) { 
    for (var key in headers) { 
      xmlhttp.setRequestHeader(key, headers[key]); 
    } 
  } 
  xmlhttp.send(content); 
  return true; 
}

function hlasovat(id, body) { 
  // kontrola preklepu
  if (body == "0" || body == "1") {
    var x = confirm("Vaše hodnocení je poměrně nízké: "+body+"*\nChcete pokračovat?");
    if (!x) return true;
  }
  
  // odeslání požadavku na aktualizaci dat  
  if (!send_xmlhttprequest(anketa_obsluha, 'GET', '/admin/save_hodn_photo.php?id='+id+'&hodn='+body+'&typ=JS')) { 
    return false; 
  } 
  document.getElementById('hodnoceni').innerHTML = 'Děkujeme za Váš hlas.'; 
  return true; 
} 

function anketa_obsluha(xmlhttp) { 
  if (xmlhttp.readyState == 4) { 
   // aktualizace odpovědí na základě aktuálního stavu  
 //   document.getElementById('nic').style.display = 'none';
    document.getElementById('body').style.display = 'block';

    var odpovedi = xmlhttp.responseXML.getElementsByTagName('odpoved'); 
	var x = 0;
	var obj;
    for (var i=0; i < odpovedi.length; i++) { 
	try{
        document.getElementById(odpovedi[i].getAttribute('id')).innerHTML = odpovedi[i].firstChild.data; // //xmlhttp.responseText; //
		if (odpovedi[i].getAttribute('id') == 'rating_a') {
			x = odpovedi[i].firstChild.data;
			document.getElementById('drating_a1').style.width = x*10+"px";
			document.getElementById('drating_a2').style.width = (10-x)*10+"px";
		}else if (odpovedi[i].getAttribute('id') == 'rating_n') {
			x = odpovedi[i].firstChild.data;
			document.getElementById('drating_n1').style.width = x*10+"px";
			document.getElementById('drating_n2').style.width = (10-x)*10+"px";
		}
      }catch(err){
	
	}
	} 
    document.getElementById('hodnoceni').innerHTML = '<span style="color: green;">Uloženo</span>'; 
  } 
}

function hit_com(idp,idc,value) {
  
var nameofobject = 'com_karma'+idc;
  if (!send_xmlhttprequest(hit_com_handler, 'GET', '/admin/hit.php?typ='+idp+'&idc='+idc+'&rank='+value+'&zpusob=JS')) { 
    return false; 
  } 

  document.getElementById(nameofobject).innerHTML = 'Ukládá se ...'; 
  return true; 
}

function hit_com_handler(xmlhttp) { 
	 if(xmlhttp.readyState == 4 && xmlhttp.status==200) {
	  //var x = "";
	  //var idc;
	  
	  var odpovedi = xmlhttp.responseXML.getElementsByTagName('odpoved');
      for (i=0;i<odpovedi.length;i++) {
		 try{
			if (odpovedi[i].getAttribute('id') == 'error'){
				var x = odpovedi[i].firstChild.data;
				alert(x);
			}
			if (odpovedi[i].getAttribute('id') == 'resp'){
				var x = odpovedi[i].firstChild.data;
			}
			if (odpovedi[i].getAttribute('id') == 'idc'){
				var idc = odpovedi[i].firstChild.data;
				document.getElementById(idc).innerHTML = "Děkujeme"; 
			}
		}catch(err){
			alert("chyba"+err);
		}
	  }
	}
}

function mailSend(txt)
{
  txt = txt.replace(/\(zavinac\)/,"@");
  return txt;
}

function valid_form_com() {
  if(document.getElementById('zprava').value == '') {
    document.getElementById('l_n').innerHTML='';
    document.getElementById('l_t').innerHTML='<strong style="color: red;">Napište nějakou zprávu.</strong>';
    return false;
  }
  else { 
/*   document.getElementById('subm').style.visibility='hidden'; */
    document.getElementById('l_t').innerHTML='<strong style="color: green;">Zpráva se odesílá...</strong>';
    return true;
  }
}

function reagovat(id, typ, autor) {
  if(autor == 1 || confirm('[O] je určeno pro rychlou reakci autora článku na dotaz čtenáře nebo pro usměrnění motykovců. NENÍ(!) určeno pro běžné diskuzní příspěvky, u kterých lze očekávat další odpovědi.\n\nPokračovat v odpovědi?')) {
    if(document.getElementById('re')) {
      var x = 'obsah_'+id;
      txt = document.getElementById(x).innerHTML;
      document.getElementById('l_n').innerHTML='<strong>Odpověď na: </strong>';
      document.getElementById('l_t').innerHTML=txt;
      document.getElementById('edit').value='';
      document.getElementById('re').value=id;
      document.getElementById('zprava').value='';
      document.getElementById('zprava').focus();
      return false;
    }
    else return true;
  }
  else return false;
}

function reset_form() {
  if(document.getElementById('re')) {
    document.getElementById('l_n').innerHTML='';
    document.getElementById('l_t').innerHTML='';
  }
}

function getHTTPObject() {
  http_request = false;

  if (window.XMLHttpRequest) {
    http_request = new XMLHttpRequest();
  } else if (window.ActiveXObject) { // IE
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
  }
  return http_request;
}

var ohttp = getHTTPObject(); // We create the HTTP Object
var txt = "";
function editovat(id,typ) {
  if(document.getElementById('re')) {
    if (!isWorking && ohttp) {
      var x = 'obsah_'+id;
      document.getElementById('edit').value=id;
      txt = document.getElementById(x).innerHTML;
      document.getElementById('l_t').innerHTML='Načítám text...';
      document.getElementById('zprava').value='';
      ohttp.open("GET", "/admin/getComment.php?id=" + escape(id) + "&typ=" + escape(typ), true);
      ohttp.onreadystatechange = handleHttpResponse;
      isWorking = true;
      ohttp.send(null);
      document.getElementById('zprava').focus();
      document.getElementById('re').value='';
      return false;
    }
    else return true;
  }
  else return true;
}

function handleHttpResponse() {
  if (ohttp.readyState == 4) {
    if (ohttp.responseText.indexOf('invalid') == -1) {
      var ret = ohttp.responseText;
      if(ret.indexOf('timeout') >= 0) {
        document.getElementById('edit').value='';
        document.getElementById('zprava').value='';
        document.getElementById('l_t').innerHTML='<span style="color: red;">Limit 30 minut na editaci komentu bohužel již vypršel.</span>';
        document.getElementById('l_n').innerHTML='';
      }
      else {
        document.getElementById('l_n').innerHTML='<strong>Původní text: </strong>';
        document.getElementById('l_t').innerHTML=txt;
        document.getElementById('zprava').value=ret;
      }
      isWorking = false;
    }
  }
}


var nhttp = getHTTPObject(); // We create the HTTP Object
function formatuj() {
  if(document.getElementById('re')) {
    if (!isWorking && nhttp) {
      txt = document.getElementById('zprava').value;
      document.getElementById('l_n').innerHTML='<strong>Náhled zprávy: </strong>';
      document.getElementById('l_t').innerHTML='Formátuji text...';
      nhttp.open("POST", "/admin/formatComment.php?", true);
      nhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      nhttp.send('zprava='+escape(txt));
      nhttp.onreadystatechange = handleHttpResponse2;
      isWorking = true;
//     nhttp.send(null);
      document.getElementById('zprava').focus();
      return false;
    }
    else return true;
  }
  else return true;
}

function handleHttpResponse2() {
  if (nhttp.readyState == 4) {
    if (nhttp.responseText.indexOf('invalid') == -1) {
      document.getElementById('l_t').innerHTML=unescape(nhttp.responseText);
      isWorking = false;
    }
  }
}
var isWorking = false;





/* (c) COPYRIGHT http://www.qark.net */
function vloz_tag(znacka){
  var spravne=false;
  
  switch (znacka){
    case "b":
    case "i":
    case "u":
      start="["+znacka+"]";
      end="[/"+znacka+"]";
      spravne=true;
    break;
  }
  
  if (spravne){
    if (document.selection) { // IE
      document.getElementById('zprava').focus();
      sel = document.selection.createRange();
     
      sel.text = start + sel.text + end;
      document.getElementById('zprava').focus();
    } else if (document.getElementById('zprava').selectionStart || document.getElementById('zprava').selectionStart == '0') { // Gecko
      var startPos = document.getElementById('zprava').selectionStart;
      var endPos = document.getElementById('zprava').selectionEnd;
      var cursorPos=endPos;
      if (startPos != endPos) {
        document.getElementById('zprava').value = document.getElementById('zprava').value.substring(0, startPos) + start + document.getElementById('zprava').value.substring(startPos, endPos) + end + document.getElementById('zprava').value.substring(endPos, document.getElementById('zprava').value.length);
        cursorPos += end.length;
      } else {
        document.getElementById('zprava').value = document.getElementById('zprava').value.substring(0, startPos) + start + end + document.getElementById('zprava').value.substring(endPos, document.getElementById('zprava').value.length);
      }
      cursorPos += start.length;
      document.getElementById('zprava').focus();
      document.getElementById('zprava').selectionStart = cursorPos;
      document.getElementById('zprava').selectionEnd = cursorPos;
    } else { //ostatni
      document.getElementById('zprava').value += start+end;
      document.getElementById('zprava').focus();
    }
  }
}

function refresh_login() {
    $.ajax({
        url:   '/admin/refresh.php',
        type:  'GET',
        data:  'ajax=1',
        cache: false,
        async: false
    });
}