﻿
var isEmail = function(str) {
    return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(str);
};
var isMobile = function(str) {
    return /^(13[0-9]|15[0-9]|18[0-9])\d{8}$/.test(str); //最新手机号
    //return /^(13[0-9]|15[0|3|6|7|8|9]|18[2|7|8|9])\d{8}$/.test(str); //最新手机号
    /*return /^((\(\d{3}\))|(\d{3}\-))?1(3|5|8)\d{9}$/.test(str);*/
};
var isZipCode = function(str) {
    return /^[0-9]\d{5}$/.test(str);
};
var isPhone = function(str) {
    return /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}$/.test(str);
};

var isNumber = function(str) {
    return /^\d+$/.test(str);

}



//保留两位小数    
//功能：将浮点数四舍五入，取小数点后2位  
function toDecimal(x) {
    var f = parseFloat(x);
    if (isNaN(f)) {
        return false;
    }
    var f = Math.round(x * 100) / 100;
    var s = f.toString();
    var pos = s.indexOf('.');
    if (pos < 0) {
        pos = s.length;
        s += '.';
    }
    while (s.length <= pos + 2) {
        s += '0';
    }

    return s;
}

/**
* 头部数据ajax初始化
**/
$(document).ready(function() {

    $("#fieldkeyword").focus(function() {
        if ($(this).val() == "输入你想搜索的关键字") {
            $(this).val('');
        }
    }).blur(function() {
        if ($(this).val() == '') {
            $(this).val("输入你想搜索的关键字");
        }
    });

    var urlkwd = decodeURI(request('kwd'));
    if (urlkwd != null && urlkwd != '' && typeof (urlkwd) != "undefined") {
        $("#fieldkeyword").val(urlkwd);
    }

    var selid = request('typeid');
    var selcurr = $("#subopt_" + selid).attr("title");
    $("#subopt_" + selid).html("<b>" + selcurr + "</b>");
    $('#cmenu_span').html(selcurr);


});


/*加入购物车*/
function p_addToCart(pid) {
    location.href = '/shopping/cartadd.aspx?pid=' + pid;
}

var addToCart = function(pid, quantity, comboId, reload, jump) {
    if (comboId == null)
        comboId = -1;
    $.ajax({
        type: "post",
        dataType: "json",
        url: "/shopping/ajax/cartaction.ashx?action=addtocart&t=" + encodeURI(new Date().getTime()),
        data: "pid=" + pid + "&qty=" + quantity + "&comboid=" + comboId,
        beforeSend: function(XMLHttpRequest) {
            /*showLoading();*/
        },
        success: function(data, textStatus) {
            //$("#goods_car_show").html("");
            var json = eval(data);
            var msg = json.entry[0].message;
            var success = json.entry[0].success;
            var orderamount = json.entry[0].orderamount;
            var ordermoney = json.entry[0].ordermoney;

            if (success) {

                $("#carcount").html(orderamount);
                $("#carmoney").html("<strong>" + ordermoney + "</strong>");
                alertMsg(msg, reload);
                if (jump)//是否购买后跳到购物车页面
                    window.location.href = "/shopping/cart.aspx?rnd=" + Math.round(Math.random() * 2147483647);
            } else {
                alertMsg(msg, false);
            }
        },
        complete: function(XMLHttpRequest, textStatus) {
            /*HideLoading();*/
        },
        error: function() {
            alertMsg("系统错误 添加商品失败");
        }
    });
};


//直接购买
function p_directBuy(pid) {
    location.href = '/shopping/cartadd.aspx?pid=' + pid;
}

