// JavaScript Document

var lastSSSID=0;

var lastTabID='';

var selectedPayType=0;

var lastFocusedId = '';

var urunSepeteEkleAdet = 1;

var secimURL = '';

// Web20 Template Fonksiyonları

var totalTopMenuItems = 0;



function sepetEkleKontrol() { return true; }



function updateAnaResim(url,width)

{

	$('.lightbox:first').attr('href',url);

	$('.lightbox:first img').attr('src','include/resize.php?path='+url+'&width='+width);

}



function uyelikIptal(str)

{

	if(confirm(str)) window.location.href = 'page.php?act=logout&remove=true';	

}



function updateOptionList(obj,stok)

{

	if ($(obj) == null || stok == '') return;

	$(obj).find('option').remove();

	var maxSatis = $(obj).parent().attr('max');

	if (maxSatis)

		stok= Math.min(stok,maxSatis);

	for(var i=0;i<=stok;i++)

	{

		if (i) 

			$('<option>'+i+'</option>').appendTo(obj);	

	}

}



function updateUrunSecim(urunID,varID,varName,widthDetay,widthList,obj)

{

	if ($(obj).attr('disabled') == 'disabled')

	{

		alert('İlgili seçim stokta bulunmamaktadır.');	

		return false;

	}

	updateOptionList('.urunSepeteEkleAdet',$(obj).attr('stok'));

	$(obj).parent().find('li').removeClass('selected');

	$(obj).addClass('selected');	

	$('#urunSecim_'+varID).val(varName);

	updateSecimURL();

	varID = varID.replace(/ozellik/i,'').replace(/detay/i,'');

	var url = 'include/ajaxLib.php?act=urunSecenekSecim&urunID='+urunID+'&urunVarID='+varID+'&urunVarName='+varName+'&r='+ Math.floor(Math.random()*99999);

	 $.ajax({

	  'url': url,

	  success: function(data) 

			   { 

					var obj = jQuery.parseJSON(data);

					var url = '';

					if (obj.resim1) $('#urunResimListContainer li').hide();

					if (obj.resim1)

					{

						url = 'images/urunler/var/'+obj.resim1;

						$('.lightbox:first').attr('href',url);

						$('.lightbox:first img').attr('src','include/resize.php?path='+url+'&width='+widthDetay);

						$('#urunResimListContainer img:first').attr('src','include/resize.php?path='+url+'&width='+widthList);

						$('#urunResimListContainer img:first').parent().parent().show();

						$('#urunResimListContainer img:first').parent().attr('onclick','');

						$('#urunResimListContainer img:first').parent().click(function() { updateAnaResim('images/urunler/var/'+obj.resim1,widthDetay); });

					}

					if (obj.resim2)

					{

						url = 'images/urunler/var/'+obj.resim2;

						$('#urunResimListContainer img:eq(1)').attr('src','include/resize.php?path='+url+'&width='+widthList);

						$('#urunResimListContainer img:eq(1)').parent().parent().show();

						$('#urunResimListContainer img:eq(1)').parent().attr('onclick','');

						$('#urunResimListContainer img:eq(1)').parent().click(function() { updateAnaResim('images/urunler/var/'+obj.resim2,widthDetay); });

					}

					if (obj.resim3)

					{

						url = 'images/urunler/var/'+obj.resim3;

						$('#urunResimListContainer img:eq(2)').attr('src','include/resize.php?path='+url+'&width='+widthList);

						$('#urunResimListContainer img:eq(2)').parent().parent().show();

						$('#urunResimListContainer img:eq(2)').parent().attr('onclick','');

						$('#urunResimListContainer img:eq(2)').parent().click(function() { updateAnaResim('images/urunler/var/'+obj.resim3,widthDetay); });

					}

					if (obj.resim4)

					{

						url = 'images/urunler/var/'+obj.resim4;

						$('#urunResimListContainer img:eq(3)').attr('src','include/resize.php?path='+url+'&width='+widthList);

						$('#urunResimListContainer img:eq(3)').parent().parent().show();

						$('#urunResimListContainer img:eq(3)').parent().attr('onclick','');

						$('#urunResimListContainer img:eq(3)').parent().click(function() { updateAnaResim('images/urunler/var/'+obj.resim4,widthDetay); });

					}

					if (obj.resim5)

					{

						url = 'images/urunler/var/'+obj.resim4;

						$('#urunResimListContainer img:eq(4)').attr('src','include/resize.php?path='+url+'&width='+widthList);

						$('#urunResimListContainer img:eq(4)').parent().parent().show();

						$('#urunResimListContainer img:eq(4)').parent().attr('onclick','');

						$('#urunResimListContainer img:eq(4)').parent().click(function() { updateAnaResim('images/urunler/var/'+obj.resim5,widthDetay); });

					}					

			   }

	  });

	//  window.open(url);	

}



