var checkit = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
var allValid;

function alphabetonly(checkStr)
{
	allValid=true
	for (i = 0; i < checkStr.length; i++)
	{
		ch1 = checkStr.charAt(i);
		for (j = 0; j < checkit.length; j++)
		if(ch1 == checkit.charAt(j))
			break;
		if (j == checkit.length)
		{
			allValid = false;
			break;
		}
	}
}

var checkthis = "0123456789+-/ ";
var allValid1;

function noalphabet(checkStr)
{
	allValid1=true
	for (i = 0; i < checkStr.length; i++)
	{
		ch1 = checkStr.charAt(i);
		for (j = 0; j < checkthis.length; j++)
		if(ch1 == checkthis.charAt(j))
			break;
		if (j == checkthis.length)
		{
			allValid1 = false;
			break;
		}
	}
}

$(function() {
  $("#find").click(function() {
	// validate and process form		
	var name = $("input#name").val();
	var email = $("input#email").val();
	if (email.indexOf("@") == -1) {
	alert("Please enter a valid email address.");
	$("input#email").focus();
	return false;
	}
	var phone = $("input#phone").val();
	noalphabet(phone);
	if (!allValid1)
	{
	alert("Please enter only numerics for phone number.")
	$("input#phone").focus();
	return false;
	}
	var comments = $("textarea#comments").val();
	var stype = $("input#stype").val();		
	var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&stype=' + stype + '&comments=' + comments;
	//alert (dataString);return false;
		
$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Contact Details Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
