/*
	EMERSON COLLEGE
	PERFORMING ARTS APPLICATION
	
		Javasctipt: Map Functions

*/

function createLink_allMaps(address_1,city,state,zip,title) {
	
	// Determine Order
		var allMaps_order = new Array('google','mapquest','yahoo');
		
	// Constans
		var linker = new Array();
		var maptitle = new Array();
		
	// Standarize inputs
		var fixed_address1 = encodeURIComponent(address1);
		var fixed_city = encodeURIComponent(city);
		var fixed_state = encodeURIComponent(state);
		var fixed_zip = encodeURIComponent(zip);
		if (title == undefined) {
			var fixed_title = "";
		} else {
			var fixed_title = encodeURIComponent(title);
		}
	
	// Declare Text names of vendors
		maptitle['yahoo'] = "Yahoo! Maps";
		maptitle['google'] = "Google Maps";
		maptitle['mapquest'] = "MapQuest";
	
	// Get final links of each vendor
		linker['yahoo'] = createLink_yahoo(fixed_address_1,fixed_city,fixed_state,fixed_zip,fixed_title);
		linker['google'] = createLink_google(fixed_address_1,fixed_city,fixed_state,fixed_zip,fixed_title);
		linker['mapquest'] = createLink_mapquest(fixed_address_1,fixed_city,fixed_state,fixed_zip,fixed_title);
		
	// Generate the final code block
		finalOutput = "<b>Maps:</b> ";
		
		// Loop for each vendor
			for (i=0;i<allMaps_order.length;i++) {
				
				finalOutput += '<a href="'+linker[allMaps_order[i]]+'" target="_blank">'+maptitle[allMaps_order[i]]+'</a>';
				
				if (i != (allMaps_order.length - 1) ) {
					finalOutput += ' | ';
				}
				
			}
		
		return finalOutput;
}

function createLink_google(address_1,city,state,zip,title) {
	
	// Create vars
		var baceURL = "http://maps.google.com/maps?oi=map";
		if (zip != "") {
			var q = "&amp;q="+address_1+"%2C"+city+"%2C"+state+"%20"+zip;
		} else {
			var q = "&amp;q="+address_1+"%2C"+city+"%2C"+state;
		}
		if (title != "") {
			var t = "&nbsp;("+title+")";
		} else {
			var t = "";
		}
		var combinedURL = baceURL+q+t;
		
	// Return full HREF
		return combinedURL;
		
}

function createLink_mapquest(address_1,city,state,zip,title) {
	
	// Create vars
		var baceURL = "http://www.mapquest.com/maps/map.adp?country=US";
		var addressURL = "&amp;address="+address_1;
		var cityURL = "&amp;city="+city;
		var stateURL = "&amp;state="+state;
		if (zip != "") {
			var zipcodeURL = "&amp;zipcode="+zip;
		} else {
			var zipcodeURL = "";
		}
		if (title != "") {
			var titleURL = "&amp;title="+title;
		} else {
			var titleURL = "";
		}
		
		var combinedURL = baceURL+addressURL+cityURL+stateURL+zipcodeURL+titleURL;
		
	// Return full HREF
		return combinedURL;
		
}

function createLink_yahoo(address_1,city,state,zip,title) {
	
	// Create vars
		var baceURL = "http://maps.yahoo.com/py/maps.py?Pyt=Tmap";
		var address_1 = "&amp;addr="+address1;
		if (zip != "") {
			var csz = "&amp;csz="+city+"%2c"+state+"%20"+zip;
		} else {
			var csz = "&amp;csz="+city+"%2C"+state;
		}
		if (title != "") {
			var titleURL = title;
		} else {
			var titleURL = "";
		}
		var combinedURL = baceURL+address_1+csz;
		
	// Return full HREF
		return combinedURL;
		
}