function sepeteEkle(urunID,obj)

{

	$(obj).removeClass('hover');

	var url = 'include/ajaxLib.php?act=sepetEkle&urunID=' + urunID + '&adet=1'; 

	$.get(url, function(data) { 

			$(obj).css({'backgroundImage':'url(/templates/tazebunlar/images/form_SepeteEklendi.gif)'});  

			$(obj).html('<img src="/templates/tazebunlar/images/form_SepeteEklendi.gif" />');

			url = 'include/ajaxLib.php?act=sepet';

			$.get(url, function(data) {

				$('#sepetGoster').html(data);	

				var sayi = $('.open').text().replace(/\(/i,'').replace(/\)/i,'');

				sayi++;

				$('.open').text('('+sayi+')');

				

			});			

			

	});

	

}



function changeSPSlide(obj,num,total)

{

	num = Math.round(num % total);

	$(obj).find(".spSlide").hide('fast');

	$(obj).find(".spSlide:eq("+num+")").fadeIn('slow');

	setTimeout(function() { changeSPSlide(obj,(num + 1),total) },5000);

}



function tckimlikkontorolu(tcno) 

{ 

	var tckontrol,toplam; tckontrol = tcno; tcno = tcno.value;    

	toplam = Number(tcno.substring(0,1)) + Number(tcno.substring(1,2)) + Number(tcno.substring(2,3)) + Number(tcno.substring(3,4)) + Number(tcno.substring(4,5)) + Number(tcno.substring(5,6)) + Number(tcno.substring(6,7)) + Number(tcno.substring(7,8)) + Number(tcno.substring(8,9)) + Number(tcno.substring(9,10));    

	strtoplam = String(toplam);    

	onunbirlerbas = strtoplam.substring(strtoplam.length, strtoplam.length-1);    

	if(onunbirlerbas == tcno.substring(10,11)) 

	{     

		return true; 

	} 

	else

	{     

		return false; 

	} 

} 





function teklifFiyatGuncelle()

{

	var ToplamKDVDahil = 0;

	var ToplamKDVHaric = 0;

	var KDVDahil = 0;

	var KDVHaric = 0;

	var KDV = 0;

	$('table.teklif tr.teklifSatir').each(function() 

											{

												KDV =  $(this).find('.kdv').text().replace(/\%/i,'');

												KDVDahil = ($(this).find('.adet').val() * $(this).find('.fiyat').val().replace(/,/i,''));

												KDVHaric = (KDVDahil / (1 + (KDV / 100)));

												ToplamKDVDahil+=KDVDahil; 

												ToplamKDVHaric+=KDVHaric;

												$(this).find('.toplam').text(moneyFormat(KDVDahil));

											});

	$('#kdvdahil').html(moneyFormat(ToplamKDVDahil));

	$('#kdvharic').html(moneyFormat(ToplamKDVHaric));

	$('#toplamkdv').html(moneyFormat((ToplamKDVDahil - ToplamKDVHaric)));

	$('#toplamytl').html(moneyFormat(ToplamKDVDahil));

	$('#dolar').html(moneyFormat((ToplamKDVDahil / dolar)));

	$('#euro').html(moneyFormat((ToplamKDVDahil / euro)));	

}



