<!--
// Last updated :  15-nov-2002
// Version MSM : 1.0

var melding
var a
var Form_Name
var FoutVeldNaam

StartVariabelen();		// ff alle Variabelen instellen


function StartVariabelen()
{
//melding			=	"Gaarne de volgende velden correct invullen: \n\n";
//a				=	melding.length;
FoutVeldNaam	=	"";
FoutVeld		=	false;
}

function BrowserVersion(Versie)
{
//How do I detect the browser the user is using?
var browser = navigator.appName;
var version = parseInt(navigator.appVersion);

//alert('Your browser is: ' + navigator.appName);
alert('Browser version is: (' + navigator.appVersion + ") " + version);

if (Versie >= version)
	{
	return true;
	}
}

function CheckField(VeldNaam, Type, MinChars, MaxChars, MeldingTekst, AantalSelectie)
{
// Type = Text, Numeric, Email, CheckBox, RadioButton
//alert(eval("window.document.forms[Form_Name]." + VeldNaam));
//alert(eval("window.document.forms[Form_Name]." + VeldNaam + ".value"));
// alert("MinChars = " + MinChars);
// alert("MaxChars = " + MaxChars);

	VeldNaam_New	= eval("window.document.forms[Form_Name]." + VeldNaam);
	VeldNaam_Value  = VeldNaam_New.value;
	
if (MinChars == "")
	MinChars = 0

if (MaxChars == "")
	MaxChars = 255
	
if (Type != "CheckBox" && Type != "RadioButton" && Type != "Select")
{
	//alert(VeldNaam + " - " + VeldNaam_Value);
	VeldNaam_Length = eval("VeldNaam_Value" + ".length");			// NETSCAPE : VeldNaam_Value has no properties. !@#$%
}
if (Type == "Select")
{
	VeldNaam_Length = VeldNaam_New[(VeldNaam_New.selectedIndex)].value.length;
}

//form.use[0].checked==false
//alert(VeldNaam_Value);
//alert(VeldNaam_Length);

switch(Type)
{
case "Text":		// WERKT PERFECT !
	if (VeldNaam_Length == "")
		{
  		melding = melding + "- " + MeldingTekst + " (is leeg)"  + "\n";
		
		FoutVeldInstellen(VeldNaam_New);
		}
	else if (VeldNaam_Length < MinChars)
		{
  		melding = melding + "- " + MeldingTekst + " (te kort)" + "\n";
		
		FoutVeldInstellen(VeldNaam_New);
		}
	else if (VeldNaam_Length > MaxChars)
		{
  		melding = melding + "- " + MeldingTekst + " (te lang)"  + "\n";
		
		FoutVeldInstellen(VeldNaam_New);
		}
		break;
case "Numeric":		// WERKT PERFECT !
	if (VeldNaam_Length == "")
		{
  		melding = melding + "- " + MeldingTekst + " (is leeg)" + "\n";

		FoutVeldInstellen(VeldNaam_New);
		}
	else if (CheckNumeric(VeldNaam_Value) == false)
		{
  		melding = melding + "- " + MeldingTekst + " (is niet nummeric)" + "\n";

		FoutVeldInstellen(VeldNaam_New);
		}
	else if (VeldNaam_Length < MinChars)
		{
  		melding = melding + "- " + MeldingTekst + " (te kort)" + "\n";

		FoutVeldInstellen(VeldNaam_New);
		}
	else if (VeldNaam_Length > MaxChars)
		{
  		melding = melding + "- " + MeldingTekst + " (te lang)" + "\n";

		FoutVeldInstellen(VeldNaam_New);
		}
		break;
case "Email":		// WERKT PERFECT !
	if (VeldNaam_Value == "")
		{
  		melding = melding + "- " + MeldingTekst + " (te leeg)" + "\n";

		FoutVeldInstellen(VeldNaam_New);
		}
	else if (CheckEmail(VeldNaam_Value) == false)
		{
  		melding = melding + "- " + MeldingTekst + " (is geen correct e-mail adres)" + "\n";

		FoutVeldInstellen(VeldNaam_New);
		}
		break;
case "Select":	// WERKT PERFECT !
	// document.myForm.mySelect.selectedIndex == 0
	// The first Value of the Pulldown must be EMPTY , if you use this script!
	if (VeldNaam_Value == "")
		{
		melding = melding + "- " + MeldingTekst + " (is geen keuze gemaakt)" + "\n";

		FoutVeldInstellen(VeldNaam_New);
		}
		break;
case "CheckBox":	// WERKT PERFECT !
	var Selectie;
	Selectie = 0;		// aantal geselecteerd in het formulier
	
	if(AantalSelectie == 1 || AantalSelectie == 0)
	{
	FoutVeldNaam = VeldNaam_New;
	
		if (VeldNaam_New.checked == true)
			Selectie = Selectie + 1;	
	}
	else
	{
	FoutVeldNaam = VeldNaam_New[0];

			for ( i = 0; i < AantalSelectie; i++ )		// Ff door alle CheckBox rennen, om te kijken of er wel iemand geCHECKED is.
			{
				if (VeldNaam_New[i].checked == true)
					Selectie = Selectie + 1;	
			}
	}

	if (Selectie == 0)		// Dan is zijn er dus MINDER CheckBox gechecked dan VERPLICHT OPGEGEVEN!! :(
	{
		melding = melding + "- " + MeldingTekst + " (is geen keuze gemaakt)" + "\n";
		if (FoutVeld != true)
			{
			FoutVeld = true
			}
	}
	else if (Selectie < MinChars)		// Dan is zijn er dus MINDER CheckBox gechecked dan VERPLICHT OPGEGEVEN!! :(
	{
		melding = melding + "- " + MeldingTekst + " (u moet minimaal " + MinChars + " items selecteren)" + "\n";
		if (FoutVeld != true)
			{
			FoutVeld = true
			}
	}
	else if (Selectie > MaxChars)		// Dan is zijn er dus MINDER CheckBox gechecked dan VERPLICHT OPGEGEVEN!! :(
	{
		melding = melding + "- " + MeldingTekst + " (u mag maximaal " + MaxChars + " items selecteren)" + "\n";
		if (FoutVeld != true)
			{
			FoutVeld = true
			}
	}

	break;	

case "RadioButton":	// WERKT PERFECT !
	var Selectie;
	Selectie = false;

	for ( i = 0; i < AantalSelectie; i++ )		// Ff door alle RadioButton rennen, om te kijken of er wel iemand geCHECKED is.
	{
		if (VeldNaam_New[i].checked == true)
			Selectie = true;	
	}
	if (Selectie == false)		// Dan is er geen RadioButton gechecked !! :(
	{
		melding = melding + "- " + MeldingTekst + " (is geen keuze gemaakt)" + "\n";
		if (FoutVeld != true)
			{
			FoutVeldNaam = VeldNaam_New[0];
			FoutVeld = true
			}
	}
	break;		
}

}

