var AutoComplateTimer = "";

function AutoComplate (word)
{
	clearTimeout(AutoComplateTimer);
	
	var url = "auto_complate.php";
	var pars = "word="+word;
	var myAjax = new Ajax.Request( url, {method: 'post', postBody: pars, onComplete: AutoComplateTmm} );
}

function AutoComplateTmm (cevap,baslik)
{
	clearTimeout(AutoComplateTimer);
	
	veri = cevap.responseXML.documentElement;
	$('autoComplate').innerHTML = null;
	
	if(veri.firstChild.getAttribute("durum") == "ok")
	{
		var kullanicilar = veri.getElementsByTagName('item');
		
		for (k=0;k<kullanicilar.length;k++)
		{
			var Link = document.createElement('a');
			
			Link.href = "javascript:AddUser ("+kullanicilar[k].getAttribute("id")+",'"+kullanicilar[k].getAttribute("text")+"')";
			Link.className = "baslik-link";
			Link.style.display = "block";
			Link.style.marginBottom = "3px"
			Link.innerHTML = kullanicilar[k].getAttribute("text");
			
			$('autoComplate').appendChild(Link);
		}
	}else{
	}
	
	$('autoComplate').style.display = 'block';
	
	AutoComplateTimer = setTimeout("CloseAutoComplate()",7000);
}

function CloseAutoComplate ()
{
	$('autoComplate').style.display = 'none';
	clearTimeout(AutoComplateTimer);
}

function AddUser (id,text)
{
	var table = document.createElement("table");
	var row = document.createElement("tr");
	var cell_1 = document.createElement("td");
	var cell_2 = document.createElement("td");
	
	cell_1.width = "166";
	cell_1.innerHTML = text;
	
	cell_2.width = "34";
	cell_2.align = "center";
	cell_2.style.backgroundColor = "#FF0000";
	cell_2.style.color = "#FFFFFF";
	cell_2.style.fontWeight = "Bold";
	cell_2.innerHTML = '<a id="item'+id+'" style="color:#FFFFFF; text-decoration:none;" href="javascript:RemoveUser('+id+',\'item'+id+'\');">SIL</a>';
	
	row.appendChild(cell_1);
	row.appendChild(cell_2);
	
	table.width = "200";
	table.border = "0";
	table.align = "center";
	table.cellpadding = "0";
	table.cellspacing = "0";
	
	table.appendChild(row);
	
	$('iliskilikullanicilar').appendChild(table);

	$('users').value += id+":";
	$('autoComplate').style.display = 'none';
	$('userSearch').value = '';
	
	clearTimeout(AutoComplateTimer);
}

function RemoveUser (id,itemx)
{
	itemxObj = document.getElementById(itemx);
	itemxObj.parentNode.parentNode.parentNode.parentNode.removeChild(itemxObj.parentNode.parentNode.parentNode);
	$('users').value = $('users').value.replace(id+":", "");
}

function FiyatKontrol(sID,sFiyat)
{
		var url = "ozelsatis_tutarkontrol.php";
		var pars = "sID="+sID+"&sFiyat="+sFiyat;
		var myAjax = new Ajax.Request( url, {method: 'post', postBody: pars, onComplete: FiyatKontrolTamam} );
}

function FiyatKontrolTamam(cevap, baslik)
{
	veri = cevap.responseXML.documentElement;

	var tutar = veri.getElementsByTagName('fiyat');
	$('kalantutar').innerHTML = tutar[0].getAttribute("tutar");
	
	if(veri.firstChild.getAttribute("durum") != "ok")
	{
		if (veri.firstChild.getAttribute("tutar") != "")
			$('fiyat').value = veri.firstChild.getAttribute("tutar");
			
		var hata = veri.getElementsByTagName('hata');
		alert(hata[0].getAttribute("mesaj"));
	}

}

function SatisGuncelle(hashCode)
{
	if (hashCode != null)
	{
		var url = "ozelgoster.php";
		var pars = "hash="+hashCode;
		var myAjax = new Ajax.Request( url, {method: 'post', postBody: pars, onComplete: SatisGuncelleTamam} );
	}
}

function SatisGuncelleTamam(cevap, baslik)
{
	veri = cevap.responseXML.documentElement;
	if(veri.firstChild.getAttribute("durum") != "ok")
	{
		var urun = veri.getElementsByTagName('urun');
		$('satis-isim').innerHTML = urun[0].getAttribute("adi");
		$('satis-fiyat').innerHTML = urun[0].getAttribute("fiyat");

		if (urun[0].getAttribute("satis") < 1)
		{
			$('satis-link').href = 'https://www.estetikinternational.com/ozel-satis.html?hash='+urun[0].getAttribute("hash");
			$('satis-img').src = '/images/simdial.gif';
		}else{
			$('satis-link').href = '#';
			$('satis-img').src = '/images/satildi.gif';
		}
		setTimeout("SatisGuncelle('"+urun[0].getAttribute("hash")+"')",3000);
	}else{
		if (veri.firstChild.getAttribute("satis") < 1)
		{
			$('satis-link').href = 'https://www.estetikinternational.com/ozel-satis.html?hash='+veri.firstChild.getAttribute("eskihash");
			$('satis-img').src = '/images/simdial.gif';
		}else{
			$('satis-link').href = '#';
			$('satis-img').src = '/images/satildi.gif';
		}
		
		setTimeout("SatisGuncelle('"+veri.firstChild.getAttribute("eskihash")+"')",3000);
	}
}


