function getAjax() {
	if(window.XMLHttpRequest) {
		try {
			req = new XMLHttpRequest();
		} catch(e) {
			req = false;
		}
	} else if(window.ActiveXObject) {
		try {
			req = new ActiveXObject('Msxml2.XMLHTTP');
		} catch(e) {
			try {
				req = new ActiveXObject('Microsoft.XMLHTTP');
			} catch(e) {
				req = false;
			}
		}
	}
	return req;
}

function maillistEkle(adres,ad,soyad,mail) {
	var xmlHttp = new getAjax();
	mailadresi = gebi(mail).value;
	isim = gebi(ad).value;
	soyisim = gebi(soyad).value;
	xmlHttp.open("GET",adres+"?ad="+isim+"&soyad="+soyisim+"&mail="+mailadresi,true);
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4 && xmlHttp.status==200) {
			deg = new Array("ð","Ð","ü","Ü","þ","Þ","ý","Ý","ö","Ö","ç","Ç");
			ara = new Array("<:g2:>","<:G2:>","<:u2:>","<:U2:>","<:s2:>","<:S2:>","<:i2:>","<:I2:>","<:o:>","<:O:>","<:c2:>","<:C2:>");
			sonuc = str_replace(ara, deg, xmlHttp.responseText);
			window.alert(sonuc);
			if(xmlHttp.responseText=="E-Posta Adresiniz Eklendi.") {
				gebi(mail).value="";
				gebi(ad).value="";
				gebi(soyad).value="";
			}
		}
	}
	xmlHttp.send(null);
}

function maillistCikar(adres,mail) {
	var xmlHttp = new getAjax();
	mailadresi = gebi(mail).value;
	xmlHttp.open("GET",adres+"?mail="+mailadresi,true);
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4 && xmlHttp.status==200) {
			deg = new Array("ð","Ð","ü","Ü","þ","Þ","ý","Ý","ö","Ö","ç","Ç");
			ara = new Array("<:g2:>","<:G2:>","<:u2:>","<:U2:>","<:s2:>","<:S2:>","<:i2:>","<:I2:>","<:o:>","<:O:>","<:c2:>","<:C2:>");
			sonuc = str_replace(ara, deg, xmlHttp.responseText);
			window.alert(sonuc);
			if(sonuc=="E-Posta adresi listeden çýkarýldý.") {window.location.replace(window.location.href);}
		}
	}
	xmlHttp.send(null);
}

function tellistEkle(adres,ad,soyad,telefon) {
	var xmlHttp = new getAjax();
	telefonno = gebi(telefon).value;
	ad = gebi(ad).value;
	soyad = gebi(soyad).value;
	xmlHttp.open("GET",adres+"?ad="+ad+"&soyad="+soyad+"&tel="+telefonno,true);
	xmlHttp.onreadystatechange=function() {
		if(xmlHttp.readyState==4 && xmlHttp.status==200) {
			deg = new Array("ð","Ð","ü","Ü","þ","Þ","ý","Ý","ö","Ö","ç","Ç");
			ara = new Array("<:g2:>","<:G2:>","<:u2:>","<:U2:>","<:s2:>","<:S2:>","<:i2:>","<:I2:>","<:o:>","<:O:>","<:c2:>","<:C2:>");
			sonuc = str_replace(ara, deg, xmlHttp.responseText);
			window.alert(sonuc);
			if(xmlHttp.responseText=="Telefon Numaraniz Eklendi.") {
				gebi(telefon).value="";
				gebi(ad).value="";
				gebi(soyad).value="";
			}
		}
	}
	xmlHttp.send(null);
}

function str_replace(search, replace, subject) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Gabriel Paderni
    // +   improved by: Philip Peterson
    // +   improved by: Simon Willison (http://simonwillison.net)
    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // -    depends on: is_array
    // *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
    // *     returns 1: 'Kevin.van.Zonneveld'
    // *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
    // *     returns 2: 'hemmo, mars'    

    var f = search, r = replace, s = subject;
    var ra = is_array(r), sa = is_array(s), f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while(j = 0, i--){
        while(s[i] = s[i].split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f);
    }
     
    return sa ? s : s[0];
}

