// <script type="text/javascript">
var	editujese=false;
var	zasobnikWt="";
var	prihlasen=false;
var	 imagelist = new Array(0);
var slide_index=0;
var frame_index=2;
var slide_speed=80;
var slide_step=1;
var slide_wait=5000;
var	fade_percent=100;
var slide_autocontinue=0;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}  

function alertik(){
	alert('Ahoj');
	return(false);
}

function menuup(xid){
	var url = "ajax.php?action=sendup&upid="+xid;
	dataSource = getHTTPObject(); 
	dataSource.open("GET",encodeURI(url), true); 
	dataSource.send(null);	
	return(false);
}

function menudn(xid){
	var url = "ajax.php?action=senddn&dnid="+xid;
	//alert(url);
	dataSource = getHTTPObject(); 
	dataSource.open("GET",encodeURI(url), true); 
	dataSource.send(null);	
	return(false);	
}

function menuup2(xid){
	var url = "ajax.php?action=sendup2&upid="+xid;
	dataSource = getHTTPObject(); 
	dataSource.open("GET",encodeURI(url), true); 
	dataSource.send(null);	
	return(false);	
}

function menudn2(xid){
	var url = "ajax.php?action=senddn2&dnid="+xid;	
	dataSource = getHTTPObject(); 
	dataSource.open("GET",encodeURI(url), true); 
	dataSource.send(null);	
	return(false);	
}
function menuup3(xid){
	var url = "ajax.php?action=sendup3&upid="+xid;
	dataSource = getHTTPObject(); 
	dataSource.open("GET",encodeURI(url), true); 
	dataSource.send(null);	
	return(false);		
}

function menudn3(xid){
	var url = "ajax.php?action=senddn3&dnid="+xid;
	
	dataSource = getHTTPObject(); 
	dataSource.open("GET",encodeURI(url), true); 
	dataSource.send(null);	
	return(false);	
}

function showtext(text){
//	cil=document.getElementById("wtObsah");
//	x=cil.clientHeight;
//	if (x>300){
//		cil=document.getElementById("wtObsah");	
//		cil.innerHTML="["+x+"]"+text;	
//	}
//	else
//	{
//		cil=document.getElementById("wtObsah");	
//		cil.innerHTML=cil.innerHTML+"["+x+"]"+text;	
//	}
}

function stopAnimate(){
	//startSlideShow();
	clearInterval(timerID);
//	timerID=window.setInterval( "fade()", slide_speed );
	cil=document.getElementById("picframe1");
	cil.style.opacity=(1);	
	cil.style.filter="Alpha(Opacity=100)";

	cil2=document.getElementById("picframe2");
	cil2.style.opacity=(0);
	cil2.style.filter="Alpha(Opacity=0)";	
	
	fade_percent=100;	 

}

function startSlideShow(){
	// nacti seynam obrazku do pole
	// az dojde seznam odstartuj slideshow...
	showtext("Odeslána žádost o seznam obrázků...<br>");
	var url = "slideajax.php?action=getimagelist";
		dataSource = getHTTPObject(); 
		dataSource.open("GET",encodeURI(url), true); 
	    dataSource.onreadystatechange = handleGetimagelist; 
	    dataSource.send(null);	
		return(false);			
}

function handleGetimagelist(){   
  if(dataSource.readyState == 4){   
    if(dataSource.status == 200){   
      {   
		showtext("Imagelist back...<br>");	  
		//alert(dataSource.responseText);	  	
        var XMLRes = dataSource.responseXML; 	
        //zachycení chyb IE a Opery   
        if(!XMLRes || !XMLRes.documentElement){   
	 	  //alert('xml bad 1');	
          throw("Chybná struktura XML1:\n"+dataSource.responseText);   		  	
        }   
        //zachycení chyb ohnivé lišky :-)   
        var rootNodeName = XMLRes.documentElement.nodeName;   
        if(rootNodeName == "parsereerror"){   
		  //alert('xml bad 2');	
          throw("Chybná struktura XML2:\n"+dataSource.responseText);   
        }   
        //čtu dokument, jelikož je vše ok :-)   		
		//alert('xml ok');
	    xmlRoot = XMLRes.documentElement;
		xmlElement= XMLRes.getElementsByTagName("record");	

		obsah="";
		var s = "<strong>Seznam obrázků:</strong><br><br>";
		for (x=0; x<xmlElement.length; x++){
		// POKUD JE ELEMENT PRAZDNY VYGYNYRUJE SE CHYBA!		
			s=s+xmlRoot.getElementsByTagName("record")[x].childNodes[0].childNodes[0].nodeValue+" "+xmlRoot.getElementsByTagName("record")[x].childNodes[1].childNodes[0].nodeValue+'<br>';
			$obr=xmlRoot.getElementsByTagName("record")[x].childNodes[1].childNodes[0].nodeValue;
			imagelist[x]=$obr;
			//alert($obr);			
		}
//		alert(imagelist[0]);	
		slide_index=0;
		frame_index=2;
		showtext(s);	
		slide_autocontinue=1;			
//		slideshow();
		timerID=window.setInterval( "waiting()", slide_wait );
      }
    }else{   
      //alert("Požadavek HTTP není v pořádku.")   
    }   
  }   
}   

function slideshow(){
	showtext("Frame_index="+frame_index+'<br>');
	if (frame_index==1){
		cil=document.getElementById("picframe1");	
		cil.innerHTML='<img src="'+imagelist[slide_index]+'" width="450" height="300"/>';
		showtext(imagelist[slide_index]+" do "+frame_index+"("+imagelist.length+")<br>");
	}
	else{
		cil=document.getElementById("picframe2");	
		cil.innerHTML='<img src="'+imagelist[slide_index]+'" width="450" height="300"/>';	
		showtext(imagelist[slide_index]+" do "+frame_index+"("+imagelist.length+")<br>");
	}		
	if (slide_index<imagelist.length-1){
		slide_index++;	
	}
	else
	{
		slide_index=0;
	}
	showtext("Next slide_index="+slide_index+"<br>");
	timerID=window.setInterval( "fade()", slide_speed );
	showtext("start of fading...<br>");	
	// zvys slide index (nebo nuluj)
	// pokud je slide_index=2 prolni 1 do 2 (po prolnuti zmen frame_index);
	// jinak prolni 2 do 1 (po prolnuti zmen frame_index); 
}

function waiting(){
	clearInterval(timerID); 
//	timerID=window.setInterval( "animateup()", speed );
	showtext("Stop<br>");
	if (slide_autocontinue==1){slideshow()};
}

function fade(){

	if (frame_index==2){ fade_percent=fade_percent-slide_step;	} else {fade_percent=fade_percent+slide_step;}
	
	cil=document.getElementById("picframe1");
	cil.style.opacity=(fade_percent/100);	
	cil.style.filter="Alpha(Opacity="+fade_percent+")";

	cil2=document.getElementById("picframe2");
	cil2.style.opacity=((100-fade_percent)/100);
	cil2.style.filter="Alpha(Opacity="+(100-fade_percent)+")";
	
	//showtext("fade_percent="+fade_percent+"<br>");

	if (frame_index==2){
		if (fade_percent<=0){
			clearInterval(timerID); 
			fade_percent=0;
			frame_index=1;
			timerID=window.setInterval( "waiting()", slide_wait );
			showtext("end of fading... i still waiting..<br>");	
		}
	}
	else
	{
		if (fade_percent>=100){
			clearInterval(timerID); 
			fade_percent=100;
			frame_index=2;		
			timerID=window.setInterval( "waiting()", slide_wait );
			showtext("end of fading... i still waiting..<br>");
		}	
	}
	
}

  function delkachatu() {
  // zjisti delku elementu left container...
  var cil = document.getElementById("chatNadpis");
  var chat = document.getElementById("chat");
  var chattext = document.getElementById("chattext");
  var cil2 = document.getElementById("indexLeftContainer");
  lcH=cil2.clientHeight;
  var ch=0;
  var cht=0;
  var pricist=0;
  ch=chat.clientHeight;
  cht=chattext.clientHeight;
  pricist=lcH-690; 
  chat.style.height=200+pricist+"px";
  chattext.style.height=200+pricist+"px";
  }

function rand (min, max) {
    // http://kevin.vanzonneveld.net
    // +   original by: Leslie Hoare
    // +   bugfixed by: Onno Marsman
    // %          note 1: See the commented out code below for a version which will work with our experimental (though probably unnecessary) srand() function)
    // *     example 1: rand(1, 1);
    // *     returns 1: 1
    
    var argc = arguments.length;
    if (argc === 0) {
        min = 0;
        max = 2147483647;
    } else if (argc === 1) {
        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
    }
    return Math.floor(Math.random() * (max - min + 1)) + min;
}


  function closeLogin(){
  var cil = document.getElementById("mainPage");
  var xlogin=document.getElementById("login");
  cil.removeChild(xlogin);
  }

