function getNavigationBar(id, gid, rep){
	//alert("nav");
     var url = "?module=getarrow&imgid="+id+"&galid="+gid;
//alert(url);
     if (url != 0){
        if (window.ActiveXObject){
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
          httpRequest = new XMLHttpRequest();
        }
        httpRequest.open("GET", url, true);
        httpRequest.onreadystatechange= function () {processRequest(id, gid, rep); } ;
        httpRequest.send(null);
      }else{
        document.getElementById("navigation").innerHTML = "URL Error!";
      }
}

function processRequest(id, gid, rep){
  if (httpRequest.readyState == 4){
    if(httpRequest.status == 200){
      var navigation = document.getElementById("navigation");
      navigation.innerHTML = httpRequest.responseText;
	
      if ( document.getElementById('a_right') != undefined )
            document.getElementById('imgAbx').onclick = document.getElementById('a_right').onclick;

	if ( rep == 1 )
		getNavigationBar(id, gid, rep);

    }else{
        alert("Chyba pri nacitani stanky"+ httpRequest.status +":"+ httpRequest.statusText);
    }
  }
}
function chImg(tgt, id, path){
	document.getElementById('imgAbx').src = tgt;
	var vara = tgt.split("/");
	//document.getElementById('nadpisWindow').innerHTML = vara[vara.length-1];
	getNavigationBar(id, path, 0);
}

function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {  
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}   
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){  
		pageWidth = xScroll;        
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}


/*function  menuPop(element){
	e = document.getElementById(element);
	if(e.style.display == "block"){
	e.style.display = "none";
	} else {
	e.style.display = "block";
	}
}

var TIMER = 5;
var SPEED = 10;

function pageWidth() {
	return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null
}

function pageHeight() {
	return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

function topPosition() {
	return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

function leftPosition() {
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

function getStyle(el,styleProp){
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function dialogCreate(div_name, title,message,type,autohide, width, height, id, path) {

	var dialog;
	var inner;

	if(!document.getElementById(div_name)){
		dialog = document.createElement('div');
		dialog.id = div_name;
		dialog.className = type +" window";
		dialog.style.position = "absolute";
		document.body.appendChild(dialog);
	} else {
		dialog = document.getElementById(div_name);
		dialog.className = type +" window";
	}

	if(width && height){
		dialog.style.minwidth = width;
		dialog.style.minheight = height;
	}

	inner = "<div class=\"title\"><h2 onClick=\"javascript: dialogHide('"+div_name+"', 'st')\">"+title+"</h2><br class=\"clearer\" /><p style=\"text-align: center;\"><img id=\"imgAbx\" onClick=\"javascript: dialogHide('"+div_name+"', 'st')\" style=\"max-width: "+(width)+"px; max-height: "+(height)+"px;\" src=\""+message+"\" /></p><div id=\"navigation\"></div></div>";
	
	document.getElementById(div_name).innerHTML = inner;
	
	dialog = document.getElementById(div_name);
	dialog.style.visibility = "visible";

	dialog.style.opacity = .00;
	dialog.style.filter = 'alpha(opacity=0)';
	dialog.alpha = 0;

	//var width = pageWidth();
	//var height = pageHeight();
	var left = leftPosition();
	var top = topPosition();

	var dialogwidth = dialog.offsetWidth;
	var dialogheight = dialog.offsetHeight;

	var topposition = top + (height / 2) - (dialogheight / 2);
	var leftposition = left + (width / 2) - (dialogwidth / 2);

	dialog.style.top = topposition + "px";
	dialog.style.left = leftposition + "px";
	var overlay = document.getElementById('content');
	
	dialog.timer = setInterval("dialogFade('"+div_name+"', 1, '')", TIMER);
	
	if(autohide) { window.setTimeout("dialogHide('"+div_name+"', 'st')", (autohide * 1000)); }
	
	getNavigationBar(id, path);
}

function colorChange(id, element, c){
	var dialog = document.getElementById(id);
	var e = document.getElementById(element);
	clearInterval(dialog.timer2);

	if(c){
		e.style.background = "#ababab"
		e.style.opacity =  0.7;
	} else {
		e.style.background = "#fff";
		e.style.opacity =  1.0;
	}

}

function dialogHide(id, d) {
	var dialog = document.getElementById(id);
	clearInterval(dialog.timer);
	dialog.timer = setInterval("dialogFade('"+id+"', 0)", TIMER);
}

function dialogFade(id, flag, html) {
	if(flag == null) {flag = 1;}
	var dialog = document.getElementById(id);
	var value;
	if(flag == 1) { value = dialog.alpha + SPEED; }
	else { value = dialog.alpha - SPEED;}
	dialog.alpha = value;
	dialog.style.opacity = (value / 100);
	dialog.style.filter = 'alpha(opacity=' + value + ')';
	if(value >= 95) {
		clearInterval(dialog.timer);
		dialog.timer = null;
		dialog.innerHTML += html;
	} else if(value <= 1) {
		dialog.style.visibility = "hidden";
		clearInterval(dialog.timer);
	}
}
*/

