var popWin;
function openPopWindow(src, options, name)
{
	var x = arguments[3];	
	var y = arguments[4];	

	if (x) options+= ",left="+x+",screenX="+x;
	if (y) options+= ",top="+y+",screenY="+y;

	if (!(src.indexOf("http")==0 || src.indexOf("/")==0)) {
		src = src;
	}

	if (src.search(/\.(jpg|gif|jpeg|png)$/ig) != -1) {
		openImagePopUp(src, options, name, x, y, '', true);
		return;
	}
	
	if (popWin) popWin.close();
	if ( popWin=window.open(src, name, options) )
		popWin.focus();
}

function openImagePopUp(src, options, name)
{
    var matches, width = 0, height = 0;
    if (matches = options.match(/width\=(\d+)/i)) width = matches[1];
    if (matches = options.match(/height\=(\d+)/i)) height = matches[1];

	var x = arguments[3] || (screen.width-width)/2;
	var y = arguments[4] || (screen.height-height)/2;
	var title = arguments[5];
	var secondary = arguments[6];

	if (!(src.indexOf("http")==0 || src.indexOf("/")==0)) {
		src = src;
	}

	if (!secondary && width && height) {
		if (x) options+= ",left="+x+",screenX="+x;
		if (y) options+= ",top="+y+",screenY="+y;
	}

	if (popWin) popWin.close();
	popWin = window.open( "", name, options);

    var size = width && height ? "width='"+width+"' height='"+height+"'" : "";

    var html = "";
	html+= "<html><head>";
	if (title) html+= "<title>" + title + "</title>";
	html+= '<style>body { margin:0px; padding:0px; top:0px; left:0px }</style>';
	html+= '</head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">';
	html+= "<img src='"+src+"' "+size+" border='0' onclick='window.close();' style='cursor: pointer;' />";
	html+= "</body></html>";	
		
	popWin.document.write(html);
	popWin.document.close();
	popWin.focus();
} 
