/* SourceSafe */

function getParam(name, 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 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;
		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;
	}
//	alert('qs:\n'+qs)
	return qs;
}

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){
	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 CookieSet(sName, sValue, sExpiry){		// sExpiry in days //
	if(sExpiry == undefined)	var sExpiry = -1;
	var today = new Date();
	var expiry = new Date(today.getTime() + sExpiry * 24 * 60 * 60 * 1000);
	expiry = expiry.toGMTString();
	document.cookie = gAppCode + sName + '=' + escape(sValue) + '; expires=' + expiry + ';' ;
}

function CookieGet(sName){				// Retrieve the value of the cookie with the specified name.
	var myCookie = document.cookie.split("; ");	// cookies are separated by semicolons
	for (var i=0; i<myCookie.length; i++){
		var aCrumb = myCookie[i].split("=");	// a name/value pair is separated by an equal sign
		if (gAppCode + sName == aCrumb[0])
			return unescape(aCrumb[1]);
	}
	return null;
}

function CookieDel(sName){				// Delete the cookie with the specified name.	eg: CookieDel('name')
	document.cookie = gAppCode + sName + '=' + escape(sName) + '; expires=Fri, 31 Dec 1999 23:59:59 GMT;';
}

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;
}

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);
	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);
//ab 19/11/2008 16:41		wrde = wrde.replace(/<phrase>/gi ,' ');
		var abtmp
		abtmp = wrde;
		var abpos = abtmp.indexOf(' ');
		if(abpos>0)
		{
	
			abtmp = "\\\"" + wrde + "\\\"";
			wrde = abtmp;
		}

		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);
}
