// JavaScript Document

function checkForm(whichForm) {
  // client sided form checks
  
  if (whichForm=='contact') {
    var submitOK = true,
        errorTxt = '',
        o = document.contact;
    
    if ((o.firstname.value=='') && submitOK) {
      // firstname moet worden ingevuld
      submitOK = false;
      errorTxt = 'Please fill in the Firstname field.';
    }
    
    if ((o.familyname.value=='') && submitOK) {
      // familyname moet worden ingevuld
      submitOK = false;
      errorTxt = 'Please fill in the Familyname field.';
    }
    
      if ((o.company.value=='') && submitOK) {
      // company moet worden ingevuld
      submitOK = false;
      errorTxt = 'Please fill in the Company field.';
    }
    
    if ((o.email.value=='') && submitOK) {
      // email moet worden ingevuld
      submitOK = false;
      errorTxt = 'Please fill in the Email field.';
    }
    
    if ((o.subject.value=='') && submitOK) {
      // subject moet worden ingevuld
      submitOK = false;
      errorTxt = 'Please fill in the Subject field.';
    }
    
    if ((o.message.value=='') && submitOK) {
      // message moet worden ingevuld
      submitOK = false;
      errorTxt = 'Please fill in the Message field.';
    }
    
    // afronding
    if (submitOK) {
      // Als ik hier zit weet ik dat formulier is gecheckt door checkForm()
      //    PDA + Pocket IE is in staat tot formsubmit waarbij alle
      //    client scripting wordt gebypasst terwijl client scripting aan staat.
      //    (door enter op keyb te gebruiken ipv de submit-knop)
      o.send.value = "1"; // submit naar de juiste pagina.
  	// bovenstaande php variabelen zijn altijd beschikbaar
    }
    else {
      alert('The form cannot be sent.\n' + errorTxt);
    }
    
    return submitOK;
  }
}


function searchsuggest(searchtext, activelanguage) {
  // zoekhulp
  var ajaxObj      = null; // fix voor ie6: creeer elke keer opnieuw een nieuw ajax object (zucht)
  var foundtext,
      foundtextArray,
      foundtextHTML;
  
  try {
    // Firefox, Opera 8+, Safari
    ajaxObj = new XMLHttpRequest();
  }
  catch(e) {
    try {
      // IE
      ajaxObj = new ActiveXObject('Msxml2.XMLHTTP');
    }
    catch(e) {
      try {
        // IE
        ajaxObj = new ActiveXObject('Microsoft.XMLHTTP');
      }
      catch(e) {
        // helaas pindakaas, geen ajax.
        return false;
      }
    }
  }
  
  ajaxObj.onreadystatechange = function () {
    // als het 4 is dan hebben we resultaat
    
    if (ajaxObj.readyState == 4) {
      // het resultaat is binnen
      
      foundtext      = ajaxObj.responseText;
      foundtextArray = foundtext.split('|');
      foundtextHTML  = '';
      
      for (var index in foundtextArray) {
        foundtextHTML += '<span onclick="shoot(this.innerHTML)">' + foundtextArray[index] + '</span><br>';
        
      }
      
      if (ajaxObj.responseText!='0') {
        // duw zoeksuggesties in layer
        document.getElementById("searchsuggest").innerHTML = foundtextHTML;
      }
      else {
        // helaas, geen match gevonden - layer verwijderen
        document.getElementById("searchsuggest").innerHTML = ''; // no result
      }
    }
  }
  
  // debug
  // ok = prompt ('Link naar php:', 'ajax.searchsuggest.php?l=' + activelanguage + '&s=' + escape(searchtext));
  ok = true;
  
  if (ok) {
    ajaxObj.open('GET', 'ajax.searchsuggest.php?l=' + activelanguage + '&q=' + searchtext, true);
    ajaxObj.send(null);
  }
  
}

function shoot(text) {
  document.zoek.q.value = text;
  // document.zoek.submit();
}