function fnTrapKD(btn, event){

 if (document.all){

  if (event.keyCode == 13){

   event.returnValue=false;

   event.cancel = true;

   btn.click();

  }
 
 }

 else if (document.getElementById){

  if (event.which == 13){

   event.returnValue=false;

   event.cancel = true;

   btn.click();

  }

 }

 else if(document.layers){

  if(event.which == 13){

   event.returnValue=false;

   event.cancel = true;

   btn.click();

  }

 }

}

function ShowProgressBar()
{
	mrqProgressBar.style.visibility = 'visible';
	mrqProgressBar.start();
}	

function HideProgressBar()
{
	mrqProgressBar.style.visibility = 'hidden';
	mrqProgressBar.stop();
}	

function Preview(arguments,width,height)
{
	var ws;
	var hs;
	var w;
	
	if(width){
		ws = width;
	}
	else {
		ws = 450;
	}
	
	if(height){
		hs = height;
	}
	else {
		hs = 400;
	}
	
	w = window.open('Preview.aspx?'+arguments,'_blank','width='+ws+',height='+hs+',status=1,scrollbars=1,menubar=0,resizable=0,toolbar=0,titlebar=0');
	w.focus();
}

//var WinIds = new Array();
//CurrentWin = 0;

function Popup(arguments,width,height)
{
	var ws;
	var hs;
	var w;
	
	if(width){
		ws = width;
	}
	else {
		ws = 450;
	}
	
	if(height){
		hs = height;
	}
	else {
		hs = 400;
	}
	
	w = window.open('Popup.aspx?'+arguments,'_blank','width='+ws+',height='+hs+',status=1,scrollbars=0,menubar=0,resizable=1,toolbar=0,titlebar=0');
	w.focus();
	
	//WinIds[CurrentWin++] = w;
}

function ClosePopups() {

	mess = "You don't really want to leave the page, do you? Stay a while. Relax. Order a pizza. Give me some more hits."
	return mess;

/*	
	if(confirm('wilt u deze pagina verlaten zonder op te slaan?')){

	//alert(WinIds.length);
	for (i=0;i<WinIds.length;i++) {
		if (WinIds[i] && !WinIds[i].closed) WinIds[i].close();
	}
	}else{
		return false;
	}
*/
}

function PopupFromPopup(page,arguments,width,height)
{
	var ws;
	var hs;
	var w;
	
	if(width){
		ws = width;
	}
	else {
		ws = 450;
	}
	
	if(height){
		hs = height;
	}
	else {
		hs = 400;
	}
	
	w = window.open(page+'?'+arguments,'_blank','width='+ws+',height='+hs+',status=1,scrollbars=0,menubar=0,resizable=0,toolbar=0,titlebar=0');
	w.focus();
}

function PopupSimple(arguments,width,height)
{
	var ws;
	var hs;
	var w;
	
	if(width){
		ws = width;
	}
	else {
		ws = 600;
	}
	
	if(height){
		hs = height;
	}
	else {
		hs = 500;
	}
	
	w = window.open('PopupSimple.aspx?'+arguments,'_blank','width='+ws+',height='+hs+',status=1,scrollbars=0,menubar=0,resizable=0,toolbar=0,titlebar=0');
	w.focus();
}

function PopupProperty(arguments,width,height)
{
	var ws;
	var hs;
	var w;
	
	if(width){
		ws = width;
	}
	else {
		ws = 450;
	}
	
	if(height){
		hs = height;
	}
	else {
		hs = 400;
	}
	
	w = window.open('../PopupAdvanced.aspx?'+arguments,'_blank','width='+ws+',height='+hs+',status=1,scrollbars=0,menubar=0,resizable=0,toolbar=0,titlebar=0');
	w.focus();
}

function PopupAdvanced(arguments,width,height)
{
	var ws;
	var hs;
	var w;
	
	if(width){
		ws = width;
	}
	else {
		ws = 450;
	}
	
	if(height){
		hs = height;
	}
	else {
		hs = 400;
	}
	
	w = window.open('PopupAdvanced.aspx?'+arguments,'_blank','width='+ws+',height='+hs+',status=1,scrollbars=0,menubar=0,resizable=0,toolbar=0,titlebar=0');
	w.focus();
	
	//WinIds[CurrentWin++] = w;
}

