﻿//获取产品搜索结果
function GetProductSearchResult($CurrentPage) {
    var $hits = $('#hits').val();
    var $price = $('#price').val();
    var $stylecss = $('#stylecss').val();
    var $keyword = $('#keywords').val();

    $.ajax({
        url: "/ajax.aspx?q=searchresult&currentpage=" + $CurrentPage + "&keyword=" + escape($keyword) + "&hits=" + $hits + "&price=" + $price + "&stylecss=" + $stylecss + "&time=" + new Date().toString(),
        type: 'GET',
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $('#status').hide();
            $('#divList').html("读取数据错误!");
        },
        success: function() {
            $('#status').hide();
            if (arguments[0].split("-----")[0] == "") {
                $('#divList').html("未检索到任何数据");
                $('#lblCounts').html("0");
            }
            else {
                $('#divList').html(arguments[0].split("-----")[0]);
                $('#lblCounts').html(arguments[0].split("-----")[1]);
            }
        }
    });
}

//获取产品类别搜索结果
function GetProductKindSearchResult($CurrentPage) {
    var $hits = $('#hits').val();
    var $price = $('#price').val();
    var $stylecss = $('#stylecss').val();
    var $kindid = $('#kindid').val();
    var $keyword = $('#keywords').val();

    $.ajax({
        url: "/ajax.aspx?q=searchkindresult&currentpage=" + $CurrentPage + "&kindid=" + $kindid + "&keyword=" + escape($keyword) + "&hits=" + $hits + "&price=" + $price + "&stylecss=" + $stylecss + "&time=" + new Date().toString(),
        type: 'GET',
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $('#status').hide();
            $('#divList').html("读取数据错误!");
        },
        success: function() {
            $('#status').hide();
            if (arguments[0].split("-----")[0] == "") {
                $('#divList').html("未检索到任何数据");
                $('#lblCounts').html("0");
            }
            else {
                $('#divList').html(arguments[0].split("-----")[0]);
                $('#lblCounts').html(arguments[0].split("-----")[1]);
            }
        }
    });
}

//读取换购的产品列表
function GetProducthuan($CurrentPage) {
    $.ajax({
        url: "/ajax.aspx?q=producthuan&currentpage=" + $CurrentPage + "&time=" + new Date().toString(),
        type: 'GET',
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $('#status').hide();
            $('#divList').html("读取数据错误!");
        },
        success: function() {
            $('#status').hide();
            if (arguments[0].split("-----")[0] == "") {
                $('#divList').html("当前没有可换购的商品");
                $('#lblCounts').html("0");
            }
            else {
                $('#divList').html(arguments[0].split("-----")[0]);
                $('#lblCounts').html(arguments[0].split("-----")[1]);
            }
        }
    });
}

//会员换购的列表1:已提交，但未批准，0：已批准
function GetMemberProducthuan($CurrentPage, $kind) {
    $.ajax({
        url: "/ajax.aspx?q=memberproducthuan&currentpage=" + $CurrentPage + "&kind=" + $kind + "&time=" + new Date().toString(),
        type: 'GET',
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
            $('#divList').html();
        },
        error: function() {
            $('#status').hide();
            $('#divList').html("读取数据错误!");
        },
        success: function() {
            $('#status').hide();
            if (arguments[0] == "") {
                $('#divList').html("没有数据");
            }
            else {
                $('#divList').html(arguments[0]);
            }
        }
    });
}


