var img_indis = 100;

function getAjaxObj(){
	if (window.XMLHttpRequest)
		return new XMLHttpRequest();	  
	else if (window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP");
	else
		return null;
}

function fotoGoster(url, nsn, secenek){
	var tablo = document.createElement("table");
	var tr1 = document.createElement("tr");

	var td1 = document.createElement("td");

	var img= document.createElement("img");
	var chk= document.createElement("input");
	img.setAttribute("src", "../fotolar/kucuk"+url);
	img.setAttribute("alt",url);
	img.style.width="90px";
	
	td1.appendChild(img);
	if(secenek){
		chk.setAttribute("type","radio");
		img.onclick=  function(){fotoSec(img, chk); bFotoYukle(img); }		
	}
	else{
		chk.setAttribute("type","checkbox");
		img.onclick=  function(){fotoSec(img, chk);}
	}
	chk.setAttribute("name","foto[]");
	chk.setAttribute("value",url);
	chk.setAttribute("id","foto_chk" + img_indis);
	td1.appendChild(chk);
	tr1.appendChild(td1);				

	tablo.appendChild(tr1);

	document.getElementById(nsn).appendChild(tablo);
	img_indis++;

}

function videoGoster(url, nsn, secenek){
	var tablo = document.createElement("table");
	var tr1 = document.createElement("tr");

	var td1 = document.createElement("td");

	var img= document.createElement("img");
	var chk= document.createElement("input");
	var rurl;
	rurl = url.substring(0, url.length-4) + ".jpg";

	img.setAttribute("src", "../videolar/"+rurl);
	img.setAttribute("alt",url);
	img.style.width="90px";
	
	td1.appendChild(img);
	if(secenek){
		chk.setAttribute("type","radio");
		img.onclick=  function(){fotoSec(img, chk); bFotoYukle(img); }		
	}
	else{
		chk.setAttribute("type","checkbox");
		img.onclick=  function(){fotoSec(img, chk);}
	}
	chk.setAttribute("name","foto[]");
	chk.setAttribute("value",url);
	chk.setAttribute("id","foto_chk" + img_indis);
	td1.appendChild(chk);
	tr1.appendChild(td1);				

	tablo.appendChild(tr1);

	document.getElementById(nsn).appendChild(tablo);
	img_indis++;

}

function fotoSec(img, indis){
	var c= img.style.borderColor;
	if (c==""){
		img.style.borderColor = "#6c0";
		if( isNaN(Number(indis)) )
			indis.checked="checked"
		else
			document.getElementById("foto_chk"+indis).checked = "checked";
	}
	else {
		img.style.borderColor = "";
		if( isNaN(Number(indis)) )
			indis.checked="";
		else
			document.getElementById("foto_chk"+indis).checked = "";
	}
}

function hedefBul(islem){
	switch(islem){
		case 0: document.getElementById("hedefbulPen").style.display='none'; break;
		case 1: document.getElementById("hedefbulPen").style.display='block'; break;		
	}
}

function haberYukle(haberid, tablo){
	document.frm.haber.value = haberid;
	fotoYukle(haberid, tablo);
	hedefBul(0);
	document.getElementById("f_sec_e").style.display="block";
}

function egitmenYukle(eid){
	document.frm.egitmen_id.value = eid;
	hedefBul(0)
}

function iliskiYukle(iid){
	document.frm.iliski_id.value = iid;
	hedefBul(0)
}

function fotoYukle(hid, tbl){
	var xmlhttp = getAjaxObj();
	var url = "sayfalar/fotobul.php?id=" + hid + "&tablo="+tbl;
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	document.getElementById("foto_ktm").innerHTML="";
	if(xmlhttp.responseText.length > 0){
		var fotolar=xmlhttp.responseText.split("%");
		for(var i=0; i< fotolar.length; i++)
			fotoGoster(fotolar[i],"foto_ktm",1)
		
	}
	else document.getElementById("foto_ktm").innerHTML = "Fotoğraf bulunamadı!";
}

function bFotoYukle(img){
	document.getElementById("b_foto_ktm").style.background= "url(" + img.src.replace("kucuk","")+") top left no-repeat";
	document.getElementById("ust").value= 0
	document.getElementById("sol").value= 0
	document.getElementById("b_foto_ktm").style.display="block";
	document.getElementById("gosterge").style.display="block";
	document.getElementById("f_a_e").style.display="block";
	document.getElementById("foto_url").value= img.src.replace("fotolar/kucuk","")
	document.getElementById("cerceve").onmousedown = basla	
	document.getElementById("cerceve").onmouseup = dur
}

var x, dx, y, dy, sur, tmpx, tmpy;

function basla(e){
	if(!e) e= window.event;
	var d=document.getElementById("cerceve");
	var ust=document.getElementById("ust");
	var sol=document.getElementById("sol");
	
	sur= true;
	x= e.clientX;
	y= e.clientY;
	dx= parseInt(sol.value);
	dy= parseInt(ust.value);
	d.onmousemove = surukle
}

function dur(e){
	if(!e) e= window.event;
	sur= false;
	document.getElementById("cerceve").onmousemove= null;
	dx= tmpx;
	dy= tmpy;
}

function surukle(e){
	if(!e) e= window.event;
	if(sur){
		var d=document.getElementById("cerceve");
		tmpx =dx + e.clientX - x ;
		tmpy =dy + e.clientY - y ;
		document.getElementById("ust").value= tmpy
		document.getElementById("sol").value= tmpx
		ayarlaXY();
	}
	
}


function ayarlaXY(){
	document.getElementById("b_foto_ktm").style.backgroundPosition= document.getElementById("sol").value +"px "+ document.getElementById("ust").value + "px";
}

function mansetKaydet(){
	document.getElementById("ust_bosluk").value= document.getElementById("ust").value
	document.getElementById("sol_bosluk").value= document.getElementById("sol").value
	document.frm.submit();
}


var aktifHaber=1, aktifEtkinlik=1, aktifEgitim=1, aktifPlatform=1;

function haberGoster(i){
	document.getElementById("slider"+aktifHaber).style.display="none";	
	document.getElementById("slider"+i).style.display="block";	
	document.getElementById("slidernav"+aktifHaber).setAttribute("class","")
	document.getElementById("slidernav"+i).setAttribute("class","aktif")
	aktifHaber= i;
}

function degistir(id){
	var sonraki
	if(aktifHaber == topHaber) sonraki=1
	else sonraki = aktifHaber + 1
	
	haberGoster(sonraki)
	setTimeout("degistir()",2000)
}

function etkinlikGoster(i){
	document.getElementById("slider2"+aktifEtkinlik).style.display="none";	
	document.getElementById("slider2"+i).style.display="block";	
	document.getElementById("slider2nav"+aktifEtkinlik).setAttribute("class","")
	document.getElementById("slider2nav"+i).setAttribute("class","aktif")	
	aktifEtkinlik= i;
}

function degistir2(id){
	var sonraki
	if(aktifEtkinlik == topEtkinlik) sonraki=1
	else sonraki = aktifEtkinlik + 1
	
	etkinlikGoster(sonraki)
	setTimeout("degistir2()",2000)
}

function egitimGoster(i){
	document.getElementById("slider3"+aktifEgitim).style.display="none";	
	document.getElementById("slider3"+i).style.display="block";	
	document.getElementById("slider3nav"+aktifEgitim).setAttribute("class","")
	document.getElementById("slider3nav"+i).setAttribute("class","aktif")	
	aktifEgitim= i;
}

function platformGoster(i){
	document.getElementById("slider4"+aktifPlatform).style.display="none";	
	document.getElementById("slider4"+i).style.display="block";	
	document.getElementById("slider4nav"+aktifPlatform).setAttribute("class","")
	document.getElementById("slider4nav"+i).setAttribute("class","aktif")	
	aktifPlatform= i;
}

function etkinlikEkle(){
	var ktm= document.getElementById("etkinlikler")
	
	var tr1= document.createElement("tr"), tr2= document.createElement("tr"), tr3= document.createElement("tr"), tr4= document.createElement("tr"), tr5= document.createElement("tr"), tr6= document.createElement("tr")
	var td1= document.createElement("th"), td2= document.createElement("td"), td3= document.createElement("th"), td4= document.createElement("td"), td5= document.createElement("th"), td6= document.createElement("td")
	var txt1= document.createElement("input"), txt2= document.createElement("input"), txt3= document.createElement("input")
	
	td1.innerHTML="Gün"
	tr1.appendChild(td1)
	ktm.appendChild(tr1)
	
	txt1.setAttribute("type","text")
	txt1.setAttribute("name","gun[]")
	txt1.style.width="50px"
	td2.appendChild(txt1)
	tr2.appendChild(td2)
	ktm.appendChild(tr2)
	
	td3.innerHTML="Etkinlik Tanımı"
	tr3.appendChild(td3)
	ktm.appendChild(tr3)
	
	txt2.setAttribute("type","text")
	txt2.setAttribute("name","tanim[]")
	td4.appendChild(txt2)
	tr4.appendChild(td4)
	ktm.appendChild(tr4)
	
	td5.innerHTML="Yer &amp; Saat Bilgileri"
	tr5.appendChild(td5)
	ktm.appendChild(tr5)
	
	txt3.setAttribute("type","text")
	txt3.setAttribute("name","yersaat[]")
	td6.appendChild(txt3)
	tr6.appendChild(td6)
	ktm.appendChild(tr6)
	
	txt1.focus();
}

function kapat(ktm){	
	document.getElementById(ktm).style.display='none';
	document.getElementById("sayfa").style.display='block';	
}
function refGoster(baslik, url, tip){
	window.open('player.php?f='+url,'_blank','width=640,height=480')	
}
function getScrollY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) 
    scrOfY = window.pageYOffset;
  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
    scrOfY = document.body.scrollTop;
  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
    scrOfY = document.documentElement.scrollTop;

  return scrOfY;
}

