/* gedruktmateriaal.js */

/* 
  C-like sprintf function. 
  Example: 
  document.write(sprintf('A cow says %1, a squirrel says %2.', 'moo', 'sqeak'))
 */
function sprintf(strTemplate) 
{ 
	if (arguments.length == 0) return ''; 
	if (arguments.length == 1) return arguments[0]; 
	var line = new String(strTemplate); 
	var template = arguments[0]; 
	var rx; 
	for (var i = 1; i < arguments.length; i++) { 
		rx = new RegExp('(%' + i + ')', 'g'); 
		line = line.replace(rx, arguments[i]) 
	} 
	return line; 
} 

/* Open het helpscherm voor een bepaalde pagina */
function OpenHelp(pagina,bookmark,paginaNaam,niveau, hoogte, breedte)
{	
	var url = pagina;
	var querystringindex = url.indexOf("?");
	if(querystringindex != -1)
		url = url.substring(0,querystringindex);
		
	url = url.replace(".aspx",".html");
	
	var lastslashindex = url.lastIndexOf("/");
	var partone = url.substring(0,lastslashindex);
	var parttwo = url.substring(lastslashindex,url.length);
	url = partone+ "/help.aspx?url="+partone+"/help&helpbestand="+parttwo;
		
	if (bookmark.length != 0)
		url = url+"#"+bookmark;
	
	wnd = window.open(url,paginaNaam,"left=15,top=15,height=" + hoogte + ",width=" + breedte + ",channelmode=no,directories=no,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes");
	wnd.focus();
}

/* Maak een popup waarin een scan getoond wordt. */
function image_viewer(strUrl)
{
	var width = document.body.offsetWidth;
	var height = screen.height - 120;
	var x = (screen.width - width) / 2;
	var y = (screen.height - height) / 2;
	var windowFeatures  = sprintf('top=%1,left=%2,width=%3,height=%4,resizable=yes,scrollbars=yes', y, x, width, height);
	var wnd = window.open(strUrl, 'imageviewer', windowFeatures);
}

/* Functies gebruikt in de akten pagina's. */
function handleOnload()
{
	window.focus(); 
	load_layout_settings();
	panel_do_layout();
}

i_textpanel = 2
i_editorpanel = 8
i_panel_ratio = 0.8

function panel_enlarge(strOption)
{
	if (!strOption) strOption = 'equal'
	if (strOption == 'text') {
		i_textpanel = 8
		i_editorpanel  = 2
	} else if (strOption == 'editor') {
		i_textpanel= 2
		i_editorpanel = 8
	} else {
		i_textpanel= 1
		i_editorpanel = 1
	}
	i_panel_ratio = i_textpanel / (i_textpanel + i_editorpanel)
	
	panel_do_layout()
}
					
function panel_do_layout()
{
	var textpanel = document.getElementById('text_panel');
	if (!textpanel) 
		return;

	var fixedheight = 200; 
	var height = 700; 
	if (document.body.clientHeight) 
		height = document.body.clientHeight - fixedheight;  
	
	textpanel.style.height = height - 5 + 'px';

	var hiddenwidth = document.getElementById('HiddenScreenWidth');
	var hiddenheight = document.getElementById('HiddenScreenHeight');
	if (!hiddenwidth) 
		return;
	if (!hiddenheight) 
		return;
	
	var tmpclientwidth = 0.90 * document.body.clientWidth;

	if( (hiddenwidth.value != tmpclientwidth) || (hiddenheight.value != height) )
	{
		hiddenwidth.value = tmpclientwidth;
		hiddenheight.value = height;
		__doPostBack('HiddenScreenWidth','');
	}
}
					
function store_layout_settings()
{
	document.cookie = 'PANEL_RATIO=' + i_panel_ratio;
}
					
function load_layout_settings()
{
	var cookiestring = new String(document.cookie)
	var ratio = cookiestring.match(/PANEL_RATIO=([\d\.]+)/)
	if (ratio) {
		i_panel_ratio = new Number(ratio[1])
		i_text_panel = i_panel_ratio
		i_editor_panel = 1 - i_text_panel;
	} else {
		i_panel_ratio = 0.8
		i_text_panel = 2
		i_editor_panel = 8
	}
}

/* Open het persoonscherm voor een bepaald object */
function openPersoon(rolid, actie, persoonid, titel, showberoep)
{
	var url = "MuteerPersoon.aspx?rolid="+rolid+"&actie="+actie+"&persoonid="+persoonid+"&titel="+titel+"&showberoep="+showberoep;
	window.open(url,"Persoon","scrollbars=yes,resizable=yes,width=740,height=470");
}

function getScreenResolution()
{
	var tmpelement = document.getElementById('HiddenScreenWidth');
	if (!tmpelement) return;
	
	var tmpclientwidth = 0.85 * document.body.clientWidth;
	tmpelement.value = tmpclientwidth;
}

function getOffset(n) 
{
	var pos = new Object();

	pos.x = n.offsetLeft; pos.y = n.offsetTop;

	if(n == document.body) return pos;

	while((n = n.offsetParent) != document.body) {

	pos.x += n.offsetLeft;

	pos.y += n.offsetTop;

	} return pos;
}

function getCoords(evt)
{
	var xpos = (evt || event).clientX,
	ypos = (evt || event).clientY,
	target = (typeof evt != 'undefined') ? evt.target : event.srcElement;

	if(target.id == 'ImgDocument')
	{
		var xcoordinaat = document.getElementById('XCoordinaat');
		var ycoordinaat = document.getElementById('YCoordinaat');
	
		xcoordinaat.value = (xpos - (getOffset(target)).x) - 2;
		ycoordinaat.value = (ypos - (getOffset(target)).y) - 2;

		if((evt || event).button == 1)
			document.getElementById('BtnInzoomen').click();
		else if((evt || event).button == 2)
			document.getElementById('BtnUitzoomen').click();
		return false;
	}
	return true;
}

function clickIE() {
	if (document.all) return false;
}

function clickNS(e) {
	if (document.layers||(document.getElementById&&!document.all)) {
		if (e.which==2||e.which==3) return false;
	}
}

function gotoResultaten()
{
	var bookmarkindex = document.location.href.indexOf("#");
	if(bookmarkindex == -1)
		document.location.href += "#resultaten";
}

