// Module: CROW uavgc //
// Versie: 0000 //
// Datum: 29-3-2004 15:39 //

function newSearch(){
	top.Fhead.zoekform.reset();
	top.Fzoek.readOnly();
}

function OpenSearch(){
	top.myFnode3.location.href='xload.htm';
}

function getParam(name, url){
//	alert(url)
	qm = url.indexOf('?');
	if (qm > -1){
		start = url.indexOf(name + '=', qm);
		if (start > -1){
			end = url.indexOf('&', start);
			if (end > -1){
				return unescape(url.substring(start + name.length + 1, end));
			}else{
				end = url.indexOf('#', start);
				if (end > -1){
					return unescape(url.substring(start + name.length + 1, end));
				}else{
					return unescape(url.substring(start + name.length + 1));
				}
			}
		}
	}
	return null;
}

function fillId(Id, data){
	var elem = document.getElementById(Id);
	elem.innerHTML = data;
}

function loaded(qs){
	qs='dummy.htm?'+decodeURIComponent(qs);
	top.Fhead.zoekform.foboomid.value=getParam('foboomid',qs);
	top.Fhead.zoekform.querytext.value=getParam('querytext',qs);
	top.Fhead.zoekform._md_pubyear_from.value=getParam('_md_pubyear_from',qs);
	top.Fhead.zoekform._md_pubyear_to.value=getParam('_md_pubyear_to',qs);
	top.Fhead.zoekform._md_person.value=getParam('_md_person',qs);
	top.Fhead.zoekform._md_da_title.value=getParam('_md_da_title',qs);
	top.Fhead.zoekform._md_publisher.value=getParam('_md_publisher',qs);
	//ModeSearch=getParam('ModeSearch',qs);
}

function GatherQuery(){
	var qs = '';

	//arrays of type and query//
	var htype  = top.myFzoek.document.getElementsByName('htype');
	var hquery = top.myFzoek.document.getElementsByName('hquery');

	if(htype){
		//special fields//
		var usedRow = top.myHiddenForm.usedRow.value;
		qs += '?foboomid=' +top.myHiddenForm.foboomid.value;
		qs += '&InTree=' +top.myHiddenForm.InTree.value;
		qs += '&usedRow=' +top.myHiddenForm.usedRow.value;
		qs += '&freeId=' +top.myHiddenForm.freeId.value;
//		qs += '&refinequery=' +top.myHiddenForm.refinequery.value;
//		qs += '&inResult=' +top.myHiddenForm.inResult.value;//
		var j = 0;
		var qst = '';
		for(var i=0; i<usedRow.length; i++){//type and query fields//
			qst += '&htype' +j+ '=' +encodeURIComponent(htype[i].value);
			qst += '&hquery' +j+ '=' +encodeURIComponent(hquery[i].value);
			j++;
		}
		qs += '&count='+j;
		qs += qst;
	}
	return qs;
}

function SaveQuery(){
location.href='xsave.htm'+GatherQuery();
}

function LC(str, ss){
	var Oc = 0;
	while (str.indexOf(ss) != -1){
		Oc++;
		str = str.substring(str.indexOf(ss)+ss.length, str.length);
	}
	return Oc;
}

var initLoadQuery = '';
function InitLoadQuery(qs){
//	top.FtextLoad('/leeg.htm');
	initLoadQuery = qs;
	top.gSearched = false;
	top.FtextLoad(tabFtextArr[0][1]);
}

function GGGiveName(naam){
	var r = ''+unescape(naam);
	var pdfstr = '.pdf';
	var htmstr0 = '.html';
	var htmstr1 = '.htm';
	var p1 = r.indexOf('&VdkVgwKey=');
	var p2 = r.indexOf('&DocOffset=',p1);
	if(p1>0 && p2>0){
		r = r.substr(p1+13,p2-(p1+13));
	}
	var l = r.toLowerCase();
	p1 = l.indexOf(top.gDataPath.toLowerCase());
	if(gFtextPdf){
		p2 = l.indexOf(pdfstr);
		if(p1 > 0){
			r = r.substring(p1, p2+pdfstr.length);
		}

	}else{
		p2 = l.indexOf(htmstr0);
		alert('0\nhtm(l) document');
		if(p1 > 0){
			if(p2 != -1){
				r = r.substring(p1, p2+htmstr0.length);
				alert('1\n'+r);
			}else{
				p2 = l.indexOf(htmstr1);
				r = r.substring(p1, p2+htmstr1.length);
				alert('2\n'+r);
			}
		}
	}
	return r;
}

