
/*
Brazil - 		Montevideo@sivananda.org
NeyyarDam- 		YogaIndia@sivananda.org
Nassau - 		Nassau@sivananda.org
Reith, tyrol - 	Reith@sivananda.org
Netala - 		Delhi@sivananda.org
England - 		London@sivananda.org
GrassValley - 	YogaFarm@sivananda.org
Luthivania - 	Berlin@sivananda.org
WoodBourne - 	YogaRanch@sivanada.org
ValMorin - 		Hqaccounts@sivananda.org
Orleans - 		Orleans@sivananda.org
Spain - 		Madrid@sivananda.org
Austria - 		Reith@sivananda.org
Madurai - 		YogaIndia@sivananda.org
*/

// a null location
var nolocation	= new Location ( "", "", "" );

/* Section for Location Objects - set these after the Location() function above */ 
var camp        			= new Location ( "Val Morin, Canada",           "/camp/",									"registrations@sivananda.org" );    
var dorset      			= new Location ( "England",         		    "/ttceurope/",								"London@sivananda.org" );
var farm        			= new Location ( "Grass Valley, California",    "/farm/",									"YogaFarm@sivananda.org" );
var ranch       			= new Location ( "Woodbourne, NY, USA",         "/ranch/",									"YogaRanch@sivananda.org" );
var meissen     			= new Location ( "Meissen, Germany",            "/ttceurope/",								"Berlin@sivananda.org" );
var nassau      			= new Location ( "Nassau, Bahamas",             "/nassau/",									"Nassau@sivananda.org" ); // http://www.my-yoga.net
var orleans     			= new Location ( "Orleans, France",             "/orleans/",								"Orleans@sivananda.org" );
var reith       			= new Location ( "Reith, Tyrol, Austria",       "/tyrol/",									"Reith@sivananda.org" );
var mittersill  			= new Location ( "Mittersill, Austria",         "/tyrol/",									"Reith@sivananda.org" );
var spain       			= new Location ( "Spain",                       "/madrid/ttc/introduction_en.html",			"Madrid@sivananda.org" );
var cuenca      			= new Location ( "Spain",           		    "/madrid/ttc/introduction_en.html",			"Madrid@sivananda.org" );
var uruguay     			= new Location ( "Uruguay",                     "/montevideo/",								"Montevideo@sivananda.org" );
var garopaba    			= new Location ( "Brasil&#134;",      	      "/montevideo/mailing-ttc-2008/ttc_2008eng.htm ",				"Montevideo@sivananda.org" );
var garopaba_attc			= new Location ( "Brasil&#134;",      			"/montevideo/mailing-attc-2008/attc_2008.htm",				"Montevideo@sivananda.org" );
var santillana  			= new Location ( "Spain", 					    "/madrid/ttc/introduction_en.html",			"Madrid@sivananda.org" );
var lithuania 				= new Location ( "Palanga, Lithuania", 			"/ttceurope/",								"Berlin@sivananda.org" );
var austria     			= new Location ( "Austria",                 	"/ayurveda-europe",							"Reith@sivananda.org" );
var poland	 					= new Location ( "Poland", 						"/ttceurope/",								"Berlin@sivananda.org" );
                			