function PopupAdvancedWithScrollBar(arguments,width,height)
{
	var ws;
	var hs;
	var w;
	
	if(width){
		ws = width;
	}
	else {
		ws = 450;
	}
	
	if(height){
		hs = height;
	}
	else {
		hs = 400;
	}
	
	w = window.open('PopupAdvanced.aspx?'+arguments,'_blank','width='+ws+',height='+hs+',status=0,scrollbars=auto,menubar=0,resizable=0,toolbar=0,titlebar=0');
	w.focus();
}

function PopupAdvanced2(arguments,width,height)
{
	var ws;
	var hs;
	var w;
	
	if(width){
		ws = width;
	}
	else {
		ws = 450;
	}
	
	if(height){
		hs = height;
	}
	else {
		hs = 400;
	}
	
	w = window.open('PopupAdvanced2.aspx?'+arguments,'_blank','width='+ws+',height='+hs+',status=1,scrollbars=0,menubar=0,resizable=0,toolbar=0,titlebar=0');
	w.focus();
}

function PopupAdvanced3(arguments,width,height)
{
	var ws;
	var hs;
	var w;
	
	if(width){
		ws = width;
	}
	else {
		ws = 450;
	}
	
	if(height){
		hs = height;
	}
	else {
		hs = 400;
	}
	
	w = window.open('PopupAdvanced3.aspx?'+arguments,'_blank','width='+ws+',height='+hs+',status=1,scrollbars=0,menubar=0,resizable=0,toolbar=0,titlebar=0');
	w.focus();
	
	//WinIds[CurrentWin++] = w;
}

function ModalDialogBox(arguments,width,height)
{
	var ws;
	var hs;
	var w;
	
	if(width){
		ws = width;
	}
	else {
		ws = 450;
	}
	
	if(height){
		hs = height;
	}
	else {
		hs = 400;
	}
	
	w = window.showModalDialog('Popup.aspx?'+arguments,'_blank','dialogWidth='+ws+'px,dialogHeight='+hs+'px');
	w.focus();
}

function ModalDialogBoxAdvanced(arguments,width,height)
{
	var ws;
	var hs;
	var w;
	
	if(width){
		ws = width;
	}
	else {
		ws = 450;
	}
	
	if(height){
		hs = height;
	}
	else {
		hs = 400;
	}
	
	w = window.showModalDialog('PopupAdvanced.aspx?'+arguments,'','dialogWidth='+ws+'px;dialogHeight='+hs+'px');

	return w;
}

function build_subfolders(arguments,width,height)
{
	var ws;
	var hs;
	var w;
	
	if(width){
		ws = width;
	}
	else {
		ws = 800;
	}
	
	if(height){
		hs = height;
	}
	else {
		hs = 600;
	}
	
	w = window.open('build_subfolders.aspx?'+arguments,'_blank','width='+ws+',height='+hs+',status=1,scrollbars=1,menubar=0,resizable=0,toolbar=0,titlebar=0');
	w.focus();
}

function PopUp_Select_Documents(arguments,width,height)
{
	var ws;
	var hs;
	var w;
	
	if(width){
		ws = width;
	}
	else {
		ws = 900;
	}
	
	if(height){
		hs = height;
	}
	else {
		hs = 605;
	}
	
	w = window.open('Mini_DMS.aspx?'+arguments,'_blank','width='+ws+',height='+hs+',status=1,scrollbars=1,menubar=0,resizable=0,toolbar=0,titlebar=0');

	w.focus();	
}

function  GetDate(CtrlName) 
{ 
	ChildWindow = window.open('../Global/Extra/Calendar.aspx?FormName=' + document.Form1.name + '&CtrlName=' + CtrlName, "PopUpCalendar", "width=232,height=264,top=200,left=200"); 
	ChildWindow
}

function doNothing()
{
	return;
}

function checkAll(checkVal)
{	
	for(i = 0; i < document.forms[0].elements.length; i++) 
	{
		elm = document.forms[0].elements[i]

		if (elm.type == 'checkbox') 
		{
			elm.checked = checkVal;
		}
	}
}

function checkAllFiltered(checkVal, name) // filter out certain checkboxes, eg with part of their name
{	
	for(i = 0; i < document.forms[0].elements.length; i++) 
	{
		elm = document.forms[0].elements[i]

		if (elm.type == 'checkbox'&&elm.name.indexOf(name)>=0) 
		{
			elm.checked = checkVal;
		}
	}
}