var dataSource7; 
var dataSource6;
var dataSource5;   
var dataSource4; 
var dataSource3; 
var dataSource2;   
var dataSource; 
function getHTTPObject() { 
    request = false; 
    if(window.XMLHttpRequest) { 
        try { 
            request = new XMLHttpRequest(); 
        } catch(e) { 
            request = false; 
        } 
    } else if(window.ActiveXObject) { 
           try { 
            request = new ActiveXObject("Msxml2.XMLHTTP"); 
          } catch(e) { 
            try { 
                  request = new ActiveXObject("Microsoft.XMLHTTP"); 
            } catch(e) { 
                  request = false; 
            } 
        } 
    } 
    return request; 
} 

function delproduct(x){
	if (confirm('Smazat produkt PID:'+x+'?')){
//		alert('Produkt PID:'+x+' byl smazán...');
		s="produkty.php?delpr="+x;
		self.location=s;		
	}
 
 }
 
  function prihlas(f){
  	  deanim=setInterval("deanimateLogin()",10);
	  var login = document.getElementById("login");	
	  var i=login.clientWidth;	    
	  name=f['username'].value;
 	  pwd=f['password'].value;
 	  sul=f['sul'].value;	  
	  cisteSHA=SHA256(pwd);
	  //alert(cisteSHA);
	  //shapwd=SHA256(sul+SHA256(pwd));
	  shapwd=pwd;
	  var cil = document.getElementById("indexRightContainer");	  
	  //alert(name+'\n'+pwd+'\n'+sul+'\n'+cisteSHA+'\n'+shapwd);
	  //alert(name+'\n'+shapwd);	 	  
	  var url = "ajax.php?action=login&name="+name+"&hash="+shapwd;
	  //alert(url);
		dataSource = getHTTPObject(); 
		dataSource.open("GET", url, true); 
	    dataSource.onreadystatechange = handlePrihlas; 
	    //dataSource.send(null);	  
	  //closeLogin();
	  return false;
  }
  
    function odhlasit(){
	  var url = "ajax.php?action=unlog";
  	  	//alert(url);
		prihlasen=false;
		dataSource = getHTTPObject(); 
		dataSource.open("GET", url, true); 
	    dataSource.onreadystatechange = handlePrihlas; 
	    dataSource.send(null);   		  	  
	  return false;
  }

  function login(sul){
  var cil = document.getElementById("mainPage");
  var puvodiHTML=cil.innerHTML;  
  fTop=cil.clientHeight+15;   
  var newText='<div class="login" id="login">';  
  newText=newText+'<div style="background-color: red; color: white; height:15px;"><div style="float: left;">Login</div><div style="float: right;" onclick="closeLogin()">x</div></div>';
  newText=newText+'<form class="loginform" name="loginform" method="post" action="" onsubmit="return prihlas(this);">';    
  newText=newText+'<table border="0">';
  newText=newText+'  <tr>';
  newText=newText+'    <td width="150">uživatelské jméno:</td>';
  newText=newText+'    <td width="150">';
  newText=newText+'      <input id="username" class="loginEdt" type="username" name="username" />';
  newText=newText+'    </td>';
  newText=newText+'  </tr>';
  newText=newText+'  <tr>';
  newText=newText+'    <td>heslo:</td>';
  newText=newText+'    <td>';
  newText=newText+'      <input id="sul" type="hidden" name="sul" value="'+sul+'" />';  
  newText=newText+'      <input id="password" class="loginEdt" type="password" name="password" />';
  newText=newText+'    </td>';
  newText=newText+'  </tr>';
  newText=newText+'  <tr>';
  newText=newText+'    <td>&nbsp;</td>';
  newText=newText+'    <td>';
  newText=newText+'      <input class="loginBtn" type="submit" name="Submit" value="přihlásit"/>';  
  newText=newText+'    </td>';
  newText=newText+'  </tr>';
  newText=newText+'</table>';
  newText=newText+'</form>';  
  newText=newText+'</div>  ';    
  cil.innerHTML=newText+puvodiHTML;
  var login = document.getElementById("login");
  maxHeight=login.clientHeight;
  maxWidth=login.clientWidth;   
  login.style.top=fTop+"px";
  login.style.width=0+"px";
  login.style.height=12+"px";
  anim=setInterval("animateLogin()",1);     
  }

  function animateLogin2(){
    var login = document.getElementById("login");
	  if (login.clientWidth<300)
	  {
	  	// zvzsuj width... 
		  login.style.width=login.clientWidth+10+"px";
	  }
	  else
	  {
 			clearInterval(anim);
	  }
	  if (login.clientHeight<100){
		  login.style.height=login.clientHeight+10+"px";
	   }	  
  }
  
  function animateLogin(){
    var login = document.getElementById("login");
	  if (login.clientWidth<300)
	  {
	  	// zvzsuj width... 
		  login.style.width=login.clientWidth+10+"px";
	  }
	  else 
	  {
	  	if (login.clientHeight<100){
		  login.style.height=login.clientHeight+10+"px";
		}
		else
		{
			clearInterval(anim);
		}
	  
	  }

  }  
  
  function deanimateLogin(){
  	//alert('deanimate');
    var login = document.getElementById("login");
	  if (login.clientWidth>10)
	  {
	  	// zvzsuj width... 
		  login.style.width=login.clientWidth-10+"px";
	  }
	  else 
	  {
	  	if (login.clientHeight>10){
		  login.style.height=login.clientHeight-10+"px";
		}
		else
		{
   		 	dataSource.send(null);
			clearInterval(deanim);
			closeLogin();
		}	  
	  }
  }    

	function handlePrihlas() { 
		  if (dataSource.readyState == 4) { 
			 if (dataSource.status == 200) { 
				//alert(dataSource.responseText);			
				$logtext="";
				$logtext=dataSource.responseText;
				//alert($logtext);
				if ($logtext=="status:logged"){	
					prihlasen=true;			
					//alert(prihlasen);
					window.location.reload(true);
					//provedli jsme reload, php na zacatku nas presmeruje na data.php
				 }
				if ($logtext=="status:unlogged"){	
					prihlasen=false;			
					window.location.reload(true);
					//provedli jsme reload, php na zacatku nas presmeruje na data.php
				 }			 
				window.location.reload(true);	
	//  target = document.getElementById('footer');	
	//	oldHTML=target.innerHTML;
	//	newHTML=oldHTML+dataSourceResponseText;
		
	//	ddat=new Date();
	//	months=ddat.getMonth()+1;
	//	if (months<10) months="0"+months;
	//	days=ddat.getDate();
	//	if (days<10) days="0"+days;	
	//	hours=ddat.getHours();
	//	if (hours==0) hours="0"+hours;
	//	minutes=ddat.getMinutes();
	//	if (minutes<10) minutes="0"+minutes;
	//	seconds=ddat.getSeconds();
	//	if (seconds<10) seconds="0"+seconds;
	//	datstr=days+"-"+months+"-"+ddat.getFullYear()+" "+hours+":"+minutes+":"+seconds;
	//	target.innerHTML='&nbsp;načteno '+datstr;	
			}     
		  } 
	}  
  function closeAddChat(){
  var cil = document.getElementById("mainPage");
  var xlogin=document.getElementById("addchat");
  cil.removeChild(xlogin);  
  timerID=window.setInterval( "fade()", slide_speed );
  }

  function odeslivzkaz(f){
  var odeslat=true;
	  if (f['name'].value=='vyplňte jméno !'){
	  	odeslat=false;
		f['name'].value='vyplňte jméno !';
		cil = document.getElementById("chatname");
		cil.style.color='red';			
	  }		      
	  if (f['name'].value==''){
	  	odeslat=false;
		f['name'].value='vyplňte jméno !';
		cil = document.getElementById("chatname");
		cil.style.color='red';		
	  }	
	  if (f['chataddtext'].value=='vyplňte text !'){
	  	odeslat=false;
		f['chataddtext'].value='vyplňte text !';
		cil = document.getElementById("chataddtext");
		cil.style.color='red';			
	  }	  	  	  	 	  
	  if (f['chataddtext'].value==''){
	  	odeslat=false;
		f['chataddtext'].value='vyplňte text !';
		cil = document.getElementById("chataddtext");
		cil.style.color='red';			
	  }	  	  
	  
	  if (odeslat==true){  
  		
		  deanim2=setInterval("deanimateXchat()",10);
		  
		  xname=f['name'].value;
		  xemail=f['mail'].value;
		  xunsp=f['unspm'].value;	  		
		  xtext=f['chataddtext'].value;
		  xtext=convert(xtext);		  
		  var url = "ajax.php?action=addchat&name="+xname+"&email="+xemail+"&unsp="+xunsp+"&text="+xtext;		  
//		  if (prihlasen==true){
//			  	alert(url);
//		  }
		  //cil = document.getElementById("chattext");
		  //cil.innerHTML=url+cil.innerHTML;
		  //alert(url);
			dataSource2 = getHTTPObject(); 
//			dataSource2.open("GET", url, true); 
			dataSource2.open("GET", encodeURI(url), true); 
			dataSource2.onreadystatechange = handleOdesliVzkaz; 
			//dataSource.send(null);	  
		  //closeLogin();  
	  }
	  return false;
  }  

  function addchat(){
 stopAnimate();
//alert('hi');
  var cil = document.getElementById("mainPage");
  var cil2 = document.getElementById("indexRightContainer");
  var puvodiHTML=cil.innerHTML;
  var newText='<div class="addchat" id="addchat">';
  newText=newText+'<div style="background-color: red; color: yellow; border: 1px solid red; height: 15px;">  '; 
  newText=newText+'<div style="float: left; ">  '
  newText=newText+'Přidání nového vzkazu'  ;  
  newText=newText+'</div>  '; 
  newText=newText+'<div style="float: right;">';
  newText=newText+'<span onclick="closeAddChat()">X</span>';  
  newText=newText+'</div>';
  newText=newText+'</div>';
  newText=newText+'<div>';
  newText=newText+'<form class="chatform" name="" method="post" action="" onsubmit="return odeslivzkaz(this);">';  
  newText=newText+'<table border="0">';
  newText=newText+'  <tr>';
  newText=newText+'    <td width="150">jméno:</td>';
  newText=newText+'    <td width="150">';
  newText=newText+'      <input id="chatname" class="chatEdt" name="name" type="text" />';  
  newText=newText+'    </td>';
  newText=newText+'  </tr>';
  newText=newText+'  <tr>';
  newText=newText+'    <td>email(nezobrazí se):</td>';
  newText=newText+'    <td>';
  newText=newText+'      <input class="chatEdt" name="mail" type="text"/>';
  newText=newText+'      <input class="chatEdth" name="unspm" type="text"/>';    
  newText=newText+'    </td>';
  newText=newText+'  </tr>';
  newText=newText+'  <tr>';
  newText=newText+'    <td>text:</td>';
  newText=newText+'    <td>';
  newText=newText+'    </td>';
  newText=newText+'  </tr>'; 
  newText=newText+'  <tr>';
  newText=newText+'    <td colspan=2><textarea id="chataddtext" name="chataddtext" class="addchattext"></textarea></td>';
  newText=newText+'  </tr>'; 
  newText=newText+'  <tr>';
  newText=newText+'    <td>';
  newText=newText+'      <input class="addchatBtn" type="submit" name="Submit" value="odeslat"/>';   
  newText=newText+'    </td>';  
  newText=newText+'    <td>';
  newText=newText+'    </td>';    
  newText=newText+'  </tr>';      
  newText=newText+'</table>';    
  newText=newText+'</form>';     
  newText=newText+'</div>';    
  newText=newText+'</div>';
  cil.innerHTML=newText+puvodiHTML;
  var xchat = document.getElementById("addchat");
  maxHeight=xchat.clientHeight;
  maxWidth=xchat.clientWidth;   
  xchat.style.width=0+"px";
  xchat.style.height=12+"px";
  anim2=setInterval("animateXchat()",10);     
  }  
  
  function animateXchat(){
    var xchat = document.getElementById("addchat");
	  if (xchat.clientWidth<370)
	  {
	  	// zvzsuj width... 
		  xchat.style.width=xchat.clientWidth+20+"px";
	  }
	  else 
	  {
	  	if (xchat.clientHeight<400){
		  xchat.style.height=xchat.clientHeight+20+"px";
		}
		else
		{
			clearInterval(anim2);
		}
	  
	  }

  }    
      
  function deanimateXchat(){
  	//alert('deanimate');
    var xchat = document.getElementById("addchat");
	  if (xchat.clientHeight>20)
	  {
  		  xchat.style.height=xchat.clientHeight-10+"px";
	  }
	  else 
	  {
	  	if (xchat.clientWidth>10){
		  xchat.style.width=xchat.clientWidth-10+"px";
		}
		else
		{
   		 	dataSource2.send(null);
			//alert('odeslano');
			clearInterval(deanim2);
			closeAddChat();
		}	  
	  }
  }    
  
  function nadpisZpet(){
	clearInterval(nadpis);
	cil = document.getElementById("chatNadpis");
	cil.innerHTML="CASEA chat:";
  }
  
  
	function handleOdesliVzkaz() { 
		  if (dataSource2.readyState == 4) { 
			 if (dataSource2.status == 200) { 
				//xtarget.innerHTML = dataSource.responseText;			
				$logtext="";
				$logtext=dataSource2.responseText;
				//alert($logtext);
				if ($logtext=="status:added"){	
					cil = document.getElementById("chatNadpis");
					cil.innerHTML=cil.innerHTML+"[ vzkaz byl přidán]";
					nadpis=setInterval("nadpisZpet()",2000);
					nactichat();
//					window.location.reload(true);
					//provedli jsme reload, php na zacatku nas presmeruje na data.php
				 }		
				 else {	
					cil = document.getElementById("chatNadpis");
					cil.innerHTML=cil.innerHTML+"[ CHYBA! vzkaz nebyl přidán... ]";
					nadpis=setInterval("nadpisZpet()",2000);
					//alert($logtext);
					//cil2 = document.getElementById("chattext");
					//cil2.innerHTML=$logtext;
//					window.location.reload(true);
					//provedli jsme reload, php na zacatku nas presmeruje na data.php
				 }						 			 				
			}     
		  } 
	}  
  
  
 
