function checkEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {      
      return false;
   }
   
   return true;
}


function insertNBSP() {
    return "&nbsp;";
}
function insertEuro() {
    return "&euro;";
}
function getNumberFormatter( nummersAchterKomma ) {
	var num = new NumberFormat();
	num.setInputDecimal( '.' );
	num.setPlaces( nummersAchterKomma );
	num.setCurrencyValue( '&euro;' );
	num.setCurrency( false );
	num.setCurrencyPosition( num.LEFT_OUTSIDE );
	num.setNegativeFormat( num.LEFT_DASH );
	num.setNegativeRed( false );
	num.setSeparators( true, '.', ',' );
	
	return num;
	
	// Als volgt gebruiken:
	//  num.setNumber( obj.value );
	//  obj.value = num.toFormatted();
}

// Temporary variables to hold mouse x-y pos.s
var tempX = 0
var tempY = 0

// Main function to retrieve mouse x-y pos.s
// Gebruik: addEvent( document, "mousemove", getMouseXY ); en dan kan je overal de x en y uitlezen
function getMouseXY(e) {
    if ( browserIsInternetExplorer() ) { // grab the x-y pos.s if browser is IE
      tempX = event.clientX + document.body.scrollLeft
      tempY = event.clientY + document.body.scrollTop
    } else {  // grab the x-y pos.s if browser is NS
      tempX = e.pageX
      tempY = e.pageY
    }  
    
    // catch possible negative values in NS4
    if (tempX < 0){tempX = 0}
    if (tempY < 0){tempY = 0}  
    
    //window.status = 'x: '+ tempX +' y: '+ tempY;
    
    return true
}

function hideElement( obj ) {
	obj.style.display = 'none'; 
	obj.style.visibility = 'hidden';
}

function showElement( obj ) {
	obj.style.display = 'block'; 
	obj.style.visibility = 'visible';
}

function browserIsInternetExplorer() {
	var browser = navigator.appName;

	if ( browser.search(/microsoft/i) == 0 ) {
    	return true;
   	} else {
    	return false;
    }
}

function createModalDialog( url, title, width, height, centered, scrollable, resizeable, modal ) {
	var windowScroll = '';
	var windowResize = '';
	
	// url verbouwen
	url = '/modal.php5?location='+ url +'&title='+ title;
	
	if ( browserIsInternetExplorer() ) {
		if ( scrollable ) {
			windowScroll = 'scroll:yes;';
	    } else {
			windowScroll = 'scroll:no;';
	    }
	    if ( resizeable ) {
			windowResize = 'resizable:yes;';
	    } else {
			windowResize = 'resizable:no;';
	    }
	    var windowCenter = '';
	    if ( centered ) {
	    	windowCenter = 'center:yes;';
	    } else {
	    	windowCenter = 'center:no;dialogLeft:10px;dialogTop:10px;';
	    }

		if ( modal ) {	    
			window.showModalDialog( url, window, 'dialogWidth:'+ width +'px;dialogHeight:'+ height +'px;status:no;'+ windowScroll + windowResize + windowCenter );
		} else {
			window.showModelessDialog( url, window, 'dialogWidth:'+ width +'px;dialogHeight:'+ height +'px;status:no;'+ windowScroll + windowResize + windowCenter );
		}
	} else {
	    // scrollen?
		if ( scrollable ) {
			windowScroll = 'scrollbars=yes,';
	    } else {
			windowScroll = 'scrollbars=no,';
	    }
	    // resizen?
	    if ( resizeable ) {
			windowResize = 'resizable=yes,';
	    } else {
			windowResize = 'resizable=no,';
	    }
	    // centreren?
	    var windowLeft = '';
	    var windowTop = '';
	    if ( centered ) {
	        // dan ff berekenen
	        var screenWidth = 0;
	        var screenHeight = 0;
			if (self.innerWidth) {
			    screenWidth = self.innerWidth;
			    screenHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientWidth) {
			    screenWidth = document.documentElement.clientWidth;
			    screenHeight = document.documentElement.clientHeight;
			} else if (document.body) {
			    screenWidth = document.body.clientWidth;
			    screenHeight = document.body.clientHeight;
			}
//			alert( 'w:'+ screenWidth +' - h:'+ screenHeight );
	    	windowLeft = ( ( screenWidth / 2 ) - ( width / 2 ) ) +'px';
	    	windowTop = ( ( screenHeight / 2 ) - ( height / 2 ) ) +'px';
	    } else {
	    	windowLeft = '10px';
	    	windowTop = '10px'
	    }
	    
		w = window.open( url, 'yourDictionary', 'width='+ width +',height='+ height + windowScroll + windowResize +',top='+ windowTop +',left='+ windowLeft +',resizable=no,modal=yes' );
		w.focus();
	} 
}

