
//create the ToolTip overlay object
function ToolTip(marker,html,width) {
	this.html_ = html;
	this.width_ = (width ? width + 'px' : 'auto');
	this.marker_ = marker;
}

ToolTip.prototype = new GOverlay();

ToolTip.prototype.initialize = function(map) {
	var div = document.createElement("div");
	div.style.display = 'none';
	map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
	
	this.map_ = map;
	this.container_ = div;
}

ToolTip.prototype.remove = function() {
	this.container_.parentNode.removeChild(this.container_);
}

ToolTip.prototype.copy = function() {
	return new ToolTip(this.html_);
}

ToolTip.prototype.redraw = function(force) {
	if (!force) return;
	
	var relLocation = this.map_.fromLatLngToContainerPixel(this.marker_.getPoint());
	var pixelLocation = this.map_.fromLatLngToDivPixel(this.marker_.getPoint());
	relLocation.x += 15;
	relLocation.y -= 10;
	pixelLocation.x += 15;
	pixelLocation.y -= 10;
	
	this.container_.innerHTML = this.html_;
	this.container_.style.position = 'absolute';
	
	this.container_.style.left = pixelLocation.x + "px";
	this.container_.style.top = pixelLocation.y + "px";
	this.container_.style.font = '10px/10px verdana, arial, sans';
	this.container_.style.border = '1px solid black';
	this.container_.style.background = 'white';
	this.container_.style.padding = '4px';
	this.container_.style.textAlign = 'left';
	this.container_.style.opacity = '.75';
	
	//one line to desired width
	this.container_.style.whiteSpace = 'nowrap';
	if(this.width_ != 'auto') this.container_.style.overflow = 'hidden';
	this.container_.style.display = 'block';
	
	// Get the map dimensions
	var mapContainer = this.map_.getContainer();
	var mapWidth = mapContainer.offsetWidth;
	var mapHeight = mapContainer.offsetHeight;

	addPixels = (relLocation.x + this.container_.offsetWidth + 2) - mapWidth;
	if (addPixels >= 0) {
		this.container_.style.left = (pixelLocation.x - addPixels - 5) + "px";
		pixelLocation.y += 10;
		relLocation.y += 10;
		this.container_.style.top = pixelLocation.y + "px";
	}
	if (relLocation.y > mapHeight-this.container_.offsetHeight) {
		this.container_.style.top = (pixelLocation.y - (this.container_.offsetHeight*2)) + "px";
	}
}

GMarker.prototype.ToolTipInstance = null;

GMarker.prototype.openToolTip = function(content) {
	//don't show the tool tip if there is acustom info window
	if(this.ToolTipInstance == null) {
		this.ToolTipInstance = new ToolTip(this,content)
		map.addOverlay(this.ToolTipInstance);
	}
}

GMarker.prototype.closeToolTip = function() {
	if(this.ToolTipInstance != null) {
		map.removeOverlay(this.ToolTipInstance);
		this.ToolTipInstance = null;
	}
}

function initialize_map() {
  if (GBrowserIsCompatible()) LoadMap();
}
var streetAvailable = true;
var myPano;

var streetPov;
var streetLatLng;

function init_street_view() {
  if (GBrowserIsCompatible()) {	  
	streetLatLng = new GLatLng(streetLat, streetLong);

	if(streetYaw !=undefined) {
		streetPov = {yaw:streetYaw,pitch:streetPitch,zoom:streetZoom};	 
		
	  	panoramaOptions = { features: { streetView: true, userPhotos: false },latlng:streetLatLng, pov:streetPov };
	}else {
		panoramaOptions = { features: { streetView: true, userPhotos: false },latlng:streetLatLng };
	}
	myPano = new GStreetviewPanorama(document.getElementById("pano"), panoramaOptions);

	GEvent.addListener(myPano, 'initialized', function(pano) {
	 // alert("newlng: " + pano.latlng.lng() + ", newlat: " + pano.latlng.lat());
	  streetLatLng = pano.latlng;
	});

	GEvent.addListener(myPano, 'yawchanged', function(newyaw){
	  streetPov.yaw = newyaw;
	});

	GEvent.addListener(myPano, 'pitchchanged', function(newpitch) {
	  //alert("pitchchanged: " + newpitch);
	  streetPov.pitch = newpitch;
	});

	GEvent.addListener(myPano, 'zoomchanged', function(newzoom) {
	  streetPov.zoom = newzoom;
	});
		
	GEvent.addListener(myPano, "error", handleErrors);
	  
	  
	  
	streetLatLng = myPano.getLatLng();
	streetPov = myPano.getPOV(); 
  }	
}