function nactichat(){
  var url = "ajax.php?action=getchat";
	dataSource3 = getHTTPObject(); 
	dataSource3.open("GET", url, true); 
	dataSource3.onreadystatechange = handleZobrazChat;
	dataSource3.send(null);	  
  //closeLogin();  
  return false;	  
}    
  
function handleZobrazChat() { 
	  if (dataSource3.readyState == 4) { 
		 if (dataSource3.status == 200) { 
			//xtarget.innerHTML = dataSource.responseText;			
			//dataSource3.responseText;
			cil=document.getElementById("chattext");
			cil.innerHTML=dataSource3.responseText;			
		} 
	  }
}  

//----------------------------
function delchat(id) {
 	//rozbal okno,
	//nacti udaje...
	if (confirm("opravdu smazat tento záznam?")){
		  var url = "ajax.php?action=delchat&delid="+id;
			dataSource4 = getHTTPObject(); 
			dataSource4.open("GET", url, true); 
			dataSource4.onreadystatechange = handleDelChat;
			dataSource4.send(null);	  
		  //closeLogin();  
		  return false;	  	
	 }
 } 
 
function handleDelChat() { 
	  if (dataSource4.readyState == 4) { 
		 if (dataSource4.status == 200) { 
		 nactichat();
		} 
	  }
}	  


//-------------
  function editchatOrg(id){
  stopAnimate();
  var cil = document.getElementById("mainPage");
  var cil2 = document.getElementById("indexRightContainer");
//  alert(id);
  var puvodiHTML=cil.innerHTML;
  var newText='<div class="editchat" id="editchat">';
  newText=newText+'<div style="background-color: red; color: yellow; border: 1px solid red; height: 15px;">  '; 
  newText=newText+'<div style="float: left; ">  '
  newText=newText+'Editace vzkazu'  ;  
  newText=newText+'</div>  '; 
  newText=newText+'<div style="float: right;">';
  newText=newText+'<span onclick="closeEditChat()">X</span>';  
  newText=newText+'</div>';
  newText=newText+'</div>';
  newText=newText+'<div>';
  newText=newText+'<form class="chatform" name="" method="post" action="" onsubmit="return savevzkaz(this);">';  
  newText=newText+'<table border="0">';
  newText=newText+'  <tr>';
  newText=newText+'    <td width="150">jméno:</td>';
  newText=newText+'    <td width="150">';
  newText=newText+'      <input id="chatname" class="chatEdt" name="name" type="text" />';  
  newText=newText+'    </td>';
  newText=newText+'  </tr>';
  newText=newText+'  <tr>';
  newText=newText+'    <td>email(nezobrazí se):</td>';
  newText=newText+'    <td>';
  newText=newText+'      <input class="chatEdt" id="chatemail" name="mail" type="text"/>';
  newText=newText+'      <input class="chatEdth" id="unspm" name="unspm" type="text"/>'; 
  newText=newText+'      <input name="idedit" type="hidden" id="idedit" value="0"/>';        
  newText=newText+'    </td>';
  newText=newText+'  </tr>';
  newText=newText+'  <tr>';
  newText=newText+'    <td>text:</td>';
  newText=newText+'    <td>';
  newText=newText+'    </td>';
  newText=newText+'  </tr>'; 
  newText=newText+'  <tr>';
  newText=newText+'    <td colspan=2><textarea id="chataddtext" name="chataddtext" class="addEdittext"></textarea></td>';
  newText=newText+'  </tr>'; 
  newText=newText+'  <tr>';
  newText=newText+'    <td>odpověď:</td>';
  newText=newText+'    <td>';
  newText=newText+'    </td>';
  newText=newText+'  </tr>'; 
  newText=newText+'  <tr>';
  newText=newText+'    <td colspan=2><textarea id="chatanswtext" name="chatanswtext" class="addEdittext"></textarea></td>';
  newText=newText+'  </tr>';   
  newText=newText+'  <tr>';
  newText=newText+'    <td colspan=2><input name="sendmail" type="checkbox" value="" /> odeslat mail</td>';
  newText=newText+'  </tr>';     
  newText=newText+'  <tr>';
  newText=newText+'    <td>';
  newText=newText+'      <input class="addchatBtn" type="submit" name="Submit" value="uložitt"/>';   
  newText=newText+'    </td>';  
  newText=newText+'    <td>';
  newText=newText+'    </td>';    
  newText=newText+'  </tr>';      
  newText=newText+'</table>';    
  newText=newText+'</form>';     
  newText=newText+'</div>';    
  newText=newText+'</div>';
  cil.innerHTML=newText+puvodiHTML;
  
  nactiEditChat(id);
  
  var xchat = document.getElementById("editchat");
  maxHeight=xchat.clientHeight;
  maxWidth=xchat.clientWidth;   
  xchat.style.width=0+"px";
  xchat.style.height=12+"px";
  animEdit=setInterval("animateEditchat()",10);     
  }  
  
