function doSearch()
{
  var el = document.getElementById("SEARCHTXT");
  var idsite = siteid;
  if (el!=null) if (el.value != null) if (el.value != "") {
      to(73,"search="+el.value);
  }
}
function keydown(e) {
  if (e==null) return;
  try 
  {
    var keyCode = e.keyCode;
  }
  catch(e) 
  {
    alert(e.message);
  }
  if (keyCode==null) keyCode=e.which;
  if (keyCode==13) {
    try 
    {
	    if (e.cancelBubble!=null) e.cancelBubble=true;
	    if (e.returnValue!=null) e.returnValue=false;
	    if (e.keyCode!=null) e.keyCode=0;
	    if (e.which!=null) e.which=0;
    }
    catch(e)
    {
    }
    doSearch();
    return false;
  };
}

function hidePath()
{
	var el = document.getElementById("kruimelpad-title");
	
	if (el != null)
		el.style.display="none";
}


/* Functions for document download system */
function ToStep(stepNr) {
    var frm = document.forms["downloadform"];
    if (frm == null) {
		alert("Form not found!");
		return;
	}
    
    var docs = frm.elements["docDownload"];
    if (docs == null) {
		alert("Download field not found!");
		return;
	}
    
    var go = false;
    
    for (var i = 0; i < docs.length; i++) {
        if (docs[i] != null)
            if (docs[i].checked) {
                go = true;
                break;
            }
    }
    
    if (!go) {
        alert("U dient ten minste een document te selecteren!");
        return;
    }
    else {
        if (stepNr == null) stepNr = 1;
        var layerNAW = document.getElementById("layerNAW");
        var layerDownload = document.getElementById("layerDownloads");
        if (layerNAW != null && layerDownload != null) {
            if (stepNr == 2) { // Step 2 NAW form
                layerNAW.style.display = "block";
                layerDownload.style.display = "none";
				if (window.scroll != null) window.scroll(0,0);
            }
            else {  // Step 1 download form
                layerNAW.style.display = "none";
                layerDownload.style.display = "block";
            }
        }    
    }
}

function DoPost() {
    var frm = document.forms["downloadform"];
    if (frm == null) {
		alert("Form not found!");	
	}
	
	submitForm(frm);
}





function validEmailAddress(email) {
	if (email==null) return true;
	var legalchars = "@.-_";
	var c = "";
	email = ""+email;
	if (email.indexOf("@")==-1) return false;
	if (email.indexOf(".")==-1) return false;

	for (var i=0; i<=email.length-1; i++) {
		c = email.substr(i,1);
		if (!((c>="a" && c<="z") || (c>="A" && c<="Z") || (c>="0" && c<="9") || (legalchars.indexOf(c)>=0)))
			return false;
	}
	var arr = email.split("@");
	if (arr[0] == "") return false;
	if (arr[1] == "") return false;
	if (arr[0] == ".") return false;
	if (arr[1] == ".") return false;

	if (email.substr(email.length-1,1)=="@") return false;
	if (email.substr(email.length-1,1)==".") return false;
	if (email.substr(0,1)=="@") return false;
	if (email.substr(0,1)==".") return false;
	return true;
}


function CheckEmail(emailField) {
    if (emailField != null) {
		if (emailField.value != null)
			if (validEmailAddress(emailField.value))
				return true;
			else {
				alert("Ongeldig email adres!");
				if (emailField.focus != null) emailField.focus();
				return false;
			}
    }
	return false;
}

function CheckField(formField) {
    if (formField != null) {
        if (formField.value.length < 1) {
            alert("Het veld "+formField.name+" is niet ingevuld!");
            formField.focus();
        }
        else {
            return true;
        }
    }
    return false;
}

function submitForm(theform) {
  if (theform == null) return;

  var sCompanyName    = theform.elements["Bedrijfsnaam"];
  var sContact        = theform.elements["Contactpersoon"];
  var sFunction       = theform.elements["Functie"];
  var sEmail          = theform.elements["E-mail"];
  var sPhone          = theform.elements["Telefoon"];  
  var btnSubmit       = theform.elements["aanvragen"];  
  var nieuwsbrief     = theform.elements["Nieuwsbrief"];  
  if (nieuwsbrief != null)
	if (nieuwsbrief.checked == true) {
		var nb = "1";
	}
	else {
		var nb = "0";
	}

  // Check fields
  if (CheckField(sCompanyName) == false) return;
  if (CheckField(sContact) == false) return;
  if (CheckField(sFunction) == false) return;
  if (CheckField(sEmail) == false) return;
  if (CheckEmail(sEmail) == false) return;
  if (CheckField(sPhone) == false) return;

  // Submit
  //if (btnSubmit != null) btnSubmit.disabled = true;

  theform.action = "/scripts/downloads.asp?n="+nb+"&dlmode=POST";
  var status = AjaxRequest.submit(
    theform
    ,{
	'onSuccess':function(req){ window.location = "/downloaden.html?dlmode=RDY"; }
	//'onSuccess':function(req){ alert(req.responseText); }
    }
  );
  return status;
}
        
/* End - Functions for document download system */        