// JavaScript Document

$(document).ready(function() {
	
	$('input').focus(function() {
		if (this.className != 'sty') {												
		$(this).parents("div:first").addClass('actix');
		}
	});

	$('input:button').focus(function() {
		$(this).parents("div:first").removeClass('actix');
	});

	$('input:submit').focus(function() {
		$(this).parents("div:first").removeClass('actix');
	});

	$('input').blur(function() {
		$(this).parents("div:first").removeClass('actix');
	});
	

	// METİN FOCUS ***********************************	
		$('input[type="text"],textarea').focus(function() {
			if (this.className != 'stx') {												
				if (this.value == this.defaultValue){
					this.value = '';
				}
				if(this.value != this.defaultValue){
				//	this.select();
				}
			}
		
		});
		$('input[type="text"],textarea').blur(function() {
			if (this.className != 'stx') {												
				if ($.trim(this.value) == ''){
					this.value = (this.defaultValue ? this.defaultValue : '');
				}
			}
		});
	
	// SEPET GÖSTER ***********************************	
	$(function(){
	
		$("#sepetgoster").click(function () {
		  $("#sepetmenu").slideDown('normal');
		  $("#sepetgoster").hide();
		  $("#sepetgizle").show();
		  sepetdetaybul();
		});
		
		$("#sepetgizle").click(function () {
		  $("#sepetmenu").slideUp('fast');
		  $("#sepetgizle").hide();
		  $("#sepetgoster").show();
		   $("#sepetmenu").html("");
		});
		
	});
	
	sepetozetbul();

});

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// ÜRÜN LİSTELEME ****************************************************************
function durum1(divx) {
	$("#"+divx).html('<div class=yukleniyor>Yükleniyor, Lütfen Bekleyiniz<br /><img src=asset/std/loading.gif alt=Yükleniyor /></div>');
}

function gtliste(selObj){ 
	dtt = selObj.options[selObj.selectedIndex].value;
	getlist(dtt);
}


function getlist(dtt) {
	if (dtt!='') {
					
		$.ajax({
				type:"GET",
				url: "grup.asp",
				dataType: "application/x-www-form-urlencoded",
				data: dtt,
				async: false,
				ajaxStart: durum1('listejx'),
				success: function(msg){ $("#listejx").html(msg);}
			})
	}
}
// SİPARİŞ İŞLEMLERİ ****************************************************************
// *******************************************************************************







// SEPET İŞLEMLERİ ****************************************************************
function sepeteat(urun,adet) {
	
	str = "do=ekle&urun="+urun+"&adet="+adet
		$.ajax({
			type:"POST",
			url: "lib/module/sepet.asp",
			dataType: "application/x-www-form-urlencoded",
			data: str,
			async: false
		})
	sepetozetbul();
	sepetdetaybul();
}

function sepeteat2(urun) {
	
		var adet = $("#sp_adet").val();
		adet = parseFloat(adet); 
	
	str = "do=ekle&urun="+urun+"&adet="+adet
		$.ajax({
			type:"POST",
			url: "lib/module/sepet.asp",
			dataType: "application/x-www-form-urlencoded",
			data: str,
			async: false
		})
	sepetozetbul();
	sepetdetaybul();
}

function sepetozetbul() {
	
	$.ajax({
		type:"POST",
		url: "lib/module/sepet.asp",
		dataType: "application/x-www-form-urlencoded",
		data: "do=ozet",
		async: false,
		success: function(msg){
			
			if (msg == 'Boş<span style="width:25px;">&nbsp;</span>') {
				$("#sepetdugme").hide();
				$("#sepet").css({"text-align" : "center"});
				

			} else
				$("#sepetdugme").show();
				$("#sepetozet").html(msg);
				$("#sepet").css({"padding" : "13px 3px 5px 5px"});
			}
			
	})
	
}

