﻿
var xpath = "/koubei/";
//Element.addMethods({
//  scrollTo: function(element, left, top){
//    var element = $(element);
//    if (arguments.length == 1){
//      var pos = element.cumulativeOffset();
//      window.scrollTo(pos[0], pos[1]);
//    } else {
//      element.scrollLeft = left;
//      element.scrollTop  = top;
//    }
//    return element;
//  },
//  scrollToA:function(element,to){
//    if(to&&element){
//        var element = $(element);
//        var to = $(to);
//        var top = to.cumulativeOffset()[1]-element.cumulativeOffset()[1];
//        element.scrollTo(0,top);
//    }
//  }
//});
var util =
{
    navigator: {
        ie6: navigator.appVersion.indexOf('MSIE 6') > 0,
        ie7: navigator.appVersion.indexOf('MSIE 7') > 0,
        ie8: navigator.appVersion.indexOf('MSIE 8') > 0,
        mac: (navigator.appVersion.indexOf('Mac') > -1)
    },
    createCookie: function(name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else var expires = "";
        document.cookie = name + "=" + value + expires + "; path=/";
    },
    readCookie: function(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    },
    eraseCookie: function(name) {
        createCookie(name, "", -1);
    },
    ajaxload: null,
    loading: function(element) {
        if (util.ajaxload == null) {
            var div = new Element('div', { 'style': 'position:absolute;top:0;display:none;z-index:100;' });
            var img = new Element('img', { 'src': 'http://pic.baa.bitautotech.com/webpic/review/bitauto/loading.gif' });
            div.appendChild(img);
            $$('body')[0].appendChild(div);
            util.ajaxload = div;
        }
        util.ajaxload.style.top = (util.position(element)[0]) + 'px';
        util.ajaxload.style.left = (util.position(element)[1] + element.getWidth()) + 'px';
        util.ajaxload.show();
    },
    loaded: function() {
        setTimeout("if(util.ajaxload)util.ajaxload.hide()", 100);
    },
    position: function(element) {
        if (Prototype.Browser.IE) {
            return [element.cumulativeOffset().top + 1, element.cumulativeOffset().left + 1];
        }
        else {
            return [element.cumulativeOffset().top, element.cumulativeOffset().left];
        }
    },
    m_1: null,
    showMessage: function(div, msg) {
        if (util.m_1 != null && util.m_1.parentNode != null) util.m_1.remove();
        util.m_1 = new Element('div', { 'class': 'msg', 'style': 'display:none;' });
        util.m_1.update('<span>' + msg + '</span><a href="#" onclick="$(this).up(\'div\').hide();return false;" title="关闭">X</a>');
        div.down('div').insert(util.m_1, { 'postion': 'bottom' });
        util.m_1.show();

        setTimeout(function() { try { util.m_1.fade() } catch (e) { util.m_1.hide() } }, 2000);
    },
    //位置
    mBox: {
        top: 0,
        left: 0,
        o: null
    },
    //设置位置
    setMBox: function(o, l, t) {
        util.mBox.left = util.position(o)[1] + l;
        util.mBox.top = util.position(o)[0] + t;
    },
    /*
    power:动态创建提示框
    meg:提示框内容
    */
    showMsg: function(msg, name) {
        if (name == null || name == undefined) {
            name = "msg";
        }
        if (util.mBox.o != null && util.mBox.o.parentNode != null) util.mBox.o.remove();
        util.mBox.o = new Element('div', { 'class': name, 'style': 'position:absolute;display:none;left:' + util.mBox.left + 'px;top:' + util.mBox.top + 'px;' });

        util.mBox.o.update('<span>' + msg + '</span><a href="#" onclick="$(this).up(\'div\').hide();return false;" title="关闭">X</a>');
        $$('body')[0].insert(util.mBox.o);
        util.mBox.o.show();
        setTimeout(function() { try { util.mBox.o.fade() } catch (e) { util.mBox.o.hide() } }, 2000);
    },
    showThanks: function(div) {
        util.showMessage(div, '谢谢您的参与');
    },
    showErrors: function(div) {
        util.showMessage(div, '您已经投过票了');
    },
    showRYes: function(div) {
        util.showMessage(div, '举报成功');
    },
    showCopyYes: function(div) {
        util.showMessage(div, '网址复制成功！<br/>按CTRL+V，粘贴到QQ、MSN，或其他聊天工具上发送给好朋友吧！');
    },
    clip: null
};
var Init = {
    UserName: '',
    TagName: '',
    IssueName: '',
    jsFile: null,
    newJsFile: function(src, evnt) {
        Init.jsFile = new Element('script', { 'src': src });
        $$('body')[0].insert(Init.jsFile);

        util.loading(Event.element(evnt))
        setTimeout(function() { util.loaded() }, 500);
    },
    Fold: function() {
        //初始化页面的展开合上事件
        $$('a.open_more').each(function(e) {
            e.observe('click', function(evnt) {
                var act = 'all';

                if (e.className == 'open_more') {
                    e.className = 'open_less';
                }
                else {
                    e.className = 'open_more';
                    act = 'part';
                }
                Init.newJsFile(xpath + 'models/listitem.ashx?review_id=' + $(e).up('div').up('div').id + '&act=' + act + '&tagname=' + Init.TagName + '&issuename=' + Init.IssueName, evnt);

                return false;
            });
        });
    },
    FormTags: function() {
        //初始化表单标签点击事件
        $$('p.tags a').each(function(o) {
            Event.observe(o, 'click', function(evnt) {
                var _strtagvalue = $('contenttags').value;
                _strtagvalue = _strtagvalue.length > 50 ? _strtagvalue.substring(0, 50) : _strtagvalue;
                var _tags = _strtagvalue.split(/\s+|　|,|，/);
                _strtagvalue.split(/\s+|　|,|，/).without(o.innerHTML).length != _tags.length ? $('contenttags').value = _tags.without(o.innerHTML).join(' ') : $('contenttags').value = (_tags.join(' ') + ' ' + o.innerHTML).strip();
                return false
            });
        });
    },
    Vote: function() {
        //初始化页面的支持反对事件
        ZeroClipboard.setMoviePath('http://js.inc.baa.bitautotech.com/review/zeroclipboard.swf');
        util.clip = null;
        $$('div.review_dlist').each(function(d) {
            if (d.down("li").down("a") != null) {
                d.down("li").down("a").observe('click', function(evnt) {
                    evnt.stop();

                    Init.newJsFile(Event.element(evnt).href.replace('chezhan', 'car') + '&type=1', evnt);
                });
            }
            if (d.down("li", 1).down("a") != null) {
                d.down("li", 1).down("a").observe('click', function(evnt) {
                    evnt.stop();

                    Init.newJsFile(Event.element(evnt).href.replace('chezhan', 'car') + '&type=0', evnt);
                });
            }
            if (d.down("li", 4) != null) {
                d.down("li", 4).down("a").observe('click', function(evnt) {
                    evnt.stop();

                    Init.newJsFile(Event.element(evnt).href, evnt);
                });
            }
            if (d.down("li", 5) != null) {
                d.down("li", 5).down("a").observe('mouseover', function(evnt) {
                    if (util.clip == null) util.clip = new ZeroClipboard.Client();
                    util.clip.setText('推荐一个汽车点评给你：' + d.up("div", 2).down("h1").down("a").innerHTML.gsub("[\r|\n]", "") + '\r\n' + d.up("div", 2).down("h1").down("a").href);
                    if (util.clip.div) {
                        util.clip.receiveEvent('mouseout', null);
                        util.clip.reposition(this);
                    }
                    else util.clip.glue(this);
                    util.clip.handlers['complete'] = [];
                    util.clip.addEventListener('complete', function(client, text) {
                        util.showCopyYes(d);
                    });
                });
            }
        });
    },
    Index: {
        fold: function() {
            var i = 0;
            $('car_tab_ul').select('li').each(function(li) {
                li.i = i++;
            });
            $$('#car_tab_ul li').each(function(a) { a.observe('click', function(evnt) { Init.Index.nvTab2(this); evnt.stop(); }) });
        },
        nvTab2: function(_1) {
            $$('#car_tab_ul .current').each(function(e) { if (_1 == e) { if ($(_1).down('a').innerHTML == '新车上市') { window.open($(_1).down('a').href); return; } window.location = '/by_jiage/#jibie' + $(_1).down('a').innerHTML.replace('万-', '-'); } $(e).removeClassName('current') });

            for (var i = 0; i <= 8; i++) {
                $('data_table_' + i).style.display = 'none';
                $('best_car_' + i).style.display = 'none';
            }

            $(_1).addClassName('current');
            $('data_table_' + _1.i).style.display = '';
            $('best_car_' + _1.i).style.display = '';
        },
        tab2: function(to) {
            for (var i = 1; i <= 6; i++) {
                $('ctab_' + i).hide();
            }
            $('ctab_' + to).show();
            $$('#pageTop li').each(function(a) { a.removeClassName('on'); })
            $$('#pageTop li')[to - 1].addClassName('on');
        },
        tab2go: function(to, go) {
            Init.Index.tab2(to);
            window.location = '/#' + go;
        },
        toJiBie: function(go) {
            Init.Index.tab2(4);
            window.location = '/jibie/#' + go;
        }
    },
    SetUserName: function(name) {
        Init.UserName = name;
    }
};
var ZeroClipboard = {

    version: "1.0.4",
    clients: {}, // registered upload clients on page, indexed by id
    moviePath: 'ZeroClipboard.swf', // URL to movie
    nextId: 1, // ID of next movie
    $: function(thingy) {
        // simple DOM lookup utility function
        if (typeof (thingy) == 'string') thingy = document.getElementById(thingy);
        if (!thingy.addClass) {
            // extend element with a few useful methods
            thingy.hide = function() { this.style.display = 'none'; };
            thingy.show = function() { this.style.display = ''; };
            thingy.addClass = function(name) { this.removeClass(name); this.className += ' ' + name; };
            thingy.removeClass = function(name) {
                this.className = this.className.replace(new RegExp("\\s*" + name + "\\s*"), " ").replace(/^\s+/, '').replace(/\s+$/, '');
            };
            thingy.hasClass = function(name) {
                return !!this.className.match(new RegExp("\\s*" + name + "\\s*"));
            }
        }
        return thingy;
    },
    setMoviePath: function(path) {
        // set path to ZeroClipboard.swf
        this.moviePath = path;
    },
    dispatch: function(id, eventName, args) {
        // receive event from flash movie, send to client		
        var client = this.clients[id];
        if (client) {
            client.receiveEvent(eventName, args);
        }
    },
    register: function(id, client) {
        // register new client to receive events
        this.clients[id] = client;
    },
    getDOMObjectPosition: function(obj) {
        // get absolute coordinates for dom element
        var info = {
            left: 0,
            top: 0,
            width: obj.width ? obj.width : obj.offsetWidth,
            height: obj.height ? obj.height : obj.offsetHeight
        };

        while (obj) {
            info.left += obj.offsetLeft;
            info.top += obj.offsetTop;
            obj = obj.offsetParent;
        }

        return info;
    },
    Client: function(elem) {
        // constructor for new simple upload client
        this.handlers = {};

        // unique ID
        this.id = ZeroClipboard.nextId++;
        this.movieId = 'ZeroClipboardMovie_' + this.id;

        // register client with singleton to receive flash events
        ZeroClipboard.register(this.id, this);

        // create movie
        if (elem) this.glue(elem);
    }
};
ZeroClipboard.Client.prototype = {

    id: 0, // unique ID for us
    ready: false, // whether movie is ready to receive events or not
    movie: null, // reference to movie object
    clipText: '', // text to copy to clipboard
    handCursorEnabled: true, // whether to show hand cursor, or default pointer cursor
    cssEffects: true, // enable CSS mouse effects on dom container
    handlers: null, // user event handlers

    glue: function(elem) {
        // glue to DOM element
        // elem can be ID or actual DOM element object
        this.domElement = ZeroClipboard.$(elem);

        // float just above object, or zIndex 99 if dom element isn't set
        var zIndex = 101;
        if (this.domElement.style.zIndex) {
            zIndex = parseInt(this.domElement.style.zIndex) + 1;
        }

        // find X/Y position of domElement
        var box = ZeroClipboard.getDOMObjectPosition(this.domElement);

        // create floating DIV above element
        this.div = document.createElement('div');
        var style = this.div.style;
        style.position = 'absolute';
        style.left = '' + box.left + 'px';
        style.top = '' + box.top + 'px';
        style.width = '' + box.width + 'px';
        style.height = '' + box.height + 'px';
        style.zIndex = zIndex;

        // style.backgroundColor = '#f00'; // debug

        var body = document.getElementsByTagName('body')[0];
        body.appendChild(this.div);

        this.div.innerHTML = this.getHTML(box.width, box.height);
    },

    getHTML: function(width, height) {
        // return HTML for movie
        var html = '';
        var flashvars = 'id=' + this.id +
			'&width=' + width +
			'&height=' + height;

        if (navigator.userAgent.match(/MSIE/)) {
            // IE gets an OBJECT tag
            var protocol = location.href.match(/^https/i) ? 'https://' : 'http://';
            html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="' + protocol + 'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + width + '" height="' + height + '" id="' + this.movieId + '" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="' + ZeroClipboard.moviePath + '" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="' + flashvars + '"/><param name="wmode" value="transparent"/></object>';
        }
        else {
            // all other browsers get an EMBED tag
            html += '<embed id="' + this.movieId + '" src="' + ZeroClipboard.moviePath + '" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="' + this.movieId + '" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="' + flashvars + '" wmode="transparent" />';
        }
        return html;
    },

    hide: function() {
        // temporarily hide floater offscreen
        if (this.div) {
            this.div.style.left = '-2000px';
        }
    },

    show: function() {
        // show ourselves after a call to hide()
        this.reposition();
    },

    destroy: function() {
        // destroy control and floater
        if (this.domElement && this.div) {
            this.hide();
            this.div.innerHTML = '';

            var body = document.getElementsByTagName('body')[0];
            try { body.removeChild(this.div); } catch (e) { ; }

            this.domElement = null;
            this.div = null;
        }
    },

    reposition: function(elem) {
        // reposition our floating div, optionally to new container
        // warning: container CANNOT change size, only position
        if (elem) {
            this.domElement = ZeroClipboard.$(elem);
            if (!this.domElement) this.hide();
        }

        if (this.domElement && this.div) {
            var box = ZeroClipboard.getDOMObjectPosition(this.domElement);
            var style = this.div.style;
            style.left = '' + box.left + 'px';
            style.top = '' + box.top + 'px';
        }
    },

    setText: function(newText) {
        // set text to be copied to clipboard
        this.clipText = newText;
        if (this.ready) this.movie.setText(newText);
    },

    addEventListener: function(eventName, func) {
        // add user event listener for event
        // event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
        eventName = eventName.toString().toLowerCase().replace(/^on/, '');
        if (!this.handlers[eventName]) this.handlers[eventName] = [];
        this.handlers[eventName].push(func);
    },

    setHandCursor: function(enabled) {
        // enable hand cursor (true), or default arrow cursor (false)
        this.handCursorEnabled = enabled;
        if (this.ready) this.movie.setHandCursor(enabled);
    },

    setCSSEffects: function(enabled) {
        // enable or disable CSS effects on DOM container
        this.cssEffects = !!enabled;
    },

    receiveEvent: function(eventName, args) {
        // receive event from flash
        eventName = eventName.toString().toLowerCase().replace(/^on/, '');

        // special behavior for certain events
        switch (eventName) {
            case 'load':
                // movie claims it is ready, but in IE this isn't always the case...
                // bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
                this.movie = document.getElementById(this.movieId);
                if (!this.movie) {
                    var self = this;
                    setTimeout(function() { self.receiveEvent('load', null); }, 1);
                    return;
                }

                // firefox on pc needs a "kick" in order to set these in certain cases
                if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) {
                    var self = this;
                    setTimeout(function() { self.receiveEvent('load', null); }, 100);
                    this.ready = true;
                    return;
                }

                this.ready = true;
                this.movie.setText(this.clipText);
                this.movie.setHandCursor(this.handCursorEnabled);
                break;

            case 'mouseover':
                if (this.domElement && this.cssEffects) {
                    this.domElement.addClass('hover');
                    if (this.recoverActive) this.domElement.addClass('active');
                }
                break;

            case 'mouseout':
                if (this.domElement && this.cssEffects) {
                    this.recoverActive = false;
                    if (this.domElement.hasClass('active')) {
                        this.domElement.removeClass('active');
                        this.recoverActive = true;
                    }
                    this.domElement.removeClass('hover');
                }
                break;

            case 'mousedown':
                if (this.domElement && this.cssEffects) {
                    this.domElement.addClass('active');
                }
                break;

            case 'mouseup':
                if (this.domElement && this.cssEffects) {
                    this.domElement.removeClass('active');
                    this.recoverActive = false;
                }
                break;
        } // switch eventName

        if (this.handlers[eventName]) {
            for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) {
                var func = this.handlers[eventName][idx];

                if (typeof (func) == 'function') {
                    // actual function reference
                    func(this, args);
                }
                else if ((typeof (func) == 'object') && (func.length == 2)) {
                    // PHP style object + method, i.e. [myObject, 'myMethod']
                    func[0][func[1]](this, args);
                }
                else if (typeof (func) == 'string') {
                    // name of function
                    window[func](this, args);
                }
            } // foreach event handler defined
        } // user defined handler for event
    }

};
var Bubble = {
    gBubblePos: new Array(),
    initialize: function() {
        Bubble.gBubblePos[0] = "159,11#20,70#109,126#5,2#96,4#177,143#8,149#101,75#166,99#64,146";
        Bubble.gBubblePos[0] = "28,64#131,195#92,113#8,205#100,16#9,7#162,38#19,152#163,141#84,192";
        Bubble.gBubblePos[1] = "10,131#78,84#103,8#143,135#85,192#31,22#159,69#14,215#7,83#155,214";
        Bubble.gBubblePos[2] = "55,122#136,93#83,26#36,202#154,8#23,4#118,179#17,75#9,151#165,222";
        Bubble.gBubblePos[3] = "3,72#104,83#81,10#43,205#152,20#16,7#143,164#60,142#12,160#156,219";
        Bubble.gBubblePos[4] = "11,71#140,196#98,75#41,203#149,28#10,7#92,11#18,152#150,141#83,149";
        Bubble.gBubblePos[5] = "20,70#140,196#89,124#13,205#99,47#10,7#162,17#10,152#165,119#90,193";
        Bubble.gBubblePos[6] = "10,63#138,165#78,119#22,205#104,50#48,5#162,23#6,149#166,99#90,204";
        Bubble.gBubblePos[7] = "8,22#137,185#58,136#9,199#103,77#87,11#160,13#5,104#163,120#85,222";
        Bubble.gBubblePos[8] = "37,35#124,193#51,136#5,188#110,95#106,8#163,49#7,97#166,145#72,225";
        Bubble.gBubblePos[9] = "54,56#119,196#53,177#7,126#123,106#148,38#86,2#4,18#168,154#4,226";
        Bubble.gBubblePos[10] = "4,54#127,118#85,201#31,148#156,209#97,23#4,213#82,95#165,70#28,1";
        Bubble.gBubblePos[11] = "9,58#138,99#87,168#11,145#152,208#85,13#33,216#83,111#162,36#29,5";
        Bubble.gBubblePos[12] = "13,51#138,108#91,184#22,145#157,211#90,22#11,214#83,103#172,34#13,2";
        Bubble.gBubblePos[13] = "7,51#139,87#90,165#23,135#153,210#90,14#20,212#85,87#160,34#37,3";
        Bubble.gBubblePos[14] = "5,58#140,56#110,138#26,140#138,209#71,10#52,221#85,90#142,9#16,3";
        Bubble.gBubblePos[15] = "4,75#140,61#131,137#15,159#150,210#78,49#72,212#78,124#132,13#23,22";
        Bubble.gBubblePos[16] = "10,78#139,49#141,132#8,168#155,204#72,38#86,207#83,128#125,6#10,15";
        Bubble.gBubblePos[17] = "3,105#80,66#148,107#76,149#154,194#64,5#97,217#16,215#138,6#10,45";
        Bubble.gBubblePos[18] = "3,105#111,121#148,53#19,187#154,191#57,5#98,206#77,84#132,6#14,50";
        Bubble.gBubblePos[19] = "3,113#103,112#148,49#21,198#154,185#34,3#96,195#68,71#107,23#10,63";
        Bubble.gBubblePos[20] = "11,118#133,11#106,150#73,65#151,210#19,14#90,218#157,103#2,75#29,206";
        Bubble.gBubblePos[21] = "5,118#122,8#113,146#73,77#154,206#36,5#83,218#158,90#12,68#20,206";
        Bubble.gBubblePos[22] = "12,127#114,5#98,145#68,68#153,194#36,11#77,211#146,92#4,66#20,214";
        Bubble.gBubblePos[23] = "15,138#97,2#134,127#76,88#139,200#29,21#77,219#162,67#6,89#12,226";
        Bubble.gBubblePos[24] = "23,138#88,2#142,115#77,85#145,187#16,22#84,217#163,60#6,100#21,226";
        Bubble.gBubblePos[25] = "19,149#80,2#148,104#79,85#150,179#10,25#103,217#163,43#7,104#51,226";
        Bubble.gBubblePos[26] = "2,156#73,6#142,89#64,113#152,166#10,28#109,217#151,24#7,104#59,226";
        Bubble.gBubblePos[27] = "81,152#60,3#107,74#16,110#155,144#4,46#149,215#144,14#4,186#51,225";
        Bubble.gBubblePos[28] = "88,169#44,4#96,71#5,162#156,122#9,74#160,208#134,14#75,130#58,225";
        Bubble.gBubblePos[29] = "92,162#36,5#104,68#3,170#157,131#9,83#161,213#124,11#69,125#58,227";
        Bubble.gBubblePos[30] = "13,71#140,188#89,123#19,205#92,38#26,3#155,11#7,152#159,107#90,202";
        Bubble.gBubblePos[31] = "13,79#140,174#88,113#21,207#87,26#18,14#152,24#4,158#159,94#95,211";
        Bubble.gBubblePos[32] = "15,79#134,166#93,100#25,204#76,15#7,14#150,18#7,156#158,80#83,169";
        Bubble.gBubblePos[33] = "4,90#142,138#95,65#15,184#65,6#3,10#141,6#73,147#168,70#122,207";
        Bubble.gBubblePos[34] = "5,96#140,111#80,65#22,195#58,2#3,34#134,6#86,168#167,54#147,207";
        Bubble.gBubblePos[35] = "3,110#138,109#75,70#27,198#50,3#3,44#124,8#95,179#168,47#168,207";
        Bubble.gBubblePos[36] = "2,122#138,102#70,71#27,205#44,1#3,54#118,9#103,183#168,43#168,196";
        Bubble.gBubblePos[37] = "30,133#138,88#71,58#10,206#33,2#6,71#113,4#116,173#165,33#170,202";
        Bubble.gBubblePos[38] = "7,144#139,94#73,63#71,205#23,3#6,75#102,5#94,153#171,38#158,194";
        Bubble.gBubblePos[39] = "2,160#133,95#64,52#81,205#10,16#9,87#120,10#84,145#164,47#163,186";
        Bubble.gBubblePos[40] = "29,65#140,186#97,112#19,204#90,28#4,7#161,35#5,145#171,108#87,187";
        Bubble.gBubblePos[41] = "34,62#136,186#108,110#19,204#90,17#3,11#161,20#13,145#170,92#87,175";
        Bubble.gBubblePos[42] = "35,72#136,173#114,101#21,204#70,3#3,18#147,9#12,149#167,69#85,177";
        Bubble.gBubblePos[43] = "26,72#128,175#116,101#42,204#76,4#6,12#150,6#9,160#166,64#71,151";
        Bubble.gBubblePos[44] = "16,76#137,152#104,81#58,204#72,13#4,5#140,6#2,168#166,54#84,152";
        Bubble.gBubblePos[45] = "7,118#137,166#95,72#71,204#60,16#7,54#133,4#5,206#169,48#93,150";
        Bubble.gBubblePos[46] = "10,118#138,144#95,57#85,197#51,7#12,55#127,4#10,205#169,43#89,134";
        Bubble.gBubblePos[47] = "6,124#139,139#95,63#89,200#48,7#11,62#117,4#21,212#170,52#89,144";
        Bubble.gBubblePos[48] = "7,127#139,129#85,63#111,201#36,7#3,62#112,4#27,220#165,45#89,144";
        Bubble.gBubblePos[49] = "7,145#139,108#73,62#130,201#26,8#3,76#110,4#51,217#165,41#89,146";
        Bubble.gBubblePos[50] = "89,157#40,4#109,63#5,155#156,119#12,88#160,201#124,6#72,120#61,223";
        Bubble.gBubblePos[51] = "94,151#20,5#99,64#6,162#155,105#8,86#160,210#110,6#68,120#70,223";
        Bubble.gBubblePos[52] = "110,126#12,5#79,58#8,170#154,65#4,99#160,197#98,2#65,134#84,217";
        Bubble.gBubblePos[53] = "119,125#3,25#76,60#10,190#154,47#4,119#161,215#88,3#67,144#95,211";
        Bubble.gBubblePos[54] = "122,121#3,39#81,62#13,201#148,24#4,129#146,205#82,3#68,133#86,197";
        Bubble.gBubblePos[55] = "135,102#3,45#82,55#16,199#144,9#10,131#144,192#66,3#76,128#89,184";
        Bubble.gBubblePos[56] = "135,91#3,60#79,47#28,203#136,8#1,145#158,184#42,4#82,128#97,179";
        Bubble.gBubblePos[57] = "135,87#2,69#77,41#47,202#143,9#2,154#159,174#34,5#71,128#106,167";
        Bubble.gBubblePos[58] = "136,69#2,81#62,34#63,203#132,4#6,176#161,181#9,9#84,117#113,165";
        Bubble.gBubblePos[59] = "137,82#3,86#69,26#87,197#143,4#6,189#150,173#6,21#64,145#89,101";
        Bubble.gBubblePos[60] = "17,126#143,128#80,82#13,204#44,7#5,62#112,9#85,193#163,49#139,218";
        Bubble.gBubblePos[61] = "13,126#138,128#87,75#13,204#39,6#5,59#108,14#86,182#163,42#143,218";
        Bubble.gBubblePos[62] = "6,126#138,107#79,67#43,205#35,4#12,60#101,8#90,150#163,25#164,192";
        Bubble.gBubblePos[63] = "5,140#142,105#84,63#49,205#20,9#5,72#91,8#93,160#152,15#151,192";
        Bubble.gBubblePos[64] = "2,146#137,102#74,66#55,205#9,9#5,82#82,8#93,153#144,16#143,191";
        Bubble.gBubblePos[65] = "2,152#138,74#68,69#61,204#5,20#5,91#73,8#95,146#136,12#156,192";
        Bubble.gBubblePos[66] = "1,157#138,68#68,72#70,203#4,26#5,95#68,8#106,146#130,12#162,189";
        Bubble.gBubblePos[67] = "5,171#137,56#66,72#94,197#4,35#5,102#61,8#114,139#123,13#162,186";
        Bubble.gBubblePos[68] = "15,188#141,40#73,66#103,200#4,45#27,121#54,8#136,129#114,8#173,183";
        Bubble.gBubblePos[69] = "30,180#135,32#73,71#111,202#5,52#3,129#44,6#108,140#99,14#167,147";
        Bubble.gBubblePos[70] = "7,123#138,142#94,57#78,204#48,3#10,54#133,5#17,208#169,60#93,133";
        Bubble.gBubblePos[71] = "9,131#138,131#90,53#93,200#36,3#4,61#127,5#20,216#168,51#89,129";
        Bubble.gBubblePos[72] = "4,132#139,117#73,51#103,199#19,6#4,70#115,6#39,214#168,44#88,137";
        Bubble.gBubblePos[73] = "6,137#132,96#68,51#121,197#15,6#3,75#110,5#44,214#168,22#91,141";
        Bubble.gBubblePos[74] = "5,163#132,96#60,52#147,186#7,13#3,86#96,3#83,220#159,25#95,155";
        Bubble.gBubblePos[75] = "6,171#131,91#66,65#145,184#5,23#4,91#84,4#87,217#157,16#88,160";
        Bubble.gBubblePos[76] = "6,184#135,88#66,74#141,180#4,28#4,103#75,7#90,217#147,16#84,160";
        Bubble.gBubblePos[77] = "8,188#140,84#66,80#145,176#2,39#5,111#69,7#94,217#142,17#93,161";
        Bubble.gBubblePos[78] = "12,187#140,78#68,69#147,167#16,31#11,111#76,7#97,216#149,14#86,159";
        Bubble.gBubblePos[79] = "20,190#141,74#62,78#147,178#11,27#3,118#81,7#101,213#153,11#94,151";
        Bubble.gBubblePos[80] = "20,183#139,62#68,69#112,202#9,26#92,139#75,11#6,113#133,7#164,164";
        Bubble.gBubblePos[81] = "21,196#139,52#63,75#130,198#5,37#99,139#68,11#9,121#131,7#165,151";
        Bubble.gBubblePos[82] = "32,191#133,48#63,68#140,198#6,49#108,132#50,9#10,132#117,7#172,141";
        Bubble.gBubblePos[83] = "15,79#134,166#93,100#25,204#76,15#7,14#150,18#7,156#158,80#83,169";
        Bubble.gBubblePos[84] = "5,94#135,195#88,69#34,204#143,132#7,14#150,14#78,152#168,83#81,20";
        Bubble.gBubblePos[85] = "5,102#137,182#87,53#43,201#144,112#7,36#139,1#88,139#168,67#60,7";
        Bubble.gBubblePos[86] = "4,121#137,166#82,45#60,195#148,100#7,50#125,3#91,124#168,51#52,7";
        Bubble.gBubblePos[87] = "3,147#137,160#68,51#70,201#148,86#5,75#115,6#91,129#168,35#22,11";
        Bubble.gBubblePos[88] = "3,157#138,145#49,40#76,199#122,81#5,87#108,6#82,129#166,35#11,11";
        Bubble.gBubblePos[89] = "4,179#137,149#43,40#83,198#136,75#4,101#108,13#77,128#167,17#3,20";
        Bubble.gBubblePos[90] = "5,62#141,159#70,121#29,200#98,53#56,4#148,13#3,149#158,80#106,222";
        Bubble.gBubblePos[91] = "4,55#133,159#62,119#14,198#97,59#63,4#155,20#3,141#160,99#91,221";
        Bubble.gBubblePos[92] = "4,49#133,165#62,125#18,197#103,65#70,5#159,25#5,133#165,117#90,222";
        Bubble.gBubblePos[93] = "4,39#129,171#59,126#8,189#103,70#89,5#159,40#5,127#160,111#85,222";
        Bubble.gBubblePos[94] = "16,33#131,179#69,135#7,184#96,71#95,4#159,31#5,118#164,116#76,225";
        Bubble.gBubblePos[95] = "18,13#133,171#63,133#2,170#88,71#101,7#159,39#6,107#153,105#66,227";
        Bubble.gBubblePos[96] = "23,13#124,189#71,138#3,167#106,81#107,3#161,54#19,106#168,133#50,228";
        Bubble.gBubblePos[97] = "26,8#133,200#73,147#2,167#91,77#114,4#161,60#10,91#156,135#60,225";
        Bubble.gBubblePos[98] = "36,8#130,197#77,147#1,157#85,77#120,3#164,67#5,86#149,135#53,225";
        Bubble.gBubblePos[99] = "35,7#130,192#74,154#5,146#76,82#120,11#164,73#12,83#154,143#41,225";
    },
    putIn: function() {
        this.initialize();
        var bubbleList = new Array();
        var circle = $("popo");
        if (circle != null) {
            var nodes = circle.childNodes;
            if (nodes.length == 0 && $("popo").up('div', 0)) {
                $("popo").up('div', 0).hide();
                return;
            }
            for (var j = 0; j < nodes.length; j++) {
                if (nodes[j].nodeName.toLowerCase() == "div") {
                    bubbleList.push(nodes[j]);
                }
            }
        }

        var colorlist = new Array(1, 2, 3, 4, 5);
        colorlist.sort(function() { return Math.random() > 0.5 ? -1 : 1; });

        var randomIndex = Math.round(Math.random() * Bubble.gBubblePos.length);
        var dataline = Bubble.gBubblePos[randomIndex];
        var coorList = dataline.split("#");
        for (var i = 0; i < coorList.length; i++) {
            var coors = coorList[i].split(",");
            var id = i + 1;
            var circle = bubbleList[i];
            if (circle != null) {
                var left = parseInt(coors[0]);
                var top = parseInt(coors[1]);
                circle.style.top = top + "px";
                circle.style.left = left + "px";
                circle.style.display = "block";
                var classValue = "popo" + colorlist[parseInt(i / 2)] + "_" + parseInt((11 - i) / 2); 	//popo1_1
                circle.className = classValue;
            }
        }
    }
}
/**
* @Copyright (c) 2009 
* @All rights reserved.
*
* @file_name   login.js
* @version     1.0
* @author      李志东
* @date        2009-2-6 16:04:40
*/
/**
* Class and Function List:
* Function list:
* - initialize : function(id, msg, state)
* - createDiv : function()
* - removeDiv : function()
* - loginCheck : function()
* Classes list:
* - .Login
*/
var Login = {
    boxid: "login_register",
    onComplete: function() { }, 				//登录完毕后事件处理
    createDiv: function() {
        Login.flag = true;
        form = $('reviewform');
        if ($("login_register")) {
            $("login_register").style.position = util.navigator.ie6 ? 'absolute' : 'fixed';
            $("login_register").style.top = util.navigator.ie6 ? (document.documentElement.scrollTop + screen.availHeight * 0.3 - 100 + 'px') : '30%';
            $("login_register").style.left = '50%';
            $("login_register").style.marginLeft = '-158px';
            $("login_register").show();

            Login.showOverlay();
            Login.removeMsg();

            if (util.navigator.ie6)
                window.onscroll = function() { $("login_register").style.top = document.documentElement.scrollTop + screen.availHeight * 0.3 - 100 + 'px' }
        }
    },
    removeMsg: function() { $$(".error").each(function(e) { e.hide() }) },
    loginCheck: function() { },
    showOverlay: function() {
        overlay = new Element('div', { 'id': 'overlay', 'style': 'position:absolute; top:0; left:0; width:100%; height:100%; z-index:10000000; background-color:#000; -moz-opacity: 0.4; opacity:.40; filter: alpha(opacity=40);' });
        overlay.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + 'px';
        $$("body")[0].appendChild(overlay);
    },
    hideOverlay: function() { $('overlay').remove(); }
};
function addTag(tag) {
    var _strtagvalue = $('contenttags').value;
    _strtagvalue = _strtagvalue.length > 50 ? _strtagvalue.substring(0, 50) : _strtagvalue;
    var _tags = _strtagvalue.split(/\s+/);
    _strtagvalue.split(/\s+/).without(tag).length != _tags.length ? $('contenttags').value = _tags.join(' ') : $('contenttags').value = (_tags.join(' ') + ' ' + tag).strip();
};

