// Sabit
// ---------------------------------------------
var UA = navigator.userAgent.toLowerCase();
var OP = ( UA.indexOf('opera')   != -1);
var FF = ( UA.indexOf('firefox') != -1);
var IE = ((UA.indexOf('msie')    != -1) && (!OP) && (!FF));
var rn = '\r\n';
var _nesne_ = new Array();
var capa = Capa();

// Menu
// ---------------------------------------------
function Menu(){
	var menu = {
		alt    : Array(),
		nesne  : _nesne('menu'),
		basla  : function(){
			var li = menu.nesne.getElementsByTagName('li');
			var i, a, ul, durum;

			for(i=0; i<li.length; i++){
				if(li[i].className == 'mu'){
					a  = li[i].getElementsByTagName('a')[0];
					a.no = i;
					a.ul = ul = menu.alt[i] = li[i].getElementsByTagName('ul')[0];
					a.href = 'javascript:void(0)';
					a.onclick = function(){
						var d =  this.ul.style.display;
						for(var i in menu.alt){
							menu.alt[i].style.display = 'none';
							_cerez_yaz('menu_'+i,'none',10000000);
						}
						this.ul.style.display =  d == 'none' ? 'block' : 'none';
						_cerez_yaz('menu_'+this.no,'block',10000000);
					}
					durum = _cerez_oku('menu_'+i);
					ul.style.display = durum ? durum : 'none';
				}
			}
		}
	}
	menu.basla();
	return menu;
}

// Tablo
// ---------------------------------------------
function Tablo(no){
	var tablo = {
		resim : false,
		cagir : function(no){
			tablo.no    = no;
			tablo.table = _nesne(no,true);
		},
		aydinlat : function(){
			var satir;
			for(var i=1; i<tablo.table.rows.length; i++){
				satir = tablo.table.rows[i];
				satir.className = 'pasif';
				satir.onmouseover = function(){ this.className = 'aktif'; }
				satir.onmouseout = function(){ this.className = 'pasif'; }
			}
		}
	}
	if(no) tablo.cagir(no);
	return tablo;
}

// Baslik
// ---------------------------------------------
function Baslik(){
	var baslik = {
		aktif  : '',
		div    : _nesne('baslik'),
		tercih : -1,
		icerik : {},
		kaldir : function(gizlen){
			var a, t, arr, tag, elm, p, p1, p2;
			arr = ['applet','iframe','select'];
			if(baslik.tercih === 1){
				p   = _konum(baslik.div);
				p1  = {
					'x':[p.x,baslik.div.offsetWidth + p.x],
					'y':[p.y,baslik.div.offsetHeight + p.y]
				}
			}
			for(a=arr.length; a>0;){
				tag = document.getElementsByTagName(arr[--a]);
				for(t=tag.length; t>0;){
					elm = tag[--t];
					if(!gizlen && baslik.tercih === 0){
						if(!elm._sakla) elm._sakla = _stil(elm,'visibility');
						elm.style.visibility = 'hidden';
					} else {
						p   = _konum(elm);
						p2  = {
							'x':[p.x,elm.offsetWidth + p.x],
							'y':[p.y,elm.offsetHeight + p.y]
						}
						if(gizlen || (p2.x[0] > p1.x[1]) || (p2.x[1] < p1.x[0]) || (p2.y[0] > p1.y[1]) || (p2.y[1] < p1.y[0])) {
							if(!elm._sakla) elm._sakla = _stil(elm,'visibility');
							elm.style.visibility = elm._sakla;
						} else {
							if(!elm._sakla) elm._sakla = _stil(elm,'visibility');
							elm.style.visibility = 'hidden';
						}
					}
				}
			}
		},
		basla : function(){
			if(!baslik.div){
				var div = document.createElement('DIV');
				document.body.appendChild(div);
				baslik.div = div;
			}
			baslik.div.className = 'ibaslik';
			baslik.div.style.top  = '-500px';
			baslik.div.style.left = '-500px';
			baslik.div.style.visibility = 'hidden';
			for(var i in baslik.icerik){
				var nesne = _nesne(i,true);
				if(!nesne) continue;
				nesne.icerik = baslik.icerik[i];
				nesne.onmouseover = function(e){
					if(!e) e = window.event;
					if(baslik.tercih === 0) baslik.kaldir(false);
					baslik.div.innerHTML = '<p class="ust"></p><p class="ort">'+this.icerik+'</p><p class="alt"></p>';
					baslik.div.style.visibility = 'visible';
				}
				nesne.onmousemove = function(e){
					if(!e) e = window.event;
					if(baslik.tercih === 1) baslik.kaldir(false);
					baslik.div.style.top  = (e.clientY+_scrollY()+20)+'px';
					baslik.div.style.left = (e.clientX+_scrollX())+'px';
				}
				nesne.onmouseout = function(){
					if(baslik.tercih > -1) baslik.kaldir(true);
					baslik.div.style.visibility = 'hidden';
				}
			}
		}
	}
	return baslik;
}

