$().ready(function() {
$("#nereden").autocomplete("http://www.rekorkurye.com/autocomplete.php", {
		width: 150,
		selectFirst: true,
		formatItem: function(data, i, max) {
			return  data[0];
		}
		
		
	}); 
	
	$("#nereden").result(function(event, data, formatted) {
		if (data){
			
			$('#git').val(data[1]);
			
			
		}
	});
	$("#nereye").autocomplete("http://www.rekorkurye.com/autocomplete.php", {
		width: 150,
		selectFirst: true,
		formatItem: function(data, i, max) {
			return  data[0];
		}
		
		
	}); 
	
	$("#nereye").result(function(event, data, formatted) {
		if (data){
			
		$('#al').val(data[1]);
		var form = $("#hesapla_formu").serialize();  
		
		$.ajax({
				type: "POST",
				url: "http://www.rekorkurye.com/autocomplete.php",
				data: form,
					
				success: function(cevap) {
					$("#fiyat_ogren").html(cevap);
						
				}
				
			});
			
			
		}
	});
	$("#gonder").click(function() {
		var email = $("#mailadres").val();
		if($("#isim").val()=='' || $("#isim").val().length < 3) {alert("Lütfen Isminizi Yaziniz"); $("#isim").focus(); return false;}
		if(email=='' || email.length < 3) {alert("Lütfen e-mail Adresinizi Yazınız"); $("#mailadres").focus();  return false;}
		if(isValidEmailAddress(email) == false)	{alert("Lütfen e-mail Adresinizi Doğru Yazınız"); $("#mailadres").focus();  return false}
		if($("#telefon").val()=='' || $("#telefon").val().length < 7) {alert("Lütfen Telefon Numaranizi Yaziniz"); $("#telefon").focus();  return false;}
		var form = $("#forms").serialize();
		
		$("#form_area").ajaxStart(function(){
			$(this).html('<img src="http://www.rekorkurye.com/_files/images/loading.gif" />');
		});
		
		$.post('../autocomplete.php',form, function(data) {
			$("#form_area").html(data);
		});


		
	});
});



function isValidEmailAddress(emailAddress) {
 		var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
 		return pattern.test(emailAddress);
	}