$(document).ready(function() {

	$('input[name$="cvv2"]').click(function() { $('#numpad').hide(); });

	$('span.button').parents('form:first').submit(function() { $(this).find('span.button').html(lang_lutfenBekleyin); });

	$('li[disabled=disabled]').addClass('disabled');

	$("table.teklif input").keyup(teklifFiyatGuncelle);

	$('#arttir,#azalt').click(function() {

		var obj = this;

		$('table.teklif .fiyat').each(function() 

		{	 

			if($(obj).attr('id') == 'arttir') 

				$(this).val(moneyFormat($(this).val() * (1 + $('#oran').val() / 100)));

			else

				$(this).val(moneyFormat($(this).val() * (1 - $('#oran').val() / 100)));

		});

		teklifFiyatGuncelle();

	});

	/*

	$("input").keyup(function(e) {

		if(e.keyCode == 13) {

			if ($(this).closest("form").attr('class') != 'generatedForm') $(this).closest("form").submit(); 

		}

	});

	*/

	$('.MenuContainer').show();	

	$('.HarfListe .Harf:last').css({'borderRight':'none'});	

	$('.SubMenuItem a').each(function() { $(this).css({'marginLeft':($(this).attr('level') * 10) + 'px'}); if ($(this).attr('level') == 1) $(this).css({'padding':'0','background':'none'}); });

	$('.FilitreKategori').css({'width':(($('.FilitreKategoriListe').width() / 3) - 40) +'px'});	

	$('body').css('overflowX','hidden');

	$('.spSlides').each(

		function() {

			var totalSlides = $(this).find('.spSlide').size();

			changeSPSlide(this,0,totalSlides);

		}

	);	

						   

	$('#detailSearchKey,.detailSearchKey').autocomplete('include/ajaxLib.php?act=arama',{

			minChars: 2,

			width: 300,

			multiple: false,

			matchContains: true,

			formatItem: formatItem,

			formatResult: formatResult,

			selectFirst:false

	});	

	var zoomOptions = {preloadText:'Yükleniyor'};

	

	//$('.lightbox:first').jqzoom(zoomOptions).removeClass('lightbox');

	//$('.lightbox').lightBox({fixedNavigation:false,imageBtnClose: 'images/lightbox-btn-close.gif',imageLoading:'images/lightbox-ico-loading.gif',containerResizeSpeed:350,txtOf:' / ',txtImage:$(this).attr('title')});

	if ($('#imgSepetGoster').position() != null) $("#sepetGoster").css({'top':($('#imgSepetGoster').position().top + $('#imgSepetGoster').height() + 3) + 'px','left':($('#imgSepetGoster').position().left - 400) + $('#imgSepetGoster').width() + 'px'});	

	$('#imgSepetGoster').hover(						   

		function() { $('#sepetGoster').slideDown(200); },

		function() { $('#sepetGoster').slideUp(200); }

	);

	if ($('#imgLoginGoster').position() != null) $("#loginGoster").css({'top':($('#imgLoginGoster').position().top + $('#imgLoginGoster').height() + 3) + 'px','left':($('#imgLoginGoster').position().left - 200) + $('#imgLoginGoster').width() + 'px'});

	$('#imgLoginGoster').toggle(						   

		function() { $('#loginGoster').slideDown(200); },

		function() { $('#loginGoster').slideUp(200); }

	);	

	$('.imgCaptchaRefresh').click(function() { $(this).parent().find('.imgCaptcha').attr({'src':'include/create_captcha.php?u=1&' + Math.random()}) });

	$('#gf_city,#gf_city2').change(function() { formCityChange(this) });	

	$('#gf_semt').change(

		function() {

			if (!$('#gf_semt2').html()) return;

			var errorID = $(this).attr('id').replace(/gf_/i,'error_'); 

			$('#'+errorID).text('');

			$('.generatedForm .button').show();

			if ($(this).find('option:selected').attr('kargo') == 0) 

			{

				$('#'+errorID).text(' Bu ilceye gonderimimiz yoktur!');

				$('.generatedForm .button').hide();

			}

			if ($(this).find('option:selected').attr('fiyatfarki') != 0) 

			{

				$('#'+errorID).text(' Bu ilceye +'+$(this).find('option:selected').attr('fiyatfarki')+' TL kargo farki uygulanmaktadır.');

			}

		}

	);

	if ($('#gf_city').html()) formCityChange($('#gf_city'));

	

	$('.fillAddress').change(

		function() 

		{

			var preFix = $(this).attr('addressPrefix');

			var pars = 'act=addressList&adresID='+$(this).val();

			$.ajax({

			  url: 'include/ajaxLib.php?' + pars,

			  success: function(data) 

					   { 

							var dataArray = data.split('||');

							$('#gf_address'+preFix).val(dataArray[0]);

							$('#gf_city'+preFix).val(dataArray[1]);

							var pars = 'act=town&cityID='+dataArray[1];

							$.ajax({

							  url: 'include/ajaxLib.php?' + pars,

							  success: function(data) 

									   { 

											$('#gf_semt'+preFix).html(data);

											$('#gf_semt'+preFix).val(dataArray[2]);

									   }

							});

							

					   }

			});									 

		}

	);

	$('.sepeteEkleAdet').disableTextSelect().click(function() { $(this).val(''); });

	$('.sepeteEkleAdet[max=0]').attr('disabled','disabled');

	$('.sepeteEkleAdet').keyup(function(e) 

        {

            var key = e.charCode || e.keyCode || 0;  

			var total = ($(this).val() + '' + String.fromCharCode(key)); 

            var OK = ( 

                key == 8 ||  

                key == 9 || 

                key == 46 || 

                (key >= 37 && key <= 40) || 

                (key >= 48 && key <= 57) || 

                (key >= 96 && key <= 105)); 

			if (is_int(total)) {

				OK =true;

				urunSepeteEkleAdet = total;

				return true; 

			}

			if (OK) {

				if (parseInt(total) > $(this).attr('max')) 

				{	

					$(this).val($(this).attr('max'));

					alert(lang_urunStoguAsanDeger);

					urunSepeteEkleAdet = $(this).val();

					return false;

				}

				urunSepeteEkleAdet = total;

				return true;	

			}

			else return false;

        });

	$('.urunSecimTable select').change(updateSecimURL);

	updateSecimURL();

});