var Topic = {
    ratingarr: ["very_p", "poor", "general", "basic", "very"],
    ratingdata: { very_p: { v: 2, n: '非常差' }, poor: { v: 4, n: '差' }, general: { v: 6, n: '一般' }, basic: { v: 8, n: '满意' }, very: { v: 10, n: '非常满意'} },
    ratingno: $('general'),
    newRatingFold: function() {
        $$(".ass em").each(function(em) {
            em.onclick = function() {
                $("rating").value = eval('Topic.ratingdata.' + this.id + ".v");
                Topic.ratingno = this;
            };

            em.observe('mouseover', function() {
                Topic.ratingTo(this);
            });

            em.observe('mouseout', function() {
                Topic.ratingTo(Topic.ratingno);
            });
        });
    },
    ratingTo: function(e) {
        e = e == null ? $('general') : e;
        $$(".ass em").each(function(eitem) {
            eitem.className = '';
        });

        e.className = 'layer_top';

        for (var i = 0; i < Topic.ratingarr.length; i++) {
            if (Topic.ratingarr[i] != e.id)
                $(Topic.ratingarr[i]).className = 'layer_top';
            else
                break;
        }
        $("pingjia").update(eval('Topic.ratingdata.' + e.id + ".n"));
        $("pingjia").className = e.id;
    },
    getTopicList: function(page, top, type, id) {
        new Ajax.Request(xpath + "Common/Ajax.ashx", { parameters: "model_id=" + id + "&t=gettopiclistbytype&p=" + page + "&s=" + top + "&type=" + type, onLoading: function(request) { util.loading(Event.element(evnt)) }, onLoaded: function(request) { util.loaded(); } });
    },
    createInit: function() {
        this.title = '';
        this.content = '';
        this.form = $('reviewform');
        this.errcount = 0;
        this.checkflag = false;
        this.contentErrMsgbox = $('contentErrMsg');
        this.titleErrMsgbox = $('titleErrMsg');

        Topic.ratingTo($(Topic.ratingarr[eval($F("rating")) / 2 - 1]));

        $('content').observe('blur', function(evnt) { new Ajax.Request(xpath + 'Common/Ajax.ashx', { parameters: { 't': 'gettags', 'content': encodeURI(this.value) }, method: 'post' }); });
        $('content').observe('keyup', function(evnt) {
            if (this.value.length > 2000) {
                this.value = this.value.truncate(2000)
            };
            if (this.value.length >= 30) { $('contentErrMsg').className = 'tips'; $('contentErrMsg').update('<strong>\u60A8\u8FD8\u53EF\u4EE5\u8F93\u5165<em>' + (2000 - this.value.length) + '</em>\u4E2A\u5B57\u7B26</strong>'); $('contentErrMsg').show(); }
            else
                Topic.checkContent();
        });
        $("title").observe('keyup', function(evnt) { Topic.checkTitle(); });
        $('postbutton').observe('click', function(evnt) { new Ajax.Request(xpath + 'Common/Ajax.ashx', { parameters: { 't': 'getusername', 'rnd': Math.random() }, method: 'get', onComplete: function() { Topic.submit(); } }); evnt.stop(); });
    },
    formcheck: function() {
        this.clear();
        this.checkTitle();
        this.checkContent();
        this.checkflag = this.errcount == 0;
    },
    clear: function() {
        this.errcount = 0;
        this.contentErrMsgbox.innerHTML = '';
        this.titleErrMsgbox.innerHTML = '';
        Element.hide(this.contentErrMsgbox, this.titleErrMsgbox);
    },
    checkContent: function() {
        this.content = $('content').value.strip();
        if (this.content.length < 30) { this.contentErrMsgbox.className = 'error'; this.contentErrMsgbox.update('<strong>\u8BC4\u4EF7\u8FD8\u9700\u8981\u8F93\u5165<em>' + (30 - this.content.length) + '</em>\u4E2A\u5B57</strong>'); this.contentErrMsgbox.show(); this.errcount++; }
        else { this.contentErrMsgbox.hide(); this.contentErrMsgbox.innerHTML = ''; }
    },
    checkTitle: function() {
        this.title = $('title').value;
        if (this.title) {
            if (!this.regexp('^.{1,30}$', this.title)) { this.titleErrMsgbox.innerHTML = '<strong>\u6807\u9898\u4E0D\u80FD\u8D85\u8FC730\u5B57</strong>'; this.titleErrMsgbox.show(); this.errcount++; }
            else { this.titleErrMsgbox.hide() }
        }
        else {
            this.titleErrMsgbox.className = 'error';
            this.titleErrMsgbox.innerHTML = '<strong>\u8BF7\u7ED9\u4F60\u7684\u70B9\u8BC4\u8D77\u4E00\u4E2A\u6807\u9898</strong>'; this.titleErrMsgbox.show(); this.errcount++;
        }
    },
    regexp: function(reg, str) {
        var re = new RegExp(reg);
        return re.test(str);
    },
    submit: function() {
        Topic.formcheck();
        if (Topic.checkflag) {
            if (!Init.UserName) {
                Login.createDiv();
                return;
            }
            $('postbutton').disabled = true;
            $('postbutton').className = 'box5_no';
            this.form.submit();
            Topic.updating = false;
        }
    },
    edit: function(element) {
        dd = $(element).up('dl').down('dd');
        if (dd.edit == null || dd.edit == false) {
            dd.edit = true;
            dd.className = 'edit';
            ta = new Element('textarea');
            if (dd.getHeight() > 53)
                ta.style.height = (dd.getHeight() + 40) + "px";
            this.postcontent = dd.innerHTML;
            ta.value = dd.innerHTML.gsub(/<\/p><p>/i, '\r\n').gsub(/<p>/i, '').gsub(/<\/p>/i, '');
            dd.innerHTML = '';
            dd.insert(ta, { 'position': 'bottom' });
            btn = new Element('input', { 'value': '提交回应', 'type': 'button' });
            cancel = new Element('input', { 'value': '取消修改', 'type': 'button' });
            dd.insert(btn, { 'position': 'bottom' });
            dd.insert(cancel, { 'position': 'bottom' });
            cancel.observe('click', function(evnt) { Topic.cancelEdit(Event.element(evnt)) });
            pid = dd.up('li').id;
            btn.observe('click', function(evnt) {
                new Ajax.Request(xpath + 'posts/edit.ashx', { parameters: 'post_id=' + pid + '&content=' + ta.value, onLoading: function(request) { util.loading(Event.element(evnt)) }, onLoaded: function(request) { util.loaded(); } });
            });
        }

    },
    cancelEdit: function(element) {
        dd = element.up('dd');
        ta = dd.down('textarea');
        dd.innerHTML = this.postcontent;
        dd.className = '';
        dd.edit = false;
    },
    renderCookieHelper: function(str) {
        div = new Element('div', { 'style': 'display:none;' }).update(str);
        $$('body')[0].insert(div, { 'position': 'bottom' });
    },
    updating: true,
    updateList: function() {
        new PeriodicalExecuter(function(pe) {
            if (Topic.updating == true) {
                Topic.updating = false;
                var review_id = $$('div.main_review1_010')[0].id;
                var count = $$('div.main_review1_011')[0].select('li').length;
                var s = document.createElement("script");
                s.src = xpath + 'posts/list.ashx?name=' + util.readCookie("TempUserName") + '&review_id=' + review_id + '&count=' + count;
                $$('.body')[0].insert(s);
            } 
        }, 2);
    }
};


