// JavaScript Document

var prefix = "http://" + location.hostname + "/";

function IMG_zoom(url) {
  var w    = 300;
  var h    = 300;
  var left = (screen.width/2) -(w/2);
  var top  = (screen.height/2)-(h/2);
  var raksts_imgzoom = open(prefix + 'raksts_imgzoom.php?url=' + url, 'raksts_imgzoom', 'width=' + w + ', height = ' + h + ', top=' + top + ', left=' + left);
  raksts_imgzoom.focus();
}

function Popup(url) {
  var w    = 800;
  var h    = 600;
  var left = (screen.width/2) -(w/2);
  var top  = (screen.height/2)-(h/2);
  var popup_zoom = open(prefix + 'popup.php?url=' + url, 'popup_zoom', 'width=' + w + ', height = ' + h + ', top=' + top + ', left=' + left + ', scrollbars');
  popup_zoom.focus();
}

function Bibls(id, arhivs) {
    var w = 300;
    var h = 300;    
    var top  = screen.height/2-h/2;
    var left = screen.width/2-w/2;    
	var bibls = open(prefix + 'avizes_bibls.php?id=' + id + '&arhivs=' + arhivs, 'bibls', 'width=' + w + ', height=' + h + ', left=' + left + ', top=' + top + ', scrollbars');
	bibls.focus();
}

function IMG_repl_link() {

  function IMG_urlencode(url) {
	var n_url = '';
    for (var i = 0; i < url.length; i++)
	  switch (url.charAt(i)) {
		  case '?': n_url += '%3F'; break;
		  case '&': n_url += '%26'; break;
		  case '=': n_url += '%3D'; break;
		  case ' ': n_url += '%20'; break;
		  default:  n_url += url.charAt(i);
	  }
	return n_url;
  }
  
  var a = document.getElementsByTagName('a');  
  for (i = 0; i < a.length; i++)
	if (a.item(i).childNodes.length == 1 && a.item(i).childNodes[0].src != null && 
		a.item(i).childNodes[0].src != "" && a.item(i).href.indexOf('javascript:') == -1 && a.item(i).href.indexOf('imgs/') != -1) {

	  if (a.item(i).childNodes[0].nodeName.toLowerCase() == 'img' && a.item(i).childNodes[0].src.indexOf('imgs/') != -1) {

		a.item(i).href = "javascript:IMG_zoom('" + IMG_urlencode(a.item(i).href) + "')";
		a.item(i).target = "";
	  
	  }
	
	} else
	if (a.item(i).target == '_popup') {
	
	  a.item(i).href = "javascript:Popup('" + IMG_urlencode(a.item(i).href) + "')";
	  a.item(i).target = "";
		
	}
		
}