//-----------------
  function editchat(id){
  stopAnimate();
  var cil = document.getElementById("mainPage");
  var cil2 = document.getElementById("indexRightContainer");
//  alert(id);
  var puvodiHTML=cil.innerHTML;
  var newText='<div class="editchat" id="editchat">';
  newText=newText+'<div style="background-color: red; color: yellow; border: 1px solid red; height: 15px;">  '; 
  newText=newText+'<div style="float: left; ">  '
  newText=newText+'Editace vzkazu'  ;  
  newText=newText+'</div>  '; 
  newText=newText+'<div style="float: right;">';
  newText=newText+'<span onclick="closeEditChat()">X</span>';  
  newText=newText+'</div>';
  newText=newText+'</div>';
  newText=newText+'<div>';
  newText=newText+'<form class="chatform" name="" method="post" action="index.php">';  
  newText=newText+'<table border="0">';
  newText=newText+'  <tr>';
  newText=newText+'    <td width="150">jméno:</td>';
  newText=newText+'    <td width="150">';
  newText=newText+'      <input id="chatname" class="chatEdt" name="name" type="text" />';  
  newText=newText+'    </td>';
  newText=newText+'  </tr>';
  newText=newText+'  <tr>';
  newText=newText+'    <td>email(nezobrazí se):</td>';
  newText=newText+'    <td>';
  newText=newText+'      <input class="chatEdt" id="chatemail" name="mail" type="text"/>';
  newText=newText+'      <input class="chatEdth" id="unspm" name="unspm" type="text"/>'; 
  newText=newText+'      <input name="idedit" type="hidden" id="idedit" value="0"/>';        
  newText=newText+'    </td>';
  newText=newText+'  </tr>';
  newText=newText+'  <tr>';
  newText=newText+'    <td>text:</td>';
  newText=newText+'    <td>';
  newText=newText+'    </td>';
  newText=newText+'  </tr>'; 
  newText=newText+'  <tr>';
  newText=newText+'    <td colspan=2><textarea id="chataddtext" name="chataddtext" class="addEdittext"></textarea></td>';
  newText=newText+'  </tr>'; 
  newText=newText+'  <tr>';
  newText=newText+'    <td>odpověď:</td>';
  newText=newText+'    <td>';
  newText=newText+'    </td>';
  newText=newText+'  </tr>'; 
  newText=newText+'  <tr>';
  newText=newText+'    <td colspan=2><textarea id="chatanswtext" name="chatanswtext" class="addEdittext"></textarea></td>';
  newText=newText+'  </tr>';   
  newText=newText+'  <tr>';
  newText=newText+'    <td colspan=2><input name="sendmail" type="checkbox" value="" /> odeslat mail s odpovědí tazateli</td>';
  newText=newText+'  </tr>';      
  newText=newText+'  <tr>';
  newText=newText+'    <td>';
  newText=newText+'      <input class="addchatBtn" type="submit" name="Submit" value="uložit"/>';   
  newText=newText+'    </td>';  
  newText=newText+'    <td>';
  newText=newText+'    </td>';    
  newText=newText+'  </tr>';      
  newText=newText+'</table>';    
  newText=newText+'</form>';     
  newText=newText+'</div>';    
  newText=newText+'</div>';
  cil.innerHTML=newText+puvodiHTML;
  
  nactiEditChat(id);
  
  var xchat = document.getElementById("editchat");
  maxHeight=xchat.clientHeight;
  maxWidth=xchat.clientWidth;   
  xchat.style.width=0+"px";
  xchat.style.height=12+"px";
  animEdit=setInterval("animateEditchat()",10);     
  }  
  
  function animateEditchat(){
    var echat = document.getElementById("editchat");
	  if (echat.clientWidth<370)
	  {
	  	// zvzsuj width... 
		  echat.style.width=echat.clientWidth+10+"px";
	  }
	  else 
	  {
	  	if (echat.clientHeight<400){
		  echat.style.height=echat.clientHeight+10+"px";
		}
		else
		{
			clearInterval(animEdit);
		}
	  
	  }

  }    
      
  function deanimateEditchat(){
  	//alert('deanimate');
    var echat = document.getElementById("editchat");
	  if (echat.clientHeight>20)
	  {
  		  echat.style.height=echat.clientHeight-10+"px";
	  }
	  else 
	  {
	  	if (echat.clientWidth>10){
		  echat.style.width=echat.clientWidth-10+"px";
		}
		else
		{
			//alert('odeslano');
			dataSource6.send(null);
			clearInterval(deanimEdit);
			closeEditChat();
		}	  
	  }
  }    

  function closeEditChat(){
  var cil = document.getElementById("mainPage");
  var xlogin=document.getElementById("editchat");
  cil.removeChild(xlogin);  
  }

function nactiEditChat(id) {
  var url = "ajax.php?action=editchat&editid="+id;
	dataSource5 = getHTTPObject(); 
	dataSource5.open("GET", url, true); 
	dataSource5.onreadystatechange = handleNactiEeditChat;
	dataSource5.send(null);	
	//alert(url);
  return false;	  	
 } 
 

function handleNactiEeditChat(){
  if(dataSource5.readyState == 4){   
    if(dataSource5.status == 200){   
      {   
		//alert(dataSource5.responseText);	  
        var XMLRes = dataSource5.responseXML;   	
        //zachycení chyb IE a Opery   
        if(!XMLRes || !XMLRes.documentElement){   
          throw("Chybná struktura XML1:\n"+dataSource5.responseText);   
        }   
        //zachycení chyb ohnivé lišky :-)   
        var rootNodeName = XMLRes.documentElement.nodeName;   
        if(rootNodeName == "parsereerror"){   
          throw("Chybná struktura XML2:\n"+dataSource5.responseText);   
        }   
        //čtu dokument, jelikož je vše ok :-)   		
	    xmlRoot = XMLRes.documentElement;    
		cil=document.getElementById("chatname");
		//alert(dokumentXml.getElementsByTagName("name")[0].childNodes[0].nodeValue);
		try{ cil.value=xmlRoot.getElementsByTagName("name")[0].childNodes[0].nodeValue;	} catch(e) { cil.value="";}
		cil2=document.getElementById("chatemail");
		try{ cil2.value=xmlRoot.getElementsByTagName("email")[0].childNodes[0].nodeValue;	} catch(e) { cil2.value="";}
		cil3=document.getElementById("chataddtext");
		try{ 
			xtext=xmlRoot.getElementsByTagName("text")[0].childNodes[0].nodeValue;
			xtext=convertback(xtext);			
			cil3.value=xtext;				
			} catch(e) { cil3.value="";}
		cil4=document.getElementById("chatanswtext");
		try{ 
			xtext=xmlRoot.getElementsByTagName("answer")[0].childNodes[0].nodeValue;
			xtext=convertback(xtext);			
			cil4.value=xtext;			
			} catch(e) { cil4.value="";}
		cil5=document.getElementById("idedit");
		cil5.value=xmlRoot.getElementsByTagName("idedit")[0].childNodes[0].nodeValue;		
      }
    }else{   
//      alert("Požadavek HTTP není v pořádku.")   
    }   
  }   
}   

