function konus()
{
	var mesaj = document.getElementById("form").mesaj.value;
	if(mesaj != ''){
		yaz(mesaj);
		ajax( 'botacad.php', mesaj )
	}
	document.getElementById("form").mesaj.value = '';
}

function botacad( mesaj )
{
	document.getElementById("sohbet").innerHTML = document.getElementById("sohbet").innerHTML + "<br/><strong>Botacad:</strong> " + (mesaj);
	alt();
}

function nesne()
{
	var nesne;
	var tarayici = navigator.appName;

	if(tarayici == "Microsoft Internet Explorer")
	{
		nesne = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		nesne = new XMLHttpRequest();
	}
	return nesne;
}

var http = nesne();

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function ajax(sayfa, mesaj)
{
	http.open('get', sayfa + '?mesaj=' + URLEncode(escape(mesaj)));
	http.onreadystatechange = cevap;
	http.send(null);

	function cevap()
	{
		if(http.readyState == 4)
		{
			botacad( http.responseText );
		}
	}
}

function alt()
{
	var sohbet = document.getElementById("sohbet");
	sohbet.scrollTop = sohbet.scrollHeight;
}

function yaz( mesaj )
{
	var sohbet = document.getElementById("sohbet");
	sohbet.innerHTML = sohbet.innerHTML + "<br/><strong>Misafir: </strong><font class='b'>" + mesaj+"</font>";
	alt()
}

function cekle ()
{
	document.getElementById("cevaplar").innerHTML =   document.getElementById("cevaplar").innerHTML + '<textarea name="cevap[]" cols="45"></textarea><br/>'
}

function sil (id)
{
	if(confirm('Silmek istedigize emin misiniz?')){
		window.location.href = '/duzenle.php?sil&id='+id
	}
}

function sekle ()
{
	document.getElementById("sorular").innerHTML =   document.getElementById("sorular").innerHTML + '<input type="text" size="55" name="soru[]" /><br/>'
}
