
// form validation
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

function chkMailForm()
{
	var returnValue = false;
	var email = $("#EmailAddress").val();
	var missing = new Array();
	
	$(".required").each(function(n)
	{
		var theId = this.id;
		var theValue = $("#" + this.id).val();
		if (theValue == '')
		{
		missing.push(theId);
		$("label[for='" + this.id + "']").addClass('error');
		}
		else
		{
		$("label[for='" + this.id + "']").removeClass('error');
		}
		
	});
	

	eChk = echeck(email);
	
	if (missing.length > 0)
	{
		var alertMsg = "'" + missing[0] + "' is a required field.";
		alert(alertMsg);
		$("#" + missing[0]).focus();
	}
	else if (!eChk)
	{
		$("label[for='EmailAddress']").addClass('error');
		alert('Not a valid email address.');
		$("#EmailAddress").focus();
	}
	else
	{
		returnValue = true;
	}
	
	return returnValue;
}

	// get the values from the mail form
	function doSendMail()
	{
		name = $("#Name").val();
		email = $("#Email").val();
		message = $("#Message").val();
		$.post('index.php', {fa: 'c.send', name: name, email: email, message: message, submit: 'submit'}, function(returnMsg){
			$("#contactForm").html('<h1>' + returnMsg + '</h1>');
		});
	}
	
	// open the mail form
	function openMail()
	{
	$.post('index.php', {fa: 'c.contact'}, function(strForm) {
	$('#dialog').html(strForm);
	$('#dialog').dialog('open');
	})
	}