function txtGiris(txt){
	txt.value="";
	txt.setAttribute("class","aktif");
	txt.onblur = function (){ txtCikis(txt); }
}

function txtCikis(txt){
		txt.setAttribute("class","");
		txt.onblur = function (){ txtCikis(txt); }
}

function kontrolEt(inp){
	switch(inp.getAttribute("name")){
		case "k_adi":  
				document.getElementById("uyari_ad").setAttribute("class","uyari_hata");
				document.getElementById("uyari_ad").innerHTML="Bu kullanıcı adı kullanımda!"
				break;		
		case "sifre":
				document.getElementById("uyari_sifre").setAttribute("class","uyari_hata");
				document.getElementById("uyari_sifre").innerHTML="Şifreler uyuşmuyor!"
				break;
		case "sifre2":
				document.getElementById("uyari_sifre2").setAttribute("class","uyari_hata");
				document.getElementById("uyari_sifre2").innerHTML="Şifreler uyuşmuyor!"
				break;
	}
}

function oturumAc(){
	var xmlhttp = getAjaxObj();
	var url = "sayfalar/sifrekontrol.php?email=" + document.uye_frm.email.value + "&sifre=" + document.uye_frm.sifre.value;
	xmlhttp.open("GET",url,false);
	xmlhttp.send(null);
	var sonuc = xmlhttp.responseText;
	if ( sonuc == "hata") alert("Oturum Açılamadı! \n Hatalı giriş!");
	else if (sonuc == "pasif") alert("Hesabınız pasif durumda! \n Oturum açamazsınız!");
	else window.location = sonuc;
}

function kategoriGoster(){
	var k1=document.getElementById("k1")
	var k2=document.getElementById("k2")
	
	if(k1.value=="yeni"){
		k1.disabled="disabled"
		k1.style.display="none"
		k2.disabled=""
		k2.style.display="block"
	}
}

function tumunuSec(btn){
	var secimler= document.getElementsByName("yetkiler[]");
	for(var i=0; i<secimler.length; i++)
		if(btn.innerHTML=="Tümünü Seç")	secimler[i].checked= "checked"
		else secimler[i].checked= ""
		
	if(btn.innerHTML=="Tümünü Seç")	btn.innerHTML = "Tümünü Kaldır"
	else btn.innerHTML="Tümünü Seç"
}
