function IsValidEmail(objName) {
	var fieldName = objName;
	if (EmailCheck(fieldName.value) == false) {
		alert("Email adres is niet geldig.");
		fieldName.focus();
		return false;
	} else {
		return true;
	}
}

function CheckField(objName) {
	var fieldName = objName;
	if (IsEntered(fieldName) == false) {
		alert("Niet alle verplichte velden zijn ingevuld.");
		fieldName.focus();
		return false;
	} else {
		return true;
   }
}

function IsEntered(objName) {
	var fieldName = objName;
	if (fieldName.value.length > 0) 
		return true
	else
		return false;		
}

function HasCategory() {	
	var selName = "category[]";
	return MultiChecked(selName);
}


function MultiChecked(formfield) {	
	var theForm = document.forms[0];
	var selName = formfield;
	// get a handle to the object
	var selObject = GetObjectArrayFromName( theForm, selName );
	// programmer error?
	if (selObject == null ) {
		alert("Formulierfout: " & selName & "niet gevonden.");
		return false;
	}
	// check at least one checkbox is checked
	checkFlag = false;
	for (i = 0; i < selObject.length; i++) {
		if (selObject[i].checked) checkFlag = true;	
	}
	// halt submit of form if not enough info
	if (!checkFlag) {
		alert("U moet tenminste 1 checkbox selecteren.");
		return false;
	} else 
	 	return true;
}

/*
 need special javascript code to reach object handle 
 because of incompatibility between javascript and php
 when we want a multiple selection.
*/
function GetObjectArrayFromName(theForm, theObjectName ) {
	var theObjectArray = Array();
	a = 0;
	// go through each form element looking for the name
	for (var i=0;i<theForm.elements.length;i++) {
		if ( theForm.elements[i].name == theObjectName ) {
			// found it, add object to array
			theObjectArray[a] = theForm.elements[i];
			a++;
		}
   	}
	if (theObjectArray.length > 0) 
		return theObjectArray
	else
   	   return null;
}


function EmailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	var validChars="\[^\\s" + specialChars + "\]"
	var quotedUser="(\"[^\"]*\")"
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+'
	var word="(" + atom + "|" + quotedUser + ")"
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	// See if "user" is valid 
	if (user.match(userPat)==null) {
    // user is not valid
    	//alert("The username doesn't seem to be valid.")
    	return false
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
   		host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
    	// this is an IP address
	  	for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
	        	//alert("Destination IP address is invalid!")
				return false
	    	}
    	}
    	return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("The domain name doesn't seem to be valid.")
	    return false
	}

	/* domain name seems valid, but now make sure that it ends in a
	   	three-letter word (like com, edu, gov) or a two-letter word,
	   	representing country (uk, nl), and that there's a hostname preceding 
	   	the domain or country. */

	/* Now we need to break up the domain to get a count of how many atoms
   		it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
    	domArr[domArr.length-1].length>4) {
   		// the address must end in a two,three or four letter word.
   		//alert("The address must end in a three- or four-letter domain, or two letter country.")
   		return false
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
   		var errStr="This address is missing a hostname!"
   		//alert(errStr)
   		return false
	}

	// If we've gotten this far, everything's valid!
	return true;
}
