$(document).ready(function(){
	var all_links = $('a[href^="?'+site_page_name+'="]');
	if(all_links.length>0) {
		for(i=0;i<all_links.length;i++){
			$(all_links).eq(i).attr("href","/"+$(all_links).eq(i).attr("href"));
		}
	}
});

phpBil = {}
phpBil.BOX = {
	katman : document.createElement("div"),
	mesaj_kutusu : document.createElement("div"),
	z_index : "99999",
	ilk_buton : true,
	ara_mesaj : "<div style=\"clear:both;font-size:0;\"></div><div style=\"font-size:0;height:0;line-height:0;margin:10px 0 8px 0;padding:0;border-top:0;border-right:0;border-left:0;border-bottom:1px solid #ddd;\"></div>",

	pencere : function(mesaj, css_sinifi, width) {
		$(phpBil.BOX.katman).css({
			"position":"absolute",
			"left":"0",
			"top":"0",
			"width":$(window).width()+"px",
			"height":$(document).height()+"px",
			"margin":"0",
			"padding":"0",
			"z-index":phpBil.BOX.z_index
		});

		phpBil.BOX.katman.className = "phpbil-box-bg";

		document.body.appendChild(phpBil.BOX.katman);

		$(phpBil.BOX.mesaj_kutusu).html(mesaj);
		if(css_sinifi)
			$(phpBil.BOX.mesaj_kutusu).addClass(css_sinifi);

		$(phpBil.BOX.mesaj_kutusu).css({
			"position":"absolute",
			"top":(document.body.scrollTop+100)+"px",
			"width":width||"auto",
			"z-index":"999999"
		});
		document.body.appendChild(phpBil.BOX.mesaj_kutusu);
		phpBil.BOX.konumlandir();
		window.scrollTo(document.body.scrollTop,0);
	},

	konumlandir : function() {
		$(phpBil.BOX.mesaj_kutusu).css("left",(($(window).width()-phpBil.BOX.genislik(phpBil.BOX.mesaj_kutusu))/2)+"px");
	},

	kapat : function() {
		$(phpBil.BOX.katman).remove();
		$(phpBil.BOX.mesaj_kutusu).remove();
		phpBil.BOX.ilk_buton = true;
	},

	buton_ekle : function(islem, baslik) {
		$(phpBil.BOX.mesaj_kutusu).html($(phpBil.BOX.mesaj_kutusu).html() + (phpBil.BOX.ilk_buton?phpBil.BOX.ara_mesaj:"") + phpBil.BOX.buton_kodu_yap(islem, baslik));
		phpBil.BOX.ilk_buton = false;
		phpBil.BOX.konumlandir();
	},

	buton_kodu_yap : function(islem, baslik) {
		return "<div style=\"float:right;margin:0 0 0 8px;padding:6px 16px;border:1px solid #ccc;cursor:pointer;\" onmouseover=\"$(this).css('border-color','#633');\" onmouseout=\"$(this).css('border-color','#ccc');\" "+islem+">"+baslik+"</div>";
	},

	genislik : function(nesne) {
		return phpBil.BOX.myParseInt($(nesne).width()) + phpBil.BOX.myParseInt($(nesne).css("paddingLeft")) + phpBil.BOX.myParseInt($(nesne).css("paddingRight")) + phpBil.BOX.myParseInt($(nesne).css("marginLeft")) + phpBil.BOX.myParseInt($(nesne).css("marginRight")) + phpBil.BOX.myParseInt($(nesne).css("borderLeftWidth")) + phpBil.BOX.myParseInt($(nesne).css("borderRightWidth"));
	},

	yukseklik : function(nesne) {
		return $(nesne).height() + phpBil.BOX.myParseInt($(nesne).css("paddingTop")) + phpBil.BOX.myParseInt($(nesne).css("paddingBottom")) + phpBil.BOX.myParseInt($(nesne).css("marginTop")) + phpBil.BOX.myParseInt($(nesne).css("marginBottom")) + phpBil.BOX.myParseInt($(nesne).css("borderTopWidth")) + phpBil.BOX.myParseInt($(nesne).css("borderBottomWidth"));
	},

	myParseInt : function(deger) {
		deger = parseInt(deger, 10);
		if(isNaN(deger)) {
			return 0;
		} else {
			return deger;
		}
	}
}
function iframe_penceresi(src,width,height,title,close) {
	var close = close||false;
	var msg = "<iframe src=\""+src+"\" frameborder=\"0\" style=\"width:"+width+"px;height:"+height+"px;\"></iframe>";
	phpBil.BOX.pencere(msg, 'mesaj_kutusu', width||"400px");
	if(close!=false) {
		phpBil.BOX.buton_ekle("onclick=\"phpBil.BOX.kapat();window.top.location.href='"+close+"';\"",title);
	} else {
		phpBil.BOX.buton_ekle("onclick=\"phpBil.BOX.kapat();\"",title);
	}
}

