var cikti;

jlink = function (url,div ) {
	jQuery.ajax({ type: "GET", cache : false, url: url, success: function(msg){ $("#"+div).html(msg); } });
}

jform = function ( url, veri, div ) {
	jQuery.ajax({ type: "POST", cache : false, url: url, data: veri, success: function(msg){ $("#"+div).html(msg); } });
}

function yazdiriyor(kisibu,yaziyuor) {

	$.ajax({ type: "GET", cache : false, url: 'islemci.php?ap=yazdirma&kisi='+kisibu+'&islem='+yaziyuor, success: function(msg){

		if($('#oldyazidurum').html() != msg) {
			$('#yazidurum').html(msg);
			$('#oldyazidurum').html(msg);

		}
	} });
}


function startchat() {
	jform( "chat.php", $('#startchatim').serialize(), "sol" );
	$('#c_sent').attr("disabled",true);
	$('#c_sent').val('Lütfen bekleyiniz... Yükleniyor ...');

}

function yolla(mesaj) {

	if(mesaj.length>0) {
		jform("islemci.php","ap=sohbetet&mesaj="+mesaj,"sohbetislem");
		// $('#mesajalani').html('<textarea id="mesaji" onkeypress="handleEnter(this, event);"></textarea>');
		$('#mesaji').html(" ");
		document.getElementById('mesaji').focus();

	}

}

function sohbetara() {

	jlink("islemci.php?ap=sohbetyap","sohbet" );

}

function sohbet_baslat() {

	document.getElementById('buton1').value = 'Bitir';

	sohbetara();

}

function sohbet_bitir() {

	jConfirm('Sohbeti bitirmek istediğinizden emin misiniz ?', 'Sohbet Sonlandırılıyor', function(r) {

		if(r == true) {
			linkshare();
			document.getElementById('buton1').value = 'Başlat';
			document.getElementById('mesaji').value = '';
			document.getElementById('mesaji').disabled = true;
			document.getElementById('buton2').disabled = true;
			jlink("islemci.php?ap=sohbetbitir","sohbetislem" );

		}

	});
}

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (1) {
			curleft+=obj.offsetLeft;
			if (!obj.offsetParent) {
				break;
			}
			obj=obj.offsetParent;
		}
	} else if (obj.x) {
		curleft+=obj.x;
	}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (1) {
			curtop+=obj.offsetTop;
			if (!obj.offsetParent) {
				break;
			}
			obj=obj.offsetParent;
		}
	} else if (obj.y) {
		curtop+=obj.y;
	}
	return curtop;
}

function openmenu(id) {

	var gosterim = $('#'+id).css("display");

	if(gosterim == "none") {
		$('.infomenu').css("display","none");
		if(id == "resimim") {
			$('#resmindurumu').css('visibility','hidden');
		}
		$('#'+id).fadeIn(300);
		$('#'+id).css("display","block");

		$.session("sondivbilgiler-top", $('#'+id).css("top"));
		$.session("sondivbilgiler-left", $('#'+id).css("left"));
		$('#'+id).draggable();

		if(id == "resimim") {
			$('#resimim').css('top',bulyerY);
			$('#resimim').css('left',bulyerX);

		}

	} else {
		if(id == "resimim") {
			tekrarresim();

		}
		$('#'+id).fadeOut(300,function() { $('#'+id).css("top","auto");	$('#'+id).css("left","auto");});
		if(id == "resimim") {
			$('#resmindurumu').css('visibility','visible');
		}
		$('.infomenu').css("display","none");
	}
}


function bilgiguncelle(datab) {
	$('#bilgigunsonuc').animate({ opacity: 1 }, 1000 );
	$.ajax({ type: "POST", cache : false,  data: datab, url: 'islemci.php?ap=profilguncelle', success: function(msg){
		$('#bilgigunsonuc').html(msg);
		$('#bilgigunsonuc').animate({ opacity: 0 }, 3000 );
	} });

}

