/**
*地图用函数
*/

$ = function(id) { return document.getElementById(id) }
$C = function(t) { return document.createElement(t) }

/** 获取某对象位置 */
function getTop(obj) {
    var t = obj.offsetTop;

    while (obj = obj.offsetParent) {
        t += obj.offsetTop;
    }
    return t;
}

function getLeft(obj) {
    var t = obj.offsetLeft;

    while (obj = obj.offsetParent) {
        t += obj.offsetLeft;
    }
    return t;
}

/** 得到数字化的Offset值 */
function getOffset(offsetStr) {
    if (offsetStr != null && offsetStr.indexOf("px")) {
        var i = offsetStr.indexOf("px");
        return Number(offsetStr.substring(0, i));
    }
}

/** 判断浏览器类型 */
function isIE() {
    if (navigator.appName != "Microsoft Internet Explorer") {
        return false;
    }
    return true;
}

/*** 点对象 */
function Point(x, y) {
    this.x = x;
    this.y = y;
    /**
    * 计算两点间距离
    
    this.Distance = function(point) {
        return Math.sqrt(Math.pow(this.x - point.x, 2) + Math.pow(this.y - point.y, 2));
    }
    */
}
/* 两点之间距离*/
function Distance(p1,p2) {
    return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
}
/* 单个地图数据对象 */
function mapitem(x,y) {
    this.pos = new Point(x, y);
    this.id = x + '-' + y;
    if (x < 0 || y < 0 || ((x + 256) / 256 - 1) * maplevel >= 37 || ((y + 256) / 256 - 1) * maplevel >= 28) {
        this.img = new __mapitem('images/out.gif');
    } else {
        this.img = new __mapitem(imgBaseDir + '/' + maplevel + '/m_r' + (y + 256) / 256 + '_c' + (x + 256) / 256 + '.jpg');
    }
    this.img.style.left = x;
    this.img.style.top = y;
    this.img.id = 'maps__' + x + '-' + y;
}
//单个地图图片对象
function __mapitem(url) {
    var vi = $C('img');
    vi.className = 'map__picitem';
    vi.src = url;
    return vi;
}
//单点标志对象
function __mapPoint(x, y, name, url, ico) {
    this.pos = new Point(x, y);
    this.id = 'map_Point' + x + '-' + y;
    this.url = url;
    //this.title = name;
    //this.div = $C('div');
    //this.div.innerHTML = '<img src="Img.3/pitem.gif" />' + name;
    this.img = $C('img');
    this.img.className = 'map__point_img';
    this.img.src = 'Img.3/pitem.gif';
    this.img.id = this.id;
    this.img.title = name;
    this.img.onclick = function() { gopoint(this.id); }
    
    this.title = $C('font');
    this.title.className = 'map__point';
    this.title.innerText = name;
    this.title.id = this.id + 'tit';
    this.title.onmouseover = function() { this.className = 'map__point_red'; }
    this.title.onmouseout = function() { this.className = 'map__point'; }
    this.title.onclick = function() { gopoint(this.id); }
}
//是否在矩形rect内
function inRect(x, y, rect) {
    if (x >= rect[0].x && y >= rect[0].y && x <= rect[1].x && y <= rect[1].y) {
        return true;
    } else {
        return false;
    }
}
/* 获得COOKIES值 */
function getCookie(name) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for (var i = 0; i < arrCookie.length; i++) {
        var arr = arrCookie[i].split("=");
        if (arr[0] == name) return arr[1];
    }
    return "";
}

//兼容旧程序
function addCookie(name,val)
{}