function handleErrors(errorCode){
   if (errorCode == G_GEO_UNKNOWN_ADDRESS)
     streetAvailable = false;
	 if( document.getElementById("pano") != null) {
		document.getElementById("pano").innerHTML = '<img src="/images/no_view.png">';
	 }
   else if (errorCode == G_GEO_SERVER_ERROR)
     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + errorCode);
   
   else if (errorCode == G_GEO_MISSING_QUERY)
     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + errorCode);

   else if (errorCode == G_GEO_BAD_KEY)
     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + errorCode);

   else if (errorCode == G_GEO_BAD_REQUEST)
     alert("A directions request could not be successfully parsed.\n Error code: " + errorCode);
    
   else alert("An unknown error occurred.");
   
}
	

function LoadMap() {
	if ( CenterLat == "" || CenterLong == "" ){
		CenterLat 	= "43.680101";
		CenterLong = "-79.33964";
		sAddress = "Dine.TO<br/>898 Danforth Ave.<br/>Toronto, Ontario";
	} else {
		sAddress = "<span style='font-weight: bold'>" + estName + "</span><br/>";
		sAddress += "<span style='font-weight: normal; font-size: 10px;'>" + estAddress + "</span>";
	}

	var location = new GLatLng(CenterLat, CenterLong);
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.setCenter(location, map_sm_zoom);

	if (gpPoints) {
			var gpIcon = new GIcon();
			gpIcon.image = "/images/gpIcon.png";
			gpIcon.iconSize = new GSize(24, 38);
			gpIcon.iconAnchor = new GPoint(10, 36);
			gpIcon.shadow = "/images/gpshadow.png";
			gpIcon.shadowSize = new GSize(37, 34);
			gpIcon.infoShadowAnchor = new GPoint(18, 25);
			gpIcon.infoWindowAnchor = new GPoint(1, 1);
	
		totalGP = gpPoints.length/4;
		for (i=0; i<gpPoints.length; ) {
			newGPP = new GLatLng(gpPoints[i++], gpPoints[i++]);
			var marker = new GMarker( newGPP, gpIcon );
			marker.tipDiv = "<span style='font-weight:bold'>" + gpPoints[i++] + "</span><br/>Type: ";
			if (gpPoints[i++] == 0) marker.tipDiv += "Garage";
			else marker.tipDiv += "Surface";
			marker.infoDiv = marker.tipDiv;
			GEvent.addListener (marker, 'mouseover', function() { this.openToolTip(this.tipDiv); } );
			GEvent.addListener (marker, 'mouseout', function() { this.closeToolTip() } );		
			map.addOverlay(marker);
		}
	}

	var marker = new GMarker(location);
	marker.sAddress = sAddress;
	GEvent.addListener (marker, 'mouseover', function() { this.openToolTip(this.sAddress); } );
	GEvent.addListener (marker, 'mouseout', function() { this.closeToolTip() } );		
	map.addOverlay(marker);

}

function checkData() {
	if (document.Form1.FirstName.value == "") {
		alert("Please enter your First Name!")
		document.Form1.FirstName.focus()
		return false}
	if (document.Form1.LastName.value == "") {
		alert("Please enter your Last Name!")
		document.Form1.LastName.focus()
		return false}
	if (document.Form1.member_location.value == "") {
		alert("Please enter your City!")
		document.Form1.member_location.focus()
		return false}
/*
	if (document.Form1.AreaCode.value == "") {
		alert("Please enter your Area Code!")
		document.Form1.AreaCode.focus()
		return false}
	if (document.Form1.PhoneNum.value == "") {
		alert("Please enter your Phone Number!")
		document.Form1.PhoneNum.focus()
		return false}
*/
	vale=document.Form1.Email.value.indexOf("@" && ".")
	if (vale==-1){  
		alert("You must enter a valid e-mail");
		document.Form1.Email.select();
		return false}
	if (document.Form1.People.value == "") {
		alert("Please enter the number of People you would like to Reserve for !")
		document.Form1.People.focus()
		return false}
}

function DatePopUp(oForm) {
	var sPage = "reservations_date_picker.php?PickedDate=" + oForm.value+ "&FormName=" + oForm.name;
	var x=300;
	var y=180;
	var x_offset = document.width/2;
	var y_offset = document.height/2;
	
	var windetails = "width=" + x + ",height=" + y + ",toolbar=0,scrollbars=0,resizable=1,screenX=" + x_offset + ",screenY=" + y_offset;  
	win = window.open(sPage,"DatePicker", windetails);
}
//POP UP PAGE 'javascript:menupop("XXX.htm")'
function menupop(imagename) {
popwin = this.open(imagename, "menu", "width=800,height=700,left = 0,top = 0, toolbar=no,menubar=no,location=no,scrollbars=yes,status=no,resize=yes");
}

if (window.addEventListener)
{
//  window.addEventListener('load', initialize_map, false);
  window.addEventListener('load', init_street_view, false);
  window.addEventListener('unload', GUnload, false);
  
}
else if (window.attachEvent)
{
//  window.attachEvent('onload', initialize_map);
  window.attachEvent('onload', init_street_view);
  window.attachEvent('onunload', GUnload);
}





