//	cTable Javascript - Copyright (C) 2007-2010 Charles A Upsdell, All Rights Reserved; www.upsdell.com
//
//  Methods to manage names of locations


Array.prototype.addLocation = function ( name, location )
{
var $name = 'addLocation';
var $argc = arguments.length;
var isDuplicateOkay = false;
if ( ($argc > 0) && ((typeof(arguments[$argc-1])) == 'boolean') )
	isDuplicateOkay = arguments[--$argc];
if ( $argc < 2 )
	{ 'Array'.alert( $name, 'missing name and/or location' ); return; }
var sAssoc = '';
if ( typeof(calOurAssociation) != 'undefined' )
	sAssoc = 'assoc=' + calOurAssociation + '&amp;';

if ( name instanceof Array )
  {
	if ( name.length > 0 )
		this.addLocation( name[0], location );
	for ( var i = 1; i < name.length; ++i )
		this.addLocation( name[0] + ' ' + name[i], location );
  }
else if ( $argc > 2 )
  {
	var i = 1;
	if ( ($argc)%2 == 0 )
		this.addLocation( name, arguments[i++] );
	for ( ; i < $argc; i+=2 )
		this.addLocation( name + ' ' + arguments[i], arguments[i+1] );
  }
else
  {
	if ( this[name] === undefined )
	  {
		location = location.toString();
		var sExtraSpace = (location.charAt(0) == ' ') ? ' ' : '';
		location = location.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
		if ( location.indexOf('<a ') != -1 )
			;
		else if ( location.indexOf('http') == 0 )
			location = '<a ' + sExtraSpace + 'href="' + location + '" class="cal_location">';
		else if ( location.indexOf('www.') == 0 )
			location = '<a ' + sExtraSpace + 'href="http://' + location + '" class="cal_location">';
		else if ( (location.indexOf('locn=') == 0) || (location.indexOf('area=') == 0) )
			location = '<a ' + sExtraSpace + 'href="http://www.upsdell.com/cgi-bin/mmba_map.pl?' + sAssoc + location + '" class="cal_location">';
		else if ( location.indexOf('arenas/') == 0 )
			location = '<a ' + sExtraSpace + 'href="http://www.arenamaps.com/' + location + '.htm" class="cal_location">';
		if ( location.indexOf('</a>') == -1 )
			location += name + '</a>';
		this[name] = location;
	  }
	else if ( !isDuplicateOkay )
		{ 'Array'.alert( $name, 'duplicate name', name ); return; }
  }
}


Array.prototype.getLocation = function ( name )
{
var rv = '';
if ( name !== undefined )
  {
	if ( (name.length > 0) && (name.charAt(0) == '@') )
		return calMakeUrl( name, 'cal_location' );
	var sSpace = '';
	if ( name.charAt(0) == ' ' )
	  {
		sSpace = ' ';
		name = name.substring(1);
	  }
	rv = this[name];
	if ( rv === undefined )
		rv = name;
	rv = sSpace + rv;
  }
return rv;
}