function updateSecimURL()

{

	if ($('#urunSecim_ozellik1detay').val()) secimURL = 'ozellik1detay=' + $('#urunSecim_ozellik1detay').val();

	if ($('#urunSecim_ozellik2detay').val()) secimURL += '&ozellik2detay=' + $('#urunSecim_ozellik2detay').val();

	if ($('#urunSecim_ozellik3detay').val()) secimURL += '&ozellik3detay=' + $('#urunSecim_ozellik3detay').val();

	if ($('#urunSecim_ozellik4detay').val()) secimURL += '&ozellik4detay=' + $('#urunSecim_ozellik4detay').val();

	if ($('#urunSecim_ozellik5detay').val()) secimURL += '&ozellik5detay=' + $('#urunSecim_ozellik5detay').val();

	//alert(secimURL);

}



function formCityChange(obj)

{

	var semtID = $(obj).attr('id').replace(/city/i,'semt');

	$('#'+semtID).html('<option>'+lang_yukleniyor+'</option>');

	var pars = 'act=town&cityID='+$(obj).val();

	$.ajax({

	  url: 'include/ajaxLib.php?' + pars,

	  success: function(data) 

			   { 

			   		var selected = $('#'+semtID).attr('selected');

					$('#'+semtID).html(data);

					$('#'+semtID+" option[value='"+selected+"']").attr('selected', 'selected'); 

			   }

	});

	return true;

}



function trim(stringToTrim) {

	return stringToTrim.replace(/^\s+|\s+$/g,"");

}



function checkCaptcha(formID) 

{

	var pars = 'txtCaptcha='+$('.' + formID + '_txtCaptcha').val();

	$.ajax({

	  url: 'include/ajaxLib.php?act=captcha',

	  type: 'POST',

	  data: pars,

	  success: function(data) 

			   {

				   	data = trim(data);

					if(data != 'true') alert('Güvenlik kodu hatalı.');

					else {

						$('#'+formID).submit();

					}

			   }

	});	

}

var ArkadasimaGonderWidth = 450;

var ArkadasimaGonderHeight = 440;



function arkadasimaGonderPopup(urunID) { window.open('popup.php?act=arkadasimaGonder&urunID='+urunID,'_blank','width='+ArkadasimaGonderWidth+',height='+ArkadasimaGonderHeight); return false; }



function formatItem(row) {

	return '<img src="include/resize.php?path=images/urunler/' + row[0] + '&width=20&height=20"> ' + row[1];

}

function formatResult(row) {

	return row[1];	

	//return row[0].replace(/(<.+?>)/gi, '');

}



function getHash(clientId , oid , amount , okUrl , failUrl ,islemtipi, taksit  ,rnd , storekey) {

	var hash='';

	var pars = 'act=getHash&clientId='+clientId+'&oid='+oid+'&amount='+amount+'&okUrl='+okUrl+'&failUrl='+failUrl+'&islemtipi='+islemtipi+'&taksit='+taksit+'&rnd='+rnd+'&storekey='+storekey;

	$.ajax({

	  url: 'include/ajaxLib.php?' + pars,

	  success: function(data) 

			   {

				    data = trim(data); 

					$('#hash').val(data);

			   }

	});

	return hash;

}





