﻿
    var Context;
    var Pager;
    var txt;
    var split = /<(\S*?)[^>]*PAGE-BREAK-AFTER[^>]*>.*?<\/\1>/gim;
    var tt;
    var ccur = -1;
    var curSize = 14;
    
    function PrevPage() {
        if (ccur > 0) {
            ccur--;
            LoadContent();
        }
    }

    function NextPage() {
        if (ccur < tt.length) {
            if (ccur < tt.length - 1) {
                ccur++;
            }
            LoadContent();
        }
    }

    function LoadContent() {
        SetHtml(Context, tt[ccur].replace(/<p>&nbsp;<\/p>/igm, ''));
        MakePager(ccur, tt.length);
        doZoom();
        window.scrollTo(0, 0);
    }

    function GotoPage(PageIndex) {
        ccur = PageIndex;
        LoadContent();
    }

    

    function SetHtml(controlElement, template) {
        controlElement.innerHTML = template;
    }

    function spec_sn(mouseobj) {
        var obj = document.getElementById('ddlCar');
        var obj_br = document.getElementById('ddlBrand');
        var obj_fct = document.getElementById('ddlFactory');

        if (obj.value != 0 && obj.value != '') {
            var path = '//newcar.dizo.com.cn/ncar-{carid}.html';
            path = path.replace("{carid}", obj.value);
            mouseobj.href = path;
            mouseobj.target = "_blank";
        }
        else {
            if (obj_br.value != 0 && obj_br.value != '') {
                var path = '//newcar.dizo.com.cn/brand-{brandid}.html';
                path = path.replace("{brandid}", obj_br.value);
                mouseobj.href = path;
                mouseobj.target = "_blank";
            }
            else {
                mouseobj.href = "javascript:alert('请选择厂商和品牌！');";
                mouseobj.target = "_self";
            }
        }
    }

    function spec_sn2(mouseobj) {
        var obj = document.getElementById('ddlCar');
        var obj_br = document.getElementById('ddlBrand');
        var obj_fct = document.getElementById('ddlFactory');

        var cpath = '//newcar.dizo.com.cn/comparecar.aspx?carid={carid}';
        cpath = cpath.replace("{carid}", obj.value);
        mouseobj.href = cpath;
    }

    function SetText(objid, text) {
        if (isIE)
            document.getElementById(objid).innerText = text;
        else
            document.getElementById(objid).textContent = text;
    }

    function addBookmark(title, url) {
        if (!title) title = document.title;
        if (!url) url = document.location.href;
        if (document.all) {
            window.external.AddFavorite(url, title);
        } else if (window.sidebar) {
            window.sidebar.addPanel(title, url, '');
        } else if (window.opera && window.print) {
            var mbm = document.createElement('a');
            mbm.setAttribute('rel', 'sidebar');
            mbm.setAttribute('href', url);
            mbm.setAttribute('title', title);
            mbm.click();
        }
    }

    function Cascading(ControlID, Category, ParentControlID, PromptText) {
        var CascadingID = ControlID + "_Cascading";
        var ClientStateID = CascadingID + "_ClientState";
        var input = document.createElement("INPUT");
        input.type = "hidden";
        input.id = CascadingID;
        document.forms[0].appendChild(input);

        $create(Dizo.Controls.Ajax.CascadingDropDownBehavior,
        {
            "Category": Category,
            "ClientStateFieldID": ClientStateID,
            "LoadingText": "正在加载...",
            "ParentControlID": ParentControlID,
            "PromptText": PromptText,
            "ServiceMethod": "GetDropDownContents",
            "ServicePath": "/CarData.asmx",
            "id": CascadingID
        }, null, null, $get(ControlID));
    }

    function redirectUrl(url) {
        var frm = document.createElement("form");
        document.body.insertBefore(frm);
        frm.method = "post";
        frm.action = url;
        frm.target = '_top';
        frm.submit();
    }

    function pageLoad() {
        Cascading('ddlScope', 'Scope', null, '==选择产地==');
        Cascading('ddlFactory', 'Factory', 'ddlScope', '==选择厂商==');
        Cascading('ddlBrand', 'Brand', 'ddlFactory', '==选择品牌==');
        Cascading('ddlCar', 'Car', 'ddlBrand', '==选择车型==');

        Context = document.getElementById("Context");
        Pager = document.getElementById("Pager");
        txt = Context.innerHTML;
        tt = txt.split(split);

        for (var i = 0; i < tt.length; i++) {
            if (tt[i].length < 10) {
                tt.splice(i, 1);
                i--;
            }
        }
        
        NextPage();
    }

    function doZoom(size) {
        if (typeof (size) != 'undefined')
            curSize = size;
        var abc = document.getElementById('Context');
        setFont(abc, curSize);
    }

    function setFont(parentNode, fontSize) {
        if (parentNode.childNodes != null) {
            for (var i = 0; i < parentNode.childNodes.length; i++) {
                if (parentNode.childNodes[i].tagName == "FONT" && parentNode.childNodes[i].size == 2) {
                    parentNode.childNodes[i].style.fontSize = (fontSize - 2) + "px";
                    setFont(parentNode.childNodes[i], fontSize - 2);

                }
                else if (parentNode.childNodes[i] && parentNode.childNodes[i].style) {
                    parentNode.childNodes[i].style.fontSize = fontSize + "px";
                    setFont(parentNode.childNodes[i], fontSize);
                }
            }
        }
    }

    function addFav() {
        if (document.all) {
            window.external.addFavorite(window.location, document.title);
        }
        else if (window.sidebar) {
            window.sidebar.addPanel(document.title, window.location, "");
        }
    }

    function GetSearchUrl() {
        var SearchA = document.getElementById("SearchUrl");
        SearchA.href = "search.aspx?q=" + escape(document.getElementById("SearchText").value);
    }