function deleteItems()
{
	var counter = 0;
	
	for(i = 0; i < document.forms[0].elements.length; i++) 
	{
		elm = document.forms[0].elements[i];

		if (elm.type == 'checkbox') 
		{
			if (elm.checked == true)
			{
				counter++;
			}
		}
	}
	
	if (counter < 1)
	{
		alert('Kies op zijn minst een item');
	}
	else
	{
		confirm('Bent u zeker dat u de geselecteerde items wil verwijderen');return;
	}
}

function validateInput()
{
	for(i = 0; i < document.forms[0].elements.length; i++) 
	{
		elm = document.forms[0].elements[i]

		if (elm.type == 'text') 
		{
			if (indexOf(elm.value,'<') > 0)
			{
			alert('not valid');
			}
		}
	}
}

function checkIfNumeric(source,checkVal)
{
	
	var s;
	s = stripCharsInBag(checkVal.Value,' ');
	var regExpression = "^[0-9]*$";
	var rx = new RegExp(regExpression);
	
	if(rx.test(s))
	{
		checkVal.IsValid = true;
	}
	else
	{
		checkVal.IsValid = false;
	}	
}

function FrederikReverser(searchString)
{
	searchString = searchString.replace('&lt;','<')
	searchString =  searchString.replace('&gt;','>')
	searchString = searchString.replace('&quot;','"')
	searchString = searchString.replace('&lt;','<')
	searchString =  searchString.replace('&gt;','>')
	searchString = searchString.replace('&quot;','"')
	return searchString
}

function checkDecimal(source, checkVal)
{
	if(isNaN(checkVal.Value))
	{
		checkVal.IsValid = false;
	}
	else
	{
		checkVal.IsValid = true;
	}
}

function checkUniqueId(source,checkVal)
{
	var s;
	s = stripCharsInBag(checkVal.Value,' ');
	var regExpression = "^[0-9]{9}[0-9]{2}$";
	var rx = new RegExp(regExpression);

	if(s.length > 0)
	{

	if(rx.test(s))
	{
		if((97-parseInt(s.substr(0,9))%97)==parseInt(s.substr(9,2)))
		{
			checkVal.IsValid = true;
		}
		else
		{
			checkVal.IsValid = false;
		}
	}
	else
	{
		checkVal.IsValid = false;
	}
	}
	else
	{
		alert('test')
	}
}

function checkSocialSecurityNumber(source,checkVal)
{
	var s;
	s = stripCharsInBag(checkVal.Value,' ');
	var regExpression = "^[0-9]{10}$";
	var rx = new RegExp(regExpression);

	if(s.length > 0)
	{

	if(rx.test(s))
	{
		checkVal.IsValid = true;
	}
	else
	{
		checkVal.IsValid = false;
	}
	}
	else
	
	{
		alert('test')
	}
}

function checkDropDownList(source, args)
{
	var s;
	s = args.Value;
	if(s==0)
	{
		args.IsValid = false;
	}
	else
	{
		args.IsValid = true;
	}
}

function checkListboxContains(source, args)
{
	//alert(source);
	if(documents.forms[0].elements[source].options.length>0)
		return true;
	else
		return false;
}