function getHashGaranti(strTerminalID , strOrderID , strAmount , strSuccessURL , strErrorURL ,strType, taksit  ,strStoreKey , SecurityData) {

	var hash='';

	var pars = 'act=getHashGaranti&strTerminalID='+strTerminalID+'&strOrderID='+strOrderID+'&strAmount='+strAmount+'&strSuccessURL='+strSuccessURL+'&strErrorURL='+strErrorURL+'&strType='+strType+'&taksit='+taksit+'&strStoreKey='+strStoreKey+'&SecurityData='+SecurityData;

	$.ajax({

	  url: 'include/ajaxLib.php?' + pars,

	  success: function(data) 

			   { 
			
			   	    data = trim(data);
			//	alert(data);
						$('#hash').val(data);

			   }

	});

	return hash;

}

// Üst Kategori Listesi Fonksiyonları



var topCatID=0;

var topMarkaID=0;

var urunCatInsert = '';

var urunMarkaInsert = '';

var userNameError = '';

var emailNameError = '';	



function  checkRegisterStatus() {

	return true;

	if (userNameError == 'false' && emailNameError == 'false') return true;

	

	//checkAvail($('#gf_username').val(),'username');

	checkAvail($('#gf_email').val(),'email');

	return false;

}



function checkAvail(value,type) {

	if (value) { 

		$.ajax({

		  url: 'include/ajaxLib.php?act=checkAvail&str='+value+'&type='+type,

		  success: function(data) 

		  		   { 

		  		   		if  (data != '' && data.length > 5 && !(lastFocusedId == 'gf_'+type) ) {  

							if (type=='username') { $('#gf_'+type).focus(); alert(lang_kullaniciAdiDahaOnceAlinmis);  userNameError = 'true';}

							if (type=='email' && userNameError != 'true') { $('#gf_'+type).focus(); alert(lang_epostaDahaOnceAlinmis); emailNameError = 'true'; }												

						}

						else {

							if (type=='username') { userNameError = 'false';}

							if (type=='email') { emailNameError = 'false'; }								

						}

						if (userNameError == 'false' && emailNameError == 'false') $('.generatedForm').submit();

		  		   }

		});

	}

}



function updateSubCats(sID) {	

	document.getElementById('opt2').options.length = 1;

	document.getElementById('opt2').options[0].text = 'Lütfen Bekleyin...';

	var url = 'include/ajaxLib.php?act=topSubCategory&catID='+sID;

	$.ajax({

	  url: url,

	  success: function(data) 

			   { 

					if  (data != '' && data.length > 5 && !(lastFocusedId == 'gf_'+type) ) { upOptions('opt2',data); }

			   }

	});

	updateSubMarka(sID);

}



function sistemTeklifeEkle() {

	var stop = false;

	var secilenUrunArray = new Array();	

	var secilenAdetArray = new Array();	

	for (var i=1;i<=toplamkategori;i++) {

		catID = catNum[i];

		var urunID = document.getElementById('urunSelected_'+catID).options[document.getElementById('urunSelected_'+catID).selectedIndex].value;

		var stok  = urunStok[urunID];

		if (stok <=0) {

			alert(lang_stoktaOlmayanUrunuEkleyemezsiniz);

			stop = true;

		}

		if (urunID > 0) 

		{

			secilenUrunArray[secilenUrunArray.length]=urunID;

			secilenAdetArray[secilenAdetArray.length]=$('#adet_'+catID).val();

		}

	}

	if (secilenUrunArray.length > 0 && stop == false) {	

		document.getElementById('SistemSepeteEkleDiv').innerHTML = '<table><tr><td><img src="images/ajax.gif"></td><td stlye="padding-left:10px;">'+lang_lutfenBekleyin+'</td></tr></table>';

		//alert(secilenUrunArray.length);

		for (var i=0;i<secilenUrunArray.length;i++) {

			var url = 'include/ajaxLib.php?act=teklifEkle&urunID=' + secilenUrunArray[i] + '&adet=' + secilenAdetArray[i];

			//window.open(url);

			if (i<(secilenUrunArray.length - 1)) {

					

					$.get(url, function(data) {  });			

			}

			else {

					$.get(url, function(data) {  window.location = 'page.php?act=tekliflerim'; });

			}			

		}

		window.location = 'page.php?act=tekliflerim';

	}

}



