function addLoadEvent(func){
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

//var selectedAddress = new VEAddress();
var addresses = new Array();

function VEAddress(id, address, title, miniHtml, focus, longitude, latitude, iconurl, zoomlevel){

  this.ID = id;
  this.Address = address;
  this.Title = title;
  this.MiniHtml = miniHtml;
  this.Shape = null;
  this.Focus = focus;
  this.Latitude = latitude;
  this.Longitude = longitude;
  this.IconUrl = iconurl;
  this.ZoomLevel = zoomlevel;
  
  this.RenderPushPin = function(){
    try{
    
    
        var latlong = new VELatLong(this.Latitude, this.Longitude, 0, VEAltitudeMode.Default);
        var shape = new VEShape(VEShapeType.Pushpin, latlong);

        shape.SetTitle("<div class=\"pinTitle\">" + this.Title + "</div>");
        shape.SetDescription(this.MiniHtml);
        
        SPSVEMap.AddShape(shape);
        this.Shape = shape;
        
        if(this.IconUrl!=null){
          shape.SetCustomIcon(this.IconUrl);
        
        }
        if(this.Focus){
          SPSVEMap.PanToLatLong(latlong);
          //SPSVEMap.SetZoomLevel(this.ZoomLevel);
          SPSVEMap.SetCenterAndZoom(latlong, this.ZoomLevel);
        }

     }catch(err){
        alert('There seems to be an error in the following address:\r\n' + this.Address + '\r\nplease check the address again. ' + err);
     }
     
  }
}


function CreateVEAddress(id, address, title, miniHtml, focus, longitude, latitude, iconurl, zoomlevel){

  var address2Store = new VEAddress(id, address, title, miniHtml, focus, longitude, latitude, iconurl, zoomlevel);
  addresses[addresses.length] = address2Store;

}


function RenderPushPins(){
  for(var i=0;i<addresses.length;i++){
    var address = addresses[i];
    address.RenderPushPin();
  }
}

function GetAddressById(id){
  for(var i=0;i<addresses.length;i++){
    if(addresses[i].ID == id)
      return addresses[i];
  }
  return null;
}


function PanToAddress(id){
  
  var address = GetAddressById(id);
  
  if(address!=null){
    SPSVEMap.PanToLatLong(new VELatLong(address.Latitude, address.Longitude, 0, VEAltitudeMode.Default));
    //SPSVEMap.SetZoomLevel(address.ZoomLevel);
    SPSVEMap.SetCenterAndZoom(new VELatLong(address.Latitude, address.Longitude, 0, VEAltitudeMode.Default), address.ZoomLevel);
    SPSVEMap.ShowInfoBox(address.Shape);
    
  }

}

function ShowTab(tab, id){
  var container = document.getElementById(tabcontainerid);
  var tabs = container.getElementsByTagName("div");
  for (i=0; i<tabs.length; i++){
    if(tabs[i].className!="as-tab-row"){
      if(tabs[i].id!=id){
        //tabs[i].style.display = 'none';
        tabs[i].className = "as-addresspanel";
       }else{
        //tabs[i].style.display = 'block';
        tabs[i].className = "as-addresspanel-selected";
       }
     }
  }
  
  tabcells = tab.parentElement.parentElement.getElementsByTagName("LI");
  for(var i=0;i<tabcells.length;i++){
    tabcells[i].className = "as-tab-cell"
  }
  
  tab.parentElement.className = "as-tab-cell-selected";
  
 
}