function handleSaveChat() { 
//pouzijeme JSON
	  if (dataSource6.readyState == 4) { 
		 if (dataSource6.status == 200) { 
		 //alert(dataSource6.responseText);
		 nactichat();
		} 
	  }
}	   

function convertback(text) { 
var chars = {'<br>': '\r'}; 
	for (key in chars) { 
	var regexp = new RegExp(key, 'g'); 
	text = text.replace(regexp, chars[key]); 
	} 
	return text; 
}

function convert(text) { 
var chars = {'\r': '<br>'}; 
	for (key in chars) { 
	var regexp = new RegExp(key, 'g'); 
	text = text.replace(regexp, chars[key]); 
	} 
	return text; 
}

function savevzkaz(f){
  deanimEdit=setInterval("deanimateEditchat()",10);  
  xname=f['name'].value;
  xemail=f['mail'].value;
  xunsp=f['unspm'].value;	  
  xtext=f['chataddtext'].value;
  xtext=convert(xtext);
  xanswer=f['chatanswtext'].value;
  xanswer=convert(xanswer);  
  xid=f['idedit'].value;  
  var url = "ajax.php?action=savechat&name="+xname+"&email="+xemail+"&unsp="+xunsp+"&text="+xtext+"&answer="+xanswer+"&id="+xid;
  if (prihlasen==true){	  
	alert(url);	  
  }
  //cil = document.getElementById("chattext");  
  //cil.innerHTML=url+cil.innerHTML;
  //alert(url);
  //alert(encodeURI(url));
	dataSource6 = getHTTPObject(); 
	dataSource6.open("GET",encodeURI(url), true); 
	dataSource6.onreadystatechange = handleSaveChat; 
  return false;
}



function initEdW(){
	//alert('Initialize....');
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		skin : "o2k7", 
		skin_variant : "black",		
		editor_selector : "wtEdit",	
		entity_encoding : "raw",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,cut,copy,paste,pastetext,pasteword",
		theme_advanced_buttons2 : "bullist,numlist,|,outdent,indent,blockquote,|,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons3 : "undo,redo,|,link,unlink,|,insertdate,inserttime,|,forecolor,backcolor",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : false,
		height: "300",

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",
		
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}		
				
	});	
}


function editWelcome(){
//alert(prihlasen);
	if(prihlasen==true){
		if(editujese==false){
			editujese=true;
			cil=document.getElementById("wtObsah");
			obsah=cil.innerHTML;
			zasobnikWt=obsah;
			var newText='<form action="" method="post">';
			newText=newText+'<textarea name="text" class="wtEdit" id="wtEdit">';
			newText=newText+'</textarea>';
			newText=newText+'</form>';
			newText=newText+'<input name="save" type="button" value="uložit" onClick="wtEditSave()"><input name="cancel" type="button" value="zrušit" onClick="wtEditDiscard()">';
			cil.innerHTML=newText;	
			cil2=document.getElementById("wtEdit");
			cil2.value=obsah;
			initEdW();			
		}
	}
	//alert(newText);
}
  
function wtEditSave(){
		
	var obsah = tinyMCE.get('wtEdit').getContent();
//	alert(obsah);
	//obsah="nic!";
	cil=document.getElementById("edwelcome");	
	cil2=document.getElementById("wtEdit");
//	obsah=cil2.value;
	if(obsah==""){obsah="[text]"}	
	cil3=document.getElementById("formtext");
	cil3.value=obsah;
	cil3.name="wtText";
	
	cil4=document.getElementById("formgo");
	cil4.value="saveWt";	

	cil.innerHTML='<div id="wtObsah" onClick="editWelcome()">'+obsah+'</div>';
 	obnovEditPpopis=setInterval("obnovEditPpopist()",500);
	
	document.getElementById('formgo').click();	
		
				
}

function handleSaveWt(){
	  if (dataSource.readyState == 4) { 
		 if (dataSource.status == 200) { 
		 	 obsah=dataSource.responseText;
			 if(!obsah=="status:updated"){
				 //alert('>'+obsah+'<');
			 }
//		 	 cil=document.getElementById("edwelcome");
//			 cil.innerHTML='<div id="wtObsah" onClick="editWelcome()">'+obsah+'</div>';			 
//			 alert('uloženo na serveru');
		} 
	  }
}

function obnovEditWtt(){
clearInterval(obnovEditWt);
editujese=false;
return false;
}

function prihlasenje(){
	//alert('prihlasen');
	prihlasen=true;
}
function neprihlasen(){
//	alert('neprihlasen');
	prihlasen=false;
} 

function initEd(){
	//alert('Initialize....');
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		skin : "o2k7", 
		skin_variant : "black",		
		editor_selector : "ppopisEdit",
		entity_encoding : "raw",
		
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : false,
		height: "800",

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});	
}



function prodeditpopis(){
	if(prihlasen==true)
	{
		if(editujese==false){				
			editujese=true;
			cil=document.getElementById("ppopisObsah");
			obsah=cil.innerHTML;
			zasobnikWt=obsah;		
			//alert(obsah);

			var newText='<form action="" method="post">';
			newText=newText+'<textarea name="text" class="ppopisEdit" id="ppopisEdit">';
			newText=newText+'</textarea>';
			newText=newText+'</form>';
			newText=newText+'<input name="save" type="button" value="uložit" onClick="ppopisEditSave()"><input name="cancel" type="button" value="zrušit" onClick="ppopisEditDiscard()">';
			cil.innerHTML=newText;	
			cil2=document.getElementById("ppopisEdit");
			cil2.value=obsah;			
			initEd();			
		}
	}	
}

function ppopisEditSaveOld(){
	cil=document.getElementById("prodeditpopis");	
	cil2=document.getElementById("ppopisEdit");
	obsah=cil2.value;
	if(obsah==""){obsah="[prázdné pole]"}	
//	cil.innerHTML='<div id="prodeditpopis" onClick="prodeditpopis()">'+obsah+'</div>';
	cil.innerHTML='<div id="ppopisObsah" onClick="prodeditpopis()">'+obsah+'</div>';
 	obnovEditPpopis=setInterval("obnovEditPpopist()",500);
 			
  	  	//alert(url);		
}


function xsubmit(){
	cil3=document.getElementById("formtext");
	//alert('Cil3name='+cil3.name+' '+'Cil3value='+cil3.value);	
}


function ppopisEditSave(){
	var obsah = tinyMCE.get('ppopisEdit').getContent();
//	alert(obsah);
	//obsah="nic!";
	cil=document.getElementById("prodeditpopis");	
	cil2=document.getElementById("ppopisEdit");
//	obsah=cil2.value;
	if(obsah==""){obsah="[prázdné pole]"}	
	cil3=document.getElementById("formtext");
	cil3.value=obsah;
	cil3.name="ppopisText";
	cil4=document.getElementById("formgo");
	cil4.value="savePpopis";	

	cil.innerHTML='<div id="ppopisObsah" onClick="prodeditpopis()">'+obsah+'</div>';
 	obnovEditPpopis=setInterval("obnovEditPpopist()",500);
	
	document.getElementById('formgo').click();
}

function handleSavePopis(){
	  if (dataSource.readyState == 4) { 
		 if (dataSource.status == 200) { 
		 	 obsah=dataSource.responseText;
			 //alert(obsah);
			 if(!obsah=="status:updated"){
				 //alert('>'+obsah+'<');
			 }
//		 	 cil=document.getElementById("edwelcome");
//			 cil.innerHTML='<div id="wtObsah" onClick="editWelcome()">'+obsah+'</div>';			 
//			 alert('uloženo na serveru');
		} 
	  }
}

function wtEditDiscard(){
	cil=document.getElementById("edwelcome");	
	obsah=zasobnikWt;
	cil.innerHTML='<div id="wtObsah" onClick="editWelcome()">'+obsah+'</div>';
 	obnovEditWt=setInterval("obnovEditWtt()",500);
}

function ppopisEditDiscard(){
	cil=document.getElementById("prodeditpopis");	
	obsah=zasobnikWt;
	cil.innerHTML='<div id="ppopisObsah" onClick="prodeditpopis()">'+obsah+'</div>';
 	obnovEditPpopis=setInterval("obnovEditPpopist()",500);
}

function obnovEditPpopist(){
clearInterval(obnovEditPpopis);
editujese=false;
return false;
}

function prodeditmenutext(){
	if(prihlasen==true)
	{
		if(editujese==false){				
			editujese=true;
			cil=document.getElementById("pmenutextObsah");
			obsah=cil.innerHTML;
			zasobnikWt=obsah;		
			//alert(obsah);
			var newText='<form action="" method="post">';
			newText=newText+'<textarea name="text" class="pmenutextEdit" id="pmenutextEdit">';
			newText=newText+'</textarea>';
			newText=newText+'</form>';
			newText=newText+'<input name="save" type="button" value="uložit" onClick="pmenutextEditSave()"><input name="cancel" type="button" value="zrušit" onClick="pmenutextEditDiscard()">';
			cil.innerHTML=newText;	
			cil2=document.getElementById("pmenutextEdit");
			cil2.value=obsah;	
			//alert('editace: pid'+eid);		
		}
	}	
}