function pb_alert(mesaj, genislik) {
	phpBil.BOX.pencere(mesaj, 'mesaj_kutusu', genislik||"400px");
	phpBil.BOX.buton_ekle("onclick=\"phpBil.BOX.kapat();\"","Tamam");
}

function pb_info(mesaj, url, title, genislik) {
	if(!url) {
		url = "onclick=\"phpBil.BOX.kapat();\"";
	} else if(url=="go_back") {
		url = "onclick=\"history.go(-1);\"";
	} else {
		url = "onclick=\"window.location.href='"+url+"';\"";
	}
	phpBil.BOX.pencere("<h3 style=\"margin:0px 4px 8px 0;padding:0;font-size:14px;\">Bilgi</h3>"+mesaj, 'mesaj_kutusu', genislik||"400px");
	phpBil.BOX.buton_ekle(url, title||"Tamam");
}

function pb_error(mesaj, url, title, genislik) {
	if(!url || url=="go_back") {
		url = "onclick=\"history.go(-1);\"";
	} else if(url=="close") {
		url = "onclick=\"phpBil.BOX.kapat();\"";
	} else {
		url = "onclick=\"window.location.href='"+url+"';\"";
	}
	phpBil.BOX.pencere("<h3 style=\"margin:0px 4px 8px 0;padding:0;font-size:14px;\">Hata</h3>"+mesaj, 'mesaj_kutusu', genislik||"400px");
	phpBil.BOX.buton_ekle(url, title||"Tamam");
}

function pb_delete(mesaj, url, genislik) {
	mesaj = mesaj + "<div style=\"clear:both;font-size:0;\"></div><div style=\"float:right;margin:2px 0 0 4px;cursor:pointer;\" onclick=\"$('#phpbil_box_silme_onay_butonu').click();\">Onaylıyorum</div><div style=\"float:right;\"><input type=\"checkbox\" id=\"phpbil_box_silme_onay_butonu\" /></div>";
	phpBil.BOX.pencere("<h3 style=\"margin:0 4px 8px 0;padding:0;font-size:14px;\">Silme Onayı</h3>"+mesaj, 'mesaj_kutusu', genislik||"400px");
	phpBil.BOX.buton_ekle("onclick=\"phpBil.BOX.kapat();\"","Vazgeç");
	phpBil.BOX.buton_ekle("onclick=\"if($('#phpbil_box_silme_onay_butonu').attr('checked')){window.location.href='"+url+"';}\"","Sil");
}

function pb_yesno(mesaj, url, genislik, butonlar) {
	butonlar = butonlar||["Evet","Hayır"];
	phpBil.BOX.pencere(mesaj, 'mesaj_kutusu', genislik||"400px");
	phpBil.BOX.buton_ekle("onclick=\"phpBil.BOX.kapat();\"",butonlar[1]);
	phpBil.BOX.buton_ekle("onclick=\"window.location.href='"+url+"';\"",butonlar[0]);
}

