var loading = false;
var popup;
var classNameOriginal;

// start a secured transaction
function start1(f,menuID,transID,p1,p2,p3) {
	if (f == '')  f = document.form1 
	if (!loading) {
		loading = true;
		f.TRANSACTION.value=transID;
		if (p1 != undefined) f.PARAM1.value = p1;
		if (p2 != undefined) f.PARAM2.value = p2;
		if (p3 != undefined) f.PARAM3.value = p3;
		f.submit();
		window.setTimeout (releaseMe, 3000);
		return false;
	} else {
		window.status = 'Please be patient, the server is allready processing your request';
	}

}

function start2(transID,p1,p2,p3) {
	start1('','',transID,p1,p2,p3);
}

// start a public transaction
function startpbc(f,transID,p1,p2,p3) {
	if (f == '')  f = document.form1 
	if (!loading) {
		loading = true;
		f.APPNAME.value='synusflex';
		f.PRGNAME.value='STARTPBC';
		f.TRANSACTION.value=transID;
		if (p1 != undefined) f.PARAM1.value = p1;
		if (p2 != undefined) f.PARAM2.value = p2;
		if (p3 != undefined) f.PARAM3.value = p3;
		f.submit();
		window.setTimeout (releaseMe, 3000);
		return false;
	} else {
		window.status = 'Please be patient, the server is allready processing your request';
	}

}

// open a transaction in a popup window
function openInPopup(trans,PARAM1,PARAM2,PARAM3,message) {
	var popup = window.open('about:blank','popWindow','');
	if (message != undefined) {
		popup.document.body.innerHTML = message;
	}
	document.form1.target = 'popWindow';
	startpbc('',trans,PARAM1,PARAM2,PARAM3);
	document.form1.target = '_self';
}

function releaseMe () {
 loading = false;
}

function start_popup(trans,target,PARAM1,PARAM2,PARAM3,theWidth,theHeight,props) {
	// sloppy, but target is not used anymore. Only one popup allowed
	if (target == '') target = 'popup';
	
	if (props == undefined)  {
		// default width / height
		if (theWidth == undefined) theWidth = 760;
		if (theHeight == undefined) theHeight = 550;
		// center popup
		var theTop = (screen.height/2) - (theHeight/2);
		var theLeft = (screen.width/2) - (theWidth/2);
		props = 'status=yes,scrollbars=no,resizable=yes,width=' + theWidth + ',height=' + theHeight + ',top=' + theTop + ',left=' + theLeft;
	}
	
	popup = window.open('/sflexsharedfiles/loading.htm',target,props);
	popup.focus();
	
	document.form1.target = target;
	start1('','',trans,PARAM1,PARAM2,PARAM3);
	document.form1.target = '_self';
	
}

function startOpener(transID,p1,p2,p3) {
	if (window.opener) {
		window.opener.start1('','',transID,p1,p2,p3);
		window.opener.focus();
	} else {
		alert('het werkvenster is niet meer beschikbaar');
		// of dit venster start1-en met 'sflex' als target?
	}
}

function start_detail(trans,PARAM1,PARAM2,PARAM3) {
	document.form1.target = 'detailFrame';
	start1('','',trans,PARAM1,PARAM2,PARAM3);
	document.form1.target = '_self';
}

function start_dummy(trans,PARAM1,PARAM2,PARAM3) {
	document.form1.target = 'dummy_frame';
	start1('','',trans,PARAM1,PARAM2,PARAM3);
	document.form1.target = '_self';
}

/* AV: Set the rowcolors of the table*/
function setTableRowClr(arg, usedClass) {
	if (event.type == 'click') {
		<!-- document.getElementById("Layer1").style.visibility="visible"; AV : layer tonen ff uitgeschakeld-->
	
		<!-- first set all rows to the default setting -->
		var rows = tabel.rows;
		for(var i=1;i<rows.length;i++)
		{
			if (rows[i].id="detailRow") {
				if(i%2==0) {
					rows[i].className = "tbRowE";
				} else {
					rows[i].className = "tbRowU";
				}
			};
		}
		<!-- now set the active row to its active class when it is clicked -->
		arg.className = 'tbRowAct';

	<!-- set the row to its hover class when it is hovered -->
	} else if (event.type == 'mouseover' && arg.className != 'tbRowAct') {
		<!-- First store it's original className -->
		classNameOriginal = arg.className;
		<!-- set the row to it's hovered class -->
		arg.className = 'tbRowHov';

	<!-- set the row to its default setting when you hover out of it -->
	} else if (event.type == 'mouseout' && arg.className == 'tbRowHov') {
//		arg.className = usedClass;
		arg.className = classNameOriginal;
	}
}		

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}


// begin absolutely positioned autoscroll area object scripts 
/*
Extension developed by David G. Miles (www.z3roadster.net/dreamweaver)
To add more shock to your site, visit www.DHTML Shock.com
*/

//Begin dHTML Tooltip Timer
var tipTimer;
//End dHTML Tooltip Timer

<!--
function locateObject(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=locateObject(n,d.layers[i].document); return x;
}

function hideTooltip(object) {
	document.getElementById(object).style.display='none';
	document.getElementById('DivShim').style.display='none';
	return false;
}