function teklifSepetEkle()

{

	$('.teklifInfoTable').html('<center><img src="images/ajax.gif"></center>');

	$('.teklifUrunID').each(function() { var url = 'include/ajaxLib.php?act=sepetEkle&urunID=' + $(this).text() + '&adet=' + $(this).parent().find('.adet').val(); $.get(url, function(data) { }); });

	setTimeout(function() { window.location = 'page.php?act=sepet' },3000);	

}



function sistemSepeteEkle() {

	var stop = false;

	var secilenUrunArray = new Array();	

	var secilenAdetArray = new Array();	

	for (var i=1;i<=toplamkategori;i++) {

		catID = catNum[i];

		var urunID = document.getElementById('urunSelected_'+catID).options[document.getElementById('urunSelected_'+catID).selectedIndex].value;

		var stok  = urunStok[urunID];

		if (stok <=0) {

			alert('Stokta bulunmayan ürünü sepete ekleyemezsiniz.');

			stop = true;

		}

		if (urunID > 0) 

		{

			secilenUrunArray[secilenUrunArray.length]=urunID;

			secilenAdetArray[secilenAdetArray.length]=$('#adet_'+catID).val();

		}

	}

	if (secilenUrunArray.length > 0 && stop == false) {	

		document.getElementById('SistemSepeteEkleDiv').innerHTML = '<table><tr><td><img src="images/ajax.gif"></td><td stlye="padding-left:10px;">'+lang_lutfenBekleyin+'</td></tr></table>';

		//alert(secilenUrunArray.length);

		for (var i=0;i<secilenUrunArray.length;i++) {

			var url = 'include/ajaxLib.php?act=sepetEkle&urunID=' + secilenUrunArray[i] + '&adet=' + secilenAdetArray[i];;

			if (i<(secilenUrunArray.length - 1)) {

					

					$.get(url, function(data) {  });			

			}

			else {

					$.get(url, function(data) {  setTimeout(function() { window.location = 'page.php?act=sepet'; },2000); });

			}			

		}

		// window.location = 'page.php?act=sepet';

	}

}



function updateSubMarka(sID) {

	document.getElementById('opt3').options.length = 1;

	document.getElementById('opt3').options[0].text = 'Lütfen Bekleyin...';

	var pars = 'act=topSubMarka&catID='+sID;

	$.ajax({

	  url: 'include/ajaxLib.php?act=topSubMarka&catID='+sID,

	  success: function(data) 

			   { 

					 upOptions('opt3',data);

			   }

	});	

	topCatID = (document.getElementById('opt2').selectedIndex >= 0?document.getElementById('opt2').options[document.getElementById('opt2').selectedIndex].value:document.getElementById('opt1').options[document.getElementById('opt1').selectedIndex].value);																																																		}



function upOptions(id,result) {

	document.getElementById(id).options.length = 0;

	var optsArray = result.split('||');

	for (var i=0;i<optsArray.length;i++) {

		var optDataArray = optsArray[i].split('$$');

		optDataArray[1] = optDataArray[1].replace('&#39;','\'');

		document.getElementById(id).options[document.getElementById(id).options.length] = new Option(optDataArray[1],optDataArray[0]);

	}

}



// Üst Kategori Listesi Fonksiyonları



var toplamkdvdahil = 0;

var toplamkdvharic = 0;

var toplamkdv = 0;



var KDVHaricArray = new Array();



function updateToplam() {

	var is = document.getElementsByTagName('input');

	toplamkdvdahil = 0;

	toplamkdvharic = 0;

	toplamkdv = 0;

	for (var i=0;i<is.length;i++) {

		if (is[i].id.indexOf('fiyat_') == 0) {

			var realID = is[i].id.replace('fiyat_','');

			toplamkdvdahil+=parseFloat(is[i].value);

			if (KDVHaricArray[realID]) toplamkdvharic+=parseFloat(KDVHaricArray[realID]);

		}

	}

	toplamkdv = toplamkdvdahil - toplamkdvharic;

	document.getElementById('kdvdahil').innerHTML = moneyFormat(toplamkdvdahil);

	document.getElementById('kdvharic').innerHTML = moneyFormat(toplamkdvharic);

	document.getElementById('toplamytl').innerHTML = moneyFormat(toplamkdvdahil);

	document.getElementById('toplamkdv').innerHTML = moneyFormat(toplamkdv);	

	document.getElementById('dolar').innerHTML = moneyFormat(toplamkdvdahil / dolar);

	document.getElementById('euro').innerHTML = moneyFormat(toplamkdvdahil / euro);

	if (document.getElementById('havaleile')) document.getElementById('havaleile').innerHTML =  moneyFormat(toplamkdvdahil - (toplamkdvdahil * havaleindirim));	

}



