﻿/*
所在频道：买车
文件功能：车源详细页所有提交表单方法:
1.个人留言提交及展示。
2.商家留言提交。
3.保存至手机。
4.虚假信息举报。
5.客户端验证验证码是否正确。
作    者：Eagle，shihb
时    间：2010-06-13 ，2011-08-01
依赖 protyep.js
*/
/*thisObj：回复留言按钮 ，
openAId 回复框Id
keyid：回复问题隐藏变量Id
values：回复问题的Id
*/
function ReplyDisplay(thisObj, openAId, keyid, values) {
    opendiv(thisObj, openAId, -655, 20);
    $(keyid).value = values;
    refresh('img1');
}

function opendiv(thisObj, openAId, numx, numy) {
    var x = thisObj.offsetLeft;
    var y = thisObj.offsetTop;
    var newx = x + numx;
    var newy = y + numy;
    $(openAId).style.display = "block";
    $(openAId).style.top = newy + "px";
    $(openAId).style.left = newx + "px";
}
function saet(o) {
    var x = y = 0;
    do {
        x += o.offsetLeft;
        y += o.offsetTop;
    }
    while (o = o.offsetParent);
    return { "x": x, "y": y };
}
//刷新验证码
function refresh(id) {
    $(id).src += "0";
}
function AnonyChangeLeave() {
    var txtUserName = $('txtuserName');
    var txtPwd = $('txtpwd');
    var chkAnonymity = $('chkanonymity');
    txtPwd.disabled = txtUserName.disabled = chkAnonymity.checked;
}
var RegExpr = {
    CarPrice: /^(([1-9]{1}[0-9]{0,2})|([1-9]{1}[0-9]{0,2}\.[0-9]{1,2})|([0]{1}\.[0-9]{1,2}))$/, //车辆价格
    TelOrMobile: /^(0\d{2,3})?-?(\d{7,8})(-\d{3,6})?$|^13[0-9]{9}$|^15[0-9]{9}$|^18[0-9]{9}$/, //手机号或座机号
    Moblile: /^13[0-9]{9}$||^15[0-9]{9}$|^18[0-9]{9}$/
}
function len(string) {
    return string.replace(/[^\x00-\xff]/g, "**").length;
}

function AnonyChangeLeaveReplay() {
    var txtUserName = $('txtuserNameReplay');
    var txtPwd = $('txtpwdReplay');
    var chkAnonymity = $('chkanonymityReplay');
    txtPwd.disabled = txtUserName.disabled = chkAnonymity.checked;
}

