﻿$(function () {


    $("img").each(function () {
        if ($(this).attr("src").indexOf("noimage.png") > -1) {
            $(this).remove();
        }
    });

    $("a[rel^='prettyPhoto']").prettyPhoto({
        theme: 'facebook'
    });
    $("#textBodyContent a").attr('rel', 'prettyPhoto[paint]').prettyPhoto({
        theme: 'facebook'
    });

    $("#box-items-in-cart").load(base_url + "views/modules/page/handler/AddToCard.ashx?guid=&type=add2cart&ran=" + Math.random());

    $(".add_to_card").click(function () {
        /*var guid = $(this).attr('id');
        $(".cart_remove,.cart_add").hide();
        $.ajax({
        url: base_url + "views/modules/home/handler/AddToCard.ashx?guid=" + guid + "&type=add2cart&ran=" + Math.random(),
        type: "POST",
        cache: false,
        success: function(data) {
        $(".cart_add").show();
        $("#box-items-in-cart").html(data);
        //$(".osx").click();
        },
        error: function(data) {
        alert("Không thể kết nối tới server");
        }
        });
        return false;*/
    });

    $(".onlyNumber").keypress(function (event) {
        if (event.which < 48 || event.which > 57) {
            if (event.which == 8 || event.which == 127) {
                return;
            }
            return false;
        }
    });
});

function Add2Card(guid) {
    $("#" + guid).after("<span class='" + guid + "'><img src='" + resource + "view/images/loader.gif'/></span>");
    //$("#" + guid).hide();
    $(".cart_remove,.cart_add").hide();
    $.ajax({
        url: base_url + "views/modules/page/handler/AddToCard.ashx?guid=" + guid + "&type=add2cart&ran=" + Math.random(),
        type: "POST",
        cache: false,
        success: function(data) {
            $(".cart_add").show();
            $("#box-items-in-cart").html(data);
            $(".osx").click();
            $("." + guid).remove();
            //$("#" + guid).show();
        },
        error: function(data) {
            alert("Error connect to server");
        }
    });
    return false;
}

function remove_cart(guid) {
    $(".cart_remove,.cart_add").hide();
    var conf = confirm($remove_product);
    if (conf == true) {
        $.ajax({
            url: base_url + "views/modules/page/handler/AddToCard.ashx?guid=" + guid + "&type=remove&ran=" + Math.random(),
            type: "POST",
            cache: false,
            success: function(data) {
                $(".cart_remove").show();
                $("#box-items-in-cart").html(data);
                $(".osx").click();
            },
            error: function(data) {
                alert("Error connect to server");
            }
        });
    }
    return false;
}