function GiveDoc(arg){
	var str = unescape(arg).toLowerCase();
	str = str.substr(str.indexOf(gDataPath));
	var pm = str.indexOf('#');
	if(pm!=-1) str = str.substring(0,pm);
	else{
		pm = str.indexOf('?');
		if(pm!=-1) str = str.substring(0,pm);
		else{
			pm = str.indexOf('&');
			if(pm!=-1) str = str.substring(0,pm);
		}
	}
	return str;
}

function GiveDocComplete(arg){
	var str = unescape(arg).toLowerCase();
	str = str.substr(str.indexOf(gDataPath));
	pm = str.indexOf('?');
	if(pm!=-1) str = str.substring(0,pm);
	else{
		pm = str.indexOf('&');
		if(pm!=-1) str = str.substring(0,pm);
	}
	return str;
}

function GiveName(arg){
	var str = unescape(arg).toLowerCase();
	var pad = '';
	if(gFtextPdf){
		var pdf = '.pdf';
		pad = str.substr(str.indexOf(gDataPath)	,str.indexOf(pdf)+pdf.length);
	}else{
		var htm = '.htm';
		var html = 'html';
		var ml = (str.indexOf(html) != -1) ? html : htm;
		pad = str.substr(str.indexOf(gDataPath)	,str.indexOf(ml)+ml.length);
	}
	return pad;
}

function LoadQuery(){
	var zoek = top.myFtext.document;
	var seld = '';
	var wrde = '';
	qs = "dummy.htm?" + decodeURIComponent(initLoadQuery);
	var savedItems = Math.abs(getParam('count', qs));
	var rid = 0;
	for(var k=0; k<savedItems; k++){
		var seld = getParam('htype'+k,qs);
		var wrde = getParam('hquery'+k,qs);
		if(seld=='') seld="0";
		seld2 = seld.indexOf('_');
		if(seld2!=-1){
			var seld3 = seld.substr(seld2+1);
			seld  = seld.substring(0,seld2);
			rid = top.myFtext.CreateRow(seld,seld3);
			var arry = top.myFtext.eval(top.myFtext.mainArr[seld][2]);
			dtype = arry[seld3][2];
		}else{
			rid = top.myFtext.CreateRow(seld);
			dtype = top.myFtext.mainArr[seld][1];
		}
		if(dtype=='dt'){	// Periode
			var hvalue = wrde.substr( 0,4);
			var re = / /g;
			hvalue = hvalue.replace(re,"");
			zoek.getElementById('date_'	+rid).value = hvalue;
		}else if(dtype=='ft'){	// Periode
			var hvalue = wrde.substr( 0,4);
			var re = / /g;
			hvalue = hvalue.replace(re,"");
			zoek.getElementById('from_'	+rid).value = hvalue;
			hvalue = wrde.substr(4,4);
			hvalue = hvalue.replace(re,"");
			zoek.getElementById('to_'	+rid).value = hvalue;
		}else{
			zoek.getElementById('query_' +rid).value = wrde;
		}
	}
	zoek.forms.zoekform.foboomid.value		= getParam('foboomid',qs);
	var intree = zoek.forms.zoekform.InTree.value	= getParam('InTree',qs);
	var obj = zoek.getElementById('fo_zoekinboom');
	if(obj)	obj.checked = (intree=='yes');
	if(top.myFzoek.oudezoek[(top.myFzoek.zoeknr+1)&31]==""){
		obj = zoek.getElementById('inResult');
		if(obj)	obj.style.display = 'inline';
	}
	initLoadQuery = '';
}

function copySelection(){
	top.document.execCommand('Copy', false);
}

function selectAll(){//SelectAll
	top.document.execCommand('SelectAll', false);
}

function manageAnnotations(){
	var features = 'status=yes, scrollbars=yes, resizable=yes, toolbar=no, width=440, height=440';
	var win = top.OpenWindow('/annManage.htm', 'Fnotes', features);
}

function openHelpFile(){
	var features = 'status=yes, scrollbars=yes, resizable=yes, toolbar=no, width=440, height=500';
	var win = top.OpenWindow('help.htm', 'help', features);
}
/***********************************************************************************
	annotations
***********************************************************************************/
function AnnAdd(){//(AnnoId, AnnoTitle){
	if(IsInSchil()){
		if(top.myFtext.document.getElementsByName("boomId").length){
	  		// get document id//
			var loc = GiveName(top.gFtextDoc);
			alert('loc = '+loc);
			// get document title//
			var myTitle = top.Ftext.document.getElementsByTagName('title')[0].innerHTML;
			var features = 'status=yes, scrollbars=yes, resizable=yes, toolbar=no, width=440, height=440';
			var win = top.OpenWindow('annAdd.htm?si=' + loc + '&st=' + myTitle, 'annotations', features);
		}else{
			alert(top.eng ? 'This document can not be added...' : 'Dit document kan niet worden toegevoegd...');
		}
	}else{
		alert(top.eng ? 'This functionality is not supported.' : 'Deze functionaliteit wordt momenteel niet ondersteund.');
	}
}

