 $(document).ready(function(){
	$("#sendmail").click(function(){
		var valid = '';
		var isr = ' is required.';
		var name = $("#name").val();
		var phone= $("#phone").val();
		var mail = $("#mail").val();
		var mainservice = $("#mainservice").val();
		var servicetype = $("#servicetype").val();
		var text = $("#text").val();
		if (name.length<1) {
			valid += '<br />Name'+isr;
		}
		if (!mail.match(/^([a-z0-9._-]+@[a-z0-9._-]+\.[a-z]{2,4}$)/i)) {
			valid += '<br />A valid Email'+isr;
		}
		if (phone.length<1) {
			valid += '<br />Phone'+isr;
		}
		else if (!phone.match(/^[0-9\-\+]+$/i)) {
			valid += '<br />Number Only';
		}
		if (!$('#mainservice').val()){
			valid += '<br />Select a Service';
		}
		if (!$('#servicetype').val()) {
			valid += '<br />Choose type or amount';
		}

		if (text.length<1) {
			valid += '<br />Comment'+isr;
		}
		if (valid!='') {
			$("#response").fadeIn("slow");
			$("#response").html("Error:"+valid);
		}
		else {
			var datastr ='name=' + name + '&mail=' + mail + '&mainservice=' + mainservice + '&servicetype=' + servicetype  +'&phone=' + phone + '&text=' + text;
			$("#response").css("display", "block");
			$("#response").html("Sending message .... ");
			$("#response").fadeIn("slow");
			setTimeout("send('"+datastr+"')",2000);
		}
		return false;
	});
});
	//  Clear form Function add from http://www.learningjquery.com/2007/08/clearing-form-data
		$.fn.clearForm = function() {
		  return this.each(function() {
		    var type = this.type, tag = this.tagName.toLowerCase();
		    if (tag == 'form')
		      return $(':input',this).clearForm();
		    if (type == 'text' || type == 'password' || tag == 'textarea')
		      this.value = '';
		    else if (type == 'checkbox' || type == 'radio')
		      this.checked = false;
		    else if (tag == 'select')
		      this.selectedIndex = -1;
		  });
		};
function send(datastr){
	
	$.ajax({	
		type: "POST",
		url: "submit_quote.php",
		data: datastr,
		cache: false,
		
		success: function(html){
			
							$("#response").fadeIn("slow");
							$("#response").html(html);
							setTimeout('$("#response").fadeOut("slow")',2000);
							$('#quoteform').clearForm()
							
		
	}
	
	
	});
	
}