var txtSMobile = new Ucar_Validate("txtSMobile", "");
function validateMobile(focus) {
    if (txtSMobile.CheckEmptyforAlert("请填写联系电话")) {
        if (txtSMobile.CheckFormatforAlert(RegExpr.TelOrMobile, "联系电话格式不正确")) {
            return true;
        }
    }
    if (focus) {
        txtSMobile.SetFocus();
    }
    return false;
}
//保存至手机方法
function ValidateSavePhone() {
    var alertMessage = "";
    var count = 0;
    var CheckCode = $F('txtCheckCode2');
    var txtCheckCode = $('txtCheckCode2');
    var telphone = $F('telphone');
    var txttelphone = $('telphone');
    if (CheckCode.strip() == "") {
        alertMessage = "请输入验证码！";
        txtCheckCode.focus();
        count++;
    }
    if (telphone.strip() == "") {
        count++;
        alertMessage = "请输入手机号码！";
        txttelphone.focus();
    }
    else if (!RegExpr.Moblile.test(telphone)) {
        count++;
        alertMessage = "手机号码格式错误！";
        txttelphone.focus();
    }
    if (txtCheckCode == null) {
        count++;
    }
    if (count > 0) {
        alert(alertMessage);
        return false;
    }
    if (!UcarValidateCode('txtCheckCode2')) {
        $('seedfail').innerHTML = "验证码错误！";
        $('seedfail').style.display = "block";
    }
    else {
        $('butSavePhone').disabled = true;
        $('butSavePhone').value = "请稍候…";
        var UcarSerialNumber = $F("hdUcarSerialNumber");
        var Content = $F("hidSendContent");
        var url = "/ajax/buycar/ajaxsavetel.ashx";
        var messparam = "tel=" + telphone + "&ucarserialnumber=" + UcarSerialNumber + "&content=" + Content + "&codes=" + CheckCode;
        new Ajax.Request(url, { method: "post", parameters: encodeURI(messparam),
            onSuccess: SaveTelSuccess
            // evalScripts: true,
            // asynchronous: true
        }
);
        return true;
    }
}
function SaveTelSuccess(response) {
    var result = response.responseText;
    if (result == "1") {
        alert("发送成功，请注意查收！");
        $('telphone').value = "";
        $('butSavePhone').disabled = false;
        $('butSavePhone').value = "发 送";
        $('seedfail').innerHTML = "";
        $('seedfail').style.display = 'none';
        refresh('carDetail1_imgCheckCode');
        backgroundC.close('saveTel', 'layerBg');
    }
    else {
        $('seedfail').innerHTML = result;
        $('seedfail').style.display = 'block';
    }
}
// 保存至手机 end
//虚假举报 start
function CheckVoteSuccess(response) {
    var result = response.responseText;
    if (result == '1') {
        alert("举报信息成功！");
        $('txtVote').value = "";
        $('imgCheck').disabled = false;
        $('imgCheck').value = "发 送";
        backgroundC.close('fuceng1', 'layerBg');
    }
    else {
        alert(result);
    }
}
function CheckVoteMessage() {
    var ContentText = $F('txtVote');
    if (ContentText.strip() == "输入虚假信息" || ContentText.strip() == "") {
        alert("- 请输入举报内容！");
        return false;
    }
    else {
        $('imgCheck').disabled = true;
        $('imgCheck').value = "请稍候…";
        var UcarId = $F("hdUcarIdUser");
        var UcarSerialNumber = $F("hdUcarSerialNumber");
        var url = "/ajax/buycar/ajaxwhistleblowing.ashx";
        var messparam = "ucarid=" + UcarId + "&ucarserialnumber=" + UcarSerialNumber + "&content=" + ContentText;
        new Ajax.Request(url, { method: "post", parameters: encodeURI(messparam),
            onSuccess: CheckVoteSuccess
            //            evalScripts: true,
            //            asynchronous: true
        }
);
        return true;
    }
}
//虚假举报end
//验证码是否正确
function UcarValidateCode(obj) {
    var revalue = true;
    var url = "/ajax/ValidateCode.ashx?codes=" + $F(obj);
    new Ajax.Request(url, { method: "get",
        onSuccess: function (response) {
            var result = response.responseText;
            if (result == "false") {
                revalue = false;
            }
        },
        asynchronous: false
    });
    return revalue;
}