var london      			= new Location ("London, England",              "/london/",									"London@sivananda.org");
var scotland      			= new Location ("Scotland, U.K.",              "/london/",									"London@sivananda.org");
var berlin      			= new Location ("Berlin, Germany",              "/berlin/",									"Berlin@sivananda.org");
var munich      			= new Location ("Munich, Germany",              "/munich/",									"munich@sivananda.org");
var vienna      			= new Location ("Vienna, Austria",              "/vienna/",									"vienna@sivananda.org");
var geneva      			= new Location ("Geneva, Switzerland",          "/geneva/",									"geneva@sivananda.org");
var rome     					= new Location ( "Rome, Italy",	                 "/rome",									"rome@sivananda.org" );
var madrid      			= new Location ("Madrid, Spain",                "/madrid/",									"Madrid@sivananda.org");
var paris       			= new Location ("Paris, France",                "/paris/",									"paris@sivananda.org");
var buenosaires 			= new Location ("Buenos Aires, Argentina",      "/buenosaires/",							"buenosaires@sivananda.org");
var mardelplata  			= new Location ("Mar del Plata, Argentina",      "/buenosaires/",							"buenosaires@sivananda.org");
var montevideo  			= new Location ("Montevideo, Uruguay",          "/montevideo/",								"montevideo@sivananda.org");
var chicago     			= new Location ("Chicago, IL, USA",             "/chicago/",								"chicago@sivananda.org");
var newyork     			= new Location ("New York City, USA",           "/ny/",										"");
var sanfrancisco			= new Location ("San Francisco, USA",          "http://www.sfyoga.com/",					"sanfrancisco@sivananda.org");
var losangeles  			= new Location ("Los Angeles, USA",             "/la/",										"losangeles@sivananda.org");
var telaviv     			= new Location ("Tel Aviv, Israel",             "http://www.my-yoga.org/",					"telaviv@sivananda.org");
var toronto     			= new Location ("Toronto, Canada",              "/toronto/index.html",						"toronto@sivananda.org");
var montreal    			= new Location ("Montreal, Canada",             "/montreal/",								"montreal@sivananda.org");
var delhi       			= new Location ("Nataraja, Delhi, India",       "/delhi/",									"Delhi@sivananda.org");
var delhi_dwarka			= new Location("Dwarka, Delhi India",			"/delhi/",									"dwarka@sivananda.org");
var madras      			= new Location ("Chennai, India",               "/madras/",									"madras@sivananda.org");
var chennai						= new Location ("Chennai, India",           	"/madras/",									"madras@sivananda.org");
var trivandrum  			= new Location ("Trivandrum, Kerala, India",    "/trivandrum/",								"trivandrum@sivananda.org");
var madurai     			= new Location ("Madurai, India",           	"/maduraicentre/",							"maduraicenter@sivananda.org");
var vrindavan					= new Location ( "Vrindavan North India",		"/reith/",									"Reith@sivananda.org" );

var maduraiashram 		= new Location ("Madurai, India",           	"/madurai/",								"YogaIndia@sivananda.org");
var netala      			= new Location ( "Netala, U' Kashi, India",     "/uttarkashi/",								"YogaIndia@sivananda.org" );
var neyyardam   			= new Location ( "Neyyar Dam, India",           "/neyyardam/",								"YogaIndia@sivananda.org" );
var portoalegre 			= new Location ( "Porto Alegre, Brasil",		"http://www.yogasivananda.com.br/poa/",		"centro@yogasivananda.com.br" );
var riodejaneiro 			= new Location ( "Rio de Janeiro, Brasil",		"http://www.yogasivananda.com.br/rio/",		"yogasivananda@gmail.com" );

var petachtikva = nolocation;


