function checkinput(inputname,message,form,type) {
 thabool = 0;
 //if (type == 'string'){ if (form[inputname].value != '') { thabool = 1; } }
 if (type == 'int' || type == 'integer'){
  valid = new RegExp("^[0-9]+$").exec(form[inputname].value);
  if (valid) { thabool = 1; } 
 }
 else if (type == 'email'){  
  valid = new RegExp("^[a-zA-Z0-9]+([.]?[a-zA-Z0-9_-]+)*[@]([a-zA-Z0-9_-]+[.])+([a-zA-Z]{2,4})$").exec(form[inputname].value);
  if (valid) { thabool = 1; } 
 }
 else { if (form[inputname].value != '') { thabool = 1; } } // String
 if (thabool == 0) {
  alert(message);
  thisinput = document.getElementsByName(inputname)[0];
  form[inputname].focus();
  thisinput.className = thisinput.className+' warning';
  divje = thisinput.parentNode;
  divje.className = divje.className+' warning';
  highlightMandatory(form[inputname]);
  return false;
 } else { return true; }
}
function checkJSDate(inputname,message,form,type,force){
 var el = form[inputname];
 var valid = new RegExp("^^[0-3][0-9][-]([0][0-9]|[1][0-2])[-][0-9]{4}$").exec(el.value);
 if((!valid && el.value != '')||(!valid && force)){
   //alert("Ongeldige format. voorbeeld: dd-mm-yyyy");
   highlightMandatory(el);
   alert(message);
   el.focus();
   return false;
 }else if(valid){
    day =parseInt(el.value.substr(0,2),10);
    month = parseInt(el.value.substr(3,2),10)-1;
    year = el.value.substr(6,4);
    dteDate=new Date(year,month,day);
    if(month != dteDate.getMonth() || day != dteDate.getDate() || year != dteDate.getFullYear()){
      //alert("Niet bestaande datum ingevoerd" );
      highlightMandatory(el);
      alert(message);
      el.focus();
      return false;
    }
 }
 return true;
}
function checkJSYear(inputname,message,form,type,force){
 var el = form[inputname];
 var valid = new RegExp("^^[0-3][0-9][0-9][0-9]$").exec(el.value);
 if((!valid && el.value != '')||(!valid && force)){
   //alert("Ongeldige format. voorbeeld: dd-mm-yyyy");
   highlightMandatory(el);
   alert(message);
   el.focus();
   return false;
 }else if(valid){
    year = el.value;
    dteDate=new Date();
    dteDate.setFullYear(year);
    if(year != dteDate.getFullYear()){
      //alert("Niet bestaande datum ingevoerd" );
      highlightMandatory(el);
      alert(message);
      el.focus();
      return false;
    }
 }
 return true;
}
function checkStreetWithNum(name,mes,form){
 var el = form[name];
 var valid = new RegExp("^[ a-zA-Z0-9]+[ ]+[0-9]{1,}[a-zA-Z]{0,}$").exec(el.value);
  if((!valid)){
   highlightMandatory(el);
   alert(mes);
   el.focus();
   return false;
 }
 return true;
}
function checkZipcode(name,mes,form){
 var el = form[name];
 var valid = new RegExp("^[0-9]{4}[ ]{0,1}[a-zA-Z]{2}$").exec(el.value);
  if((!valid)){
    highlightMandatory(el);
   alert(mes);
   el.focus();
   return false;
 }
 return true;
}
function checkPhone(name,form,force){
 var el = form[name];
 var valid = new RegExp("^([0-9]{3}[-]{0,1}[0-9]{7,})|([0-9]{2}[-]{0,1}[0-9]{8,})$").exec(el.value);
  if((!valid && el.value != '')||(!valid && force)){
   highlightMandatory(el);
   alert(translation.invalid_phone);
   el.focus();
   return false;
 }
 return true;
}

function forceFloat(value) {
//onKeyup="this.value=forceFloat(this.value)"
var aantal = value;
aantal = aantal.replace(/,/g,'.'); //replace all commas with points
last = aantal.charAt((aantal.length)-1);
if (last=='.') { return aantal; }  // als je nog geen cijfer achter de komma hebt ingetikt zal de parsefloat de punt ook weghalen, dat is onhandig als je dit niet in de gaten hebt.

if ( isNaN(parseFloat(aantal)) ) {
    aantal = 0.00; }
aantal = parseFloat(aantal);
return aantal;
}
function forceInt(myfield, e, dec) {
//onkeypress="return numbersonly(this, event)"
var key;
var keychar;
if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) ||
    (key==9) || (key==13) || (key==27) )
   return true;
// numbers
else if ((("0123456789").indexOf(keychar) > -1))
   return true;
else
   return false;
}
function checkSelect(name,message,form){
  var el = form[name];
  var sel = 0;
  if(el.multiple){
    for(var i=0;i<el.options.length;i++){
      if(el.options[i].selected){
        sel++;
      }
    }
  }else{
    if(el[el.selectedIndex].value != ''){
      sel++;
    }
  }
  if(sel< 1){
      alert(message);
      el.focus();
      return false;
    }
  return true;
}
function highlightMandatory(el){
  jQuery(el).addClass('mandatory_empty');
}
