//Function valid(form), BEGIN
function valid(form) {

if ((document.getElementById("last").value=="") || (document.getElementById("first").value=="") || (document.getElementById("birth").value=="")) {
      alert("You have to enter your last name, first name, and year of birth");
      return false;
      }
if ((document.getElementById("sex").value=="") || (document.getElementById("marital_status").value=="") || (document.getElementById("children").value=="")) {
      alert("You have to precise your sex, marital status and if you have children");
      return false;
      }
if ((document.getElementById("street").value=="") || (document.getElementById("city").value=="") || (document.getElementById("country").value=="")) {
      alert("You have to enter your address (street, city and country)");
      return false;
      }
if ((document.getElementById("email").value=="") || (document.getElementById("phone").value=="")) {
      alert("You have to enter your email and phone number");
      return false;
      }
if ((document.getElementById("uni_1").value=="") || (document.getElementById("date_1").value=="")) {
      alert("You have to complete at least one university/college attended and select a year");
      return false;
      }
if ((document.getElementById("degree_1").value=="") || (document.getElementById("date_degree_1").value=="")) {
      alert("You have to complete at least one degree obtained and select a year");
      return false;
      }
if (document.getElementById("english").value=="") {
      alert("You have to select your level in English");
      return false;
      }
if (document.getElementById("research_experience").value=="") {
      alert("You have to complete the Research experience section");
      return false;
      }
if (document.getElementById("scientific_interests").value=="") {
      alert("You have to complete the 2 fields in the Scientific interests section");
      return false;
      }
if (document.getElementById("scientific_interests_areas").value=="") {
      alert("You have to complete the 2 fields in the Scientific interests section");
      return false;
      }
	  
// Check if the applicant has ticked exactly 3 checkboxes, Begin  
var allChkbox = document.getElementsByTagName("INPUT");
var cnt;
cnt=0;
for(var y=0;y<allChkbox.length;y++)
{
 if(allChkbox[y].checked == true && allChkbox[y].value == 'keys')
 {
 cnt = cnt + 1 ;
 }
}
if ((cnt < 3) || (cnt > 3))
 {
 alert("You have to select 3 keywords (not more, not less) closest to your interests !");
 return false;
 }
// Check if the applicant has ticked exactly 3 checkboxes, End

} //Function valid(form), End

//Function to count the words and the characters in the fields, Begin
function CountWords (this_field, show_word_count, show_char_count) {
if (show_word_count == null) {
show_word_count = true;
}
if (show_char_count == null) {
show_char_count = false;
}
var char_count = this_field.value.length;
var fullStr = this_field.value + " ";
var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
var word_count = splitString.length -1;
if (fullStr.length <2) {
word_count = 0;
}
if (word_count == 1) {
wordOrWords = " word";
}
else {
wordOrWords = " words";
}
if (char_count == 1) {
charOrChars = " character";
} else {
charOrChars = " characters";
}
if (show_word_count & show_char_count) {
alert ("Word Count:\n" + "    " + word_count + wordOrWords + "\n" + "    " + char_count + charOrChars);
}
else {
if (show_word_count) {
alert ("Word Count:  " + word_count + wordOrWords);
}
else {
if (show_char_count) {
alert ("Character Count:  " + char_count + charOrChars);
      }
   }
}
return word_count;
}
//Function to count the words and characters in the fields, End