var dd_locations_array = new Array(
                 
    new Location( " -- Yoga Ashrams & Centers -- ", "/locations/", ''),
    new Location( " ",                              "#", ''),                     
    new Location( " -- ASHRAMS WORLDWIDE -- ",      "/locations/ashrams.html", ''),                       
    new Location( "Quebec",                         camp.url, ''),                       
    new Location( "New York",                       ranch.url, ''),                         
    new Location( "California",                     farm.url, ''),                     
    new Location( "Bahamas",                        nassau.url, ''),                     
    new Location( "Austria",                        reith.url, ''),                         
    new Location( "France",                         orleans.url, ''),                          
    new Location( "Uttarkashi - North India",       netala.url, ''),              
    new Location( "Kerala - South India",           neyyardam.url, ''),
    new Location( "Madurai - South India",          maduraiashram.url, ''),
                 		  
    new Location( " ",                              "#", ''),                        
    new Location( " -- CENTERS NORTH AMERICA -- ",  "/locations/northamerica.html", ''),                      
    new Location( "Montreal",                       montreal.url, ''),                         
    new Location( "Toronto",                        toronto.url, ''),                            
    new Location( "New York",                       newyork.url, ''),                    
    new Location( "Chicago",                        chicago.url, ''),                       
    new Location( "Los Angeles",                    losangeles.url, ''),                     
    new Location( "San Francisco",                  sanfrancisco.url, ''),         
                          
    new Location( " ",                              "#", ''),                       
    new Location( " -- CENTERS SOUTH AMERICA -- ",  "/locations/southamerica.html", ''),                      
    new Location( "Buenos Aires",                   buenosaires.url, ''),  
    new Location( "Montevideo",                     montevideo.url, ''),  
              
    new Location( " ",                              "#", ''),                           
    new Location( " -- CENTERS EUROPE -- ",         "/locations/europe.html", ''),                         
    new Location( "London",                         london.url, ''),                         
    new Location( "Paris",                          paris.url, ''),                       
    new Location( "Madrid",                         madrid.url, ''),                         
    new Location( "Geneva",                         geneva.url, ''),               
    new Location( "Berlin",                         berlin.url, ''),                       
    new Location( "Munich",                         munich.url, ''),
    new Location( "Vienna",                         vienna.url, ''),                        
    new Location( "Rome",                         	rome.url, ''), 
              
    new Location( " ",                              "#", ''),     
    new Location( " -- CENTERS MIDDLE EAST -- ",    "/locations/mideast.html", ''), 
    new Location( "Petach Tiqva",                   "/locations/centers/index.html#pet", ''),                       
    new Location( "Tel Aviv",                       telaviv.url, ''),   
                                    
    new Location( " ",                              "#", ''),     
    new Location( " -- CENTERS INDIA -- ",          "/locations/india.html", ''),                     
    new Location( "New Delhi",                      delhi.url, ''),                          
    new Location( "Chennai",                        chennai.url, ''),        
    new Location( "Madurai",                        madurai.url, ''),                               
    new Location( "Trivandrum",                     trivandrum.url, ''),
    
    new Location( " ",                              "#", ''),                         
    new Location( " -- AFFILIATES -- ",             "/locations/affiliat.html", ''),                       
    new Location( "Centers",                        "/locations/affiliat.html", ''),                       
    new Location( "Teachers",                       "/locations/affiliated/outsteac.html", '' )
);




function get_plain_locations_array() {
	
	return new Array( 
			        
	    new Location( " -- Select Member Location -- ", "", ''),
	    new Location( " ",                              "", ''),  
	    new Location( "No Current Membership",          "", ''),  
	    new Location( " ",                              "", ''),                        
	    new Location( " CENTERS NORTH AMERICA",  			"", ''),                      
	    new Location( " -- Montreal",                       montreal.title, ''),                         
	    new Location( " -- Toronto",                        toronto.title, ''),                            
	    new Location( " -- New York",                       newyork.title, ''),                    
	    new Location( " -- Chicago",                        chicago.title, ''),                       
	    new Location( " -- Los Angeles",                    losangeles.title, ''),                     
	    new Location( " -- San Francisco",                  sanfrancisco.title, ''),         
	                          
	    new Location( " ",                              	"", ''),                       
	    new Location( " CENTERS SOUTH AMERICA",  			"", ''),                      
	    new Location( " -- Buenos Aires",                   buenosaires.title, ''),  
	    new Location( " -- Montevideo",                     montevideo.title, ''),  
	              
	    new Location( " ",                              	"", ''),                           
	    new Location( " CENTERS EUROPE",         			"", ''),                         
	    new Location( " -- London",                         london.title, ''),                         
	    new Location( " -- Paris",                          paris.title, ''),                       
	    new Location( " -- Madrid",                         madrid.title, ''),                         
	    new Location( " -- Geneva",                         geneva.title, ''),               
	    new Location( " -- Berlin",                         berlin.title, ''),                       
	    new Location( " -- Munich",                         munich.title, ''),
	    new Location( " -- Vienna",                         vienna.title, ''),                        
	    new Location( " -- Rome",                         	rome.title, ''), 
	              
	    new Location( " ",                              	"", ''),     
	    new Location( " CENTERS MIDDLE EAST",    			"", ''), 
	    new Location( " -- Petach Tiqva",                   "Petach Tiqva", ''),                       
	    new Location( " -- Tel Aviv",                       telaviv.title, ''),   
	                                    
	    new Location( " ",                              	"", ''),     
	    new Location( " CENTERS INDIA",          			"", ''),                     
	    new Location( " -- New Delhi",                      delhi.title, ''),                          
	    new Location( " -- Chennai",                        chennai.title, ''),        
	    new Location( " -- Madurai",                        madurai.title, ''),                               
	    new Location( " -- Trivandrum",                     trivandrum.title, ''),
		
	    new Location( " ",                              	"", ''),                     
	    new Location( " ASHRAMS WORLDWIDE",      			"", ''),                       
	    new Location( " -- Quebec",                         camp.title, ''),                       
	    new Location( " -- New York",                       ranch.title, ''),                         
	    new Location( " -- California",                     farm.title, ''),                     
	    new Location( " -- Bahamas",                        nassau.title, ''),                     
	    new Location( " -- Austria",                        reith.title, ''),                         
	    new Location( " -- France",                         orleans.title, ''),                          
	    new Location( " -- Uttarkashi - North India",       netala.title, ''),              
	    new Location( " -- Kerala - South India",           neyyardam.title, ''),
	    new Location( " -- Madurai - South India",          maduraiashram.title, '')
	);
}








