    /* 
        script to aid submitting forms
      
        tested with IE 5.01OSX, 5.2.3OSX, NS6.02OSX, Safari 1.0, 1.1 1.2 OSX
        this funtion is called from a onkeypress tag in the <input type="image"> tags
        or via an onclick in normal anchors
        or via an href in normal anchors in a 'href="javascript:formsubmitter();"' style.
    
    */
    function formsubmitter( formname, e ) {
        if ( e == '-' ) {
            window.document.forms[formname].submit();
        } else {
            if ( e.type == 'keypress' || e.type == 'khtml_keypress' ) {
                nav4    = (window.Event) ? true : false;
                theKey  = (nav4) ? e.which : e.keyCode;
            
                if (theKey==13 && document.forms[formname]) {
                    window.document.forms[formname].submit();
                }
            }
            if (e.type == 'click') {
                window.document.forms[formname].submit();
            }
        }
    }
    /*
        helper
        
        accepts extra argument to be put into a 'selection' hidden element  

    */
    function listviewer_submitter( fname, ftype ) {

        switch ( ftype ) {
            case 'delete' :
                if ( confirm( "Weet u zeker dat u de geselecteerd items wenst te verwijderen?\n\n(Deze handeling is onomkeerbaar!)" ) ) {
                    document.forms[fname].elements["listviewer_action"].value       = 'delete';
                    document.forms[fname].submit();
                }
            break;
            case 'reset' :
                document.forms[fname].reset();
            break;
            default:
                document.forms[fname].elements["listviewer_action"].value = ftype;
                
                if ( arguments[2] && document.forms[fname].elements["listviewer_selection"] ) {
                    document.forms[fname].elements["listviewer_selection"].value    = arguments[2];
                }
                document.forms[fname].submit();
        }
    }
