function checkName(veld,melding,minimumlength)
{
var veldnaam=melding;
 
   if ( veld.value != "" && veld.value != " " && veld.value != "  " && veld.value.length >= minimumlength)
    {return true }
   else
    {alert(veldnaam+" is not entered properly.");
     veld.focus();
     veld.select();
     return false}
}//function checkName

function checkEmail(veld,melding,needit)
{
var veldnaam=melding;
var invalidChars = " /:,;"
var emailveldvalid=true;

  if (veld.value == "") {// cannot be empty
    if (needit) 
      {emailveldvalid=false;}
	else
      {emailveldvalid=true;}
	}
  else
  {
    for (i=0; i<invalidChars.length; i++) {// does it contain any invalid characters?
      badChar = invalidChars.charAt(i)
      if (veld.value.indexOf(badChar,0) > -1) {
        emailveldvalid=false;
      }
    }
    atPos = veld.value.indexOf("@",1)	// there must be one "@" symbol
    if (atPos == -1) {
      emailveldvalid=false;
    }
    if (veld.value.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
      emailveldvalid=false;
    }
    periodPos = veld.value.indexOf(".",atPos)
    if (periodPos == -1) {					// and at least one "." after the "@"
      emailveldvalid=false;
    }
    if (periodPos+3 > veld.value.length)	{		// must be at least 2 characters after the "."
      emailveldvalid=false;
    }
  }

   if (emailveldvalid)
    { return true }
   else { alert(veldnaam+" is not entered properly.");
    veld.focus();
    veld.select();
    return false}
}//function checkEmail


function checkCountry(veld,melding)
{
var veldnaam=melding;
var countryvalid=true;

   if (veld.selectedIndex == 0){// Did not select country
     countryvalid=false;}

   if (countryvalid)
    { return true }
   else { alert(veldnaam+" is not selected.");
    veld.focus();
//    veld.select();
    return false}
}//function checkCountry


function downloadDemo(pakket,bestand) {
var defaultloc='http://www.risc-site.nl/downloads/';
var RISCdownloadWindow=window.open("","RISCdownloadWindow","width=500,height=200");
    RISCdownloadWindow.document.open();
    RISCdownloadWindow.document.write('<HTML><HEAD><TITLE>Download '+pakket+'</TITLE></script></HEAD>');
    RISCdownloadWindow.document.write('<BODY bgcolor="#FFFFCC" onLoad="window.location.href=\''+defaultloc+bestand+'\';setTimeout(\'window.close()\',30000);"><font face=arial size=3 color=black><img src="images/topleft.gif" width="111" height="47" VSPACE="0" HSPACE="5" BORDER="0" align="left">Starting download of '+pakket+'.<BR>Please wait...<BR></font>');
    RISCdownloadWindow.document.write('<font face=arial size=2 color=black><BR><BR>Click on <A HREF="'+defaultloc+bestand+'">this link</A> to start the download process manually.</font></BODY></HTML>');
    RISCdownloadWindow.document.close();
    RISCdownloadWindow.focus();
}

function displaybrochure(brochure,bestand) {
var defaultloc='http://www.risc-site.nl/downloads/';
var RISCbrochureWindow=window.open("","RISCbrochureWindow","");
    RISCbrochureWindow.document.open();
    RISCbrochureWindow.document.writeln('<HTML><HEAD><TITLE>Displaying brochure '+brochure+'</TITLE></script></HEAD>');
    RISCbrochureWindow.document.writeln('<frameset rows="40,*" frameborder="NO" border="0" framespacing="0">');
    RISCbrochureWindow.document.writeln('  <frame name="riscstatusFrame" scrolling="NO" noresize src="brochurelink.htm?F='+brochure+'&B='+defaultloc+bestand+'" >');
    RISCbrochureWindow.document.writeln('  <frame name="riscbrochureFrame" src="'+defaultloc+bestand+'">');
    RISCbrochureWindow.document.writeln('<noframes>');
    RISCbrochureWindow.document.writeln('<body bgcolor="#FFFFCC" onLoad="window.location.href=\''+defaultloc+bestand+'\';"><font face=arial size=3 color=black><img src="images/topleft.gif" width="111" height="47" VSPACE="0" HSPACE="5" BORDER="0" align="left">Displaying brochure '+brochure+'.<BR>Please wait a moment....<BR></font>');
    RISCbrochureWindow.document.writeln('<font face=arial size=2 color=black><BR><BR>Click on <A HREF="'+defaultloc+bestand+'">this link</A> to manually display the brochure.</font>');
    RISCbrochureWindow.document.writeln('</body>');
    RISCbrochureWindow.document.writeln('</noframes>');
    RISCbrochureWindow.document.writeln('</frameset>');
    RISCbrochureWindow.document.writeln('</HTML>');
    RISCbrochureWindow.document.close();
    RISCbrochureWindow.focus();
}

function checkFields(formulier,naampakket,naambestand) {
var tmpnaambestand=naambestand;
  formulier.downloadtitle.value=naampakket;
  if (formulier.receivenewslettercheck.checked) {formulier.receivenewsletter.value='Yes';}
  else {formulier.receivenewsletter.value='No';}

  if (checkName(formulier.contactname,"Name",3) ) {
    if (checkEmail(formulier.emailaddress,"E-mail",true)) {
      if (checkCountry(formulier.contactcountry,"Country")) {
				if (tmpnaambestand.indexOf(".pdf") != -1){
				displaybrochure(naampakket,naambestand);}
				else
				{downloadDemo(naampakket,naambestand);}
        formulier.submit();
      }
    }
  }
}//function checkfields
