﻿var isMember = false;
var totalBasketAmount = 0;
var blnOutOfStockMessage = false;
var blnQuantityChangeMessage = false;

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g, "");
}

$(document).ready(function() {
    $(function() {
        $.getJSON("giris/kontrolet", { r: new Date().getTime()}, function(k) {
		    if (k) {
			    isMember = true;
		    } else {
			    isMember = false;
		    }
            if (isMember)
            {
                jQuery.ajax({
                    url: 'uyelik/kullanici_adi',
                    success: function(d) {
                        $("#kullanici_adi").html(d);
                        $("#customerFullName").html(d);
                    },
                    async: false
                });
                $("#girisyap").hide();
				$("#guvenlicikis").show();
                //$("#banaozel").show();
	            $("#yeniuyelik").hide();
	            $("#loginBox").hide();
                $("#userMenu").show();
                $("#headerSepet").load("sepetim/ozet");
                $(".bluebar").show();
                $(".sepetbar").show();
            }
            else
            {
	            //$("#banaozel").hide();
	            $("#yeniuyelik").show();
	            $("#girisyap").show();
	            $("#guvenlicikis").hide();
	            $("#kullanici_adi").html("Hoşgeldiniz..");
                $("#loginBox").show();
                $("#userMenu").hide();
                $(".bluebar").hide();
                $(".sepetbar").hide();
            }
	    })
    });
});

