$(document).ready(function(){	   
	$("input[name$=fiyat], input[name$=tutar]").keydown(function(event){
		return f_numeric(event, true);
	});
	if ($(".tablesorter").attr("class")) {
		$(".tablesorter").tablesorter({
			widthFixed: true, 
			widgets: ['zebra'],
			headers: {0: {sorter: false}}
			//, sortList: [[1,0]]
		});
	}
	$('select[name=kategori_id]').change(function(){
			$('select[name=kategori_alt_id]').html('<option>Yükleniyor...</option>');
			var selIndex = intval($(this).attr('selectedIndex'));
			$.post('aj_data.php', {islem: 'kategori_alt', kategori_id: $(this).val()}, function(data){
				$('select[name=kategori_alt_id]').html(data);
				$('select[name=kategori_id]').attr('selectedIndex', selIndex);
			});
	});	
	
	$("#td_kategoriler > span").click(function(){
		$("ul:visible").slideUp("fast");
		$(this).next().slideDown("fast");
		});	
	$("#td_kategoriler > ul:not(.open)").hide();

	$("#urunler a").lightBox();
});

function f_numeric(e, para) {
	k = e.keyCode;
	/*
	var s;
	for (x in e) {
		s += x+' = '+eval('e.'+x)+'<br>';
		}
	$("#en").html(s);
	*/
	if (k == 190 && para == true) {} //Nokta
	if (e.ctrlKey && (k == 90 || k == 88 || k == 67 || k == 86)) {} //Kopyala yapıştır
	else if (k == 8 || k == 9 || k == 46 || k == 35 || k == 36 || k == 37 || k == 39 || k == 13 || k == 116) {} //Home End vs. tuşları
	else if ((k >= 48 && k <= 57) || (k >= 96 && k <= 105)) {//Numaralar
			if (e.altKey || e.ctrlKey || e.shiftKey) {return false;}
			}
	else {return false; }
	}
	
function f_query(p_key){
	var s = window.location.search.replace(/\?/,'&');
	var arr = s.split("&");
	for (i=0; i<arr.length;i++){
		if (p_key == arr[i].split("=")[0]) return arr[i].split("=")[1];
		}
	}	
	
function intval( mixed_var, base ) {
    var tmp;
 
    if( typeof( mixed_var ) == 'string' ){
        tmp = parseInt(mixed_var*1);
        if(isNaN(tmp) || !isFinite(tmp)){
            return 0;
        } else{
            return tmp.toString(base || 10);
        }
    } else if( typeof( mixed_var ) == 'number' && isFinite(mixed_var) ){
        return Math.floor(mixed_var);
    } else{
        return 0;
    }
}	
