var colorGood = "#006600";
var colorBad = "#990000";
var sizeGood = "3";
var sizeBad = "2";

function chkl1()
{
  var txt = document.getElementById("l1").value;
  //document.getElementById("l1").value = restrictLastChar(txt);
  document.getElementById("l1").value = removeChars(txt);
  txt = document.getElementById("l1").value;
  var arr = txt.split("");
  if(arr[arr.length-1] == " "){
    cntl1();
  }
}
function chkl2()
{
  var txt = document.getElementById("l2").value;
  //document.getElementById("l2").value = restrictLastChar(txt);
  document.getElementById("l2").value = removeChars(txt);
  txt = document.getElementById("l2").value;
  var arr = txt.split("");
  if(arr[arr.length-1] == " "){
    cntl2();
  }
}
function chkl3()
{
  var txt = document.getElementById("l3").value;
  //document.getElementById("l3").value = restrictLastChar(txt);
  document.getElementById("l3").value = removeChars(txt);
  txt = document.getElementById("l3").value;
  var arr = txt.split("");
  if(arr[arr.length-1] == " "){
    cntl3();
  }
}
function cntl1()
{
  var txt = document.getElementById("l1").value;
  var syl = countSyllLine(txt);
  var sol = syl;
  var color;
  var size;
  if( syl != 5){
    sol += " of 5";
    color = colorBad;
    size = sizeBad;
  } else {
    sol += " !";
    color = colorGood;
    size = sizeGood;
  }
  document.getElementById("l1c").innerHTML=formatInnerHTML(sol, color, size);
}
function cntl2()
{
  var txt = document.getElementById("l2").value;
  var syl = countSyllLine(txt);
  var sol = syl;
  var color;
  var size;
  if( syl != 7){
    sol += " of 7";
    color = colorBad;
    size = sizeBad;
  } else {
    sol += " !";
    color = colorGood;
    size = sizeGood;
  }
  document.getElementById("l2c").innerHTML=formatInnerHTML(sol, color, size);
}
function cntl3()
{
  var txt = document.getElementById("l3").value;
  var syl = countSyllLine(txt);
  var sol = syl;
  var color;
  var size;
  if( syl != 5){
    sol += " of 5";
    color = colorBad;
    size = sizeBad;
  } else {
    sol += " !";
    color = colorGood;
    size = sizeGood;
  }
  document.getElementById("l3c").innerHTML=formatInnerHTML(sol, color, size);
}
function formatInnerHTML(inSol, inColor, inSize){
   return "<font color='"+inColor+"' size="+inSize+"><b>"+inSol+"</b></font>";
}

function removeChars(inStr){
  var arr = inStr.split("");
  var retArr = new Array();
  for(a=0; a<arr.length; a++){
    if( compareChars(arr[a]) != true ){
      retArr.push(arr[a]);
    }
  }
  return retArr.join("");
}
function restrictLastChar(inStr){

  var arr = inStr.split("");
  var lastChar = arr.pop();

  if( compareChars(lastChar) == true ){
    inStr = arr.join("");
  }

  return inStr;
}
function compareChars(inStr){
  var bool = false;
  
  var arr = getArr();
  
  for(c=0; c<arr.length; c++){
    if( arr[c] == inStr){
      bool = true;
    }
  }
  return bool;
}

function restrictChars(e){
  var keynum;
  var keychar;

  if(window.event) // IE
    {
    keynum = e.keyCode;
    }
  else if(e.which) // Netscape/Firefox/Opera
    {
    keynum = e.which;
    }
    
  keychar = String.fromCharCode(keynum);
 
  var bool = true;
  var arr = getArr();
  for(c=0; c<arr.length; c++){
    if( keychar == arr[c] ){
      bool = false;
      break;
    }
  }
  
  return bool;
}
function getArr(){
  var arr = new Array();
  // The escape() function encodes special characters, with the exception of: * @ - _ + . /
  arr.push("*","@","_","+","/");
  // additional characters to restrict:
  arr.push("[","]","{","}","<",">","`","~","#","%","^","&","=","\´","ø", "å");
  arr.push("0","1","2","3","4","5","6","7","8","9");
  return arr;
}

// this array is of all allowable characters
function getArrAllowable(){
  var arr = new Array();
  arr.push("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
  arr.push("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");
  arr.push(" ",".",",","?","!");
  return arr;
}