function CurrencyFormatted(amount) {
	var i = parseFloat(amount);
	if (isNaN(i)) { i = 0.00; }
	var minus = '';
	if (i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if (s.indexOf('.') < 0) { s += '.00'; }
	if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s.replace(".",",");
}

function updateAlertMaster(object, text) {
	object.text(text).effect('highlight', {}, 1500);
}

function checkInputLength(o, n, min, max, alertobject) {
	if (o.val().length > max || o.val().length < min) {
		o.addClass('ui-state-error');
		updateAlertMaster(alertobject, 'Lütfen ' + n + ' alanını doldurunuz');
		return false;
	} else {
		return true;
	}
}

function checkInputRegexp(o, regexp, n, alertobject) {
	if (!(regexp.test(o.val()))) {
		o.addClass('ui-state-error');
		updateAlertMaster(alertobject, n);
		return false;
	} else {
		return true;
	}
}

function updateBasketInfoTop() {
	$("#basketinfo_top").load("basket/baskettopinfo");
}

function updateBasketSummary() {
	$("#basketsummary-wrap").load("sepetim/sepetozeti #basketsummary");
}

function updateBasketCampaigns() {
	$('#basket-campaign-wrap').load('sepetim/sepetkampanyalari #basket-campaign', function(resp) {
		//$("#loadImage_" + basketID).hide();
	});
}

function showModalLogin() {
	$("#login_master").dialog('open');
}

function submitForm(id) {
	$('#' + id).submit();
}

function submitFormV2(id,button) {
	$('#' + id).submit();
	button.setAttribute("disabled", "disabled");
}

function printContent(ctrl)
{
    var DocumentContainer = document.getElementById(ctrl);
    var WindowObject = window.open('', "Sözleşme", 
                          "width=630,height=400,top=200,left=250,toolbars=no,scrollbars=yes,status=no,resizable=no");
    WindowObject.document.writeln(DocumentContainer.innerHTML);
    WindowObject.document.close();
    WindowObject.focus();
    WindowObject.print();
    WindowObject.close();
}

function WelcomeMessage() 
{
    h = new Date().getHours();
    wm = "";
    if (h >= 0 && h < 5)
        wm = "İyi Geceler";
    if (h >= 5 && h < 11)
        wm = "Günaydın";
    if (h >= 11 && h < 18)
        wm = "İyi Günler";
    if (h >= 18 && h < 24)
        wm = "İyi Akşamlar";
    document.write(wm);
}


$(document).ready(function() {
  $('body').addClass('javascript-enabled');

  var dropDownMenuJQueryObject = $('div.menu > ul');

  // Initialize the drop-down menus
  dropDownMenuJQueryObject.superfish({
    disableHI:		true,
    delay:			100,								// one second delay on mouseout 
    animation:		{ opacity: 'show', height: 'show' },  // fade-in and slide-down animation
    speed:			'normal',							// faster animation speed 
    autoArrows:		false,								// disable generation of arrow mark-up
    dropShadows:	false,								// disable drop shadows
	animation:     {opacity:'show'}					// an object equivalent to first parameter of jQuery’s .animate() method 
   });

   var tierOneListItemsJQueryObject = dropDownMenuJQueryObject.find('> li');
   /* This applies the PNG-fix for IE6 and also creates the iframe-shims
   to allow the drop-down bits to appear over select elements (if needed) in IE6 */
   tierOneListItemsJQueryObject
	.find('ul').ifixpng()
	.end();
   //$('img[@src$=.png]').ifixpng(); // apply to all png images 

  // Safely inject CSS3 and give the search results a shadow

   /*
   var cssObj = { 
   'box-shadow': '#888 5px 10px 10px', // Added when CSS3 is standard
   '-webkit-box-shadow': '#888 5px 10px 10px', // Safari
   '-moz-box-shadow': '#888 5px 10px 10px'
   }; // Firefox 3.5+
  
   $("#suggestions").css(cssObj);

  // Fade out the suggestions box when not active
  
   $("input").blur(function() {
   $('#suggestions').fadeOut();
   });
   */
})

function lookup(inputString) {
  if (inputString.length < 3) {
    $('#suggestions').fadeOut(); // Hide the suggestions box
  } else {
    
    /*$.post("SearchCombo", { queryString: "" + inputString + "" }, function(data) { // Do an AJAX call
    $('#suggestions').fadeIn(); // Show the suggestions box
    $('#suggestions').html(data); // Fill the suggestions box
    */
    //var html = '<div id="searchresults">';
    
  $.getJSON('arama/sc@q=' + inputString, function(data) {
	
	var html = '<div id="searchresults">';
	var result = new Boolean(false);
	
  	$.each(data, function(entryIndex, entry) {
  		html += '<a href="./' + entry['Url'] + '">';
  		html += '<img src="i/p/50/' + entry['PictureFolder'] + '/x' + entry['ProductCode'] + '_1.jpg" alt="' + entry['Name'] + '"';
  		html += '<span class="searchheading">' + entry['Name'] + ' ' + entry['Color'] + '</span>';
  		html += '<span class="searchsuggest">' + entry['MainCategory'] + ' / ' + entry['Category'] + ' / ' + entry['SubCategory'] + '</span>';
  		html += '<span class="searchsuggest">' + CurrencyFormatted(entry['Price']) + ' TL' + '</span></a>';
  	});
  	
  	if (html != '<div id="searchresults">') {
  		result = true;
  	}
  	
  	html += '<br /><div class="seperator"><a href="arama@q=' + inputString + '">Tüm Sonuçlar</a></div><br class="clear" /></div>';
  	$('#searchresults_panel').empty();
  	if (result == true) {
  		$('#searchresults_panel').append(html);
  		$('#suggestions').fadeIn();
  	}
  	
  });
  }
}

function addToBasketMaster(productID, barCode) {
	if (isMember) {
		$(function() {
		$.getJSON("sepetim/ekle/" + productID + "/" + barCode, { r: new Date().getTime() }, function(j) {
				if (j) {
					addToBasket(productID);
					showModalMessageBox('Ürün sepetinize eklendi..');
					updateBasketInfoTop();
					calculateBasket(0);
				}
			})
		})
		
	} else {
		showModalLogin();
	}
}

function addToBasketInBasket(productID, barCode) {

	if (isMember) {
		$(function() {
		$.getJSON("sepetim/ekle/" + productID + "/" + barCode, { r: new Date().getTime() }, function(j) {
				if (j) {
					addToBasket(productID);
					showModalMessageBox('Ürün sepetinize eklendi..');
					updateBasketInfoTop();
					calculateBasket(0);
					//$('#sepet-table').load('sepetim #basket', function(resp) {});
                    $('#leftwide-wrap').load('sepetim/guncel #leftwide', function(resp) {});
					updateBasketCampaigns();
				}
			})
		})

	} else {
		showModalLogin();
	}
}

function addToBasketInBasketWithQuantity(productID, barCode, intQuantity) {

	if (isMember) {
		$(function() {
			$.getJSON("sepetim/adetliekle/" + productID + "/" + barCode + '/' + intQuantity, { r: new Date().getTime() }, function(j) {
				if (j) {
					addToBasket(productID);
					showModalMessageBox('Ürün sepetinize eklendi..');
					updateBasketInfoTop();
					calculateBasket(0);
					//$('#sepet-table').load('sepetim #basket', function(resp) {});
                    $('#leftwide-wrap').load('sepetim/guncel #leftwide', function(resp) {});
					updateBasketCampaigns();
				}
			})
		})

	} else {
		showModalLogin();
	}
}

$(document).ready(function() {
	$(function() {
		$("#modalMessageBox").dialog({
			bgiframe: true,
			height: 140,
			modal: true,
			autoOpen: false
		});
	});
});

function showModalMessageBox(message) {

	$("#modalMessageBox").empty();
	$("#modalMessageBox").append('<p>' + message + '</p>');
	$("#modalMessageBox").dialog('open');
	setTimeout(function() {
		$("#modalMessageBox").dialog('close');
	}, 1000);
}

function showModalMessageBoxWithDelay(message,delay) {

	$("#modalMessageBox").empty();
	$("#modalMessageBox").append('<p>' + message + '</p>');
	$("#modalMessageBox").dialog('open');
	setTimeout(function() {
		$("#modalMessageBox").dialog('close');
	}, delay);
}

// Modal Popup Initialization - Begin
$(document).ready(function() {   
	$(function() {
		var username_modal = $("#username_modal");
		var password_modal = $("#password_modal");
		var allFormFields = $([]).add(username_modal).add(password_modal);
		$("#login_master").dialog({
			bgiframe: true,
			resizable: false,
			height: 200,
			modal: true,
			autoOpen: false,
			overlay: {
				backgroundColor: '#000',
				opacity: 0.5
			},
			buttons: {
				'Giriş': function() {
					var bValid = true;
					allFormFields.removeClass('ui-state-error');

					bValid = bValid && checkInputLength(username_modal, "Üyelik Adı", 3, 150, $("#validatetips_login_master"));
					bValid = bValid && checkInputLength(password_modal, "Şifre", 3, 150, $("#validatetips_login_master"));
					//bValid = bValid && checkRegexp_nickname(username, /^[a-z]([0-9a-z_])+$/i, "Hatalı karakter girdiniz.");

					if (bValid) {
						$("#login_master_form").submit();
						$(this).dialog('close');
					}
				},
				'Vazgeç': function() {
					$(this).dialog('close');
				}
			}
		});
	});
});	
// Modal Popup Initialization - End

//-sepet
function addProductInSepet(productID, barCode) {
	if (isMember) {
		$(function() {
		$.getJSON("sepetim/ekle/" + productID + "/" + barCode, { r: new Date().getTime() }, function(j) {
				var options = '';

				if (j) {
					$("#basketitem_" + productID).value = quantity;
					//$('#sepet-table').load('sepetim #basket', function(resp) {});
					$('#leftwide-wrap').load('sepetim/guncel #leftwide', function(resp) { });
					calculateBasket(0);
				}
			})
		})
	} else {
		alert("Lütfen üyelik girişi yapınız");
	}
  }

  function removeProduct(basketID) {
  	if (isMember) {
  		if (confirm("Ürünü sepetinizden silmek istediğinize emin misiniz?")) {
  			$(function() {
  				$("#loadImage_" + basketID).show();
  				$.getJSON("sepetim/sil/" + basketID, { r: new Date().getTime() }, function(j) {
  					var options = '';

  					if (j) {
  						$("#basketrow_" + basketID).html('');
//      						$('#sepet-table').load('sepetim #basket', function(resp) {
//      							//$("#loadImage_" + basketID).hide();
//      						});
//      						$('#basket-campaign-wrap').load('sepetim/sepetkampanyalari #basket-campaign', function(resp) {
//      							//$("#loadImage_" + basketID).hide();
//      						});
  						$('#leftwide-wrap').load('sepetim/guncel #leftwide', function(resp) {});
  						calculateBasket(0);
  					}
  				})
  			})
  		}
  	} else {
  		alert("Lütfen üyelik girişi yapınız");
  	}
  }

  function removeProductWithOutConfirm(basketID) {
  	if (isMember) {
  		//if (confirm("Ürünü sepetinizden silmek istediğinize emin misiniz?")) {
  			$(function() {
  				$("#loadImage_" + basketID).show();
  				$.getJSON("sepetim/sil/" + basketID, { r: new Date().getTime() }, function(j) {
  					var options = '';

  					if (j) {
  						$("#basketrow_" + basketID).html('');
  						//      						$('#sepet-table').load('sepetim #basket', function(resp) {
  						//      							//$("#loadImage_" + basketID).hide();
  						//      						});
  						//      						$('#basket-campaign-wrap').load('sepetim/sepetkampanyalari #basket-campaign', function(resp) {
  						//      							//$("#loadImage_" + basketID).hide();
  						//      						});
  						$('#leftwide-wrap').load('sepetim/guncel #leftwide', function(resp) {
  							//$("#loadImage_" + basketID).hide();
  						});
  						calculateBasket(0);
  					}
  				})
  			})
  		//}
  	} else {
  		alert("Lütfen üyelik girişi yapınız");
  	}
  }

  function updateBasket(basketID, inc) {
  	if (isMember) {
  		$(function() {
  			_q = $("#basket_quantity_" + basketID).attr("value");
  			_q = parseInt(_q) + parseInt(inc);
  			if (_q > 0) {
  				$("#loadImage_" + basketID).show();
  				$.getJSON("sepetim/guncelle/" + basketID + "/" + _q, { r: new Date().getTime() }, function(j) {
  				if (j) {
  					$("#basket_quantity_" + basketID).attr("value", _q);
  					$('#leftwide-wrap').load('sepetim/guncel #leftwide', function(resp) {});
/*
  					$('#sepet-table').load('sepetim@r=' + new Date().getTime() + ' #basket', function(resp) {
  					});
  					$('#basket-campaign-wrap').load('sepetim/sepetkampanyalari@r=' + new Date().getTime() + ' #basket-campaign', function(resp) {
  					});
*/  					
  					calculateBasket(basketID);
  				}
  			})
  			}
  		})
  	} else {
  		alert("Lütfen üyelik girişi yapınız");
  	}
  }

  function updateBasketV2(basketID, inc, max) {
  	if (isMember) {
  		
  		$(function() {
  			_q = $("#basket_quantity_" + basketID).attr("value");
  			_q = parseInt(_q) + parseInt(inc);
  			
  			if (_q > max) {
  				alert("Mevcut stok yeterli değil");
  				return false;
  			}
  			
  			if (_q > 0) {
  				$("#loadImage_" + basketID).show();
  				$.getJSON("sepetim/guncelle/" + basketID + "/" + _q, { r: new Date().getTime() }, function(j) {
  					if (j) {
  						$("#basket_quantity_" + basketID).attr("value", _q);
  						$('#leftwide-wrap').load('sepetim/guncel #leftwide', function(resp) { });
/*
  						$('#sepet-table').load('sepetim@r=' + new Date().getTime() + ' #basket', function(resp) {
  							//$("#loadImage_" + basketID).hide();
  						});
  						$('#basket-campaign-wrap').load('sepetim/sepetkampanyalari@r=' + new Date().getTime() + ' #basket-campaign', function(resp) {
  							//$("#loadImage_" + basketID).hide();
  						});
*/  						

  						calculateBasket(basketID);
  					}
  				})
  			}
  		})
  	} else {
  		alert("Lütfen üyelik girişi yapınız");
  	}
  }

  function calculateBasket(basketID) {
  	$(function() {
  		var html = '';
  		var basketinfo = '';
  		var i = 0;
  		$.getJSON("sepetim/hesapla", { r: new Date().getTime() }, function(data) {
  			$.each(data, function(entryIndex, entry) {
  				if (entry['Code'] != "INFOS") {
  					html += '<tr>';
  					html += '<td align="right" width="640">';
  					html += '<span class="total">' + entry['Description'] + '</span>';
  					html += '</td>';
  					html += '<td width="110">';
  					html += '<span class="total">' + CurrencyFormatted(entry['Total']) + ' TL</span>';
  					html += '</td>';
  					if (entry['Code'] == 'TOTALAMOUNT') {
  						html += '<input type="hidden" name="promo_desc_' + entry['Code'] + '" value="' + entry['Description'] + '" />';
  						html += '<input type="hidden" name="promo_total_' + entry['Code'] + '" value="' + CurrencyFormatted(entry['Total']) + '" />';
  						totalBasketAmount = CurrencyFormatted(entry['Total']);
  					} else {
  						html += '<input type="hidden" name="promo_desc_' + entry['Code'] + '_' + i + '" value="' + entry['Description'] + '" />';
  						html += '<input type="hidden" name="promo_total_' + entry['Code'] + '_' + i + '" value="' + CurrencyFormatted(entry['Total']) + '" />';
  					}
  					i++;
  					html += '</tr>';
  				}
  				if (entry['Code'] == "INFOS") {
  					if (entry['Code'] != null || entry['Code'] != "") {

  						basketinfo += '<h3 class="info-header">TEBRİKLER! HEDİYE ÇEKİ KAZANDINIZ!</h3>';
  						basketinfo += '<span>' + entry['Description'] + ' Kampanyasından ' + CurrencyFormatted(entry['Total']) + ' TL değerinde hediye çeki kazanacaksınız!</span>';

  					} else {
  					}

  					if (basketinfo != null || basketinfo != '') {
  						$('#basket_information').show();
  					} else {
  						$('#basket_information').hide();
  					}
  					
  				}
  			});

  			$('#basket_calculated').empty();
  			$('#basket_informed').empty();

  			$('#basket_calculated').append(html);
  			$('#basket_informed').append(basketinfo);

  			if (basketID > 0) {
  				$("#loadImage_" + basketID).hide();
  			}

  			if (basketinfo == '') {
  				$('#basket_information').hide();
  			}

  			updateBasketInfoTop();
  		});
  	})
  	//  	} else {
  	//  		alert("Lütfen üyelik girişi yapınız");
  	//  	}
  }

  function applyCheckbook() {
  	promotion_code = $('#promotion-code').val();
  	promotion_code = trim(promotion_code);
  	if (promotion_code != "" && promotion_code.length > 4) {
  		$(function() {
  			if (isMember) {
  				$(function() {
  					$.getJSON("sepetim/cekkullan/" + promotion_code, { r: new Date().getTime() }, function(j) {
  						if (j == 'true') {

  							couponnumber = '<ul id="used_' + promotion_code + '"><li>';
  							couponnumber += '<a title="Kuponu Sil" class="removecoupon pointer" onclick="releaseCheckbook(' + "'" + promotion_code + "'" + ');">';
  							couponnumber += '<img src="i/ico_unselect.gif" border="0" alt="Kuponu Sil" title="Kuponu Sil" /></a>';
  							couponnumber += '<span><a title="Kuponu Sil" class="removecoupon pointer">' + promotion_code + '</a></span>';
  							couponnumber += '<input type="hidden" name="couponrow_"' + promotion_code + '" value="' + promotion_code + '">';
  							couponnumber += '</li>';
  							couponnumber += '</ul>';

  							$('#promotion_codes').append(couponnumber);
  							$('#promotion-code').val('');
  							
  							showModalMessageBox('BİLGİ: İndirim kuponunuz kaydedildi. Sepetinizde uygun olduğu takdirde kampanya uygulanacaktır.');
  							
  							calculateBasket(0);
  						} else if (j == 'false') {
  							alert("Kupon numarasını hatalı girdiniz. Lütfen kontrol edip tekrar deneyiniz.");
  						} else if (j == 'used') {
  							alert("Bu kupon numarası daha önce kullanılmış.");
  						}
  					})
  				})

  			} else {
  				alert("Lütfen üyelik girişi yapınız");
  			}
  		})
  	} else {
  		alert("Kupon numarası giriniz");
  		return false;
  	}
  }

  function releaseCheckbook(promotion_code) {
  	if (promotion_code != "" && promotion_code.length > 4) {
  		$(function() {
  			if (isMember) {
  				$(function() {
  				$.getJSON("sepetim/cekbirak/" + promotion_code, { r: new Date().getTime() }, function(j) {
  						if (j) {
  							$("#used_" + promotion_code).remove();
  							showModalMessageBox('BİLGİ: İndirim kuponu kaydınız silinmiştir.');
  							calculateBasket(0);

  						} else {
  							alert("Kupon numarasını hatalı girdiniz. Lütfen kontrol edip tekrar deneyiniz.");
  						}
  					})
  				})
  			} else {
  				alert("Lütfen üyelik girişi yapınız");
  			}
  		})
  	} else 
  	{
  		alert("Kupon numarası giriniz");
  		return false;
  	} 
}

var _basketQuantity = 0;

function changeQuantity(basketID, inc) {
	updateBasket(basketID, inc);
}

function changeQuantityV2(basketID, inc, max) {
	//updateBasket(basketID, inc);
	updateBasketV2(basketID, inc, max);
}

function hideQuantityUpDown(basketID) {
	$("#removeproduct_" + basketID).hide();
	$("#addproduct_" + basketID).hide();
	$("#change_quantity_" + basketID).show();
	_basketQuantity = $("#basket_quantity_" + basketID).attr("value");
}

function showQuantityUpDown(basketID, max) {
	$("#removeproduct_" + basketID).show();
	$("#addproduct_" + basketID).show();
	$("#change_quantity_" + basketID).hide();
	if (_basketQuantity == 0 || _basketQuantity == $("#basket_quantity_" + basketID).attr("value")) { return false; }
	changeQuantityV2(basketID, 0, max);
}
//sepet

//Ürün Detay - Yorum
function rateProduct(productID, rate) {
	$(function() {
	$.getJSON("giris/kontrolet", { r: new Date().getTime() }, function(k) {
			if (k) {
				$.getJSON("urun_puanla/" + productID + "/" + rate, function(j) {

					if (j) {
						showModalMessageBox("Puanınız kaydedildi. Teşekkürler!");
					} else {
						alert("BİLGİ: Ürüne daha önce puan verilmiş.");
					}
				})
			} else {
				alert("Ürünü puanlamak için üye girişi yapmanız gerekmektedir.");
			}
		})
	})
}

function applyGiftCode() {
	gift_code = $('#gift-code').val();
	gift_code = trim(gift_code);
			
	if (gift_code != "" && gift_code.length > 4) {
		$(function() {
			if (isMember) {
				$(function() {
					$.getJSON("sepetim/hediyecekikullan/" + gift_code, { r: new Date().getTime() }, function(j) {
						if (j=='true') {

							couponnumber = '<ul id="usedgift_' + gift_code + '"><li>';
							couponnumber += '<a title="Çeki Sil" class="removeFacet pointer" onclick="releaseGiftCode(' + "'" + gift_code + "'" + ');">';
							couponnumber += '<img src="i/ico_unselect.gif" border="0" alt="Çeki Sil" title="Çeki Sil" /></a>';
							couponnumber += '<span><a title="Çeki Sil" class="removeFacet pointer">' + gift_code + '</a></span>';
							couponnumber += '<input type="hidden" name="giftrow_"' + gift_code + '" value="' + gift_code + '">';
							couponnumber += '</li>';
							couponnumber += '</ul>';

							$('#gift_codes').append(couponnumber);
							$('#gift-code').val('');
														
							showModalMessageBox('BİLGİ: Hediye çekiniz uygulanmıştır.');
							
							calculateBasket(0);
						} else if (j=='false') {
							alert("Hediye çekini hatalı girdiniz. Lütfen kontrol edip tekrar deneyiniz.");
						} else if (j == 'used') {
							alert("Bu hediye çeki daha önce kullanılmış.")
						}
					})
				})

			} else {
				alert("Lütfen üyelik girişi yapınız");
			}
		})
	} else {
		alert("Hediye çeki kodunu giriniz");
		return false;
	}
}

function releaseGiftCode(gift_code) {
	if (gift_code != "" && gift_code.length > 4) {
		$(function() {
			if (isMember) {
				$(function() {
				$.getJSON("sepetim/hediyecekiiptal/" + gift_code, { r: new Date().getTime() }, function(j) {
						if (j) {
							$("#usedgift_" + gift_code).remove();
							showModalMessageBox('BİLGİ: Hediye çeki iptal edilmiştir.');
							calculateBasket(0);

						} else {
							alert("Çek numarasını hatalı girdiniz. Lütfen kontrol edip tekrar deneyiniz.");
						}
					})
				})
			} else {
				alert("Lütfen üyelik girişi yapınız");
			}
		})
	} else {
		alert("Hediye çeki kodunu giriniz");
		return false;
	}
}

function GetGiftCodes() {
	$(function() {
		$(function() {
			$.getJSON("sepetim/hediyeceklerinigetir", { r: new Date().getTime() }, function(data) {
				$.each(data, function(entryIndex, entry) {

					var giftCode = entry["CouponSerial"];

					couponnumber = '<ul id="usedgift_' + giftCode + '"><li>';
					couponnumber += '<a title="Çeki Sil" class="removeFacet pointer" onclick="releaseGiftCode(' + "'" + giftCode + "'" + ');">';
					couponnumber += '<img src="i/ico_unselect.gif" border="0" alt="Çeki Sil" title="Çeki Sil" /></a>';
					couponnumber += '<span><a title="Çeki Sil" class="removeFacet pointer">' + giftCode + '</a></span>';
					couponnumber += '<input type="hidden" name="giftrow_"' + giftCode + '" value="' + giftCode + '">';
					couponnumber += '</li>';
					couponnumber += '</ul>';

					$('#gift_codes').append(couponnumber);
					//calculateBasket(0);
				});
			})
		})

	})
}

function GetCheckBooks() {
	$(function() {
		$(function() {
			$.getJSON("sepetim/cekbooklarigetir", { r: new Date().getTime() }, function(data) {

				$.each(data, function(entryIndex, entry) {

					var checkBook = entry["CheckbookSerial"] + entry["PromotionID"];

					couponnumber = '<ul id="used_' + checkBook + '"><li>';
					couponnumber += '<a title="Kuponu Sil" class="removecoupon pointer" onclick="releaseCheckbook(' + "'" + checkBook + "'" + ');">';
					couponnumber += '<img src="i/ico_unselect.gif" border="0" alt="Kuponu Sil" title="Kuponu Sil" /></a>';
					couponnumber += '<span><a title="Kuponu Sil" class="removecoupon">' + checkBook + '</a></span>';
					couponnumber += '<input type="hidden" name="couponrow_"' + checkBook + '" value="' + checkBook + '">';
					couponnumber += '</li>';
					couponnumber += '</ul>';

					$('#promotion_codes').append(couponnumber);
					//calculateBasket(0);
				});

			})
		})
	})
}

function addToBasketWithStockContol(productId) {
    jQuery.ajax({
        url: 'urun/stok/' + productId,
        success: function(d) {
            if(d > 0)
                addToBasketMaster(productId, 0)
            else
                alert("Ürün stoklarımızda bulunmamaktadır.")
        },
        async: false
    });
}