﻿function GetWindow() { var oWindow = null; if (window.radWindow) oWindow = window.radWindow; else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; return oWindow; }
function CloseAndReloadWindow() { GetWindow().BrowserWindow.location.reload(); }
function GetHitKey(e) {
    if (!e) { if (window.event) { e = window.event; } else { return; } }
    if (typeof (e.which) == 'number') { e = e.which; } else if (typeof (e.keyCode) == 'number') { e = e.keyCode; } else if (typeof (e.charCode) == 'number') { e = e.charCode; } else
        return; return e;
}


var _gaq = _gaq || [];
var tmpProductID;
var tmpQuantity = 1;
var tmpAddToCharResult;
function AddToChart(productID, quantity) {
    tmpProductID = productID;
    if (quantity != undefined)
        tmpQuantity = quantity;
    eComAjaxMethods.CheckLoggedIn(CheckLoggedInResultForAddToChart);
}
function CheckLoggedInResultForAddToChart(result) {
    if (result == true) {
        MultiGiftControl();
    }
    else {
        OpenSpeedLoginWindow();
    }
}

function CheckLoggedIn() {
    eComAjaxMethods.CheckLoggedIn(CheckLoggedInResult);
}

function CheckLoggedInResult(result) {
    if (result == false) {
        OpenSpeedLoginWindow();
    }
}

function ChangeTheme(theme) { eComAjaxMethods.ChangeTheme(theme, ChangeThemeResult); }
function ChangeThemeResult() { location.reload(); }

function MultiGiftControl() {
    eComAjaxMethods.IsProductHasMultipleGift(tmpProductID, MultiGiftControlResult);
}

function MultiGiftControlResult(result) {
    if (result == true) {
        eComAjaxMethods.IsGiftInTheBasket(tmpProductID, IsGiftInTheBasketControl);
    }
    else
        eComAjaxMethods.AddToChart(tmpProductID, tmpQuantity, AddToChartResult); 
}

function IsGiftInTheBasketControl(result) {
    if (!result) {
        var url = window.location.href;
        var mes;
        if (url.indexOf("ProductDetail") > -1)
            mes = "Bu ürünün birden fazla hediyesi var, öncelikle bir adet hediyeyi sepetinize ekleyiniz.";
        else
            mes = "Bu ürünün birden fazla hediyesi var, öncelikle bir adet hediyeyi sepetinize ekleyiniz.\n\n Ürün detayına yönlendiriliyorsunuz...";

        alert(mes);
        window.location = ProductDetai_URL + '?ProductID=' + tmpProductID;
    }
    else {
        eComAjaxMethods.AddToChart(tmpProductID, tmpQuantity, AddToChartResult); 
    }
}

function AddToChartResult(result) {
    tmpAddToCharResult = result;

    //Google Analytics kodu için sepete ekleme scripti eklendi.
    if (GoogleAnalyticsID != ' ') {
        _gaq.push(['_setCustomVar', 1, 'ZiyaretciTipi', 'Sepet', 2]);
        _gaq.push(['_trackPageview', '/sepete-ekle']);
    }

    eComAjaxMethods.GetAfterAddToChartJScriptMethod(GetAfterAddToChartJScriptMethodResult);
}
function GetAfterAddToChartJScriptMethodResult(result) {
    eval(result);
}

function ShowResultAndRefreshAllSideBars() {
    if (tmpAddToCharResult != "") { ShowMessage(tmpAddToCharResult); }
    RefreshAllSideBars();
}

function GotoUpSell() {
    var url = window.location.href;
    if (url.indexOf("ProductDetail") > -1) {
        window.location = UpSell_URL + '?ProductID=' + tmpProductID;
    }
    else {
        ShowResultAndRefreshAllSideBars();
    }
}

function OpenSpeedLoginWindow() { var url = SpeedLogin_URL + '?ProductID=' + tmpProductID; var oWindow = window.radopen(url, null); oWindow.setSize(500, 350); oWindow.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close); oWindow.center(); }
function ShowMessage(message) {
    radalert(message, 350, 150, 'Uyarı');
}

function VoteComment(commentId, vote) { eComAjaxMethods.AddCommentVote(commentId, vote, AddToChartResult); }
function RefreshAllSideBars() {
    if (typeof RefreshCartInfo != 'undefined') { RefreshCartInfo(); }
    if (typeof RefreshCartSideBar != 'undefined') { RefreshCartSideBar(); }
    if (typeof RefreshComparisonSideBar != 'undefined') { RefreshComparisonSideBar(); } 
}
function AddToComparisonList(productID) { eComAjaxMethods.AddToComparisonList(productID, AddToComparisonListResult); }
function AddToComparisonListResult(result) {
    if (result != "") { ShowMessage(result); }
    if (typeof RefreshComparisonSideBar != 'undefined') { RefreshComparisonSideBar(); } 
}
function Redirect(url) { window.location = url; }
function ChangeTheme(theme) { eComAjaxMethods.ChangeTheme(theme, ChangeThemeResult); }
function ChangeThemeResult() { location.reload(); }
function Print(elementId) { var printContent = document.getElementById(elementId); var windowUrl = ''; var windowName = 'Sözleşme'; var w = (window.screen.width - 640) / 2; var h = (window.screen.height - 500) / 2; var printWindow = window.open(windowUrl, windowName, 'scrollbars=yes,left=" + w + ",top=" + h + ",width=640,height=500'); printWindow.document.write(printContent.innerHTML); printWindow.document.close(); printWindow.focus(); printWindow.print(); printWindow.close(); }
function openDetails(sender, uid) {
    if ($("#" + uid).css("display") == "none") {
        $("#" + uid).slideDown('normal');
        $(sender).html('Listeyi Daralt');
    } else {
        $("#" + uid).slideUp('fast');
        $(sender).html('Tümünü Listele');
    }
}
function IsNull(x) {
    if (x != undefined && x != null && x != NaN)
        return false;
    else
        return true;
    return true;
}