function createWindow( url, title, width, height, scrollable, resizeable ) {
    if ( scrollable ) {
        var scroll = 'yes';
    } else {
    	var scroll = 'no';
    }
    if ( resizeable ) {
        var resize = 'yes';
    } else {
    	var resize = 'no';
    }

    var windowLeft = '';
	var windowTop = '';
    var screenWidth = 0;
    var screenHeight = 0;
	if (self.innerWidth) {
	    screenWidth = self.innerWidth;
	    screenHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientWidth) {
	    screenWidth = document.documentElement.clientWidth;
	    screenHeight = document.documentElement.clientHeight;
	} else if (document.body) {
	    screenWidth = document.body.clientWidth;
	    screenHeight = document.body.clientHeight;
	}
	windowLeft = ( ( screenWidth / 2 ) - ( 800 / 2 ) ) +'px';
    windowTop = ( ( screenHeight / 2 ) - ( 400 / 2 ) ) +'px';

	w = window.open( url, title, 'width='+ width +', height='+ height +', top='+ windowTop +', left='+ windowLeft +',resizable='+ resize +',scrollbars='+ scroll );
	//w.focus();
}

function radioButtonValue( radioButton ) {
    for ( x = 0; x < radioButton.length; x++ ) {
        if (radioButton[x].checked == true) return radioButton[x].value;
    }
         // if it didn't find anything, return the .value  (behaviour of single radio btn)
        return radioButton.value;
}

function emptyCombobox( aCombobox ) {
	// combo legen
	aCombobox.options.length = 0;
}

function IsNumeric(sText) {
    if ( sText == "" ) {
        return false;
    }
    //sText = str_replace( ",", ".", sText );

    var ValidChars = "0123456789.";
    var IsNumber=true;
    var Char;
 
    for (i = 0; i < sText.length && IsNumber == true; i++) { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) {
            IsNumber = false;
        }
    }
    return IsNumber;
}

function closeModalWindow() {
    parent.parent.close(); 
}