function sepetdetaybul() {
	
	$.ajax({
		type:"POST",
		url: "lib/module/sepet.asp",
		dataType: "application/x-www-form-urlencoded",
		data: "do=detay",
		async: false,
		success: function(msg){ $("#sepetmenu").html(msg);}
	})
	
}

function sepetdetaygoster() {
	$.ajax({
		type:"POST",
		url: "sepet.asp",
		dataType: "application/x-www-form-urlencoded",
		data: "",
		async: false,
		success: function(msg){ $("#orta").html(msg);}
	})
}


function sepetcikar(id) {
	
	str = "do=cikar&no="+id
	
	$.ajax({
		type:"POST",
		url: "lib/module/sepet.asp",
		dataType: "application/x-www-form-urlencoded",
		data: str,
		async: false
	})
	
	sepetozetbul();
	sepetdetaybul();
}


function sepetcikar1(id) {
	
	str = "do=cikar&no="+id
	
	$.ajax({
		type:"POST",
		url: "lib/module/sepet.asp",
		dataType: "application/x-www-form-urlencoded",
		data: str,
		async: false
	})
	
	sepetozetbul();
	sepetdetaybul();
	sepetdetaygoster();
}



function sepetcikar2(id) {
	
	str = "do=cikar&no="+id
	
	$.ajax({
		type:"POST",
		url: "lib/module/sepet.asp",
		dataType: "application/x-www-form-urlencoded",
		data: str,
		async: false
	})
	
	sepetozetbul();
	sepetdetaybul();
	$("#sepetmenu").slideUp('fast');
	$("#sepetgizle").hide();
	$("#sepetgoster").show();
	$("#sepetmenu").html("");
	
	
}


function sepetadet(id,adet) {
	
	str = "do=adet&no="+id+"&adet="+adet
	
	$.ajax({
		type:"POST",
		url: "lib/module/sepet.asp",
		dataType: "application/x-www-form-urlencoded",
		data: str,
		async: false
	})
	
	sepetozetbul();
	sepetdetaybul();
	sepetdetaygoster();
}


// SEPET İŞLEMLERİ ****************************************************************
// *******************************************************************************


function gtab(tab) {
	
	$("#tab_aciklama").removeClass('active');	
	$("#tab_teknikbilgi").removeClass('active');	
	$("#tab_taksit").removeClass('active');	
	
	$("#icerik_aciklama").hide();
	$("#icerik_teknikbilgi").hide();
	$("#icerik_taksit").hide();
	
	$("#icerik_"+tab).show();
	$("#tab_"+tab).addClass('active');	
	
	if (tab=="taksit") {
		taksitbul();
	}
	
}

function taksitgetir() {
	taksitbul();
	taksitenaz();
}


function taksitenaz() {
		fyt = $("#sp_fiyat").val();
		var adet = $("#sp_adet").val();
		fyt = parseFloat(fyt); 
		adet = parseFloat(adet); 
		snc = fyt * adet
		str = "do=enaztaksit&fiyat="+snc
		$.ajax({
				type:"POST",
				url: "lib/module/taksit.asp",
				dataType: "application/x-www-form-urlencoded",
				data: str,
				async: false,
				success: function(msg){ $("#enaztaksit").html(msg);}
			})
}

function taksitbul() {
	
		fyt = $("#sp_fiyat").val();
		var adet = $("#sp_adet").val();
		fyt = parseFloat(fyt); 
		adet = parseFloat(adet); 
		snc = fyt * adet
		str = "do=tablo&fiyat="+snc
		$.ajax({
				type:"POST",
				url: "lib/module/taksit.asp",
				dataType: "application/x-www-form-urlencoded",
				data: str,
				async: false,
				success: function(msg){ $("#icerik_taksit").html(msg);}
			})
}

function odemetaksitbul() {
	
		fyt = $("#odemetoplam").val();
		str = "do=tablo&fiyat="+fyt
		$.ajax({
				type:"POST",
				url: "lib/module/taksit.asp",
				dataType: "application/x-www-form-urlencoded",
				data: str,
				async: false,
				success: function(msg){ $("#taksittablox").html(msg);}
			})
}

