//      Author: Iain Bell
//   Copyright: (c)2003 EON Visual Media Ltd
//     Project: Chartpath Web Site
//     Created: 2003-05-14
//       RCSId: $Id: ContactCheck.js,v 1.1 2003/05/20 12:00:32 itb Exp $

function EON_ValidatePhoneNumber(phoneNumber) {
    if (phoneNumber == "") {
	return false;
    }

    // Because we don't know for sure how people will type in a phone number
    // all over the world, just make sure that there is a digit in there
    // somewhere.
    return /.*[0-9].*/.test(phoneNumber);
}

function EON_ValidateEmailAddress(emailAddress) {
    if (emailAddress == "") {
	return false;
    }

    // Because email addresses can vary so much, just check that it matches:
    // something@anything.anythingelse
    return /^.+@.+\..+$/.test(emailAddress);
}

function EON_ContactCheck(formName)
{
    if (document.forms[formName].Name.value == "") {
	alert("You need to fill in the 'Name' field.");

	return false;
    } else if (!EON_ValidateEmailAddress(document.forms[formName].Email.value)
	       &&
	       !EON_ValidatePhoneNumber(document.forms[formName].Phone.value)) {
	    alert("You need to provide either a valid phone number or email address.");

	    return false;
    }
    
    return true;
}