var Impression = {
    cacheWord: "",
    modelID: 0,
    t: null,
    heightArr: [[14, 10, 5, 8, 15], [65, 60, 67, 63, 74], [125, 128, 117, 119, 132]],
    colorArr: [[2, 1, 7, 3, 7], [5, 4, 8, 9, 9], [6, 3, 3, 2, 1]],
    iCountArr: [0, 0, 0],
    iNextWith: [8, 8, 8],
    i: 0,
    wordList: [".tages_li div a", ".eyes_ofusers li a", "#marqueey a"],
    clear: function() { Impression.iCountArr = [0, 0, 0]; Impression.iNextWith = [8, 8, 8] },
    putIn: function() {
        var i = 0;
        var j = 0;
        $$("div.tages_li div").each(function(d) {
            while (Impression.iCountArr[i] == 5) {
                ++i;
            }
            if (j == 5) {
                j = 0;
            }
            d.className = 'color' + Impression.colorArr[i][j];

            d.show();
            d.style.left = Impression.iNextWith[i] + "px";
            d.style.top = Impression.heightArr[i][j] + "px";

            Impression.iNextWith[i] = eval(d.style.left.replace("px", "")) + eval(d.clientWidth) + 5;
            Impression.iCountArr[i]++;

            j++;
        });
        Impression.Marquee2.init();
        Impression.bindWord();
    },
    Marquee2: {
        marqueeyHeight: 22,
        preTop: 0,
        currentTop: 0,
        stopscroll: false,
        init: function() {
            if ($('marqueey').select('li').length > 1) {
                with ($('marqueey')) {
                    style.height = Impression.Marquee2.marqueeyHeight + "px";
                    style.overflowX = "hidden";
                    style.overflowY = "hidden";
                    noWrap = true;
                    onmouseover = new Function("Impression.Marquee2.stopscroll=true");
                    onmouseout = new Function("Impression.Marquee2.stopscroll=false");
                }


                $('templayer').innerHTML = "";
                while ($('templayer').offsetHeight < Impression.Marquee2.marqueeyHeight) {
                    $('templayer').innerHTML += $('marqueey').innerHTML;
                    if ($('templayer').offsetHeight == 0) { break; }
                }
                $('marqueey').innerHTML = $('templayer').innerHTML + $('templayer').innerHTML;
                $('keyword').value = '不多于5个字';
            }
        },
        scrollUp: function() {
            if (Impression.Marquee2.stopscroll) return;
            Impression.Marquee2.preTop = $('marqueey').scrollTop;
            $('marqueey').scrollTop += 1;
            if (Impression.Marquee2.preTop == $('marqueey').scrollTop) {
                $('marqueey').scrollTop = $('templayer').offsetHeight - Impression.Marquee2.marqueeyHeight;
                $('marqueey').scrollTop += 1;
            }
            if (Impression.Marquee2.preTop % (Impression.Marquee2.marqueeyHeight - 2) == 0) {
                Impression.Marquee2.stopscroll = true;
                setTimeout(function() { Impression.Marquee2.stopscroll = false; Impression.Marquee2.scrollUp(); }, 4000);
            }
        }
    },
    m_1: null,
    m_2: { top: 0, left: 0 },
    showMessage: function(msg, e) {
        if (Impression.m_1 != null && Impression.m_1.parentNode != null) Impression.m_1.remove();
        Impression.m_1 = new Element('div', { 'class': 'msg', 'style': 'position:absolute;', 'id': 'msg' });
        $$('body')[0].insert(Impression.m_1);
        $(Impression.m_1).innerHTML = "<span>" + msg + "</span><a onclick='$(this).up(\"div\").hide();'>关闭</a>";

        Impression.m_1.style.top = Impression.m_2.top + 'px';
        Impression.m_1.style.left = Impression.m_2.left + 'px';


        Impression.m_1.show();
        setTimeout(function() { try { Impression.m_1.fade() } catch (e) { Impression.m_1.hide() } }, 2000);
    },
    addImpression: function(e) {
        var word = e.innerHTML ? e.innerHTML : e.value;
        Impression.m_2.top = (util.position(e)[0] + e.getHeight());
        Impression.m_2.left = (util.position(e)[1]);

        if (word.strip().length == 0 || word == "不多于5个字") { Impression.showMessage('印象总得填一个吧-_-!', e); return; }
        if (word.length > 5) { return; }

        new Ajax.Request(xpath + "Common/Ajax.ashx", { parameters: { "model_id": Impression.modelID, "t": "addimpression", "word": encodeURI(word), "msg": 'msg' }, onLoading: function(request) { util.loading(e) }, onLoaded: function(request) { util.loaded(); }, onComplete: function() { Impression.bindWord(); } });

        return false;
    },
    bindWord: function() {
        for (var i = 0; i < Impression.wordList.length; i++) {
            $$(Impression.wordList[i]).each(function(a) {
                a.onclick = function(evnt) { Impression.addImpression(this); }
            });
        }
    }
};