// Kaydir
// ---------------------------------------------
function Kaydir(no){
	var kaydir = {
		no     : no,
		hiz    : 30,
		bekle  : 0,
		basla  : function(){
			var no  = kaydir.no;
			var ana = _nesne(no,true); ana.innerHTML = '<div id="'+no+'_crc" style="float:left;"><div id="'+no+'_icr">'+ana.innerHTML+'</div></div>';
			var crc = _nesne(no+'_crc',true);
			var icr = _nesne(no+'_icr',true);
			var p   = 1;
			var aY  = parseInt(ana.offsetHeight);
			var cY  = parseInt(crc.offsetHeight);

			crc.style.height = aY+'px';
			crc.style.overflow = 'hidden';

			icr.onmouseover = function(){ p=0; }
			icr.onmouseout  = function(){ p=1; }
			icr.kay = function(){
				var t = parseInt(icr.style.marginTop); if(isNaN(t)) t = 0;
				if(t < (cY*-1)) icr.style.marginTop = aY+'px';
				else icr.style.marginTop = (t-p)+'px';
				if(t < aY && t > (cY*-1) && (t%aY) == 0) setTimeout('try{_nesne(\''+icr.id+'\').kay()}catch(e){}',kaydir.bekle);
				else setTimeout('try{_nesne(\''+icr.id+'\').kay()}catch(e){}',kaydir.hiz);
			}
			icr.kay();
		}
	}
	_nesne(no,true).kaydir = kaydir;
	return kaydir;
}

// Gecis
// ---------------------------------------------
function Gecis(no){
	var gecis = {
		nesne : _nesne(no,true),
		artis : 1,
		deger : 0,
		zaman : 0,
		islem : function(){},
		atama : function(deger){
			gecis.nesne.style.filter = deger >= 100 ? '' : 'alpha(opacity='+deger+')';
			gecis.nesne.style.opacity = deger / 100;
		},
		giris : function(){
			gecis.atama(gecis.deger);
			if(gecis.deger >= 100){
				clearInterval(gecis.zaman);
				gecis.islem();
			}
			else gecis.deger = (gecis.deger+gecis.artis)*1.1;
		},
		cikis : function(){
			gecis.atama(gecis.deger);
			if(gecis.deger <= 0){
				clearInterval(gecis.zaman);
				gecis.islem();
			}
			else gecis.deger = (gecis.deger-gecis.artis)/1.1;
		},
		basla : function(tur){
			if(tur === true){
				gecis.atama(0);
				gecis.deger = 0;
				gecis.zaman = setInterval('_nesne(\''+gecis.nesne.id+'\').gecis.giris()',24);
			}
			else{
				gecis.atama(100);
				gecis.deger = 100;
				gecis.zaman = setInterval('_nesne(\''+gecis.nesne.id+'\').gecis.cikis()',24);
			}
		}
	}

	if(_nesne(no).gecis) clearInterval(_nesne(no).gecis.zaman);
	_nesne(no,true).gecis = gecis;
	return gecis;
}