function is_array( mixed_var ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Legaev Andrey
    // +   bugfixed by: Cord
    // *     example 1: is_array(['Kevin', 'van', 'Zonneveld']);
    // *     returns 1: true
    // *     example 2: is_array('Kevin van Zonneveld');
    // *     returns 2: false
 
    return ( mixed_var instanceof Array );
}

function ajax(metod,adres,veri,sonuc,loading,senkron) {
	var xmlHttp = new getAjax();
	if(senkron!=true || senkron!=false) {
		senkron = true;
	}
	if(metod!="GET" && metod!="POST") {
		metod = "GET";
	}
	xmlHttp.onreadystatechange = function() {
		loading();
		if(xmlHttp.readyState==4 && xmlHttp.status==200) {
			sonuc(xmlHttp.responseText);
		}
	}
	xmlHttp.open(metod,adres,senkron);
	if(metod=="POST") {
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	}
	xmlHttp.send(veri);
}

function sayfaAl(sayfa,alan) {
	var xmlHttpm = new getAjax();
	xmlHttpm.open("GET",sayfa,true);
	xmlHttpm.onreadystatechange=function() {
		if(xmlHttpm.readyState==4 && xmlHttpm.status==200) {
			gebi(alan).innerHTML = xmlHttpm.responseText;
		}
	}
	xmlHttpm.send(null);
}

function pasifYap(nesne) {
	var arrPageSizes = getPageSize();
	$('#'+nesne).css({
		display:'block',
		zIndex:'99',
		opacity:'0.6',
		width:arrPageSizes[0],
		height:arrPageSizes[1]
	});
}

function aktifYap(nesne) {
	$('#'+nesne).css({
		display:'none'
	});
}

function alertWinClose() {
	$('#alertWin').css({
		display:'none'
	});
}

function alertWin(mesaj,baslik) {
	var curWinSizes = getPageSize();
	$('#alertWin').css({
		display:'block',
		zIndex:'100',
		left:(curWinSizes[2]-400)/2,
		top:(curWinSizes[3]-300)/2,
		opacity:'1'
	});
	$('#alertBaslik').html(baslik);
	$('#alertIcerik').html(mesaj);
}

function getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
};

function yardim(mesaj,nesne,e) {
	var ydiv = document.createElement("div");
	document.body.appendChild(ydiv);

	ydiv.style.left=(e.clientX+20)+"px";
	ydiv.style.top=(e.clientY+20)+"px";
	ydiv.className = "yardim";

	ydiv.innerHTML = mesaj;
	function fonksiyon() {
		ydiv.style.display="none";
	}
	if(nesne.addEventListener) {
		nesne.addEventListener("mouseout",fonksiyon,false);
	} else {
		nesne.attachEvent("onmouseout",fonksiyon);		
	}
}

$(function() {
	$('#galeri a.fotoalbum').lightBox();
});

function numarayap(numara) {
	gecerliler = [8,9,35,36,37,38,39,40,46];
	if((numara<96 || numara>105) && (numara<48 || numara>57) && jQuery.inArray(numara,gecerliler)==-1) {
		return false;
	}
}

function secenekEkle(formadi,nereye) {
	seceneksayisi = eval(document.forms[formadi].secenek_sayisi.value);
	gebi(nereye).innerHTML += '<div class="anketdeger">Seçenek '+eval(seceneksayisi+1)+' :</div><div class="anketgiris"><input type="text" name="secenek_'+seceneksayisi+'" id="secenek_'+seceneksayisi+'"></div>';
	document.forms[formadi].secenek_sayisi.value = seceneksayisi+1;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function formKontrol(dizi) {
	for(i=0;i<dizi.length;i++) {
		if(dizi[i].value.trim()=="") {
			alert("Lütfen boþ alan býrakmayýn.");
			return false;
		}
	}
	return true;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function openWindow(adres) {
	var wind = window.open(adres,"pencere","top=200,left=150,width=450,height=250,buttons=no,scrollbars=no,location=no,menubar=no,resizable=no,status=no,directories=no,toolbar=no");
}

function gebi(eleman) {
	return document.getElementById(eleman);
}