function pmenutextEditSave(){
	cil=document.getElementById("prodeditmenutext");	
	cil2=document.getElementById("pmenutextEdit");
	obsah=cil2.value;
	if(obsah==""){obsah="název v menu"}	
	cil3=document.getElementById("formtext");
	cil3.value=obsah;
	cil3.name="pmenutextText";
	cil4=document.getElementById("formgo");
	cil4.value="savePmenutext";
	

	cil.innerHTML='<div id="pmenutextObsah" onClick="prodeditmenutext()">'+obsah+'</div>';
	obnovEditPmenutext=setInterval("obnovEditPmenutextt()",500);
	
	document.getElementById('formgo').click()		
}

function pmenutextEditDiscard(){
	cil=document.getElementById("prodeditmenutext");	
	obsah=zasobnikWt;
	cil.innerHTML='<div id="pmenutextObsah" onClick="prodeditmenutext()">'+obsah+'</div>';
 	obnovEditPmenutext=setInterval("obnovEditPmenutextt()",500);
}

function obnovEditPmenutextt(){
clearInterval(obnovEditPmenutext);
editujese=false;
return false;
}


function prodedittyp(){
	if(prihlasen==true)
	{
		if(editujese==false){				
			editujese=true;
			cil=document.getElementById("ptypObsah");
			obsah=cil.innerHTML;
			zasobnikWt=obsah;		
			//alert(obsah);
			var newText='<form action="" method="post">';
			newText=newText+'<textarea name="text" class="ptypEdit" id="ptypEdit">';
			newText=newText+'</textarea>';
			newText=newText+'</form>';
			newText=newText+'<input name="save" type="button" value="uložit" onClick="ptypEditSave()"><input name="cancel" type="button" value="zrušit" onClick="ptypEditDiscard()">';
			cil.innerHTML=newText;	
			cil2=document.getElementById("ptypEdit");
			cil2.value=obsah;	
			//alert('editace: pid'+eid);		
		}
	}	
}
function ptypEditSave(){
	cil=document.getElementById("prodedittyp");	
	cil2=document.getElementById("ptypEdit");
	obsah=cil2.value;
	if(obsah==""){obsah="název v menu"}	
	cil3=document.getElementById("formtext");
	cil3.value=obsah;
	cil3.name="ptypText";
	cil4=document.getElementById("formgo");
	cil4.value="savePtyp";
	

	cil.innerHTML='<div id="ptypObsah" onClick="prodedittyp()">'+obsah+'</div>';
	obnovEditPtyp=setInterval("obnovEditPtypt()",500);
	
	document.getElementById('formgo').click()		
}

function ptypEditDiscard(){
	cil=document.getElementById("prodedittyp");	
	obsah=zasobnikWt;
	cil.innerHTML='<div id="ptypObsah" onClick="prodedittyp()">'+obsah+'</div>';
 	obnovEditPtyp=setInterval("obnovEditPtypt()",500);
}

function obnovEditPtypt(){
clearInterval(obnovEditPtyp);
editujese=false;
return false;
}


function prodeditnazev(){
	if(prihlasen==true)
	{
		if(editujese==false){				
			editujese=true;
			cil=document.getElementById("pnazevObsah");
			obsah=cil.innerHTML;
			zasobnikWt=obsah;		
			//alert(obsah);
			var newText='<form action="" method="post">';
			newText=newText+'<textarea name="text" class="pnazevEdit" id="pnazevEdit">';
			newText=newText+'</textarea>';
			newText=newText+'</form>';
			newText=newText+'<input name="save" type="button" value="uložit" onClick="pnazevEditSave()"><input name="cancel" type="button" value="zrušit" onClick="pnazevEditDiscard()">';
			cil.innerHTML=newText;	
			cil2=document.getElementById("pnazevEdit");
			cil2.value=obsah;	
			//alert('editace: pid'+eid);		
		}
	}	
}

function pnazevEditSave(){
	cil=document.getElementById("prodeditnazev");	
	cil2=document.getElementById("pnazevEdit");
	obsah=cil2.value;
	if(obsah==""){obsah="název v menu"}	
	cil3=document.getElementById("formtext");
	cil3.value=obsah;
	cil3.name="pnazevText";
	cil4=document.getElementById("formgo");
	cil4.value="savePnazev";
	

	cil.innerHTML='<div id="pnazevObsah" onClick="prodeditnazev()">'+obsah+'</div>';
	obnovEditPnazev=setInterval("obnovEditPnazevt()",500);
	
	document.getElementById('formgo').click()		
}

function pnazevEditDiscard(){
	cil=document.getElementById("prodeditnazev");	
	obsah=zasobnikWt;
	cil.innerHTML='<div id="pnazevObsah" onClick="prodeditnazev()">'+obsah+'</div>';
 	obnovEditPnazev=setInterval("obnovEditPnazevt()",500);
}

function obnovEditPnazevt(){
clearInterval(obnovEditPnazev);
editujese=false;
return false;
}


function initEd3(){
	//alert('Initialize....');
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		skin : "o2k7", 
		skin_variant : "black",		
		editor_selector : "ptechparEdit",
		entity_encoding : "raw",
		
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : false,
		height: "800",

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});	
}

function prodedittechpar(){
	if(prihlasen==true)
	{
		if(editujese==false){				
			editujese=true;
			cil=document.getElementById("ptechparObsah");
			obsah=cil.innerHTML;
			zasobnikWt=obsah;		
			//alert(obsah);
			var newText='<form action="" method="post">';
			newText=newText+'<textarea name="text" class="ptechparEdit" id="ptechparEdit">';
			newText=newText+'</textarea>';
			newText=newText+'</form>';
			newText=newText+'<input name="save" type="button" value="uložit" onClick="ptechparEditSave()"><input name="cancel" type="button" value="zrušit" onClick="ptechparEditDiscard()">';
			cil.innerHTML=newText;	
			cil2=document.getElementById("ptechparEdit");
			cil2.value=obsah;	
			initEd3();
			//alert('editace: pid'+eid);		
		}
	}	
}

function ptechparEditSave(){
	var obsah = tinyMCE.get('ptechparEdit').getContent();
	cil=document.getElementById("prodedittechpar");	
	cil2=document.getElementById("ptechparEdit");
//	obsah=cil2.value;
	if(obsah==""){obsah="<h3>technické parametry</h3>"}	
	cil3=document.getElementById("formtext");
	cil3.value=obsah;
	cil3.name="ptechparText";
	cil4=document.getElementById("formgo");
	cil4.value="savePtechpar";
	

	cil.innerHTML='<div id="ptechparObsah" onClick="prodedittechpar()">'+obsah+'</div>';
	obnovEditPtechpar=setInterval("obnovEditPtechpart()",500);
	
	document.getElementById('formgo').click()		
}

function ptechparEditDiscard(){
	cil=document.getElementById("prodedittechpar");	
	obsah=zasobnikWt;
	cil.innerHTML='<div id="ptechparObsah" onClick="prodedittechpar()">'+obsah+'</div>';
 	obnovEditPtechpar=setInterval("obnovEditPtechpart()",500);
}

function obnovEditPtechpart(){
clearInterval(obnovEditPtechpar);
editujese=false;
return false;
}

function initEd2(){
	//alert('Initialize....');
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		skin : "o2k7", 
		skin_variant : "black",		
		editor_selector : "pkartkypopisEdit",
		entity_encoding : "raw",		
		
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,blockquote",		
		theme_advanced_buttons3 : "formatselect,fontselect",
		theme_advanced_buttons4 : "fontsizeselect",		
		theme_advanced_buttons5 : "undo,redo,|,link,unlink,|,insertdate,inserttime,|",
		theme_advanced_buttons6 : "forecolor,backcolor",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : false,
		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",
		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});	
}
function prodeditkartkypopis(){
	if(prihlasen==true)
	{
		if(editujese==false){				
			editujese=true;
			cil=document.getElementById("pkartkypopisObsah");
			obsah=cil.innerHTML;
			zasobnikWt=obsah;		
			//alert(obsah);
			var newText='<form action="" method="post">';
			newText=newText+'<textarea name="text" class="pkartkypopisEdit" id="pkartkypopisEdit">';
			newText=newText+'</textarea>';
			newText=newText+'</form>';
			newText=newText+'<input name="save" type="button" value="uložit" onClick="pkartkypopisEditSave()"><input name="cancel" type="button" value="zrušit" onClick="pkartkypopisEditDiscard()">';
			cil.innerHTML=newText;	
			cil2=document.getElementById("pkartkypopisEdit");
			cil2.value=obsah;	
			//alert('editace: pid'+eid);				
			initEd2();	
		}
	}	
}

