function check_and_submit_en(theForm)
{
 var why = "";

 why += checkString(theForm.firstname.value,"First Name");
 why += checkString(theForm.lastname.value,"Last Name");
 why += checkString(theForm.company.value,"Organization");
 why += checkString(theForm.dept.value,"Deparment");
 why += checkString(theForm.position.value,"Position");
 

 why += checkString(theForm.streetno.value,"Street/Number");
 /*why += checkZipCode(theForm.zip.value,"Post Code");*/
 why += checkString(theForm.city.value,"City");

 why += checkEmail(theForm.email.value);
 why += checkPhone(theForm.phone.value,"Phone");
 why += checkFax(theForm.fax.value, "Fax");
 

 if (why != "") {
 alert(why);
 return false;
 }
 theForm.submit();
}

/*---------------------------------------------------------------------*/

function checkZipCode(strng, field)
{

    var error = "";
    if (strng == "")
    {
         error = "The field '"+field+"' is required.\n";
    }
    else{

	// Check for correct zip code
         reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
         if (!reZip.test(strng)) {
             error = "The field "+field+" is not valid.\n";
         }	
    }
    return error
}
/*---------------------------------------------------------------------*/

function checkString (strng, field)
{
 var error = "";
 if (strng == "")
 {
 error = "The field '"+field+"' is required.\n";
 }

 /*var illegalChars = /\W/;
 // allow only letters, numbers, and underscores
 if (illegalChars.test(strng))
 {
 error = "The field "+field+" contains illegal characters.\n";
 }*/

 return error
}

/*---------------------------------------------------------------------*/

function checkEmail(strng)
{
 var error = "";
 var emailFilter=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
 if (!(emailFilter.test(strng)))
 {
 error = "Please enter a valid email address.\n";
 }
 var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
 if (strng.match(illegalChars))
 {
 error = "The email address contains illegal characters.\n";
 }
 if (strng == "")
 {
 error = "The email is required.\n";
 }
 return error
}

/*---------------------------------------------------------------------*/

function checkPhone(strng,field)
{
 var error = "";
 var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
//strip out acceptable non-numeric characters
 if (isNaN(parseInt(stripped)))
 {
 error = "The "+field+" contains illegal characters.\n";
 }
 if (stripped.length<10)
 {
 error = "The phone needs to be at least 10 digits long.\n";
 }
 return error
}

/*---------------------------------------------------------------------*/

function checkFax(strng,field)
{
  var error = "";
  var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
  //strip out acceptable non-numeric characters
  if (isNaN(parseInt(stripped)) && stripped.length>0)
  {
       error = "The "+field+" contains illegal characters.\n";
  }
  return error
}
 

/*---------------------------------------------------------------------*/
/*---------------------------------------------------------------------*/
function checkDropdown(choice,field) {
 var error = "";
 if ((choice == 0 && field == "organization type") || (choice == -1 && field == "research interest")) {
 error = "You didn't choose an option from the " + field + " list.\n";
 }
return error;
}

function check_position()
{
 s = document.getElementById('member_position_id')
 if (s.options[s.options.length-1].selected)
 document.getElementById('member_position_other').disabled = false
 else
 document.getElementById('member_position_other').disabled = true

}

function check_country()
{
 s = document.getElementById('member_country_id')
 if (s.options[s.options.length-1].selected)
 document.getElementById('member_country_other').disabled = false
 else
 document.getElementById('member_country_other').disabled = true

}

function check_domain()
{
 s = document.getElementById('member_domain_id')
 if (s.options[s.options.length-1].selected)
 document.getElementById('member_domain_other').disabled = false
 else
 document.getElementById('member_domain_other').disabled = true

}