function odemetaksitozetbul() {
	
		fyt = $("#odemetoplam").val();
		tks = $("#taksitsay").val();
		krt = $("#karttip").val();
		str = "do=odemeozet&fiyat="+fyt+"&taksit="+tks+"&kart="+krt
		$.ajax({
				type:"POST",
				url: "lib/module/taksit.asp",
				dataType: "application/x-www-form-urlencoded",
				data: str,
				async: false,
				success: function(msg){$("#lbltaksitsay").html(msg);}
			})
}


// ÜYE KAYIT  //////////////////////////////////////////////////////



function uyekayit() {
	
	var durum = 0
	
	var fn1 = new LiveValidation( 'eposta', {validMessage: "+"} );
	fn1.add( Validate.Presence, { failureMessage: "-" } );
	fn1.add( Validate.Length, { minimum: 8, tooShortMessage: "-"} );
	fn1.add( Validate.Email, { failureMessage: "-" } );
	
	var fn2 = new LiveValidation( 'sifre' );
	fn2.add( Validate.Length, { minimum: 6, maximum: 10, tooShortMessage: "-", tooLongMessage: "-" } );
	fn2.add( Validate.Presence, { failureMessage: "-" } );
	
	var fn3 = new LiveValidation( 'sifre2' );
	fn3.add( Validate.Confirmation, { match: 'sifre', failureMessage: "-" } );
	fn3.add( Validate.Length, { minimum: 6, maximum: 10, tooShortMessage: "-", tooLongMessage: "-" } );
	fn3.add( Validate.Presence, { failureMessage: "-" } );
	
	var fn4 = new LiveValidation( 'ad' );
	fn4.add( Validate.Length, { minimum: 3, tooShortMessage: "-"} );
	fn4.add( Validate.Presence, { failureMessage: "-" } );
	
	var fn5 = new LiveValidation( 'soyad' );
	fn5.add( Validate.Length, { minimum: 3, tooShortMessage: "-"} );
	fn5.add( Validate.Presence , { failureMessage: "-" } );
	
	var fn6 = new LiveValidation( 'ceptel' );
	fn6.add( Validate.Presence, { failureMessage: "-" }  );
	
	var areAllValid = LiveValidation.massValidate( [ fn1, fn2, fn3, fn4, fn5, fn6 ]);
	
	if (areAllValid ) {
		durum = 1401;
		if (epostakontrol()) {
			var str = $("#kayit").serialize();
			str = "do=kayit&"+str
			
			$.ajax({
					type:"POST",
					url: "lib/module/uye.asp",
					dataType: "application/x-www-form-urlencoded",
					data: str,
					async: false,
					success: function(msg){durum = msg;}
			})

		}
			return durum;
	
	} 
}


function uyesifre() {
	
	var durum = 0
	
	var fn1 = new LiveValidation( 'esifre' );
	fn1.add( Validate.Length, { minimum: 6, maximum: 10, tooShortMessage: "-", tooLongMessage: "-" } );
	fn1.add( Validate.Presence, { failureMessage: "-" } );
	
	var fn2 = new LiveValidation( 'sifre1' );
	fn2.add( Validate.Length, { minimum: 6, maximum: 10, tooShortMessage: "-", tooLongMessage: "-" } );
	fn2.add( Validate.Presence, { failureMessage: "-" } );
	
	var fn3 = new LiveValidation( 'sifre2' );
	fn3.add( Validate.Confirmation, { match: 'sifre1', failureMessage: "-" } );
	fn3.add( Validate.Length, { minimum: 6, maximum: 10, tooShortMessage: "-", tooLongMessage: "-" } );
	fn3.add( Validate.Presence, { failureMessage: "-" } );


	var areAllValid = LiveValidation.massValidate( [ fn1, fn2, fn3 ]);
	
	if (areAllValid ) {
		durum = 1405;
			
			var esf = $("#esifre").val();
			var sf1 = $("#sifre1").val();
			var sf2 = $("#sifre2").val();
			
			str = "do=sifre&esf="+esf+"&sf1="+sf1+"&sf2="+sf2
			
			$.ajax({
					type:"POST",
					url: "lib/module/uye.asp",
					dataType: "application/x-www-form-urlencoded",
					data: str,
					async: false,
					success: function(msg){durum = msg;}
			})

			return durum;
	} 
}