var Common = {
    getBrandList: function(make) {
        if ($('brand')) { $('brand').update('<option>选择车型</option>'); }
        new Ajax.Request(xpath + "Common/Ajax.ashx", { parameters: { "make": make, "t": "getbrandlist" }, onLoading: function(request) { util.loading(Event.element(evnt)) }, onLoaded: function(request) { util.loaded(); } });
        if ($('car')) { $('car').update('<option>选择车款</option>'); }
    },
    getCarList: function(id) {
        new Ajax.Request(xpath + "Common/Ajax.ashx", { parameters: { "id": id, "t": "getcarlist" }, onLoading: function(request) { util.loading(Event.element(evnt)) }, onLoaded: function(request) { util.loaded(); } });

    }
};

var Fuel = {
    modelName: "",
    errer: 0,
    init: function() {
        $("make").observe("change", function() { Common.getBrandList(this.value); });
        $("brand").observe("change", function() { Common.getCarList(this.value); });
        $("car").observe("change", function() { Fuel.checkCar(); });

        $("city").observe("change", function() { Fuel.checkCity(); });

        $("value").observe("keyup", function() { this.value = this.value.replace(/[^\d\.]/ig, ""); });
        $("value").observe("blur", function() { Fuel.checkFuekValue() });

        $$('input[type="text"]').each(function(i) {
            i.observe("focus", function() { this.addClassName('onbg'); });
            i.observe("blur", function() { this.removeClassName('onbg'); });
        })

        if (Init.UserName == "") {
            $("check").observe("blur", function() { Fuel.checkCode() });
        }

        $('submit').observe('click', function() { window.onbeforeunload = null; });
    },
    editBreak: function() {
        $("fuelok").hide(); $("fuelwrite").show();
    },
    writeOk: function() {
        if (Fuel.errer > 0) return;

        $("fuelok").show(); $("fuelwrite").hide();
        $$("div.write_oil_ok li")[0].innerHTML = "<label>选车：</label>" + Fuel.modelName + $('car').item($('car').selectedIndex).innerHTML;
        $$("div.write_oil_ok li")[1].innerHTML = "<label>地区：</label>" + $('city').item($('city').selectedIndex).innerHTML;
        $$("div.write_oil_ok li")[2].innerHTML = "<label>油耗：</label>" + ($F('value').length > 4 ? $F('value').substring(0, 4) : $F('value')) + "L（百公里油耗）";
        $$("div.write_oil_ok li")[3].innerHTML = "<label>空调：</label>" + ($("isair").checked ? "开" : "关");
        $$("div.write_oil_ok li")[4].innerHTML = "<label>路况：</label>" + $('condition').item($('condition').selectedIndex).innerHTML;
        $$("div.write_oil_ok li")[5].innerHTML = "<label>用户名：</label>" + (Init.UserName != "" ? Init.UserName : $("anonymous").checked ? "易车网友" : $F("username"));
    },
    checkCar: function() {
        if ($F('car') == "选择车款") {
            $('carmsg').show(); Fuel.errer++;
        }
        else {
            $('carmsg').hide();
        }
    },
    checkCity: function() {
        if ($F('city') == "请选择地区") {
            $('citymsg').update('<strong>请选择地区</strong>');
            $('citymsg').show();
            Fuel.errer++;
        }
        else {
            $('citymsg').hide();
        }
    },
    checkFuekValue: function() {
        if ($F('value') != "") {
            var v = $F('value');
            if (eval(v) < 4 || eval(v) > 30) {
                $('valuemsg').update('<strong>您输入的油耗超出正常值范围.</strong>');
                $('valuemsg').show();
                Fuel.errer++;
            }
            else {
                $('valuemsg').hide();
            }
        }
        else {
            $('valuemsg').update('<strong>请输入油耗.</strong>');
            $('valuemsg').show();
            Fuel.errer++;
        }
    },
    checkCode: function(ok, page) {
        new Ajax.Request(xpath + "Common/Ajax.ashx", { parameters: { "t": "checkcode", "check": $F("check"), "ok": ok, "page": page }, onLoading: function(request) { util.loading(Event.element(evnt)) }, onLoaded: function(request) { util.loaded(); } });
    },
    checkUser: function(ok, page) {
        new Ajax.Request(xpath + "Common/Ajax.ashx", { parameters: { "t": "checkuserlogin", "username": $F("username"), "password": $F("password"), "ok": ok, 'page': page }, onLoading: function(request) { util.loading(Event.element(evnt)) }, onLoaded: function(request) { util.loaded(); } });
    },
    checkBegin: function() {
        Fuel.errer = 0;
        Fuel.checkCar();
        Fuel.checkCity();
        Fuel.checkFuekValue();
        if (!Init.UserName) $("anonymous").checked ? Fuel.checkCode(true) : Init.UserName == "" ? Fuel.checkUser(true, 'Fuel') : Fuel.writeOk();
        else Fuel.writeOk();
    },
    rankFold: function() {
        $$('.style_pie').each(function(d) {
            var lis = d.select('li');

            d.down('div', 1).show()

            for (var i = 0; i < lis.length; i++) {
                if (i == 0) {
                    lis[i].className = 'current';
                }
                lis[i].v = i;
                lis[i].onclick = function() {
                    var divs = $(this).up('div', 1).select('div.box');
                    for (var m = 0; m < divs.length; m++) {
                        m == eval(this.v) ? divs[m].show() : divs[m].hide();
                    }

                    var ls = $(this).up('ul').select('li');
                    for (var n = 0; n < ls.length; n++) {
                        n == eval(this.v) ? ls[n].className = 'current' : ls[n].className = '';
                    }
                }
            }
        });
    }
};