/**
 * (Abstract) Class YogaLocation
 *
 * Base class for displaying location address/email/web-url in a consistently
 * formatted manner. Note that this class should be considered abstract, and
 * is not intended to be directly instantiated.
 */
function YogaLocation () {
	
	this.region		= '';
	this.city 		= '';
	this.center 	= '';
	this.contact	= '';
	this.street 	= '';
	this.citypost 	= '';
	this.phone 		= '';
	this.fax 		= '';
	
	// location, email, url are here for reference only,
	// they are created in the subclass	
	// this.location 	= location; // passed in argument to subclass constructor
	// this.email 		= location.email;
	// this.url 		= location.url;
	
	return this;
}



/**
 * Static properties
 */
YogaLocation.NORTH_AMERICA 		= "North America";
YogaLocation.SOUTH_AMERICA 		= "South America";
YogaLocation.EUROPE 			= "Europe";
YogaLocation.MIDDLE_EAST 		= "Middle East";
YogaLocation.INDIA 				= "India";
YogaLocation.REST_OF_WORLD 		= "Rest Of World";

//
// IMPORTANT:
// 	- The derived classes must define these variables:
//
// _MyDerivedClass_.northamerica_list	= new Array();
// _MyDerivedClass_.southamerica_list	= new Array();
// _MyDerivedClass_.europe_list			= new Array();
// _MyDerivedClass_.middleeast_list		= new Array();
// _MyDerivedClass_.india_list			= new Array();
// _MyDerivedClass_.restofworld_list	= new Array();
// _MyDerivedClass_.locations			= new Array();
// _MyDerivedClass_.l_length			= 0;
//



/**
 * public static void add_location( YogaLocation location )
 *
 * Adds the provided YogaLocation Object (derived as a subclass) to the subclass's
 * locations array property.
 *
 * param YogaLocation location - a YogaLocation (derived) object to add to the 
 *								 derived class's locations array.
 */
YogaLocation.add_location = function ( location ) {
	
	// since YogaLocation is subclassed, get the class of the object that invoked me
	var DerivedClass = location.constructor;
	
	// set the static properties for the class of the object that invoked me
	DerivedClass.locations[ DerivedClass.l_length ] = location;
	DerivedClass.l_length = DerivedClass.locations.length;
}




/**
 * public static void draw_all ( YogaLocation class_ref )
 *
 * Draws the table of all YogaLocations defined for the derived class. Outputs
 * the HTML required to display these.
 *
 * param YogaLocation class_ref - a class that has subclassed YogaLocation.
 */
