$(document).ready(function(){
	
	$('#kolaysorueklemek').click(function(){
		$.prompt('Soruları Aşağıdaki yöntemler ile kolayca bulabilirsiniz<br /><br />Öncelikle soru eklemek için kendinize bir kategori belirleyiniz.<br /><br />Örneğin edebiyat yazarlar. Daha sonra önünüze yazarlar ile ilgili bir kitap açarak ya da internetten doğru kaynaklardan sayfalar açarak sırayla bilinen yazarlar hakkında sorular ekleyebilirsiniz.<br /><br />Kaç yılında doğdu, ilk kitabı hangisi, nerede doğdu, ne zaman öldü, kaç kitap çıkarttı, eğer şairse bilinen şiirleri, bu dizeler kime aittir vs. şeklinde sorulabilir.');
		return false;
	});
	
	$('#lang').change(function(){
		window.location = 'http://www.kimbilir.org/index.php?lang=' + $(this).val();
	});
	
	var lng = $('#langsecili').val();
	$('#'+ lng).attr('selected', true);

	$('#soruekle').click(function(){
		$('#bnzsrc').remove();
		$('.benzerler:first-child').remove();
		$.ajax({
			type: 'POST',
			url: 'soruekle.php',
			data: 'ekle=ok',
			success: function(req){
				$(req).insertBefore('#eklekardes');
			}
		});
		
		return false;
		
	});
	
	$("#add-friend").dialog({
		modal: true,
		autoOpen: false,
		draggable: false,
		width:400,
		hide: 'slide',
		resizable: false,
		buttons: {
			Ekle: function() {
				$.ajax({
					
					type: 'POST',
					url: 'ajax_inc/index.php?pg=requests',
					data: 'act=addasfriend&uid='+$('#uid').attr('value'),
					success: function(req){
						$('#addas').html(req);
						$("#add-friend").dialog('close');
					}
						
				});
			},
			İptal: function(){
				$(this).dialog('close');
			}
		}
	});
	
	$("#about-money").dialog({
		modal: true,
		autoOpen: false,
		draggable: false,
		width:550,
		hide: 'slide',
		resizable: false,
		buttons: {
			Tamam: function(){
				$(this).dialog('close');
			}
		}
	});
	
	$('#share').TextAreaExpander(25, 200);
	$('#mesaj').TextAreaExpander(50, 200);
	
	$('#share').bind('keypress', function(e){
		 var code = (e.keyCode ? e.keyCode : e.which);
		 if(code == 32) {
			var val = $(this).val();
			var myid = $(this).attr('name');
			var uid = $(this).attr('class');
			if(val.indexOf('http://') == 0 && $('.alan2').text() == 0){
				if(val.indexOf('com') > 6 || val.indexOf('org') > 6 || val.indexOf('net') > 6 || val.indexOf('us') > 6){
					if(val.length > 10){
						if($('.alan2').css('display') != 'none')
							$('.alan2').css({'display':'none'});
						$('.loader').css({'display':'block'});
						$.ajax({
								
							type: 'POST',
							url: 'checkurl.php',
							data: 'text='+val+'&myid='+myid+'&uid='+uid,
							success: function(req){
								$('.sharebtnpstatus').css({'display':'none'});
								$('.alan2').fadeIn(500);
								$('.loader').css({'display':'none'});
								$('.alan2').html(req);
							}
								
						});
					}
				}
			}
		}
	});
	
	$('#user').focus(function(){
		
		if($(this).attr('title') == 0){
			$(this).attr('value', '');
			$(this).attr('title', '1');
			$(this).css({'color':'#333'});
		}
		
	});
	
	$('#pass').focus(function(){
		
		if($(this).attr('title') == 0){
			$(this).attr('value', '');
			$(this).attr('title', '1');
			$(this).css({'color':'#333'});
		}
		
	});
	
	$('#loginbtn').click(function(){
		
		var email = $('#user').attr('value');
		var pass = $('#pass').attr('value');
		var t1 = $('#user').attr('title');
		var t2 = $('#pass').attr('title');
		
		if(t1 == 1 && t2 == 1 && email.length > 4 && pass.length > 3){
			
			$('#login_form').submit();
			
		}
		
	});
	
	$('#pass').bind('keypress', function(e){ // left.php içinde password kutusu
		
		var code = (e.keyCode ? e.keyCode : e.which);
		 if(code == 13) {
			$('#login_form').submit();
		 }
		
	});
	
	$('#go2btn').click(function(){ // Register.php sayfasında, 2. aşamaya geçen buton
	
		var namefi = $('#name').val();
		var surnamefi = $('#surname').val();
		var emailfi = $('#email').val();
		var sexfi = $('#sex').val();
		var birthdayfi = $('select[name="birth_gun"]').val();
		var birthmonthfi = $('select[name="birth_ay"]').val();
		var birthyearfi = $('select[name="birth_yil"]').val();
		var sifrefi = $('#sifre').val();
		
		if(sifrefi.length > 5){
			$.ajax({
				type: 'POST',
				url: 'ajax_inc/index.php?pg=checkemail',
				data: 'act=checkemail&email='+emailfi,
				success: function(req){
					
					if(req == 1){
			
						if(namefi.length == 0 || surnamefi.length == 0 || sexfi.length == 0 || birthdayfi == 0 || birthmonthfi == 0 || birthyearfi == 0){
							
							if(namefi.length == 0)
								$('#name').css({'border':'1px solid #F33'});
								
							if(surnamefi.length == 0)
								$('#surname').css({'border':'1px solid #F33'});
								
							if(sexfi.length == 0)
								$('#sex').css({'border':'1px solid #F33'});
								
							if(birthdayfi == 0)
								$('select[name="birth_gun"]').css({'border':'1px solid #F33'});
								
							if(birthmonthfi == 0)
								$('select[name="birth_ay"]').css({'border':'1px solid #F33'});
								
							if(birthyearfi == 0)
								$('select[name="birth_yil"]').css({'border':'1px solid #F33'});
							
						} else {
							
							$('#registerform').submit();
							
						}
					} else if(req == 2) {
						
						$('#emailusing').css({'display':'inline'});
						$('#emailerror').css({'display':'none'});
						$('#email').css({'border':'1px solid #F33'});
						
					} else {
						
						$('#emailusing').css({'display':'none'});
						$('#emailerror').css({'display':'inline'});
						$('#email').css({'border':'1px solid #F33'});
						
					}
				}
			});
		} else {
			$('#passshort').css({'display':'inline'});
		}
		
	});
	
	$('#go3btn').click(function(){
		
		$('#registerform').submit();
		
	});
	
	$('#go4btn').click(function(){
		
		$('#registerform').submit();
		
	});
	
	$('#go5btn').click(function(){
		
		$('#registerform').submit();
		
	});
	
	$('#finishreg').click(function(){
		
		$('#registerform').submit();
		
	});
	
	$('#email').keyup(function(){ // Register.php sayfasında, email field'i
		
		$('#emailusing').css({'display':'none'});
		$('#emailerror').css({'display':'none'});
		
	});
	
	$('#sifre').keyup(function(){ // Register.php sayfasında, sifre field'i
		
		$('#passshort').css({'display':'none'});
		
	});
	
	$('#all_fr').click(function(){
	
		$(this).append('<span style="padding-left:10px;"><img src="http://localhost/kimbilirk/images/ajax-loader.gif" /></span>');
		
		var a = $('#uid').attr('title');
		
		$.ajax({
			
			type: 'POST',
			url: 'ajax_inc/index.php?pg=friends',
			data: 'act=all&id='+a,
			success: function(req){
				$('#all_fr').html($('#all_fr').attr('title'));
				$('#orta').html(req);
			}
			
		});
		
		return false;
		
	});
	
	$('#recent_fr').click(function(){
	
		$(this).append('<span style="padding-left:10px;"><img src="http://localhost/kimbilirk/images/ajax-loader.gif" /></span>');
		
		$.ajax({
			
			type: 'POST',
			url: 'ajax_inc/index.php?pg=friends',
			data: 'act=recent',
			success: function(req){
				$('#recent_fr').html($('#recent_fr').attr('title'));
				$('#orta').html(req);
			}
			
		});
		
		return false;
		
	});
	
	$('#savebasicsettings').click(function(){
	
		$('#changessavedload').fadeIn();
		$(this).attr('disabled', 'true');
		
		var d = $('#savebasicsettingsform').serialize() +'&loc_id='+ $('#scid1').attr('value') +'&born_id='+ $('#scid2').attr('value') +'&act=sbset';
		
		$.ajax({
			
			type: 'POST',
			url: 'ajax_inc/index.php?pg=process',
			data: d,
			success: function(req){
				if(req == 1){
					
					$('#changessavedload').hide();
					$('#changessaved').fadeIn();
					$(this).attr('disabled', 'false');
					
				}
			}
			
		});
		
	});
	
	$('#pphoto').mouseover(function(){
		
		$('#pphotolinks').show();
		
	});
	
	$('#pphoto').mouseout(function(){
		
		$('#pphotolinks').hide();
		
	});
	
	$('.albumbox').mouseover(function(){
	
		var a = $(this).attr('id');
		
		$('#edit_'+ a).show();
		
	});
	
	$('.albumbox').mouseout(function(){
	
		var a = $(this).attr('id');
		
		$('#edit_'+ a).hide();
		
	});
	
		
	$("#something").click( function(){
	   if( $(this).is(':checked') ) alert("checked");
	});
	
	
});