function checkSelect(s)
{
	var item = s;
	if(document.forms[0].elements[item].options[document.forms[0].elements[item].selectedIndex].value == 0)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function checkSelectNotOne(s)
{
	var item = s;
	if(document.forms[0].elements[item].options[document.forms[0].elements[item].selectedIndex].value <= 1)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function checkInput(s)
{
	var item = s
	if(stripCharsInBag(document.forms[0].elements[item].value," ")=='')
	{
		return false;
	}
	else
	{
		return true;
	}
}


function checkOrganisationForm(who, wherecity, wherestreet, wherenumber, telfax, jurIdent, activity)
{
	if(checkInput(who)||checkInput(wherecity)||checkInput(wherestreet)||checkInput(wherenumber)||checkInput(telfax)||checkSelect(jurIdent)||checkInput(activity))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkPersonForm(who, wherecity, wherestreet, wherenumber, keyword, telfax, civilstate)
{
	if(checkInput(who)||checkInput(wherecity)||checkInput(wherestreet)||checkInput(wherenumber)||checkInput(keyword)||checkInput(telfax)||checkSelect(civilstate))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkGlobalForm(who, what, wherecity, wherestreet, wherenumber, keyword, telfax)
{
	if(checkInput(who)||checkSelect(what)||checkInput(wherecity)||checkInput(wherestreet)||checkInput(wherenumber)||checkInput(keyword)||checkInput(telfax))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkFunctionForm(person, organization, telfax, functiontype)
{
	if(checkInput(person)||checkInput(organization)||checkInput(telfax)||checkSelect(functiontype))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkAddressForm(wherecity, wherestreet, wherestreetnumber, country)
{
	if(checkInput(wherecity)||checkInput(wherestreet)||checkInput(wherestreetnumber)||checkSelectNotOne(country))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function checkMeetingDelay(source, args)
{
	if(confirm("Bent u zeker dat u dit punt wilt uitstellen?"))
	{
		args.IsValid = true	
	}
	else
	{
		args.IsValid = false
	}
}


/* ---------------- JAVASCRIPT UTILITIES --------------------------- */

function stripCharsInBag (s, bag){
    var i;
    var returnString = "";
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

/* ----------------- RAD EDITOR ------------------------------------ */

function showDialog(RadEditorContentArea, editorID)
{
	var result = radEditorShowDialog(editorID, "../RadControls/Editor/ImageBank/viewer.aspx?editorID=" + editorID, null, 800, 630);
	if (result != null)
	{
		//Making the r.a.d.editor content area active.
		RadEditorContentArea.setActive();
		var range = document.selection.createRange();
		if (document.selection.type =="None" || document.selection.type == "Text")
		{
			if (range.text == '')
			{
				range.pasteHTML("<img src='" + result + "'>");
			} 
			else
			{
				range.pasteHTML("<img src='" + result + "' alt='" + range.text + "'>");
			}
		} 
	}
}



function showCustomLinks(RadEditorContentArea, editorID)
{
	var result = radEditorShowDialog(editorID, "../RadControls/Editor/StuffLinker/viewer.aspx", null, 800, 600);
	if (result != null)
	{
		var words = result.split("||||");
		var sTarget = words[0];
		var value  = words[1];
		var text   = words[2];
		//Making the r.a.d.editor content area active.
		RadEditorContentArea.setActive();
		var range = document.selection.createRange();
		if (document.selection.type =="None" || document.selection.type == "Text")
		{
			if (range.text == '')
			{
				range.pasteHTML("<A HREF='" + value + "'>" + text + "</A>");
			} 
			else
			{
				range.pasteHTML("<a href='" + value + "'>" + range.text + "</a>");
			}
		} 
        else
        {
            document.execCommand("CreateLink", false, value);
            var sel = document.selection.createRange()

            if (sel(0).tagName == "IMG") 
                {
                this_href = sel(0).parentNode
                }
                        
            while(this_href.tagName!="A"&&this_href.tagName!="HTML") 
                {
                        this_href = this_href.parentElement
                }

            if (this_href.tagName == "A") 
                {
                    if (sTarget != '' || this_href.target != '') 
                        {
                            this_href.target=sTarget
                        }
                }
         }		
	}
}


   



 

/* ----------------- END RAD EDITOR ------------------------------------ */

/*
listbox : listbox object from form
hiddenfield : hidden field that has listbox values
direction : up = 1; down = -1
*/
function sortList(listbox, hiddenfield, direction){
	
	var lb = listbox;
	var hdn = hiddenfield;
	
	//check for multiple selected items
	//check if item is first
	
	var gogogo = 1;

	var selected=0;
	for(i=0;i<lb.options.length;i++){
		if(lb.options[i].selected){
			selected++;
		}
	}
	if(selected!=1){
		//alert("Maximum 1 element selecteren om te sorteren");
		gogogo = 0;
	}
	
	var lb_selectedindex = lb.selectedIndex;
	
	switch(direction){
		case 1: 
			if(lb_selectedindex==0&&gogogo){
				//alert("U kunt dit element niet naar boven verplaatsen");
				gogogo = 0;
			}
			break;
		case -1:
			if(lb_selectedindex==lb.options.length-1&&gogogo){
				//alert("U kunt dit element niet naar beneden verplaatsen");
				gogogo = 0;
			}
			break;
	}
		
	if(gogogo){
		//get items to switch
		
		var lb_selitem = document.createElement("OPTION");
		lb_selitem.value = lb.options[lb_selectedindex].value;
		lb_selitem.text = lb.options[lb_selectedindex].text;
		
		var lb_replaceitem =  document.createElement("OPTION");
		lb_replaceitem.value = lb.options[lb_selectedindex-direction].value;
		lb_replaceitem.text = lb.options[lb_selectedindex-direction].text;
		
		//switch items
		
		lb.options[lb_selectedindex-direction] = lb_selitem;
		lb.options[lb_selectedindex] = lb_replaceitem;
		
		lb.selectedIndex = lb_selectedindex-direction;
		
		//recreate hdn field string with items from listbox
		
		var hdnvalue=';';
		for(i=0;i<lb.options.length;i++){
			hdnvalue+=lb.options[i].value+';';
		}
		
		hdn.value = hdnvalue;
		
	}

}
var win_cookie=null;
function PopupProper(mypage,myname,w,h,pos,infocus)
{
	//if(GetCookie("sid") == "999")
	//	{return;}
	//document.cookie="sid=999; Path=/; Expires= " + getFuture(999);
	
	if(pos=="random"){myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){myleft=(screen.width)?(screen.width-w)/2:100;mytop=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!='center' && pos!="random") || pos==null){myleft=0;mytop=20}
	settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=yes,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";
	win_cookie=window.open('PopupAdvanced.aspx?'+mypage,myname,settings);
	win_cookie.focus();
}
	// Cookie functions borrowed from:
	// Ronnie Moore: Visit him at http://www.ronniemoore.com

function getFuture(f)
{
	var d = new Date();
	d.setTime(d.getTime() + (86400000 * f));
	return d;
}

function GetCookie (name) 
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) 
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return null;
}

function getCookieVal (offset) 
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

/** NEW GLOBAL FUNCTIONS FOR LISTBOXEN **/

function fillInListbox(lbx, hdnfield, id, name)
	{
		var v1 = lbx;
		var v2 = hdnfield;
			
		op_listbox = opener.document.forms[0].elements[v1];
		var exists = false;
		if(op_listbox.options.length>0)
		{
			for(i=0;i<op_listbox.options.length;i++)
				if(op_listbox.options[i].value==id){
					exists = true
					op_listbox.options[i].text=name;
				}
		}
		else{
			exists = false
		}
		if(!exists)
		{
			var lb_item = opener.document.createElement("OPTION");
			lb_item.text = name;
			lb_item.value = id;
			op_listbox.options.add(lb_item);
			opener.document.forms[0].elements[v2].value = opener.document.forms[0].elements[v2].value + id + ";"
		}
	}
	
function RemoveSelectedItemsFromListbox(lbx, hdnfield)
	{
		var t = lbx;
		var f = hdnfield;

		iCounter = 0;
		iLength = document.forms[0].elements[t].options.length;
		
		for(i=0;i<iLength;i++)
		{
			if(document.forms[0].elements[t].options[iCounter].selected){
				document.forms[0].elements[f].value = (document.forms[0].elements[f].value).replace(';'+document.forms[0].elements[t].options[iCounter].value+';',';');
				document.forms[0].elements[t].remove(iCounter);
				iCounter += 0;
			}
			else
			{
				iCounter += 1;
			}
 		}
	}
	
	
	
//-----------------------
// begin encoding emails 
//-----------------------
// open the client email with the specified address
function showMailTo(encodedEmail)
{
  // do the mailto: link
  //location.href = "mailto:" + decodeEmail(encodedEmail);
  location.href = decodeEmail(encodedEmail);
}

function showEmail(encodedEmail)
{
  document.write (decodeEmail(encodedEmail));
}


// display the email address in the statusbar
function displayStatus(encodedEmail)
{
  //window.status = "mailto:" + decodeEmail(encodedEmail);
  window.status = decodeEmail(encodedEmail);
}

// clear the statusbar message
function clearStatus()
{
  window.status = "";
}

// return the decoded email address
function decodeEmail(encodedEmail)
{
  var email = "";

  for (i=0; i < encodedEmail.length;)
  {
    var letter = "";
    letter = encodedEmail.charAt(i) + encodedEmail.charAt(i+1)

    email += String.fromCharCode(parseInt(letter,16));
    i += 2;
  }
  
  return email;
}

//-----------------------
// einde encoding emails 
//-----------------------
	