//个人车源留言方法 start
//显示用户留言
function ShowMessage(ucarid, pageindex) {
    //验证页面是否登陆
    IdentityName();
    $('messagediv').innerHTML = "";
    var url = "/ajax/buycar/ajaxmessage.ashx?ucartype=1&ucarid=" + ucarid + "&pageindex=" + pageindex;
    new Ajax.Updater({ success: 'messagediv', onFailure: 'messagediv' },
url, { method: "get", evalScripts: true, insertion: Insertion.Top }
);
}
function IdentityName() {
    var url = "/ajax/buycar/ajaxmessage.ashx?Identity=0";
    new Ajax.Request(url, { method: "get",
        onSuccess: function (response) {
            var result = response.responseText;
            if (result !== "5") {
                $('TruserLogReplay').style.display = "none";
                $('TruserLog').style.display = "none";
                $('txtuserName').value = result;
                $('txtuserNameReplay').value = result;
                $('txtpwd').value = "pwd";
                $('txtpwdReplay').value = "pwd";
            }
        }
    });
}
//提交留言方法
function ValidateMessageLeave() {
    var alertMessage = "";
    var count = 0;
    var txtContent = $('txtcontent');
    var ContentText = escape($F('txtcontent'));
    var txtUserName = $('txtuserName');
    var UserName;
    var pwd;
    if (txtUserName != null) {
        UserName = escape($F('txtuserName'));
    }
    var txtPwd = $('txtpwd');
    if (txtPwd != null) {
        pwd = escape($F('txtpwd'));
    }
    var txtPrice = $('txtprice');
    var Price = escape($F('txtprice'));
    var txtCheckCode = $('txtCheckCode');
    var CheckCode = $F('txtCheckCode');
    var chkAnonymity = $('chkanonymity');
    if (CheckCode.strip() == "") {
        alertMessage += "@ 请输入验证码！";
        txtCheckCode.focus();
        count++;
    }
    else if (!UcarValidateCode('txtCheckCode')) {
        alertMessage += "@ 验证码输入错误！";
        count++;
    }
    if (Price.strip() != "") {
        if (!RegExpr.CarPrice.test(Price)) {
            alertMessage += "@ 报价格式为999.99 ";
            txtPrice.focus();
            count++;
        }
        else if (parseFloat(Price) <= 0) {
            alertMessage += "@ 报价应大于0 ";
            txtPrice.focus();
            count++;
        }
    }
    if (ContentText.strip() == "") {
        alertMessage += "@ 留言不能为空！";
        txtContent.focus();
        count++;
    }
    else if (len(txtContent.value) > 100) {
        alertMessage += "@ 留言最多为50个汉字！";
        txtContent.focus();
        count++;
    }
    if (chkAnonymity != null) {
        if (chkAnonymity.checked == false) {
            if (UserName.strip() == "") {
                alertMessage += "@  请输入用户名和密码或选择匿名留言！";
                txtUserName.focus();
                count++;
            }
            else if (pwd.strip() == "") {
                alertMessage += "@ 请输入用户名和密码或选择匿名留言！";
                txtPwd.focus();
                count++;
            }
        }
    }
    if (count > 0) {
        var i = alertMessage.indexOf("@");
        alertMessage = alertMessage.substring(i + 1);
        alertMessage = alertMessage.replace(/@/g, "\n\n");
        alert(alertMessage);
        return false;
    }
    else {
        $('btnMess').value = "请稍候……";
        $('btnMess').disabled = true;
        var chkanonymity = false;
        if (chkAnonymity != null) {
            if (chkAnonymity.checked) {
                chkanonymity = true;
            }
        }
        //ajax提交留言并返回留言列表
        SumbitShowMessage(UserName, ContentText, Price, pwd, chkanonymity, 1, CheckCode);
        return true;
    }
}
//留言回复事件
function ValidateMessageLeaveReplay() {
    var alertMessage = "";
    var count = 0;
    var txtContent = $('txtcontentRepaly');
    var ContentText = escape($F('txtcontentRepaly'));
    var txtUserName = $('txtuserNameReplay');
    var UserName;
    var pwd;
    if (txtUserName != null) {
        UserName = escape($F('txtuserNameReplay'));
    }
    var txtPwd = $('txtpwdReplay');
    if (txtPwd != null) {
        pwd = escape($F('txtpwdReplay'));
    }
    var txtPrice = $('txtpriceReplay');
    var Price = escape($F('txtpriceReplay'));
    var txtCheckCode = $('txtCheckCodeReplay');
    var CheckCode = $F('txtCheckCodeReplay');
    var chkAnonymity = $('chkanonymityReplay');
    if (CheckCode.strip() == "") {
        alertMessage += "@ 请输入验证码！";
        txtCheckCode.focus();
        count++;
    }
    else if (!UcarValidateCode('txtCheckCodeReplay')) {
        alertMessage += "@ 验证码输入错误！";
        count++;
    }
    if (Price.strip() != "") {
        if (!RegExpr.CarPrice.test(Price)) {
            alertMessage += "@ 报价格式为999.99 ";
            txtPrice.focus();
            count++;
        }
    }
    if (ContentText.strip() == "") {
        alertMessage += "@ 留言不能为空！";
        txtContent.focus();
        count++;
    }
    else if (len(txtContent.value) > 100) {
        alertMessage += "@ 留言最多为50个汉字！";
        txtContent.focus();
        count++;
    }
    if (chkAnonymity != null) {
        if (chkAnonymity.checked == false) {
            if (UserName.strip() == "") {
                alertMessage += "@ 请输入用户名和密码或选择匿名留言！";
                txtUserName.focus();
                count++;
            }
            else if (pwd.strip() == "") {
                alertMessage += "@ 请输入用户名和密码或选择匿名留言！";
                txtPwd.focus();
                count++;
            }
        }
    }

    if (count > 0) {
        var i = alertMessage.indexOf("@");
        alertMessage = alertMessage.substring(i + 1);
        alertMessage = alertMessage.replace(/@/g, "\n\n");
        alert(alertMessage);
        return false;
    }
    else {
        $('btnReplay').value = "请稍候……";
        $('btnReplay').disabled = true;
        var chkanonymity = false;
        if (chkAnonymity != null) {
            if (chkAnonymity.checked) {
                chkanonymity = true;
            }
        }
        //ajax提交留言并返回留言列表
        SumbitShowMessage(UserName, ContentText, Price, pwd, chkanonymity, 2, CheckCode);
        return true;
    }
}
//个人留言提交成功后处理事件
function InitBlockSuccess(response) {
    var result = response.responseText;
    if (result == "1") {
        alert("验证码错误！");
    }
    else if (result == "2") {
        alert("提交失败！");
    }
    else {
        alert("提交成功！");
        $('txtcontent').value = "";
        $('txtprice').value = "";
        $('txtcontentRepaly').value = "";
        $('txtpriceReplay').value = "";
        refresh('imgCheckCode');
        $('messagediv').innerHTML = "";

        $('messagediv').innerHTML = result;
        $('lyhf').style.display = 'none';
    }
    $('btnMess').disabled = false;
    $('btnMess').value = "提交留言";
    $('btnReplay').disabled = false;
    $('btnReplay').value = "提交留言";
}
//提交并展示留言。
function SumbitShowMessage(userName, content, price, pwd, chkanonymity, type, code) {
    var UcarId = $F("hdUcarIdUser");
    var _ParentId = $F("hfParentID");
    var url = "/ajax/buycar/ajaxmessage.ashx";
    var messparam = "ucarid=" + UcarId + "&username=" + userName + "&content=" + content + "&price=" + price + "&pwd=" + pwd + "&parentid=" + _ParentId + "&chkanonymity=" + chkanonymity + "&type=" + type + "&codes=" + code + "&ucartype=1&pageindex=1";
    new Ajax.Request(url, { method: "post", parameters: encodeURI(messparam),
        onSuccess: InitBlockSuccess
        // evalScripts: true,
        // asynchronous: true
    }
);
}
//个人车源留言方法 end
//商家留言方法 start
//检查验证码
function TrancheckCode(txtCodeId, TipSpanId) {
    var code = document.getElementById(txtCodeId).value;
    if (code == "") {
        $(TipSpanId).update("&nbsp;验证码不能为空！");
        $(TipSpanId).show();
        return false;
    }
    else if (!UcarValidateCode(txtCodeId)) {
        $(TipSpanId).update("&nbsp;验证码错误请重新输入！");
        $(TipSpanId).show();
        return false;
    }
    else {
        $(TipSpanId).update("");
        $(TipSpanId).hide();
        return true;
    }
}
//ajax提交成功处理方法
function TranMessageSuccess(response) {
    var result = response.responseText;
    if (result == "1") {
        alert("验证码错误！");
    }
    else if (result == "2") {
        alert("提交失败！");
    }
    else if (result == "3") {
        alert("询价留言提交成功,请耐心等待商家联系!");
        $("txttitle").value = "";
        $("txtprice").value = "";
        $("txtlinkMan").value = "";
        $("txtTel").value = "";
        $("txtmail").value = "";
        $("txtRemark").value = "";
        refresh('TransLeaveMessage1_tranimgCheckCode');
    }
    else if (result == "4") {
        alert("请输入正确的用户名！");
    }
    $('btnSubmit').disabled = false;
    $('btnSubmit').value = "提交留言";
}
//提交商家留言
function ValidateTransMessageLeave() {
    var TitleValidate = new Ucar_Validate('txttitle', 'spTipTitle');
    var PriceValidate = new Ucar_Validate('txtprice', 'spTipPrice');
    var LinkManValidate = new Ucar_Validate('txtlinkMan', 'spTipLinkMan');
    var LinkTelValidate = new Ucar_Validate('txtTel', 'spTipLinkTel');
    var MailValidate = new Ucar_Validate('txtmail', 'spTipMail');
    var RemarkValidate = new Ucar_Validate('txtRemark', 'spTipRemark');
    var result = true;
    if (!(TitleValidate.CheckEmpty("请输入询价标题"))) {
        result = false;
    }
    if (!PriceValidate.CheckEmpty("请输入期望价格")) {
        result = false;
    }
    else if (!PriceValidate.CheckFormat(RegExpr.CarPrice, "请输入正确的期望价格，最多输入３位整数２位小数")) {
        result = false;
    }

    if (!LinkManValidate.CheckEmpty("请输入联系人")) {
        result = false;
    }
    if (!LinkTelValidate.CheckEmpty("请输入联系电话")) {
        result = false;
    }
    else if (!LinkTelValidate.CheckFormat(RegExpr.TelOrMobile, "电话或手机格式不对")) {
        result = false;
    }
    if ($F('hdProvId') == "" || isNaN($F('hdProvId')) || parseInt($F('hdProvId')) == 0) {
        $('spTipCity').update("请选择省份/城市");
        $('spTipCity').show();
        result = false;
    }
    else if ($F('hdCityId') == "" || isNaN($F('hdCityId')) || parseInt($F('hdCityId')) == 0) {
        $('spTipCity').update("请选择城市/城市");
        $('spTipCity').show();
        result = false;
    }
    else {
        $('spTipCity').update("");
        $('spTipCity').hide();
    }

    if ($F('txtmail').length > 0) {
        if (!MailValidate.CheckFormat(RegExpr.Email, "邮箱地址格式不对")) {
            result = false;
        }
    }
    if ($F('txtRemark').length > 0) {
        if (!RemarkValidate.CheckTrueLength(100, "补充信息字数控制在50字以内")) {
            result = false;
        }
    }
    if (!TrancheckCode('trantxtCheckCode', 'msgCode')) {
        result = false;
    }
    if (result) {
        $('btnSubmit').value = "请稍候……";
        $('btnSubmit').disabled = true;
        var UcarSerialNumber = $F("hdUcarSerialNumber");
        var Title = $F("txttitle");
        var Price = $F("txtprice");
        var linkMan = $F("txtlinkMan");
        var Tel = $F("txtTel");
        var mail = $F("txtmail");
        var MsgContent = $F("txtRemark");
        var ProvId = $F("hdProvId");
        var CityId = $F("hdCityId");
        var CheckCode = $F("trantxtCheckCode");
        var TrvaId = $F("hidTrvaId");
        var SuperiorId = $F("hidSuperiorId");
        var url = "/ajax/buycar/ajaxmessage.ashx";
        var messparam = "linkMan=" + linkMan + "&TrvaId=" + TrvaId + "&UcarSerialNumber=" + UcarSerialNumber + "&CityId=" + CityId + "&mail=" + mail + "&Price=" + Price + "&Title=" + Title + "&MsgContent=" + MsgContent + "&Tel=" + Tel + "&codes=" + CheckCode + "&ucartype=2&SuperiorId=" + SuperiorId;
        new Ajax.Request(url, { method: "post", parameters: encodeURI(messparam),
            onSuccess: TranMessageSuccess
            //evalScripts: true,
            // asynchronous: true
        }
);
    }
    else {
        return false;
    }

}
/*
objWord:输入框控件对象
objMss:提示控件对象
size:限制长度
word:输入文字
*/
function showContentSize(objWord, objMss, size, word) {
    if (word == null || word == undefined) {
        word = objWord.value.strip();
    }
    var len = 0;
    len = word.replace(/[^\x00-\xff]/g, "**").length
    var num = size - len;
    $(objMss).innerHTML = "当前已输入" + parseInt(len) + "字符，还能输入" + parseInt(num) + "字符";
    if (num < 0) {
        cutWordSize(objWord, len, size);
        $(objMss).innerHTML = "当前已输入" + size + "字符，还能输入0字符";
    }
}
function cutWordSize(objWord, len, size) {
    if (objWord.value.length != len) {
        if ((len - objWord.value.length) > (size / 2)) {
            objWord.value = objWord.value.substring(0, size / 2);
        } else {
            objWord.value = objWord.value.substring(0, size - (len - objWord.value.length));
        }
    } else {
        objWord.value = objWord.value.substring(0, size);
    }
}
//商家留言 end


