/* ============================================================================================
	 Naam:		form.js
	 Functie: Controlefuncties formulier-velden
	 Door:		Zinster Webdesign
   ============================================================================================ */
	 
function isValidEmail(str) {
  var atSym = str.lastIndexOf("@");
  if (atSym < 1) { return false; } // no local-part
  if (atSym == str.length - 1) { return false; } // no domain
  if (atSym > 64) { return false; } // there may only be 64 octets in the local-part
  if (str.length - atSym > 255) { return false; } // there may only be 255 octets in the domain

  // Is the domain plausible?
  var lastDot = str.lastIndexOf(".");
  // Check if it is a dot-atom such as example.com
  if (lastDot > atSym + 1 && lastDot < str.length - 1) { return true; }
  //  Check if could be a domain-literal.
  if (str.charAt(atSym + 1) == '[' &&  str.charAt(str.length - 1) == ']') { return true; }
  return false;
}

function zetGoed(nodeNaam) {
	var node = document.getElementById(nodeNaam);
	node.className=node.className.replace(" inputFout", "");
}

function zetFout(nodeNaam) {
	var node = document.getElementById(nodeNaam);
  var index = node.className.lastIndexOf(" inputFout");
	// alert("Index: " + nodeNaam + ":" + index);
	if (index > 0 ) {
	} else {
		node.className+=" inputFout";
	}
}

function isInputOk() {
	var inputOk = true;
	
	if(document.frmContact.naam_gast01.value.length < 1) {
		zetFout("naam_gast01");
		inputOk = false;
	} else {
		zetGoed("naam_gast01");
	}
	
	if(document.frmContact.adres.value.length < 1) {
		zetFout("adres");
		inputOk = false;
	} else {
		zetGoed("adres");
	}

	if(document.frmContact.postcode.value.length < 4) {
		zetFout("postcode");
		inputOk = false;
	} else {
		zetGoed("postcode");
	}

	if(document.frmContact.woonplaats.value.length < 2) {
		zetFout("woonplaats");
		inputOk = false;
	} else {
		zetGoed("woonplaats");
	}

	if(document.frmContact.telefoon.value.length < 6) {
		zetFout("telefoon");
		inputOk = false;
	} else {
		zetGoed("telefoon");
	}

	if(isValidEmail(document.frmContact.email.value)) {
		zetGoed("email");
	} else {
		zetFout("email");
		inputOk = false;
	}

	if(document.frmContact.aankomst_datum.value.length < 6) {
		zetFout("aankomst_datum");
		inputOk = false;
	} else {
		zetGoed("aankomst_datum");
	}

	if(document.frmContact.vertrek_datum.value.length < 6) {
		zetFout("vertrek_datum");
		inputOk = false;
	} else {
		zetGoed("vertrek_datum");
	}

	if(!document.frmContact.akkoord.checked) {
		document.frmContact.akkoord.style.outline = "1px solid #FFCCFF";
		document.frmContact.akkoord.style.border = "1px solid #FFCCFF";
		inputOk = false;
	} else {
		document.frmContact.akkoord.style.outline = "1px solid #ffffff";
		document.frmContact.akkoord.style.border = "1px solid #ffffff";
	}

	if(document.frmContact.secur.value.length < 5) {
		zetFout("secur");
		inputOk = false;
	} else {
		zetGoed("secur");
	}
	return inputOk;
}

/* ============================================================================================ */