// 
// 	// limits AREA form field 
// 	function LimitText(fieldObj,maxChars,e)
// 	{
// 		if ( e.type == 'keypress' || e.type == 'khtml_keypress' ) {
// 			nav4    = (window.Event) ? true : false;
// 			var theKey  = (nav4) ? e.which : e.keyCode;
// 		} 
// 	
// 	   var normalChar = ( theKey!=8 ) ? true : false;
// 	//   alert (theKey);
// 	 
// 	//  var result = true;
// 	  if (fieldObj.value.length >= maxChars && normalChar) result = false;
// 	  
// //	  if (window.event)	window.event.returnValue = result;
// 	
// 	 window.event.returnValue);
// 	
// 	return result;
// 	}


	 /* charAlert
	  * use in textarea onKeyUp="charAlert(this, 250);
	  * tested: mac:safari=ok,ie=ok,omniweb=nope
	  *          pc:		
	  */
	 function charAlert( textField, maxLenght ) {
		if( textField.value.length > maxLenght ) { 
			/* must be > 5, not == 5 or else the substring statement on the next line 
			will cause the function to run again if the user dismisses the alert
			by pressing the 'enter' key rather than clicking 'OK'. */
													
			// set field's value equal to first five characters. 
			textField.value= textField.value.substring(0, maxLenght);
	
			/* move cursor out of form element to keep it from placing itself at position zero, causing an overwrite of the first character */
			textField.blur();
	
			/* and back in */
			textField.focus();
		}
	}

    function newImage(arg) {
        if (document.images) {
            rslt = new Image();
            rslt.src = arg;
            return rslt;
        }
    }
        
    function createwindow( type, url ) {
        win_l = 0;
        win_t = 0;
        title = type;
        switch ( type ) {
            case 'help':
                title        = 'Help';
                features    = "width=318,height=500,menubar=no,status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no";
            break;
            case 'bewerk_pagina':
                title        = 'bewerk_paginas';
                features    = "width=758,height=500,menubar=no,status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no";
            break;
            case 'sample':
                title        = 'audio';
                features    = "width=300,height=100,menubar=no,status=no,scrollbars=no,resizable=no,toolbar=no,location=no,directories=no";
            break;
            case 'dblinker':
                title        = 'link';
                features    = "width=400,height=500,menubar=no,status=yes,scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no";
            break;
            case 'nieuwsbrief':
                title        = 'nieuwsbrief';
                features    = "width=600,menubar=no,status=yes,scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no";
            break;
            case 'concertagendaitem':
                title        = 'concertagendaitem';
                features    = "width=350,height=300,menubar=no,status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no";
            break;
            case 'standard':
                title        = 'standard';
                features    = "width=600,menubar=no,status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no";
            break;
            case 'persmap':
                title        = 'persmap';
                features    = "width=600,menubar=no,status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no";
            break;
            case 'bezettingen':
                title        = 'standard';
                features    = "width=350,menubar=no,status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no";
            break;
            case 'compositie_wizard':
                title        = 'compositie_toevoegen';
                features    = "width=440,height=540,menubar=no,status=yes,scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no";
            break;
        }
        
        wind = window.open(url,title,features);
        if (title != 'audio') wind.focus();
    }
        
    function feedback() {
        window.location.href='mailto:info@dekamervraag.org?subject=Feedback Website';
    }
    
    function opener_reload() {
        if (window.opener) window.opener.location.reload(false);
    }
    function opener_to( to ) {
        if (window.opener) window.opener.location.href = to;
    }
    



    function rewriteSelectOptions( theSelectElement, dataArray, selected_index ) {  
		// Clear
		theSelectElement.options.length = 0;

		for ( $i=0; $i< dataArray.length; $i++ ) {
			theSelectElement.options[theSelectElement.options.length] = new Option( dataArray[$i][1], dataArray[$i][0] );
		}
    }
     
    // http://javascript.about.com/library/scripts/blsafeonload.htm
    // Body onload utility (supports multiple onload functions)
    
    
	// Browser Detection
	isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
	NS4 = (document.layers) ? true : false;
	IEmac = ((document.all)&&(isMac)) ? true : false;
	IE4plus = (document.all) ? true : false;
	IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
	IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
	
	IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
	ver4 = (NS4 || IE4plus) ? true : false;
	NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;
	
	IE5plus = IE5 || IE6;
	IEMajor = 0;

	if (IE4plus)
	{
		var start = navigator.appVersion.indexOf("MSIE");
		var end = navigator.appVersion.indexOf(".",start);
		IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
		IE5plus = (IEMajor>=5) ? true : false;
	}
	
	// Body onload utility (supports multiple onload functions)
	var gSafeOnload = new Array();
	function SafeAddOnload(f)
	{
		if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
		{
			window.onload = SafeOnload;
			gSafeOnload[gSafeOnload.length] = f;
		}
		else if  (window.onload)
		{
			if (window.onload != SafeOnload)
			{
				gSafeOnload[0] = window.onload;
				window.onload = SafeOnload;
			}		
			gSafeOnload[gSafeOnload.length] = f;
		}
		else
			window.onload = f;
	}
	function SafeOnload()
	{
		for (var i=0;i<gSafeOnload.length;i++)
			gSafeOnload[i]();
	}

    //now call in scripts
    // Call the following with your function as the argument
    // SafeAddOnload(yourfunctioname);

	var _vForm_isChanged	= false;
	
	function vForm_Change() {
		_vForm_isChanged = true;
	}
	function vForm_UnChange() {
		_vForm_isChanged = false;
	}

	function vForm_ChangeHelper() {
		if ( _vForm_isChanged ) {
			var answer = confirm("Let op!\n\nUw wijzigingen zijn niet opgeslagen. Wanneer u deze pagina nu verlaat, gaan uw wijzigingen verloren.\n\nWilt u doorgaan zonder uw wijzigingen eerst te bewaren?");

			if (answer) return true;
			else return false;
			
		} else return true;
	}

