﻿function $(a)
{
    return document.getElementById(a);
}

// Archivo JScript
function visualitzaSubmemu(num)
{        
    /* close all submenus */
    var lis = document.getElementsByTagName('li')
    {
        for (var i=0; i<lis.length; i++)
        {
            if (lis[i].id.indexOf('sub') == 0)
            {
                lis[i].style.display = 'none';
            }
        }
    }
    
    var subMenu = document.getElementById('sub' + num);
    if (subMenu != null)
    {
        if (subMenu.style.display == 'none')
        {
            subMenu.style.display = '';
        }
        else
        {
            subMenu.style.display = 'none'
        }
    }
}

function ConfirmDelete()
{
    return confirm('¿Deseas suprimir esta línea?');
}

var map = null;
var geocoder = null;

function preload()
{
    if (GBrowserIsCompatible()) 
    {
        map = new GMap2(document.getElementById("map"));
    }
}

function load() {

  var contactHTML = 'C/ Diputación, 235, 3<sup>º</sup><br />08007 BARCELONA<br /><br /><b>Tel.:</b> 902 32 36 36<br /><b>Fax:</b> 902 36 59 07';
  
  if (GBrowserIsCompatible()) {
  
    var icon = new GIcon();
    icon.image = "App_Themes/public/images/contract-ico.gif";
    icon.iconSize = new GSize(32, 32);
    icon.iconAnchor = new GPoint(6, 20);
    icon.infoWindowAnchor = new GPoint(5, 1);

  
  
    map = new GMap2(document.getElementById("map"));
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());       
    map.addControl(new GScaleControl());      
    //map.addControl(new GOverviewMapControl());
    
    map.setCenter(new GLatLng(41.389544, 2.16435), 14);
    //geocoder = new GClientGeocoder();
    
    // Add marker to CV HQ
    var point = new GLatLng(41.388544, 2.16455);
    var marker = new GMarker(point, icon);
    
    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(contactHTML);
      });

    map.addOverlay(marker);
  }
}

function AddMarker(x, y, textAddress, icon)
{
    var point = new GLatLng(x, y);
    var marker = new GMarker(point, icon);    
    GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(textAddress);
      });
      
    return marker;
}

function showAddress(address) {
  if (geocoder) {
    geocoder.getLatLng(
      address,
      function(point) {
        if (!point) {
          //alert(address + " not found");
        } else {          
          // the assignment x = y and y = x is correct becauce google keeps ordered pair like [y,x] ... ?!?!
          $('mapX').value = point.y;
          $('mapY').value = point.x;          
          document.forms[0].submit();
          //map.setCenter(point, 13);
          //var marker = new GMarker(point);
          //map.addOverlay(marker);
          //marker.openInfoWindowHtml(address);
        }
      }
    );
  }
}

/**** NEWS ***/
function RotateNews(name)
{
    var array = newsArray[name];
    
    if (array[array.length - 1] == array.length - 1)
    {
        array[array.length - 1] = 0;
    }
    
    // display news
    var newsHolder = document.getElementById(name + '_newsHolder');
    newsHolder.innerHTML = array[array[array.length - 1]];
    
    array[array.length - 1]++;
    
    
    setTimeout("RotateNews('" + name + "')", 4000);
}

// TODO: Optimize with initarray
var newsArray = new Array();
function InitArray()
{
    newsArray = new Array();
}

/**** end NEWS ***/

/*** Reports ****/

function ShowReport(listID)
{
    var list = $(listID);
    window.open('../Herramientas/ReportViewer.aspx?Id=' + list.selectedValue);
    
}

/***************/
