function digitsOnly(obj)
{
	obj.value=obj.value.replace(/[^\d]/g,'');
} // digitsOnly

function checkcharityform()
{
	trimall(0);
	
	// Get form values
	organization=document.charityform.organization.value;
	contactname=document.charityform.contactname.value;
	contactphone=document.charityform.contactphone.value;	
	contactemail=document.charityform.contactemail.value;	
	
	// Check organization
	if(organization=="" )
	{
		alert("You must provide the name of your organization.");
		document.charityform.organization.focus();
		return;
	} // if
	
	// Check contact name
	if(contactname=="" )
	{
		alert("You must provide a contact name.");
		document.charityform.contactname.focus();
		return;
	} // if
	
	// Check contact email/phone
	if((contactemail=="" || !checkEmail(contactemail)) && contactphone.length<10)
	{
		alert("You must provide a valid email address or a 10 digit phone number.");
		document.charityform.contactemail.focus();
		return;
	} // if

	document.charityform.submit();
} // checkcharityform

function checkform()
{
	trimall(0);
	
	// Get form values
	name=document.contactform.name.value;
	email=document.contactform.email.value;
	phone=document.contactform.phone.value;
	comment=document.contactform.comment.value;
	
	// Check name
	if(name=="")
	{
		alert("You must provide your name.");
		document.contactform.firstname.focus();
		return;
	}
	
	// Check email
	if(email=="" || !checkEmail(email))
	{
		alert("You must provide a valid email address.");
		document.contactform.email.focus();
		return;
	}

	// Check phone
	if(phone.length!=10)
	{
		alert("You must provide a 10 digit phone number.");
		document.contactform.phone.focus();
		return;
	}
	
	// Submit form
	document.contactform.submit();
} // checkform

function checkregistrationform()
{
	trimall(0);
	
	// Get form values
	firstname=document.contactform.firstname.value;
	lastname=document.contactform.lastname.value;
	address=document.contactform.address1.value;	
	city=document.contactform.city.value;
	zip=document.contactform.zip.value;	
	email=document.contactform.email.value;
	phone=document.contactform.phone.value;
	comment=document.contactform.comment.value;
	expmonth=document.contactform.expmonth.value;
	cc=document.contactform.cc.value;
	//cause=document.contactform.cause.value;
	
	// Check name
	if(firstname=="" || lastname=="")
	{
		alert("You must provide your first and last name.");
		document.contactform.firstname.focus();
		return;
	}
	
	// Check address
	if(address=="" || city=="" || zip=="")
	{
		alert("You must provide your address, city, and zip code.");
		document.contactform.address1.focus();
		return;
	}
	
	// Check email
	if(email=="" || !checkEmail(email))
	{
		alert("You must provide a valid email address.");
		document.contactform.email.focus();
		return;
	}

	// Check phone
	if(phone.length!=10)
	{
		alert("You must provide a 10 digit phone number.");
		document.contactform.phone.focus();
		return;
	}

	// Check comment
	if(comment=="")
	{
		alert("You must provide a comment.");
		document.contactform.comment.focus();
		return;
	}
	
	// Check cc
	if(cc=="")
	{
		str ="You did not provide a credit card number.\n";
		str+="You may proceed with on-line registration but you must call\n";
		str+="to arrange payment of your deposit.\n\n";
		str+="Press 'OK' to submit the form, 'Cancel' to enter the credit card number";
		if(confirm(str))
		{
			document.contactform.submit();
			return;
		}
	} // if
	else if(cc.length<13)
	{
		alert("The credit card number does not appear to be valid");
		document.contactform.cc.focus();
		return;
	} // if
	
	// Check credit card expiration month
	if(expmonth==0)
	{
		alert("You must provide the credit card expiration month.");
		document.contactform.expmonth.focus();
		return;
	}
	
	// Submit form
	document.contactform.submit();
} // checkregistrationform

function checkreferrerform()
{
	trimall(0);
	
	// Get form values
	firstname=document.referrerform.firstname.value;
	lastname=document.referrerform.lastname.value;	
	email=document.referrerform.email.value;
	
	// Check name
	if(firstname=="" || lastname=="")
	{
		alert("You must provide your first and last name.");
		document.referrerform.firstname.focus();
		return;
	}
	
	// Check email
	if(email=="" || !checkEmail(email))
	{
		alert("You must provide a valid email address.");
		document.referrerform.email.focus();
		return;
	}
	
	// Submit form
	document.referrerform.submit();
} // checkreferrerform

function checkvalidateform()
{
	trimall(0);
	
	// Get form values
	code=document.validateform.code.value;
	email=document.validateform.email.value;
	
	
	// Check email
	if(email=="" || !checkEmail(email))
	{
		alert("You must provide a valid email address.");
		document.validateform.email.focus();
		return;
	}

	// Check email
	if(code=="")
	{
		alert("You must provide a code.");
		document.validateform.code.focus();
		return;
	}

	// Submit form
	document.validateform.submit();
} // checkvalidateform


function trim(str)
{
	// Return string created by removing 'whitespace' from both ends of str
	return str.replace(/^[ \t]+|[ \t]+$/g,"");
} // trim

function trimall(fnum)
{
	// Check for missing parameter
	if(fnum==null)
		fnum=0;
		
	// Trims all text boxes on forms[fnum]
	var theForm = document.forms[fnum];
	
   	for(i=0; i<theForm.elements.length; i++)
   	{
   		if(theForm.elements[i].type == "text")
			theForm.elements[i].value=trim(theForm.elements[i].value);   		
   	}
} // trimall

function checkEmail(str)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str))
		return true;
	return false;
} // checkEmail