// Capa
// ---------------------------------------------
function Capa(){
	var capa = {
		fixAllLinks: function(){
			var allLinks = document.getElementsByTagName('a');
			for(var i=0;i<allLinks.length;i++){
				var lnk = allLinks[i];
				if((lnk.href && lnk.href.indexOf('#') != -1) &&
					( (lnk.pathname == location.pathname) ||
					('/'+lnk.pathname == location.pathname) ) &&
					(lnk.search == location.search)){
					capa.addEvent(lnk,'click',capa.smoothScroll);
				}
			}
		},
		smoothScroll: function(e){
			if(window.event){
				target = window.event.srcElement;
			} else if(e){
				target = e.target;
			} else return;
			if(target.nodeType == 3){
				target = target.parentNode;
			}
			if(target.nodeName.toLowerCase() != 'a') return;
			anchor = target.hash.substr(1);
			var allLinks = document.getElementsByTagName('a');
			var allDivs = document.getElementsByTagName('div');
			var all = [allLinks, allDivs];
			var destinationLink = null;
			for(var j=0; j<all.length; j++){
				for(var i=0;i<all[j].length;i++){
					var lnk = all[j][i];
					if(lnk.name && (lnk.name == anchor)){
						destinationLink = lnk;
						break;
					} else if(lnk.id && (lnk.id == anchor)){
						destinationLink = lnk;
						break;
					}
				}
			}
			if(!destinationLink) return true;
			var destx = destinationLink.offsetLeft;
			var desty = destinationLink.offsetTop;
			var thisNode = destinationLink;
			while (thisNode.offsetParent && (thisNode.offsetParent != document.body)){
				thisNode = thisNode.offsetParent;
				destx += thisNode.offsetLeft;
				desty += thisNode.offsetTop;
			}
			clearInterval(capa.INTERVAL);
			cypos = capa.getCurrentYPos();
			capa_stepsize = parseInt((desty-cypos)/capa.STEPS);
			capa.INTERVAL = setInterval('capa.scrollWindow('+capa_stepsize+','+desty+',"'+anchor+'")',10);
			if(window.event){
				window.event.cancelBubble = true;
				window.event.returnValue = false;
			}
			if(e && e.preventDefault && e.stopPropagation){
				e.preventDefault();
				e.stopPropagation();
			}
		},
		scrollWindow: function(scramount,dest,anchor){
			wascypos = capa.getCurrentYPos();
			isAbove = (wascypos < dest);
			window.scrollTo(0,wascypos + scramount);
			iscypos = capa.getCurrentYPos();
			isAboveNow = (iscypos < dest);
			if((isAbove != isAboveNow) || (wascypos == iscypos)){
				window.scrollTo(0,dest);
				clearInterval(capa.INTERVAL);
				location.hash = anchor;
			}
		},
		getCurrentYPos: function(){
			if(document.body && document.body.scrollTop)
			return document.body.scrollTop;
			if(document.documentElement && document.documentElement.scrollTop)
			return document.documentElement.scrollTop;
			if(window.pageYOffset)
			return window.pageYOffset;
			return 0;
		},
		addEvent: function(elm, evType, fn, useCapture){
			if(elm.addEventListener){
				elm.addEventListener(evType, fn, useCapture);
				return true;
			} else if(elm.attachEvent){
				var r = elm.attachEvent("on"+evType, fn);
				return r;
			} else {
				alert("Handler could not be removed");
			}
		}
	}
	capa.STEPS = 25;
	capa.addEvent(window,"load",capa.fixAllLinks);
	return capa;
}

