﻿
function Order() {
    this.base = {
        documentElement: function(type) {
            return document.documentElement[type] || document.body[type];
        }
    }

    var webhost = '';
    this.getInfo = function(url) {
        var jsId = "messageId0";
        if (document.getElementById(jsId)) {
            pro.remove(jsId);
        }
        var messageObj = document.createElement("script");
        messageObj.setAttribute("type", "text/javascript")
        messageObj.setAttribute("src", url);
        messageObj.setAttribute("id", jsId);
        var head = document.getElementsByTagName('head')[0];
        this.remove(jsId);
        head.appendChild(messageObj);
        if (document.all) {
            messageObj.onreadystatechange = function() {
                if (this.readyState == "complete" || this.readyState == "loaded") {
                    try {
                        pro.setData();
                    } catch (e) {
                        setTimeout(function() {
                            pro.remove(jsId);
                            head.appendChild(messageObj);
                        }, 2000);
                    }
                }
            };
        }
        else {
            messageObj.onload = function() { pro.setData(); };
        }
    }

    this.remove = function(id) {
        var head = document.getElementsByTagName('head')[0];
        if (document.getElementById(id)) {
            head.removeChild(document.getElementById(id));
        }
    };


    this.GetPriceInfo = function(vendorId, carId) {
    var hostAdd = webhost + "/Ajax/BuyCarOrder.aspx";
        var parm = "?vendorId=" + vendorId + "&newcarid=" + carId; //+"&"+Math.random();
        if (this.isTestDrive == 2) {
            document.getElementById("ordersubmith3").innerText = "试驾意向";
            parm += "&ordertype=2";
        }
        else {
            document.getElementById("ordersubmith3").innerText = "购车意向";
        }
        if (this.addressType == 2) {
            parm += "&addressType=2";
        }
        pro.getInfo(hostAdd + parm);

    }

    this.GetPriceInfoNewCarID = function(vendorId, carId) {
    var hostAdd = webhost + "/Ajax/BuyCarOrder.aspx";
        var parm = "?vendorId=" + vendorId + "&newcarid=" + carId; //+"&"+Math.random();
        if (this.isTestDrive == 2) {
            document.getElementById("ordersubmith3").innerText = "试驾意向";
            parm += "&ordertype=2";
        }
        else {
            document.getElementById("ordersubmith3").innerText = "购车意向";
        }
        if (this.addressType == 2) {
            parm += "&addressType=2";
        }

        pro.getInfo(hostAdd + parm);
    }
    this.GetMerchandiseInfo = function(dealerId, mId, type, carid) {
       
        var hostAdd = "/Ajax/BuyCarOrder.aspx";
        var parm = "";

        var buyNum = 0, runNum = 0, yearNum = 0, monthNum = 0;
        var parm_t = "";
        if (gid("runNum") && gid("runNum").value.length > 0)
            parm_t += "&runNum=" + gid("runNum").value;
        if (gid("buyYear") && gid("buyYear").value.length > 0)
            parm_t += "&yearNum=" + gid("buyYear").value;
        if (gid("buyMonth") && gid("buyMonth").value.length > 0)
            parm_t += "&monthNum=" + gid("buyMonth").value;

        if (type) {
            switch (type) {                
                case 3://汽车用品
                    parm = "?vendorId=" + dealerId + "&merchandiseId=" + mId + "&ordertype=3&" + Math.random();
                    break;
                case 4://保养服务
                    parm = "?vendorId=" + dealerId + parm_t + "&csid=" + mId + "&newcarid=" + carid + "&ordertype=4&" + Math.random();
                    break;
            }
        }
        
        this.getInfo(hostAdd + parm);
    }
    var pro = this;

    this.setData = function() {
        if (returnMemo && returnMemo != "") {
            var memo = returnMemo;
            var tt = document.getElementById("orderLayersubmit");
            tt.innerHTML = memo;
            popload("ordersubmit");
            return false;
        }

    }
 
    this.CheckMobile = function(mobile) {
        var regMobile1 = /^0?15\d{9}$/;
        var regMobile2 = /^0?13\d{9}$/;

        if (regMobile1.test(mobile) || regMobile2.test(mobile)) {
            return true;
        }
        else {
            return false;
        }
    }
    /*Mayh2010-12-06添加*/
    this.validateOrderData = function(type) {
        var buyNum = document.getElementById("buyNum");
        var runNum = document.getElementById("runNum");
        var yearNum = document.getElementById("yearNum");
        var monthNum = document.getElementById("monthNum");

        var phone = document.getElementById("phone");
        var memo = document.getElementById("memo");

        var carColor = document.getElementById("carColor");
        var user = document.getElementById("userName");
        var city = document.getElementById("cityvalue");

        var email = document.getElementById("email");



        var msg = true;
        var errorMessage = "";
        user.value = user.value.replace(/'/gi, '').replace(/"/gi, '').replace(/</gi, '').replace(/>/gi, '').replace(/\//gi, '').replace(/\\/gi, '').replace(/\./gi, '');
        if (gid("email")) {
            email = document.getElementById("email");
            email.value = email.value.replace(/'/gi, '').replace(/"/gi, '');
        }
        memo.value = memo.value.replace(/'/gi, '').replace(/"/gi, '').replace(/</gi, '').replace(/>/gi, '').replace(/\//gi, '').replace(/\\/gi, '').replace(/\./gi, '');

        while (user.value.indexOf(" ") > -1) {
            user.value = user.value.replace(" ", "");
        }

        while (user.value.indexOf("&") > -1) {
            user.value = user.value.replace("&", "");
        }

        while (user.value.indexOf("\\") > -1) {
            user.value = user.value.replace("\\", "");
        }

        if (user.value == "") {
            errorMessage += "用户名不能为空。<br />";
            msg = false;
        }
        else {
            if (user.value.length > 10) {
                errorMessage += "用户名请勿大于10个字符。<br/>";
                msg = false;
            }
            else {
                this.RemoveErrSpan(user);
            }
        }
        if (buyNum) {
            if (buyNum.value == "") {
                errorMessage += "请填写购买数量。<br/>";
                msg = false;
            }
            else if (!this.CheckNum(buyNum.value)) {
                errorMessage += "填写数量有误。<br/>";
                msg = false;
            }
            else if (buyNum.value.length > 10) {
                errorMessage += "填写购买数量超过范围。<br/>";
                msg = false;
            }
            else {
                this.RemoveErrSpan(buyNum);
            }
        }
        if (!gid("carId") || parseInt(gid("carId").value) <= 0) {
            if (gid("CarType")) {
                if (!gid("CarType") || gid("CarType").value == -1 || gid("CarType").value == 0 || gid("CarType").value == "请选择车型") {
                    errorMessage += "请选择车型。<br/>";
                    msg = false;
                }
                else
                    this.RemoveErrSpan(gid("CarType"));
            }
        }


        if (runNum) {
            if (runNum.value == "") {
                errorMessage += "请填写行驶里程。<br/>";
                msg = false;
            }
            else if (!this.CheckNum(runNum.value)) {
                errorMessage += "填写里程有误。<br/>";
                msg = false;
            }
            else if (runNum.value.length > 10) {
                errorMessage += "填写行驶里程超过范围。<br/>";
                msg = false;
            }
            else {
                this.RemoveErrSpan(runNum);
            }
        }
        if (yearNum && monthNum) {
            if ((yearNum.value || monthNum.value) && (yearNum.value != "请选择" || monthNum.value != "请选择")) {
                if (!yearNum.value || yearNum.value == "请选择") {
                    errorMessage += "请选择年份。<br/>";

                    msg = false;
                }
                if (!monthNum.value || monthNum.value == "请选择") {
                    errorMessage += "请选择月份。<br/>";

                    msg = false;
                }
            }
            else {
                this.RemoveErrSpan(yearNum)
            }
        }



        if (city.value == "" || city.value == "0") {
            errorMessage += "请选择城市。<br/>";
            msg = false;
        }
        else {
            this.RemoveErrSpan(city);
        }
        if (phone.value.Trim() == "") {
            errorMessage += "请填写电话或手机号码。<br/>";
            msg = false;
        }
        else {
            var tel = phone.value;
            if (!this.CheckMobile(tel)) {
                if (!this.CheckTel(tel)) {
                    errorMessage += "联系方式格式不正确。<br/>";
                    msg = false;
                }
                else {
                    this.RemoveErrSpan(phone);
                }
            }
        }


        if (email && email.value != "") {
            //            if (email.value.Trim().length > 50) {
            //                email.value = email.value.substr(0, 50);
            //            }
            if (email.value.Trim().length > 50) {
                errorMessage += "邮箱长度不能超过50个字符。<br/>";
                msg = false;
            }
            else {
                this.RemoveErrSpan(email);
            }
            var reg = /^([a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)*)+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
            if (!reg.test(email.value)) {
                errorMessage += "邮件格式不正确。<br/>";
                msg = false;
            }
            else {
                this.RemoveErrSpan(email);
            }

        }


        if (gid("ItemsDiv")) {
            var xid = "";
            var objs = window.document.getElementsByName("repairItem");
            for (var i = 0; i < objs.length; i++) {
                if (objs[i].checked) {
                    xid += objs[i].value;
                    if (i != objs.length - 1)
                        xid += ",";
                }
            }
            if (xid == "") {
                errorMessage += "请选择故障类型。<br/>";
                msg = false;
            }
            else {
                this.RemoveErrSpan(gid("ItemsDiv"));
            }
        }

        if (gid("subTime")) {
            gid("subTime").value = gid("subTime").value.replace(/'/gi, '').replace(/"/gi, '').replace(/</gi, '').replace(/>/gi, '').replace(/\//gi, '').replace(/\\/gi, '').replace(/\./gi, '');
            var subTime = gid("subTime").value;
            if (subTime == "") {
                errorMessage += "请选择填写预约时间。<br/>";
                msg = false;
            }
            else {
                this.RemoveErrSpan(gid("subTime"));
            }
        }

        if (type == 5) {
            if (memo.value.length > 200) {
                errorMessage += "补充说明不能大于200个字符。<br/>";
                msg = false;
            }
            else {
                this.RemoveErrSpan(memo);
            }
        }
        else {
            if (memo.value.length > 50) {
                errorMessage += "补充说明不能大于50个字符。<br/>";
                msg = false;
            }
            else {
                this.RemoveErrSpan(memo);
            }
        }


        if (!msg) {


            if (type == 5) {
                $("#pErrorMsg1").html("<em class=\"warning\"><i></i>" + errorMessage + " </em>");
                popload("errorMessage");
                return false;
            }
            _M.IframeFloor("ordersubmit");
            _M.ErrorMsg(null, errorMessage, 'orderLayersubmit');
            $("#ErrorMsg2").css("z-index", 999999);
            msg = true;
            return false;
        }
        return true;
    }
this.CheckNum = function(str) {
        var reg = /^([1-9]\d*)$/;
        if (reg.test(str)) {
            return true;
        }
        else {
            return false;
        }
    }
    this.saveOrderMerchandise = function(type) {
        if (this.isProcess) {
            //return false;
        }

        this.isProcess = true;
        if (!this.validateOrderData(type)) {
            this.isProcess = false;
            return false;
        }
        //参数
        this.isTestDrive = type;
        var hostAdd = "/Ajax/BuyCarOrder.aspx";
        var parm = this.GetParamsInfo();
       
        pro.getInfo(hostAdd + parm);
        return true;
    }
    
//    this.successMerchandise = function(vendorName, vendorId, orderId, type) {
//        this.isProcess = false;
//        var hostAdd = "/Ajax/BuyCarOrder.aspx";
//        var parm
//        if (type) {
//            parm = "?order=" + type + "&action=success&vendorName=" + escape(vendorName) + "&vendorId=" + vendorId + "&orderid=" + orderId + "&" + Math.random();
//        }
//        this.getInfo(hostAdd + parm);
//    }
//    /*Mayh2010-12-15添加*/
//    this.backModifyMerchandise = function(id, vendorId, type) {
//        var hostAdd = "/Ajax/BuyCarOrder.aspx";
//        var parm = this.GetParamsInfo();
//        this.getInfo(hostAdd + parm);
//    }
     /*Mayh2010-12-06添加*/
    this.CheckTel = function(tel) {
        var regTel = /^\d{7,16}$/;

        if (regTel.test(tel)) {
            return true;
        }
        else {
            return false;
        }
    }
    
    this.CreateErrSpan = function(obj, msg) {
        this.RemoveErrSpan(obj);
        var span = document.createElement("span");
        span.id = "__ErrorMessagePanel";
        span.className = "alert";
        obj.parentNode.appendChild(span);
        if (msg.length > 0) {
            span.innerHTML = msg;
        }
        else {
            span.innerHTML = obj.msg;
        }
    }

    this.RemoveErrSpan = function(obj) {
        if (obj.parentNode.lastChild.id == "__ErrorMessagePanel") {
            obj.parentNode.removeChild(obj.parentNode.lastChild);
        }
    }

    this.isProcess = false;
    this.isTestDrive = 1;
    this.addressType = 1;

    this.saveOrder = function() {
        if (this.isProcess) {
            return false;
        }

        this.isProcess = true;
        if (!this.validateOrderData(this.isTestDrive)) {
            this.isProcess = false;
            return false;
        }

        var hostAdd = webhost + "/Ajax/BuyCarOrder.aspx";
        var parm = this.GetParamsInfo();

        if (this.addressType == 2) {
            parm += "&addressType=2";
        }
        pro.getInfo(hostAdd + parm);
    }
    ///获取参数
    this.GetParamsInfo = function() {
        var parm = "";
        if (document.getElementById("carColor")) {
            var carColor = document.getElementById("carColor").value;
            if (parm.length > 0 && carColor.length > 0) {
                parm += "&";
            }
            if (carColor.length > 0) {
                parm += "carColor=" + escape(carColor);
            }
        }
        if (document.getElementById("userName")) {
            var user = document.getElementById("userName").value.replace(/'/gi, '').replace(/"/gi, '');
            if (parm.length > 0 && user.length > 0) {
                parm += "&";
            }
            if (user.length > 0) {
                parm += "user=" + escape(user);
            }
        }
        if (document.getElementById("userSex1")) {
            var userSex = document.getElementById("userSex1").checked == true ? "1" : "0";

            if (userSex == "0") {
                if (document.getElementById("userSex2")) {
                    userSex = document.getElementById("userSex2").checked == true ? "0" : "-1";
                }
            }
            if (parm.length > 0 && userSex.length > 0) {
                parm += "&";
            }
            if (userSex.length > 0) {
                parm += "sex=" + userSex;
            }
        }
        else if (document.getElementById("userSex")) {
            var userSex = document.getElementById("userSex").value;
            if (parm.length > 0 && userSex.length > 0) {
                parm += "&";
            }
            if (userSex.length > 0) {
                parm += "sex=" + userSex;
            }
        }

        if (document.getElementById("phone")) {

            var phone = document.getElementById("phone").value;
            if (parm.length > 0 && phone.length > 0) {
                parm += "&";
            }
            if (phone.length > 0) {
                parm += "phone=" + escape(phone);
            }
        }
        if (document.getElementById("email")) {
            var email = document.getElementById("email").value.replace(/'/gi, '').replace(/"/gi, '');
            if (parm.length > 0 && email.length > 0) {
                parm += "&";
            }
            if (email.length > 0) {
                parm += "email=" + email;
            }
        }
        if (document.getElementById("memo")) {
            var memo = document.getElementById("memo").value.replace(/'/gi, '').replace(/"/gi, '');
            if (parm.length > 0 && memo.length > 0) {
                parm += "&";
            }
            if (memo.length > 0) {
                parm += "memo=" + escape(memo);
            }
        }
        if (document.getElementById("carId") && parseInt( document.getElementById("carId").value) > 0) {
            var carId = document.getElementById("carId").value;
            if (parm.length > 0 && carId.length > 0) {
                parm += "&";
            }
            if (carId.length > 0) {
                parm += "newcarid=" + carId;
            }
        }
        else if (gid("CarType")) {
            var carId = gid("CarType").options[gid("CarType").selectedIndex].value;
            if (parm.length > 0 && carId.length > 0) {
                parm += "&";
            }
            if (carId.length > 0) {
                parm += "newcarid=" + carId;
            }
        }
        if (document.getElementById("vendorId")) {
            var vendorId = document.getElementById("vendorId").value;
            if (parm.length > 0 && vendorId.length > 0) {
                parm += "&";
            }
            if (vendorId.length > 0) {
                parm += "vendorId=" + vendorId;
            }
        }
        if (document.getElementById("price")) {
            var price = document.getElementById("price").value;
            if (parm.length > 0 && price.length > 0) {
                parm += "&";
            }
            if (price.length > 0) {
                parm += "price=" + price;
            }
        }
        //
        if (document.getElementById("bpprice")) {
            var bpprice = document.getElementById("bpprice").value;
            if (parm.length > 0 && bpprice.length > 0) {
                parm += "&";
            }
            if (bpprice.length > 0) {
                parm += "bpprice=" + bpprice;
            }
        }
        if (document.getElementById("subscribeprice")) {
            var subscribeprice = document.getElementById("subscribeprice").value;
            if (parm.length > 0 && subscribeprice.length > 0) {
                parm += "&";
            }
            if (subscribeprice.length > 0) {
                parm += "subscribeprice=" + subscribeprice;
            }
        }
        if (document.getElementById("deliverywaitdays")) {
            var deliverywaitdays = document.getElementById("deliverywaitdays").value;
            if (parm.length > 0 && deliverywaitdays.length > 0) {
                parm += "&";
            }
            if (deliverywaitdays.length > 0) {
                parm += "deliverywaitdays=" + deliverywaitdays;
            }
        }
        if (document.getElementById("ready")) {
            var ready = document.getElementById("ready").value;
            if (parm.length > 0 && ready.length > 0) {
                parm += "&";
            }
            if (ready.length > 0) {
                parm += "ready=" + ready;
            }
        }
        //
        if (document.getElementById("province")) {
            var cityName = document.getElementById("province").options[document.getElementById("province").selectedIndex].text;
            cityName += " " + document.getElementById("cityvalue").options[document.getElementById("cityvalue").selectedIndex].text;
            if (parm.length > 0 && cityName.length > 0) {
                parm += "&";
            }
            if (cityName.length > 0) {
                parm += "cityName=" + escape(cityName);
            }
        } else if (document.getElementById("cityName")) {
            var cityName = document.getElementById("cityName").value;
            if (parm.length > 0 && cityName.length > 0) {
                parm += "&";
            }
            if (cityName.length > 0) {
                parm += "cityName=" + escape(cityName);
            }
        }
        if (document.getElementById("cityvalue")) {
            try {
                var city = document.getElementById("cityvalue").value;
                if (parm.length > 0 && city.length > 0) {
                    parm += "&";
                }
                if (city.length > 0) {
                    parm += "city=" + escape(city);
                }
            }
            catch (err) { }
        }
        if (document.getElementById("orderId")) {
            var orderId = document.getElementById("orderId").value;
            if (parm.length > 0 && orderId.length > 0) {
                parm += "&";
            }
            if (orderId.length > 0) {
                parm += "orderId=" + orderId;
            }
        }
        if (document.getElementById("carname")) {
            var carname = document.getElementById("carname").value;
            if (parm.length > 0 && carname.length > 0) {
                parm += "&";
            }
            if (carname.length > 0) {
                parm += "carname=" + escape(carname);
            }
        }
        else if (gid("CarType")) {
            var carname = gid("subBrandId").options[gid("subBrandId").selectedIndex].text;
            carname += " " + gid("CarType").options[gid("CarType").selectedIndex].text;
            if (parm.length > 0 && carname.length > 0) {
                parm += "&";
            }
            if (carname.length > 0) {
                parm += "carname=" + escape(carname);
            }

        }
        //以下2010-12-06添加

        if (document.getElementById("MerchandiseDealerId")) {
            var MerchandiseDealerId = document.getElementById("MerchandiseDealerId").value;
            if (parm.length > 0 && MerchandiseDealerId.length > 0) {
                parm += "&";
            }
            if (MerchandiseDealerId.length > 0) {
                parm += "merchandiseId=" + escape(MerchandiseDealerId);
            }
        }


        if (document.getElementById("buyNum")) {
            var buyNum = document.getElementById("buyNum").value;
            if (parm.length > 0 && buyNum.length > 0) {
                parm += "&";
            }
            if (buyNum.length > 0) {
                parm += "buyNum=" + escape(buyNum);
            }
        }
        if (gid("shotId")) {
            var shotId = gid("shotId").value;
            if (parm.length > 0 && shotId.length > 0) {
                parm += "&";
            }
            if (shotId.length > 0) {
                parm += "shotId=" + escape(shotId);
            }
        }
        if (document.getElementById("runNum")) {
            var runNum = document.getElementById("runNum").value;
            if (parm.length > 0 && runNum.length > 0 && !isNaN(runNum)) {
                parm += "&";
            }
            if (runNum.length > 0 && !isNaN(runNum)) {
                parm += "runNum=" + escape(runNum);
            }
        }
        if (document.getElementById("yearNum")) {
            var yearNum = document.getElementById("yearNum").value;
            if (parm.length > 0 && yearNum.length > 0 && !isNaN(yearNum) && parseInt(yearNum) > 0) {
                parm += "&";
            }
            if (yearNum.length > 0 && !isNaN(yearNum) && parseInt(yearNum) > 0) {
                parm += "yearNum=" + escape(yearNum);
            }
        }
        if (document.getElementById("monthNum")) {
            var monthNum = document.getElementById("monthNum").value;
            if (parm.length > 0 && monthNum.length > 0 && !isNaN(monthNum) && parseInt(monthNum) > 0) {
                parm += "&";
            }
            if (monthNum.length > 0 && !isNaN(monthNum) && parseInt(monthNum) > 0) {
                parm += "monthNum=" + escape(monthNum);
            }
        }
       
        if (gid("csid")) {
            var cs_gid = gid("csid").value;
            if (parm.length > 0 && cs_gid.length > 0) {
                parm += "&";
            }
            if (cs_gid.length > 0) {
                parm += "csid=" + escape(cs_gid);
            }
        }

       

        if (gid("groupid")) {
            var groupid = gid("groupid").value;
            if (parm.length > 0 && groupid.length > 0 && parseInt(groupid) > 0) {
                parm += "&";
            }
            if (groupid.length > 0 && parseInt(groupid) > 0) {
                parm += "groupid=" + escape(groupid);
            }
        }

        if (gid("subTime")) {
            var subTime = gid("subTime").value;
            if (parm.length > 0 && subTime.length > 0) {
                parm += "&";
            }
            if (subTime.length > 0) {
                parm += "subTime=" + escape(subTime);
            }
        }

        if (gid("ItemsDiv")) {
            var xid = "";
            var objs = window.document.getElementsByName("repairItem");
            for (var i = 0; i < objs.length; i++) {
                if (objs[i].checked) {
                    xid += objs[i].value;
                    if (i != objs.length - 1)
                        xid += ",";
                }
            }
            var repairItems = xid;
            if (parm.length > 0 && repairItems.length > 0) {
                parm += "&";
            }
            if (repairItems.length > 0) {
                parm += "repairItems=" + escape(repairItems);
            }
        }
        
        //以上2010-12-06 添加
        if (parm.length > 0 && (parm.lastIndexOf('&', 0) == parm.length - 1)) {
            parm = parm.substr(0, parm.length - 1);
        }
        if (parm.length > 0) {
            parm += "&";
        }
        parm += "ordertype=" + this.isTestDrive;
        if (parm.length > 0) {
            parm = '?' + parm;
        }
        return parm;
    }

    this.changeProvince = function() {
        var province = document.getElementById("province").value;
        var city = document.getElementById("cityvalue");

        city.options.length = 0;
        city.options.add(new Option("所在城市", 0));
        for (var i = 0; i < orderCitys.Rows.length; i++) {
            var cityId = orderCitys.Rows[i].city_Id + '';
            var cityName = orderCitys.Rows[i].city_Name;

            if (province + '' == cityId.substring(0, cityId.length - 2)) {
                city.options.add(new Option(cityName, cityId));
            }
        }
    }


    this.backModify = function(id) {
        var hostAdd = webhost + "/Ajax/BuyCarOrder.aspx";
        var parm = this.GetParamsInfo();
        parm += '&action=edit'

        if (this.addressType == 2) {
            parm += "&addressType=2";
        }
        this.getInfo(hostAdd + parm);
        this.isProcess = false;
        return false;

    }
    this.setOrderInfo = function() {
        if (pro.xmlHttp.readyState == 4) {
            if (pro.xmlHttp.status == 200) {
                if (pro.xmlHttp.responseText != "") {
                    var orderLayer = document.getElementById("orderLayer");
                    orderLayer.innerHTML = pro.xmlHttp.responseText;
                    this.isTestDrive = false;
                }
            }
        }
    }
    this.close = function() {
        this.isProcess = false;
        
        hide('orderLayer');

        hide("popIframe1");
        hide("ordersubmit");
        hide("popBox1");
        hide("popIframe1");

        return false;
    }

    this.Tip400Message = function(vendor400Tel, exNumber) {
        //                        vendor400Tel = ''+vendor400Tel;
        var memo = "";

        memo += "<div class=\"wd_alert\">";
        memo += "<h3>联系我们</h3>";
        memo += "<div class=\"wd_alert_blc\">";

        memo += "<div class=\"wd_alert_tip\"><img alt=\"\" src=\"/images/crow.gif\"><span>顾客您好！请您拨打以下电话直接与我们联系。</span></div>";
        memo += "<div class=\"wd_alert_phone\"><i></i> <em>";
        memo += String(vendor400Tel) + "</em> <span>转</span> <em>" + exNumber;
        memo += "</em></div>";
        memo += "<div class=\"wd_btns wd_btns_c\"><input type=\"button\" value=\"确定\" onclick=\"O.close();\"></div>";
        memo += "</div>";
        memo += " <span class=\"more\"><a title=\"关闭\" onclick=\"O.close();\" class=\"alert_close\">关闭</a></span></div>";
        var tt = document.getElementById("orderLayer");
        tt.innerHTML = memo;
        popload("orderLayer");

    }
    this.success = function(vendorName, vendorId, orderId) {
        this.isProcess = false;
        var hostAdd = webhost + "/Ajax/BuyCarOrder.aspx";
        var parm = this.GetParamsInfo();
        parm += "&action=success&vendorName=" + escape(vendorName);

        this.getInfo(hostAdd + parm);
    }
    function setSelectState(state) {
        var objl = document.getElementsByTagName('select');
        for (var i = 0; i < objl.length; i++) {
            objl[i].style.visibility = state;
        }
    }
    this.ShowTip = function() {
        if (isIe) {
            setSelectState("hidden");
        }
        document.getElementById("DialogTip").style.display = "block";
    }

    this.HideTip = function() {

        if (isIe) {
            setSelectState("");
        }
        document.getElementById("DialogTip").style.display = "none";
    }

}
var O = new Order();
String.prototype.Trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
var isIe = (document.all) ? navigator.appVersion.indexOf('MSIE 6.0') > 0 ? true : false : false;
function showtips() { show("DialogTip"); hide("province"); hide("cityvalue"); }
function hidetips() { hide("DialogTip"); show("province"); show("cityvalue"); }



function hide(id) { var Div = document.getElementById(id); if (Div) { Div.style.display = "none" } }
function show(id) { var Div = document.getElementById(id); if (Div) { Div.style.display = "block" } }

function GetOrderInfos(ordertype, vendorid, carid,mid) {
    if (ordertype == 1) {
        document.getElementById("ordersubmith3").innerHTML = "购车意向";
    }
    else if (ordertype == 3) {
    document.getElementById("ordersubmith3").innerHTML = "汽车用品在线预订";
    }
    else if (ordertype == 4) {
        document.getElementById("ordersubmith3").innerHTML = "预约保养";
    }
    else if (ordertype == 5) {
        document.getElementById("ordersubmith3").innerHTML = "预约维修";
    }
    else {
        document.getElementById("ordersubmith3").innerHTML = "试驾意向";
    }
    O.isTestDrive = ordertype;
    if (carid != null && carid > 0) {
        return getOrder(vendorid, carid, ordertype);
    }
    return getOrders(vendorid, carid, ordertype,mid);
}

function GetOrderInfo(ordertype, vendorid, carid) {
    if (ordertype == 1) {
        document.getElementById("ordersubmith3").innerHTML = "购车意向";
    }
    else if (ordertype == 3) {
    document.getElementById("ordersubmith3").innerHTML = "汽车用品在线预订";
    }
    else if (ordertype == 4) {
        document.getElementById("ordersubmith3").innerHTML = "预约保养";
    }
    else if (ordertype == 5) {
        document.getElementById("ordersubmith3").innerHTML = "预约维修";
    }
    else {
        document.getElementById("ordersubmith3").innerHTML = "试驾意向";
    }
    O.isTestDrive = ordertype;
    return getOrder(vendorid, carid,ordertype,0);
}
function backModify(ordertype, orderid) {
    if (ordertype == 1) {
        document.getElementById("ordersubmith3").innerHTML = "购车意向";
    }
    else if (ordertype == 3) {
        document.getElementById("ordersubmith3").innerHTML = "汽车用品在线预订";
    }
    else if (ordertype == 4) {
        document.getElementById("ordersubmith3").innerHTML = "预约保养";
    }
    else if (ordertype == 5) {
        document.getElementById("ordersubmith3").innerHTML = "预约维修";
    }
    else {
        document.getElementById("ordersubmith3").innerHTML = "试驾意向";
    }
    O.isTestDrive = ordertype;
    return O.backModify(orderid);
}
function OrderSuccess(orderType, vendorFullName, vendorId, orderID) {
    if (orderType == 1) {
        document.getElementById("ordersubmith3").innerHTML = "购车意向";
    }
    else if (orderType == 3) {
        document.getElementById("ordersubmith3").innerHTML = "汽车用品在线预订";
    }
    else if (orderType == 4) {
        document.getElementById("ordersubmith3").innerHTML = "预约保养";
    }
    else if (orderType == 5) {
        document.getElementById("ordersubmith3").innerHTML = "预约维修";
    }
    else {
        document.getElementById("ordersubmith3").innerHTML = "试驾意向";
    }
    O.isTestDrive = orderType;
    O.success(vendorFullName, vendorId, orderID);
    //    return false;
}
function GetSerialSelect() {
    if (MainSerialIds && csid) {
    ViewAllCarsId = true;
    bindsbrandSome(MainSerialIds ,  csid );bindmode(csid, -1);
        setTimeout("bindsbrandSome('" + MainSerialIds + "', " + csid + "); bindmode(" + csid + ", -1)", 1200);
    }
}



