function foc(win) {
 if (window.focus) {win.focus()}
 return false;
}
function pop(url) {
 newwindow=window.open(url, "popup", 'height=400,width=600,toolbar=no,scrollbars=no,resizable=yes');
 return foc(newwindow);
}
function popHTML(url) {
 newwindow=window.open(url, "popup", 'height=400,width=600,toolbar=no,scrollbars=yes,resizable=yes');
 return foc(newwindow);
}

function popFlash(url) {
 newwindow=window.open(url, "popup", 'height=400,width=600,toolbar=no,scrollbars=no,resizable=yes');
 return foc(newwindow);
}

function popImage(img) {
	titre="Popup Image";
	w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=yes');	
	w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE>");
	w.document.write("<SC"+"RIPT language=java"+"script> function checksize()  { if (document.images['img'].complete) {  window.resizeTo(document.images[0].width+12,document.images[0].height+30); window.focus();} else { setTimeout('checksize()',250) } }</"+"SCRIPT></HEAD>");
	w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><a href=\"#\" onClick=\"window.close()\"><IMG src='"+img+"' border=0 name='img'></a>");
	w.document.write("");
	w.document.write("</BODY></HTML>");
	w.document.close();
 return foc(w);
}

var x = document.getElementsByTagName('a');
for (var i=0;i<x.length;i++) {
 if (x[i].getAttribute('type') == 'popup') {
  x[i].onclick = function () {
   return pop(this.href)
  }
  x[i].title += ' (Popup)';
 }
 if (x[i].getAttribute('type') == 'image') {
  x[i].onclick = function () {
   return popImage(this.href)
  }
  x[i].title += ' (Popup)';
 }
 if (x[i].getAttribute('type') == 'html') {
  x[i].onclick = function () {
   return popHTML(this.href)
  }
  x[i].title += ' (Popup)';
 } 
 if (x[i].getAttribute('type') == 'flash') {
  x[i].onclick = function () {
   return popFlash(this.href)
  }
  x[i].title += ' (Popup)';
 }
}
