﻿var Util = {
    MsgBox: function (isErr, msg, callback) {
        Ext.MessageBox.show({
            title: "系統訊息",
            msg: msg,
            minWidth: 200,
            scope: this,
            buttons: Ext.MessageBox.OK,
            icon: (isErr ? "dialog-ERROR" : "dialog-RIGHT"),
            fn: callback
        });
    },

//    FrameResize: function (frameid, height) {
//        var iframe = null;
//        try {
//            if (parent.window.document.getElementById(frameid) != null) {
//                iframe = parent.window.document.getElementById(frameid);
//                iframe.height = height != undefined && height != null ? height : (iframe.contentWindow.document.body.offsetHeight + 12);
//                parent.Ext.get(iframe.contentWindow.document.body).fadeIn({ endOpacity: 1, duration: .5, remove: false, concurrent: true });
//                parent.location.hash = "top";
//            }
//        }
//        catch (e) {
//            return;
//        }
//        finally {
//            iframe = null;
//        }
//    },

    MailBox: function (mail) {
        Ext.MessageBox.show({
            title: "投稿專區",
            minWidth: 200,
            scope: this,
            buttons: Ext.MessageBox.OK,
            //msg:'【歡迎投稿，<a href=\'mailto:'+mail+'\'>請來信至'+mail+'</a>。謝謝】'
            msg: '【歡迎投稿，請來信至' + mail + '。謝謝】'
        });
    }
}

//Gmap
var gmap, markers = [];
function MapOnLoad(zoom, area) {
    var resp = null, first = false, mk;
    //var icon = '../../images/regio/map_icon_scenic_location.png';

    gmap = new cmGmap({
        boxEl: $('#GMap')[0],
        addDefaultMarker: false,
        zoom: zoom
        //defaultIcon: icon
    });

    resp = jQuery.parseJSON($('#latlng').html());
    if (!resp) return;

    for (var i in resp) {
        if (!resp[i].latlng) continue;

        //點位
        mk = gmap.addMarker({
            nlat: parseFloat(resp[i].latlng[0]),
            elng: parseFloat(resp[i].latlng[1]),
            //icon: icon,
            clickable: true,
            animate: true
        });

        markers.push(mk);

        if (!first) {
            first = true;
            //設中心點
            if (area != null && area != 'undefined')
                gmap.getMap().setCenter(new google.maps.LatLng(area[0], area[1]));
            else
                gmap.getMap().setCenter(mk.getPosition());
        }


        //介紹視窗
        mk = gmap.setInfoWindow({
            marker: mk,
            event: '',
            content: '<a href="' + resp[i].link + '" style="color:#3B9FAA;"><b>' + resp[i].name + '</b></a><br />' + resp[i].text
        });
    }
}

