// deze functie controleert de juistheid van het e-mailadres op meerdere punten
function checkEmail(emailAddress) {

var foundAtSymbol = 0;
var foundDot = 0;
var md;

// Go through each character in the email address.
for (var x=0; x<emailAddress.length - 1; x++) {
md = emailAddress.substr(x, 1);

// Is the character an @ symbol?
if (md == '@') foundAtSymbol++;

// Count how many dots there are after the @ symbol.
if (md == '.' && foundAtSymbol == 1) foundDot++;
};

// Is there only one @ symbol, and are there more than one dots?
if (foundDot > 0 && foundAtSymbol == 1) {
return true;
} else {
return false;
};

};

function check_email() {
  var emailadres = document.frmmail.p_email.value;
  if (emailadres =="")
  {
  alert("Vul uw e-mailadres in.");
  document.frmmail.p_email.focus();
  return false;
  } else {
    if (!checkEmail(emailadres))
    {
    alert("Vul een geldig e-mailadres in.");
    document.frmmail.p_email.focus();
	return false;
	} else {
	  document.frmmail.submit();
	}
  }
}
function check_part_active() {
  var emailadres = document.frm.f_email.value;
  var partcode   = document.frm.f_code.value;
  if (emailadres =="")
  {
  alert("Vul uw e-mailadres in.");
  document.frm.f_email.focus();
  } else {
    if (!checkEmail(emailadres))
    {
    alert("Vul een geldig e-mailadres in.");
    document.frm.f_email.focus();
	} 
	else {
	   if (partcode=="") {
	     alert("Vul uw persoonlijke code in.");
	     document.frm.f_code.focus();
	   } else {
	   xmlhttpHandler2("/owa_dima/owa/att_occ_ptr.check_part_active_xml?p_email="+emailadres+"&p_code="+partcode,"part_active");
	   }
	   
	}
  }
}
function xmlhttpResponse(xml,elt) {
 if (elt=="pers_code") {
  try{
    var message = xml.getElementsByTagName('MESSAGE');
    alert(message[0].firstChild.nodeValue);

  } catch (error){
    alert(error);
  }
   
 } else if (elt=="part_active") {
   try{
   var proceed = xml.getElementsByTagName('PROCEED')[0].firstChild.nodeValue;
   if (proceed=="ok") {
     document.frm.submit();
   } else {
     alert("U heeft geen actieve occasions. Klik op de link onder aan de pagina om een occasion te plaatsen.");
   } 
   } catch (error){
     document.frm.submit();
   }
 }

}
