var MapControl = null;
myObject = new Array();
	//window.moveTo(0,0);
	//window.resizeTo(screen.width,screen.height);

var windowWidth=0;
var windowHeight=0;
var scrollbarWidth=null;
function GetWindowWidth(){var width=0;if(typeof(window.innerWidth)=='number'){width=window.innerWidth;}else if(document.documentElement&&document.documentElement.clientWidth){width=document.documentElement.clientWidth;}else if(document.body&&document.body.clientWidth){width=document.body.clientWidth;}if(!width||width<100){width=100;}return width;}
function GetWindowHeight(){var height=0;if(typeof(window.innerHeight)=='number'){height=window.innerHeight;}else if(document.documentElement&&document.documentElement.clientHeight){height=document.documentElement.clientHeight;}else if(document.body&&document.body.clientHeight){height=document.body.clientHeight;}if(!height||height<100){height=100;}return height;}

function GetScrollbarWidth(){if(scrollbarWidth){return scrollbarWidth;}var div=document.createElement("div");var sbWidth=null;div.style.visible='hidden';div.style.overflowY='scroll';div.style.position='absolute';div.style.width=0;document.body.insertAdjacentElement("afterBegin",div);sbWidth=div.offsetWidth;div.parentNode.removeChild(div);if(!sbWidth){sbWidth=16;}scrollbarWidth=sbWidth;return sbWidth;}
function GetMousePosX(e)
	{
	if (!e)
		var e = window.event;

	var posX = 0;

	if (e.pageX)
		{
		posX = e.pageX;
		}

	else if (e.clientX)
		{
		posX = e.clientX + document.body.scrollLeft;
		}

	return posX;
	}

function GetMousePosY(e)
	{
	if (!e)
		var e = window.event;

	var posY = 0;

	if (e.pageY)
		{
		posY = e.pageY;
		}

	else if (e.clientY)
		{
		posY = e.clientY + document.body.scrollTop;
		}

	return posY;
	}

function ToolTip(flag, arg)
	{
	if (flag == null)
		{
		document.getElementById('ToolTip').style.display = 'none';
		}

	else
		{
		var top;
		var links;

		if (flag == 0 || flag == 2)
			{
			var hoogte = 125;
			}

		else
			{
			var hoogte = 50;
			}

		var breedte = 128;
		var posx = GetMousePosX();

		if (posx >= GetWindowWidth() / 2)
			{
			var posx = posx - breedte - 15;
			}

		var posy = GetMousePosY();

		if (posy >= GetWindowHeight() / 2)
			{
			var posy = posy - hoogte - 15;
			}

		document.getElementById('ToolTip').style.display = 'block';
		document.getElementById('ToolTip').style.top = posy + 'px';
		document.getElementById('ToolTip').style.left = posx + 'px';
		document.getElementById('ToolTip').style.height = hoogte + 'px';
		document.getElementById('ToolTip').style.width = breedte + 'px';

		if (flag == 0)
			{
			TooltipInhoud = '<img border="0" src="http://' + myObject[0][arg][4]
								+ '" width="128px" height="85px">'
			TooltipInhoud += '<br /><b>' + myObject[0][arg][3] + '</b>';
			TooltipInhoud += '<br />' + myObject[0][arg][5] + ' Persons';
			TooltipInhoud += '<br />Week, from: ' + myObject[0][arg][6] + ' &euro;';
			}

		else if (flag == 1)
			{
			TooltipInhoud = '<b>Airport: ' + myObject[2][arg][3] + '</b>';
			TooltipInhoud += '<br />City: ' + myObject[2][arg][4];
			TooltipInhoud += '<br />Airportcode: ' + myObject[2][arg][2];
			}
			else if (flag == 2)
			{
			TooltipInhoud = '<img src= "thumb.php?src='+ myObject[3][arg][4] +'"> </img>';
			var titel = myObject[3][arg][3].replace(/_/g,' ');
			TooltipInhoud += '<b>' + titel + '</b>';
			}
	

		document.getElementById('ToolTip').innerHTML = TooltipInhoud;
		}
	}