function closeModalWindowWithConfirm() {
    if ( confirm('Weet u zeker dat u wilt annuleren?') ) { 
        parent.parent.close(); 
    }
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function httpget( name ){
    var GET_DATA = new Array();
    var getDataString = new String( window.location );
    var questionMarkLocation = getDataString.search(/\?/);
    
    if ( questionMarkLocation != -1 ){
        getDataString = getDataString.substr( questionMarkLocation +1 );
        var getDataArray = getDataString.split(/&/g);
        
        for ( var i = 0; i < getDataArray.length; i++ ) {
            var nameValuePair = getDataArray[ i ].split(/=/);
            
            GET_DATA[ unescape( nameValuePair[ 0 ] ) ] = unescape( nameValuePair[ 1 ] );
        }
    }
    
    return GET_DATA[ name ];
}

function str_replace( search, replace, subject ) {
	var strText = new String( subject );
	var re = new RegExp ( search, 'gi' );
	return strText.replace( re, replace );
}

function ucfirst( str ) {
	var part1 = str.slice( 0, 1 );
	var part2 = str.slice( 1 );
	
	return part1.toUpperCase() + part2.toLowerCase();
}

function keypressInteger( e ) {
    var pressedKeyCode;  	
    if ( typeof( e ) == 'undefined' ) {
      e = window.event;
    }
    if ( typeof( e.which ) == 'undefined' ) {
      pressedKeyCode = e.keyCode;
    } else {
      pressedKeyCode = e.which;
    }
			
	if ( ( !( typeof( e.which ) == 'undefined' ) ) && ( ( pressedKeyCode == 0 ) || ( pressedKeyCode == 8 ) ) ) return true;
    if( pressedKeyCode >= 48 && pressedKeyCode <= 57 ) return true;
    return false;
}

function keypressDate( e ) {
    var pressedKeyCode;  	
    if ( typeof( e ) == 'undefined' ) {
      e = window.event;
    }
    if ( typeof( e.which ) == 'undefined' ) {
      pressedKeyCode = e.keyCode;
    } else {
      pressedKeyCode = e.which;
    }
	
	if ( ( !( typeof( e.which ) == 'undefined' ) ) && ( ( pressedKeyCode == 0 ) || ( pressedKeyCode == 8 ) ) ) return true;	
    if( ( pressedKeyCode >= 48 && pressedKeyCode <= 57 ) || ( pressedKeyCode == 45 ) ) return true;
    return false;
}

function keypressDouble( e ) {
    var pressedKeyCode;  	

    if ( typeof( e ) == 'undefined' ) {
      e = window.event;
    }
    if ( typeof( e.which ) == 'undefined' ) {
      pressedKeyCode = e.keyCode;
    } else {
      pressedKeyCode = e.which;
    }
			
    if ( pressedKeyCode == 46 ) {
      if ( typeof( e.which ) == 'undefined' ) {
        e.keyCode = 44;
      } else {
      	try {
          e.which = 44;
        } catch ( error ) {}
      }
    	pressedKeyCode = 44;
    }
    
    if ( pressedKeyCode == 44 ) {
    	var objSender = event.target || event.srcElement;
    	
    	if ( objSender.value.indexOf( "," ) > -1 ) {
    		return false;
    	}
    }

	if ( ( !( typeof( e.which ) == 'undefined' ) ) && ( ( pressedKeyCode == 0 ) || ( pressedKeyCode == 8 ) ) ) return true;
    if( ( pressedKeyCode >= 48 && pressedKeyCode <= 57 ) || ( pressedKeyCode == 44 )  ) return true;
    return false;
}

function keypressAlpha( e ) {
    var pressedKeyCode;  	

    if ( typeof( e ) == 'undefined' ) {
        e = window.event;
    }
    if ( typeof( e.which ) == 'undefined' ) {
        pressedKeyCode = e.keyCode;
    } else {
        pressedKeyCode = e.which;
    }
	
	if ( ( !( typeof( e.which ) == 'undefined' ) ) && ( ( pressedKeyCode == 0 ) || ( pressedKeyCode == 8 ) ) ) return true;		
    if( ( pressedKeyCode >= 0 && pressedKeyCode <= 240 ) ) return true;
    return false;
}

function keypressLimitLength( obj, e, limit ) {
	if ( obj.value.length >= limit ) {
	    var pressedKeyCode;  	
	
	    if ( typeof( e ) == 'undefined' ) {
	        e = window.event;
	    }
	    
	    if ( typeof( e.which ) == 'undefined' ) {
	        pressedKeyCode = e.keyCode;
	    } else {
	        pressedKeyCode = e.which;
	    }
	    if ( ( !( typeof( e.which ) == 'undefined' ) ) && ( ( pressedKeyCode == 0 ) || ( pressedKeyCode == 8 ) ) ) {
	    	return true;
	    } else {
	    	return false;
	    }
	}
}


/*function formatCurrency( num ) {
	var foundKomma = false;
	var tempnum = num;
	for ( i = 0; i < tempnum.length; i++ ) {
        if ( tempnum.charAt( i ) == "," ) {
            foundKomma = true;
            break;
        }
	}
	
	if ( !foundKomma ) {
    	return tempnum +",00";
	} else {
	    if ( tempnum.charAt( tempnum.length -2 ) == "," ) {
        	return tempnum + "0";
    	} else {
    	    tempnum = str_replace( ",", ".", tempnum );
    	    var dbl = tempnum;//parseDouble( tempnum );
            tempnum = Math.round( dbl *100 ) /100;

            if ( isNaN( tempnum ) ) {
                return false;
            } else {        
                //tempnum = formatCurrency( tempnum );
                var newnum = tempnum;
                tempnum = str_replace( ".", ",", newnum );
                return tempnum;
            }
        }
	}
}*/

function formatCurrency(mnt) {
	if ( mnt == "," ) {
		mnt = "0";
	}
    mnt = str_replace( ",", ".", mnt );

    mnt -= 0;
    mnt = (Math.round(mnt*100))/100;
    var tmp = (mnt == Math.floor(mnt)) ? mnt + '.00' : ( (mnt*10 == Math.floor(mnt*10)) ? mnt + '0' : mnt);
    
	var myString = tmp +"";
	var replaceCharacter = ",";
	var replacePosition = myString.length -3;
	var outputVar = myString.substring(0,replacePosition) + replaceCharacter + myString.substring(replacePosition+1,myString.length);    
    
//    if ( isNaN( outputVar ) ) {
//    	outputVar = "0,00";
//    }
    return outputVar;
}

function formatDrieDecimalen( number ) {
	if ( number != "" ) {
		number = str_replace( ",", ".", number );
		var output = FormatNumber( number, 3, true, true );
		if ( !isNaN( output ) ) {
			var dotPos = output.indexOf( "." );
			
			if ( dotPos == -1 ) {
				output = output +",000";
			} else {
				var behindKomma = output.slice( ( dotPos +1 ) );
				for ( var i = 0; behindKomma.length < 3; i++ ) {
					behindKomma = behindKomma +"0";
				}
				
				output = output.slice( 0, dotPos ) +","+ behindKomma;
			}
			
		    return output;
		} else {
			return "";
		}
	} else {
		return "";
	}
}

function format4calculation( num ) {
	return str_replace( ",", ".", num );
}

function FormatNumber(num, decimalNum, bolLeadingZero, bolParens)
   /* IN - num:            the number to be formatted
           decimalNum:     the number of decimals after the digit
           bolLeadingZero: true / false to use leading zero
           bolParens:      true / false to use parenthesis for - num

      RETVAL - formatted number
   */
   {
       var tmpNum = num;

   // Return the right number of decimal places
   //decimalNum++;
   tmpNum *= Math.pow(10,decimalNum);
   tmpNum = Math.floor(tmpNum);
   tmpNum /= Math.pow(10,decimalNum);

   // afronden
   //var dotPos = tmpNum.indexOf( "." );
   //if ( dotPos > -1 ) {
   //   var behindKomma = output.slice( ( dotPos +1 ) );
   //}
 
   var tmpStr = new String(tmpNum);

   // See if we need to hack off a leading zero or not
   if (!bolLeadingZero && num < 1 && num > -1 && num !=0)
       if (num > 0)
           tmpStr = tmpStr.substring(1,tmpStr.length);
       else
           // Take out the minus sign out (start at 2)
           tmpStr = "-" + tmpStr.substring(2,tmpStr.length);                        


   // See if we need to put parenthesis around the number
   if (bolParens && num < 0)
       tmpStr = "(" + tmpStr.substring(1,tmpStr.length) + ")";


   return tmpStr;
}

function formatPrintCurrency( mnt ) {
	return "&euro; "+ formatCurrency(mnt);
}

function tryFormatDate( field ) {
	var checkVal = field.value;
	
	if ( isDate( checkVal, 'dd-M-yyyy' ) ) {
		field.value = formatDate( new Date( getDateFromFormat( checkVal, 'dd-M-yyyy' ) ) , 'dd-MM-yyyy' );
	} else if ( isDate( checkVal, 'd-MM-yyyy' ) ) {
		field.value = formatDate( new Date( getDateFromFormat( checkVal, 'd-MM-yyyy' ) ) , 'dd-MM-yyyy' );
	} else if ( isDate( checkVal, 'd-M-yyyy' ) ) {
		field.value = formatDate( new Date( getDateFromFormat( checkVal, 'd-M-yyyy' ) ) , 'dd-MM-yyyy' );
	}
}

function deleteArrayElement( array, delindex ) {
	size = array.length;
	validNo = ( delindex != "NaN" );
	inRange = ( ( delindex >= 0 ) && ( delindex <= array.length ) );
	
	if ( validNo && inRange ) {
		/*for ( var i = 0; i <= size; i++ ) {
			array[ i ] = ( ( i == delindex) ? "delete" : array[ i ] );
		}
		for ( var j = delindex; j < size -1; j++ ) {
			if ( j != size ) {
				array[ j ] = array[ j +1 ];
			}
			array.length = size -1;
		}*/
		delete( array[ delindex ] );
		for ( var j = delindex; j < size -1; j++ ) {
			array[ j ] = array[ j +1 ];
		}
		array.length = size -1;
	}
}

function iif( check, return1, return2 ) {
    if ( check ) {
        return return1;
    } else {
        return return2;
    }
}

function selectOption( obj, selectvalue ) {
	for ( var i = 0; i < obj.options.length; i++ ) {
		if ( obj.options[i].value = selectvalue ) {
			obj.selectedIndex = i;
			break;
		}
	}
}

function cloneObject(what) {
    for (i in what) {
        this[i] = what[i];
    }
}

/**
 * X-browser event handler attachment and detachment
 *
 * @argument obj - the object to attach event to
 * @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 * @argument fn - function to call
 */
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

function formatDuizendTallen(num){	
	if( num.length > 3 ){
		var num = num.slice(0,(num.length-3))+"."+num.slice(-3)
	}
		 
	return num;
}