function AnnLink(){//(annId, annTitle){
	if(IsInSchil()){
		var features = 'status=yes, scrollbars=yes, resizable=yes, toolbar=no, width=440, height=440';
		var win = top.OpenWindow('addlink.htm?ti=' + annId + '&tt=' + annTitle, 'annotations', features);
	}else{
		alert(top.eng ? 'This functionality is not supported.' : 'Deze functionaliteit wordt momenteel niet ondersteund.');
	}
}

function AnnView(AnnoId){
	if(IsInSchil())	{
		var dok = top.GiveName(top.gFtextDoc).toLowerCase();
		var features = 'status=yes, scrollbars=yes, resizable=yes, toolbar=no, width=440, height=440';
		var win = top.OpenWindow('/annView.htm?docid='+dok, 'annotations', features);
	}else{
		alert(top.eng ? 'This functionality is not supported.' : 'Deze functionaliteit wordt momenteel niet ondersteund.');
	}
}

// Afhankelijk of het huidig doc een annotatie heeft wordt de anno knop getoond//
// Aanroepen na laden van data document //
// 'annShowCallBack.xsl' dient in de Resources folder aanwezig te zijn //
function UpdateAnnoBut(){
	if(top.init && IsInSchil()){
		if(top.gFtextData){
			var currentDoc = GiveName(top.gFtextDoc);
			//alert('currentDoc = '+currentDoc);// debug //
			top.myFschil.document.location.href= "/xannoview.htm?fn=AnnShowCallBack&p=notes&xf=annShowCallBack.xsl&currentDoc=" + currentDoc;
		}else{
			HideAnnoBut();
		}
	}
}
function AnnShowCallBack(p1,p2, succ){
	if(succ){
		//alert('p1: '+p1+'\np2: '+p2+'\nsucc'+succ);// debug //
		if(p2.indexOf('1')>0){
			ShowAnnoBut();
		}else{
			HideAnnoBut();
		}
	}else 	alert(top.eng ? 'Annotation file is broken or missing.' : 'Aantekeningen bestand ontbreekt of is beschadigd');
}

function HideAnnoBut(){
	var obj = top.myFtextTop.document.getElementById('annoBut');
	if(obj)	obj.style.display = 'none';
}

function ShowAnnoBut(){
	var obj = top.myFtextTop.document.getElementById('annoBut');
	if(obj)	obj.style.display = 'block';
}

/***********************************************************************************
	favorites
***********************************************************************************/

function IsInSchil(winprint){
	if(typeof(winprint) == 'undefined'){
		var winprint = top.myFrame;
	}
	try{
		return (typeof(winprint.external.HasTemplate) != 'undefined');
	}catch(e){
		return false;
	}
}

function FavoriteAdd(){
	// get document location and BoomId //
	var obj = null;
	var myTitle = '';
	if(top.myFtext.document.getElementsByName('boomId').length){
		// get document title //
		obj = top.myFtext.document.getElementsByTagName('shortName')[0];
		if(obj)	myTitle = obj.innerHTML;
		else	myTitle = top.myFtext.document.getElementsByTagName('title')[0].innerText;
		if(myTitle.length > 110)	myTitle = myTitle.substring(0, 104)+'&nbsp;[...]';

		// give document location and title to WebCDbrowser... //
		location.href = "xaddfavo.htm?id=" + GiveName(top.gFtextDoc) + "&t=" + myTitle;
		location.href = "xupdmenu.htm";
	}else{
		alert(top.eng ? 'This document can not be added...' : 'Dit document kan niet worden toegevoegd...');
	}
}

var favorite = 0;
function getDocument(favDocument){// gets called when a favorite is loaded from menu
	favorite = 1;
	top.gRelatedDocs = true;
	top.FtextLoad(favDocument);
}

function FavoriteManage(){
	var features = 'status=yes, scrollbars=yes, resizable=yes, toolbar=no, width=440, height=440';
	var doc = '/favManage.htm';
	var win = top.OpenWindow(doc, 'favorites', features);
}