


var numTestimonials = 9;



var index=Math.floor(Math.random()*numTestimonials);;



function init() {
	if (window.showMap === undefined) {
		
	}
	else {
		loadMap();
	}
}
	






function fadeOut(){

	new Effect.Opacity('testimonialTable', { duration: 1.0, transition: Effect.Transitions.linear, from: 1.0, to: 0 });

	window.setTimeout("fadeIn()", 1000);

}



function fadeIn(){

	var temp = index;

	while(index == temp)

		temp = Math.floor(Math.random()*numTestimonials);

	index = temp;

	var testDiv = document.getElementById('testimonials');

	testDiv.innerHTML = texts[index];

	new Effect.Opacity('testimonialTable', { duration: 0.5, transition: Effect.Transitions.linear, from: 0, to: 1.0 });

}


function verifyAddress(address, returnFunction) {
	var geocoder = new GClientGeocoder();
	geocoder.getLatLng(
		address,
		function(point) {
			if (!point) {
				returnFunction(null);
			} else {
				returnFunction(point);
			}
		}
	);
}


/*
	This function is just to update the dealers database with Latitudes and Longitudes.
	To update, uncomment the call to setGeoPoints() and then click OK on all of the proceeding
	alert boxes. For dealers with no address in the database their Lats and Longs are left as Null.
*/
function setGeoPoints() {
	var address;
	var geocoder = new GClientGeocoder();
	if (fullAddress) {
		address = addresses[curAddressIndex]["Address 1"] + " " + addresses[curAddressIndex]["Address 2"] + " " + addresses[curAddressIndex]["Billing City"] + " " + addresses[curAddressIndex]["Billing State"];
	} else {
		address = addresses[curAddressIndex]["Billing City"] + " " + addresses[curAddressIndex]["Billing State"];
	}
	geocoder.getLatLng(
		address,
		function(point) {
			if (!point) {
				if (!fullAddress) {
					fullAddress = true;
					curAddressIndex++;
					e = true;
					alert(address + ": address not found twice");
				} else {
					fullAddress = false;
					alert("address not found once");
				}
				setGeoPoints();
			} else {
				fullAddress = true;
				assignValues(point);
			}
		}
	);
}

function assignValues(point) {
	addresses[curAddressIndex]["Latitude"] = point.y;
	addresses[curAddressIndex]["Longitude"] = point.x;
	curAddressIndex++;
	if (curAddressIndex < addresses.length) {
		alert(curAddressIndex);
		setGeoPoints();
	} else {
		alert("should be updating database now");
		updateDatabase();
	}
}
