// JavaScript Document
$(document).ready(function(){


/*
 * Ajax formları
 */

//giris yap
$('form#girisyap').submit(
	function(){
	
		$(this).hide();
		$('div#hata').hide();
		$('div#bekle').show();
		
		$.ajax({
			type     : 'POST',
			url      : 'action.php',
			dataType : 'json',
			data     : $(this).serialize(),					
			success   : function(veri)
			{
				$('div#bekle').hide();
					
				if(veri.hata === true){
					$('div#hata').show();
					$('form#girisyap').show();
					$('div#hata').html('<img src="inc/images/warning.png" style="vertical-align:middle" /> '+veri.mesaj);
				} else{
					location.href = 'index.php?v=anasayfa';
				}
			}
		});
		
		
	return false;
	}
);

//ödeme bildirimi gönderme
$('form#odemebildirimi').submit(
	function(){
	
		$(this).hide();
		$('div#hata').hide();
		$('div#tamam').hide();
		$('div#bekle').show();
		
		$.ajax({
			type     : 'POST',
			url      : 'action.php',
			dataType : 'json',
			data     : $(this).serialize(),					
			success   : function(veri)
			{
				$('div#bekle').hide();
				
				if(veri.hata === true){
					$('div#hata').show();
					$('form#odemebildirimi').show();
					$('div#hata').html('<img src="inc/images/warning.png" style="vertical-align:middle" /> '+veri.mesaj);
				} else{
					$('div#tamam').show();
					$('form#odemebildirimi').show();
					$('div#tamam').html('<img src="inc/images/accept2.png" style="float:left; margin-right:5px" /> '+veri.mesaj);					
				}
			}
		});
				
	return false;
	}
);

//ödeme yap
$('form#odeme').submit(
	function(){
	
		$(this).hide();
		$('div#hata').hide();
		$('div#bekle').show();
		
		$.ajax({
			type     : 'POST',
			url      : 'action.php',
			dataType : 'json',
			data     : $(this).serialize(),					
			success   : function(veri)
			{
				$('div#bekle').hide();
					
				if(veri.hata === true){
					$('div#hata').show();
					$('form#odeme').show();
					$('div#hata').html('<img src="inc/images/warning.png" style="vertical-align:middle" /> '+veri.mesaj);
				} else{
					location.href = 'index.php?v=odeme_final&siparisno='+veri.siparis_no;
				}
			}
		});
		
		
	return false;
	}
);




});