﻿var _link = '';

function changeCountry(_val)
{
    var _israel = false;
    var _items = _val.split(';');
    if (_items.length==7)
    {
        if (_items[3] == 'ישראל') { _israel = true; }
        document.getElementById("spnCountry").innerHTML = _items[3];
        document.getElementById("spnCity").innerHTML = _items[2];
        //document.getElementById("spnMapCity").innerHTML = "מפת " + _items[2];
        document.getElementById("imgCity").src = _items[5];
        document.getElementById("trDet").style.display = '';
        _link = _baseurl + "guide/" + _items[4];
        var _name = _items[2].replace("'", "`");
        var _html = "<table class='CIWTbl' cellspacing='0' cellpadding='0'><tr><td class='CIWHeader'>" + _items[2] + ", " + _items[3] + "</td></tr><tr><td class='CIWT'></td></tr><tr><td class='CIWM'><div class='CIDiv'>" + _items[6] + " <a class='CIWA' href='" + _link + "default.aspx'>המשך</a></div></td></tr><tr><td class='CIWM'><table width='95%'><tr><td><a class='CIWA' href='" + _link + "map.aspx' title='מפת " + _name + "'>מפה</a></td><td><a class='CIWA' href='" + _link + "weather.aspx' title='מזג אוויר ב" + _name + "'>מזג אוויר</a></td><td><a class='CIWA' href='" + _link + "attractions.aspx' title='אטרקציות ב" + _name + "'>אטרקציות</a></td></tr><tr><td><a class='CIWA' href='" + _link + "events.aspx' title='אירועים ב" + _name + "'>אירועים</a></td><td><a class='CIWA' href='" + _link + "restaurants.aspx' title='מסעדות ב" + _name + "'>מסעדות</a></td><td><a class='CIWA' href='" + _link + "time.aspx' title='זמן מקומי ב" + _name + "'>זמן מקומי</a></td></tr><tr><td><a class='CIWA' href='" + _link + "nightlife.aspx' title='חיי לילה ב" + _name + "'>חיי לילה</a></td><td><a class='CIWA' href='" + _link + "electricity.aspx' title='מתח חשמלי ב" + _name + "'>מתח חשמלי</a></td><td><a class='CIWA' href='" + _link + "shopping.aspx' title='קניות ב" + _name + "'>קניות</a></td></tr><tr>";
        if (!_israel) { _html = _html + "<td><a class='CIWA' href='" + _link + "language.aspx' title='שפה ב" + _name + "'>שפה</a></td>"; }
        _html = _html + "<td><a class='CIWA' href='" + _link + "currency.aspx' title='מטבע ב" + _name + "'>מטבע</a></td><td></td></tr></table></td></tr><tr><td class='CIWB'></td>"; // <a class='CIWA' href='" + _link + "gallery.aspx' title='גלריית תמונות ב" + _name + "'>גלריית תמונות</a>
        if (_israel) { _html = _html + "<td></td>"; }
        _html = _html + "</tr></table>";
        GetNewMap(_items[0], _items[1], 10, _html);
    }
    else {
        document.getElementById("trDet").style.display = 'none';
        //document.getElementById("spnMapCity").innerHTML = 'יעדים נבחרים בעולם';
        GetNewMap("42", "0", 1, "");        
    }
}

function GetNewMap(MapCenterLat, MapCenterLng, _mapsize, _html)
{
    if (GBrowserIsCompatible()){
    var map = new GMap2(document.getElementById("map"));
    map.addControl(new GSmallMapControl()); //+-
    map.addControl(new GMapTypeControl()); //-M-S-H-
    var point = new GLatLng(parseFloat(MapCenterLat)+0.08, parseFloat(MapCenterLng));
    map.setCenter(point, _mapsize);
    if (_html!="") {
        var baseIcon = new GIcon();
        baseIcon.iconSize=new GSize(18,18);
        baseIcon.iconAnchor=new GPoint(0,0);
        baseIcon.infoWindowAnchor=new GPoint(8,0);
        var point = new GLatLng(parseFloat(MapCenterLat), parseFloat(MapCenterLng));
        var icon = new GIcon(baseIcon);
        icon.image = _baseurl + "resources/images/map/map_Icon.png";
        var marker = new GMarker(point, icon);
        
        map.addOverlay(marker);
        marker.openExtInfoWindow(map, "custom_info_window_green", _html, {beakOffset: 0});
        GEvent.addListener(marker, 'click', function(){ 
            marker.openExtInfoWindow(map, "custom_info_window_green", _html, {beakOffset: 0});
          });
        }
    }
}

function InitScreen()
{   
    var _numindex = document.getElementById("drpDest").length-1;
    if (_numindex>0) {
        _numindex = parseInt(Math.random()*_numindex, 10) + 1;
        document.getElementById("drpDest").selectedIndex = _numindex;
        changeCountry(document.getElementById("drpDest").value);
    }  
}

function gotopage(_cat)
{
    var _url = '';
    if (_cat=="0") _url = _link + "default.aspx";
    else if (_cat=="3") _url = _link + "attractions.aspx";
    else if (_cat=="4") _url = _link + "nightlife.aspx";
    else if (_cat=="2") _url = _link + "shopping.aspx";
       
    if (_url!='')
        this.location.href = _url;
}


function loadmap(address, _base, _mapsize) {
  if (address!='') {
    var map = new GMap2(document.getElementById("map"));
    var geocoder = new GClientGeocoder();
      geocoder.getLatLng(
        address,
        function(point) {
          if (!point) {
          } else {
            map.setCenter(point, parseInt(_mapsize));
            var baseIcon = new GIcon();
            baseIcon.iconSize=new GSize(14,18);
            baseIcon.iconAnchor=new GPoint(9,34);
            var icon = new GIcon(baseIcon);
            icon.image = _base + "resources/images/guide/mapIcon.png";
            var marker = new GMarker(point, icon);
            map.addOverlay(marker);
            //map.setCenter(point);
            //map.checkResize();
          }
        }
      );
  }
}
