// JavaScript Document

distributorMapLinks = function() {
	
	var mapAreas = $$('area');

	// loop through all area tags
	for (var i=0; i< mapAreas.length; i++){

		var area = mapAreas[i];
		var relAttribute = String(area.getAttribute('rel'));
		var classAttribute = String(area.getAttribute('name'));

		if (!relAttribute.match('223') && classAttribute.match('COUNTRY')){
			area.onclick = function () { distributorSelectCountry(this); return false; }
		}
		else if (classAttribute.match('REGION')) {
			area.onclick = function () { distributorSelectRegion(this); return false; }
		}
	}

}

distributorSelectCountry = function (country) {

	// Populate the distributors list from the database...
	var ajax = new Ajax.Request('/actions/distributors.asp?type=country&id=' + $(country).getAttribute('rel'), {
		method: 'get',
		requestHeaders: {Accept: 'text/html'},
		onSuccess: function(transport) {

			var response = transport.responseText;
			$('divListContainer').update(response);

		},

	  	onFailure: function(transport){ alert('There was an error sending the data') }

	});

	
}

distributorSelectRegion = function (region) {

	// Populate the distributors list from the database...
	var ajax = new Ajax.Request('/actions/distributors.asp?type=region&id=' + $(region).getAttribute('rel'), {
		method: 'get',
		requestHeaders: {Accept: 'text/html'},
		onSuccess: function(transport) {

			var response = transport.responseText;
			$('divListContainer').update(response);

		},

	  	onFailure: function(transport){ alert('There was an error sending the data') }

	});

	
}

Event.observe(window, 'load', distributorMapLinks, false);