function aradigimkisi(datab) {

	$.ajax({ type: "POST", cache : false,  data: datab, url: 'islemci.php?ap=aradigimkisi', success: function(msg){

		if(msg == "hata1") {

			$('#bilgigunsonuc2').html('2. yaş alanı 1. yaş alanından büyük olmalıdır. Lütfen düzeltiniz');
			$('#bilgigunsonuc2').css('color','red');
			$('#bilgigunsonuc2').animate({ opacity: 1 }, 1000 );

		} else {

			$('#bilgigunsonuc2').html('Bilgileriniz başarı ile güncellenmiştir');
			$('#bilgigunsonuc2').append(msg);
			$('#bilgigunsonuc2').css('color','green');
			$('#bilgigunsonuc2').animate({ opacity: 1 }, 1000 );
			$('#bilgigunsonuc2').animate({ opacity: 0 }, 3000 );
		}


	} });
}

function arkaplan(renk,tur) {
	$('body').animate({ backgroundColor: renk }, 1000 );
	if(tur == "1") {
		$.ajax({ type: "POST", cache : false,  data: 'rengim='+renk, url: 'islemci.php?ap=renklendir', success: function(msg){ } });
	}
}

function arkaplansifirla() {
	$('body').animate({ backgroundColor: '#eee' }, 1000 );
	$.ajax({ type: "POST", cache : false,  data: 'rengim=', url: 'islemci.php?ap=renklendir'});
	jAlert('Arkaplan renk ayarınız sıfırlanmıştır', 'Bilgilendirme');

}

function resimiduzenle() {
	if($.browser.msie) {
		$('#resimim').css('margin-top',"0px");
	}

	$('#resimim').animate({ height: '362px', "left" : (($('#container').width()<800) ? "0px" : (($('#container').width()-750)/2)+"px")  , "top" : (($('#container').width()<800) ? ((680-362)/2)+"px" : (($('#container').height()-362)/2)+"px"), width: "750px" },"1000", "linear",

	function ()  {
		$('#resimim').css('top',(($('#container').width()<800) ? ((680-362)/2)+"px" : (($('#container').height()-362)/2)+"px"));
		$('#resimyuklemealani').html("<iframe src='resimkes.php?"+Math.random()+"' scrolling='no' frameborder=0 style='width:100%;height:340px;'></iframe>");
	} );
	$('#resimyujkl').remove();
}

function tekrarresim() {

	$('#resimyuklemealani').html('<input class="text" type="file" name="imagedgd" id="imagedgd" size="14" /><br><center style="color:red;font-size:9pt;width:170px;">Lütfen resim seçiniz otomatik yükleme başlıyacaktır</center><script>new AjaxUpload(\'imagedgd\', {  action: \'islemci.php?ap=resimyukle\',  name: \'imagedgd\',  autoSubmit: true,  responseType: false,  onChange: function(file, extension){},  onSubmit: function(file, extension) {$(\'#resimyuklemealani\').html(\'<br><center>Resminiz yükleniyor lütfen bekleyiniz kapatmayınız<br><img align="absmiddle" src="images/loading.gif"></center>\'); },  onComplete: function(file, response) {  resimiduzenle(); }});	</script>');
	$('#resimim').css("width","180px");
	$('#resimim').css("height","80px");
	if($.browser.msie) {
		$('#resimim').css("margin-top","-110px");
	}
	resimiim();
}

function profilresmim() {

	if($.browser.msie) {
	
	$.ajax({ type: "GET", cache : false, url: 'islemci.php?ap=profilresmim', success:

	function(msg){

		if(($('#benimresmim').attr('src').indexOf('pics/thumbnail_'+msg) < 0) && msg != " ") {
			$('#resimalanisil').fadeIn(30);
			$('#resimalanim').fadeOut(100);
			$('#resimdegisim').html('<img id="benimresmim" width="100" height="100" src="pics/thumbnail_'+msg+'">');
			$('#resimalanim').fadeIn(1000);
			$("#resmindurumu [value=\"1\"]").attr("selected","selected");
		} else if(msg == " ") {
			$('#resimdegisim').html('<img id="benimresmim" width="100" height="100" src="images/genericfriendicon.png">');
			DD_belatedPNG.fix('#benimresmim');
			$('#resimalanisil').fadeOut(30);
		}
	}});
	
	} else {
	
	$.ajax({ type: "GET", cache : false, url: 'islemci.php?ap=profilresmim', success:

	function(msg){

		if($('#benimresmim').attr('src') != 'pics/thumbnail_'+msg && msg != " ") {

			$('#resimalanisil').fadeIn(30);
			document.getElementById('benimresmim').src = 'pics/thumbnail_'+msg;
			$('#resimalanim').fadeIn(1000);
			$("#resmindurumu [value=\"1\"]").attr("selected","selected");
		} else if(msg == " ") {
			$('#benimresmim').attr('src','images/genericfriendicon.png');
			$('#resimalanisil').fadeOut(30);
		}
	}});	
	
	}
}