YogaLocation.draw_all = function ( class_ref ) {
	
	var output = '';
	var DerivedClass = class_ref;
	
	var region_array = new Object();
	region_array.na = '';
	region_array.sa = '';
	region_array.eu = '';
	region_array.me = '';
	region_array.id = '';
	region_array.rw = '';
	
	for ( idx=0; idx<DerivedClass.l_length; idx++ ) {
		
		var location = DerivedClass.locations[idx];
		var location_info = location.draw_location_info();		
		var this_region_id = null;
		
		// figure out the region it belongs to, and populate the corresponding array
		switch ( location.region ) {
			
			case YogaLocation.NORTH_AMERICA:
				this_region_id = "na";
				break;
				
			case YogaLocation.SOUTH_AMERICA:
				this_region_id = "sa";
				break;
				
			case YogaLocation.EUROPE:
				this_region_id = "eu";
				break;
				
			case YogaLocation.MIDDLE_EAST:
				this_region_id = "me";
				break;
				
			case YogaLocation.INDIA:
				this_region_id = "id";
				break;
				
			case YogaLocation.REST_OF_WORLD:
				this_region_id = "rw";
				break;
		}
		
		
		// if it is empty, start with the section title (i.e. the region)
		if ( !region_array[this_region_id] ) { 
			region_array[this_region_id] += '<div class="header3" style="line-height:20px;margin:40px 0px 0px 0px;background-color:#efefef">' + location.region + '</div>';
		}
		
		// now add the location information
		region_array[this_region_id] += location_info;
	}
	
	
	output = (
				region_array.na
			+	region_array.sa
			+	region_array.eu
			+	region_array.me
			+	region_array.id
			+	region_array.rw
	);
	
	document.write( output );
}




/**
 * public static void TableOfContents ( YogaLocation class_ref )
 *
 * Draws a table of contents for all YogaLocations defined for the derived class. 
 * This table of contents is an organised listing of anchor-links for each location
 * which link to the actual address information elsewhere on the HTML page. Outputs
 * the HTML required to display these.
 *
 * param YogaLocation class_ref - a class that has subclassed YogaLocation.
 */
YogaLocation.TableOfContents = function ( class_ref ) {
	
	
	var na_header 	= '';
	var na_list		= '';
	var eu_header 	= '';
	var eu_list		= '';
	var rw_header 	= '';
	var rw_list		= '';
	var sa_header 	= '';
	var sa_list		= '';
	var me_header 	= '';
	var me_list		= '';
	var id_header 	= '';
	var id_list		= '';
	
	
	var region_output_array = YogaLocation._populate_region_arrays( class_ref );
	

	// this is a hack, clean this up some day...
	if ( region_output_array.na != '' ) {
		na_header = YogaLocation._get_region_header( YogaLocation.NORTH_AMERICA );
		na_list	  = YogaLocation._get_region_list( region_output_array.na );
	}
		
	if ( region_output_array.eu != '' ) {
		eu_header = YogaLocation._get_region_header( YogaLocation.EUROPE );
		eu_list	  = YogaLocation._get_region_list( region_output_array.eu );
	}
	
	if ( region_output_array.rw != '' ) {
		rw_header = YogaLocation._get_region_header( YogaLocation.REST_OF_WORLD );
		rw_list	  = YogaLocation._get_region_list( region_output_array.rw );
	}
	
	if ( region_output_array.sa != '' ) {
		sa_header = YogaLocation._get_region_header( YogaLocation.SOUTH_AMERICA );
		sa_list	  = YogaLocation._get_region_list( region_output_array.sa );
	}
	
	if ( region_output_array.me != '' ) {
		me_header = YogaLocation._get_region_header( YogaLocation.MIDDLE_EAST );
		me_list	  = YogaLocation._get_region_list( region_output_array.me );
	}
	
	if ( region_output_array.id != '' ) {
		id_header = YogaLocation._get_region_header( YogaLocation.INDIA );
		id_list	  = YogaLocation._get_region_list( region_output_array.id );
	}
		
	
	var table_output = (
			'<table cellpadding="5" cellspacing="0" border="0" width="100%">'
		  + 	'<tr> '
		  + 		na_header
		  + 		eu_header
		  + 		rw_header
		  + 	'</tr>'
		  +		'<tr>'
		  + 		na_list
		  +			eu_list
		  +			rw_list
		  + 	'</tr>'
		  + 	'<tr> '
		  + 		sa_header
		  + 		me_header
		  + 		id_header
		  + 	'</tr>'
		  +		'<tr>'
		  + 		sa_list
		  +			me_list
		  +			id_list
		  + 	'</tr>'
		  + '</table>'
	);
	
	document.write( table_output );
}