function uyeguncelle() {
	
	var durum = 0
	
	var fn4 = new LiveValidation( 'ad' );
	fn4.add( Validate.Length, { minimum: 3, tooShortMessage: "-"} );
	fn4.add( Validate.Presence, { failureMessage: "-" } );
	
	var fn5 = new LiveValidation( 'soyad' );
	fn5.add( Validate.Length, { minimum: 3, tooShortMessage: "-"} );
	fn5.add( Validate.Presence , { failureMessage: "-" } );
	
	var fn6 = new LiveValidation( 'ceptel' );
	fn6.add( Validate.Presence, { failureMessage: "-" }  );
	
	var areAllValid = LiveValidation.massValidate( [ fn4, fn5, fn6 ]);
	
	if (areAllValid ) {
		durum = 1404;
			var str = $("#kayit").serialize();
			str = "do=guncelle&"+str
			
			$.ajax({
					type:"POST",
					url: "lib/module/uye.asp",
					dataType: "application/x-www-form-urlencoded",
					data: str,
					async: false,
					success: function(msg){durum = msg;}
			})

			return durum;
	
	} 
}


function epostakontrol() {
	var eposta = $("#eposta").val();
	str = "do=epostakontrol&eposta="+eposta;
	var durum 
	
		$.ajax({
				type:"POST",
				url: "lib/module/uye.asp",
				dataType: "application/x-www-form-urlencoded",
				data: str,
				async: false,
				success: function(msg)
					{ if (msg=='1401') {durum = false} else {durum = true} }
		})
		return durum;
}

function hata(kod) {
	switch(kod)
	{
	case '1401':
	  var sonuc = 'Seçtiğiniz e-posta adresi sistemde kayıtlı.<br>Eğer daha önce kaydolmuşsanız lütfen <a href="uye.asp?s=sifre">Şifre Hatırlatma</a> servisini kullanın.';
	  err = true;
	  break;
	  
	case 1401:
	  var sonuc = 'Seçtiğiniz e-posta adresi sistemde kayıtlı.<br>Eğer daha önce kaydolmuşsanız lütfen <a href="uye.asp?s=sifre">Şifre Hatırlatma</a> servisini kullanın.';
	  err = true;
	  break;
	  
	case '1402':
	  var sonuc = 'Şifre Alanı Boş Bırakılamaz!';
	  err = true;
	  break;
	  
	case '1403':
	  var sonuc = 'Şifreler birbiriyle aynı olmalıdır!';
	  err = true;
	  break;
	  
	case '1404':
	  var sonuc = 'Lütfen gerekli alanları boş bırakmayın!';
	  err = true;
	  break;
	  
	case '1400':
	  var sonuc = 'Üye Kaydınız Başarıyla Sonuçlandı.<br /><a href="uye.asp">Üye Girişi</a> ni kullanarak sisteme giriş yapabilirsiniz.<br /><br /><strong id="sure">5</strong> sn. içinde Üye Girişi sayfasına yönlendirileceksiniz.';
	  err = false;
	  break;
	  
	case '1405':
	  var sonuc = 'Üye Bilgileriniz Başarıyla Güncellendi.';
	  err = false;
	  break;
	  
	  
	case '1406':
	  var sonuc = 'Eski ve Yeni şifreleriniz birbirinden farklı olmalıdır.';
	  err = true;
	  break;
	  
	case '1407':
	  var sonuc = 'Eski şifreniz doğru değil.<br />Lütfen kontrol edip tekrar deneyin.';
	  err = true;
	  break;
	  
	case '1408':
	  var sonuc = 'Şifreniz Başarıyla Değiştirildi.';
	  err = false;
	  break;
	  
	case '1409':
	  var sonuc = 'Lütfen gerekli alanları boş bırakmayın!';
	  err = true;
	  break;
	  
	case '1410':
	  var sonuc = 'Adresiniz Başarıyla Kaydedildi.';
	  err = false;
	  break;
	  
	  default:
	  err = false;
	  var sonuc = '';
	}
	
	
	if (kod==0) {
		$("#sonuc").hide();
	} else {
		
		if (sonuc!='') {
			$("#sonuc").show();
			$("#sonuc").show();
			$("#sonuc").html(sonuc);	
			if (err) {
				$("#sonuc").removeClass('highlight');
				$("#sonuc").addClass('error');
			} else {
				$("#sonuc").removeClass('error');
				$("#sonuc").addClass('highlight');
				
				if (kod=='1408') {
					$("#sifrekayit").hide();
				} else {
					$("#kayit").hide();
				}
				
				if (kod=='1400') {
				
					$(".info").hide();
					
					$("#sonuc").oneTime(5000, function() {
						window.location = "uye.asp";
					});
					
					var sure = 5;
					
					$("#sure").everyTime(1000,function(i) {
						sure = --sure;
						$(this).html(sure);
					});
				}
				
			}
		}
	}
}