function AllInfo(arg)
	{
	PanelInhoud = '<p><img border="0" src="http://' + myObject[0][arg][4]
					  + '" width="128" height="85">'
	PanelInhoud += '<br /><b>' + myObject[0][arg][3] + '</b>';
	go(2, myObject[0][arg][2]);
	}
	
function WereldInfo(arg)
	{
	PanelInhoud = '<p><img src= "thumb.php?src='+ myObject[3][arg][4] +'"> </img>';
	var titel = myObject[3][arg][3].replace(/_/g,' ');
	PanelInhoud += '<br /><b>' + titel + '</b>';
	go(3, myObject[3][arg][2]);
	}	
	

//ajax aanvraag
var xmlhttp, alerted
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (e) {
   alert("Je browser moet Microsofts XML parsers beschikbaar hebben")
  }
 }
@else
 alert("Je browser moet minstens JScript 5 ondersteunen.")
 xmlhttp=false
 alerted=true
@end @*/
if (!xmlhttp && !alerted)
	{
	try
		{
		xmlhttp = new XMLHttpRequest();
		}
	catch (e)
		{
		alert("Je hebt een browser nodig die het XMLHttpRequest object ondersteunt.")
		}
	}

var arg;
var aanvraag;
var latli;
var longli;

function go(arg, arg2)
	{
	document.getElementById('Error').style.display = 'none';

	if (arg == 1)
		{
		if (document.huisForm.cid.value == 'default')
			{
			alert('Choose Country')
			}
		pan = arg;
		url = 'v3_feed.php';
		aanvraag = "flag=" + arg + "&taal=" + taal + "&land=" + document.huisForm.cid.value + "&rgo=" + document.huisForm.rgo.value
					   + '&pers=' + document.huisForm.personen.value + '&maand=' + document.huisForm.month.value
					   + '&periode=' + document.huisForm.period.value;
		}

	else if (arg == 2)
		{
		pan = arg;
		url = 'v3_feed.php';
		aanvraag = "flag=" + arg + "&taal=" + taal + "&hcode=" + arg2 + '&maand=' + document.huisForm.month.value + '&periode='
					   + document.huisForm.period.value;
		}
	else if (arg == 3)
		{
		pan = arg;
		url = 'v3_feed.php';
		aanvraag = "flag=" + arg + "&taal=" + taal + "&wereldcode=" + arg2;
		}

	if (xmlhttp)
		{
		document.getElementById('Loading').style.display = 'block';
		xmlhttp.open("POST", url, true);
		xmlhttp.onreadystatechange = RSchange
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.setRequestHeader('Connection', 'close');
		xmlhttp.setRequestHeader('Cache-Control', 'no-cache');
		xmlhttp.send(aanvraag);
		}
	}