function updateKategori(urunID) {

	var url = 'include/ajaxLib.php';

	var catID=0;

	var data='';

	var myAjax = new Array();

	for (var i=2;i<=updatekategori;i++) {

		catID = catNum[i];

		var pars = 'act=updateKategori&urunID='+urunID+'&catID='+catID+'&randID='+Math.floor(Math.random()*1000000);

		var target = 'catNum_'+i;

		if (urunID > 0) {

			pcTopLoading(i);

			$('#' + target).load('include/ajaxLib.php?'+pars);

		}

		up('adet_'+catID,0);

		up('fiyat_'+catID,0);

		document.getElementById('detail_href_'+catID).href = '#';

		document.getElementById('detail_href_'+catID).target = '_self';

		ch('stok_'+catID,'stok_def_'+catID);		

		KDVHaricArray[catID]=0;

		//window.open('include/ajaxLib.php?'+pars);

	}

	

	updateToplam();

}



function pcTopLoading(i) {

	document.getElementById('catNum_'+i).innerHTML='<img src="images/ajax.gif"> '; 

}



			 



function pcTopLoaded(response,i) {

	document.getElementById('catNum_'+i).innerHTML=response.responseText; 

}



function updateFiyat(urunID,catID) {

	var fiyat = urunFiyat[urunID];

	var stok  = urunStok[urunID];

	up('adet_'+catID,1);

	if (fiyat > 0) up('fiyat_'+catID,moneyFormat(fiyat));

	if (urunID > 0) {

		if (stok > 0) ch('stok_'+catID,'stok_var_'+catID);

		else {

			ch('stok_'+catID,'stok_yok_'+catID);

			up('adet_'+catID,0);

			up('fiyat_'+catID,0);

		}

	}

	else {

		ch('stok_'+catID,'stok_def_'+catID);

		up('adet_'+catID,0);

		up('fiyat_'+catID,0);

	}

	if (stok > 0) KDVHaricArray[catID] = urunKDVHaricFiyat[urunID];

	document.getElementById('detail_href_'+catID).href=(urunID > 0?'page.php?act=urunDetay&urunID=' + urunID:'#');

	document.getElementById('detail_href_'+catID).target=(urunID > 0?'_blank':'_self');

	updateToplam();

}



function updateAdet(v,catID) {

	var xID = '#urunSelected_'+catID;

	var urunID = $(xID).val();

	if(v==0 || !v) 	

		KDVHaricArray[catID] = 0;

	else 

	    KDVHaricArray[catID] = (urunKDVHaricFiyat[urunID] * v);

	var urunID = document.getElementById('urunSelected_'+catID).options[document.getElementById('urunSelected_'+catID).selectedIndex].value;

	var fiyat = urunFiyat[urunID];

	var stok  = urunStok[urunID];

	if (!isInt(v)) {		

		alert(lutfenSadeceRakkamKullanin);

		v = (urunID > 0 && stok > 0 ? 1 : 0);

		up('adet_'+catID,v);

	}

	else if (v > stok) {

		alert(lang_stoktlarimizdaYok);	

		up('adet_'+catID,stok);

		v = stok;

	}

	if (urunID > 0) up('fiyat_'+catID,moneyFormat(fiyat * v));

	updateToplam();

}



function ShowDetailPic(catID) {

	var urunID = document.getElementById('urunSelected_'+catID).options[document.getElementById('urunSelected_'+catID).selectedIndex].value;

	document.getElementById('detail_div_'+catID).innerHTML = '<img src="include/resize.php?path=images/urunler/'+urunResim[urunID]+'&width=500&height=100">';

	if (urunResim[urunID]) document.getElementById('detail_div_'+catID).style.display = 'block';

}

// PC Toplama Fonksiyonları



