function ktCheck(id, val) 
{
    var field = document.getElementById(id);
    var length = field.value.length;    
    
    switch(id) 
    {
        case "kt_inp1" :
            if (length==2) 
            { 
                colr(field, 'good'); 
                document.getElementById('kt_inp2').focus();
            }
            else
            {
                colr(this,'wrong');
            }
            break;
        case "kt_inp2" :
            if (length==3)
            {
                colr(field, 'good'); 
                document.getElementById('kt_inp3').focus();
            }
            else
            {
                if (length==2)
                {
                    colr(field, 'good');     
                }
                else
                {
                    colr(this,'wrong');
                }
            }
            break;
        case "kt_inp3" :
            // afhankelijk lengte van veld 2
            var length_2 = document.getElementById('kt_inp2').value.length;
            
            if (length_2==3 && length == 1)
            {
                colr(field, 'good'); 
                document.getElementById('kt_inp3').focus();
            }
            else
            {
                if (length_2==2 && length == 2)
                {
                    colr(field, 'good'); 
                    document.getElementById('kt_inp3').focus();
                }
                else
                {
                    colr(this,'wrong');
                }    
            }
            break;        
    }
    
    if (length==2)
    {
        colr(field, 'good'); 
        if (id == 'kt_inp1') document.getElementById('kt_inp2').focus();
    }
    else
    {
        colr(this,'wrong');
    }
}

function ktxAll(i) {
  i.value = i.value.toUpperCase().replace(/([^0-9A-Z])/g,"");
}

function ktxNum(i) {
  i.value = i.value.replace(/([^0-9])/g,"");
}

function ktValiForm() {
  var vali = true;
  var xItem;
  
  xItem = document.kenteken_form.kt_inp1;
  if(xItem.value.length != 2){
  	vali = false; colr(xItem, "failed"); 
  }
  
  xItem = document.kenteken_form.kt_inp2;
  if(xItem.value.length < 2 && xItem.value.length > 3){
  	vali = false; colr(xItem, "failed"); 
  } 

  xItem = document.kenteken_form.kt_inp3;
  if(xItem.value.length < 1 && xItem.value.length > 2){
  	vali = false; colr(xItem, "failed"); 
  }
  
  xItem = document.kenteken_form.kt_chassis;
  if(xItem.value.length != 4){
  	vali = false; colr(xItem, "failed"); 
  }
  
  return vali;
}


function colr(i, xCase) {
  switch(xCase) 
  {
  	case "good":
  	  i.style.backgroundColor = "#ffde00";
  	  i.style.borderColor = "#ffde00";
  	  i.style.color = "#000000";
  	  i.style.fontWeight = "bold";
  	  break;
  	case "failed":
   	  i.style.backgroundColor = "#ffffff";
  	  i.style.borderColor = "#ff0000";
  	  i.style.color = "#ff0000";
  	  i.style.fontWeight = "normal";
  	  break;
  	case "wrong":
      i.style.backgroundColor = "#ffffff";
  	  i.style.borderColor = "#ffa740";
  	  i.style.color = "#000000";
  	  i.style.fontWeight = "normal";
   	  break;
   	case "good2":
      i.style.backgroundColor = "#e8f5ed";
  	  i.style.borderColor = "#00a740";
  	  i.style.color = "#000000";
  	  i.style.fontWeight = "normal";
  }
}

function IsNumeric(strString) {
  var strValidChars = "0123456789";
  var strChar;
  var blnResult = true;

  if (strString.length == 0) return false;

  //  test strString consists of valid characters listed above
  for (i = 0; i < strString.length && blnResult == true; i++) {
    strChar = strString.charAt(i);
    if (strValidChars.indexOf(strChar) == -1) {
      blnResult = false;
    }
  }
  return blnResult;
}