var directBuy = function(pid, quantity, comboId, reload, jump) {
    if (comboId == null)
        comboId = -1;

    $.ajax({
        type: "post",
        dataType: "json",
        url: "/shopping/ajax/cartaction.ashx?action=directbuy&t=" + new Date().getTime(),
        data: "pid=" + pid + "&qty=" + quantity + "&comboid=" + comboId,
        beforeSend: function(XMLHttpRequest) {
            /*showLoading();*/
        },
        success: function(data, textStatus) {
            //$("#goods_car_show").html("");
            var json = eval(data);
            var msg = json.entry[0].message;
            var success = json.entry[0].success;
            var orderamount = json.entry[0].orderamount;
            var ordermoney = json.entry[0].ordermoney;

            if (success) {

                $("#carcount").html(orderamount);
                $("#carmoney").html("<strong>" + ordermoney + "</strong>");
                //alertMsg(msg, reload);
                window.setTimeout(function() {
                    if (jump)//是否购买后跳到购物车页面
                        window.location.href = "/shopping/cart.aspx?rnd=" + Math.round(Math.random() * 2147483647);
                }, 1000);

            } else {
                alertMsg(msg, false);
            }
        },
        complete: function(XMLHttpRequest, textStatus) {
            /*HideLoading();*/
        },
        error: function() {
            alertMsg("系统错误 添加商品失败");
        }
    });
};


/*头部购物车[只在购物车页面上使用]*/
function headerCart() {
    $.ajax({
        type: "post",
        dataType: "json",
        url: "/shopping/ajax/cartaction.ashx?action=headercart&t=" + encodeURI(new Date().getTime()),
        success: function(data) {
            //$("[name='goodscount']").each(function() { $(this).html(data.carCount) });
            //$("[name='goodstotal']").each(function() { $(this).html("￥" + data.carTotalPrice + ".00") });
            var entry = eval(data).entry[0];
            var success = eval(data).entry[0].success;
            var totalamount = eval(data).entry[0].totalamount;
            var totalprice = eval(data).entry[0].totalprice;
            var totalweight = entry.totalweight;
            if (success) {
                //头部购物车
                $("#carcount").html(totalamount); //头部
                $("#carmoney").html("<strong>" + totalprice + "</strong>");
                //购物车统计
                $("#carttotalcount").html(totalamount);
                $("#carttotalmoney").html('￥' + totalprice); //总金额
                $("#carttotalweight").html(totalweight); //总重量
                $("#hdqty").val(totalamount);
            }

        },
        error: function() { }
    });
};

/*商品数量增加*/
function addCountToCart(pid, comboId) {
    if (parseInt($("#goodscount_" + pid).val()) > cart_max_amount - 1) {
        alertMsg("商品数量不能大于" + cart_max_amount);
        return;
    }
    if (comboId == null) {
        comboId = -1;
    }
    $.ajax({
        type: "post",
        dataType: "json",
        url: "/shopping/ajax/cartaction.ashx?action=addcountcart&t=" + encodeURI(new Date().getTime()),
        data: "pid=" + pid + "&comboid=" + comboId,
        success: function(data, textStatus) {
            var msg = eval(data).entry[0].message;
            var success = eval(data).entry[0].success;
            if (success) {
                var count = parseInt($("#goodscount_" + pid).val()) + 1;
                $("#goodscount_" + pid).val(count);
                var total = toDecimal($("#goodsprice_" + pid).html()) * count;
                total = toDecimal(total);
                $("#goodstotal_" + pid).html(total);
                //headerCart();
                alertMsg(msg, true);
            } else {
                alertMsg(msg, false);
            }
        },
        error: function() {
            alertMsg("系统错误 增加商品数量失败");
        }
    });
};