// Adres
// ---------------------------------------------
function Adres(no,ulke,il,ilce,semt){
	var adres = {
		ulke  : Liste(no,ulke),
		il    : Liste(no,il),
		ilce  : Liste(no,ilce),
		semt  : Liste(no,semt),
		secim : 'evet',
		getir : function(ulke,il,ilce,semt){
			var xhr = new XHR(konum+'/servis.php');
			xhr.talep('metot=adres&tur=ulke&ulke='+ulke+'&il='+il+'&ilce='+ilce+'&secim='+adres.secim);
			xhr.islem = function(){
				var cevap = xhr.cevap();
				eval('var dizi='+cevap);
				if(adres.ulke.select){
					adres.ulke.yenile(dizi.ulke);
					adres.ulke.select.value = ulke;
					adres.ulke.select.onchange = function(){ adres.yenile('il','ulke='+adres.ulke.select.value); }
				}
				if(adres.il.select){
					adres.il.yenile(dizi.il);
					adres.il.select.value = il;
					adres.il.select.onchange = function(){ adres.yenile('ilce','il='+adres.il.select.value); }
				}
				if(adres.ilce.select){
					adres.ilce.yenile(dizi.ilce);
					adres.ilce.select.value = ilce;
					adres.ilce.select.onchange = function(){ adres.yenile('semt','ilce='+adres.ilce.select.value); }
				}
				if(adres.semt.select){
					adres.semt.yenile(dizi.semt);
					adres.semt.select.value = semt;
				}
			}
		},
		yenile : function(tur,ust){
			var xhr = new XHR(konum+'/servis.php');
			xhr.talep('metot=adres&tur='+tur+'&'+ust+'&secim='+adres.secim);
			xhr.islem = function(){
				eval('var dizi='+xhr.cevap());
				if(tur == 'il') adres.il.yenile(dizi.il);
				if(tur == 'il' || tur == 'ilce') adres.ilce.yenile(dizi.ilce);
				if(tur == 'il' || tur == 'ilce' || tur == 'semt') adres.semt.yenile(dizi.semt);
			}
		}
	}
	return adres;
}

// Liste
// ---------------------------------------------
function Liste(no,isim){
	var liste = {
		cagir : function(no,isim){
			liste.select = _nesne(no).elements[isim];
		},
		ekle : function(deger,metin){
			var secenek   = document.createElement('OPTION');
			secenek.value = deger;
			secenek.text  = metin;
			liste.select.options.add(secenek);
		},
		kaldir : function(no){
			if(!no) var no = liste.select.selectedIndex;
			try{ liste.select.options[no] = null; }
			catch(e){}
		},
		yenile : function(dizi){
			liste.temizle();
			if(dizi){
				for(var i=0; i<dizi.length; i++){
					liste.ekle(dizi[i][0],dizi[i][1]);
				}
			}
		},
		temizle : function(){
			for(var i=liste.select.options.length-1; i>=0; i--){
				liste.kaldir([i]);
			}
		},
		icinde : function(deger){
			for(var i=liste.select.options.length-1; i>=0; i--){
				if(liste.select.options[i].value == deger) return true;
			}
			return false;
		},
		sec : function(){
			for(var i=liste.select.options.length-1; i>=0; i--){
				liste.select.options[i].selected = true;
			}
		},
		secim : function(){
			return liste.select.options[liste.select.selectedIndex];
		}
	}
	if(isim) liste.cagir(no,isim);
	return liste;
}

// XHR
// ---------------------------------------------
function XHR(hedef,async){
	var xhr = {
		islem : function(){
			return true;
		},
		baglan : function(hedef,async){
			this.xhr = new _xhr(this);
			this.xhr.open('POST',hedef,async);
			this.xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=windows-1254');
		},
		talep : function(talep){
			this.xhr.send(talep);
		},
		deger : function(deger){
			var sonuc = /<script>(.*?)<\/script>/.exec(deger);
			if(sonuc){
				eval(sonuc[1]);
			}
		},
		cevap : function(xsl,xml){
			var xml,rst;
			if(xsl){
				xml = new XML();
				xml.yarat(this.xhr.responseText);
				rst = xml.donustur(xsl);
			}
			else{
				if(xml){
					if(window.ActiveXObject) rst = this.xhr.responseXML;
					else{
						xml = new XML();
						xml.yarat(this.xhr.responseText);
						rst = xml.getir();
					}
				}
				else rst = this.xhr.responseText;
			}
			return rst;
		}
	}
	if(hedef){
		var async = typeof(async) == 'undefined' ? true : async;
		xhr.baglan(hedef,async);
	}
	return xhr;
}

