// Controleer contactformulier

function checkForm() {
	var strEmail = document.nieuwsbrief.email.value;
	
	if (document.nieuwsbrief.bedrijfsnaam.value == "" || document.nieuwsbrief.bedrijfsnaam.value == "Bedrijfsnaam") {
		alert("Vul een bedrijfsnaam in")
		document.nieuwsbrief.bedrijfsnaam.focus();
	} else if (document.nieuwsbrief.contactpersoon.value == "" || document.nieuwsbrief.contactpersoon.value == "Contactpersoon") {
		alert("Vul uw naam in")				
		document.nieuwsbrief.contactpersoon.focus();
	} else if (document.nieuwsbrief.functie.value == "" || document.nieuwsbrief.functie.value == "Functie") {
		alert("Vul uw functie in")				
		document.nieuwsbrief.functie.focus();
	} else if (!checkEmail(strEmail)) {
		alert("Vul een correct e-mailadres in")
		document.nieuwsbrief.email.focus();
	} else if (document.nieuwsbrief.telefoon.value == "" || document.nieuwsbrief.telefoon.value == "Telefoonnummer") {
	alert("Vul uw telefoonnummer in")				
	document.nieuwsbrief.telefoon.focus();
	} else {
		document.nieuwsbrief.submit();
	}		
}

function checkNieuwsbrief() {
	var strEmail = document.nieuwsbriefVervolg.email.value;
	
	if (document.nieuwsbriefVervolg.bedrijfsnaam.value == "" || document.nieuwsbriefVervolg.bedrijfsnaam.value == "Bedrijfsnaam") {
		alert("Vul een bedrijfsnaam in")
		document.nieuwsbriefVervolg.bedrijfsnaam.focus();
	} else if (document.nieuwsbriefVervolg.contactpersoon.value == "" || document.nieuwsbriefVervolg.contactpersoon.value == "Contactpersoon") {
		alert("Vul uw naam in")				
		document.nieuwsbriefVervolg.contactpersoon.focus();
	} else if (document.nieuwsbriefVervolg.functie.value == "" || document.nieuwsbriefVervolg.functie.value == "Functie") {
		alert("Vul uw functie in")				
		document.nieuwsbriefVervolg.functie.focus();
	} else if (!checkEmail(strEmail)) {
		alert("Vul een correct e-mailadres in")
		document.nieuwsbriefVervolg.email.focus();
	} else if (document.nieuwsbriefVervolg.telefoon.value == "" || document.nieuwsbriefVervolg.telefoon.value == "Telefoonnummer") {
	alert("Vul uw telefoonnummer in")				
	document.nieuwsbriefVervolg.telefoon.focus();
	} else {
		document.nieuwsbriefVervolg.submit();
	}		
}

function checkEmail(strEmail)
{
	strtmpEmail = String(strEmail);
	
	// Er moet een @ en een . voorkomen in een emailadres
	if (strtmpEmail.indexOf("@")== -1 || strtmpEmail.indexOf(".")== -1)
	{
		return false;
	}
	nAt = strtmpEmail.indexOf("@")
	if (nAt > 0) {
		strCheck = strtmpEmail.slice(nAt + 1)
		// De @ komt voor de .  xxx.ppibv@nl, maar tim@ppibv.nl moet ook kunnen
		// Indien de . direct na de @ komt is dat ook fout  tim@.nl
		if (strCheck.indexOf(".") <= 0 )
		{
			return false;
		}
		else {
			// Na de punt minimaal 2 tekens tim@ppibv.n
			return ((parseInt(strCheck.length) -1) - parseInt(strCheck.indexOf("."))  > 1 );
		}	
	}
	else {
		return false;
	}
}	
