﻿$(function(){
YYYYMMDDstart();
callServerGetProvince();    
});

function callServerGetProvince() {
    head.getProvince(function CallBack(response) {
        if (response.value.Rows.length > 0) {
            for (var i = 0; i < response.value.Rows.length; i++) {
                document.getElementById("ddlProvince").options.add(new Option(" " + response.value.Rows[i]["province"], response.value.Rows[i]["provinceID"]));
            }
        }
    });
}

function callServerGetCity(value) {
    if (value == "") {
         document.getElementById("ddlCtiy").options.length = 1;
        document.getElementById("ddlArea").options.length = 1;
        return;
    }
    head.getCity(value, function CallBack(response) {
        if (response.value.Rows.length > 0) {
            document.getElementById("ddlCtiy").options.length = 1;
            document.getElementById("ddlArea").options.length = 1;
            for (var i = 0; i < response.value.Rows.length; i++) {
                document.getElementById("ddlCtiy").options.add(new Option(" " + response.value.Rows[i]["city"], response.value.Rows[i]["cityID"]));
            }
        }
        else {
            document.getElementById("ddlCtiy").options.length = 1;
            document.getElementById("ddlArea").options.length = 1;
            return;
        }
    });
}

function callServerGetArea(value) {
    if (value == "") {
        document.getElementById("ddlArea").options.length = 1;
        return;
    }
    head.getArea(value, function CallBack(response) {
        if (response.value.Rows.length > 0) {
            document.getElementById("ddlArea").options.length = 1;
            for (var i = 0; i < response.value.Rows.length; i++) {
                document.getElementById("ddlArea").options.add(new Option(" " + response.value.Rows[i]["area"], response.value.Rows[i]["areaID"]));
            }
        }
        else {
            document.getElementById("ddlArea").options.length = 1;
            return;
        }
    });
}

function getCart()
{
    head.getCart(function(res) {
        $('#tbody').html("");
        if (res.value != null) {
            for (var i = 0; i < res.value.Rows.length; i++) {
                $('#tbody').append("<tr><td class=\"product\"><img src=http://image.viptemai.net/web/" + res.value.Rows[i]["proPic"] + " /></td><td class='info'><strong>" + res.value.Rows[i]["proName"] + "</strong><p><span>型号：</span>" + res.value.Rows[i]["proKindName"] + "</p></td><td class='price' id='222'>" + res.value.Rows[i]["proNewPrice"] + "</td><td class='number'><div class='td'><div id='t"+res.value.Rows[i]["proID"]+"' class='tipsBar'><span id='sss'  class='pointer pointerB'></span><p>数量已修改</p></div></div><input type=\"text\" value=\"" + res.value.Rows[i]["proQuantity"] + "\"  /></td><td class='total'>" + res.value.Rows[i]["proSumPrice"] + "</td><td class='control'><label onclick=\"delCar('" + res.value.Rows[i]["proID"] + "');\">删除</label></td></tr>");
            }
            windowShoppingCar();           
        }
    });
}

function windowShoppingCar() {
    $('#popLogin input').each(function() {
        $(this).val('');
    })
     $("#popShoppingCart").modal({
            overlayId: 'osx-overlay',
            containerId: 'osx-container',

            minHeight: 80,
            opacity: 65,
            position: ['0', ],
            overlayClose: true,
            onOpen: popShoppingCart.open,
            onClose: popShoppingCart.close
        });
}

function windowLogin()
{
    $("#popLogin").modal({
            overlayId: 'osx-overlay',
            containerId: 'osx-container',

            minHeight: 80,
            opacity: 65,
            position: ['0', ],
            overlayClose: true,
            onOpen: popLogin.open,
            onClose: popLogin.close
        });
        ReloadCode();
//        $("#loginstatus fieldset").not("#loginstatus fieldset:first").hide();
}

var popShoppingCart = {
        container: null,
        open: function(d) {
            var self = this;
            self.container = d.container[0];
            d.overlay.fadeIn('slow', function() {
                $("#popShoppingCart", self.container).show();
                var title = $("#popShoppingCartTitle", self.container);
                title.show();
                d.container.slideDown('slow', function() {
                    setTimeout(function() {
                        var h = $("#popShoppingCartData", self.container).height()
							+ title.height()
							+ 20; // padding
                        d.container.animate(
							{ height: h },
							0,
							function() {
							    $("div.close", self.container).show();
							    $("#popShoppingCartData", self.container).show();
							}
						);
                    }, 300);
                });
            })
        },




		close: function(d) {
            var self = this;
            d.container.animate(
				{ top: "-" + (d.container.height() + 20) },
				500,
				function() {
				    self.close(); // or $.modal.close();
				}
			);
        }
    };

    var popLogin = {
        container: null,
        open: function(d) {
            var self = this;
            self.container = d.container[0];
            d.overlay.fadeIn('slow', function() {
                $("#popLogin", self.container).show();
                var title = $("#popLoginTitle", self.container);
                title.show();
                d.container.slideDown('slow', function() {
                    setTimeout(function() {
                        var h = $("#popLoginData", self.container).height()
							+ title.height()
							+ 20; // padding
                        d.container.animate(
							{ height: h },
							0,
							function() {
							    $("div.close", self.container).show();
							    $("#popLoginData", self.container).show();
							}
						);
                    }, 300);
                });
            })
        },
        close: function(d) {
            var self = this;
            d.container.animate(
				{ top: "-" + (d.container.height() + 20) },
				500,
				function() {
				    self.close(); // or $.modal.close();
				    $("#loginstatus fieldset").hide();
				    $("#loginstatus fieldset:first").show();
				    $(".formAlipay").show();
				}
			);
        }
    };
    
