
function fillCategory(){ 
  // this function is used to fill the category list on load
  addOption(document.drop_list.Category, "contant", "Contant", "");
  addOption(document.drop_list.Category, "rekening", "Op Rekening", "");
  addOption(document.drop_list.Category, "ideal", "iDEAL (online)", "");
  }

function SelectSubCat(){
  // ON selection of category this function will work
  removeAllOptions(document.drop_list.SubCat);
  addOption(document.drop_list.SubCat, "", "Levering", "");
  
  if(document.drop_list.Category.value == 'contant'){
    addOption(document.drop_list.SubCat,"Ophalen", "ophalen");
    addOption(document.drop_list.SubCat,"Verzenden", "verzenden");
    }
  
  if(document.drop_list.Category.value == 'rekening'){
    addOption(document.drop_list.SubCat,"Ophalen", "ophalen");
    addOption(document.drop_list.SubCat,"Verzenden", "verzenden");
    }
  
  if(document.drop_list.Category.value == 'ideal'){
    addOption(document.drop_list.SubCat,"Ophalen", "ophalen");
    addOption(document.drop_list.SubCat,"Verzenden", "verzenden");
    }
  }
////////////////// 

function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}


function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}



////////////////////////////////////////////////////////////////////////
//                                                                    //
//  BERICHTENCONTROLE GASTENBOEK                                      //
//                                                                    //
////////////////////////////////////////////////////////////////////////

function emoticon(text) {
	text = ' ' + text + ' ';
	if (document.message.userinput.createTextRange && document.message.userinput.caretPos) {
		var caretPos = document.message.userinput.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		document.message.userinput.focus();
	  }
  else {
  	document.message.userinput.focus();
	  document.message.userinput.value  += text;
  	}
  }

function validate_gastenboek(formulier){
  var orig_message = "Onderstaande velden is/zijn niet ingevuld:<br><br>";
  var themessage   = orig_message; // zo geen problemen meer bij evt. typfouten
  var i = 0;
  
  if(!formulier.subject.value) {
    themessage = themessage + "- Naam<br>";
    i++;
    }
  if(formulier.userinput.value == "") {
    themessage = themessage + "- Bericht<br>";
    i++;
    }
  
  // als berichten gelijk zijn, mag het formulier worden verstuurd
  if(themessage == orig_message){
    document.message.submit();
//    window.location.reload();
    }
  else{
    if(i == 1){
      themessage = themessage + "<br>Dit veld is ook verplicht!<br>";
      }
    else{
      themessage = themessage + "<br>Deze velden zijn verplicht!<br>";
      }
    toggle_visibility('foutmelding');
    toggle_visibility('foutmelding1');
    document.getElementById('foutmelding1').innerHTML = themessage;
    }

	}


function toggle_visibility(id) {
  var e = document.getElementById(id);
  
  if(e.style.display == 'none')
    e.style.display = 'block';
  else
    e.style.display = 'none';
  }

////////////////////////////////////////////////////////////////////////
//                                                                    //
//  TEKENS-TELLER GASTENBOEK                                          //
//                                                                    //
////////////////////////////////////////////////////////////////////////

function textCounter(field,cntfield,maxlimit) {
  if (field.value.length > maxlimit) // if too long...trim it!
    field.value = field.value.substring(0, maxlimit);
    // otherwise, update 'characters left' counter
  else
    cntfield.value = maxlimit - field.value.length;
  }



