
//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();
}

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);
}

