/* SourceSafe */
/*
function newSearch(){
	top.mySearchFrame.zoekform.reset();
	top.myFzoek.readOnly();
}

function OpenSearch(){
	top.myFschil.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(myid, str){
	var obj = document.getElementById(myid);
	if(obj)	obj.innerHTML = str;
}
/*
function loaded(qs){
	qs='dummy.htm?'+decodeURIComponent(qs);
	top.mySearchFrame.document.forms.zoekform.foboomid.value=getParam('foboomid',qs);
	top.mySearchFrame.document.forms.zoekform.querytext.value=getParam('querytext',qs);
	top.mySearchFrame.document.forms.zoekform._md_pubyear_from.value=getParam('_md_pubyear_from',qs);
	top.mySearchFrame.document.forms.zoekform._md_pubyear_to.value=getParam('_md_pubyear_to',qs);
	top.mySearchFrame.document.forms.zoekform._md_person.value=getParam('_md_person',qs);
	top.mySearchFrame.document.forms.zoekform._md_da_title.value=getParam('_md_da_title',qs);
	top.mySearchFrame.document.forms.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.myFzoek.document.forms.resultform.usedRow.value;
		qs += '?foboomid=' +top.myFzoek.document.forms.resultform.foboomid.value;
		qs += '&InTree=' +top.myFzoek.document.forms.resultform.InTree.value;
		qs += '&usedRow=' +top.myFzoek.document.forms.resultform.usedRow.value;
		qs += '&freeId=' +top.myFzoek.document.forms.resultform.freeId.value;
//		qs += '&refinequery=' +top.myFzoek.document.forms.resultform.refinequery.value;
//		qs += '&inResult=' +top.myFzoek.document.forms.resultform.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;
	if(top.myFtext.location.href.indexOf(tabFtextArr[0][1]) != -1){
		top.myFtext.location.reload(true);
	}else{
		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.substring(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.substring(str.indexOf(gDataPath)	,str.indexOf(ml)+ml.length);
	}
	return pad;
}

var extentionArr = [
	 ['.html','.htm']
	,['.pdf']
	,['.doc','.ppt','.mpg','.mpeg']
];

function ReturnExt(arg){// doc path //
	var loc = unescape(arg).toLowerCase();
	var ret = '';
	var arr0 = extentionArr;
	var arr1 = '';
	for(var i=0; i<arr0.length; i++){
		arr1 = arr0[i];
		for(var j=0; j<arr1.length; j++){
			if(loc.indexOf(arr1[j]) != -1){
				//ret = i+','+j;
				ret = arr0[i][j];
				break;
			}
		}
		if(ret != '')	break;
	}
	//alert(ret);
	return ret;
}

function ReturnIsData(arg){
	var str = unescape(arg).toLowerCase();
	return str.indexOf(gDataPath) != -1;
}

function ReturnDocPath(arg, typ){
	var str = '';
	//alert(typeof(arg))
	if(typeof(arg) == 'object'){
		str = arg.location.href;
	}else{
		str = arg;
	}
	str = unescape(str).toLowerCase();
	var ret = str;
	var ext = ReturnExt(str);
	if(ReturnIsData(str)){	// wel data
		ret = str.substring(str.indexOf(gDataPath) ,str.indexOf(ext)+ext.length);
	}else{			// geen data
		ret = str.substring(str.indexOf(gHostPath)+gHostPath.length ,str.indexOf(ext)+ext.length);
	}
	if(typ == 'full'){
		alert(str+'\n\n'+ret);
	}else if(typ == 'srch'){
		;
	}
//	alert('typ = '+typ);
	return ret;
}

function LoadQuery(){
	var zoek = top.mySearchFrame.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,10);
			var re = / /g;
			hvalue = hvalue.replace(re,'');
			zoek.getElementById('date_'	+rid).value = hvalue;
		}else if(dtype=='ft'){	// Periode
			var hvalue = wrde.substr( 0,10);
			var re = / /g;
			hvalue = hvalue.replace(re,"");
			zoek.getElementById('from_'	+rid).value = hvalue;
			hvalue = wrde.substr(20,10);
			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.myFtext.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...' : 'aantekeningen kunnen alleen worden toegevoegd als er een document wordt getoond');
		}
	}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 aantekening 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.location.replace('/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 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.getElementsByName('shortName')[0];
		if(obj)	myTitle = obj.content;
		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);
}