function stripquot(str) {
str=str.replace(/\\/g,'');
str=str.replace(/\'/g,'');
str=str.replace(/\"/g,'');
str=str.replace(/\0/g,'');
return str;
}

function rmval(a, b){
	
	$('#'+a).attr('value', '');
	$('#'+b).attr('value', '');
	
	$('#'+a).focus();
	
	return false;
	
}

function goURI(val){
	
	window.location = val;
	
}

function ldpic(a,b){
	
	if($('#'+b).val().length < 5){
		
		$("#sel-fl").dialog({
			modal: true,
			autoOpen: true,
			draggable: false,
			width:350,
			height: 130,
			hide: 'slide',
			resizable: false,
			buttons: {
				Tamam: function(){
					$(this).dialog('close');
				}
			}
		});
		
		return false;
	} else {
		
		$('#picupsuccess').hide();
		$('#changessavedload').css({'display':'block'});
		$('#selpic1').hide();
		$('#selpic2').hide();
		$('#sizeover').hide();
		
		return true;
	}
	
}

function rmshr(a){
	$("#del-shr").dialog({
		modal: true,
		autoOpen: true,
		draggable: false,
		width:550,
		hide: 'slide',
		resizable: false,
		buttons: {
			İptal: function(){
				$(this).dialog('close');
			},
			Kaldır: function(){
				$.ajax({
					
					type: 'POST',
					url: 'ajax_inc/index.php?pg=process',
					data: 'act=rmshr&a='+a,
					success: function(req){
						$('#f_'+a).fadeOut();
						$("#del-shr").dialog('close');
					}
					
				});
			}
		}
	});
	
	return false;
}

function rfrq(uid, type){
	
	$.ajax({
		
		type: 'POST',
		url: 'ajax_inc/index.php?pg=requests',
		data: 'act=response&uid='+uid+'&type='+type,
		success: function(req){
			if(req==1){
				$('#reqbtn-'+uid).hide();
				$('#reqresp-'+uid).fadeIn();
				$('#reqques-'+uid).hide();
				$('#reqbox-'+uid).css({'background':'#FFC'});
			} else {
				$('#reqbox-'+uid).fadeOut();
			}
		}
		
	});
	
	return false;
	
}

function shwfr(a, b, c){
	
	var t = $(c).attr('title');
	
	$.ajax({
		
		type: 'POST',
		url: 'ajax_inc/index.php?pg=friends',
		data: 'act='+b+'&id='+a+'&swtyp=2',
		success: function(req){
			$("#shw-fr").html(req);
		}
	
	});
	
	$("#shw-fr").dialog({
		modal: true,
		autoOpen: true,
		draggable: false,
		width:450,
		height:350,
		title: t,
		hide: 'slide',
		resizable: false,
		buttons: {
			Kapat: function(){
				$(this).dialog('close');
				$("#shw-fr").html('');
			}
		}
	});
	
	return false;
	
}

function shwntf(a){
	
	$('#ntfarea').show();
	
	$.ajax({
		
		type: 'POST',
		url: 'ajax_inc/index.php?pg=process',
		data: 'act=showntf',
		success: function(req){
			
			$('#ntfarea').html(req);
			$(a).fadeOut();
			
		}
		
	});
	
	return false;
	
}

function shwcm(a, b){
	
	if(b == 'y'){
		if($('#ta-'+a).attr('class') == 'c-'+a+'-0'){
			$('#comment-'+a).show();
			$('#ta-'+a).focus();
			$('#ta-'+a).attr('class', 'c-'+a+'-1');
			$('#commentmin-'+a).hide();
		} else if($('#ta-'+a).attr('class') == 'c-'+a+'-1'){
			$('#comment-'+a).hide();
			$('#ta-'+a).attr('class', 'c-'+a+'-0');
			$('#commentmin-'+a).show();
			$('#ta-'+a).val('');
		}
	} else if(b == 't') {
		
		if($('#ta-'+a).val().length == 0){
			$('#comment-'+a).hide();
			$('#ta-'+a).attr('class', 'c-'+a+'-0');
			$('#commentmin-'+a).show();
		}

	} else if(b == 'tmin'){
			
		$('#comment-'+a).show();
		$('#ta-'+a).focus();
		$('#ta-'+a).attr('class', 'c-'+a+'-1');
		$('#commentmin-'+a).hide();
		
	}
	
	return false;
	
	
}

function comment(i, u, t, p){
	
	var title = $('#ta-'+i).val();
	
	$('#cmbtn-'+i).attr('disabled', 'true');
	
	if(title.length > 0){
		
		$.ajax({
			
			type: 'POST',
			url: 'ajax_inc/index.php?pg=comment',
			data: 'i='+i+'&t='+t+'&p='+p+'&c='+title+'&u='+u,
			success: function(req){
				$('#cmarea-'+i).before(req);
				$('#cmbtn-'+i).removeAttr("disabled");
				$('#ta-'+i).val('');
				$('#comment-'+i).hide();
				$('#ta-'+i).attr('class', 'c-'+i+'-0');
				$('#commentmin-'+i).show();				
			}
			
		});
		
	}
	
	return false;
	
}

function shwallcm(i){
	
	$.ajax({
		
		type: 'POST',
		url: 'ajax_inc/index.php?pg=comment',
		data: 'i='+i+'&act=all',
		success: function(req){
			
			$('#cmarea-li-'+i).html(req);
			
		}
		
	});
	
	return false;
	
}

function enaltkat(){
	$('#altkat2').html('<td width="50%" align="right" valign="middle" class="name">&nbsp;</td><td width="50%" align="left" valign="middle" class="value"><img src="images/ajax-loader.gif" /></td>');
	$.ajax({
		type: 'POST',
		url: 'loadcat.php',
		data: 'cat='+ $(this).attr('value') +'&layer=3',
		success: function(req){
			$('#altkat2').html(req);
		}
	});
}

function editval(a){
	var origval = $(a).text();
	if($(a).text() != ''){
	$(a).html('<input type="text" id="editinput" value="'+ origval +'" onBlur="removeEditArea(this, \''+ stripquot(origval) +'\')" />');
	$('#editinput').focus();
	}
}

function removeEditArea(i, v){
	var val = $(i).attr('value');
	
	if(val != '')
		$(i).replaceWith(val);
	else
		$(i).replaceWith(v);
}

function share(i, t){
	
	$('#share').attr('disabled', 'true');
	var h = $('.bilgi .baslik').text();
	var l = $('.bilgi .link').text();
	var d = $('.bilgi .aciklama').text();
	var s = $('#share').val();
	
	$.ajax({
		
		type: 'POST',
		url: 'ajax_inc/index.php?pg=share',
		data: 'act=paylas&i='+i+'&t='+t+'&h='+h+'&l='+l+'&d='+d+'&s='+s,
		success: function(req){
			$('#share').removeAttr('disabled');
			$('#share').attr('value', '');
			$('.alan2').fadeOut(200);
			setTimeout(function(){
			
				$('.profilefeed').prepend(req);
				$('.alan2').html('');
				
				if($('.nopost').length){
					$('.nopost').remove();
				}
			}, 150);
			if(t == 1){
				$('.status').html(s);
			}
		}
		
		
	});
	
	return false;
}

function like(i, t, u){ // EKSİK
	
	if(u == 1){
		$('#youlike-'+i).fadeIn();
		$('#like-'+i).hide();
		$('#unlike-'+i).fadeIn();
	} else {
		$('#youlike-'+i).fadeOut();
		$('#unlike-'+i).hide();
		$('#like-'+i).fadeIn();
	}
	
	$.ajax({
		
		type: 'POST',
		url: 'ajax_inc/index.php?pg=like',
		data: 'i='+i+'&t='+t+'&u='+u,
		success: function(req){
			
		}
		
	});
	
	return false;
	
}

function rmfr(a, b){
	
	$('#del-fr').html($(b).attr('title'));
	
	$("#del-fr").dialog({
		modal: true,
		autoOpen: true,
		draggable: false,
		width:550,
		hide: 'slide',
		resizable: false,
		buttons: {
			İptal: function(){
				$(this).dialog('close');
			},
			Kaldır: function(){
				$.ajax({
					
					type: 'POST',
					url: 'ajax_inc/index.php?pg=process',
					data: 'act=rmfr&a='+a,
					success: function(req){
						if(req == 1){
							$('#fr_'+a).fadeOut();
							$("#del-fr").dialog('close');
							window.location = $(b).attr('href');
						}
					}
					
				});
			}
		}
	});
	
	return false;
	
}

function lookup(inputString, type, tbl) {
	if(inputString.length == 0) {
		// Hide the suggestion box.
		$('#suggestions'+type).hide();
	} else {
		$.post("rpc.php?t="+ type +"&tbl="+ tbl, {queryString: ""+inputString+""}, function(data){
			if(data.length > 0) {
				$('#suggestions'+type).show();
				$('#autoSuggestionsList'+type).html(data);
			} else {
				setTimeout("$('#suggestions"+type+"').fadeOut(100);", 20);
			}
		});
	}
} // lookup
	
function fill(thisValue, id, type) {
	$('#inputString'+type).val(thisValue);
	$('#scid'+type).attr('value', id);
	setTimeout("$('#suggestions"+type+"').hide();", 200);
}

function aqc(l){
	
	if(l == 1){
		$('#subcat2').html('');
	}
	
	$('#subcat'+l).show();
	var cat = $('#cat'+l).attr('value');
	
	$.ajax({
		
		type: 'POST',
		url: 'ajax_inc/index.php?pg=process',
		data: 'cat='+cat+'&l='+l+'&act=catlayer',
		success: function(req){
			$('#subcat'+l).html(req);
		}
		
	});
	
}

function anq(m){
	
	$('#anql').show();
	$('.inputd').attr('class', '');
	
	$.ajax({
		
		type: 'POST',
		url: 'ajax_inc/index.php?pg=process',
		data: 'm='+m+'&act=anq',
		success: function(req){
			$('#qend').before(req);
			$('#anql').hide();
		}
		
	});
	
	return false;
	
}

function aqctrl(){
	
	var c = $('#cat1').attr('value');
	
	if($('#qrulescheck').attr('checked')){
		if((typeof(c) === 'number' || typeof(c) === 'string') && c !== '' && !isNaN(c)){
			$('#addq').attr('value', 'ok');
			$('#addqbtn').attr('disabled', 'true');
			$('#soruekleform').submit();
		} else {
			$('#selcatalert').show();
			window.location = '#';
		}
	} else {
		$("#qralert").dialog({
			modal: true,
			autoOpen: true,
			draggable: false,
			width:550,
			hide: 'slide',
			resizable: false,
			buttons: {
				Tamam: function(){
					$(this).dialog('close');
				}
			}
		});
	}
	
}

function spm(i){
	
	$("#private-message").dialog({
		modal: true,
		autoOpen: true,
		draggable: false,
		width:550,
		hide: 'slide',
		resizable: false,
		buttons: {
			Gönder: function() {
				
				var h = $('#konu').val();
				var c = $('#mesaj').val();
				
				$.ajax({
				
					type: 'POST',
					url: 'ajax_inc/index.php?pg=process',
					data: 'act=sendpm&i='+i+'&h='+h+'&c='+c,
					success: function(req){
						$("#private-message").dialog('close');
					}
				
				});
			},
			İptal: function(){
				$(this).dialog('close');
			}
		}
	});

	return false;
	
}

function expand(i){
	
	$('.expand-'+i).show();
	$('#expandlink-'+i).remove();
	
	return false;
	
}

function reply(i){
	
	$('#replyloader').show();
	var c = $('#replytxt').val();
	
	$.ajax({
		
		type: 'POST',
		url: 'ajax_inc/index.php?pg=process',
		data: 'act=replymsg&i='+i+'&c='+c,
		success: function(req){

			$('#replyafter').before(req);
			$('#replytxt').attr('value', '');
			$('#replyloader').hide();
			
		}
		
	});
	
}

function rmthread(i, r){

	$('#rm-thread').dialog({
		modal: true,
		autoOpen: true,
		draggable: false,
		width:550,
		hide: 'slide',
		resizable: false,
		buttons: {
			İptal: function(){
				$(this).dialog('close');
			},
			Sil: function(){
				
				$.ajax({
					
					type: 'POST',
					url: 'ajax_inc/index.php?pg=process',
					data: 'act=rmthread&i='+i,
					success: function(req){
						if(r == 'in'){
							$('#rm-thread').dialog('close');
							window.location = 'messages.php';
						} else {
							$('#rm-thread').dialog('close');
							$('.thread-'+i).fadeOut();
						}
					}
					
				});
				
			}
		}
	});
	
	return false;

}

function dounread(i){
	
	$.ajax({
		
		type: 'POST',
		url: 'ajax_inc/index.php?pg=process',
		data: 'act=dounread&i='+i,
		success: function(req){
			if(req == 1)
				window.location = 'messages.php';
		}
		
	});
	
}

function shrpho(i){

	$("#shr-photo").dialog({
		modal: true,
		autoOpen: true,
		draggable: false,
		width:550,
		hide: 'slide',
		resizable: false,
		buttons: {
			İptal: function(){
				$(this).dialog('close');
			},
			Paylaş: function(){
				
				
				$(this).dialog('close');
				$("#photo-shrd").dialog({
					modal: true,
					autoOpen: true,
					draggable: false,
					width:550,
					hide: 'slide',
					resizable: false,
					buttons: {
						Kapat: function(){
							$(this).dialog('close');
						}
					}
				});
				
			} // Paylas btn fin
		}
	});
	
	return false;
}

function lookforbenzer(){

	var q = $('.inputd').val();
	
	
	$.ajax({
		
		type: 'POST',
		url: 'ajax_inc/index.php?pg=process',
		data: 'act=getbenzer&q='+q,
		success: function(req){
			
			$("#look-for-benz").html(req);
			
			$("#look-for-benz").dialog({
				modal: true,
				autoOpen: true,
				draggable: false,
				width:700,
				hide: 'slide',
				resizable: false,
				buttons: {
					Tamam: function(){
						$(this).dialog('close');
					}
				}
			});
		}
	
	});
	
}
