﻿
function open_zipcode(obj, goodsNo) {

    if ($("#todayZipcode").length == 0) {

        var layer = document.createElement("div");
        layer.id = "todayZipcode";
        document.body.appendChild(layer);
        $(layer).css("position", "absolute");
        $(layer).hide();

        var x, y;

        x = get_obj_x(obj);
        y = get_obj_y(obj);

        $.get("/common/todaydeliveryZipcode.aspx?GoodsNo=" + goodsNo, function(data, textStatus) {
            $(layer).html(data);
            set_layer_xy(layer, x, y);
            $(layer).show();
        });

    }
}

function close_zipcode() {
    $("#todayZipcode").remove();
}

function open_expectdateLayer(layerId, obj, date1, date2) {

    if ($('#' + layerId).length == 0) {
        var layer = document.createElement("div");
        document.body.appendChild(layer);
        $(layer).css("position", "absolute");
        $(layer).hide();

        var x, y;

        x = get_obj_x(obj);
        y = get_obj_y(obj);

        $(layer).load('/24/content/yes24layer.html #' + layerId, function() {
            set_layer_xy(this, x, y);
            $("#lblExpect1", this).html(date1);
            $("#lblExpect2", this).html(date1);
            $("#lblExpect3", this).html(date2);
            $(this).show();
        });

    }

}

function open_msgLayer(layerId, obj, msg) {

    if ($('#' + layerId).length == 0) {
        var layer = document.createElement("div");
        document.body.appendChild(layer);
        $(layer).css("position", "absolute");
        $(layer).hide();

        var x, y;
        x = get_obj_x(obj);
        y = get_obj_y(obj);

        $(layer).load('/24/content/yes24layer.html #' + layerId, function () {
            set_layer_xy(this, x, y);
            $("#msg", this).html(msg);
            $(this).show();
        });
    }
}

function open_usedgoodsLayer(layerId, obj, msg_grade, msg_state, msg_usesign, msg_damage, msg_acesori) {
    if ($('#' + layerId).length == 0) {
        var layer = document.createElement("div");
        document.body.appendChild(layer);
        $(layer).css("position", "absolute");
        $(layer).hide();

        var x, y;
        x = get_obj_x(obj);
        y = get_obj_y(obj);

        $(layer).load('/24/content/yes24layer.html #' + layerId, function () {
            set_layer_xy(this, x, y);

            $("#msg_grade", this).html(msg_grade);
            $("#msg_state", this).html(msg_state);
            $("#msg_usesign", this).html(msg_usesign);
            $("#msg_damage", this).html(msg_damage);
            $("#msg_acesori", this).html(msg_acesori);

            $(this).show();
        });
    }
}

function goodsLineBanner(filegroup, goodssortno, isfreeprice) {
    var banner = "";
    var imageFormat = "<a href='{1}'>" + "<img src='{2}' alt='{3}' " + "style='border-style: none'/></a>";
    var couponFormat = "<a href='javascript:getEventGouponDownload(\"{1}\");'>" + "<img src='{2}' alt='{3}' " + "style='border-style: none'/></a>";
    $.ajax({
        async: true
        , cache: false
        , type: 'get'
		, dataType: "xml"
		, url: "../_par_/Goods/" + filegroup + "_GoodsLineBanner.xml"
		, success: function (xml) {
		    if ($(xml).find("list").find("banner").length > 0) {
		        $(xml).find("list").find("banner").each(function () {
		            if (goodssortno.indexOf($(this).find("sortno").text()) == 0) {
		                var now = new Date();
		                var s = getDateByString($(this).find("startdate").text());
		                var e = getDateByString($(this).find("enddate").text());

		                if (now.getTime() >= s.getTime() && now < e.getTime()) {
		                    if ($(this).find("isincludenewbook").text() == "true" || isfreeprice == true) {
		                        var src = $(this).find("src").text();
		                        var url = $(this).find("url").text();
		                        var title = $(this).find("title").text();
		                        if ($(this).find("iscoupondown").text() == "true")
		                            banner = couponFormat.replace('{1}', url).replace('{2}', src).replace('{3}', title);
		                        else
		                            banner = imageFormat.replace('{1}', url).replace('{2}', src).replace('{3}', title);

		                        $("#goodsLineBanner").html(banner);
		                    }
		                }
		            }
		        });
		    }
		}
		, error: function (xhr, status, error) { }
    });
}
function getDateByString(idate) {
    var arrDate = idate.split('-');

    var d = new Date(arrDate[0], arrDate[1], arrDate[2]);
    d.setMonth(d.getMonth() - 1); // because javascript month start zero
    return d;
}