//评论之前弹出的登录
function checkLogin($s) {
    var $name = $("#txtUserName").val()
    var $password = $("#txtPassWord").val();
    if ($name == "") {
        $("#loginStatus").html("请输入登录用户名");
        $("#txtUserName").focus();
        return false;
    }

    if ($password == "") {
        $("#loginStatus").html("请输入登录用户名");
        $("#txtPassWord").focus();
        return false;
    }
    var $saveStatus = ($("#saveName").checked == true ? 1 : 0)
    $.ajax({
        url: "/ajaxLogin.aspx?saveType=" + $saveStatus + "&name=" + escape($name) + "&password=" + MD5($password) + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $("#loginStatus").html("正在登录中");
        },
        error: function() {
            $("#loginStatus").html("登录失败!");
        },
        success: function() {
            var $status = Number(arguments[0]);
            if ($status > 1) {
                $("#btnClose").click();
                if ($s == "a")
                    parent.$("#submitConsult").click();
                else
                    parent.$("#submitComment").click();
                //登录成功后，开始发表评论
            }
            else if ($status == 0) {
                $("#loginStatus").html("用户名不正确");
                $("#txtUserName").focus();
            }
            else if ($status == -1) {
                $("#loginStatus").html("密码不正确");
                $("#txtPassWord").focus();
            }
            else {
                $("#loginStatus").html("帐号已经被删除");
            }
        }
    });
}
//回复评论
function addComment($c_ID) {
    var $ParentID = $("#hdParent").val();
    //评论的父ID
    ParentID = c_ID;

    //跳转到评论的地方
    $("#txtComment").focus();

}


