﻿







function pos_login_box()







{







	$('#login_form').css('left',$(window).width()/2-$('#login_form').width()/2);







	$('#login_form').css('top',$(window).height()/2-$('#login_form').height()/2);



}

function pos_reg_box()

{









	$('#reg_form').css('left',$(window).width()/2-$('#reg_form').width()/2);







	$('#reg_form').css('top',$(window).height()/2-$('#reg_form').height()/2);



	







}







function hide_login_box()







{







	$('#login_box').hide();







	window.scroll(1,1);







}







function hide_reg_box()







{







	$('#reg_box').hide();







	window.scroll(1,1);







}







function logout()







{







	$.cookie('dating_user','',{expires:-1});







	location.reload(true);







}







function send_message()







{







	var content=$('#textfield').val();







	var user=$.cookie('dating_user');







	var to=$.cookie('id');







	$.post('send_message.php',{u:user,c:content,t:to},function(data)







		{







			if (data=='okay')



			{

				window.setInterval(' window.location = "msg_sent.php"',1000);

				$.cookie('msg_sent','sent',{expires:1});

			}

			else if (data=='3msg')

			{

				alert('Mesaj göndermek için yeterli kontörünüz yok');

				window.location="message.php?id=1";

			}

			else if (data!='')

			{

				alert(data);

			}







		});







	if ($('#login_box').css('display')!='none')







	{







		 hide_login_box();







	}







	







}















function get_message()







{







	if ($.cookie('dating_user')=='' ||$.cookie('dating_user')==null)







	{







		// not logined	







		var note='Merhaba ziyaretçi. Hiç yeni mesajınız yok.';







		//		message-midd-pro-center







		$('.message-midd-pro-center').html('');







		$('.message-midd-center').text(note);







		







	}







	else







	{







		//logined







		//check for message







		var user=$.cookie('dating_user');





		var token=0;

		$.post('check_token.php',{u:user},function(num)

				{

					token=num;
					
					$.post('check_message.php',{u:user},function(data)




						
						

						{

							
							
							


							







							if (data!='')







							{







								//message-midd-pro-center







								







								var note='';

								 note=note+''+token+' kontörünüz kaldı !';



								


							
								$(data).appendTo('.message-midd-pro-center');







								$('.message-midd-center').text(note);







							}







							else







							{







								var note='';

								note=note+''+token+' kontörünüz var';





								$('.message-midd-pro-center').html(data);







								$('.message-midd-center').text(note);







							}







						});

				

					

				});

		



	



		







														 







	}







	







	







}







$(document).ready(function()







	{







		get_message()



		



	



		if ($.cookie('dating_user')!='' && $.cookie('dating_user')!=null)







		{







			$('#register').hide();







		}







		$('.background').click(function()







			{







				 hide_login_box();



				 hide_reg_box();







			});



		$('#show_login').click(function()



					{



						hide_reg_box();



						$('#login_box').show();







						 pos_login_box();



					});







		$('#send').click(function()







			{







				//function send message







				if ($('#textfield').val()=='')







				{







					alert('Mesajı yazmadınız');







				}







				else







				{







					//check for login







					if ($.cookie('dating_user')=='' || $.cookie('dating_user')==null)







					{







						//show login box







						$('#reg_box').show();







						 pos_reg_box();







						







					}







					else







					{







						//send message







						send_message();







					}







					







				}







			});







		$('#login_form input[name="login"]').click(function()







				{







					var user=$('#login_form input[name="username"]').val();







					var pass=$('#login_form input[name="password"]').val();







					if (user =='' || pass=='')







					{







						alert('Kullanıcı adı ve şifrenizi girin');







					}







					else







					{







						$.post('login.php',{u:user,p:pass},function(data)







									{







										

										





										if (data=='okay')







										{







											//set cookie







											$.cookie('dating_user',user,{expires:30});







											send_message();







										}







										else if (data=='fail')







										{







											alert('Hatalı kullanıcı adı veya şifre');







										}







										else if (data!='')







										{







											alert(data);







										}







									});







					}







				});







		$('#register input[name="login"]').click(function()







				{







					var user=$('#register input[name="username"]').val();







					var pass=$('#register input[name="password"]').val();







					if (user =='' || pass=='')







					{







						alert('Kullanıcı adı ve şifre seçin');







					}







					

					else if ($.cookie('reged')=='reged')

									{

										alert('Daha önce kayıt olmuşsunuz! Lütfen daha önce açtığınız hesapla giriş yapın');

									}



					else	



					{







						$.post('reg_ajax.php',{u:user,p:pass},function(data)







								{







									if (data=='fail')







									{







										alert('Bu kullanıcı alınmış. Başka seçin.');







									}





									else if (data=='okay' && ($.cookie('reged')=='' || $.cookie('reged')==null))







									{







										alert('Şu isimle kaydoldunuz: '+user+'. Giriş yapıyorsunuz.');







										$.post('login.php',{u:user,p:pass},function(data){});







										$.cookie('dating_user',user,{expires:30});

										$.cookie('reged','reged',{expires:10000});





										location.reload(true);







										







										







									}







									else if (data!='')







									{







										alert(data);







									}







									







							







								});







					}







				});



		



		



		



		



		$('#reg_form input[name="reg"]').click(function()







				{



					







					var user=$('#reg_form input[name="user"]').val();







					var pass=$('#reg_form input[name="pass"]').val();







					if (user =='' || pass=='')







					{







						alert('Kullanıcı adı ve şifre seçin');







					}







					else if ( $.cookie('reged')=='reged')

									{

										alert('Lütfen daha önce açtığınız hesapla giriş yapın.');

									}

					else

					{







						$.post('reg_ajax.php',{u:user,p:pass},function(data)







								{







									if (data=='fail')







									{







										alert('Bu kullanıcı alınmış. Başka seçin.');







									}

									

									else if (data=='okay' && ($.cookie('reged')=='' || $.cookie('reged')==null))





									{







										alert('Şu isimle kaydoldunuz: '+user+'. Giriş yapıyorsunuz.');







										$.post('login.php',{u:user,p:pass},function(data){});



										 $.cookie('reged','reged',{expires:10000});



										$.cookie('dating_user',user,{expires:30});



										



										if ($('#textfield').val()=='')



										{

											alert('Mesajı yazmadınız');

										}

										else

										{

											send_message();

										}

										







										







										







									}







									else if (data!='')







									{







										alert(data);







									}







									







							







								});







					}







				});







	});
