// This site requires jQuery!
function ajax(func, what) {
	$.ajax({
		dataType:'json',
		data: {
			'ajax': func,
			'data': what
		},
		type: 'POST',
		success: function(JSON) {
			if (JSON.alert) {
				alert(JSON.alert);
			} else {
				$.each(JSON.data, function(key,val) {
					$('#'+key).html(val);
				});
				if (JSON.focus) {
					$('#'+JSON.focus).focus();
				}
			}
		}
	})
}

$(document).ready(function() {
	if (window.XMLHttpRequest) {
		// IE 7, mozilla, safari, opera 9
	} else {
		alert('Internet Explorer 6 veya daha düşük bir versiyon kullanıyorsunuz. Bazı fonksiyonlar çalışmayabilir. Lütfen Internet Explorer 8\'e güncelleyin veya en iyisi Mozilla Firefox veya Google Chrome kullanın.');
	}

	$(".POP").each(function() {
		var $link = $(this);
		var $url = ($link.attr('url'))?$link.attr('url'):$link.attr('href');
		var $title = $link.attr('title');
		$link.click(function(e) {
			wo($url,$title,1);
			e.preventDefault();
		});
	});

	$(".sorBakalim").each(function() {
		var $link = $(this);
		var $url = ($link.attr('url'))?$link.attr('url'):$link.attr('href');
		var $title = $link.attr('title');
		var $text = ($link.attr('text'))?$link.attr('text'):'Emin misin?';
		$link.click(function(e) {
			sorbakalim($url,$title,$text);
			e.preventDefault();
		});
	});

	$.datepicker.regional['tr'] = {
		closeText: 'Kapat',
		prevText: '&#x3c;Geri',
		nextText: 'İleri&#x3e',
		currentText: 'Bugün',
		monthNames: ['Ocak','Şubat','Mart','Nisan','Mayıs','Haziran',
		'Temmuz','Ağustos','Eylül','Ekim','Kasım','Aralık'],
		monthNamesShort: ['Oca','Şub','Mar','Nis','May','Haz',
		'Tem','Ağu','Eyl','Eki','Kas','Ara'],
		dayNames: ['Pazar','Pazartesi','Salı','Çarşamba','Perşembe','Cuma','Cumartesi'],
		dayNamesShort: ['Pz','Pt','Sa','Ça','Pe','Cu','Ct'],
		dayNamesMin: ['Pz','Pt','Sa','Ça','Pe','Cu','Ct'],
		dateFormat: 'dd.mm.yy', firstDay: 1,
		isRTL: false};
	$.datepicker.setDefaults($.datepicker.regional['tr']);
});

function wo(url,title,refresh) {
	var tt = (title)?title:'Dialog Title';
	var $dialog = $('<div></div>')
		.html('<iframe width="100%" height="99%" src="'+url+'"></iframe>')
		.dialog({
			autoOpen: false,
			resizable: false,
			height: 400,
			width: 800,
			modal: true,
			title: tt,
			position: ['',80],
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			}
		});
	$dialog.dialog('open');
}

function sorbakalim(url,title,text) {
	var tt = (title)?title:'Dialog Title';
	var $dialog = $('<div></div>')
		.html(text)
		.dialog({
			autoOpen: false,
			resizable: false,
			width: 400,
			modal: true,
			title: tt,
			position:['',80],
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				'Tamam': function() {
					$(this).dialog('close');
					document.location.replace(url);
				},
				'Vazgeç': function() {
					$(this).dialog('close');
				}
			}
		});
	$dialog.dialog('open');
}

function setfocus(ii) {
	var i = document.getElementById(ii);
	i.focus();
	switch (i.type) {
		case "text":
		case "textarea":
			i.select();
		break;
	}
}

function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
	for(z=0; z<theForm.length;z++){
		if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall') {
			theForm[z].checked = theElement.checked;
		}
	}
}

/*
Redirection function, very simple, just send the url that
you would like to be redirected.
*/
function lr(url) { location.replace(url); }