var Fee = {
    modelName: "",
    errer: 0,
    feecount: 0,
    init: function() {
        $("make").observe("change", function() { Common.getBrandList(this.value); });
        $("brand").observe("change", function() { Common.getCarList(this.value); });
        $("car").observe("change", function() { Fee.checkCar(); });

        $("city").observe("change", function() { Fee.checkCity(); });

        $("gasfee").observe("keyup", function() { this.value = this.value.replace(/[^\d\.]/ig, ""); });
        $("insurancefee").observe("keyup", function() { this.value = this.value.replace(/[^\d\.]/ig, ""); });
        $("fixfee").observe("keyup", function() { this.value = this.value.replace(/[^\d\.]/ig, ""); });
        $("fixcount").observe("keyup", function() { this.value = this.value.replace(/[^\d\.]/ig, ""); });
        $("parkingfee").observe("keyup", function() { this.value = this.value.replace(/[^\d\.]/ig, ""); });
        $("toll").observe("keyup", function() { this.value = this.value.replace(/[^\d\.]/ig, ""); });
        $("fine").observe("keyup", function() { this.value = this.value.replace(/[^\d\.]/ig, ""); });
        $("other").observe("keyup", function() { this.value = this.value.replace(/[^\d\.]/ig, ""); });


        $("gasfee").observe("blur", function() { Fee.checkNumber(this.id, 100, 10000, this.id + "msg"); });
        $("insurancefee").observe("blur", function() { Fee.checkNumber(this.id, 950, 50000, this.id + "msg"); });
        $("fixfee").observe("blur", function() { Fee.checkNumber(this.id, 100, 10000, this.id + "msg"); });
        $("fixcount").observe("blur", function() { Fee.checkNumber('fixcount', 1, 25, "fixfeemsg"); });
        $("parkingfee").observe("blur", function() { Fee.checkNumber(this.id, 0, 2000, this.id + "msg"); });
        $("toll").observe("blur", function() { Fee.checkNumber(this.id, 0, 5000, this.id + "msg"); });
        $("fine").observe("blur", function() { Fee.checkNumber(this.id, 0, 10000, this.id + "msg"); });
        $("other").observe("blur", function() { Fee.checkNumber(this.id, 0, 10000, this.id + "msg"); });


        $$('input[type="text"]').each(function(i) {
            i.observe("focus", function() { this.addClassName('onbg'); });
            i.observe("blur", function() { this.removeClassName('onbg'); });
        })

        if (Init.UserName == "") {
            $("check").observe("blur", function() { Fuel.checkCode() });
        }

        $('submit').observe('click', function() { window.onbeforeunload = null; });
    },
    editBreak: function() {
        $("feeok").hide(); $("feewrite").show();
    },
    writeOk: function() {
        if (Fee.errer > 0) return;

        if (Fee.feecount == 0) {
            $("gasfeemsg").update('<strong>总不能费用为0还提交吧?</strong>');
            $("gasfeemsg").show();
            Fee.errer++;
            return;
        }

        $("feeok").show(); $("feewrite").hide();
        var gas = Fee.getNumber($F("gasfee"));
        var insurance = Fee.getNumber($F("insurancefee"));
        insurance = Math.round(insurance / 12);
        var fixf = Fee.getNumber($F("fixfee"));
        var fixc = Fee.getNumber($F("fixcount"));

        var fix = Math.round(fixf * fixc / 12);

        var parking = Fee.getNumber($F("parkingfee"));
        var tol = Fee.getNumber($F("toll"));
        var fin = Fee.getNumber($F("fine"));
        var othe = Fee.getNumber($F("other"));

        var sumM = Math.round(gas + insurance + fix + parking + tol + fin + othe);


        $$("div.write_oil_ok li")[0].innerHTML = "<label>选车：</label>" + Fee.modelName + $('car').item($('car').selectedIndex).innerHTML;
        $$("div.write_oil_ok li")[1].innerHTML = "<label>地区：</label>" + $('city').item($('city').selectedIndex).innerHTML;
        $$("div.write_oil_ok li")[2].innerHTML = "<label>油费：</label><span>" + ($F("gasfee") ? $F("gasfee") : '0') + "</span>元/月";
        $$("div.write_oil_ok li")[3].innerHTML = "<label>保险：</label><span>" + insurance + "</span>元/月";
        $$("div.write_oil_ok li")[4].innerHTML = "<label>维修保养：</label><span>" + fix + "</span>元/月";
        $$("div.write_oil_ok li")[5].innerHTML = "<label>停车费：</label><span>" + ($F("parkingfee") ? $F("parkingfee") : '0') + "</span>元/月";
        $$("div.write_oil_ok li")[6].innerHTML = "<label>过路费：</label><span>" + ($F("toll") ? $F("toll") : '0') + "</span>元/月";
        $$("div.write_oil_ok li")[7].innerHTML = "<label>违章罚款：</label><span>" + ($F("fine") ? $F("fine") : '0') + "</span>元/月";
        $$("div.write_oil_ok li")[8].innerHTML = "<label>其它：</label><span>" + ($F("other") ? $F("other") : '0') + "</span>元/月";
        $$("div.write_oil_ok li")[9].innerHTML = "<dl><dt>为您计算：</dt><dd>每月平均费用为：<em>" + sumM + "元</em></dd><dd>一年总费用为：<em>" + sumM * 12 + "元</em></dd></dl>";


        ZeroClipboard.setMoviePath('http://js.inc.baa.bitautotech.com/review/zeroclipboard.swf');

        $('copy').observe('mouseover', function(evnt) {
            if (util.clip == null) util.clip = new ZeroClipboard.Client();
            util.clip.setText('\
我每月的养车费用如下，分享给你看看：' + window.location.href.replace('tianjia/', '') + '\r\n\n\
    选　　车：' + (Fee.modelName + $('car').item($('car').selectedIndex).innerHTML.strip()) + '\n\
    地　　区：' + $('city').item($('city').selectedIndex).innerHTML + '\r\n\
    油　　费：' + ($F("gasfee") ? $F("gasfee") : '0') + '元/月\r\n\
    保　　险：' + insurance + '元/月\r\n\
    维修保养：' + fix + '元/月\r\n\
    停 车 费：' + ($F("parkingfee") ? $F("parkingfee") : '0') + '元/月\r\n\
    过 路 费：' + ($F("toll") ? $F("toll") : '0') + '元/月\r\n\
    违章罚款：' + ($F("fine") ? $F("fine") : '0') + '元/月\r\n\
    其　　它：' + ($F("other") ? $F("other") : '0') + '元/月\r\n\n\n\
每月平均费用为：' + sumM + '元\r\n\
一年总费用为：' + sumM * 12 + '元');
            if (util.clip.div) {
                util.clip.receiveEvent('mouseout', null);
                util.clip.reposition(this);
            }
            else util.clip.glue(this);
            util.clip.handlers['complete'] = [];
            util.clip.addEventListener('complete', function(client, text) {
                alert('复制成功,快去发给你的好友吧..')
            });
        });

    },
    getNumber: function(str) {
        try {
            return !str.strip() ? 0 : eval(str.strip());
        }
        catch (err) {
            return 0;
        }
    },
    checkNumber: function(id, min, max, msgid) {
        var fee = $F(id);
        try {
            if (fee.match(/[^\d.]/)) {
                $(msgid).show();
                $(msgid).update('<strong>您输入的费用超出正常值范围.</strong>');
                Fee.errer++;
            }
            fee = eval(fee);
            if (fee == 0) {

            }
            if (fee < min || fee > max) {
                $(msgid).show();
                $(msgid).update('<strong>您输入的费用超出正常值范围.</strong>');
                Fee.errer++;
            }
            else if (fee) {
                $(msgid).hide();
                Fee.feecount++;
            }
        }
        catch (err) {
            $(msgid).show();
            $(msgid).update('<strong>请输入正确的数字类型.</strong>');
            Fee.errer++;
        }
    },
    checkCar: function() {
        if ($F('car') == "选择车款") {
            $('carmsg').show(); Fee.errer++;
        }
        else {
            $('carmsg').hide();
        }
    },
    checkCity: function() {
        if ($F('city') == "请选择地区") {
            $('citymsg').update('<strong>请选择地区</strong>');
            $('citymsg').show();
            Fee.errer++;
        }
        else {
            $('citymsg').hide();
        }
    },
    checkUser: function(ok) {
        new Ajax.Request(xpath + "Common/Ajax.ashx", { parameters: { "t": "checkuserlogin", "username": $F("username"), "password": $F("password"), "ok": ok }, onLoading: function(request) { util.loading(Event.element(evnt)) }, onLoaded: function(request) { util.loaded(); } });
    },
    checkBegin: function() {
        Fee.errer = 0;
        Fee.feecount = 0;


        Fee.checkCar();
        Fee.checkCity();

        Fee.checkNumber("gasfee", 100, 10000, "gasfeemsg");
        Fee.checkNumber("insurancefee", 1000, 50000, "insurancefeemsg");
        Fee.checkNumber("fixfee", 100, 10000, "fixfeemsg");
        Fee.checkNumber('fixcount', 1, 25, "fixfeemsg");

        Fee.checkNumber("parkingfee", 0, 2000, "parkingfeemsg");
        Fee.checkNumber("toll", 0, 5000, "tollmsg");
        Fee.checkNumber("fine", 0, 10000, "finemsg");
        Fee.checkNumber("other", 0, 10000, "othermsg");
        if (!Init.UserName) $("anonymous").checked ? Fuel.checkCode(true, 'Fee') : Init.UserName == "" ? Fuel.checkUser(true, 'Fee') : Fee.writeOk();
        else Fee.writeOk();
    },
    rankFold: function() {
        $$('.style_fare').each(function(d) {
            var lis = d.select('li');

            d.down('div', 1).show()

            for (var i = 0; i < lis.length; i++) {
                if (i == 0) {
                    lis[i].className = 'current';
                }
                lis[i].v = i;
                lis[i].onclick = function() {
                    var divs = $(this).up('div', 1).select('div.box');
                    for (var m = 0; m < divs.length; m++) {
                        m == eval(this.v) ? divs[m].show() : divs[m].hide();
                    }

                    var ls = $(this).up('ul').select('li');
                    for (var n = 0; n < ls.length; n++) {
                        n == eval(this.v) ? ls[n].className = 'current' : ls[n].className = '';
                    }
                }
            }
        });
    }
};

