function writemail(naam,mail,mailhost) {
document.write("<a href=" + "mail" + "to:" + mail + "@" + mailhost+ " title=" + mail + "@" + mailhost + ">" + naam + "</a>")
}

function createHTTPHandler(){
    httphandler = false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    try {
      httphandler = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
       httphandler = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
          httphandler = false;
      }
    }
    @end @*/
    if (!httphandler && typeof XMLHttpRequest!='undefined') {
        httphandler = new XMLHttpRequest();
    }
    return httphandler;
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function show(o)
{
  var imganchors = o.parentNode.parentNode.getElementsByTagName("a")
    , i = imganchors.length
    , re = /\sclicked/gi;
 
  while (i--)
    imganchors[i].className = imganchors[i].className.replace(re, '');
 
  o.className += ' clicked';
}


function EncodeUrl(string) {
  string = string.replace(/\r\n/g,"\n");
  var utftext = "";
    for (var n = 0; n < string.length; n++) {
      var c = string.charCodeAt(n);
        if (c < 128) {
          utftext += String.fromCharCode(c);
        }
        else if((c > 127) && (c < 2048)) {
          utftext += String.fromCharCode((c >> 6) | 192);
          utftext += String.fromCharCode((c & 63) | 128);
        }
        else {
         utftext += String.fromCharCode((c >> 12) | 224);
         utftext += String.fromCharCode(((c >> 6) & 63) | 128);
         utftext += String.fromCharCode((c & 63) | 128);
       }
    }
  return escape(utftext);
} 

function ajax_form($form_id,$action,$result_function) {
  statusdiv = document.getElementById('statusdiv');
  xmlhttp_form = createHTTPHandler();
  form = document.getElementById($form_id);
  
  //maak functie die submit button kan veranderen
  function submit_value(value,disabling) {
    for($i = 0; $i < form.elements.length;$i++) {
      if(form.elements[$i].type == 'submit') { form.elements[$i].value = value; }
      form.elements[$i].disabled = disabling;
    }
  }
  
  //get form element names en inhoud
  sElements = '';
  for($i = 0; $i < form.elements.length;$i++) {
    if($i != 0) { 
      sElements += '&'; 
    }
    sElements += form.elements[$i].name +'='+ EncodeUrl(form.elements[$i].value);
    //alert(form.elements[$i].name +'='+ EncodeUrl(form.elements[$i].value));
  }
  //alert(sElements);
  //set method en .open parameter
  if(form.method == 'post') {xmlhttp_form.open('POST', $action, true); }
  else {xmlhttp_form.open('GET', $action +'?'+sElements, true);}
  
  //zorg voor afhandeling
  xmlhttp_form.onreadystatechange = function() {
    if(xmlhttp_form.readyState==4 && xmlhttp_form.status == 200) {
      submit_value('Verzenden',false);
      //alert(xmlhttp_form.responseText);
      eval($result_function+'(\''+xmlhttp_form.responseText+'\')');
    }
    else if(xmlhttp_form.readyState==4) {
      submit_value('Verzenden',false);
      statusdiv.innerHTML = 'Error: '+xmlhttp_form.status;
    }
    else {
      statusdiv.innerHTML = "<img src=\"img/loading.gif\" alt=\"\"> Bezig...";
      submit_value('Bezig...',true);
    }
  }
  
  //set headers
  xmlhttp_form.setRequestHeader("Cache-Control", "no-cache");
  xmlhttp_form.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlhttp_form.setRequestHeader('Connection', 'close');
  
  //send
  if(form.method == 'post') {xmlhttp_form.send(sElements); }
  else {xmlhttp_form.send(null);}
}


function tekengb_result(value) {
  if(value === 'ok:insert') {
    window.location.href = 'gastenboek.php';//refresh
  }
  else if(value == 'error:empty_values') {
    statusdiv.innerHTML = 'Alle velden invullen aub.';
  }
  else {
    statusdiv.innerHTML = 'Fout: '+ value;
  }
}