/*商品数量减少*/
function subCountToCart(pid, comboId) {
    if (parseInt($("#goodscount_" + pid).val()) < cart_min_amount + 1) {
        alertMsg("商品数量不能小于1");
        return;
    }
    if (comboId == null) {
        comboId = -1;
    }
    $.ajax({
        type: "post",
        dataType: "json",
        url: "/shopping/ajax/cartaction.ashx?action=subcountcart&t=" + encodeURI(new Date().getTime()),
        data: "pid=" + pid + "&comboid=" + comboId,
        success: function(data, textStatus) {
            var msg = eval(data).entry[0].message;
            var success = eval(data).entry[0].success;
            if (success) {
                var count = parseInt($("#goodscount_" + pid).val()) - 1;
                $("#goodscount_" + pid).val(count);
                var total = toDecimal($("#goodsprice_" + pid).html()) * count;
                total = toDecimal(total);
                $("#goodstotal_" + pid).html(total);
                //headerCart();
                alertMsg(msg, true);
            } else {
                alertMsg(msg, false);
            }
        },
        error: function() {
            alertMsg("系统错误 减少商品数量失败");
        }
    });
};


/*购物车删除商品*/
function delToCart(pid, comboId) {

    if (!confirm("确定移除此商品吗？")) { return false; }


    if (comboId == null) {
        comboId = -1;
    }
    $.ajax({
        type: "post",
        dataType: "json",
        url: "/shopping/ajax/cartaction.ashx?action=removecart&t=" + encodeURI(new Date().getTime()),
        data: "pid=" + pid + "&comboid=" + comboId,
        success: function(data, textStatus) {
            //$("#goods_car_show").html("");
            var msg = eval(data).entry[0].message;
            var success = eval(data).entry[0].success;
            if (success) {
                $("#cart_tr_" + pid).hide();
                //清空成功
                alertMsg(msg, true);
            } else {
                //清空失败
                alertMsg(msg, false);
            }
        },
        error: function() {
            alertMsg("系统错误 移除商品失败");
        }
    });
};

/*清空购物车商品*/
function clearCart(reload) {

    if (!confirm("确定清空购物车吗？")) { return false; }

    $.ajax({
        type: "post",
        dataType: "json",
        url: "/shopping/ajax/cartaction.ashx?action=clearcart&t=" + encodeURI(new Date().getTime()),
        data: "1=1",
        success: function(data, textStatus) {
            var msg = eval(data).entry[0].message;
            var success = eval(data).entry[0].success;
            if (success) {
                //清空成功
                $('.cart_l_bottom .cart_null').hide();
                $('#carttotalcount').html('0');
                $('#carttotalmoney').html('0.00');
                $("#carcount").html('0');
                $("#carmoney").html("<strong>0.00</strong>");
                alertMsg(msg, reload);
            } else {
                //清空失败
                alertMsg(msg, false);
            }
        },
        error: function() {
            alertMsg("系统错误 清空购物车商品失败");
        }
    });
};

//添加收藏
function doAddFavour(pid, type) {
    $.ajax({
        type: "post",
        dataType: "json",
        url: "/shopping/ajax/favouraction.ashx?action=favourite_add&t=" + encodeURI(new Date().getTime()),
        data: "pid=" + pid + "&cate=" + type,
        success: function(data) {

            var msg = eval(data).entry[0].message;
            var success = eval(data).entry[0].success;
            var login = eval(data).entry[0].login;
            var have = eval(data).entry[0].have;

            if (success == "true" && login == "false") {
                alertMsgTime("您还没有登录！&nbsp;<a href=\"/portal/?refer=" + location.href + "\">立即登录</a>", false, 4500);
                return;
            }

            if (success == "true" && have == "true") {
                alertMsg("此产品您已收藏过！");
                return;
            }

            alertMsg(msg);

        },
        error: function() {
            alertMsg("系统错误 添加收藏失败");
        }
    });
};


