﻿
String.prototype.format = function() {
    var arg = arguments;
    return this.replace(/\{(\d+)\}/g, function(i, m) {
        return arg[m];
    });
}

function utf8(wide) {
    var c, s;
    var enc = "";
    var i = 0;
    while (i < wide.length) {
        c = wide.charCodeAt(i++);
        //   handle   UTF-16   surrogates   
        if (c >= 0xDC00 && c < 0xE000) continue;
        if (c >= 0xD800 && c < 0xDC00) {
            if (i >= wide.length) continue;
            s = wide.charCodeAt(i++);
            if (s < 0xDC00 || c >= 0xDE00) continue;
            c = ((c - 0xD800) << 10) + (s - 0xDC00) + 0x10000;
        }
        //   output   value   
        if (c < 0x80) enc += String.fromCharCode(c);
        else if (c < 0x800) enc += String.fromCharCode(0xC0 + (c >> 6), 0x80 + (c & 0x3F));
        else if (c < 0x10000) enc += String.fromCharCode(0xE0 + (c >> 12), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
        else enc += String.fromCharCode(0xF0 + (c >> 18), 0x80 + (c >> 12 & 0x3F), 0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F));
    }
    return enc;
}

var hexchars = "0123456789ABCDEF";

function toHex(n) {
    return hexchars.charAt(n >> 4) + hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponentNew(s) {
    var s = utf8(s);
    var c;
    var enc = "";
    for (var i = 0; i < s.length; i++) {
        if (okURIchars.indexOf(s.charAt(i)) == -1)
            enc += "%" + toHex(s.charCodeAt(i));
        else
            enc += s.charAt(i);
    }
    return enc;
}

jQuery(document).ready(function() {
    jQuery("#Header1_txt_location").autocomplete(cityData,
    {
        minChars: 0,
        max: 10,
        //mustMatch: 'word',
        width: 173,
        scroll: false,
        matchContains: true,
        autoFill: false,
        formatItem: function(row, i, max) {
            return '{0} / {1} '.format(row.n, row.p);
        },
        formatMatch: function(row, i, max) {
            return row.p + " " + row.n;
        },
        formatResult: function(row) {
            return "{0}".format(row.n);
        }
    }).result(function(event, data, formatted) {
        jQuery(this).attr("code", data.c);
    });

    jQuery(".areaUL li").mouseover(function() {//鼠标滑过
        jQuery(this).addClass("ac_over");
    }).mouseout(function() { //鼠标滑出
        jQuery(this).removeClass("ac_over");
    })

});




function GetProvinceCity(value) {
    var array = new Array();
    array[0] = "";
    array[1] = "";
    for (var i = 0; i < areas.length; i++) {
        if (areas[i][0] == value) {
            array[0] = areas[i][0];

            break;
        }
        else {
            for (var j = 1; j < areas[i].length; j++) {
                if (areas[i][j] == value) {
                    array[0] = areas[i][0];
                    array[1] = areas[i][j];

                    break;
                }
            }
        }
    }
    return array;
}

function SetArea(areaCode, isRedirect) {
    jQuery.cookie("IpLocationArea", areaCode, { expires: 30, path: '/', domain: '1car1.cn', secure: false });
    if ((areaCode == 0||areaCode=="") && isRedirect == true)
        document.location = "http://www.1car1.cn";
}

