function change_lang(theLang) {

    if (theLang == myLang)
        return;


    if (location.href.indexOf("mapapp.php") == -1)
    {
        location.replace(location.href + "/mapapp.php?lang=" + theLang);
    } else
    {
        if (location.href.indexOf("lang=") > -1)
        {
            location.replace(location.href.replace("lang=" + myLang, "lang=" + theLang));
        } else
        {
            if (location.href.indexOf("?") > -1)
            {
                location.replace(location.href + "&lang=" + theLang);
            } else
            {
                location.replace(location.href + "?lang=" + theLang);
            }
        }
    }

    myLang = theLang;

}

function fullext()
{
    var BBox = getBBox(legalExtent);
    if (BBox)
    {
        mapObject.setCenter(BBox.getCenter(), mapObject.getBoundsZoomLevel(BBox) > 15 ? 15 : mapObject.getBoundsZoomLevel(BBox));
        geocoder.setViewport(BBox);
    }else
    {
        mapObject.setCenter(point, gZoomLevel);
    }
}

function getBBox(ext)
{
    if (ext.length == 0)
        return false;

    var BBox = new GLatLngBounds(new GLatLng(ext[0][1], ext[0][0]), new GLatLng(ext[0][3], ext[0][2]));

    if (ext.length == 1)
        return BBox;

    for (var i = 1; i < ext.length; i++)
    {
        BBox.extend(new GLatLng(ext[i][1], ext[i][0]));
        BBox.extend(new GLatLng(ext[i][3], ext[i][2]));
    }

    return BBox;
}

function getWinSize()
{
    if (window.innerWidth) {
        return [innerWidth, innerHeight];
    } else if (document.body && document.body.offsetHeight) {
        return [document.documentElement.offsetWidth, document.documentElement.offsetHeight];
    } else {
        return [0, 0];
    }
}

function ResizeGMap(isInit)
{
    var mapSize = getMapSize();

    document.getElementById('map_canvas').style.height = mapSize[1] + "px";
    document.getElementById('map_canvas').style.width = mapSize[0] + "px";
    document.getElementById('map_canvas').style.marginLeft = LEFT_GAP + "px";
    document.getElementById('headerline').style.marginLeft = LEFT_GAP + "px";
    document.getElementById('headerline').style.width =(mapSize[0]-35*0) + "px";

    if (mapSize[0] < TopImage[0])
    {
        document.getElementById('topimage').style.width = mapSize[0] + "px";
        document.getElementById('topimage').style.height = mapSize[0]/TopImage[0]*TopImage[1] + "px";
    } else
    {
        document.getElementById('topimage').style.width = TopImage[0] + "px";
        document.getElementById('topimage').style.height =TopImage[1] + "px";
    }

    document.getElementById('rightbar').style.top = TOP_GAP + "px";
    document.getElementById('rightbar').style.left = (LEFT_GAP + mapSize[0] + 20 + 10) + "px";
    document.getElementById('geomer').style.left = (LEFT_GAP + mapSize[0] - 250) + "px";

    document.getElementById('searchresultslist').style.left = document.getElementById('searchinput').offsetLeft;
    document.getElementById('searchresultslist').style.top = document.getElementById('searchinput').offsetTop;

    document.getElementById('setMapType').style.left = (document.getElementById('map_canvas').offsetLeft +  document.getElementById('map_canvas').offsetWidth - document.getElementById('setMapType').offsetWidth - 5) + "px";
    document.getElementById('setMapType').style.top = (document.getElementById('map_canvas').offsetTop + 5 + "px");


    if (!isInit || isInit != 'init')
    {
        if (mapObject)
            mapObject.checkResize();
    }
    
    TOP_GAP = document.getElementById('map_canvas').offsetTop;

}

function getMapSize()
{
        var winsize = getWinSize();

        if (winsize[1] > 680 + TOP_GAP + BOTTOM_GAP )
        {
            var mapheight = 680;
        } else if (winsize[1] < 300 + TOP_GAP + BOTTOM_GAP )
        {
            var mapheight = 300;
        } else if (winsize[1] == 0)
        {
            var mapheight = 400;
        } else
        {
            var mapheight  = winsize[1]- (TOP_GAP + BOTTOM_GAP);
        }
        if (winsize[0] > 1100 + RIGHT_GAP + LEFT_GAP)
        {
            var mapwidth = 1100;
        } else if (winsize[0] < 450 + RIGHT_GAP + LEFT_GAP)
        {
            var mapwidth = 450;
        } else if (winsize[0] == 0)
        {
            var mapwidth = 700;
        } else
        {
            var mapwidth = winsize[0] - (RIGHT_GAP + LEFT_GAP);
        }

        return [mapwidth, mapheight];
}