/*添加浏览历史*/
function addToViewHistory(pid, reload) {
    $.ajax({
        type: "post",
        dataType: "json",
        url: "/shopping/ajax/viewhistory.ashx?action=addtohistory&t=" + encodeURI(new Date().getTime()),
        data: "pid=" + pid,
        beforeSend: function(XMLHttpRequest) {
            /*showLoading();*/
        },
        success: function(data, textStatus) {
            //$("#goods_car_show").html("");
            var msg = eval(data).entry[0].message;
            var success = eval(data).entry[0].success;
            var totalamount = eval(data).entry[0].totalamount;
            var totalprice = eval(data).entry[0].totalprice;
            if (success) {
                //添加
            }
            alertMsg(msg, reload);
        },
        complete: function(XMLHttpRequest, textStatus) {
            /*HideLoading();*/
        },
        error: function() {
            alertMsg("系统错误 添加浏览历史失败");
        }
    });
};


/*清空浏览历史*/
function clearViewHistory() {
    $.ajax({
        type: "post",
        dataType: "json",
        url: "/shopping/ajax/viewhistory.ashx?action=clearhistory&t=" + encodeURI(new Date().getTime()),
        beforeSend: function(XMLHttpRequest) {
            /*showLoading();*/
        },
        success: function(data, textStatus) {

            var message = eval(data).entry[0].message;
            var success = eval(data).entry[0].success;

            if (success) {
                $("#dv_viewhistory").remove();
            }

            alertMsg(message);

        },
        complete: function(XMLHttpRequest, textStatus) {
            /*HideLoading();*/
        },
        error: function() {
            alertMsg("系统错误 清空浏览历史失败");
        }
    });
};



/*弹出提示层:是否重载当前页面*/
var alertMsg = function(msg, reload) {
    alertMsgEx(msg, reload, '', true);
};

/*弹出提示层:是否转向指定页面*/
var redirectMsg = function(msg, url) {
    alertMsgEx(msg, false, url, true);
};

/*弹出提示层：等待时间不可设置*/
var alertMsgEx = function(msg, reload, url, autohide) {
    //alert(msg);
    if ($("#alertbox").html() != null) return;
    var y; //取滚动条高度
    if (self.pageYOffset) y = self.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop) y = document.documentElement.scrollTop;
    else if (document.body) y = document.body.scrollTop;

    var top = (screen.height + 100 - 250) / 2 - 150 + y;
    var left = screen.width / 2 - 279 / 2;
    var box = "<div id=\"alertbox\" style=\"margin:0 auto;padding:0;width:363px;position:absolute; z-index:11000;top:" + top + "px;left:" + left + "px;\">";
    //box += "<p style=\"margin:0;padding:0;\"><img src=\"/images/ajax/tcc_tit.gif\"/></p>";//标题栏
    box += "<div style=\"width:360px;margin:0 auto;border:2px solid #C0C0C0;background:#F5F5F5;overflow:hidden;\">";
    box += "<div style=\"clear:both;padding:30px 30px 20px 30px;color:#565662;font-size:14px;letter-spacing:1px;text-align:center;line-height:24px;overflow:hidden;\">";
    box += "<p style=\"margin:0;padding:0;\">" + msg + "</p>";
    box += "<div><input type=\"button\" style=\"clear:both;margin-top:10px;padding:0;background:url(/images/ajax/tcc_btn.gif) no-repeat;border:0;width:61px;height:21px;cursor:pointer;\"/></div>";
    box += "</div>";
    box += "</div>";
    box += "</div>";
    $("body").append(box);
    $("#alertbox").animate({ opacity: "1" }, 500, function() {
        $(this).find("input").click(function() {
            $("#alertbox").animate({ opacity: "0" }, 1000, function() {
                $("#alertbox").remove();
                if (!reload && url != '') {
                    window.location.href = url;
                } else {
                    if (reload) window.location.reload();
                }
            });
        });
    });
    /*自动隐藏*/
    if (autohide) {
        window.setTimeout(function() {
            $("#alertbox").animate({ opacity: "0" }, 1000, function() {
                $("#alertbox").remove();
                if (!reload && url != '') {
                    window.location.href = url;
                } else {
                    if (reload) window.location.reload();
                }
            });
        }, 500);
    }

};


