// JavaScript Document
// MAIN JAVASRIPT for web Media-M.sk
// Copyright 2010 by Tibor Engler
// All rights reserved. Any unabled copy of this code, or part of this code could be punished.
      
var code, parm, data, id, xmlDoc, timerObject, timerId = null;

function sndReq(codex, parmx, datax) { 
	code = codex;
	parm = parmx;  
	data = datax;

$.ajax({
   type: "POST",
   url: "urob.php",
   data: "code="+code+"&parm="+parm+"&data="+data,
   success: function(xmlDoc){
     handleResponse(xmlDoc);
   }
 });
 
}

function handleResponse(xmlDoc){
 if (parm!="register" && parm!="loadfile" && parm!="loadinform" && parm!="LoadUser" && parm!="isimage"){
  alert(xmlDoc);
 }
 if (parm=="revision" || parm=="deletemessTS" || parm=="clrenew" || parm=="cldelete" || parm=="delinform" || parm=="delforummess" || parm=="createtopic" || parm=="delforumtopic" || parm=="deletecomment" || parm=="deletecommentgallery" || parm=="delfile"){
  location.reload();
  location.href = location.href;
 }
 if (parm=="register"){
  if (xmlDoc=='\n\nallright' || xmlDoc=='\n\n**allright'){
   document.getElementById('registerfinish').style.display ='block';
   document.getElementById('register').style.display = 'none';
   document.getElementById('right-img').style.display = 'none';
  }else{
  alert(xmlDoc);
  document.getElementById('waitimg').style.visibility = 'hidden';
  }
 }
 if (parm=="isimage"){
 document.getElementById("loading").style.visibility = 'hidden';
  xmlDoc.replace("\n","");
  if (xmlDoc=='nok' || xmlDoc=='\n\nnok'){
   document.getElementById("showimghlaskaok").style.display = 'none';
   document.getElementById("showimghlaskanok").style.display = 'block';
  }
  else{
  document.getElementById("showimage").src = xmlDoc;
  document.getElementById("showimghlaskaok").style.display = 'block';
  document.getElementById("showimghlaskanok").style.display = 'none';
  }
 }
 if (parm=="loadfile"){
	CKEDITOR.instances['editorK1'].setData(xmlDoc);
	document.getElementById("newLib").style.display = 'hidden';
  document.getElementById("editLib").style.display = 'block';
  document.getElementById("loading").style.visibility = 'hidden';
  }
   if (parm=="loadinform"){
  xmlDoc = xmlDoc.replace("<div class=\"article-info2\">", "*/");
  xmlDoc = xmlDoc.replace("<h2>", "*/");
  xmlDoc = xmlDoc.replace("</h2>", "*/");
  xmlDoc = xmlDoc.replace("</div><!-- /article-info2 -->", "*/");
   var brokenstring=xmlDoc.split("*/*/");
   document.getElementById('nadpisedit').value = brokenstring[1];
	CKEDITOR.instances['editorK1'].setData(brokenstring[2]);
	document.getElementById("newInfo").style.display = 'hidden';
  document.getElementById("editInfo").style.display = 'block';
  document.getElementById("loading").style.visibility = 'hidden';
  }
 if (parm=="LoadUser"){
     //  document.getElementById('edituser').style.display = "block";
       eval(xmlDoc);
							for (x in u)
						{
						
							if (document.getElementById("e" + x))
							{
							  if (u[x]=='1' || u[x]=='0'){
								if (u[x]==1)
								{
									document.getElementById("e" + x).checked = true;
								}
								else
								{
									document.getElementById("e" + x).checked = false;
								}
							}
							else{
               document.getElementById("e" + x).value = u[x];
              }
						 }
						
						if (u[21]!=""){
             document.getElementById('xcheckbox').checked = true;
             if (document.getElementById('e21').value==""){
            // showhidetr('xfunction');
            document.getElementById('xfunction').style.display = 'block';
             }
            }
            else{
             document.getElementById('xfunction').style.display = 'none';
             document.getElementById('xcheckbox').checked = false;
             document.getElementById('e21').value = "";
            }
            						 
						}
  } 
}



function revision(codex, datax, datac){
 code = codex;
 data = datax+"**"+datac;
 if (datax=="zverejnit"){
  if (confirm("Naozaj chcete tento článok zverejniť?")==true){
   sndReq(code,'revision',data)
  }
 }
 if (datax=="zahodit"){
  if (confirm("Naozaj chcete tento článok zahodiť? (tj. úplne zmazať)")==true){
   sndReq(code,'revision',data)
  }
 }

}

function delts(codex, datax){
 if (confirm("Naozaj si prajete tento príspevok nenávratne odstrániť?")==true){
  code = codex;
  data = datax;
  sndReq(code,'deletemessTS',data);
 }
 else{
  alert('Operácia bola stornovaná!');
 }
}

function delfile(codex, datax){
 if (confirm("Naozaj si prajete odstrániť tento súbor?")==true){
  code = codex;
  data = datax;
  sndReq(code,'delfile',data);
 }
 else{
  alert('Operácia bola stornovaná!');
 }
}
function delinform(codex, datax){
 if (confirm("Naozaj si prajete odstrániť tento súbor?")==true){
  code = codex;
  data = datax;
  sndReq(code,'delinform',data);
 }
 else{
  alert('Operácia bola stornovaná!');
 }
}
function delimg(codex, datax){
 if (confirm("Naozaj si prajete odstrániť tento obrázok?")==true){
  code = codex;
  data = datax;
  sndReq(code,'delimg',data);
 }
 else{
  alert('Operácia bola stornovaná!');
 }
}
function loadfile(codex, datax){
document.getElementById("loading").style.visibility = 'visible';
code = codex;
data = datax;
document.getElementById("filename").value = data;
  sndReq(code,'loadfile',data);
}
function loadinform(codex, datax){
document.getElementById("loading").style.visibility = 'visible';
code = codex;
data = datax;
document.getElementById("filename").value = data;
  sndReq(code,'loadinform',data);
}

