﻿
/*********注册首页阅读条款**********/
function check() {
    var ck = document.getElementById('checkbox');
    if (ck.checked == true) {
        alert('true');
    } else {
        alert('请先阅读协议条款');
    }
}
/**********用户登陆验证*************************************************/
function ULogin() {
    if ($("#ContentPlaceHolder1_strUserName").val() == "" || $("#ContentPlaceHolder1_strUserName").val() == null) {
        $("#html").html("请输入用户名");
        return false;
    }
    if ($("#ContentPlaceHolder1_strUserPass").val() == "" || $("#ContentPlaceHolder1_strUserPass").val() == null) {
        $("#html").html("请输入密码");
        return false;
    }
    if (!ValidatePhone($("#ContentPlaceHolder1_strUserName").val()) && !ValidateEmail($("#ContentPlaceHolder1_strUserName").val())) {
        $("#html").html("账号格式错误");
        return false;
    }
    else {
        $("#ContentPlaceHolder1_Button1").click();
        return true;
    }
}
function ClearULogin() {
    if ($("#ContentPlaceHolder1_strUserName").val() != "" || $("#ContentPlaceHolder1_strUserName").val() != null) {
        $("#html").html("");
        return true;
    }
    if ($("#ContentPlaceHolder1_strUserPass").val() != "" || $("#ContentPlaceHolder1_strUserPass").val() != null) {
        $("#html").html("");
        return true;
    }
    if (ValidatePhone($("#ContentPlaceHolder1_strUserName").val()) && ValidateEmail($("#ContentPlaceHolder1_strUserName").val())) {
        $("#html").html("");
        return true;
    }
}
/*********修改密码验证为空和密码两次输入是否一样(登陆密码，取票密码)**********/
function NullPwd() {
    if ($("#ContentPlaceHolder1_txtCurrentPwd").val() == "" || $("#ContentPlaceHolder1_txtCurrentPwd").val() == null) {
        $("#html").html("请输入当前密码");
        //alert('密码不能为空！');
        return false;
    }

    if ($.trim($("#ContentPlaceHolder1_txtNewPwd").val()) == "" || $.trim($("#ContentPlaceHolder1_txtNewPwd").val()) == null) {
        $("#html").html("请输入新密码");
        return false;
    }
     
    if ($("#ContentPlaceHolder1_txtNewPwd").val().indexOf(" ") > -1 || $("#ContentPlaceHolder1_txtNewPwd").val().indexOf("　") > -1) {
        $("#html").html("您的密码中含有空格请重新输入");
        return false;
    }
    if ($.trim($("#ContentPlaceHolder1_txtNewPwd").val()).length < 6) {
        $("#html").html("对不起，密码只能为6-12位字符");
        return false;
    }
    if ($.trim($("#ContentPlaceHolder1_txtNewPwd").val()).length>12) {
        $("#html").html("对不起，密码只能为6-12位字符");
        return false;
    }
    if ($("#ContentPlaceHolder1_txtNewPwd").val() != $("#ContentPlaceHolder1_txtConfirmPwd").val()) {
        $("#html").html("您输入的两次新密码不一致请重新输入");
        return false;
    }
    return true;
}

function ClearPwd() {
    if ($("#ContentPlaceHolder1_txtCurrentPwd").val() != "" || $("#ContentPlaceHolder1_txtCurrentPwd").val() != null) {
        $("#html").html("");
        return true;
    }
    if ($("#ContentPlaceHolder1_txtNewPwd").val() != "" || $("#ContentPlaceHolder1_txtNewPwd").val() != null) {
        $("#html").html("");
        return true;
    }
    if ($("#ContentPlaceHolder1_txtConfirmPwd").val() != "" || $("#ContentPlaceHolder1_txtConfirmPwd").val() != null) {
        $("#html").html("");
        return true;
    }
    return false;
}


