function ValidateForm() {
	var error = '';
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var name = jQuery.trim($("#ctl00_ctl00_cplMain_cplSubMain_txtToName").val());
	var email = jQuery.trim($("#ctl00_ctl00_cplMain_cplSubMain_txtToEmail").val());
	
	if (name  == '')
		error += "<li>You have not entered your friend's name</li>";
		
	if (email  == '')
		error += "<li>You have not entered your friend's email address</li>";
	else if (!filter.test(email))
		error += "<li>Your friend's email address doesn't appear to be valid</li>";
	
	if (error == '') {
		var friendCount = parseInt($("#ctl00_ctl00_cplMain_cplSubMain_hidFriendCount").val()) + 1;
		
		// add to hidden fields and increment counter
		$("#tblFriends").append("<tr><td style=\"width:20px;\"><input type=\"checkbox\" name=\"chk" + friendCount + "\" checked=\"true\" value=\"send\" /></td><td><input type=\"hidden\" name=\"UserName" + friendCount  + "\" value=\"" + name.replace(/"/g, "&#34;") + "\" /><input type=\"hidden\" name=\"UserEmail" + friendCount  + "\" value=\"" + email.replace(/"/g, "&#34;") + "\" />" + name + "</td><td>" + email + "</td></tr>");
		$("div#ctl00_ctl00_cplMain_cplSubMain_divFriends").show();
		$('.stripeMe tr:odd').addClass('tbl_row_alt');
		
		$("div#pnlError").hide();

		// Increment friend count
		$("#ctl00_ctl00_cplMain_cplSubMain_hidFriendCount").val(friendCount);
		
		// clear textboxes
		$("#ctl00_ctl00_cplMain_cplSubMain_txtToName").val('');
		$("#ctl00_ctl00_cplMain_cplSubMain_txtToEmail").val('');
	} else {
		$("div#pnlError").html('<ul>' + error + '</ul>');
		$("div#pnlError").show();
	}
}

$(document).ready(function() {
	$("#btnAddFriend").click(function() {
		ValidateForm();
	})
});

