﻿function DoPayment() {
    $("#DoPayment").hide();

    if ($("[name=Name]").val() == "") { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen yıldızlı alanları doldurun."); $("#DoPayment").show(); return false; }
    if ($("[name=LastName]").val() == "") { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen yıldızlı alanları doldurun."); $("#DoPayment").show(); return false; }
    //if ($("[name=TCNO]").val() == "") { $("#PaymentResut").html("Lütfen yıldızlı alanları doldurun."); $("#DoPayment").show(); return false;}
    if ($("[name=Address]").val() == "") { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen yıldızlı alanları doldurun."); $("#DoPayment").show(); return false; }
    if ($("[name=City]").val() == "") { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen şehir seçimini yapınız."); $("#DoPayment").show(); return false; }
    if ($("[name=Town]").val() == "") { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen ilçe seçimini yapınız."); $("#DoPayment").show(); return false; }
    if ($("[name=MobilePhone]").val() == "") { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen yıldızlı alanları doldurun."); $("#DoPayment").show(); return false; }

    if ($("[name=UserID]").val().length == 0) {
        if ($("[name=Email]").val().length < 6) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen yıldızlı alanları doldurun.."); $("#DoPayment").show(); return false; }
        if ($("[name=Password]").val().length < 6) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen yıldızlı alanları doldurun..."); $("#DoPayment").show(); return false; }
        if ($("[name=Repassword]").val().length < 6) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen yıldızlı alanları doldurun..."); $("#DoPayment").show(); return false; }
    }

    if ($("[name=PaymentType]:checked").val() == "1000") {
        if ($("[name=CCName]").val().length < 4) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen kart üzerindeki ismi giriniz."); $("#DoPayment").show(); return false; }
        if ($("[name=CCBank] :selected").val() == 0) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen kredi kartı seçiminizi yapınız."); $("#DoPayment").show(); return false; }
        if ($("[name=CCNo1]").val().length < 4 && $("[name=CCNo2]").val().length < 4 && $("[name=CCNo3]").val().length < 4 && $("[name=CCNo4]").val().length < 4) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen kart numalarını kontrol ediniz."); $("#DoPayment").show(); return false; }
        if ($("[name=CCV]").val().length < 3) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen kartın arka yüzündeki güvenlik numarasını giriniz."); $("#DoPayment").show(); return false; }
        if ($("[name=CCInstallment] :selected").val() == 'x') { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen ödeme türünü seçiniz."); $("#DoPayment").show(); return false; }
    }
    if (!$("[name=terms]").attr("checked")) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#PaymentResut").html("Lütfen sözleşmeyi okuyup onaylayınız."); $("#DoPayment").show(); return false; }


    var Data = $("[name=PaymentForm]").serialize();
    //alert(Data);
    $.ajax({
        type: "POST",
        url: "Ajax.aspx",
        timeout: 15000,
        cache: false,
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        data: Data,
        beforeSend: function () {
            //$("#PaymentResut").html('Lütfen bekleyiniz...');
            $("#dialog").html("<p align='center'><img src='/images/loaddisk-small.gif' style='width: 64px; height: 47px;' /><br /><br /><span style='font-size: 10pt; color: #0000ff;'>Lütfen bekleyiniz...</p></span>")
            $("#dialog").dialog({
                modal: true
	            , title: "İşlem devam ediyor..."
	            , closeOnEscape: false
            });
        },
        success: function (msg) {
            if (parseFloat(msg) > 0) {
                location.href = './?Q=OrderComplete&OrderID=' + msg;
            } else {
                $("#PaymentResut").html(msg);
                $("#DoPayment").show();
                $("#dialog").dialog("destroy");
            }
            //$("#PaymentResut").html(msg);
        },
        error: function (xhr, textStatus, errorThrown) {
            $("#dialog").dialog("destroy");
            alert("Üzgünüz, bir hatadan dolayı işleminize devam edemiyoruz.\nLütfen siparişinizin durumuyla ilgili bizimle iletişime geçiniz.\n" + textStatus);
            $("#DoPayment").show();
        }
    });
}

function LoginPayment() {
    var Data = "Q=LoginPayment&" + $("[name=LoginEmail], [name=LoginPassword]").serialize();
    $.ajax({
        type: "POST",
        url: "Ajax.aspx",
        timeout: 90000,
        cache: false,
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        data: Data,
        beforeSend: function () {
            $("#LoginResult").html("");
        },
        success: function (msg) {
            if (msg == "True") {
                $("#LoginTable").hide();
                location.reload(true);
            } else {
                $("#LoginResult").html("Hatalı email yada parola!");
            }
        },
        error: function (xhr, textStatus, errorThrown) {
            alert("Error: " + textStatus);
        }
    });
}

function Register() {
    $("#RegisterResult").html('');
    $("#Register").hide();
    if ($("[name=Name]").val() == "") { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#RegisterResult").html("Lütfen yıldızlı alanları doldurun."); $("#Register").show(); return false; }
    if ($("[name=LastName]").val() == "") { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#RegisterResult").html("Lütfen yıldızlı alanları doldurun."); $("#Register").show(); return false; }
    //if ($("[name=TCNO]").val() == "") { $("#RegisterResult").html("Lütfen yıldızlı alanları doldurun."); $("#DoPayment").show(); return false;}
    if ($("[name=Email]").val().length < 6) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#RegisterResult").html("Lütfen yıldızlı alanları doldurun.."); $("#Register").show(); return false; }
    if ($("[name=Password]").val().length < 6) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#RegisterResult").html("Lütfen yıldızlı alanları doldurun.."); $("#Register").show(); return false; }
    if ($("[name=Repassword]").val().length < 6) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#RegisterResult").html("Lütfen yıldızlı alanları doldurun..."); $("#Register").show(); return false; }
    if ($("[name=Repassword]").val() != $("[name=Password]").val()) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#RegisterResult").html("Parola tekrarınız uyumsuz."); $("#Register").show(); return false; }

    var Data = $("[name=RegisterForm]").serialize();
    //alert(Data);
    $.ajax({
        type: "POST",
        url: "Ajax.aspx",
        timeout: 90000,
        cache: false,
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        data: Data,
        beforeSend: function () {
            $("#RegisterResult").html("Lütfen bekleyiniz...");
        },
        success: function (msg) {
            if (msg > 0) { location.href = './?Q=Members'; }
            if (parseFloat(msg) > 0) {
                //$("#RegisterResult").html(msg);
                location.href = "./?Q=Members"
            } else {
                $("#RegisterResult").html(msg);
            }
            $("#Register").show();
        },
        error: function (xhr, textStatus, errorThrown) {
            alert("Error: " + textStatus);
            $("#Register").show();
        }
    });
}


function UpdateUser() {
    $("#UpdateUserResult").html('');
    $("#UpdateUser").hide();
    if ($("[name=Name]").val() == "") { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#UpdateUserResult").html("Lütfen yıldızlı alanları doldurun."); $("#UpdateUser").show(); return false; }
    if ($("[name=LastName]").val() == "") { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#UpdateUserResult").html("Lütfen yıldızlı alanları doldurun."); $("#UpdateUser").show(); return false; }
    //if ($("[name=TCNO]").val() == "") { $("#UpdateUserResult").html("Lütfen yıldızlı alanları doldurun."); $("#UpdateUser").show(); return false;}
    if ($("[name=Email]").val().length < 6) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#UpdateUserResult").html("Lütfen yıldızlı alanları doldurun.."); $("#UpdateUser").show(); return false; }

    if ($("[name=Password]").val().length > 0) {
        if ($("[name=Password]").val().length < 6) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#UpdateUserResult").html("Lütfen yıldızlı alanları doldurun.."); $("#UpdateUser").show(); return false; }
        if ($("[name=Repassword]").val().length < 6) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#UpdateUserResult").html("Lütfen yıldızlı alanları doldurun..."); $("#UpdateUser").show(); return false; }
        if ($("[name=Repassword]").val() != $("[name=Password]").val()) { $("#errorcontrol").html("<img src='images/error-control.gif' style='width: 120px; height: 25px;' />"); $("#UpdateUserResult").html("Parola tekrarınız uyumsuz."); $("#UpdateUser").show(); return false; }
    }
    var Data = "";
    Data += "Q=UpdateUser"
    Data += $("[name=Name]").serialize();
    Data += $("[name=LastName]").serialize();
    Data += $("[name=Email]").serialize();
    Data += $("[name=Password]").serialize();
    Data += $("[name=Repassword]").serialize();

    //Data = $("[id=TVUrunForm]").serialize();

    $.ajax({
        type: "POST",
        url: "/Ajax.aspx",
        timeout: 90000,
        cache: false,
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        data: Data,
        beforeSend: function () {
            $("#UpdateUserResult").html('Lütfen bekleyiniz...');
        },
        success: function (msg) {
            $("#UpdateUserResult").html(msg);
            $("#UpdateUserResult").append("<br />");
            //$("#UpdateUserResult").append(Data);
            $("#UpdateUser").show();
        },
        error: function (xhr, textStatus, errorThrown) {
            alert("Error: " + textStatus);
            $("#UpdateUser").show();
        }
    });
}


function CheckCouponCode() {
    var Data = "Q=CheckCouponCode&" + $("[name=CouponCode]").serialize();
    $.ajax({
        type: "POST",
        url: "Ajax.aspx",
        timeout: 90000,
        cache: false,
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        data: Data,
        beforeSend: function () {
            $("#CouponResult").html('Lütfen bekleyiniz...');
        },
        success: function (msg) {
            if (msg == "OK") {
                $("#CouponResult").html("Lütfen bekleyin, sayfa yeniden yükleniyor...");
                location.reload(true);
            } else {
                $("#CouponResult").html(msg);
            }
        },
        error: function (xhr, textStatus, errorThrown) {
            alert("Error: " + textStatus);
            $("#CouponResult").html('');
        }
    });
}


function GetTownListOfTheCity(Town) {
    var Data = "Q=GetTownListOfTheCity&" + $("[name=City]").serialize();
    $.ajax({
        type: "POST",
        url: "Ajax.aspx",
        timeout: 90000,
        cache: false,
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        data: Data,
        beforeSend: function () {
            $("#TownSpan").html('Yükleniyor...');
        },
        success: function (msg) {
            $("#TownSpan").html(msg);
            if (Town != "") {
                $("[name=Town]").val(Town);
            }
        },
        error: function (xhr, textStatus, errorThrown) {
            alert("Error: " + textStatus);
            $("#TownSpan").html('Yeniden şehir seçiniz.');
        }
    });
}





jQuery.fn.ForceNumericOnly =
function () {
    return this.each(function () {
        $(this).keydown(function (e) {
            var key = e.charCode || e.keyCode || 0;
            // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
            return (
                key == 8 ||
                key == 9 ||
                key == 46 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
        })
    })
};


function GoSearch(e) {
    if (e.keyCode == 13) {
        location.href = '/Search.aspx?key=' + encodeURI($('#SearchKey').val())
        return false;
    }
}

function AddToBasket(item) {
    //$("#VariantID option").eq(item).attr('selected', true);
    //$("#VariantID").click();
    //$("#AddToBasketButton").click();
    $("#VariantIDOrderForm option").eq(item).attr('selected', true);
    $.scrollTo('#OrderForm', 800);
}
