var phpBil = {
	element_sil : function(element) {
		element.parentNode.removeChild(element);
	},
	width : function(element) {
		return Math.max(element.clientWidth,element.scrollWidth);
	},
	height : function(element) {
		return Math.max(element.clientHeight,element.scrollHeight);
	},
	pencere : function(msg,opc) {
		var ekran_boyutlari = sayfaBoyutlari();
		document.body.appendChild(document.createElement("div")).id = "phpbil_durdur";
		with(gebi("phpbil_durdur").style) {
			width = ekran_boyutlari[0]+"px";
			height = ekran_boyutlari[1]+"px";
			backgroundColor = "#000";
			position = "absolute";
			left = "0";
			top = "0";
			opacity = opc||"0.3";
			filter = "alpha(opacity="+(parseFloat((opc||"0.3"))*100)+")";
			zIndex = "2";
		}

		document.body.appendChild(document.createElement("div")).id = "phpbil_mesaj";
		gebi("phpbil_mesaj").className = "phpbil-pencere";
		with(gebi("phpbil_mesaj").style) {
			width = "350px";
			position = "absolute";
			left = ((ekran_boyutlari[0] - 350)/2)+"px";
			top = (parseInt(document.body.scrollTop)+parseInt(document.documentElement.scrollTop)+150)+"px"
			backgroundColor = "#ffffff";
			zIndex = "4";
		}
		gebi("phpbil_mesaj").innerHTML = msg;
		document.body.appendChild(document.createElement("div")).id = "phpbil_kenarlik";
		with(gebi("phpbil_kenarlik").style) {
			width = "394px";
			height = (this.height(gebi("phpbil_mesaj"))+20)+"px";
			position = "absolute";
			left = ((ekran_boyutlari[0] - 370)/2)+"px";
			top = (parseInt(document.body.scrollTop)+parseInt(document.documentElement.scrollTop)+140)+"px"
			backgroundColor = "#000";
			opacity = "0.4";
			filter = "alpha(opacity=40)";
			zIndex = "3";
		}
	},
	pencere_kapat : function() {
		silinecekler = 'phpbil_durdur,phpbil_mesaj,phpbil_kenarlik'.split(',');
		for(i=0;i<silinecekler.length;i++) {
			this.element_sil(gebi(silinecekler[i]));
		}
	},
	bilgi_penceresi : function(msg,link,metin,opc) {
		msg = msg + "<div style=\"clear:both;font-size:0px;height:14px;\"></div>";
		msg = msg + "<div class=\"phpbil-js-link\"><a href=\""+(link||"javascript:void(0);\" onclick=\"phpBil.pencere_kapat();")+"\">"+(metin||"Tamam")+"</a></div>";
		this.pencere(msg,opc);
	},
	hata_penceresi : function(msg,link,metin,opc) {
		msg = msg + "<div style=\"clear:both;font-size:0px;height:14px;\"></div>";
		msg = msg + "<div class=\"phpbil-js-link\"><a href=\""+(link||"javascript:history.go(-1);")+"\">Tamam</a></div>";
		this.pencere(msg,opc);
	},
	onay_penceresi : function(msg,link,metin,opc) {
		msg = msg + "<div style=\"clear:both;font-size:0px;height:14px;\"></div>";
		msg = msg + "<div class=\"phpbil-js-link\"><div style=\"float:left;text-align:left;\"><input type=\"checkbox\" id=\"pencere_onay_onay\" /></div><div style=\"float:left;padding:2px 0 0 6px;cursor:pointer;\" onclick=\"if(gebi('pencere_onay_onay').checked==true){gebi('pencere_onay_onay').checked=false}else{gebi('pencere_onay_onay').checked=true}\">Onaylıyorum</div><a href=\"javascript:void(0);\" onclick=\"phpBil.pencere_kapat();\">Vazgeç</a><a href=\"javascript:void(0);\" onclick=\"if(gebi('pencere_onay_onay').checked==true){window.location.href=&quot;"+link+"&quot;}\">"+(metin||"Tamam")+"</a></div>";
		this.pencere(msg,opc);
	}
}
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);
		}
	}
}
uyari = window.uyari = function(mesaj,adres) {
	phpBil.bilgi_penceresi(mesaj);
}
function alertErrors(error_text) {
	phpBil.hata_penceresi(error_text);
}
function alertMessages(text,url,redirect_timeout) {
	phpBil.bilgi_penceresi(text,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;
		}
	})});
	if(url!='') {
		setTimeout(function(){
			window.location=url;
		},5000);
	}
}
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 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");
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height) {
	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


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