	function showEmail(name,domain) {
		sep = '@';
		document.write(name+sep+domain);
	}

	function showMailTo(name,domain,clName,lnName) {
		className = '';
		linkName = (lnName>"")?(lnName):(name+"@"+domain);
		if (clName>"") {
			className = 'class="'+clName+'" ';
		}
		document.write('<a '+className);
		document.write('href="');
		document.write('mail');
		document.write('to:');
		showEmail(name, domain);
		document.write('">');
		document.write(linkName);
		document.write('</a>');
	}

	function openWin(url, name, features){
		var newWin = window.open( url, name, features )
	}	

	function imagePopup (url, width, height) {
		var features = 'width='+width+', height='+height+', menubar';
		var newWin = window.open(url, null, features);
	}
	
	function trim(s)
	{
	  return s.replace(/^\s+|\s+$/, '');
	}
	
	function validateEmail(email_address) {
	    var error="";
	    var tfld = trim(email_address.value);                 // value of field with whitespace trimmed off
	    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
	   
	    if (email_address.value == "") {
	        email_address.style.background = '#FFA07A';
	        error = "your email address\n";
	    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
	        email_address.style.background = '#FFA07A';
	        error = "a valid email address.\n";
	    } else if (email_address.value.match(illegalChars)) {
	        email_address.style.background = '#FFA07A';
	        error = " email address contains illegal characters.\n";
	    } else {
	        email_address.style.background = '#f0f0f0';
	    }
	    return error;
	}
	function validateConEmail(contributor_email) {
		    var error="";
		    var tfld = trim(contributor_email.value);                 // value of field with whitespace trimmed off
		    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
		    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
		   
		    if (contributor_email.value == "") {
		        contributor_email.style.background = '#FFA07A';
		        error = "your email address\n";
		    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
		        contributor_email.style.background = '#FFA07A';
		        error = "a valid email address.\n";
		    } else if (contributor_email.value.match(illegalChars)) {
		        contributor_email.style.background = '#FFA07A';
		        error = " email address contains illegal characters.\n";
		    } else {
		        contributor_email.style.background = '#f0f0f0';
		    }
		    return error;
	}
	
	function validateName(name) {
	    var error = "";
	 
	    if (name.value == 0) {
	        name.style.background = '#FFA07A'; 
	        error = "your first name\n"
	    } else {
	       name.style.background = '#f0f0f0';
	    }
	    return error;  
	}
	function validatePhoneNumber(contact_number) 
	{
	   var error="";
	   var stripped = contact_number.value.replace(/[\(\)\.\-\ ]/g, '');     
	   
	     if (contact_number.value == "") {
	     	contact_number.style.background = '#FFA07A';
		error = "your telephone\n";
	     }else if (isNaN(parseInt(stripped))) {
	         contact_number.style.background = '#FFA07A';
	         error =" enter a valid telephone\n"
	     }else if (!(stripped.length == 10)) {
                  error = "The phone number is the wrong length. Make sure you included an area code.\n";
                  contact_number.style.background = '#FFA07A';
                  return false;
             }else{
	     
	         contact_number.style.background = '#f0f0f0';
	     }
	
	return error;
      }
          
	function validateConName(contributor_name) {
		    var error = "";
		 
		    if (contributor_name.value == 0) {
		        contributor_name.style.background = '#FFA07A'; 
		        error = "your first name\n"
		    } else {
		       contributor_name.style.background = '#f0f0f0';
		    }
		    return error;  
	}
	
	function validateTitle(event_title) {
	    var error = "";
		 
	    if (event_title.value == 0) {
	        event_title.style.background = '#FFA07A'; 
	        error = "the event title\n"
	    } else {
	       event_title.style.background = '#f0f0f0';
	    }
	    return error;  
	}
	function validateConTitle(contributor_title) {
		    var error = "";
			 
		    if (contributor_title.value == 0) {
		        contributor_title.style.background = '#FFA07A'; 
		        error = "the contributor's title\n"
		    } else {
		       contributor_title.style.background = '#f0f0f0';
		    }
		    return error;  
	}
	
	 function validateDate(event_start_date) {
	     var error = "";
	 	 
	     if (event_start_date.value == '') {
	         event_start_date.style.background = '#FFA07A'; 
	         error = "the start date\n"
	     } else {
	         event_start_date.style.background = '#f0f0f0';
	     }
	     return error;  
	}
	  function validateEndDate(event_end_date) {
	       var error = "";
	  	 	 
	       if (event_end_date.value == '') {
	           event_end_date.style.background = '#FFA07A'; 
	           error = "the end date\n"
	       } else {
	           event_end_date.style.background = '#f0f0f0';
	       }
	       return error;  
	}
	
		
	function validateSurname(surname) {
	    var error = "";
	 
	    if (surname.value == 0) {
	        surname.style.background = '#FFA07A'; 
	        error = "your surname\n"
	    } else {
	        surname.style.background = '#f0f0f0';
	    }
	    return error;  
	}
	function validateConSurname(contributor_surname) {
		    var error = "";
		 
		    if (contributor_surname.value == 0) {
		        contributor_surname.style.background = '#FFA07A'; 
		        error = "your surname\n"
		    } else {
		        contributor_surname.style.background = '#f0f0f0';
		    }
		    return error;  
	}
	
	function validateOrganisation(organisation_name) {
	    var error = "";
	 
	    if (organisation_name.value == 0) {
	        organisation_name.style.background = '#FFA07A'; 
	        error = "your organisation/institution\n"
	    } else {
	        organisation_name.style.background = '#f0f0f0';
	    }
	    return error;  
	}
	
	
	function validateCountry(country_ref) {
	    var error = "";
	 
	    if (country_ref.selectedIndex == 0) {
	        country_ref.style.background = '#FFA07A'; 
	        error = "your country\n"
	    } else {
	        country_ref.style.background = '#f0f0f0';
	    }
	    return error;  
	}
	
	function validateFormOnSubmit(memberInfo) {
	var reason = "";
	
	  reason += validateName(memberInfo.name);
	  reason += validateSurname(memberInfo.surname);
	  reason += validateEmail(memberInfo.email_address);
	  reason += validateOrganisation(memberInfo.organisation_name);
	  reason += validateCountry(memberInfo.country_ref);
	      
	  if (reason != "") {
	    alert("Please enter/select:\n" + reason);
	    return false;
	  }
	
	  return true;
}

      function validateEventOnSubmit(eventDetails) {
      	  var reason = "";
      	
      	  reason += validateConTitle(eventDetails.contributor_title);
	  reason += validateConName(eventDetails.contributor_name);
	  reason += validateConSurname(eventDetails.contributor_surname);
	  reason += validateConEmail(eventDetails.contributor_email);
      	  reason += validateTitle(eventDetails.event_title);
      	  reason += validateDate(eventDetails.event_start_date);
      	  reason += validateEndDate(eventDetails.event_end_date);
      	  reason += validatePhoneNumber(eventDetails.contact_number);
      	  
      	        	        	      
      	  if (reason != "") {
      	    alert("Please enter/select:\n" + reason);
      	    return false;
      	  }
      	
	  return true;
}