

function validateForm() {
	
	
	var form_name = document.ecardform.realname.value;
	var form_email = document.ecardform.email.value;
	var form_recName = document.ecardform.realnameto.value;
	var form_recEmail = document.ecardform.recipient.value;
	var form_time = document.ecardform.meettime.value;
	if (form_name.length < 1) { 
		erralert(1); 
		return false;
	} else if (form_email.length < 1) { 
		erralert(2);
		return false;
	} else if (form_email.indexOf('@') < 0) { 
		erralert(6);
		return false;
	} else if (form_email.indexOf('@') != form_email.lastIndexOf('@')) { 
		erralert(9); 
		return false;
	} else if (form_recName.length < 1) { 
		erralert(3); 
		return false;
	} else if (form_recEmail.length < 1) { 
		erralert(4); 
		return false;
	} else if (form_recEmail.indexOf('@') < 0) { 
		erralert(7); 
		return false;
	} else if (form_recEmail.indexOf('@') != form_recEmail.lastIndexOf('@')) { 
		erralert(8); 
		return false;
	} else if (form_time.length < 1) { 
		erralert(10); 
		return false;
	} else {
		return true;
	}
	
}

function erralert(x) {
	if (x == 1) { 
		alert("Please fill in your name"); 
		document.ecardform.realname.focus();
	}  else if (x == 2) { 
		alert("Please ensure that you fill in your email address"); 
		document.ecardform.email.focus();
	} else if (x == 3) { 
		alert("Please fill in the name of the person you want to send your e-card to"); 
		document.ecardform.realnameto.focus();
	} else if (x == 4) { 
		alert("Please fill in the email address of the person you are sending your card to"); 
		document.ecardform.recipient.focus();
	} else if (x == 6) { 
		alert("Please ensure that you use the correct email format, e.g. friend@xyz.com"); 
		document.ecardform.email.focus();
	} else if (x == 7) { 
		alert("Please ensure that you use the correct email format, e.g. friend@xyz.com"); 
		document.ecardform.recipient.focus();
	} else if (x == 8) { 
		alert("Please enter only one email address to send your e-card to"); 
		document.ecardform.recipient.focus();
	} else if (x == 9) { 
		alert("Please enter only one email address for yourself"); 
		document.ecardform.email.focus();
	} else if (x == 10) { 
		alert("Please put a time to meet your friend"); 
		document.ecardform.meettime.focus();
	}			
}