uyari = window.uyari = function(mesaj,adres) {
	pb_alert(mesaj);
}
function alertErrors(error_text) {
	pb_error(error_text);
}
function alertMessages(text,url,redirect_timeout) {
	pb_info(text, url);
	if(url) {
		$(document).ready(function(){$(document).keyup(function(event) {
			event = event || window.event;
			if(event.keyCode==32 || event.keyCode==27 || event.keyCode==13) {
				window.location=url;
			}
		})});
		setTimeout(function(){
			window.location=url;
		},5000);
	}
}

var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}
function AddSelectOption(selectObj, text, value, isSelected) 
{
    if (selectObj != null && selectObj.options != null)
    {
        selectObj.options[selectObj.options.length] = 
            new Option(text, value, false, isSelected);
    }
}
function changeClassName(sinif,value) {
	if(document.getElementsByClassName) {
		var elems = document.getElementsByClassName(sinif);
	} else {
		var elems = gebc(sinif);
	}
	for(i=0;i<elems.length;i++) {
		elems[i].className=value;
	}
}
function gebc(className, tag, elm){
		var tag = tag || "*";
		var elm = elm || document;
	if(document.getElementsByClassName && tag=="*") {
		return elm.getElementsByClassName(className);
	} else {
		var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
		var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
		var returnElements = [];
		var current;
		var length = elements.length;
		for(var i=0; i<length; i++){
			current = elements[i];
			if(testClass.test(current.className)){
				returnElements.push(current);
			}
		}
		return returnElements;
	}
}
function changeFckEditor(editorname,mode) {
	var theEditor = FCKeditorAPI.GetInstance(editorname);
	if(mode==0 || mode=='off' || mode==false) {
		if(document.all) {
			theEditor.EditorDocument.body.disabled = true;
		} else {
			theEditor.EditorDocument.designMode = 'off';
		}
		theEditor.EditorWindow.parent.FCK.ToolbarSet._ChangeVisibility(true);
	} else {
		if(document.all) {
			FCKeditorAPI.GetInstance(editorname).EditorDocument.body.disabled = false;
		} else {
			FCKeditorAPI.GetInstance(editorname).EditorDocument.designMode = 'on';
		}
		theEditor.EditorWindow.parent.FCK.ToolbarSet._ChangeVisibility(false);
		// set focus on editorArea
		theEditor.EditorWindow.focus();
		// and update toolbarset
		theEditor.EditorWindow.parent.FCK.ToolbarSet.RefreshModeState();
	}
}
function sadece_sayi(nesne) {
	nesne.value = nesne.value.replace(/[^0-9]+/,"");
}
function sadece_para(nesne) {
	nesne.value = nesne.value.replace(/[^0-9\.\,]+/,"");
	nesne.value = nesne.value.replace(/\,+/,".");
	nesne.value = nesne.value.replace(/(\.){2,}/,".");
}
function sadece_virgul(nesne) {
	nesne.value = nesne.value.replace(/[^0-9\,]+/,"");
	nesne.value = nesne.value.replace(/(\,){2,}/,",");
}
var dArea = document.createElement("div");
function setFckDisable(fckParent) {
	var position = $('#'+fckParent).position();
	$(dArea).css({
		'position':'absolute',
		'visibility':'visible',
		'left':position.left,
		'top':position.top,
		'width':($('#'+fckParent).width())+"px",
		'height':($('#'+fckParent).height()+10)+"px",
		'z-index':'9',
		'opacity':'0.1',
		'background-color':'#000000'
	});
	$('#'+fckParent).append($(dArea));
}
function setFckEnable() {
	$(dArea).css({
		'visibility':'hidden'
	});
}
function bisey_ac(e,baslik,icerik) {
	e = e || window.event;
	if (gebi("bisey")) {
		gebi("bisey").parentNode.removeChild(gebi("bisey"));
	}
	var tiklanan = e.srcElement || e.target;
	pozisyon = $(tiklanan).position();
	var bisey = document.createElement("div");
	with(bisey.style) {
		position="absolute";
		zIndex="9";
		left=(pozisyon.left)+"px";
		top=(pozisyon.top)+"px";
		padding="2px";
		backgroundColor="#E9E2E2";
		fontFamily="Verdana";
		border="1px solid #977D7D";
	}
	bisey.setAttribute("id","bisey");
	document.body.appendChild(bisey);
	bisey.innerHTML = '<div style="width:150px;padding:2px 4px;overflow:hidden;background-color:#977D7D;color:#fff;"><span style="float:left">'+baslik+'&nbsp;</span><span style="float:right;cursor:pointer;" onclick="gebi(\'bisey\').parentNode.removeChild(gebi(\'bisey\'));" onmouseover="this.style.color=\'#C9C2C2\';" onmouseout="this.style.color=\'#fff\';">X</span></div><div style="padding:3px 1px 1px 1px;font-size:12px;">'+icerik+'</div>';
}
function tooltip(nesne,timeout,width,css) {
	phpbil_com_tooltip(nesne,nesne.title,timeout);
}
function phpbil_com_tooltip(nesne,mesaj,timeout,css) {
	var tool = new Object;
	tool.nesne = nesne;
	tool.title = nesne.title;
	tool.alt = nesne.alt;

	// nesnenin title ve alt bilgisini boşalt
	nesne.title="";
	nesne.alt="";

	nesne.style.cursor="help";

	// mesajı al
	tool.mesaj = mesaj;

	// yarat ve sayfaya dahil et
	tool.tip = document.createElement("div");
	tool.tip.style.display = "none";
	tool.tip.innerHTML = tool.mesaj;
	tool.tip.className = css||"tooltip";
	document.body.appendChild(tool.tip);

	timeout = timeout||0;

	setTimeout(function() {tool.tip.style.display = "block"},timeout);

	add_event_listener(nesne,"onmousemove",function(e) {
		e=e||window.event;
		tasi(tool.tip,e.clientX,e.clientY);
	});

	add_event_listener(nesne,"onmouseout",function(e) {
		e=e||window.event;
		nesne.title = tool.title;
		nesne.alt = tool.alt;
		try {
			tool.tip.parentNode.removeChild(tool.tip)
		}catch(e){}
	});

	function tasi(ne,x,y) {
		x = x+document.body.scrollLeft+document.documentElement.scrollLeft;
		y = y+document.body.scrollTop+document.documentElement.scrollTop;
		ne.style.position="absolute";

		x = x + ne.offsetWidth > document.body.clientWidth ? x - ne.offsetWidth - 20 : x;
		y = y + ne.offsetHeight > document.body.clientHeight ? y - ne.offsetHeight -20 : y;

		ne.style.left=x+"px";
		ne.style.top=y+"px";
	}

	function add_event_listener(element,listener,action) {
		if(document.all) {
			element.attachEvent(listener,action);
		} else {
			element.addEventListener(listener.substring(2),action,false);
		}
	}
}
function remove_element(element) {
	element.parentNode.removeChild(element);
}
function getCssValue(oElm, strCssRule){
	var strValue = "";
	if(document.all && strCssRule=="opacity") {
		strCssRule="filter";
	}
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}
function sayfaBoyutlari() {
	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 str_replace(search, replace, subject, count) {
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }
 
    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}
function diziye_ekle(dizi,eklenecek) {
	dizi.push(eklenecek);
}
function diziden_cikar(dizi,cikarilacak) {
	dizi_u = dizi.length;
	for(i=0;i<dizi_u;i++) {
		if(dizi[i]==cikarilacak) {
			dizi[i] = '';
		}
	}
}
function is_numeric(content) {
	return /^[0-9]$/.test(content);
}
function radio_degeri(radyolar) {
	if(!radyolar) return false;
	if(typeof radyolar.length == 'undefined') {
		if(radyolar.checked) {
			return radyolar.value;
		} else {
			return false;
		}
	}

	for(i=0;i<radyolar.length;i++) {
		if(radyolar[i].checked) {
			return radyolar[i].value;
		}
	}
	return false;
}
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
function gebi(nesne) {
	return document.getElementById(nesne);
}