/*************设置取票密码***********/
function NullPwdqpmm() {
    if ($("#ContentPlaceHolder1_txtCurrentPwd").val() == "" || $("#ContentPlaceHolder1_txtCurrentPwd").val() == null) {
        $("#html").html("请输入原取票密码");
        //alert('密码不能为空！');
        return false;
    }
    if (!IsZIPqpmm(document.getElementById('ContentPlaceHolder1_txtCurrentPwd'))) {
        $("#html").html("对不起，原密码只能为6位数字!");
        return false;
    }
    if ($("#ContentPlaceHolder1_txtNewPwd").val() == "" || $("#ContentPlaceHolder1_txtNewPwd").val() == null) {
        $("#html").html("请输入新的取票密码");
        return false;
    }
    if (!IsZIPqpmm(document.getElementById('ContentPlaceHolder1_txtNewPwd'))) {
        $("#html").html("对不起，密码只能为6位数字!");
        return false;
    }
    if ($("#ContentPlaceHolder1_txtConfirmPwd").val() == "" || $("#ContentPlaceHolder1_txtConfirmPwd").val() == null) {
        $("#html").html("请输入重复密码");
        return false;
    }
    if ($("#ContentPlaceHolder1_txtNewPwd").val() != $("#ContentPlaceHolder1_txtConfirmPwd").val()) {
        $("#html").html("您输入的两次新密码不一致请重新输入");
        return false;
    }
    return true;
}

/*********注册页面关闭层********ReturnString()**/
function ShowHide() {
    document.getElementById('tanchukuang').style.display = "none";   //隐藏
}
function Location() {
    window.navigate("UserLogin.aspx");
}
/*********取票密码设置页面验证新密码是否为6位数字********ReturnString()**/
function IsZIPqpmm(obj) {
    var str = obj.value;
    if (str.length != 0) {
        reg = /^\d{6}$/;
        if (!reg.test(str)) {
            //alert('对不起，密码只能为6位数字!');
            return false;
        } else {
            return true;
        }
    } else {
        //alert('请输入新密码！');
        return false;
    }
}
var SendPhoneID;
var SendPhone;
var time = 61;
function s() {
    if (time <= 0) {
        clearInterval(SendPhone);
        time = 61;
        $("#SendPhone").text("发送验证码至手机").click(function () { SendPhoneCode('ContentPlaceHolder1_phone', 1) });
      
        return;
    }
    time--;
    $("#SendPhone").text("距离下次验证还有" + time + "秒");
}
//发送验证码
function SendPhoneCode(id, bindtype) {
    var mobile = $.trim($("#" + id).val());
    if (mobile.length == 0) {
        $("#html").html("请输入手机号码");
        return false;
    }
    if (ValidatePhone(mobile) == false) {
        $("#html").html("请输入正确的手机号码");
        return false;
    }
    SendPhoneID = id;
    $("#SendPhone").attr("onclick", "");
    $("#SendPhone").unbind();
    SendPhone = setInterval(s, 1000);
    $.get("AjaxServer/BindCancelPhone.aspx", { type: 0, phone: mobile, sendtype: bindtype, code: Math.random() },
                function (result) {
                    alert(result);
                    return false;
                });
}
//清空绑定页面的文本框内容
function ClerarBindCode() {
    if ($("#ContentPlaceHolder1_phone").val() != "" || $.trim($("#ContentPlaceHolder1_code").val()) != "") {
        $("#html").html("");
        return false;
    }
}
//绑定手机
function BindPhoneCode() {
    var mobile = $.trim($("#ContentPlaceHolder1_phone").val());

    if (mobile.length == 0) {
        $("#html").html("请输入手机号码");
        return false;
    }

    if (ValidatePhone(mobile) == false) {
        $("#html").html("请输入正确的手机号码");
        return false;
    }

    var sendCode = $.trim($("#ContentPlaceHolder1_code").val());

    if (ValidateNum(sendCode) == false) {
        $("#html").html("请输入4位数字验证码");
        return false;
    }
    if (sendCode.length <= 0) {
        $("#html").html("请输入4位数字验证码");
        return false;
    }
    if (sendCode.length != 4) {
        $("#html").html("请输入4位数字验证码");
        return false;
    }
    return true;
}
/**************************注册页面验证*****************************************/
function NullPwdRegis() {
    var txtPhone = $("#ContentPlaceHolder1_txtPhone").val();
    if ($("#ContentPlaceHolder1_txtPhone").val() == "" || $("#ContentPlaceHolder1_txtPhone").val() == null) {
        $("#htmlR").html("<b>手机号码不能为空</b>");
        return false;
    }
    if (!ValidatePhone(txtPhone)) {
        $("#htmlR").html("您输入的手机号码格式不正确");
        return false;
    }
    if (!NullnewPwd()) {
        $("#htmlR").html("请输入密码");
        return false;
    }
    if (!pwdAgain()) {
        $("#htmlR").html("两次密码输入不一致");
        return false;
    }
    if (!IsZIP()) {
        $("#htmlR").html("对不起，密码由6—12位的字母和数字组成");
        return false;
    }
    if (!$("#ContentPlaceHolder1_checkbox").attr("checked")) {
        $("#htmlR").html("请先阅读协议");
        return false;
    }
    else {
        $("#ContentPlaceHolder1_ImageButton1").click();
        return true;
    }
}