function showTooltip(object,e, tipContent, tooltipclass, displaytime, kruisje) {
	
	// top
	document.getElementById(object).style.top=document.body.scrollTop+event.clientY+20;
	
	// content
	document.getElementById(object + '_content').innerHTML='<table width="10" border="0" cellspacing="1" cellpadding="1"><tr><td style="padding:5px;" nowrap>'+unescape(tipContent)+'</td></tr></table> ';
	
	// left
	if ((e.x + document.getElementById(object).clientWidth) > (document.body.clientWidth + document.body.scrollLeft)) {	
		document.getElementById(object).style.left = (document.body.clientWidth + document.body.scrollLeft) - document.getElementById(object).clientWidth-10;
	} else {
		document.getElementById(object).style.left=document.body.scrollLeft+event.clientX;
	}
	
	// show
	document.getElementById(object).style.display='block';
	
	
	//ShOw da Cr0szzz?
	if (kruisje) {
		document.getElementById('tooltip_kruis').style.display='';
	} else {
		document.getElementById('tooltip_kruis').style.display='none';
	}
	
	// iframe behind layer because of IE bug
	var IfrRef = document.getElementById('DivShim');
	var DivRef = document.getElementById(object);
	IfrRef.style.width = DivRef.offsetWidth;
	IfrRef.style.height = DivRef.offsetHeight;
	IfrRef.style.top = DivRef.style.top;
	IfrRef.style.left = DivRef.style.left;
	IfrRef.style.zIndex = DivRef.style.zIndex - 1;
	IfrRef.style.display = "block";
	
	//alert(DivRef.offsetWidth + ' - ' + DivRef.offsetHeight + ' - ' + DivRef.style.top + ' - ' + DivRef.style.left + ' - ' + DivRef.style.zIndex);

	// notimeout, tooltip is displayed till hideTooltip is called
	if (displaytime>0) {
		window.setTimeout("hideTooltip('"+object+"')", displaytime);
	}
}


// Web-CRM tooltip toggler

// /*

// */

// upload
function start_upload(trans,PARAM1,PARAM2,PARAM3) {
	document.form1.Prgname.value = 'START_UPLOAD';
	document.form1.Arguments.value = 'FILE1';
	start1('','',trans,PARAM1,PARAM2,PARAM3);
	document.form1.prgname = 'START';
	document.form1.Arguments.value = '';
}

function showLayer(lay, show) {
	if (show == true) {
		document.getElementById(lay).style.display='';
	}	else	{
		document.getElementById(lay).style.display='none';
	}
}


// ****************** branches / functiegroepen / functienamen
function fill_branches(combo_id,selval) {
	// init
	var cb = document.getElementById(combo_id);
	cb.options.length = 0;
	
	oOption = document.createElement('OPTION');
	oOption.value = 0;
	oOption.text = 'Alle branches';
	cb.add(oOption);
	for (i in bra) {
		oOption  = document.createElement('OPTION');
		oOption.value = i;
		oOption.text = bra[i];
		cb.add(oOption);
	}
	if (selval > 0) cb.value = selval;
}

function fill_functiegroepen(combo_id,bra_id,selval) {
	// init
	var cb = document.getElementById(combo_id);
	cb.options.length = 0;

	oOption = document.createElement('OPTION');
	oOption.value = '';
	oOption.text = 'Alle functiegroepen';
	cb.add(oOption);
	for (i in grn) {
		if (bra_id == 0 || bra_id > 0 && gbr[bra_id].indexOf(i+',') > -1) {
			oOption  = document.createElement('OPTION');
			oOption.value = i;
			oOption.text = grn[i];
			cb.add(oOption);
		}
	}
	cb.value = selval;
}

function fill_functienamen (combo_id, bra_id, fgr_id) {
	// init
	var cb = document.getElementById(combo_id);
	cb.options.length = 0;
	
	// create "all" option
	oOption = document.createElement('OPTION');
	oOption.value = '';
	oOption.text = 'Alle functienamen';
	cb.add(oOption);

	// add other options
	if (bra_id > 0) {
		// only select from branche array
		for (i in fbr[bra_id]) {
			if (fgr[i] == fgr_id || fgr_id == '') {
				oOption = document.createElement('OPTION')
				oOption.value = fbr[bra_id][i];
				oOption.text = fnm[fbr[bra_id][i]];
				cb.add(oOption);
			}
		}
	} else {
		// select from all 
		for (i in fnm) {
//			if (fgr[i] == fgr_id || fgr_id == '') {
				oOption = document.createElement('OPTION')
				oOption.value = i;
				oOption.text = fnm[i];
				cb.add(oOption);
//			}
		}
	}
	
}


function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


function set_all(f,prefix,c) {
	var elms = f.elements;
	for (var i=0; i<elms.length;i++) {
		var elm = elms[i];
		if (elm.name.indexOf(prefix) >= 0) {
			elm.checked = c;
		}
	}
}

function fck_editor (fieldname, toolbar, height) {
	var sBasePath = '/sflexsharedfiles/scripts/FCKEditor/' ;
	var oFCKeditor = new FCKeditor( fieldname ) ;
	oFCKeditor.BasePath	= sBasePath ;
	oFCKeditor.Height	= height ;
	oFCKeditor.Value	= document.getElementById('container_' + fieldname).innerHTML;
	oFCKeditor.ToolbarSet = toolbar;
	oFCKeditor.Config['SkinPath'] = sBasePath + 'editor/skins/office2003/';
	oFCKeditor.Create();
}

// leeftijd berekenen

function calc_age(txtAge){
	var d = txtAge.split('-');
	var today=new Date();
	var bday=new Date(d[2],d[1],d[0]);
	var by=bday.getFullYear();
	var bm=bday.getMonth()-1;
	var bd=bday.getDate();
	var age=0; var dif=bday;
	while(dif<=today){
		var dif = new Date(by+age,bm,bd);
		age++;
	}
	age +=-2 ;
	return age;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