var Model = {
    selectCar: [],
    photo: {
        tab: function() {
            $("lantern_list").select('li').each(function(l) {
                l.observe("mousemove", function() {
                    $("lantern_list").select('li').each(function(_li) {
                        _li.className = '';
                    })
                    this.className = 'current';
                    $$('#lantern_pic img')[0].src = $(this).down('img').src.replace('_1.', '_4.');
                    $$('#lantern_pic img')[0].title = $(this).down('img').title;

                    $$('#lantern_pic a')[0].href = $(this).down('a').href;
                });
            });
        }
    },
    compare: {
        path: 'duibi',
        fold: function() {
            Model.compare.closeFold();

            if ($('make')) $('make').observe("change", function() { Common.getBrandList(this.value); });
        },
        closeFold: function() {
            $$('.del').each(function(a) {
                a.onclick = function() {
                    if (confirm('确定取消对比此车型?')) {
                        Model.compare.removeCompare(eval(this.up('div').id));
                        Model.compare.toNewCompare();
                    }
                }
            });

            $$('.kbbaogao dt span').each(function(a) {
                a.onclick = function() {
                    if (confirm('确定取消对比此车型?')) {
                        Model.compare.removeCompare(this.id);
                        Model.compare.toNewCompare();
                    }
                }
            });
        },
        toTab: function(t) {
            $$('.duibi_li').each(function(d) {
                d.select('.dongli_koubei').each(function(_d) {
                    _d.hide();
                });
            });

            $$('.duibi_li').each(function(d) {
                d.select('.dongli_koubei')[t].show();
            });
        },
        tabFold: function() {
            $$('.dongli_koubei').each(function(d) { d.hide() });

            var lis = $$('.ul_show')[0].select('li');
            for (var i = 0; i < lis.length; i++) {
                lis[i].v = i;
                lis[i].onclick = function(evnt) {
                    $$('.ul_show')[0].select('li').each(function(l) { l.className = ''; })
                    this.className = 'current';
                    Model.compare.toTab(eval(this.v));
                    evnt.stop();
                }
            }
        },
        addCompare: function(mid) {
            var ids = $F('compares') + ',' + mid;
            ids = ids.split(',').compact().uniq();
            $('compares').value = ids.without('').join(',');
        },
        removeCompare: function(mid) {
            ids = $F('compares').strip().split(',').without(mid).uniq();
            if (ids.length == 0) { window.location = 'http://koubei.bitauto.com/' + Model.compare.path + '/'; }
            $('compares').value = ids.without('').join(',');
        },
        toNewCompare: function() {
            if ($F('compares') == '' || $F('compares').split(',').compact().join(',').replace(',', '') == "") {
                window.location = 'http://koubei.bitauto.com/' + Model.compare.path + '/';
                return;
            }
            else {
                window.location = 'http://koubei.bitauto.com/' + Model.compare.path + '/' + $F('compares').split(',').compact().join(',') + '.html';
            }
        },
        selectCompare: function() {
            var arr = new Array();

            $$('.model_contrast')[0].select('input[type="checkbox"]').each(function(i) {
                if (i.checked) arr.push(i.value);
            });
            if (arr.length > 0) {
                window.open('http://koubei.bitauto.com/' + Model.compare.path + '/' + arr.join(',') + '.html');
            }
            else
                alert('请选择所要对比的车型.');
        },
        selectCarBoxTo: function(_1) {
            $('selectCarBox').show();
            $$('.line_box .on').each(function(li) { $(li).removeClassName('on'); });
            $$('.line_box .on_').each(function(li) { $(li).removeClassName('on_'); });
            $(_1).addClassName('on');
            Model.compare.selectCarListBoxBind(_1.innerHTML, _1);
        },
        selectCarListBoxBind: function(ty, o) {
            new Ajax.Request(xpath + 'Common/Ajax.ashx', { parameters: { 't': 'getcarselectlist', 'ty': encodeURI(ty), r: util.rdn }, method: 'get', onLoading: function(request) { util.loading(Event.element(o)) }, onLoaded: function(request) { util.loaded(); }, onComplete: function(response) { Model.selectCar = eval(response.responseText); Model.compare.selectCarBoxBind(); } });
        },
        selectCarBoxBind: function() {
            var i = 1;
            var arr = Array();
            Model.selectCar.each(function(o) {
                arr.push('<dl');
                switch (i++) {
                    case 2: arr.push(' class="j"'); break;
                    case 3: arr.push(' class="no_line"'); break;
                    default: break;
                }
                arr.push('>');
                arr.push('<dt>' + o.n + '</dt><dd><ul>');
                o.list.each(function(li) {
                    if (scar[li.toString()]) arr.push('<li><a onclick="Model.compare.addCompare(' + li + ');Model.compare.toNewCompare();">' + scar[li.toString()] + '</a></li>');
                });
                arr.push('</ul></dd></dl>');
            });
            $('selectCarBox').update(arr.join(''));
        }
    }
};

function getr(b, e) {
    return Math.round(Math.random() * (e - b) + b);
}