﻿Type.registerNamespace("AOM");

AOM.Marktonderzoekbureau = function(bedrijfId, naam, straat, postcode, plaats, land, website, latitude, longitude) {
  AOM.Marktonderzoekbureau.initializeBase(this);

	this._bedrijfId = "";
	if (bedrijfId) {
		this._bedrijfId = bedrijfId;		
	}
	this._naam = "";
	if (naam) {
		this._naam = naam;		
	}
	this._straat = "";
	if (straat) {
		this._straat = straat;		
	}
	this._postcode = "";
	if (postcode) {
		this._postcode = postcode;		
	}
	this._plaats = "";
	if (plaats) {
		this._plaats = plaats;		
	}
	this._land = "";
	if (land) {
		this._land = land;		
	}
	this._website = "";
	if (website) {
		this._website = website;		
	}
	this._latitude = "";
	if (latitude) {
		this._latitude = latitude;		
	}
	this._longitude = "";
	if (longitude) {
		this._longitude = longitude;		
	}
}

AOM.Marktonderzoekbureau.prototype = {
  get_bedrijfId : function() {
      return this._bedrijfId;
  },
  set_bedrijfId : function(value) {
    if (this._bedrijfId !== value) {
      this._bedrijfId = value;
      this.raisePropertyChanged('bedrijfId');
    }
  },
  get_naam : function() {
      return this._naam;
  },
  set_naam : function(value) {
    if (this._naam !== value) {
      this._naam = value;
      this.raisePropertyChanged('naam');
    }
  },
  get_straat : function() {
      return this._straat;
  },
  set_straat : function(value) {
    if (this._straat !== value) {
      this._straat = value;
      this.raisePropertyChanged('straat');
    }
  },
	get_postcode : function() {
      return this._postcode;
  },
  set_postcode : function(value) {
    if (this._postcode !== value) {
      this._postcode = value;
      this.raisePropertyChanged('postcode');
    }
  },
  get_plaats : function() {
      return this._plaats;
  },
  set_plaats : function(value) {
    if (this._plaats !== value) {
      this._plaats = value;
      this.raisePropertyChanged('plaats');
    }
  },
  get_land : function() {
      return this._land;
  },
  set_land : function(value) {
    if (this._land !== value) {
      this._land = value;
      this.raisePropertyChanged('land');
    }
  },
  get_website : function() {
      return this._website;
  },
  set_website : function(value) {
    if (this._website !== value) {
      this._website = value;
      this.raisePropertyChanged('website');
    }
  },
  get_latitude : function() {
      return this._latitude;
  },
  set_latitude : function(value) {
    if (this._latitude !== value) {
      this._latitude = value;
      this.raisePropertyChanged('latitude');
    }
  },
  get_longitude : function() {
      return this._longitude;
  },
  set_longitude : function(value) {
    if (this._longitude !== value) {
      this._longitude = value;
      this.raisePropertyChanged('longitude');
    }
  },
  get_omschrijving : function() {
    var sb = new Sys.StringBuilder("");
    
    sb.append(this._straat);
    sb.append("<br />");
    sb.append(this._postcode);
    sb.append(" ");
    sb.append(this._plaats);
    sb.append("<br /><br /><a href='");
    sb.append(this._website);
    sb.append("'>");
    sb.append(this._website);
    sb.append("</a>");
    
    sb.append("<br /><br /><br /><a href='http://www.allesovermarktonderzoek.nl/Bedrijf.aspx?bid=");
    sb.append(this._bedrijfId);
    sb.append("' style='color:#68C3EE'>Meer informatie over dit bureau...</a>");
    
    return sb.toString();
  },
  
  dispose: function() {
    AOM.Marktonderzoekbureau.callBaseMethod(this, 'dispose');
  }
}
AOM.Marktonderzoekbureau.registerClass('AOM.Marktonderzoekbureau', Sys.Component);

AOM.BureauMapper = function(mapToPushpinId, data) {
	AOM.BureauMapper.initializeBase(this);

	this._mapToPushpinId = mapToPushpinId;
	this._map = null;
	this._geocodeMap = null;
	this._data = new Array();
	if (data) {
		this._data = data;
	}
	this._iconSpec = null;
	this._currentIndex = -1;
	this._timeoutId = -1;
}

AOM.BureauMapper.prototype = {
	set_data : function(value) {
		if (this._data !== value && value != null) {
			this._data = value;
			this.raisePropertyChanged('data');
		}
	},					
	initialize : function() {
		// instantiate the map the user is seeing
		this._map = new VEMap(this._mapToPushpinId);
		this._map.LoadMap(new VELatLong(128.4, 5.0), 7 );
		
		// instantiate hidden geocoding map
		var elMapGeocode = document.createElement("div");
		elMapGeocode.id = this._mapToPushpinId + '_geocode';
		elMapGeocode.style.position = 'absolute';
		elMapGeocode.style.left = '-1024px';
		elMapGeocode.style.top = '-768px';
		elMapGeocode.style.height = '100px';
		elMapGeocode.style.width = '100px';
		$get(this._mapToPushpinId).appendChild(elMapGeocode);
		this._geocodeMap = new VEMap(elMapGeocode.id);
		this._geocodeMap.LoadMap();
		
		this._iconSpec = new VECustomIconSpecification();
		this._iconSpec.Image = 'http://www.allesovermarktonderzoek.nl/_images/pin.gif'
		
		this.plot();
	},
	dispose : function() {
		AOM.BureauMapper.callBaseMethod(this, 'dispose');
	},
	plot : function() {
		if (this._data.length > 0) 
		{
			this._map.DeleteAllPushpins();
			
			this._currentIndex = 0;
			this._plotMarktonderzoekbureau();
		}					
	},
	_plotMarktonderzoekbureau : function() {
		var bedrijfId, naam, straat, postcode, plaats, land, latitude, longitude, omschrijving;
		if (this._currentIndex < this._data.length) 
    {
			bedrijfId = this._data[this._currentIndex].get_bedrijfId();
			naam = this._data[this._currentIndex].get_naam();
      straat = this._data[this._currentIndex].get_straat();
      postcode = this._data[this._currentIndex].get_postcode();
      plaats = this._data[this._currentIndex].get_plaats();
      land = this._data[this._currentIndex].get_land();
      latitude = this._data[this._currentIndex].get_latitude();
      longitude = this._data[this._currentIndex].get_longitude();
      omschrijving = this._data[this._currentIndex].get_omschrijving();
      
      if (
          (straat == "" &&
          postcode == "" &&
          plaats == "" &&
          land == "") ||
          (latitude == "" ||
          longitude == "")
          )
      {
				this._next();
      }
      else 
      {        
        var latLong = new VELatLong(parseFloat(latitude), parseFloat(longitude));
        var pin = this._map.AddPushpin(latLong);
			
				if (naam) pin.SetTitle(naam);
				if (omschrijving) pin.SetDescription(omschrijving);
				pin.SetCustomIcon(this._iconSpec);
				
				this._next();
      }       
    }            
    else
    {
      window.status = "Complete.";
    }
	},
	_next : function() {
		this._currentIndex++;
    this._plotMarktonderzoekbureau();					
	}
}
AOM.BureauMapper.registerClass('AOM.BureauMapper', Sys.Component);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();