function pkartkypopisEditSave(){
	var obsah = tinyMCE.get('pkartkypopisEdit').getContent();	
	cil=document.getElementById("prodeditkartkypopis");	
	cil2=document.getElementById("pkartkypopisEdit");
	//obsah=cil2.value;
	if(obsah==""){obsah="<h3>technické parametry</h3>"}	
	cil3=document.getElementById("formtext");
	cil3.value=obsah;
	cil3.name="pkartkypopisText";
	cil4=document.getElementById("formgo");
	cil4.value="savePkartkypopis";
	

	cil.innerHTML='<div id="pkartkypopisObsah" onClick="prodeditkartkypopis()">'+obsah+'</div>';
	obnovEditPkartkypopis=setInterval("obnovEditPkartkypopist()",500);
	
	document.getElementById('formgo').click()		
}

function pkartkypopisEditDiscard(){
	cil=document.getElementById("prodeditkartkypopis");	
	obsah=zasobnikWt;
	cil.innerHTML='<div id="pkartkypopisObsah" onClick="prodeditkartkypopis()">'+obsah+'</div>';
 	obnovEditPkartkypopis=setInterval("obnovEditPkartkypopist()",500);
}

function obnovEditPkartkypopist(){
clearInterval(obnovEditPkartkypopis);
editujese=false;
return false;
}
function sendAP(){
	cil=document.getElementById("archiveproduct");	
	//alert(cil.checked);
	var url = "ajax.php?action=sendAP&value="+cil.checked;
		//alert(url);
		dataSource = getHTTPObject(); 
		dataSource.open("GET",encodeURI(url), true); 
	    dataSource.onreadystatechange = handlesendAP; 
	    dataSource.send(null);   			
}

function handlesendAP(){
	  if (dataSource.readyState == 4) { 
		 if (dataSource.status == 200) { 
		 	 $obsah=dataSource.responseText;
			 //alert($obsah);
			 if (editujese==false){
			 	window.location.href="produkty.php";
			 }
		} 
	  }
}
function sendSP(){
	cil=document.getElementById("showproduct");	
	//alert(cil.checked);
	var url = "ajax.php?action=sendSP&value="+cil.checked;
  	//alert(url);
		dataSource = getHTTPObject(); 
		dataSource.open("GET",encodeURI(url), true); 
	    dataSource.onreadystatechange = handlesendSP; 
	    dataSource.send(null);   			
}

function handlesendSP(){
	  if (dataSource.readyState == 4) { 
		 if (dataSource.status == 200) { 
		 	 $obsah=dataSource.responseText;
			 if (editujese==false){
				//alert($obsah);
			 	window.location.href="produkty.php";
			 }
			 //alert(obsah);
//		 	 cil=document.getElementById("edwelcome");
//			 cil.innerHTML='<div id="wtObsah" onClick="editWelcome()">'+obsah+'</div>';			 
//			 alert('uloženo na serveru');
		} 
	  }
}
function sendNM(){
	cil=document.getElementById("newvmenu");	
	//alert(cil.checked);
	var url = "ajax.php?action=sendNM&value="+cil.checked;
  	//alert(url);
		dataSource = getHTTPObject(); 
		dataSource.open("GET",encodeURI(url), true); 
	    dataSource.onreadystatechange = handlesendNM; 
	    dataSource.send(null);   			
}

function handlesendNM(){
	  if (dataSource.readyState == 4) { 
		 if (dataSource.status == 200) { 
		 	 obsah=dataSource.responseText;	
			 if (editujese==false){
			 window.location.href="produkty.php";
			 }			 		 
			 //alert(obsah);
//		 	 cil=document.getElementById("edwelcome");
//			 cil.innerHTML='<div id="wtObsah" onClick="editWelcome()">'+obsah+'</div>';			 
//			 alert('uloženo na serveru');
		} 
	  }
}

function sendDI(){
	cil=document.getElementById("doindexu");	
	//alert(cil.checked);
	var url = "ajax.php?action=sendDI&value="+cil.checked;
//  	alert(url);
		dataSource = getHTTPObject(); 
		dataSource.open("GET",encodeURI(url), true); 
	    dataSource.onreadystatechange = handlesendDI; 
	    dataSource.send(null);   			
}

function handlesendDI(){
	  if (dataSource.readyState == 4) { 
		 if (dataSource.status == 200) { 
		 	 obsah=dataSource.responseText;		
			 if (editujese==false){
			 //window.location.href="produkty.php";
			 }						 	 
//			 alert(obsah);
//		 	 cil=document.getElementById("edwelcome");
//			 cil.innerHTML='<div id="wtObsah" onClick="editWelcome()">'+obsah+'</div>';			 
//			 alert('uloženo na serveru');
		} 
	  }
}

function sendPP(){
	cil=document.getElementById("popis");	
	//alert(cil.checked);
	var url = "ajax.php?action=sendPP&value="+cil.checked;
  	//alert(url);
		dataSource = getHTTPObject(); 
		dataSource.open("GET",encodeURI(url), true); 
	    dataSource.onreadystatechange = handlesendPP; 
	    dataSource.send(null);
}

function handlesendPP(){
	  if (dataSource.readyState == 4) { 
		 if (dataSource.status == 200) { 
		 	 obsah=dataSource.responseText;	
			 if (editujese==false){
			 //window.location.href="produkty.php";
			 }						 		 
//			 alert(obsah);
//		 	 cil=document.getElementById("edwelcome");
//			 cil.innerHTML='<div id="wtObsah" onClick="editWelcome()">'+obsah+'</div>';			 
//			 alert('uloženo na serveru');
		} 
	  }
}

function sendMR(){
	cil=document.getElementById("mereni");	
	//alert(cil.checked);
	var url = "ajax.php?action=sendMR&value="+cil.checked;
  	//alert(url);
		dataSource = getHTTPObject(); 
		dataSource.open("GET",encodeURI(url), true); 
	    dataSource.onreadystatechange = handlesendMR; 
	    dataSource.send(null);
}

function handlesendMR(){
	  if (dataSource.readyState == 4) { 
		 if (dataSource.status == 200) { 
		 	 obsah=dataSource.responseText;			 
			 if (editujese==false){
			 //window.location.href="produkty.php";
			 }						 
//			 alert(obsah);
//		 	 cil=document.getElementById("edwelcome");
//			 cil.innerHTML='<div id="wtObsah" onClick="editWelcome()">'+obsah+'</div>';			 
//			 alert('uloženo na serveru');
		} 
	  }
}

function sendTP(){
	cil=document.getElementById("techpar");	
	//alert(cil.checked);
	var url = "ajax.php?action=sendTP&value="+cil.checked;
  	//alert(url);
		dataSource = getHTTPObject(); 
		dataSource.open("GET",encodeURI(url), true); 
	    dataSource.onreadystatechange = handlesendTP; 
	    dataSource.send(null);
}

function handlesendTP(){
	  if (dataSource.readyState == 4) { 
		 if (dataSource.status == 200) { 
		 	 obsah=dataSource.responseText;		
			 if (editujese==false){
			 //window.location.href="produkty.php";
			 }						 	 
//			 alert(obsah);
//		 	 cil=document.getElementById("edwelcome");
//			 cil.innerHTML='<div id="wtObsah" onClick="editWelcome()">'+obsah+'</div>';			 
//			 alert('uloženo na serveru');
		} 
	  }
}

function sendPH(){
	cil=document.getElementById("photos");	
	//alert(cil.checked);
	var url = "ajax.php?action=sendPH&value="+cil.checked;
  	//alert(url);
		dataSource = getHTTPObject(); 
		dataSource.open("GET",encodeURI(url), true); 
	    dataSource.onreadystatechange = handlesendPH; 
	    dataSource.send(null);
}

function handlesendPH(){
	  if (dataSource.readyState == 4) { 
		 if (dataSource.status == 200) { 
		 	 obsah=dataSource.responseText;	
			 if (editujese==false){
			 //window.location.href="produkty.php";
			 }						 		 
//			 alert(obsah);
//		 	 cil=document.getElementById("edwelcome");
//			 cil.innerHTML='<div id="wtObsah" onClick="editWelcome()">'+obsah+'</div>';			 
//			 alert('uloženo na serveru');
		} 
	  }
}



function initEd4(){
	//alert('Initialize....');
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",		
		skin : "o2k7", 
		skin_variant : "black",		
		editor_selector : "pmereniEdit",
		entity_encoding : "raw",
		
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : false,
		theme_advanced_default_foreground_color : "#999999",
		theme_advanced_default_background_color : "#000000",
		theme_default_background_color : "#000000",		
		
		

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",
		height: "800",	
		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});	
}


