////////////////////////////////////////////////////////////////////////////////////////////////////////////
// variable defaults
var tciHasSecondAddr = false;
var tciSecondAddr = '';
var tciSecondAddrForGM = '';
var dealerSecondAddForDirInput = '';

// constructs form input for Google Maps daddr (dealerAddrForGM set in dealer_display.xsl)
var dealerAddForDirInput = "<input value='" + dealerAddrForGM + "' type='hidden' name='daddr' />";

////////////////////////////////////////////////////////////////////////////////////////////////////////////
// determines what server we are on so as to call the proper google code 

var thisServer  = window.location.hostname;

var googleCert = '';

if (thisServer == 'lexus2.freeflight.it.devlin.ca') {
	googleCert = 'ABQIAAAAShc3sokCAXRlI2avqYje-BTR3YC8Dq74MfUkhPB3pRPdqO956hRZXbDY4KGa6RyTOrikvsgZo6S5eA';
}

if (thisServer == 'lexus1.freeflight.it.devlin.ca') {
	googleCert = 'ABQIAAAAShc3sokCAXRlI2avqYje-BQ9x9XyPX1VOlRSbz6sQFpVle-VChTfgU-CStgUkC9U62oxcoX7pzOA2w';
}

if (thisServer == 'mnt.lexus.seth.it.devlin.ca') {
	googleCert = 'ABQIAAAAShc3sokCAXRlI2avqYje-BRXKpRJwOeX_vyAsCd_jgp_gXLT9BT135qtIfhOPnmuwyU_mP-DT3PGPQ';
}

if (thisServer == 'pubmnt.staging.lexus.ca') {
	googleCert = 'ABQIAAAAShc3sokCAXRlI2avqYje-BRgKWPc00xFr_mkXrTuRGalc0mdtBQltajAW67NwecAiK4PWM9N7e-hiQ';
}

if (thisServer == 'www.lexus.ca') {
	googleCert = 'ABQIAAAAShc3sokCAXRlI2avqYje-BTyp2hKK9Q84EL266Pnauhb_cnWUxTNFLZnCztq25PH0Lw82ZENl7qmsg';
}		

// this script calls the appropriate code from Google for the base address
var googleCodeCall = '<scr'+ 'ipt src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=' + googleCert + '"  type="text/javascript"></scr' + 'ipt>';


//////////////////////////////////////////////////////////////////////////////////////////////////////////
// initializes variables for second address map for Parts & Service (some variables set in dealer_display.xsl)

function tciInitializeSecond(dealername) {
	
	tciHasSecondAddr = true;
		
	switch(dealername) {
		case 'Regency Lexus' :
			tciSecondAddr = '620 Evans Ave<br />Vancouver, BC<br />V6A 2K9';
			tciSecondAddrForGM = '620 Evans Ave, Vancouver, BC, V6A 2K9';
			break;
		case 'Spinelli Lexus' :
			tciSecondAddr = '561 boul. St-Joseph<br />Lachine, QC<br />H8S 2K9';
			tciSecondAddrForGM = '561 boul. St-Joseph, Lachine, QC, H8S 2K9';
			break;
		case 'Lexus On the Park' :
			tciSecondAddr = '1083 Leslie St<br/>Toronto, ON<br/>M3C 2J7';
			tciSecondAddrForGM = '1083 Leslie St, Toronto, ON, M3C 2J7';
			break;			
		default : 
			tciSecondAddr = '';	
			break;
	}

	// constructs form input for second Google Maps daddr
	dealerSecondAddForDirInput = "<input value='" + tciSecondAddrForGM + "' type='hidden' name='daddr' />";

	
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// loads a Google Map into a div
function loadDealerMapGM(targetDiv, targetAddress) {
	if (GBrowserIsCompatible()) {

		var map = new GMap2(document.getElementById(targetDiv));

		map.addControl(new GLargeMapControl());
		map.enableDoubleClickZoom();

		function createMarker(point) {
			var toyIcon = new GIcon();
			toyIcon.image = "/images/gmaps/icon_logo.png";
			toyIcon.shadow = "/images/gmaps/icon_shadow.png";
			toyIcon.iconSize = new GSize(29, 31);
			toyIcon.shadowSize = new GSize(38, 31);
//			toyIcon.iconAnchor = new GPoint(29, 31);
			toyIcon.iconAnchor = new GPoint(15, 31);
			toyIcon.infoWindowAnchor = new GPoint(15, 1);

			map.setCenter(point, 15);

			var marker = new GMarker(point,toyIcon);

			return marker;
		}


		function createMarkerForAddress(place) {
			var geocoder = new GClientGeocoder();
			geocoder.getLatLng(place,function (point) {
						if (!point) {
							alert(dealerAddrForGM + " not found");
						} else {
							 var dealerMarker = createMarker(point);
							 map.addOverlay(dealerMarker);
						}
					}
				);
		}

		createMarkerForAddress(targetAddress);
		

	}
}

