$(document).ready(function(){
  $("#gonder").click(function () {

    var error = "";
    var info = $('#sonuc');
    var isim = $.trim($("#isim").val());
    var soyisim = $.trim($("#soyisim").val());
    var sinavNo = $("#sinavNo").val();

    if ((isim == "") && (soyisim == "")) {
      error = "Lütfen isminizi veya soyisminizi giriniz.\n";
    } else if ((isim.length < 2) && (soyisim.length < 2)) {
      error = "İsminiz ve soyisminiz 2 karakterden küçük olamaz.\n";
    }
    
    if (sinavNo == 0) {
      error += "Lütfen sınav numarasını seçiniz.";
    }
    
    if (error == "") {
      info.html('<img src="images/ajax-loader.gif" height="16" width="16" /> yükleniyor...');

      $.ajax({
    	type: 'POST',
    	encoding: 'UTF-8',
    	data: "value1=" + encodeURIComponent(sinavNo) + "&value2=" + encodeURIComponent(soyisim) + "&value3=" + encodeURIComponent(isim),
        url: '/sonuclar/sonuc.php',
        success: function (msg) {
          info.html(msg);
        },
        error: function () {
          info.html("Bir hata ile karşılaşıldı. Lütfen tekrar deneyiniz.1");
        }
      });
    } else {
      alert(error);
    }


  });  
});

function sonucGetir(e, id) {
  cancelEvent(e);
  stopEvent(e);
  var ogr = ($("#" + id).text()).split(' ');
  var sinavNo =  ($("#" + id).attr("href")).split('#');
  var info = $('#sonuc');

  $.ajax({
    	type: 'POST',
    	encoding: 'UTF-8',
    	data: "value1=" + encodeURIComponent(sinavNo[1]) + "&value2=" + encodeURIComponent(ogr[0]) + "&value3=" + encodeURIComponent(ogr[1]),
        url: '/sonuclar/sonuc.php',
        success: function (msg) {
          info.html(msg);
        },
        error: function () {
          info.html("Bir hata ile karşılaşıldı. Lütfen tekrar deneyiniz.2");
        }
  });
}
    
function cancelEvent(e) {
  if (!e) e = window.event;
  if (e.preventDefault) {
      e.preventDefault();
  } else {
      e.returnValue = false;
  }
}

function stopEvent(e) {
  if (!e) e = window.event;
  if (e.stopPropagation) {
      e.stopPropagation();
  } else {
      e.cancelBubble = true;
  }
}