var currOpen = "";
var lock = false;
var onOpenMenu = function(i) {
    if (!lock) {
        lock = true;
        
        if(currOpen==i) {
            ViewLayer.Slide({
                element: $("ctl00_cphBody_sub_item_"+currOpen),
                speed: 3,
                values: {
                    height:0
                },
                func: function(){
                    lock = false;
                }
            });
            currOpen = "";
        } else {
            ViewLayer.Slide({
                element: $("ctl00_cphBody_sub_item_"+currOpen),
                speed: 3,
                values: {
                    height:0
                }
            });
            ViewLayer.Slide({
                element: $("ctl00_cphBody_sub_item_"+i),
                speed: 3,
                values: {
                    height:250
                },
                func: function(){
                    lock = false;
                }
            });
            currOpen = i;
        }
    }
}

var currTab = "1";
var loadedi2 = false;
var loadedi3 = false;
var onChangeTab = function(t) {
    $("tab_" + currTab).className = "good_tab";
    $("tab_" + t).className = "good_tab curr";
    
    $("tab_panel_" + currTab).style.display = "none";
    $("tab_panel_" + t).style.display = "block";
    
    currTab = t;
    
    if (t == "2" && !loadedi2) {
        ViewLayer.ajax({
            url : "/lib/xml-rpc/HomeAction.ashx?act=getgoods",
            type : "json",
            data : {
                action : "POST",
                values : "t=N"
            },
            success : function (x) {
                $("panel_2").innerHTML = "";
                for(var i=0; i<x.dt.length; i++) {
                    var strShortName = (x.dt[i].GoodName.length > 15) ? x.dt[i].GoodName.substr(0, 12) : x.dt[i].GoodName;
                    var strPrice = commafy(x.dt[i].Price);
                    $("panel_2").innerHTML += setGoodItem(x.dt[i].GoodId, x.dt[i].GoodThumURL, strShortName, strPrice, x.dt[i].GoodName);
                }
                loadedi2 = true;
            }
        });
    } else if (t == "3" && !loadedi3) {
        ViewLayer.ajax({
            url : "/lib/xml-rpc/HomeAction.ashx?act=getgoods",
            type : "json",
            data : {
                action : "POST",
                values : "t=H"
            },
            success : function (x) {
                $("panel_3").innerHTML = "";
                for(var i=0; i<x.dt.length; i++) {
                    var strShortName = (x.dt[i].GoodName.length > 15) ? x.dt[i].GoodName.substr(0, 12) : x.dt[i].GoodName;
                    var strPrice = commafy(x.dt[i].Price);
                    $("panel_3").innerHTML += setGoodItem(x.dt[i].GoodId, x.dt[i].GoodThumURL, strShortName, strPrice, x.dt[i].GoodName);
                }
                loadedi3 = true;
            }
        });
    }
}

var setGoodItem = function(GoodId, GoodThumURL, strShortName, Price, GoodName) {
    var temp = "<div class=\"list_item\">" +
               "<a target=\"_blank\" href=\"/goods/item-"+GoodId+"\" class=\"thum\" title=\""+GoodName+"\"><img src=\""+GoodThumURL+"\" alt=\""+strShortName+"\" width=\"100\" height=\"100\" /></a>" +
               "<div><a target=\"_blank\" href=\"/goods/item-"+GoodId+"\" title=\""+GoodName+"\">"+strShortName+"</a></div><div><small>&yen;"+Price+"</small></div></div>";
    return temp;
}

var onLoginSubmit = function(source, args) {
    var result = true;
    if($("ctl00_cphBody_txtEmail").value == "") {
        $("ctl00_cphBody_lblMessage").innerHTML = "请输入邮箱";
        result = false;
    } else if (!$("ctl00_cphBody_txtEmail").value.match(/^[A-Za-z0-9._%+-]+@+([A-Za-z0-9]+\.)+[A-Za-z]{2,4}$/)) {
        $("ctl00_cphBody_lblMessage").innerHTML = "邮箱格式不正确";
        result = false;
    } else if ($("ctl00_cphBody_txtPassword").value == "") {
        $("ctl00_cphBody_lblMessage").innerHTML = "请输入密码";
        result = false;
    } else if ($("ctl00_cphBody_txtPassword").value.length < 6) {
        $("ctl00_cphBody_lblMessage").innerHTML = "密码长度不对";
        result = false;
    } else {
        result = true;
    }
    args.IsValid = result;
}

var onSearch = function() {
    if(event.keyCode == 13){ document.getElementById("<%= ibtnSearch.ClientID %>").click(); }
}