function FoutVeldInstellen(VeldNaam)
{
	if (FoutVeld != true)
		{
		FoutVeldNaam = VeldNaam;
		FoutVeld = true
		}
}

function CheckEmail(emailad) {
/*
Notes:
'exclude' checks 5 conditions:
a) characters that should not be in the address
b) characters that should not be at the start
c) & d) characters that shouldn't be together
e) there's not more than one '@'
'check' checks there's at least one '@', later followed by at least one '.'
'checkend' checks the address ends with a period followed by 2 or 3 alpha characters
N.B. Javascript 1.2 only works with version 4 browsers and higher.
*/
var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
var check=/@[\w\-]+\./;
var checkend=/\.[a-zA-Z]{2,4}$/;

	if(((emailad.search(exclude) != -1)||(emailad.search(check)) == -1)||(emailad.search(checkend) == -1)){
		return false;
		//alert("Incorrect email address!");
	}
	else {
		return true;
		//alert("Email address format OK!");
	}
}

function CheckNumeric(Waarde)
 {
  //nr1=document.isn.nr.value;
  nr1=Waarde;
  flg=0;
  str="";
  spc=""
  arw="";
  
  for (var i=0;i<nr1.length;i++)
  	{
	   cmp="0123456789"
	   tst=nr1.substring(i,i+1)
	   if (cmp.indexOf(tst)<0)
	   	{
		    flg++;
		    str+=" "+tst;
		    spc+=tst;
		    arw+="^";
		}
	   else{arw+="_";}
    }
  
  if (flg!=0)
  	{
   		if (spc.indexOf(" ")>-1)
			{
		    str+=" and a space";
		    }
   	//alert(nr1+"\r"+arw+"\rI'm sorry. This entry must be a number. I found " +flg+" unacceptable: "+str+".");
   	return false;
    }
  else
  	return true;
}

function DisableForm(theform)
{
	if (document.all || document.getElementById)
		{
			for (i = 0; i < theform.length; i++)
				{
				var tempobj = theform.elements[i];
				if (tempobj.type.toLowerCase() == "submit")
					{
					tempobj.value = "  Sending...  ";
					tempobj.disabled = true;
					}
				if (tempobj.type.toLowerCase() == "reset")
				tempobj.disabled = true;
				}
		//setTimeout('alert("Your form would have been submitted, but this is just a demo.  Notice how the submit and reset buttons were disabled upon submission.")', 2000);
		}
	else
		{
		//alert("Your form would have been submitted, but this is just a demo.  But, since you're not using IE 4+ or NS 6, the submit button was not disabled on form submission.");
	   }
}

function PlaceFocus()
// Places the focus on the first editable field in a form on any web page. Efficient! 
{
		if (document.forms.length > 0)
			{
			var field = document.forms[0];
			for (i = 0; i < field.length; i++)
				{
				if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s"))
					{
					document.forms[0].elements[i].focus();
					break;
			         }
			    }
		   }
}

//-->