function moneyFormat(V){

	var intPart,decPart

	ret=V*100;ret=Math.round(ret);

	ret=V<.1?"0"+ret:ret;

	ret=V< 1?"0"+ret:""+ret;

	intPart=ret.substring(0,ret.length-2);

	decPart=ret.substring(ret.length-2);

	ret=intPart+"."+decPart;

	if (ret.indexOf('-') >=0) ret = ret.replace('00','');

	return(ret);

}



function pause(numberMillis)

{

	var now = new Date();

	var exitTime = now.getTime() + numberMillis;

	while (true)

	{

		now = new Date();

		if (now.getTime() > exitTime)

		return;

	}

} 



function isInt(x) { 

   var y=parseInt(x); 

   if (isNaN(y)) return false; 

   return x==y && x.toString()==y.toString(); 

 } 





function gv(id) {

	if (document.getElementById(id)) return document.getElementById(id).value; 

	else alert('DEBUG gv : '+id+' -> NOID.');	

}



function up(id,v) {

	if (document.getElementById(id)) document.getElementById(id).value = v; 

	else alert('DEBUG up : '+id+' -> NOID.');

}



function ch(oldid,newid) {

	if (!document.getElementById(oldid)) alert('DEBUG ch : '+oldid+' -> NOID.');

	if (!document.getElementById(newid)) alert('DEBUG ch : '+newid+' -> NOID.');

	document.getElementById(oldid).innerHTML = document.getElementById(newid).innerHTML;

}



function openTab(id) {

	if ($('#fancyTabContainer').html() != null && $('#fancyTabContainer').html() != '')

	{

		id++;

		$('#fancyTabContainer .tabs1 li:eq('+id+')').click();

		return;

	}

	//if (lastTabID == id) return;	

	var cont = false;

	{

		if (lastTabID) $('#tabData' + lastTabID).hide('fast');

		$('#tabData' + id).show('fast');

		$('#tabData' + id + ' .imgCaptchaRefresh').click();

		lastTabID = id;

		cont = true;

	}

	for (var i=1;i<=10;i++) {

		if (document.getElementById('option'+i)) {

			document.getElementById('option'+i).style.backgroundPosition = '0% 0px';

			document.getElementById('option'+i).getElementsByTagName('span')[0].style.backgroundPosition = '100% 0px';

		}

	}

	if (cont && document.getElementById('option'+id) != null) {

		document.getElementById('option'+id).style.backgroundPosition = '0% -42px';

		document.getElementById('option'+id).getElementsByTagName('span')[0].style.backgroundPosition = '100% -42px';

	}

}



function flash(w,h,u,t) {

	document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='"+w+"' height='"+h+"'><param name='movie' value='"+u+"'><param name='quality' value='high'>");

	document.write("<param name='wmode' value='transparent'>");

	document.write("<embed src='"+u+"' quality='high' wmode='transparent' type='application/x-shockwave-flash' width='"+w+"' height='"+h+"'></embed></object>");	

}



function Validate_Email_Address(email_address)

         {

         at = email_address.indexOf('@');

         dot = email_address.indexOf('.');         

         if(at == -1 || 

            dot == -1 || 

            dot <= at + 1 ||

            dot == 0 || 

            dot == email_address.length - 1)

            return(false);

			else return true;

		 }





function trFix (string) {

	//string = string.replace(/y/g,'ı');

	//string = string.replace(/?/g,'ş');

	//string = string.replace(/?/g,'ğ');	

	return string;

}



function sssOpen(ID) {

	if (lastSSSID) {

		$('#sss_cevap_'+lastSSSID).slideUp('fast');

		$('#sss_image_'+lastSSSID).attr({'src':'images/sss_close.gif'});

	}

	if (lastSSSID != ID) {

		$('#sss_cevap_'+ID).slideDown('fast');

		$('#sss_image_'+ID).attr({'src':'images/sss_open.gif'});

		lastSSSID=ID;

	}

	else lastSSSID=0;

	

}



function fc(obj) {

	obj.innerHTML = obj.innerHTML + '<input type="submit" style="display:none" id="sb">';

	document.getElementById('sb').click();

}



function pencereAc(url,en,boy) {

	window.open(url,null,"height="+boy+",width="+en+",status=no,toolbar=no,menubar=no,location=no,scrollbars=1");

}



function is_int(input){

    return typeof(input)=='number'&&parseInt(input)==input;

}