/*等待提示层：可自定义等待时间*/
var alertMsgTime = function(msg, reload, timeout) {
    alertMsgTimeEx(msg, reload, '', true, timeout);
};

/*等待提示层：可自定义等待时间*/
var alertMsgTimeEx = function(msg, reload, url, autohide, timeout) {

    if ($("#alertbox").html() != null) return;
    var y; //取滚动条高度
    if (self.pageYOffset) y = self.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop) y = document.documentElement.scrollTop;
    else if (document.body) y = document.body.scrollTop;

    var top = (screen.height + 100 - 250) / 2 - 150 + y;
    var left = screen.width / 2 - 279 / 2;
    var box = "<div id=\"alertbox\" style=\"margin:0 auto;padding:0;width:363px;position:absolute; z-index:11000;top:" + top + "px;left:" + left + "px;\">";
    //box += "<p style=\"margin:0;padding:0;\"><img src=\"/images/ajax/tcc_tit.gif\"/></p>";//标题栏
    box += "<div style=\"width:360px;margin:0 auto;border:2px solid #C0C0C0;background:#F5F5F5;overflow:hidden;\">";
    box += "<div style=\"clear:both;padding:30px 30px 20px 30px;color:#565662;font-size:14px;letter-spacing:1px;text-align:center;line-height:24px;overflow:hidden;\">";
    box += "<p style=\"margin:0;padding:0;\">" + msg + "</p>";
    box += "<div><input type=\"button\" style=\"clear:both;margin-top:10px;padding:0;background:url(/images/ajax/tcc_btn_close.gif) no-repeat;border:0;width:61px;height:21px;cursor:pointer;\"/></div>";
    box += "</div>";
    box += "</div>";
    box += "</div>";
    $("body").append(box);
    $("#alertbox").animate({ opacity: "1" }, 500, function() {
        $(this).find("input").click(function() {
            $("#alertbox").animate({ opacity: "0" }, 1000, function() {
                $("#alertbox").remove();
                if (!reload && url != '') {
                    window.location.href = url;
                } else {
                    if (reload) window.location.reload();
                }
            });
        });
    });
    /*自动隐藏*/
    if (autohide) {
        timeout = (timeout == '' ? 2000 : timeout);
        window.setTimeout(function() {
            $("#alertbox").animate({ opacity: "0" }, 1000, function() {
                $("#alertbox").remove();
                if (!reload && url != '') {
                    window.location.href = url;
                } else {
                    if (reload) window.location.reload();
                }
            });
        }, timeout);
    }

};


/*确认提示层：确认后转向指定地址*/
var confirmEx = function(msg, url) {
    if ($("#alertbox").html() != null) return;
    var y; //取滚动条高度
    if (self.pageYOffset) y = self.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop) y = document.documentElement.scrollTop;
    else if (document.body) y = document.body.scrollTop;

    var top = (screen.height + 100 - 250) / 2 - 150 + y;
    var left = screen.width / 2 - 279 / 2;
    var box = "<div id=\"alertbox\" style=\"margin:0 auto;padding:0;width:363px;position:absolute; z-index:11000;top:" + top + "px;left:" + left + "px;\">";
    box += "<div style=\"width:360px;margin:0 auto;border:2px solid #C0C0C0;background:#F5F5F5;overflow:hidden;\">";
    box += "<div style=\"clear:both;padding:30px 30px 20px 30px;color:#565662;font-size:14px;letter-spacing:1px;text-align:center;line-height:24px;overflow:hidden;\">";
    box += "<p style=\"margin:0;padding:0;\">" + msg + "</p>";
    box += "<div>";
    box += "<input type=\"button\" id=\"btnSure\" style=\"clear:both;margin-top:10px;padding:0;background:url(/images/ajax/tcc_btn_sure.gif) no-repeat;border:0;width:61px;height:21px;cursor:pointer;\"/>";
    box += "&nbsp;<input type=\"button\" id=\"btnExit\"style=\"clear:both;margin-top:10px;padding:0;padding-left:8px;background:url(/images/ajax/tcc_btn_close.gif) no-repeat;border:0;width:61px;height:21px;cursor:pointer;\"/>";
    box += "</div>";
    box += "</div>";
    box += "</div>";
    box += "</div>";
    $("body").append(box);

    /*alertbox*/
    $("#alertbox").animate({ opacity: "1" }, 500, function() {
        $(this).find("input[id='btnSure']").click(function() {
            $("#alertbox").animate({ opacity: "0" }, 1000, function() {
                $("#alertbox").remove();
                if (url != '') {
                    window.location.href = url;
                } else {
                    if (reload) window.location.reload();
                }
            });
        });

        $(this).find("input[id='btnExit']").click(function() {
            $("#alertbox").animate({ opacity: "0" }, 1000, function() {
                $("#alertbox").remove();
            });
        });
    });
    /*alertbox ending*/

    /*自动隐藏*/
    var autohide = true;
    if (autohide) {
        var timeout = 6000;
        window.setTimeout(function() {
            $("#alertbox").animate({ opacity: "0" }, 1000, function() {
                $("#alertbox").remove();
            });
        }, timeout);
    }
};

