/*pef*/
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

String.prototype.strrev = function(){
    var str = this + '';
    var grapheme_extend = /(.)([\uDC00-\uDFFF\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065E\u0670\u06D6-\u06DC\u06DE-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u0901-\u0903\u093C\u093E-\u094D\u0951-\u0954\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C01-\u0C03\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C82\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D02\u0D03\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F90-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B6-\u17D3\u17DD\u180B-\u180D\u18A9\u1920-\u192B\u1930-\u193B\u19B0-\u19C0\u19C8\u19C9\u1A17-\u1A1B\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAA\u1C24-\u1C37\u1DC0-\u1DE6\u1DFE\u1DFF\u20D0-\u20F0\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA67C\uA67D\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C4\uA926-\uA92D\uA947-\uA953\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uFB1E\uFE00-\uFE0F\uFE20-\uFE26])/g;
    str = str.replace(grapheme_extend, '$2$1'); // Temporarily reverse
    return str.split('').reverse().join('');
}

var disable = "";
var sess_id = 'PHPSESSID';
var secure_ajax_thread = true;

function pefSaat(){
    var currentTime = new Date()
    var hours = currentTime.getHours()
    var minutes = currentTime.getMinutes()
    var seconds = currentTime.getSeconds()
    if (hours < 10){
	hours = "0" + hours;
    }
    if (minutes < 10){
	minutes = "0" + minutes;
    }
    if (seconds < 10){
	seconds = "0" + seconds;
    }
    return hours + ":" + minutes + ":" + seconds;
}

function pefSetCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function pefGetCookie(c_name){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function pefAjax(arg_uri, arg_function){
    $.ajax({
		url: arg_uri + '&r=' + Math.random(),
		success: function(data) {
			if(arg_function != '')eval(arg_function + '(data);');
		}
	});
}

function pefSecureAjax(arg_uri, arg_query, arg_function){
	if(secure_ajax_thread == false){
		setTimeout("pefSecureAjax('" + arg_uri + "', '" + arg_query + "', " + arg_function + ")", 50);
		return false;
	}
	
	secure_ajax_thread = false;
    $.ajax({
		type: "POST",
		url: arg_uri + '?ajax=' + aes_enc(arg_query + '&r=' + Math.random()),
		success: function(data) {
			data = aes_dec(data);
			tmp = data.split("{::|}");
			
			if(tmp.length > 1){
				pefSetCookie('AES', tmp[tmp.length - 1], 1);
				aes_setkey(tmp[tmp.length - 1]);
				
				var tmp_data = '';
				for(i = 0; i < tmp.length - 1; i++){
					tmp_data+=tmp[i] + '{::|}';
				}
				tmp_data = tmp_data.substr(0, tmp_data.length - 5);
				arg_function(tmp_data);				
				secure_ajax_thread = true;
				//3x yavaşlatıyor ama biraz daha güvenli
				//pefSetCookie('AES', '-', -1);
				//aes_setkey('-');
			}else{
				$.ajax({
					type: "POST",
					url: arg_uri + '?ajax=&get_aes=&r=' + Math.random(),
					success: function(a) {
						tmp = a.split("{::|}");
						pefSetCookie('AES', tmp[1], 1);
						aes_setkey(tmp[1]);		
						secure_ajax_thread = true;
						pefSecureAjax(arg_uri, arg_query, arg_function);
					}
				});
			}
			
		}
	});
}

function pefClearAllControls(){
	var obj = document.getElementsByTagName("*");
	for(var i = 0; i < obj.length; i++){
		if(obj[i].disabled == false && obj[i].id != "" && obj[i].type != "hidden"){
			obj[i].value = "";
			if(obj[i].tagName.toLowerCase() == "select"){
				obj[i].options.selectedIndex = 0;
			}
		}
	}
}

function pefDisableAllControls(){
	disable = "";
	var obj = document.getElementsByTagName("*");
	for(var i = 0; i < obj.length; i++){
		if(obj[i].disabled == false && (obj[i].tagName.toLowerCase() == "input" || obj[i].tagName.toLowerCase() == "select" || obj[i].tagName.toLowerCase() == "button" || obj[i].tagName.toLowerCase() == "textarea")){
			var drm = true;
			if(obj[i].id == "")drm = false;
			if(obj[i].type && obj[i].id == ""){
					if(obj[i].type.toLowerCase() == "button" || obj[i].type.toLowerCase() == "submit" || obj[i].type.toLowerCase() == "reset" || obj[i].type.toLowerCase() == "radio" || obj[i].type.toLowerCase() == "checkbox" || obj[i].type.toLowerCase() == "file" || obj[i].type.toLowerCase() == "text"){
						obj[i].id = "object_" + parseInt(Math.random() * 10000);
						drm = true;
					}
			}
			if(drm){
				disable += (obj[i].id == ""?i:obj[i].id) + "|";
				obj[i].disabled = true;
			}
		}
	}
	disable = disable.substr(0, disable.length - 1);
}

function pefEnableAllControls(){
	var elem = disable.split("|");
	for(var i = 0; i < elem.length; i++){
		if(parseInt(elem[i]) > 0){
			var obj = document.getElementsByTagName("*");
			for(var j = 0; j < obj.length; j++){
				if(j == parseInt(elem[i]))obj[j].disabled = false;
			}
		}else{
			if(document.getElementById(elem[i]))$$(elem[i]).disabled = false;
		}
	}
}

function urlDecode(str){
	str=str.replace(new RegExp('\\+','g'),' ');
	return unescape(str);
}

function pefIFrame( id ) {
    return $$(id).contentWindow ? $$(id).contentWindow.document : $$(id).contentDocument
}

function pefInnerText(id){
	if(document.all){
		return id.innerText;
	} else{
		return id.textContent;
	}
}

function pefDivSelectTumunuSec(id){
	var obj = document.getElementsByTagName("input");
	for(var i = 0; i < obj.length; i++){
		if(obj[i].id.search(id) == 0){
			if($$('div_' + obj[i].id).style.display == '' && obj[i].disabled == false){
				obj[i].checked = true;
				$$('div_' + obj[i].id).className = "divSelect";
			}
		}
	}
}

function pefDivSelectTumunuKaldir(id){
	var obj = document.getElementsByTagName("input");
	for(var i = 0; i < obj.length; i++){
		if(obj[i].id.search(id) == 0){
			if($$('div_' + obj[i].id).style.display == ''){
				obj[i].checked = false;
				$$('div_' + obj[i].id).className = "divNormal";
			}
		}
	}
}

function pefDivSelectFiltrele(id){
	$$('inpFilter_' + id).value = '';
	if($$('trFilter_' + id).style.display == 'none'){
		$$('trFilter_' + id).style.display = '';
		$$('trFilterTool_' + id).style.display = 'none';
		$$('inpFilter_' + id).focus();
	}else{
		$$('trFilterTool_' + id).style.display = '';
		$$('trFilter_' + id).style.display = 'none';
	}
	var obj = document.getElementsByTagName("input");
	for(var i = 0; i < obj.length; i++){
		if(obj[i].id.search(id) == 0){
			$$('div_' + obj[i].id).style.display = "";
		}
	}
}

function pefInnerText(id){
	if(document.all){
		return id.innerText;
	} else{
		return id.textContent;
	}
}

function pefDivSelectFiltre(id){
	var obj = document.getElementsByTagName("input");
	for(var i = 0; i < obj.length; i++){
		if(obj[i].id.search(id) == 0){
			$$('div_' + obj[i].id).style.display = "";
		}
	}
	
	for(var i = 0; i < obj.length; i++){
		if(obj[i].id.search(id) == 0){
			if(pefInnerText($$('div_' + obj[i].id)).toLowerCase().search($$('inpFilter_' + id).value.toLowerCase()) >= 0 || obj[i].id.toLowerCase().search($$('inpFilter_' + id).value.toLowerCase()) >= 0){
				$$('div_' + obj[i].id).style.display = "";
			}else{
				$$('div_' + obj[i].id).style.display = "none";
			}
		}
	}
}

function urlEncode(str){
	for(i = 1; i <= 100; i++){
		str = str.replace(' ', '%20');
		str = str.replace('=', '%3D');
		str = str.replace('&', '%26');
		str = str.replace('"', '%22');
		str = str.replace('\\', '%5C%5C');
		str = str.replace('\n', '\\n');
	}
	return str;
}

function pefRemoveTR(tbl, tr){
	if(document.all){
		tbl.removeChild(tr);
	}else{
		tbl.deleteRow(tr.rowIndex);
	}
}

function $$(i){ return document.getElementById(i); }

function $$$(i){ return document.getElementsByTagName(i); }

function pefNumberF(number, decimals, dec_point, thousands_sep){    
	var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
	var d = dec_point == undefined ? "," : dec_point;
	var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
	var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
	return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}
/*--pef*/
