// browser window
function MM_openBrWindow(theURL,winName,features) { //v2.0
	var win_position = ',left=150,top=150,screenX=150,screenY=150';
	window.open(theURL,winName,features+win_position);
	newWindow.focus();
}
// radial button redirection
function usePage(frm,nm){
	for (var i_tem = 0, bobs=frm.elements; i_tem < bobs.length; i_tem++)
	if(bobs[i_tem].name==nm&&bobs[i_tem].checked)
	frm.action=bobs[i_tem].value;
}
/**********************
	DISTANCE PROGRAM
***********************/
// GRISSOM
var geocoder, location1, location2, gDir;
function initialize() {
	geocoder = new GClientGeocoder();
	gDir = new GDirections();
	GEvent.addListener(gDir, "load", function() {
		var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
		drivingDistanceMiles *= 100;
		drivingDistanceMiles = Math.round(drivingDistanceMiles);
		drivingDistanceMiles /= 100;
		
		var drivingDistanceKilometers = gDir.getDistance().meters / 1000;
		
		if(drivingDistanceMiles > 4.0){
			document.getElementById('results').innerHTML = '<strong>Distance to Grissom Location: </strong>' + drivingDistanceMiles + ' miles.....<span style="color:#FF0000;">X</span>';
		} else {
			document.getElementById('results').innerHTML = '<strong>Distance to Grissom Location: </strong>' + drivingDistanceMiles + ' miles.....<span><img src="../images/CheckMark.jpg" width="12" height="12" alt="You are eligable for delivery!">&nbsp;<a style="color:#33FF00; text-decoration: underline; font-style:italic;" href="orderonline/grissom_delivery/" target="_self">Click here to continue</a></span>';
		}
	});
}
function showLocation() {
	geocoder.getLocations(document.forms[0].address1.value, function (response) {
		if (!response || response.Status.code != 200) {
			alert("Sorry, we couldn't find your address. Please enter in a new one.");
		} else {
			location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
			geocoder.getLocations(document.forms[0].address2.value, function (response) {
				if (!response || response.Status.code != 200) {
					alert("Sorry, we couldn't find your address. Please enter in a new one.");
				} else {
					location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
					gDir.load('from: ' + location1.address + ' to: ' + location2.address);
				};
			});
		};
	});
};

// POTRANCO
var geocoder2, location3, gDir2;
function initialize2() {
	geocoder2 = new GClientGeocoder();
	gDir2 = new GDirections();
	GEvent.addListener(gDir2, "load", function() {
		var drivingDistanceMiles = gDir2.getDistance().meters / 1609.344;
		drivingDistanceMiles *= 100;
		drivingDistanceMiles = Math.round(drivingDistanceMiles);
		drivingDistanceMiles /= 100;
		
		var drivingDistanceKilometers = gDir2.getDistance().meters / 1000;
		
		if(drivingDistanceMiles > 4.0) {
			document.getElementById('results2').innerHTML = '<strong>Distance to Potranco Location: </strong>' + drivingDistanceMiles + ' miles.....<span style="color:#FF0000;">X</span>';
		} else {
			document.getElementById('results2').innerHTML = '<strong>Distance to Potranco Location: </strong>' + drivingDistanceMiles + ' miles.....<span><img src="../images/CheckMark.jpg" width="12" height="12" alt="You are eligable for delivery!">&nbsp;<a style="color:#33FF00; text-decoration: underline; font-style:italic;" href="orderonline/potranco_delivery/" target="_self">Click here to continue</a></span>';
		};
	});
};
function showLocation2() {
	geocoder2.getLocations(document.forms[0].address1.value, function (response) {
		if (!response || response.Status.code != 200) {
			alert("Sorry, we couldn't find your address. Please enter in a new one.");
		} else {
			location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
			geocoder2.getLocations(document.forms[0].address3.value, function (response) {
				if (!response || response.Status.code != 200) {
					alert("Sorry, we couldn't find your address. Please enter in a new one.");
				} else {
					location3 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
					gDir2.load('from: ' + location1.address + ' to: ' + location3.address);
				};
			});
		};
	});
};