function ClearRegis() {
    if ($("#ContentPlaceHolder1_txtPhone").val() != "" && $("#ContentPlaceHolder1_txtPhone").val() != null) {
        $("#htmlR").html("");
        return true;
    }
    if (NullnewPwd()) {
        $("#htmlR").html("");
        return true;
    }
    if (pwdAgain()) {
        $("#htmlR").html("");
        return true;
    }
}

function ValidatePhone(txt) {
    var regPhone = /^0{0,1}(13[0-9]|15[0|1|7|8|9]|152|153|156|18[6-9])[0-9]{8}$/;
    return regPhone.test(txt);
}

function ValidateEmail(txt) {
    var regMail = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    return regMail.test(txt);
}

function NullnewPwd() {
    if (document.getElementById('ContentPlaceHolder1_txtPwd').value == "" || document.getElementById('ContentPlaceHolder1_txtPwd').value == null) {
        return false;
    }
    return true;
}

function IsZIP() {
    var str = document.getElementById('ContentPlaceHolder1_txtPwd').value;
    if (str.length != 0) {
        reg = /^[A-Za-z0-9]{6,12}$/;
        if (!reg.test(str)) {
            return false;
        } else {
            return true;
        }
    } else {
        //alert('请输入新密码！');
        return false;
    }
}
function IsZIPsix() {
    var str = document.getElementById('ContentPlaceHolder1_txtNewPwd').value;
    if (str.length != 0) {
        reg = /^\d{6,12}$/;
        if (!reg.test(str)) {
            return false;
        } else {
            return true;
        }
    } else {
        //alert('请输入新密码！');
        return false;
    }
}


function pwdAgain() {
    if (document.getElementById('ContentPlaceHolder1_txtPwd').value != document.getElementById('ContentPlaceHolder1_txtPwdAgain').value) {
        return false;
    }
    return true;
}

