﻿var SELECT_CITY_WIDTH = 402, SELECT_CITY_HEIGHT = 210;

function gethotarea(clickCall) {
    jQuery.ajax({
        type: "Get",
        cache: true,
        url: "/txthotarea.aspx",
        success: function(data) {
            var val = data.split("\n");
            var list = new Array();
            list.push("<ul id='hotcitylist'>");
            for (var i = 0; i < val.length - 1; i++) {
                list.push("<li><a style='cursor:pointer' onmousedown=\"$1($2,'$3');$('#hotcity').css('display', 'none');\">$3</a></li>".format(clickCall, val[i].split('|')[1].split(':')[0], val[i].split('|')[0].replace('市', '')));
            }
            list.push("<li class='more'><a class='orange' style='cursor:pointer' onmousedown=\"SelectCity('WindowHandler');\" title='更多城市'>更多>></a></li></ul>");
            $("#hotcity").html(list.join(""));
        }
    });
}

//function GetObjPosition(obj) {
//    var position = '';
//    if (obj.getBoundingClientRect) {
//        position = obj.getBoundingClientRect();
//        return '{x:' + position.left + ',y:' + position.top + '}';
//    }
//    else if (document.getBoxObjectFor) {
//        position = document.getBoxObjectFor(obj);
//        return '{x:' + position.x + ',y:' + position.y + '}';
//    }
//    else {
//        var pos = [obj.offsetLeft, obj.offsetTop];
//        var parent = obj.offsetParent;
//        while (parent) {
//            pos[0] += parent.offsetLeft;
//            pos[1] += parent.offsetTop;
//            parent = parent.offsetParent;
//        }
//        return '{x:' + pos[0] + ',y:' + pos[1] + '}';
//    }
//}

function GetObjPosition(obj) {
        var pos = [obj.offsetLeft, obj.offsetTop];
        var parent = obj.offsetParent;
        while (parent) {
            pos[0] += parent.offsetLeft;
            pos[1] += parent.offsetTop;
            parent = parent.offsetParent;
        }
        return '{x:' + pos[0] + ',y:' + pos[1] + '}';
}

var TIPX, TIPY;
function setTIPXY(obj) {
    var pos = eval('(' + GetObjPosition(obj) + ')');
    TIPX = pos.x;
    TIPY = pos.y + obj.offsetHeight + 8;
}

function tip(obj, clickCall) {
    var pos = eval('(' + GetObjPosition(obj) + ')');
    $("#hotcity").css({ "display": "", "position": "absolute", "width": "200px", "height": "72px", "border": "1px solid #FAFAFA", "background-color": "#EAEAEA" ,"z-index":9999});
    $("#hotcity").css("left", pos.x + "px");
    $("#hotcity").css("top", (pos.y + obj.offsetHeight + 6) + "px");
    TIPX = pos.x;
    TIPY = pos.y + obj.offsetHeight + 8;
    gethotarea(clickCall);
}

$(document).ready(function() {
    var newNode = document.createElement("div");
    newNode.setAttribute("id", "hotcity");
    document.body.appendChild(newNode);
});

function closeHotcity() {
    $("#hotcity").css("display", "none");
}