function  menuPop(element){
	e = document.getElementById(element);
	if(e.style.display == "block"){
	e.style.display = "none";
	} else {
	e.style.display = "block";
	}
}

var TIMER = 5;
var SPEED = 10;

function pageWidth() {
	return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

function pageHeight() {
	return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

function topPosition() {
	return typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
}

function leftPosition() {
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

function getStyle(el,styleProp){
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function __dialogCreate(div_name, title,message,type,autohide, width, height, id, path, rep, prev, next, min, max, wrap) {

	var black;
	var dialog;
	var inner;
	
	var index;
	var se;
	se = getPageSize();
	//alert(se[0]se[1]se[2]se[3]);
	if(!document.getElementById("indexer")){
		index = document.createElement('div');
		index.id = "indexer";
		index.style.width = se[2]+"px";
		index.style.height = se[3]+"px";
		index.style.left = "0px";
		index.style.top = "0px";
		index.style.float = "none";
		index.style.paddingTop = "0px";
		index.style.paddingBottom = "0px";
		index.style.paddingLeft = "0px";
		index.style.paddingRight = "0px";
		index.style.position = "fixed";
		index.style.background = "#CCC";
		
  	index.style.alpha = 80;
  	index.style.opacity = (80 / 100);
  	index.style.filter = 'alpha(opacity=' + 80 + ')';
	
		index.style.zIndex  = "49";
		document.body.appendChild(index);

	} else {
  
    document.getElementById("indexer").style.display="block";
  
  }
	
	if(!document.getElementById(div_name)){
		dialog = document.createElement('div');
		dialog.id = div_name;
		dialog.className = type +" window";
		dialog.style.zIndex  = "50";
		dialog.style.position = "absolute";
		document.body.appendChild(dialog);

  	if ( title != "text"){
      inner = "<div class=\"title\"><h1>Obrázek</h1><hr /><p style=\"text-align: center;\"><img style=\"max-width: 500px;\" onClick=\"javascript: dialogHide('"+div_name+"', 'st')\" src=\""+message+"\" /></p></div>";
    }else{  
      inner = "<style>#blk, #blk:visited, #blk:link{color: #000;}</style></style><div class=\"title\"><h1>Novinka</h1><hr /><p>"+message+"</p><p onClick=\"javascript: dialogHide('"+div_name+"', 'st')\" id=\"blk\" style=\"text-weight: bold; text-align: right;\">Zavrit</p></div>";
  	} 
  	document.getElementById(div_name).innerHTML = inner;
  	document.getElementById(div_name).style.background = "#FFFFFF";

  } else {
		dialog = document.getElementById(div_name);
		dialog.className = type +" window";
		dialog.style.display = "block";                                
  	dialog.style.background = "#FFFFFF";
	}
	
	if ( title == "Obrazek"){
    inner = "<div class=\"title\"><h1>Obrázek</h1><p style=\"position: absolute; right: 0; top: 0; padding: 5px; width: 150px; margin: 5px; text-align: center; background: #2F2F2F;\"><a href=\"javascript:dialogHide('"+div_name+"', 'st');\">Zavřít</a></p><hr /><p style=\"text-align: center;\"><img id=\"imgPopup\" style=\"max-width: 500px;\" onClick=\"javascript: dialogHide('"+div_name+"', 'st')\" src=\""+message+"\" /></p>";
    
    inner = inner+"<div id=\"contentM\">";
    
    if ( prev != '' )
      inner = inner + "<p style=\"padding: 5px; width: 150px; float: left; margin: 5px; text-align: center; background: #2F2F2F;\"><a href=\"javascript:chImgPopup("+prev+", "+min+", "+max+", '"+wrap+"');\">Předchozí</a></p>";
    if ( next != '' )
      inner = inner + "<p style=\"padding: 5px; width: 150px; float: right; margin: 5px; text-align: center; background: #2F2F2F;\"><a href=\"javascript:chImgPopup("+next+", "+min+", "+max+", '"+wrap+"');\">Další</a></p>";
    
    inner = inner+"<br style=\"clear: both;\" /></div>";
    
    inner = inner+"</div>";
  	document.getElementById(div_name).innerHTML = inner;
  }

	if(width && height){
		dialog.style.maxwidth = width;
		dialog.style.maxheight = height;
		var dialogwidth = width;
		var dialogheight = height;
	}else{		
		var dialogwidth = dialog.offsetWidth;
		var dialogheight = dialog.offsetHeight;
	}

	//inner = "<div class=\"title\"><h2 id=\"nadpisWindow\" onClick=\"javascript: dialogHide('"+div_name+"', 'st')\">"+title+"</h2><img style=\"float:right;\"  onClick=\"javascript: dialogHide('"+div_name+"', 'st')\" src=\"./images/zavrit.jpg\" /><br class=\"clearer\" /><p style=\"text-align: center;\"><img id=\"imgAbx\" onClick=\"javascript: dialogHide('"+div_name+"', 'st')\" style=\"max-width: "+(width-200)+"px; max-height: "+(height-200)+"px;\" src=\""+message+"\" /></p><div id=\"navigation\"></div></div>";
	//inner = "<div class=\"title\"><img style=\"float:right;\"  onClick=\"javascript: dialogHide('"+div_name+"', 'st')\" src=\"./images/zavrit.jpg\" /><br class=\"clearer\" /><p style=\"text-align: center;\"><img id=\"imgAbx\"  style=\"max-width: "+(width-200)+"px; max-height: "+(height-200)+"px;\" src=\""+message+"\" /></p><div id=\"navigation\"></div></div>"; 
	
	dialog = document.getElementById(div_name);
	dialog.style.visibility = "visible";
	//if (navigator.appName == "Microsoft Internet Explorer"){
	//	document.getElementById("indexer").style.visibility = "hidden";
	//}else{
		document.getElementById("indexer").style.visibility ="visible";
	//}

	dialog.style.opacity = .00;
	dialog.style.filter = 'alpha(opacity=0)';
	dialog.alpha = 0;

	var width = window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
	var height = window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
	var left = typeof window.pageXOffset != 'undefined' ? window.pageXOffset : document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
	var top = typeof window.pageYOffset != 'undefined' ? window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;

	//var dialogwidth = dialog.offsetWidth;
	//var dialogheight = dialog.offsetHeight;

	var topposition = top + (height / 2) - (dialogheight / 2);
	var leftposition = left + (width / 2) - (dialogwidth / 2);

	dialog.style.top = topposition + "px";
	dialog.style.left = leftposition + "px";
	var overlay = document.getElementById('content');
	
	dialog.style.display="block";
	
	dialog.timer = setInterval("dialogFade('"+div_name+"', 1, '')", TIMER);
	
	if(autohide) { window.setTimeout("dialogHide('"+div_name+"', 'st')", (autohide * 1000)); }
	
	getNavigationBar(id, path, rep);
}

function chImgPopup(id, min, max, wrap){
  document.getElementById('imgPopup').src = "./upload/"+wrap+id+".jpg";
  
  var innerV = "";
  if ( id-1 > 0 )
    innerV = innerV + "<p style=\"padding: 5px; width: 150px; float: left; margin: 5px; text-align: center; background: #2F2F2F;\"><a href=\"javascript:chImgPopup("+(id-1)+", "+min+", "+max+", '"+wrap+"');\">Předchozí</a></p>";
  if ( id+1 <= max )
    innerV = innerV + "<p style=\"padding: 5px; width: 150px; float: right; margin: 5px; text-align: center; background: #2F2F2F;\"><a href=\"javascript:chImgPopup("+(id+1)+", "+min+", "+max+", '"+wrap+"');\">Další</a></p>";
  
  innerV = innerV+"<br style=\"clear: both;\" />";
  
  document.getElementById('contentM').innerHTML = innerV;
    
}

function colorChange(id, element, c){
	var dialog = document.getElementById(id);
	var e = document.getElementById(element);
	clearInterval(dialog.timer2);

	if(c){
		e.style.background = "#ababab"
		e.style.opacity =  0.7;
	} else {
		e.style.background = "#fff";
		e.style.opacity =  1.0;
	}

}

function dialogHide(id, d) {

	document.getElementById(id).style.display="none";
	document.getElementById("indexer").style.display="none";
	
	/*var dialog = document.getElementById(id);
	clearInterval(dialog.timer);
	dialog.timer = setInterval("dialogFade('"+id+"', 0)", TIMER);*/
}

function dialogFade(id, flag, html) {
	if(flag == null) {flag = 1;}
	var dialog = document.getElementById(id);
	var value;
	if(flag == 1) { value = dialog.alpha + SPEED; }
	else { value = dialog.alpha - SPEED;}
	dialog.alpha = value;
	dialog.style.opacity = (value / 100);
	dialog.style.filter = 'alpha(opacity=' + value + ')';
	if(value >= 95) {
		clearInterval(dialog.timer);
		dialog.timer = null;
		dialog.innerHTML += html;
	} else if(value <= 1) {
		dialog.style.visibility = "hidden";
		document.getElementById("indexer").style.visibility="hidden";
		clearInterval(dialog.timer);
	}
}

var __a = '<td style="padding-right: 10px;"><div class="aa1"><big style="font-weight: bold;">Text</big> <br><p style="padding-left: 30px; line-height: 19px;"><span style="font-weight: bold;">Text</span><br>adresa<br>adresa<br>adresa<br></p></div></td>';

function __addNewRow( id ){
  
  var tgt = document.getElementById(id);
  var dialog = document.createElement('tr');
  tgt.appendChild(dialog);
  
}

function __addNewBubble( id ){
  
  var tgt = document.getElementById(id);
  var tr = tgt.getElementsByTagName('tr');
  
  tr[tr.length-1].innerHTML = tr[tr.length-1].innerHTML + __a;
  
}

function addNews(){

  if (document.getElementById('con2') && document.getElementById('con3').innerHTML ) document.getElementById('con3').innerHTML = document.getElementById('con2').innerHTML;
  if (document.getElementById('con2') && document.getElementById('con1').innerHTML ) document.getElementById('con2').innerHTML = document.getElementById('con1').innerHTML;
  if (document.getElementById('con1') ) document.getElementById('con1').innerHTML = "&nbsp;<p>text</p>";
  
  if (document.getElementById('qcon2') && document.getElementById('qcon3').innerHTML ) document.getElementById('qcon3').innerHTML = document.getElementById('qcon2').innerHTML;
  if (document.getElementById('qcon2') && document.getElementById('qcon1').innerHTML ) document.getElementById('qcon2').innerHTML = document.getElementById('qcon1').innerHTML;
  if (document.getElementById('qcon1') ) document.getElementById('qcon1').innerHTML = "&nbsp;<p>text</p>";

}