// XHR - Temel
// ---------------------------------------------
function _xhr(nesne){
	var xhr;

	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) {
		try{ xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch(e){ xhr = false; }
	}
	@else xhr=false; @end @*/

	if(!xhr && typeof XMLHttpRequest != 'undefined'){
		try{ xhr = new XMLHttpRequest(); }
		catch (e){ xhr = false; }
	}

	xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200) nesne.islem();
	};

	return xhr;
}

// Cerez
// ---------------------------------------------
function _cerez_yaz(isim,deger,sure){
	var gecikme = '';

	gecikme = new Date((new Date()).getTime()+sure*3600000);
	gecikme = "; expires=" + gecikme.toGMTString();
	document.cookie = isim+'='+escape(deger)+gecikme;
}

function _cerez_oku(isim){
	var deger = '';
	var ara   = isim + '=';

	if(document.cookie.length > 0){
		basla = document.cookie.indexOf(ara);
		if(basla != -1){
			basla += ara.length;
			bitir = document.cookie.indexOf(';',basla);
			if(bitir == -1) bitir = document.cookie.length;

			deger = unescape(document.cookie.substring(basla, bitir))
		}
		else return false;
	}
	return deger;
}

// Nesne
// ---------------------------------------------
function _nesne(no,zorla){
	if(!_nesne_[no] || zorla){
		if(typeof(document.getElementById(no)) != 'undefined') _nesne_[no] = document.getElementById(no);
		else _nesne_[no] = false;
	}
	return _nesne_[no];
}

// Ileri
// ---------------------------------------------
function _ileri(n){
	do n = n.nextSibling;
	while (n && n.nodeType != 1);
	return n;
}

// Stil
// ---------------------------------------------
function _stil(n,s){
	var stil = n.style[s];

	if (!stil) {
		if(document.defaultView && typeof(document.defaultView.getComputedStyle) == 'function') stil = document.defaultView.getComputedStyle(n,'').getPropertyValue(s);
		else if(n.currentStyle) stil = n.currentStyle[s];
		else stil = '';
	}

	return stil;
};

// Konum
// ---------------------------------------------
function _konum(n) {
	var sl = 0, st = 0, p, t;
	var is_div = /^div$/i.test(n.tagName);

	if (is_div && n.scrollLeft) sl = n.scrollLeft;
	if (is_div && n.scrollTop)  st = n.scrollTop;

	p = { x: n.offsetLeft - sl, y: n.offsetTop - st };
	if (n.offsetParent) {
		t = _konum(n.offsetParent);
		p.x += t.x;
		p.y += t.y;
	}

	return p;
};

function _scrollY(){
	if(window.scrollY) return window.scrollY;
	else return document.documentElement.scrollTop;
}

function _scrollX(){
	if(window.scrollX) return window.scrollX;
	else return document.documentElement.scrollLeft;
}


// Trim
// ---------------------------------------------
function _trim(metin,ek){
	 return _ltrim(_rtrim(metin,ek),ek);
}

function _ltrim(metin,ek){
	 ek = ek || '\\s';
	 return metin.replace(new RegExp('^[' + ek + ']+','g'),'');
}

function _rtrim(metin,ek){
	 ek = ek || '\\s';
	 return metin.replace(new RegExp('[' + ek + ']+$','g'),'');
}

// Pencere
// ---------------------------------------------
function _pencere(theURL,winName,features, myWidth, myHeight, isCenter) {
	if(window.screen)if(isCenter)if(isCenter=="true"){
		var myLeft = (screen.width-myWidth)/2;
		var myTop  = (screen.height-myHeight)/2;
		features += (features!='') ? ',' : '';
		features += ',left='+myLeft+',top='+myTop;
	}
	window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}