var map = 0;
var id = 0;
var myPoints = new Array();
var myOverlays = new Array();
var mydate = new Date();

myPoints[0] = new Array();
myPoints[1] = new Array();
myPoints[2] = new Array();
myPoints[3] = new Array();

var geocoder = new GClientGeocoder();

function showAddress(addr, id) {
	var blah = "";
	geocoder.getLatLng(addr, function(point){ 
		if (!point) { 
			alert(address + " not found"); 
		} else { 
			// alert("latlon.aspx?id=" + id + "&lat=" + point.y + "&lon=" + point.x);
			getremotevalue("/visitors/listing/latlon.aspx?id=" + id + "&lat=" + point.y + "&lon=" + point.x);
		}
	});
}
	
function showCoords(z, id, lat, lon, html, icon) {
	jicon = icon.toString();
	if(icon!=""){
		var bicon = new GIcon(G_DEFAULT_ICON, icon); 
		//bicon.iconSize = new GSize(32, 32);
		//bicon.shadow = null;
		//bicon.printShadow = null;
		//bicon.printImage = jicon.replace(".png", ".gif");
		//bicon.mozPrintImage = jicon.replace(".png", ".gif");
		//bicon.imageMap = [7,14, 26,14, 26,31, 7,31];
		
		myPoints[z][id] = new GMarker(new GLatLng(lat, lon), bicon); 
	} else {
		myPoints[z][id] = new GMarker(new GLatLng(lat, lon));
	}
	// myPoints = new GMarker(new GLatLng(lat, lon));
	GEvent.addListener(myPoints[z][id], "click", function() { 
		//tempjunk = getremotevalue("http://www.vbfun.com/conventionCenter/planners/hotel-planner/address.aspx?id=" + id);
		//document.getElementById("daddr").value=tempjunk.trim();
		myPoints[z][id].openInfoWindowHtml("<div class='infowindow'>" + html + "</div>", { maxWidth: 310 }); 
	});
	
	GEvent.addListener(myPoints[z][id], "infowindowopen", function() { 
		document.getElementById("saddr").value = $.cookie("myaddress");
	});
	
	map.addOverlay(myPoints[z][id]);
}

function showCoords2x(z, id, lat, lon, btitle, html, cicon) {
	jicon = cicon.toString();
	if(cicon!=""){
		var bicon = new GIcon(G_DEFAULT_ICON, cicon); 
		//bicon.iconSize = new GSize(32, 32);
		//bicon.shadow = null;
		//bicon.printShadow = null;
		//bicon.printImage = jicon.replace(".png", ".gif");
		//bicon.mozPrintImage = jicon.replace(".png", ".gif");
		//bicon.imageMap = [7,14, 26,14, 26,31, 7,31];
		
		myPoints[z][id] = new GMarker(new GLatLng(lat, lon), { title: btitle, icon: bicon }); 
	} else {
		myPoints[z][id] = new GMarker(new GLatLng(lat, lon));
	}
	// myPoints = new GMarker(new GLatLng(lat, lon));
	GEvent.addListener(myPoints[z][id], "click", function() { 
		//tempjunk = getremotevalue("http://www.vbfun.com/conventionCenter/planners/hotel-planner/address.aspx?id=" + id);
		//document.getElementById("daddr").value=tempjunk.trim();
		myPoints[z][id].openInfoWindowHtml("<div class='infowindow'>" + html + "</div>", { maxWidth: 310 }); 
	});
	
	GEvent.addListener(myPoints[z][id], "infowindowopen", function() { 
		document.getElementById("saddr").value = $.cookie("myaddress");
	});
	
	map.addOverlay(myPoints[z][id]);
}


function mapclick(i, x, y) { toggleOpen();  GEvent.trigger(myPoints[1][i], "click"); scrollTo(x, y);   return false; }

function toggleOpen(){ $('#map_holder').stop().animate({height: '320'},900); }

function initialize(lat, lon) {
	if (GBrowserIsCompatible()) {
    
		map = new GMap2(document.getElementById("map_canvas"));
		map.addControl(new GLargeMapControl3D());
		map.enableDoubleClickZoom();
		map.setCenter(new GLatLng(lat, lon), 11);

	}
	
	
	$(".gmnoprint").css("z-index", "100");
	
	
}
	
function getremotevalue(url){
	var content = '';

	if (window.XMLHttpRequest) {
		request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (request){
		request.open("GET", url, false);
		request.send(null);

		if (request.status == 200) {
			content = request.responseText;
		} else {
			content = 'Error: ' + request.status + ' ' + request.statusText;
		}
	}
	return content;
}

function domPDFhtml(){
	document.getElementById("domHTML").value = $("#map_table").html();
}

function changeMapView(val){
	temp = val.split(',');
	if(temp.length == 3){
		map.setCenter(new GLatLng(temp[0], temp[1]), parseInt(temp[2]));
	}
}

function thicboxCleanup(){
	
	if(document.getElementById("email-copy")){
		if(document.getElementById("email-copy").value==""){
			alert("Please add a message for your email.");
			return false;
		}
	
		if(document.getElementById("emails").value==""){
			alert("Please enter one or more email addresses to continue");
			return false;
		}
	}
	
	
	var checkboxes = "";
	$('input:checkbox').each(function(){ if(this.checked){ checkboxes = checkboxes + "--" + this.value; } });
	document.getElementById("ids").value=checkboxes;
	tb_remove();
	return true;
}

function checkChecked(){
		var checkboxes = "";
		$('input:checkbox').each(function(){ if(this.checked){ checkboxes = checkboxes + "--" + this.value; } });

		if(checkboxes==""){
			alert("Please select one or more hotels to display on your map");
			return false;
		} else {
			return true;
		}

}

function remove_img(){ 
	$("#uploaded-image-ref").css("display", "none"); 
	$.cookie("_ccm-logo", "");
}

function getDirections(){ $.cookie("myaddress", document.getElementById("saddr").value, { expires: 180, path: '/' }); window.open("http://maps.google.com/maps?f=d&source=s_d&hl=en&mra=ls&ie=UTF8&t=h&saddr=" + escape(document.getElementById("saddr").value) + "&daddr=" + escape(document.getElementById("daddr").value)); }

String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); };