/*确认退出层：确认后转向指定地址*/
var confirmLogoutEx = function(msg, url) {
    if ($("#alertbox").html() != null) return;
    var y; //取滚动条高度
    if (self.pageYOffset) y = self.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop) y = document.documentElement.scrollTop;
    else if (document.body) y = document.body.scrollTop;

    var top = (screen.height + 100 - 250) / 2 - 150 + y;
    var left = screen.width / 2 - 279 / 2;
    var box = "<div id=\"alertbox\" style=\"margin:0 auto;padding:0;width:363px;position:absolute; z-index:11000;top:" + top + "px;left:" + left + "px;\">";
    box += "<div style=\"width:360px;margin:0 auto;border:2px solid #C0C0C0;background:#F5F5F5;overflow:hidden;\">";
    box += "<div style=\"clear:both;padding:30px 30px 20px 30px;color:#565662;font-size:14px;letter-spacing:1px;text-align:center;line-height:24px;overflow:hidden;\">";
    box += "<p style=\"margin:0;padding:0;\">" + msg + "</p>";
    box += "<div>";
    box += "<input type=\"button\" id=\"btnSure\" style=\"clear:both;margin-top:10px;padding:0;background:url(/images/ajax/tcc_btn_sure.gif) no-repeat;border:0;width:61px;height:21px;cursor:pointer;\"/>";
    box += "&nbsp;<input type=\"button\" id=\"btnExit\"style=\"clear:both;margin-top:10px;padding:0;padding-left:8px;background:url(/images/ajax/tcc_btn_close.gif) no-repeat;border:0;width:61px;height:21px;cursor:pointer;\"/>";
    box += "</div>";
    box += "</div>";
    box += "</div>";
    box += "</div>";
    $("body").append(box);

    /*alertbox*/
    $("#alertbox").animate({ opacity: "1" }, 500, function() {
        $(this).find("input[id='btnSure']").click(function() {
            $("#alertbox").animate({ opacity: "0" }, 1000, function() {
                $.cookie(COOKIE_NAME, null, { expires: -1, path: '/' });
                $("#alertbox").remove();
                if (url != '') {
                    window.location.href = url;
                } else {
                    if (reload) window.location.reload();
                }
            });
        });

        $(this).find("input[id='btnExit']").click(function() {
            $("#alertbox").animate({ opacity: "0" }, 1000, function() {
                $("#alertbox").remove();
            });
        });
    });
    /*alertbox ending*/

    /*自动隐藏*/
    var autohide = true;
    if (autohide) {
        var timeout = 6000;
        window.setTimeout(function() {
            $("#alertbox").animate({ opacity: "0" }, 1000, function() {
                $("#alertbox").remove();
            });
        }, timeout);
    }

};


