//Alleen cijfers toestaan als keyboardinput van een tekstvak
function alleenCijfers() {
    if(!(event.keyCode==48||event.keyCode==49||event.keyCode==50||event.keyCode==51||event.keyCode==52||event.keyCode==53||event.keyCode==54||event.keyCode==55||event.keyCode==56||event.keyCode==57)) {
        event.returnValue=false;
    }
}

//Maak een grijze half-doorzichtige laag aan baven de html pagina
//Om te kunnen refocussen op de onderliggende pagina moet er een functie refocusPage() bestaan (zie functions_sms.js)
function grayOut(vis, options) {
  // Pass true to gray out screen, false to ungray
  // options are optional.  This is a JSON object with the following (optional) properties
  // opacity:0-100         // Lower number = less grayout higher = more of a blackout
  // zindex: #             // HTML elements with a higher zindex appear on top of the gray out
  // bgcolor: (#xxxxxx)    // Standard RGB Hex color code
  // grayOut(true, {'zindex':'50', 'bgcolor':'#0000FF', 'opacity':'70'});
  // Because options is JSON opacity/zindex/bgcolor are all optional and can appear
  // in any order.  Pass only the properties you need to set.
  var options = options || {};
  var zindex = options.zindex || 50;
  var opacity = options.opacity || 70;
  var opaque = (opacity / 100);
  var bgcolor = options.bgcolor || '#000000';
  var dark=document.getElementById('darkenScreenObject');
  if (!dark) {
    // The dark layer doesn't exist, it's never been created.  So we'll
    // create it here and apply some basic styles.
    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
    var tbody = document.getElementsByTagName("body")[0];
    var tnode = document.createElement('div');           // Create the layer.
        tnode.style.position='absolute';                 // Position absolutely
        tnode.style.top='0px';                           // In the top
        tnode.style.left='0px';                          // Left corner of the page
        tnode.style.overflow='hidden';                   // Try to avoid making scroll bars
        tnode.style.display='none';                      // Start out Hidden
        tnode.id='darkenScreenObject';                   // Name it so we can find it later

        tnode.onclick=function(){refocusPage()};         // Refocus op de onderliggende pagina

    tbody.appendChild(tnode);                            // Add it to the web page
    dark=document.getElementById('darkenScreenObject');  // Get the object.
  }
  if (vis) {
      var pageWidth;
      var pageHeight
    // Calculate the page width and height
    if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) {
        if(document.body.scrollWidth < screen.width) {
            pageWidth = screen.width + 'px';
        }
        else {
            pageWidth = document.body.scrollWidth+'px';
        }
        if(document.body.scrollHeight < screen.height) {
            pageHeight = screen.height + 'px';
        }
        else {
            pageHeight = document.body.scrollHeight + 'px';
        }
    } else if( document.body.offsetWidth ) {
        if(document.body.offsetWidth < screen.width) {
            pageWidth = screen.width + 'px';
        }
        else {
            pageWidth = document.body.offsetWidth + 'px';
        }
        if(document.body.offsetHeight < screen.height) {
            pageHeight = screen.height + 'px';
        }
        else {
            pageHeight = document.body.offsetHeight + 'px';
        }
    } else {
       pageWidth='100%';
       pageHeight='100%';
    }

    //set the shader to cover the entire page and make it visible.
    dark.style.opacity=opaque;
    dark.style.MozOpacity=opaque;
    dark.style.filter='alpha(opacity='+opacity+')';
    dark.style.zIndex=zindex;
    dark.style.backgroundColor=bgcolor;
    dark.style.width= pageWidth;
    dark.style.height= pageHeight;
    dark.style.display='block';
  } else {
     dark.style.display='none';
  }
}

//Het <div>-element met opgegeven id verwijderen van de pagina
function verwijderElement(divId, parentDivId) {
    //De <div> waarin we gaan werken ophalen
    var parentdiv = document.getElementById(parentDivId);
    //De oude <div> ophalen
    var olddiv = document.getElementById(divId);
    //De oude <div> verwijderen
    parentdiv.removeChild(olddiv);
}

//trim functie
//(http://stackoverflow.com/questions/3000649/trim-spaces-from-start-and-end-of-string)
function trim (str) {
    str = str.replace(/^\s+/, '');
    for (var i = str.length - 1; i >= 0; i--) {
        if (/\S/.test(str.charAt(i))) {
            str = str.substring(0, i + 1);
            break;
        }
    }
}

//check for valid numeric strings
//(http://snippets.dzone.com/posts/show/3381)
function IsNumeric(strString) {
	if(!/\D/.test(strString)) return true;//IF NUMBER
	else if(/^\d+\.\d+$/.test(strString)) return true;//IF A DECIMAL NUMBER HAVING AN INTEGER ON EITHER SIDE OF THE DOT(.)
	else return false;
}
