var map = null;
	
function GetMap()
{
	map = new VEMap('myMap');
	map.LoadMap();
	map.SetCenterAndZoom(new VELatLong(51.38101075012712, 10.458211487299689), 7);
}  
	
function FindLoc(where)
{
    if(!isNaN(where)){
        //we assume a PLZ, lets add germany to this
        where = where + ', Germany';
    }
	map.Find(null, where);
}

function SetCenterAndZoom(latitude, longitude, zoom){
    map.SetCenterAndZoom(new VELatLong(latitude, longitude), zoom);
}

function GetCenterAndZoom(){
	var centerPos = map.GetCenter();
    window.prompt("", "SetCenterAndZoom(" + centerPos.Latitude + "," + centerPos.Longitude + "," + map.GetZoomLevel() + ")");
}

function GetPosition(){
	var centerPos = map.GetCenter();
	document.getElementById("txtLatitude").value = centerPos.Latitude;
	document.getElementById("txtLongitude").value = centerPos.Longitude;
}

function MoveToPosition(){
	var pos = new VELatLong(document.getElementById("txtLatitude").value, document.getElementById("txtLongitude").value);
	map.SetCenter(pos);
	map.SetZoomLevel(15);
}
	
function ReturnPosition(){
	opener.setLetLong(document.getElementById("txtLatitude").value, document.getElementById("txtLongitude").value);
	self.close();
}


function CreatePushPin(id, latitude, longitude, title, text, image)
{
	var pos=new VELatLong(latitude.replace(',','.'), longitude.replace(',','.'));
	
    var shape = new VEShape(VEShapeType.Pushpin, pos);

    //Set the icon
    var icon = '<img src="images/pushpin.png" />';
    if(image)
    {
		icon = '<img border="0" src="' + image + '" />';
    }
    shape.SetCustomIcon(icon);
    
    //Set the info box
    shape.SetTitle(title);
    shape.SetDescription(text);
    //shape.SetMoreInfoURL("http://www.proticket.biz/?vid=" + id);

	mainShapeLayer.AddShape(shape);
    
    //Add the shape the the map
    //map.AddShape(shape);
}

function CreatePushPinOld(id, latitude, longitude, title, text, image){
    var pushpinImage = 'images/pushpin.png';
    if(image)pushpinImage = image;
	var pin = new VEPushpin(
			id, //ID
			new VELatLong(latitude.replace(',','.'), longitude.replace(',','.')), //Location
			pushpinImage, //Icon Url
			title, //Title
			text, //Details
			'iconStyle', //Icon style class name
			'titleStyle', //Title style class name
			'previewStyle'); //Preview style class name
	map.AddPushpin(pin);
}
        
function ResizeMap(){
	var curWidth = window.document.body.offsetWidth;
	var curHeight = window.document.body.offsetHeight;
	map.Resize(curWidth-1, curHeight - 35);
	try{
	    if(document.getElementById("smallOverviewImageMapControl")){
	        document.getElementById("smallOverviewImageMapControl").style.top = (curHeight - 310) + "px";
	    }
	}catch(e){
	}
}


//shows the list- control
function viewList(){
    document.getElementById("smallOverviewImageMapControl").style.display="none";
	document.getElementById("myList").style.display="block";
	document.getElementById("myMap").style.display="none";		
	document.getElementById("showList").style.display="none";
	document.getElementById("showMap").style.display="inline";
	if(!BrowserIsIE())document.body.style.overflow="auto";
}

//show the map- control
function viewMap(){
    document.getElementById("smallOverviewImageMapControl").style.display="inline";
	document.getElementById("myList").style.display="none";
	document.getElementById("myMap").style.display="block";			
	document.getElementById("showMap").style.display="none";
	document.getElementById("showList").style.display="inline";
	if(!BrowserIsIE())document.body.style.overflow="hidden";
}




///////////////////////////////////////////////////////////////////////////////////////
//	debugging- Stuff
///////////////////////////////////////////////////////////////////////////////////////


function viewCurrentZoom(){
	alert(map.GetZoomLevel());
}

function AddPolygon()
{   
	map.DeleteAllPolygons();
	var curPos = map.GetMapView();
	var points = new Array(
		new VELatLong(curPos.TopLeftLatLong.Latitude, curPos.TopLeftLatLong.Longitude),
		new VELatLong(curPos.BottomRightLatLong.Latitude, curPos.BottomRightLatLong.Longitude)
	);

	poly = new VEPolygon('polygon1',points);
	poly.SetOutlineWidth(3);
	poly.SetOutlineColor(new VEColor(0,150,100,1.0));
	poly.SetFillColor(new VEColor(0,150,100,0.5));
	map.AddPolygon(poly);
	//map.SetMapView(points); 
}   

function AddPolygon(left, top, right, bottom)
{   
	map.DeleteAllPolygons();
	var curPos = map.GetMapView();
	var points = new Array(
		new VELatLong(top, left),
		new VELatLong(bottom, right)
	);

	poly = new VEPolygon('polygon1',points);
	poly.SetOutlineWidth(3);
	poly.SetOutlineColor(new VEColor(0,150,100,1.0));
	poly.SetFillColor(new VEColor(0,150,100,0.5));
	map.AddPolygon(poly);
	//map.SetMapView(points); 
}   
