function form_onay()
{
	var hata = false; 
	var itemm;
	var mesaj="";
	var kayitsirasi=0; var radioGroupName;
	var radiobutonlar = new Array (); 
	var elementler = document.IletisimForm.getElementsByTagName('input');
	var textarea_elementler = document.IletisimForm.getElementsByTagName('textarea');
	var select_elementler = document.IletisimForm.getElementsByTagName('select');
	
	for(var i=0, itemm; itemm=select_elementler.item(i++); )
	{
		if(itemm.value.length<1)
		{
			hata = true;
			mesaj += "<li>" + itemm.name + " Lütfen Seçiniz.</li>";
		}
	}
	
	for(var i=0, itemm; itemm=textarea_elementler.item(i++); )
	{
		if(itemm.value.length<1)
		{
			hata = true;
			mesaj += "<li>" + itemm.name + " Alanını Boş Bırakılamaz.</li>";	
		}
	}
	
	for(var i=0, itemm; itemm=elementler.item(i++); )
	{
		if (itemm.getAttribute('type') == "text")
		{
			if(itemm.value=="" && itemm.name!="E-Posta")
			{
				hata = true;
				mesaj += "<li>" + itemm.name + " Alanı Boş Bırakılamaz.</li>";	
			}
		}
		
		if(itemm.getAttribute('type') == "radio")
		{	
			if(!(contains(radiobutonlar,itemm.name)))
			{
				radiobutonlar[kayitsirasi]= itemm.name;
				kayitsirasi++;	
			}
		}

		if(itemm.name=="E-Posta" && !(e_posta_uyumu(itemm.value)))
		{
			hata = true;
			mesaj += "<li>" + itemm.name + " Adresi Geçersiz. Lütfen E-Posta Adresinizi Kontrol Ediniz.</li>";	
		}
		
	}
	
	 for (var i=0; i<radiobutonlar.length; i++)
	 {
		radioGroupName = radiobutonlar[i];
		for(var j=0, itemm; itemm=elementler.item(j++); )
		{
			if (itemm.type == 'radio' && itemm.name == radioGroupName && itemm.checked)
			{
				radiobutonlar[i] = "true" + radiobutonlar[i];	
			}
		}
	 }
	 
	 for (var i=0; i<radiobutonlar.length; i++)
	 {
		 if(!(strStartsWith(radiobutonlar[i],"true")))
		 {
			hata = true;
			mesaj += "<li>" + radiobutonlar[i] + " Herhangi birini Seçmelisiniz</li>";	
		 }
	 }
	
	if(hata==true)
	{
		document.getElementById("hata").style.visibility = "visible";
		document.getElementById("hataa").innerHTML= mesaj;
				
		for(var i=0, itemm; itemm=elementler.item(i++); )
		{
			if (itemm.getAttribute('type') == "text")
			{
				itemm.onkeyup = new Function("form_onay()");
			}
		
			if(itemm.getAttribute('type') == "radio")
			{
				itemm.onclick = new Function("form_onay()");	
			}
		}
		
		for(var i=0, itemm; itemm=textarea_elementler.item(i++); )
		{
			itemm.onkeyup = new Function("form_onay()");
		}
		
		for(var i=0, itemm; itemm=select_elementler.item(i++); )
		{
			itemm.onclick = new Function("form_onay()");
		}
		document.getElementById("gonder").disabled=true;
		return false;
	}
	else
	{
		document.getElementById("hata").style.visibility = "hidden";
		document.getElementById("gonder").disabled=false;
		return true;
	}
}

function strStartsWith(str, prefix) {
    return str.indexOf(prefix) === 0;
}


function e_posta_uyumu(e_posta)
{
	var filtrele = /^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filtrele.test(e_posta)) 
	{
        return true;
    }
    else 
	{
        return false;
    }
}

function contains(a, obj) {
  var i = a.length;
  while (i--) {
    if (a[i] === obj) {
      return true;
    }
  }
  return false;
}

function form_gonder()
	{
		if(form_onay())
		{
			var q = $.post("../gonder.php", $("#IletisimForm").serialize(), function(data) {
        		if (data.substr(0, 1) == "1") 
				{
					alert("Mesajınız Alınmıştır. Size En Kısa Sürede Cevap Verilecektir. Teşekkür Ederiz.");
		    		document.getElementById("gonder").disabled=true;
		   			document.getElementById("IletisimForm").reset();
					window.location.reload();
        		}
       		 	else 
				{
            		alert('Hata!!! Lütfen Resimde Gördünüz Karaktarleri Yanındaki Kutucuğa Giriniz.');
        		}
    	});		
		}
	}

	
	