//我的现金券－显示
$().ready(function () {
    $("#my_gold_tab1 table a").click(function () {
        $("#divCouponList").dialog({
            autoOpen: false,
            modal: true,
            height: '489',
            width: '506',
            draggable: false,
            resizeable: false
        });
        $("#divCouponList").removeClass('ui-dialog-content ui-widget-content');
        $("#divCouponList").parent().removeAttr("class");
        $("#divCouponList").parent().children().each(function () {
            if (this.id != "divCouponList") {
                this.style.display = "none";
            }
        });
        $("#divCouponList").dialog("open");
        $("#divCouponList").parent().css("height", "489px");
        $("#divCouponList").parent().css("left", "30%");
        $("#divCouponList").parent().css("width", "506px");
        $("#divCouponList").css("width", "506px");
        $("#divCouponList").css("height", "489px");
        $("#divCouponList").attr("rel", $(this).attr("rel"));
        $("#divCouponListDetail").empty();
        $("#divCouponListDetail").html("<div class='flf' style='padding-top:2em;'><font color='#fff'>正在加载数据……</font></div>");
        $.ajax({
            type: "GET",
            contentType: "application/html",
            url: '../Utils/GetCouponDetails.aspx?pPackID=' + $(this).attr("rel") + '&pStart=0&pEnd=3',
            data: "",
            cache: false,
            dataType: "html",
            success: function (result) {
                if (result == "timeout") { alert("登录超时，请重新登录"); location.replace("UserLogin.aspx?ReturnUrl=UserAccount/UserGold.aspx"); }
                var strAry = result.split('|');
                $("#lbCurrentPage").html("1");
                $("#lbPageCount").html(parseInt(parseInt(strAry[0]) / parseInt($("#iPageSize").val())) + 1);
                $("#divCouponListDetail").empty();
                $("#divCouponListDetail").html(strAry[1]);
            },
            error: function (result) {
                if (status == 'error') { alert(status); }
            }
        });
    });

    //我的现金券-关闭
    $("#imgbtnCouponListClose").click(function () {
        $("#divCouponList").dialog("close");
    });
    //我的现金券-上一页
    $("#iCouponListLast").click(function () {
        if ($("#lbCurrentPage").text() == "1") {
            //alert("aaa");
            return;
        }
        var start = (parseInt($("#lbCurrentPage").html()) - 2) * parseInt($("#iPageSize").val());
        var end = (parseInt($("#lbCurrentPage").html()) - 2) * parseInt($("#iPageSize").val()) + parseInt($("#iPageSize").val()) - 1;
        $("#divCouponListDetail").empty();
        $("#divCouponListDetail").html("<div class='flf' style='padding-top:2em;'><font color='#fff'>正在加载数据……</font></div>");
        $.ajax({
            type: "GET",
            contentType: "application/html",
            url: '../Utils/GetCouponDetails.aspx?pPackID=' + $("#divCouponList").attr("rel") + '&pStart=' + start.toString() + '&pEnd=' + end.toString(),
            data: "",
            cache: false,
            dataType: "html",
            success: function (result) {
                if (result == "timeout") { alert("登录超时，请重新登录"); location.replace("UserLogin.aspx?ReturnUrl=UserAccount/UserGold.aspx"); }
                var strAry = result.split('|');
                $("#lbCurrentPage").html(parseInt($("#lbCurrentPage").text()) - 1);
                $("#lbPageCount").html(parseInt(parseInt(strAry[0]) / parseInt($("#iPageSize").val())) + 1);
                $("#divCouponListDetail").empty();
                $("#divCouponListDetail").html(strAry[1]);
            },
            error: function (result) {
                if (status == 'error') { alert(status); }
            }
        })
    });
    //我的现金券-下一页
    $("#iCouponListNext").click(function () {
        if ($("#lbCurrentPage").text() == $("#lbPageCount").text()) {
            //alert("aaa");
            return;
        }
        var start = parseInt($("#lbCurrentPage").html()) * parseInt($("#iPageSize").val());
        var end = parseInt($("#lbCurrentPage").html()) * parseInt($("#iPageSize").val()) + parseInt($("#iPageSize").val()) - 1;
        $("#divCouponListDetail").empty();
        $("#divCouponListDetail").html("<div class='flf' style='padding-top:2em;'><font color='#fff'>正在加载数据……</font></div>");
        $.ajax({
            type: "GET",
            contentType: "application/html",
            url: '../Utils/GetCouponDetails.aspx?pPackID=' + $("#divCouponList").attr("rel") + '&pStart=' + start.toString() + '&pEnd=' + end.toString(),
            data: "",
            cache: false,
            dataType: "html",
            success: function (result) {
                if (result == "timeout") { alert("登录超时，请重新登录"); location.replace("UserLogin.aspx?ReturnUrl=UserAccount/UserGold.aspx"); }
                var strAry = result.split('|');
                $("#lbCurrentPage").html(parseInt($("#lbCurrentPage").text()) + 1);
                $("#lbPageCount").html(parseInt(parseInt(strAry[0]) / parseInt($("#iPageSize").val())) + 1);
                $("#divCouponListDetail").empty();
                $("#divCouponListDetail").html(strAry[1]);
            },
            error: function (result) {
                if (status == 'error') { alert(status); }
            }
        })
    });
});