function resimdurum (durumu) {



	$.ajax({ type: "POST", cache : false,  data: 'durum='+durumu, url: 'islemci.php?ap=status', success: function(msg){

		if(msg == "true") {

			if(durumu == "1") {
				jAlert('Karşı taraf artık resminizi görecektir.',"Bilgilendirme");
			} else {
				jAlert('Karşı taraf artık resminizi görmeyecektir.',"Bilgilendirme");
			}

		}


	} });
}

function resimsil() {

	$.ajax({ type: "GET", cache : false, url: 'islemci.php?ap=resimsil', success: function(msg){

		if(msg == "true") {
			jAlert('Resminiz başarı ile silinmiştir.',"Bilgilendirme");
		}


	} });

}

function iconekle(ikon) {
	if(document.getElementById('mesaji').disabled == false) {
		insertAtCursor(document.vuduu.mesaji, ikon);
	}
}

function insertAtCursor(myField, myValue) {
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	}
	//MOZILLA/NETSCAPE support
	else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	} else {
		myField.value += myValue;
	}
}

resolutions = function (acilim) {

	$('#alt').height($(window).height()-130);
	$('#container').width($(window).width());
	$('#container').height($(window).height());
	// $('#c_cins, #c_yas, #c_sehir').css('visibility','hidden');

	if($.browser.msie) {

		var width1 = 187;
		
		if($.browser.version < 7) {
			var width2 = 237;
		} else {
			var width2 = 228;
		}

		var height1 = 90;
		if(browserfb) {
			var height2 = 220;
		} else {
			if($.browser.version > 7) {
				var height2 = 132;
			} else {
				var height2 = 137;

			}
		}

		if($(window).width()<956) {
			$('#sag').css('display','none');
			$('#sol').width($(window).width());
			$('#alt').width($(window).width()-10);
			$('#ust').width($(window).width()-10);
			$('#ust2').width($(window).width()-10);
		} else {
			$('#sag').css('display','block');
			$('#alt').css('width','100%');
			$('#ust').css('width','100%');
			$('#sol').width($(window).width()-width2);
		}


		$('#profilbilgi').css("margin-top","22px");
		$('#aradigimkisi').css("margin-top","22px");
		if($('#resimim').width()<700) {
			$('#resimim').css("margin-top","-110px");
		} else {
			$('#resimim').css("margin-top","0px");
		}

		$('#mesaji').css("height","57px");
		$('#mesaji').css("width","99%");
		$('#sag').height($(window).height()/100*85);

	} else if ($.browser.mozilla || $.browser.opera || $.browser.safari) {
		var width1 = 184;
		var width2 = 225;
		var height1 = 90;

		if(browserfb) {
			var height2 = 235;
		} else {
			var height2 = 132;
		}

		if($(window).width()<956) {
			$('#sag').css('display','none');
			$('#sagalt').css('display','none');
			$('#sol').width($(window).width());
			$('#alt').width($(window).width()-20);
			$('#ust').width($(window).width()-20);
			$('#ust2').width($(window).width()-20);
		} else {
			$('#sag').css('display','block');
			$('#sagalt').css('display','block');
			$('#alt').css('width','100%');
			$('#ust').css('width','100%');
			$('#sol').width($(window).width()-width2);
		}

	}




	$('#sag').width(width1);
	$('#sag').height($(window).height()/100*85);
	$('#sol').width($(window).width()-width2);

	$('#ust').height(height1);
	$('#alt').height($(window).height()-height2);


	if($.browser.opera) {
		//$('#sohbet').height($('#alt').height()-120);
		$('#sohbetx').height($('#alt').height()-120);
	} else {
		//$('#sohbet').height($('#alt').height()-110);
		$('#sohbetx').height($('#alt').height()-110);
	}

	// $('#preloader').fadeOut(300);
	// $('#c_cins, #c_yas, #c_sehir').css('visibility','visible');

	if(acilim == "1") {
		//	$("#container").animate({     opacity: 1  }, 1000, "linear", function(){   }  );
		renkkodu();

	}

}

$(window).bind('resize', function() {
	resolutions(0);
});
$(window).bind('load', function() {
	resolutions(1);

});