function prodeditmereni(){
	if(prihlasen==true)
	{
		if(editujese==false){				
			editujese=true;
			cil=document.getElementById("pmereniObsah");
			obsah=cil.innerHTML;
			zasobnikWt=obsah;		
			//alert(obsah);
			var newText='<form action="" method="post">';
			newText=newText+'<textarea name="text" class="pmereniEdit" id="pmereniEdit">';
			newText=newText+'</textarea>';
			newText=newText+'</form>';
			newText=newText+'<input name="save" type="button" value="uložit" onClick="pmereniEditSave()"><input name="cancel" type="button" value="zrušit" onClick="pmereniEditDiscard()">';
			cil.innerHTML=newText;	
			cil2=document.getElementById("pmereniEdit");
			cil2.value=obsah;	
			//alert('editace: pid'+eid);	
			initEd4();				
		}
	}	
}

function pmereniEditSave(){
	var obsah = tinyMCE.get('pmereniEdit').getContent();
	cil=document.getElementById("prodeditmereni");	
	cil2=document.getElementById("pmereniEdit");
	//obsah=cil2.value;
	if(obsah==""){obsah="<h3>Měření</h3>"}	
	cil3=document.getElementById("formtext");
	cil3.value=obsah;
	cil3.name="pmereniText";
	cil4=document.getElementById("formgo");
	cil4.value="savePmereni";

	cil.innerHTML='<div id="pmereniObsah" onClick="prodeditmereni()">'+obsah+'</div>';
	obnovEditPmereni=setInterval("obnovEditPmereni()",500);
	
	document.getElementById('formgo').click()		
}

function pmereniEditDiscard(){
	cil=document.getElementById("prodeditmereni");	
	obsah=zasobnikWt;
	cil.innerHTML='<div id="pmereniObsah" onClick="prodeditmereni()">'+obsah+'</div>';
 	obnovEditPmereni=setInterval("obnovEditPmerenit()",500);
}

function obnovEditPmerenit(){
clearInterval(obnovEditPmereni);
editujese=false;
return false;
}

function addPrice(pid){
url="ajax.php?action=addprice&prodid="+pid;
//alert(url);
self.location=url;
}

function delPrice(id,pid){
url="ajax.php?action=delprice&prodid="+pid+"&idprice="+id;
//alert(url);
self.location=url;
}

function discardprice(){
x=rand(100,9999);
url="produkty.php#"+x;
self.location=url;
cil=document.getElementById("editpricebox");
//alert(cil.style.visibility);
cil.style.visibility="hidden";
}

function buy(id,prodid){
	//alert('Kupujete zbozi: '+prodid+' za cenu id:'+id);
	cil=document.getElementById("basketinfo");	
	cil.innerHTML="zboží bylo voženo do košíku...<br>";
	
	//alert(cil.checked);
	var url = "ajax.php?action=buy&buyProdId="+prodid+"&priceId="+id;
  	//alert(url);
		dataSource = getHTTPObject(); 
		dataSource.open("GET",encodeURI(url), true); 
	    dataSource.onreadystatechange = handleBuy; 
	    dataSource.send(null);				
	
}

function buyeng(id,prodid){
	//alert('Kupujete zbozi: '+prodid+' za cenu id:'+id);
	cil=document.getElementById("basketinfo");	
	cil.innerHTML="product has been added to basket...<br>";
	
	//alert(cil.checked);
	var url = "ajax.php?action=buy&buyProdId="+prodid+"&priceId="+id;
  	//alert(url);
		dataSource = getHTTPObject(); 
		dataSource.open("GET",encodeURI(url), true); 
	    dataSource.onreadystatechange = handleBuyEng; 
	    dataSource.send(null);				
	
}

function handleBuy(){
	  if (dataSource.readyState == 4) { 
		 if (dataSource.status == 200) { 
		   var XMLRes = dataSource.responseXML;   	
			//zachycení chyb IE a Opery   
			if(!XMLRes || !XMLRes.documentElement){   
			  throw("Chybná struktura XML1:\n"+dataSource.responseText);   
			}   
			//zachycení chyb ohnivé lišky :-)   
			var rootNodeName = XMLRes.documentElement.nodeName;   
			if(rootNodeName == "parsereerror"){   
			  throw("Chybná struktura XML2:\n"+dataSource.responseText);   
			}   
			//čtu dokument, jelikož je vše ok :-)   		
			xmlRoot = XMLRes.documentElement;
			pcs=xmlRoot.getElementsByTagName("pcs")[0].childNodes[0].nodeValue;    		
			price=xmlRoot.getElementsByTagName("price")[0].childNodes[0].nodeValue;
			//alert(pcs+" "+price);
			cil=document.getElementById("basket");
			cil.innerHTML="[ "+pcs+" pol.] "+price+" Kč";
			cil2=document.getElementById("basketBox");
			cil2.style.visibility="visible";			
			
//			 cil.innerHTML='<div id="wtObsah" onClick="editWelcome()">'+obsah+'</div>';			 
//			 alert('uloženo na serveru');
		} 
	  }
}

function handleBuyEng(){
	  if (dataSource.readyState == 4) { 
		 if (dataSource.status == 200) { 
		   var XMLRes = dataSource.responseXML;   	
			//zachycení chyb IE a Opery   
			if(!XMLRes || !XMLRes.documentElement){   
			  throw("Chybná struktura XML1:\n"+dataSource.responseText);   
			}   
			//zachycení chyb ohnivé lišky :-)   
			var rootNodeName = XMLRes.documentElement.nodeName;   
			if(rootNodeName == "parsereerror"){   
			  throw("Chybná struktura XML2:\n"+dataSource.responseText);   
			}   
			//čtu dokument, jelikož je vše ok :-)   		
			xmlRoot = XMLRes.documentElement;
			pcs=xmlRoot.getElementsByTagName("pcs")[0].childNodes[0].nodeValue;    		
			price=xmlRoot.getElementsByTagName("price")[0].childNodes[0].nodeValue;
			//alert(pcs+" "+price);
			cil=document.getElementById("basket");
			cil.innerHTML="[ "+pcs+" pcs.] "+price+" &euro;";
			cil2=document.getElementById("basketBox");
			cil2.style.visibility="visible";			
			
//			 cil.innerHTML='<div id="wtObsah" onClick="editWelcome()">'+obsah+'</div>';			 
//			 alert('uloženo na serveru');
		} 
	  }
}

function saveprice(id,prodid){
	//alert(document.getElementById("changeprice"));
	
	cil=document.getElementById("changedesc");	
	var descr=cil.value;
	
	cil2=document.getElementById("priceid");
	var	priceid=cil2.value;
		
	cil3=document.getElementById("changeprice");	
	var cena=cil3.value;	
	
	url="ajax.php";
	url="ajax.php?action=updateprice&idprice="+priceid+"&price="+cena+"&descr="+descr;;
	//alert(url);
	self.location=url;	
}

function editprice(id,cena){
	//alert(id+' '+cena);
	xid="changeprice";
	cil=document.getElementById(xid);
	cil.value=cena;
	
	xid="pricedesc"+id;	
	cil=document.getElementById(xid);
	text=cil.innerHTML;
	
	cil=document.getElementById("changedesc");
	cil.value=text;	
	
	cil=document.getElementById("priceprodid");
	cil.value=text;
	
	cil=document.getElementById("priceid");
	cil.value=id;	
	
	cil=document.getElementById("editpricebox");
//alert(cil.style.visibility);
	cil.style.visibility="visible";	
					
}

function tuningphoto(id){
	cil=document.getElementById("popis");	
	var url = "ajax.php?action=showphotos&fProdId="+id;
		dataSource = getHTTPObject(); 
		dataSource.open("GET",encodeURI(url), true); 
	    dataSource.onreadystatechange = handlePhoto; 
	    dataSource.send(null);	
		return(false);
}
function handlePhoto(){
	  if (dataSource.readyState == 4) { 
		 if (dataSource.status == 200) { 
//		   alert(dataSource.responseText);
		   var XMLRes = dataSource.responseXML;   			   
			//zachycení chyb IE a Opery   
			if(!XMLRes || !XMLRes.documentElement){   
			  throw("Chybná struktura XML1:\n"+dataSource.responseText);   
			}   
			//zachycení chyb ohnivé lišky :-)   
			var rootNodeName = XMLRes.documentElement.nodeName;   
			if(rootNodeName == "parsereerror"){   
			  throw("Chybná struktura XML2:\n"+dataSource.responseText);   
			}   
			//čtu dokument, jelikož je vše ok :-)   		
			xmlRoot = XMLRes.documentElement;
			photoid=xmlRoot.getElementsByTagName("photoid")[0].childNodes[0].nodeValue;  
			photoidhtml=xmlRoot.getElementsByTagName("photoidHTML")[0].childNodes[0].nodeValue;
			cil=document.getElementById("photoid"+photoid);
			cil.innerHTML=photoidhtml;
		} 
	  }
}
//</script>

