 function validateEmail(addr,man,db) 
	{
	if (addr == '' && man) 
	{
	  if (db) alert('Please enter a valid email address');
	  return false;
	}
		                                
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
		                                
	for (i=0; i<invalidChars.length; i++) 
	{
	  if (addr.indexOf(invalidChars.charAt(i),0) > -1) 
	  {
	    if (db) alert('email address contains invalid characters');
	      return false;
	  }
	}
		                                
	for (i=0; i<addr.length; i++) 
	{
	  if (addr.charCodeAt(i)>127) 
	  {
	    if (db) alert("email address contains non ascii characters.");
	      return false;
	  }
	}

	var atPos = addr.indexOf('@',0);
		                                
	if (atPos == -1) 
	{
	  if (db) alert('email address must contain an @');
	    return false;
	}
	if (atPos == 0) 
	{
	  if (db) alert('email address must not start with @');
	    return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) 
	{
	  if (db) alert('email address must contain only one @');
	    return false;
	}

	if (addr.indexOf('.', atPos) == -1) 
	{
	  if (db) alert('email address must contain a period in the domain name');
	    return false;
	}
	if (addr.indexOf('@.',0) != -1) 
	{
	  if (db) alert('period must not immediately follow @ in email address');
	    return false;
	}
	if (addr.indexOf('.@',0) != -1)
	{
	  if (db) alert('period must not immediately precede @ in email address');
	    return false;
	}
	if (addr.indexOf('..',0) != -1) 
	{
	  if (db) alert('two periods must not be adjacent in email address');
	    return false;
	}

	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') 
	{
	  if (db) alert('invalid primary domain in email address');
	    return false;
	}
	return true;
	} 

function validatefriendform()
{
    var error = '';
    
    if (document.sendtoafriendform.securitycheck.value == ''){
	    error = 'Please enter the security code into the box';
	    document.getElementById('securitycheck').className='inputFieldsError';
	    document.sendtoafriendform.securitycheck.focus();
    }
    else
    {
	    document.getElementById('securitycheck').className='inputFields';
    }
    
    if (!validateEmail(document.sendtoafriendform.friendsemail.value,1,0)){
		error = 'Please enter a valid email address for your friend';
		document.getElementById('friendsemail').className='inputFieldsError';
		document.sendtoafriendform.friendsemail.focus();
	}
	else
	{
		document.getElementById('friendsemail').className='inputFields';
	}
    
	if (document.sendtoafriendform.friendsname.value == ''){
		error = 'Please enter your friend\'s name';
		document.getElementById('friendsname').className='inputFieldsError';
		document.sendtoafriendform.friendsname.focus();
	}
	else
	{
		document.getElementById('friendsname').className='inputFields';
	}
    
    if (!validateEmail(document.sendtoafriendform.youremail.value,1,0)){
		error = 'Please enter a valid email address';
		document.getElementById('youremail').className='inputFieldsError';
		document.sendtoafriendform.youremail.focus();
	}
	else
	{
		document.getElementById('youremail').className='inputFields';
	}
	
	if (document.sendtoafriendform.yourname.value == ''){
		error = 'Please enter your name';
		document.getElementById('yourname').className='inputFieldsError';
		document.sendtoafriendform.yourname.focus();
	}
	else
	{
		document.getElementById('yourname').className='inputFields';
	}	
    
	if (error == '')
	{
        return true;
	}
	else
	{
		alert(error);
		return false;
	}
}