// textarea limit ***********************************
(function($){$.fn.extend({limit:function(limit,element){var interval,f;var self=$(this);$(this).focus(function(){interval=window.setInterval(substring,100)});$(this).blur(function(){clearInterval(interval);substring()});substringFunction="function substring(){ var val = $(self).val();var length = val.length;if(length > limit){$(self).val($(self).val().substring(0,limit));}";if(typeof element!='undefined')substringFunction+="if($(element).html() != limit-length){$(element).html((limit-length<=0)?'0':limit-length);}";substringFunction+="}";eval(substringFunction);substring()}})})(jQuery);




function pausescroller(content, divId, divClass, delay){
this.content=content //message array content
this.tickerid=divId //ID of ticker div to display information
this.delay=delay //Delay between msg change, in miliseconds.
this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
this.hiddendivpointer=1 //index of message array for hidden div
document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
var scrollerinstance=this
if (window.addEventListener) //run onload in DOM2 browsers
window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
else if (window.attachEvent) //run onload in IE5.5+
window.attachEvent("onload", function(){scrollerinstance.initialize()})
else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize=function(){
this.tickerdiv=document.getElementById(this.tickerid)
this.visiblediv=document.getElementById(this.tickerid+"1")
this.hiddendiv=document.getElementById(this.tickerid+"2")
this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
this.getinline(this.visiblediv, this.hiddendiv)
this.hiddendiv.style.visibility="visible"
var scrollerinstance=this
document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
if (window.attachEvent) //Clean up loose references in IE
window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup=function(){
var scrollerinstance=this
if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+5)){
this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-5+"px"
this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-5+"px"
setTimeout(function(){scrollerinstance.animateup()}, 50)
}
else{
this.getinline(this.hiddendiv, this.visiblediv)
this.swapdivs()
setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs=function(){
var tempcontainer=this.visiblediv
this.visiblediv=this.hiddendiv
this.hiddendiv=tempcontainer
}

pausescroller.prototype.getinline=function(div1, div2){
div1.style.top=this.visibledivtop+"px"
div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage=function(){
var scrollerinstance=this
if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
setTimeout(function(){scrollerinstance.setmessage()}, 100)
else{
var i=this.hiddendivpointer
var ceiling=this.content.length
this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
this.animateup()
}
}

pausescroller.getCSSpadding=function(tickerobj){ //get CSS padding value, if any
if (tickerobj.currentStyle)
return tickerobj.currentStyle["paddingTop"]
else if (window.getComputedStyle) //if DOM2
return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
else
return 0
}