function RSchange()
	{
	if (xmlhttp.readyState == 4)
		{
		if (pan == 1)
			{
		    //alert(xmlhttp.responseText);
			myObject = eval(xmlhttp.responseText);
			document.getElementById('MoreInfo').style.display = 'none';
			document.getElementById('ClickHouse').style.display = 'block';

			if (myObject[0][0] == 'leeg')
				{
				MapControl.ClearPushpins();
				document.getElementById('Loading').style.display = 'none';
				document.getElementById('Error').style.display = 'block';
				}

			else
				{
				MapControl.ClearPushpins();

				if (myObject[0][0] != 'leeg')
					{
					MapControl.SetViewport(myObject[1][0], myObject[1][1], myObject[1][2], myObject[1][3]);
				
					for (var i = 0; i < myObject[0].length; i++)
						{
						var lon = myObject[0][i][0];
						var lat = myObject[0][i][1];
						if (myObject[0][i][2] == hcode){
							housegif = 'house_2.gif';
							laag = 51;
						}
						else {
							housegif = 'house.gif';
							laag=50;
						}
						MapControl.AddPushpin(i,
											  lat,
											  lon,
											  32,
											  30,
											  '',
											  '<a  onclick = \'AllInfo(' + i + '); return false;\' href="#"><img onmouseover = \'ToolTip(0,' + i
												  + ')\' onmouseout = \'ToolTip()\' class="house" src="images/'+ housegif +'"></a>',
											  laag);
						}

					if (myObject[2][0] != 'leeg')
						{
						for (var i = 0; i < myObject[2].length; i++)
							{
							var lon = myObject[2][i][1];
							var lat = myObject[2][i][0];
							var id = 100 + i;
							MapControl.AddPushpin(id,
												  lat,
												  lon,
												  28,
												  28,
												  '',
												  '<img onmouseover = \'ToolTip(1,' + i
													  + ')\' onmouseout = \'ToolTip()\'  return false;\' class="plane" src="images/plane.gif">',
												  48);
							}
						}
					if (myObject[3][0] != 'leeg')
						{
						for (var i = 0; i < myObject[3].length; i++)
							{
							var lon = myObject[3][i][1];
							var lat = myObject[3][i][0];
							var id = 500 + i;
							var welklik;
								if (taal == 'nl') {
								welklik = 'onclick = \'WereldInfo(' + i + '); return false;\'';
								}
							MapControl.AddPushpin(id,
												  lat,
												  lon,
												  26,
												  26,
												  '',
												  '<a '+ welklik + ' href="#"><img onmouseover = \'ToolTip(2,' + i
													  + ')\' onmouseout = \'ToolTip()\'  return false;\'  class="moreinfo" src="images/info.gif"></a>',
												  49);
							}
						}						

					//document.getElementById('MoreInfo').style.display = 'block';
					}

				document.getElementById('Loading').style.display = 'none';
				}
			}

		else if (pan == 2)
			{
			myHcObject = eval(xmlhttp.responseText);
			//alert(xmlhttp.responseText)
			document.getElementById('Loading').style.display = 'none';
			document.getElementById('MoreInfo').style.display = 'block';
			PanelInhoud += myHcObject[3];
			PanelInhoud += "<input type='hidden' name='globedate' value='" + document.huisForm.month.value + "' />"; 

			for (var i = 0; i < myHcObject[2].length; i++)
				{
				PanelInhoud += myHcObject[2][i] + '<br />';
				}

			PanelInhoud += '<br />' + myHcObject[1];
			PanelInhoud += '</form></p>';
			document.getElementById('MoreInfo').innerHTML = PanelInhoud;
			}
		else if (pan == 3)
			{
			myWrObject = eval(xmlhttp.responseText);
			document.getElementById('Loading').style.display = 'none';
			document.getElementById('MoreInfo').style.display = 'block';
			PanelInhoud += '<br /><br />';
			PanelInhoud += myWrObject;
			document.getElementById('MoreInfo').innerHTML = PanelInhoud;
			}
		}
	}

function size()
	{
	MapWidth = GetWindowWidth() - 170;
	MapHeight = GetWindowHeight() - 55;

	document.getElementById('map').style.left = 170 + 'px';
	document.getElementById('map').style.top = 55 + 'px';
	document.getElementById('map').style.width = MapWidth  + 'px';
	document.getElementById('map').style.height = MapHeight + 'px';
	document.getElementById('links').style.height = MapHeight + 'px';
	MapControl.Resize(MapWidth, MapHeight);
	
		if (myObject.length != 0)
		{
//alert('error');
		MapControl.SetViewport(myObject[1][0], myObject[1][1], myObject[1][2], myObject[1][3]);
		}
	}

window.onresize = size;


function OnPageLoad()
	{
	var params = new Object();
	params.latitude = 52.311200;
	params.longitude = 13.224800;
	params.zoomlevel = 5;
	params.mapstyle = Msn.VE.MapStyle.Road;
	params.showScaleBar = true;
	params.showDashboard = true;
	params.dashboardSize = Msn.VE.DashboardSize.Normal;
	params.dashboardX = 5;
	params.dashboardY = 10;
	MapControl = new Msn.VE.MapControl(document.getElementById("map"), params);
MapControl.Init();

MapControl.AttachEvent("onchangeview", function(e) {
		if (MapControl.GetZoomLevel() > 15)	{
		MapControl.SetZoom(15);
		}
	}
   );
   
	//size();
	document.huisForm.cid.focus();
	}

