
function getlangFromPage(){
    
  var t = document.getElementsByTagName("html")[0];
  var att = t.attributes["xml:lang"];
  att = att ? att : t.attributes["lang"];
  var ldang = att ? att.value : "en";
  
  return ldang;
}
	var URL = 'http://maps.maporama.com/idl/accor/process.aspx?xsl=worldmap&xml=world&Lang='  ;
	var origin = domain_select(); // 'ALL' == accorhotels
	var domainmap = '&siteOrigine='+ origin ;
	var bSelect = '&SA_config=';
	var bSelectValue= new Array();
		bSelectValue['all']='All';
			bSelectValue['sea']=				'Sea';
			bSelectValue['mountain']=			'Mount';
			bSelectValue['thalasso']=	'Thal';
			bSelectValue['spa'] =			'Club' ;

function mapo_site(selection)
{
	var lg = getlangFromPage() ;
	var lgmap = lg.substring(0,1).toUpperCase() + lg.substring(1,2);
	if(origin == 'ALL') {	// pas sur que ces elements existent sur les marques
		$('isite').addClassName('on');
		$('icarte').removeClassName('on');
		$('iadresse').removeClassName('on');
		$('photo').src = '../images/reservation/bandeau-site.jpg';
	}
	if(typeof selection == "undefined") selection = '';
	document.getElementById('themap').src = URL+ lgmap+domainmap+bSelect+bSelectValue['all']+'&GeoSearch=site'+selection;
}
function mapo_adresse(selection)
{
	var lg = getlangFromPage() ;
	var lgmap = lg.substring(0,1).toUpperCase() + lg.substring(1,2);
	if(origin == 'ALL') { // pas sur que ces elements existent sur les marques
		$('iadresse').addClassName('on');
		$('icarte').removeClassName('on');
		$('isite').removeClassName('on');
		$('photo').src = '../images/reservation/bandeau-adresse.jpg';
	}
	document.getElementById('themap').src = URL+ lgmap+domainmap+bSelect+bSelectValue['all']+'&GeoSearch=adr'+selection ;
}
function domain_select()
{
	switch(document.domain) { /* ou location.host */
/*		case 'www.novotel.com' :		case 'novotel.com' :		return 'NOV&NOV=1' ; break; // + brands selection...
		case 'www.mercure.com' :		case 'mercure.com' :		return 'MER&MER=1&MGA=1' ; break; // + cacher block "brands"
		
		case 'www.accorhotels.com' :		case 'accorhotels.com' :
*/		default :
		return 'ALL';
	}
}
function mapo_url() {  
	var lg = getlangFromPage() ;
	
	var lgmap = lg.substring(0,1).toUpperCase() + lg.substring(1,2);

	var where = window.location.toString() ;
	var coupe = where.lastIndexOf('#') ;
	var selection = '';
	var action ='normal' ;
	
	if (coupe != -1) {
		var arg = where.substring(coupe+1, where.length);
		var arguments_arr = arg.split('&');
		for (var i =0 ; i < arguments_arr.length ; i++) {
			var dd = arguments_arr[i].split('=');
			
			// selection += '&' brands
			if(dd[0]=='Brands' && origin == 'ALL') { // il ne doit pas etre possible de rajouter un brand sur un site marque
				selection += '&Brand=1' ; // a priori, on ouvre le bloc marques...
				var allbrands = dd[1].split('|') ;
				reg = new RegExp('HLB|PUL|SOF|MER|MGA|NOV|SUI|CM|ASE|IBI|ETP|FOR|MOT|VIL|STD|COR','');
				for (var j =0 ; j < allbrands.length ; j++)
					if (reg.test(allbrands[j]))
						selection += '&'+allbrands[j] + '=1' ;
				/*-	Lucien Barrière : &HLB=1
					-	Pullman : &PUL=1
					-	Sofitel : &SOF=1
					-	Mgallery : &MGA=1
					-	Novotel : &NOV=1
					-	Mercure : &MER=1
					-	Suitehotel : &SUI=1
					-	Club Med : &CM=1
					-	All Seasons : &ASE=1
					-	Ibis : &IBI=1
					-	Etap Hotel : &ETP=1
					-	Formule 1 : &FOR=1
					-	Motel 6 : &MOT=1
					-	Villages Hotel : &VIL=1
					-	Studio 6 : &STD=1
					-	Coralia : &COR=1
					24/09 : a priori ca fonctionnerait dans l'autre sens. Ingérable !!
					*/
			}
			// selection += '&' services
			if(dd[0]=='Services') {
				var allservices = dd[1].split('+') ; // REST+POOL+PARK+MEET+PETS+WIFI
				reg = new RegExp('rest|pool|park|meet|pets|wifi','i');
				for (var j =0 ; j < allservices.length ; j++) {
					if (reg.test(allservices[j]))
						selection += '&'+ allservices[j].substring(0,1).toUpperCase() + allservices[j].substring(1).toLowerCase() + '=1' ;
				}
/*« Services&equipements » :
-	Restaurant: &Rest=1
-	Piscine: &Pool=1
-	Parking: &Park=1
-	Salle de reunion: &Meet=1
-	Animaux acceptés: &Pets=1
-	Wifi : &Wifi=1
*/			}
			// selection += '&' regions
			if(dd[0]=='Area') {
			}
			
			if(dd[0]=='GeoSearch') {
				switch(dd[1]){
					case 'adr' :  	action = 'address' ;				break;
					case 'site' : 	action = 'site' ; 					break;
/*					default :
					document.getElementById('themap').src = URL+ lgmap+domainmap+bSelect+bSelectValue['all']+selection;					
*/				}
			}
			if(dd[0]=='ThemaSearch') {
				switch(dd[1]){
					case 'sea' :  
					case 'mountain' : 
					case 'thalasso' : 
					case 'spa' : 
					action = dd[1] ; 
					break;
/*					default :
					document.getElementById('themap').src = URL+ lgmap+domainmap+bSelect+bSelectValue['all']+selection;					
*/				}
			}			
		}

	}/* else {
		document.getElementById('themap').src = URL+ lgmap+domainmap+bSelect+bSelectValue['all']+selection;
	}*/

	switch(action) {
		case 'normal' : 
			document.getElementById('themap').src = URL+ lgmap+domainmap+bSelect+bSelectValue['all']+selection; 
			break;
		case 'address' : mapo_adresse(selection); break ;
		case 'site' : mapo_site(selection); break;
		case 'sea' :  
		case 'mountain' : 
		case 'thalasso' : 
		case 'spa' : 
			document.getElementById('themap').src = URL+ lgmap+domainmap+bSelect+bSelectValue[dd[1]]+selection;	
			break;
	}
}



if (window.addEventListener)
	window.addEventListener('load', mapo_url, false);
else
	window.attachEvent('onload', mapo_url);