/**
 * private static String populate_region_arrays
 *
 * Reads each YogaLocation object, and populates the region-array that this
 * YogaLocation object belongs to (as defined in the object's configuration).
 *
 * param LocationClass - a reference to the subclass implementing YogaLocation
 *
 * returns (String) a formatted list of anchored locations
 */
YogaLocation._populate_region_arrays = function ( LocationClass ) {
	
	
	var region_array = new Object();
	region_array.na = '';
	region_array.sa = '';
	region_array.eu = '';
	region_array.me = '';
	region_array.id = '';
	region_array.rw = '';
	
	
	// read the entire array of defined YogaLocation objects
	for ( idx=0; idx<LocationClass.l_length; idx++ ) {
		
		var location = LocationClass.locations[idx];
		var toc_entry = '<div class="table-body" style="line-height:20px;margin:0px 0px 0px 0px"><a href="#' + location.id + '">' + location.city + '</a></div>';
		
		// figure out the region it belongs to, and populate the corresponding array
		switch ( location.region ) {
			
			case YogaLocation.NORTH_AMERICA:
				region_array.na += toc_entry;
				break;
				
			case YogaLocation.SOUTH_AMERICA:
				region_array.sa += toc_entry;
				break;
				
			case YogaLocation.EUROPE:
				region_array.eu += toc_entry;
				break;
				
			case YogaLocation.MIDDLE_EAST:
				region_array.me += toc_entry;
				break;
				
			case YogaLocation.INDIA:
				region_array.id += toc_entry;
				break;
				
			case YogaLocation.REST_OF_WORLD:
				region_array.rw += toc_entry;
				break;
		}
	}
	
	return region_array;
}






YogaLocation._get_region_header = function ( header ) {
	return '<td class="header5brown-plain">' + header + '</td>';
}





YogaLocation._get_region_list = function ( list ) {
	return '<td valign="top">' + list + '</td>';
}




/**
 * private String draw_location_info
 *
 * Builds a formatted paragraph containing the address and info for the location.
 * Override this method for customized display/formatting of the location addresses.
 *
 * returns (String) the formatted address paragraph
 */
YogaLocation.prototype.draw_location_info = function () {
		
	var showcenter = '';
	if ( this.center ) {
		showcenter 		= '<br>' + this.center;
	}
	
	var showcontact = '';
	if ( this.contact != '' ) {
		showcontact 	= '<br>' + this.contact;
	}
	
	var showstreet = ''
	if ( this.street ) {
		showstreet 		= '<br>' + this.street + ',';
	}
	
	var showcitypost = '';
	if ( this.citypost ) {
		showcitypost	= '<br>' + this.citypost;
	}
	
	var showphone = '';
	if ( this.phone ) {
		showphone 		= '<br>Tel: ' + this.phone;
	}
	
	var showfax = '';
	if ( this.fax != '' ) {
		showfax 		= '<br>Fax: ' + this.fax;
	}
	
	var showemail = '';
	if ( this.email != '' ) {
		showemail 		= '<br>E-mail: <a href="mailto:' + this.email + '">' + this.email + '</a>';
	}
		
	var website_href = this.city; // default is no href, just plain text...
	var showurl = '';
	if ( this.url != '' ) {
		website_href = '<a href="' + this.url + '" target="yogalocation">' + this.city + '</a>';
		showurl		 = '<br>Web: <a href="' + this.url + '" target="yogalocation">' + this.url + '</a>';
	}
	var location_label = '<div class="header5brown-plain" style="margin:15px 0px 0px 0px">' + website_href + '</div>';
	
	
	
	var output_info = (
			  
			    '<div style="margin:0px 0px 0px 40px">'
			  + '<a name="' + this.id + '">&nbsp;</a>'
			  + location_label
			  + '<div class="table-body" style="margin:-8px 0px 0px 20px;line-height:15px">'
			  + 	showcenter
			  +		showcontact
			  + 	showstreet
			  + 	showcitypost
			  + 	showphone
			  + 	showfax	
			  + 	showemail
			  +		showurl
			  + '<br><br><a href="#top" class="footer-colored">back to top</a>'
			  + '</div></div>'
	);
	
	return output_info;
}