function fotobuyuk(fotoid)
{
	window.open("/popup.php?ex=fotobuyuk&fotoid="+fotoid,"foto"+fotoid,"top=10,left=10,width=200,height=200,buttons=no,scrollbars=yes,location=no,menubar=no,resizable=yes,status=no,directories=no,toolbar=no")
}

function NewWindow(page,top,left,width,height,buttons,scrollbars,location,menubar,resizable,status,directories,toolbar)
{
	window.open(page+",top="+top+",left="+left+",width="+width+",height="+height+",buttons="+buttons+",scrollbars="+scrollbars+",location="+location+",menubar="+menubar+",resizable="+resizable+",status="+status+",directories="+directories+",toolbar="+toolbar)
}

function eminMisin(adres)
{
	if(window.confirm('Devam etmek istediginize emin misiniz?'))
	{
		self.location = adres;
	}
}

var menuzaman;
function altmenuOn(no)
{
	clearTimeout(menuzaman);
	altkapat(no);
	if($('#altmenu'+no).length>0)
	{
		$('#altmenu'+no).fadeIn();
	}
}

function altmenuOff(no)
{
	menuzaman = window.setTimeout("altkapat(0)", 500);
}


function altkapat(no)
{
	
	for(i=1; i<=9; i++)
	{
		if(i!=no)
		{
			if($('#altmenu'+i).length>0)
			{
				$('#altmenu'+i).fadeOut();
			}
		}
	}
}

function ajax(data, method, url, divid){
document.getElementById(divid).innerHTML='Parça isleniyor...';
var page_request = false
if (window.XMLHttpRequest)
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
page_request.onreadystatechange=function(){
loadpage(page_request, divid)
}
if (method == 'GET') {var url = url +'?'+ data}
page_request.open(method, url, true)
page_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
page_request.send(data)
	return page_request
}

function loadpage(page_request, divid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)){
	if (page_request.responseText == "ok" || page_request.responseText == "complate")
		alert("Parça basariyla eklendi");
	else if(page_request.responseText == "error")
		alert("Puzzle oynamak için üye girisi yapmalisiniz!");
	else
		alert("Parça Eklenemedi");
	
	if (page_request.responseText == "complate")
		window.location = "/tebrikler-tamamladiniz.html";
	else if (page_request.responseText == "error")
		window.location = "/uye-giris.html";
	else
		window.location = window.location;
}}

function ackapa(divid)
{
	if ($(divid).style.display == 'none')
		$(divid).style.display = 'block';
	else
		$(divid).style.display = 'none';
}

onConnected = function() {

	$("#fb-uyegiris").html('<div id="uyeLoad"><img src="/images/load.gif" alt="Yükleniyor..." />Oturum açılıyor...</div>');
	$("#fb-uyegiris").load("/uyegiris_bolumu.php",null,uyegirisYuklendi);

}
onNotConnected = function() {

	$("#fb-uyegiris").html('<div id="uyeLoad"><img src="/images/load.gif" alt="Yükleniyor..." /></div>');
	$("#fb-uyegiris").load("/uyegiris_bolumu.php",null,uyegirisYuklendi);

}

function uyegirisYuklendi() { FB.XFBML.Host.parseDomTree(); }


function yayinla_donen(post_id, exception) {

	// alert(post_id+"-"+exception+"-"+yayinTip+"-"+yayinID);

	if ( post_id !== "null" ) {
		
		$.post("/publish_ekle.php", { Action: "PublishAdd", PUBLISH_ID:post_id, PUBLISH_BOLUM:yayinTip, PUBLISH_BOLUM_ID:yayinID },
		function(data){

			if (data.status=="OK") { alert("Bu içeriği FaceBook üzerinde paylaştığınız için, "+data.puan+" Puan kazandın.\nDaha çok yorumu profilinde paylaş, daha çok puan kazan."); }
			else { alert(data.status); }
			
		},"json");
	
	}
	
}

function yayinla(Mesaj, attachment, tip, icerikid, action_link) {

	FB.Connect.showPermissionDialog("publish_stream", function(result){

		if (result=="publish_stream") {
		
			yayinTip = tip;
			yayinID = icerikid;
			FB.Connect.streamPublish(Mesaj, attachment, action_link, null, '', yayinla_donen);
		
		} else { return; }
		
	});

}