//等待提示弹屏
var loadingEx = function(msg) {
    if ($("#alertbox_loading").html() != null) return;
    var y; //取滚动条高度
    if (self.pageYOffset) y = self.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop) y = document.documentElement.scrollTop;
    else if (document.body) y = document.body.scrollTop;

    var top = (screen.height + 100 - 250) / 2 - 150 + y;
    var left = screen.width / 2 - 279 / 2;
    var box = "<div id=\"alertbox_loading\" style=\"margin:0 auto;padding:0;width:363px;position:absolute; z-index:11000;top:" + top + "px;left:" + left + "px;\">";
    box += "<div style=\"width:360px;margin:0 auto;border:2px solid #C0C0C0;background:#F5F5F5;overflow:hidden;\">";
    box += "<div style=\"clear:both;padding:10px 10px 5px 10px;color:#565662;font-size:14px;letter-spacing:1px;text-align:center;line-height:24px;overflow:hidden;\">";
    box += "<p style=\"margin:0;padding:0;\">" + msg + "</p>";
    box += "<div style=\"padding:10px 0 20px;\">";
    box += "<image src='/images/ajax/tcc_loading.gif' width='32px' height='32px'\"/>";
    box += "</div>";
    box += "</div>";
    box += "</div>";
    box += "</div>";
    $("body").append(box);

};

//移除等待弹屏
var removeEx = function(id) {
    var $container = (id == null || id == '' ? $("#alertbox_loading") : $("#" + id));
    $container.animate({ opacity: "0" }, 100, function() {
        $container.remove();
    });
}


//搜索
function doSearcher(etid, ekwd) {

    var tid = $("#" + etid).val();
    var kwd = $("#" + ekwd).val();
    var url = "/product/searcher.aspx?typeid=" + tid + "&kwd=" + encodeURI(kwd);
    //alert(url);
    if (kwd != '' && kwd != '输入你想搜索的关键字') {
        location.href = url;
    } else {
        alertMsg("请输入你想搜索的关键字", false);
        return false;
    }
}

function doQueryProduct(ekwd) {

    var kwd = $("#" + ekwd).val();
    var url = "/product/searcher.aspx?kwd=" + encodeURI(kwd);
    //alert(url);
    if (kwd != '' && kwd != '搜索名称或编号') {
        location.href = url;
    } else {
        alertMsg("请输入你想搜索名称或编号", false);
        return false;
    }
}

function doQueryTeacher(ekwd) {

    var kwd = $("#" + ekwd).val();
    var url = "/teacher/default.aspx?kwd=" + encodeURI(kwd);
    //alert(url);
    if (kwd != '' && kwd != '搜索文章关键字') {
        location.href = url;
    } else {
        alertMsg("请输入你想搜索文章关键字", false);
        return false;
    }
}

function doLogout() {
    var url = '/portal/logout.aspx?t=' + new Date().getTime();
    //$.cookie('wwwcom',null,{ expires: 0, path: '/'});	
    confirmEx("您确定要退出吗?", url);
}


//热键方法
function pressEvent(btnId) {
    if (event.keyCode == 13) {
        event.keyCode = 9;
        event.returnValue = false;
        $('#' + btnId).click();
        return false;
    }
}


//输入参数名,返回参数值
function request(paras) {
    var url = location.href;
    var paramStr = url.substring(url.indexOf('?') + 1, url.length).split('&');
    var j;
    var paramObj = {};
    for (var i = 0; j = paramStr[i]; i++) {
        paramObj[j.substring(0, j.indexOf('=')).toLowerCase()] = j.substring(j.indexOf('=') + 1, j.length);
    }

    var returnValue = paramObj[paras.toLowerCase()];

    if (typeof (returnValue) == "undefined") {
        return "";
    } else {
        return returnValue;
    }
}   