//获取评论列表
function GetCommentList($CurrentPage) {

    var $o_ID = $('#hdo_ID').val();
    var $kind = $('#hd_Kind').val();

    $.ajax({
        url: "/ajax.aspx?q=commonlist&currentpage=" + $CurrentPage + "&o_ID=" + $o_ID + "&kind=" + $kind + "&time=" + new Date().toString(),
        type: 'GET',
        timeout: 60000,
        beforeSend: function() {
            $('#status').html("正在加载评论列表");
            $('#status').show();
        },
        error: function(err) {
            alert(err.responseText);
            $('#status').hide();
            $('#divList').html("读取评论列表超时，请刷新页面重试!");
        },
        success: function() {
            $('#status').hide();
            if (arguments[0].split("-----")[0] == "") {
                $('#divList').html("还没有人评论，抢沙发哟");
                $('#lblCounts').html("0");
                $('#lblScore').html("0");
            }
            else {
                $('#divList').html(arguments[0].split("-----|-----")[0]);
                $('#lblCounts').html(arguments[0].split("-----|-----")[1]);
                $('#c_counts').html(arguments[0].split("-----|-----")[1]);
                $('#lblScore').html(arguments[0].split("-----|-----")[2]);
                
				if($CurrentPage>1)
				{
					//跳转到指定的锚点
					$("#jumplist").click();
				}
            }
        }
    });


}
//添加评论
function InsertComment($o_ID, $commentKind) {
    //    ymPrompt.alert({ message: '为响应国家号召，保证信息的安全性，暂停会员对商品的评论，感谢您参与！！', title: '系统提示', btn: [['确定', 'ok']], handler: setFocus });
    //    $("#txtConsult").focus();
    //    return false;

    //商品咨询
    if ($commentKind == 5) {
        var $ParentID = $("#hdParenta").val();
        var $Content = $("#txtConsult").val();
        var $code = $("#txtcodea").val();
        //        var $score=$('input[@name=score][@checked]').val();
        var $emot = $('input[@name=emota][@checked]').val();
        if ($Content == "") {
            ymPrompt.alert({ message: '请输入咨询内容！', title: '系统提示', btn: [['确定', 'ok']], handler: setFocus });
            $("#txtConsult").focus();
            return false;
        }
        if ($code == "") {
            ymPrompt.alert({ message: '请输入验证码！', title: '系统提示', btn: [['确定', 'ok']], handler: setFocus });
            $("#txtcodea").focus();
            return false;
        }
        $.ajax({
            url: "/ajax.aspx?q=insertcomment&code=" + $code + "&o_ID=" + $o_ID + "&CommentKind=" + $commentKind + "&parentID=" + $ParentID
		    + "&content=" + escape($Content) + "&score=1&emot=" + $emot + "&time=" + new Date().toString(),
            type: 'GET',
            timeout: 30000,
            beforeSend: function() {
                $('#statusa').show();
            },
            error: function() {
                $('#statusa').hide();
                ymPrompt.alert({ message: '发表咨询失败！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
            },
            success: function() {
                $('#statusa').hide();
                if (arguments[0] == "-1") {
                    ymPrompt.alert({ message: '验证码不正确，请重新输入！', title: '系统提示', btn: [['确定', 'ok']], handler: setFocus });
                    $("#txtcodea").focus();
                    $("#txtcodea").select;
                }
                else if (arguments[0] == "0") {
                    ymPrompt.win({ message: '/login4Comment.aspx?q=a', width: 300, height: 250, title: '系统登录', handler: null, maxBtn: false, minBtn: false, iframe: true })
                }
                else if (arguments[0] == "-3") {
                    ymPrompt.alert({ message: '1件商品每天最多只能发3条咨询！', title: '系统提示', btn: [['确定', 'ok']], handler: setFocus });
                }
                else {
                    GetConsultList(1); //发表评论成功之后重新load评论列表 
                }
            }
        });
    }
    else {
        var $ParentID = $("#hdParent").val();
        var $Content = $("#txtComment").val();
        var $code = $("#txtcode").val();
        var $score = $('input[@name=score][@checked]').val();
        var $emot = $('input[@name=emot][@checked]').val();
        if ($Content == "") {
            ymPrompt.alert({ message: '请输入评论内容！', title: '系统提示', btn: [['确定', 'ok']], handler: setFocus });
            $("#txtComment").focus();
            return false;
        }
        if ($code == "") {
            ymPrompt.alert({ message: '请输入验证码！', title: '系统提示', btn: [['确定', 'ok']], handler: setFocus });
            $("#txtcode").focus();
            return false;
        }
        $.ajax({
            url: "/ajax.aspx?q=insertcomment&code=" + $code + "&o_ID=" + $o_ID + "&CommentKind=" + $commentKind + "&parentID=" + $ParentID
		    + "&content=" + escape($Content) + "&score=" + $score + "&emot=" + $emot + "&time=" + new Date().toString(),
            type: 'GET',
            timeout: 30000,
            beforeSend: function() {
                $('#status').show();
            },
            //            error:function(){
            //                $('#status').hide();
            //                ymPrompt.alert({message:'发表评论失败！',title:'系统提示',btn:[['确定','ok']],handler:null});   
            //            },
            success: function() {
                $('#status').hide();
                if (arguments[0] == "-1") {
                    ymPrompt.alert({ message: '验证码不正确，请重新输入！', title: '系统提示', btn: [['确定', 'ok']], handler: setFocus });
                    $("#txtcode").focus();
                    $("#txtcode").select;
                }
                else if (arguments[0] == "0") {
                    ymPrompt.win({ message: '/login4Comment.aspx?q=b', width: 300, height: 250, title: '系统登录', handler: null, maxBtn: false, minBtn: false, iframe: true })
                }
                else if (arguments[0] == "-2") {
                    ymPrompt.alert({ message: '只有购买过此商品才允许发表评论！', title: '系统提示', btn: [['确定', 'ok']], handler: setFocus });
                }
                else if (arguments[0] == "-3") {
                    ymPrompt.alert({ message: '1件商品每天最多只能发3条评论！', title: '系统提示', btn: [['确定', 'ok']], handler: setFocus });
                }
                else {
                    ymPrompt.alert({ message: '发表评论成功!', title: '系统提示', btn: [['确定', 'ok']], handler: null });
                    GetCommentList(1); //发表评论成功之后重新load评论列表
                    $("#txtComment").val("");
                    $("#txtcode").val("");
                }
            }
        });
    }
}

//换购之前的登录界面
function checkhuanLogin() {
    var $name = $("#txtUserName").val()
    var $password = $("#txtPassWord").val();
    if ($name == "") {
        $("#loginStatus").html("请输入登录用户名！");
        $("#txtUserName").focus();
        return false;
    }

    if ($password == "") {
        $("#loginStatus").html("请输入登录密码！");
        $("#txtPassWord").focus();
        return false;
    }
    var $saveStatus = ($("#saveName").checked == true ? 1 : 0)
    $.ajax({
        url: "/ajaxLogin.aspx?saveType=" + $saveStatus + "&name=" + escape($name) + "&password=" + MD5($password) + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $("#loginStatus").html("<img src=\"/images/member/mem_loading2.gif\" />正在登录中...");
        },
        error: function() {
            $("#loginStatus").html("登录失败！");
        },
        success: function() {
            var $status = Number(arguments[0]);
            if ($status > 1) {
                $("#btnClose").click();
                //登录成功后，继续提交换购申请
                checksubmitTry($("#p_ID"), $("#p_Price"));
            }
            else if ($status == 0) {
                $("#loginStatus").html("用户名不正确！");
                $("#txtUserName").focus();
            }
            else if ($status == -1) {
                $("#loginStatus").html("密码不正确！");
                $("#txtPassWord").focus();
            }
            else {
                $("#loginStatus").html("帐号已经被删除！");
            }
        }
    });
}
//提交换购之前的检测
function checksubmitTry($p_ID, $p_Price) {
    $.ajax({
        url: "/ajax.aspx?q=checkTry&p_ID=" + $p_ID + "&p_Price=" + $p_Price + "&time=" + new Date().toString(),
        type: "GET",
        timeout: 30000,
        beforeSend: function() {
            $('#status').html("操作进行中...");
            $('#status').show();
        },
        error: function() {
            $('#status').hide();
            ymPrompt.alert({ message: '申请换购失败！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
        },
        success: function() {
            $("#status").hide();
            if (arguments[0].split("--")[0] == 0)
                ymPrompt.win({ message: '/login4Huango.aspx?pid=' + $p_ID + '&price=' + $p_Price, width: 300, height: 250, title: '系统登录', handler: null, maxBtn: false, minBtn: false, iframe: true })
            else if (arguments[0].split("--")[0] == -1)
                ymPrompt.alert({ message: '您当前M金只有' + arguments[0].split("--")[1] + ',请选择其它商品换购！', title: '系统提示', btn: [['确定', 'ok']], handler: null });
            else
                ymPrompt.win({ message: '/Huango/ApplyTry_' + $p_ID + '.shtml', width: 700, height: 430, title: '我选择换购的商品', handler: null, maxBtn: null, minBtn: null, iframe: true });
            //window.location=("/Huango/ApplyTry_"+$p_ID+".shtml");

        }
    });
}
//提交M金换购订单
function SubmitTry() {
    var $hpid = $("#ph_ID").val();
    var $name = $("#txtName").val();
    var $mobile = $("#txtPhone").val();
    var $tel = $("#txtTel").val();
    var $zip = $("#txtZip").val();
    var $email = $("#txtEmail").val();
    var $address = $("#txtAddress").val();
    var $price = $("#hp_Price").val();
    $.ajax({
        url: "/ajax.aspx?q=submittry&hpid=" + $hpid + "&name=" + escape($name) + "&mobile=" + $mobile + "&tel=" + $tel + "&zip=" + $zip
		+ "&email=" + $email + "&address=" + escape($address) + "&price=" + $price + "&time=" + new Date().toString(),
        type: 'GET',
        timeout: 30000,
        beforeSend: function() {
            $('#status').show();
        },
        error: function() {
            $('#status').hide();
            alert("提交换购订单失败！");
            parent.ymPrompt.close();
            //parent.ymPrompt.alert({message:'提交换购订单失败！',title:'系统提示',btn:[['确定','ok']],handler:null});   
        },
        success: function() {
            $('#status').hide();
            if (arguments[0] == "1") {
                alert('提交换购订单成功！');
                parent.ymPrompt.close();
                //	            parent.ymPrompt.alert({message:'提交订单成功！',title:'系统提示',btn:[['确定','ok']],handler:go2Url}); 
            }
            else {
                alert("提交换购订单失败！");
                parent.ymPrompt.close();
                // parent.ymPrompt.alert({message:'提交换购订单失败！',title:'系统提示',btn:[['确定','ok']],handler:null}); 
            }
        }
    });
}

function go2Url() {
    window.location = ("/huango"); //订单提交成功后
}
function setFocus() {
    var $Content = $("#txtComment").val();

    if (trimStr($Content) == "")
        $("#txtComment").focus();
    else {
        $("#txtcode").focus();
        $("#txtcode").select();
    }
}

//显示M金兑换的div
function showExchange($flag) {
    var $obj = $("#exchange");
    var $obj2 = $("#content");
    if ($flag == 1) {
        $obj.show();
        $obj2.show();
    }
    else {
        $obj.hide();
        $obj2.hide();
    }
}

//兑换M金
function configExchange($tscore, $flag) {
    var $score = $("#txtScore");
    var $status = $("#cstatus");
    $("#status").hide();
    if ($score.val() == "" || $score.val() == 0) {
        $status.html("请输入要兑换的学分");
        $status.show();
        $score.focus();
        return false;
    }
    else if ($score.val() > $tscore) {
        $status.html("您输入的学分大于您现有学分!");
        $status.show();
        $score.focus();
    }
    else if (Number($score.val()) < 100) {
        $status.html("请输入大于100的数");
        $status.show();
        $score.focus();
        return false;
    }
    else if (Number($score.val()) % 100 != 0) {
        $status.html("请输入100的整数倍数");
        $status.show();
        $score.focus();
        return false;
    }
    else {
        $("#status").hide();
        if ($flag == 1) {
            $.ajax({
                url: "/ajax.aspx?q=exchange&score=" + $score.val() + "&tscore=" + $tscore + "&time=" + new Date().toString(),
                type: "GET",
                timeout: 30000,
                beforeSend: function() {
                    $('#status').show();
                    $('#status').html("正在提交兑换申请...");
                },
                error: function() {
                    $("#status").show();
                    $("#status").html("提交兑换申请失败！");
                },
                success: function() {
                    if (arguments[0] == 0) {
                        $("#status").html("");
                        alert("您好，您的兑换申请提交成功，管理员审核通过后，您的M金将加到您的个人账户中。");
                        $("#content").hide();
                        $("#exchange").hide();
                    }
                    else {
                        $("#status").show();
                        $("#status").html("提交兑换申请失败!");
                    }

                }
            });
        }
    }
}


//发布试用报告
function SaveReport($trID) {
    var $classid = $('#selectProduct').val();
    var $Title = $('#txtTitle').val();
    var $Content = myEditor.getHTML();
    var $second = 0; //默认不进行二次申请，如果选中,则为申请二次申领

    if ($("#second").attr("checked") == true)
        $second = 1;

    if ($classid == 0) {
        alert('请选择试用的产品！');
        $('#selectProduct').focus();
        return false;
    }

    if ($.trim($Title) == '') {
        alert('请填写试用报告的标题！');
        $('#txtTitle').focus();
        return false;
    }

    if ($.trim($Content) == '') {
        alert('请填写试用报告的内容！');
        return false;
    }
    if ($Content.length < 5) {
        alert('请认真填写试用报告内容！');
        return false;
    }

    //将报告内容赋给隐藏控件
    $("#hdcontent").attr("value", $Content);

    //执行后台保存操作
    $("#btnSave").click();
}


//发布试用报告
function SaveProductReport() {
    var $Title = $('#txtTitle').val();
    var $Content = myEditor.getHTML();

    if ($.trim($Title) == '') {
        alert('请填写试用报告的标题！');
        $('#txtTitle').focus();
        return false;
    }

    if ($.trim($Content) == '') {
        alert('请填写试用报告的内容！');
        return false;
    }
    if ($Content.length < 5) {
        alert('请认真填写试用报告内容！');
        return false;
    }
    if ($.trim($Content).length < 60) {
        if (!confirm('您的试用报告不足60字，确认提交?'));
        return false;
    }

    //将报告内容赋给隐藏控件
    $("#hdcontent").attr("value", $Content);

    //执行后台保存操作
    $("#btnSave").click();
}