function LoadUser(codex, datax){
  code = codex;
  data = datax;
  if (data!="" && data!="-"){
  document.getElementById('id').value = data;
   sndReq(code,'LoadUser',data);
  }
}

function saveinfo(codex){
code = codex;
data = "";
for (i=0; i<=5; i++){
 data += document.getElementById("e"+i).value + "**";
}
for (i=6;i<=20;i++)
{
						document.getElementById("e"+i).checked ? s = 1 : s = 0;
						data += s + "**";
}
data += document.getElementById("e21").value + "**";
data += document.getElementById("selname").value + "**";
sndReq(code,'saveinfo',data);

}

function deluser(codex){
 code = codex;
 data = document.getElementById("selname").value;
 if (confirm("Skutočne si prajete absolútne odstrániť tohto užívateľa?")==true){
  sndReq(code,'deluser',data);
 }
 else{
  alert('Zrušené!');
 }
 
}

function isimage(codex,datax){
  code = codex;
  data = datax;
  document.getElementById("loading").style.visibility = 'visible';
  sndReq(code,'isimage',data); 
  
}

function delcom(codex, datax){
 if (confirm("Naozaj si prajete tento komentár nenávratne odstrániť?")==true){
  code = codex;
  data = datax;
  sndReq(code,'deletecomment',data);
 }
 else{
  alert('Operácia bola stornovaná!');
 }
}
	
function delgalcom(codex, datax){
 if (confirm("Naozaj si prajete tento komentár nenávratne odstrániť?")==true){
  code = codex;
  data = datax;
  sndReq(code,'deletecommentgallery',data);
 }
 else{
  alert('Operácia bola stornovaná!');
 }
}

function delforummess(codex, datax){
 if (confirm("Naozaj si prajete tento príspevok nenávratne odstrániť?")==true){
  code = codex;
  data = datax;
  sndReq(code,'delforummess',data);
 }
 else{
  alert('Operácia bola stornovaná!');
 }
}

function delforumtopic(codex, datax){
 if (confirm("Naozaj si prajete odstrániť túto tému a všetky príspevky v nej?")==true){
  code = codex;
  data = datax;
  sndReq(code,'delforumtopic',data);
 }
 else{
  alert('Operácia bola stornovaná!');
 }
}
	
function createtopic(codex){
// 0 nazov
// 1 forwho
// 2 description
 code = codex;
 if (document.getElementById('NTnazov').value!=""){
  data = document.getElementById('NTnazov').value+'**';
  if (document.getElementById('NTforwho').checked == true){
    data += '1';
  }
  else{
   data += '0';
  }
  data += '**';
  data += document.getElementById('NTdescript').value;
  sndReq(code,'createtopic',data);
 }
 else{
  alert('Nezadali ste názov témy!');
 }
}

function mtt(codex, datax){
 if (confirm("Naozaj si prajete presunúť tento článok do koša?")==true){
  code = codex;
  data = datax;
  sndReq(code,'movetotrash',data);
 }
 else{
  alert('Operácia bola stornovaná!');
 }
}

function clrenew(codex, datax){
 if (confirm("Naozaj si prajete obnoviť tento článok?")==true){
  code = codex;
  data = datax;
  sndReq(code,'clrenew',data);
 }
 else{
  alert('Operácia bola stornovaná!');
 }
}
function cldelete(codex, datax){
 if (confirm("Naozaj si prajete NENÁVRATNE ODSTRÁNIŤ tento článok?")==true){
  code = codex;
  data = datax;
  sndReq(code,'cldelete',data);
 }
 else{
  alert('Operácia bola stornovaná!');
 }
}

function TSedit(codex, datax){
 if (confirm("Naozaj si prajete upraviť svoj príspevok?")==true){
  code = codex;
  datal = datax;
  text = document.getElementById("editTSX-"+datal).value;
  data = datal + '**' + text;
  sndReq(code,'tsedit',data);
 }
 else{
  alert('Operácia bola stornovaná!');
 }
}
	
	
// Operacie so vzhladom stranky	
	
	var elid,el1,el2;
	var browserName=navigator.appName; 

function showhide(elid){
 if (document.getElementById(elid).style.display == 'none'){
  document.getElementById(elid).style.display = 'block';
 }
 else{
  document.getElementById(elid).style.display = 'none';
 }
}

function showhidetr(elid){
 if (document.getElementById(elid).style.display == 'none'){
   if (browserName=="Microsoft Internet Explorer"){
   document.getElementById(elid).style.display = 'block';
   }
   else{
   document.getElementById(elid).style.display = 'table-row';
   }
 }
 else{
  document.getElementById(elid).style.display = 'none';
 }
}

function showhidetarea(el1,el2){
 if (document.getElementById(el1).style.display == 'none'){
  document.getElementById(el1).style.display = 'block';
  document.getElementById(el2).style.display = 'none';
 }
 else{
  document.getElementById(el1).style.display = 'none';
  document.getElementById(el2).style.display = 'block';
 }
}

function xcheck(){
var checker = document.getElementById('xcheckbox'); 
 if (checker.checked==true){
  showhidetr('xfunction');
 }
 else{
  showhidetr('xfunction');
  document.getElementById('e21').value = '';
 }
}



