function openPicWin(pFileName,pWinName,pWidth,pHeight) {
	var isNS = (document.layers) ? true : false;
	
	if (isNS) pHeight = pHeight + 19;
		eval("allSettings = 'width="+pWidth+",height="+pHeight+",menubar=yes,scrollbars=yes,status=yes,resizable=yes'");
		w=window.open(pFileName,pWinName,allSettings);
		w.window.focus();
}

// functions for iframe expander in all various browsers [START]

function getIFrameDoc( name ) {
  var IFrameDoc;
  var Height;
  var IFrameObj = document.getElementsByName(''+name)[0];
  
  if (typeof document.frames != 'undefined') {
    IFrameObj = document.frames[name];
  }
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return false;
  }
  
  if(typeof IFrameDoc.body != 'undefined')
  {
    return IFrameDoc.body;
  }
  else
  {
    return IFrameDoc.documentElement;
  }
}

/*
* gets the height of an iframe document
*/
function getIFrameDocHeight( name )
{
var IFrameDoc = getIFrameDoc( name );
  if(typeof IFrameDoc == 'undefined')
    return false;
  return IFrameDoc.scrollHeight;
}

/*
* gets the width of an iframe document
*/
function getIFrameDocWidth( name )
{
var IFrameDoc = getIFrameDoc( name );
  if(typeof IFrameDoc == 'undefined')
    return false;
  return IFrameDoc.scrollWidth;
}

// functions for iframe expander in all various browsers [END]

/**
 * Register onclick events for all document links to track
 * them whith WhosOn
 */
document.observe("dom:loaded", function() {
	$$('a').each(function(link,index) {
		if(link.tagName == 'A' && typeof(link.href) == "string" && link.href != ''){
			var href = link.href;
			var pattern = /\.pdf|dyn_link\.html|media\/download\.html/i;
			// is not external and is downloadable
			if(href != null && href.match(pattern) != null && href.match(/^https?:\/\//i) == null) {
				if(href.match(/dyn_link\.html/i) || href.match(/media\/download\.html/i)) {
					var file = href.replace(/^.*(\?|&)media[\._]id=/i, '');
					new Ajax.Request(absCorrect+'ajax.html?content.display=getLinkType&content.file='+file, {
						method: 'get',
						onSuccess: function(data) {
							var info = data.responseText.evalJSON();
							if(info.mimetype == 'application/pdf' && info.name) {
								Event.observe(link, 'click', function(event) {
									sendWhosOnRequest(info.name);
								});
							}
						}
					});
				} else {
					var name = href.replace(/^([^\/]*\/)*/i, '');
					Event.observe(link, 'click', function(event) {
						sendWhosOnRequest(name);
					});
				}
			}
		}	
	});
});

function sendWhosOnRequest(filename) {
	new Ajax.Request(absCorrect+'ajax.html?navigation.display=whosonOptions&navigation.path='+encodeURIComponent(window.location), {
		method: 'get',
		onSuccess: function(data) {
			var info = data.responseText.evalJSON();
			var path = info.path+filename;
			
			writeWhosOn(
				info.gateway+':'+info.port,
				info.domain,
				path
			);
		}
	});
	
	return true;
}

