var currentTab=null;

function swTab(n) {
 var me;
 if (typeof(n)=='object') {
	me=n;
	var m=me.id.match(/tabBtn([0-9])/);
	n=m[1];
 } else
	if (n.toString().search(/^[123456]$/)<0) n=1;
 if (currentTab) {
	getObj('tabBtn'+currentTab).className='';
	getObj('tabLayout'+currentTab).style.visibility='hidden';
	if (currentTab>1) getObj('tabBtn'+(currentTab-1)).className='';
 }
 getObj('tabBtn'+n).className='active';
 var layout=getObj('tabLayout'+n);
 layout.style.visibility='visible';
 if (document.all)
	document.all.tabs.style.height=layout.clientHeight+10;
 else
	getObj('tabs').style.height=layout.clientHeight+10;
// alert(layout.clientHeight);
// setTimeout('getObj("tabs").style.height='+layout.clientHeight,1000);
 currentTab=n;
}

var backImg, playImg;

function setBackImg(me) {
 backImg=me;
 me.onload=null;
}

function startSlideShow(me) {
 playImg=me;
 me.onload=null;
}

var currentImg=0, currentZoomImg=0, nextImgTimer;

function nextPic(n) {
 var ROW=SUPPLIER;
 if ((!ROW.pics) || (ROW.pics.length==0)) return false;
 if (nextImgTimer) clearTimeout(nextImgTimer);
 currentImg+=n;
 if (currentImg<0) currentImg=ROW.pics.length-1;
 if (currentImg>=ROW.pics.length) currentImg=0;
 backImg.src=playImg.src;
 setOpacity(playImg,0);
 playImg.src='/files/pic-'+ROW.pics[currentImg].n;
 return false;
}

function playVideo(me) {
 var ROW=SUPPLIER;
 if (!ROW.videofile) { alert('Not available'); return false; }
 return true;
}

function play360(me) {
 var ROW=SUPPLIER;
 if (!ROW.panofile) alert('Not available');
 else
	w=window.open(me.href,'','width=670,height=520,scrollbars=yes');
 return false;
}

function fitWindow(w,img) {
 var dY=Platform.MSIE?96:64;
 w.resizeTo(img.width+24,img.height+dY);
}

function zoomImg(me) {
 var ROW=SUPPLIER;
 currentZoomImg=currentImg;
 var strNext=me.getAttribute('strnext');
 if (!strNext) strNext='Next';
 var w=window.open(me,'','width=640,height=500,resizable=1');
 var s='<html><head><link rel="stylesheet" type="text/css" href="/style.css"></head><body style="margin:0; padding:0"><table width=100% border=0 cellspacing=0 cellpadding=2>' + 
 	'<tr><td align=right><a class="bold maroon" href="" onclick="return opener.zoomNext(window)" style="padding-right: 20px; background:url(/images/play-right.gif) right 50% no-repeat">'+strNext+'</a>' +
	'<tr><td align=center valign=middle>'+
 		'<img onload="opener.fitWindow(window,this)" border=0 src="' + me + '">' +
	'</body></html>';
 w.document.write(s);
 w.document.close();
 w.Pics=ROW.pics;
 w.currentPic=currentImg;
 return false;
}

function zoomNext(w) {
 if ((!w.Pics) || (w.Pics.length==0)) return false;
 w.currentPic+=1;
 if (w.currentPic>=w.Pics.length) w.currentPic=0;
 var nextImg='/files/pic-'+w.Pics[w.currentPic].n;
 w.document.images[0].src=nextImg;
 return false;
}

function getDataList(rows,headers) {

 if (typeof(rows) == 'string') rows=xSplit(rows);
 headers=headers.split(',');
 var nCols=headers.length;
 
 var s='<table class=dataList width=100% border=1 cellspacing=0 cellpadding=2>' +
 	'<tr><th>' + headers.join('<th>');

 for (var i=0; i<rows.length; i++) {
	var row=rows[i];
	s+='<tr>';
	for (var j=0; j<nCols; j++) 
		s+='<td>'+(row[j] || '--');
 }

 s+='</table>';
 return s;
}

function ids2names(s,a,maxRows) {
 if (!maxRows) {
	s=s.replace(/(\d+),?/g, function (cero,uno) {
 		return '<b>\xB7</b> ' + a[uno] + '<br>';
 	});
	return s;
 }
 var res='<table border=0 cellspacing=0 cellpadding=2><tr>';
 s=s.split(',');
 for (var i=0; i<s.length; i++) {
	if (i % maxRows == 0) res+='<td valign=top>';
 	res+='<b>\xB7</b> ' + a[s[i]] + '<br>';
 }
 res+='</table>';
 return res;
}

function ids2names2(s,a) {
 var N=0;
 s=s.replace(/(\d+),?/g, function (cero,uno) {
// 	return (++N%2?'<tr>':'')  + '<td width=50%>- ' + a[uno];
 	return (++N%2?'<tr>':'')  + '<td width=50%>' + a[uno];
 	});
 if (N%2==0) s+= '<td>&nbsp;';
 s='<table width=100% border=0 cellspacing=0 cellpadding=1>' + s + '</table>';
 return s;
}

function ids2names3(s,a,prefs) { 
 var res='', cols=prefs.split(';');
 for (var i=0; i<cols.length; i++) {
 	ncols=cols[i].split(',');
 	res+='<td valign=top>';
 	for (var j=0; j<ncols.length; j++) {
 		if (contains(s,ncols[j])) res+=a[ncols[j]] + '<br>';
 	}
 }	
 res='<table width=100% border=0 cellspacing=0 cellpadding=1><tr>' + res + '</table>';
 return res;
}

function strListInCols(s,c,maxRows) {
 s=s.split(/, |\n/);
 var nRows=maxRows;
 if (c>1) {
	nRows=Math.floor(s.length/c) + ((s.length % c) ? 1: 0)
	if ((maxRows) && (nRows>maxRows)) nRows=maxRows;
 }
 var cols=Math.ceil(s.length/nRows), perc=Math.floor(100/cols);
 var res='<table width=100% border=0 cellspacing=0 cellpadding=2>';
 for (var i=0; i<s.length; i++) {
 	if (i % nRows==0) res+='<td width='+perc+'% valign=top>'; 
 	res+='\xB7 ' + s[i] +'<br>'
 }
 res+='</table>';
 return res;
}

function initialize() {

 if (window.TObjPlainArrayFromTable) {
 	var aux;
 	var s='HCATEGS,LOCATIONS,SERVICES,SPECIALITIES,HTYPES,ACTIVITIES,ROOMSFAC,MEETINGFAC,EVENTTYPES'.split(',');

 	for (var i=0, n; i<s.length; i++) if ((n=s[i]) && (!window[n]))
 		window[n]=new TObjPlainArrayFromTable('data_'+n.toLowerCase());
	if ((!window.CUISINES) && (aux=getObj('data_cuisines'))) window.CUISINES=CUISINES=s2o(aux.innerHTML);
 }
 
 var ROW=SUPPLIER;
 if (ROW.airportname) ROW.airportname=ROW.airportname.trim().nl2br();
 if (ROW.seaportname) ROW.seaportname=ROW.seaportname.trim().nl2br();
 if (ROW.trainstationname) ROW.trainstationname=ROW.trainstationname.trim().nl2br();
 
 if (window.ROW_preInitialize) window.ROW_preInitialize();
 
 var C=0, htype=strTrim(ROW.htype), obj;
 
 if (window.HCATEGS && ROW.categ) ROW.categ=HCATEGS[ROW.categ];
// ROW.htype=ROW.pclass==1?ids2names2(ROW.htype,HTYPES):ids2names(ROW.htype,HTYPES);
// if (ROW.pclass=1) row.htype='6,16,17,18;37,7,3,1');
 ROW.htype=ROW.pclass==1 ? ids2names3(ROW.htype,SERVICES,'6,16,17,18;37,7,3,1') : ids2names(ROW.htype,SERVICES);
// ROW.htype=ROW.pclass==1?ids2names2(ROW.htype,SERVICES):ids2names(ROW.htype,SERVICES);

 var exp=new RegExp(ROW.city+'\\b','i');
 if ((ROW.codpost) && (ROW.address.indexOf(ROW.codpost)<0)) {
// 	if (ROW.address.toUpperCase().indexOf(ROW.city.toUpperCase())<0) 
 	if (ROW.address.search(exp)<0) {
// 	if (!(m=ROW.address.match(exp))) {
 		ROW.address+=' '+ROW.codpost+' '+ROW.city+', '+ROW.country;
// 		alert(1+'\n'+exp+'\n'+m);
 	} else {
 		ROW.address=ROW.address.replace(exp,ROW.codpost + ' ' + ROW.city);
// 		alert(2+'\n'+exp+'\n'+m);
 	}
 }
 
 ROW.address0=ROW.address;
 if (!ROW.weather) ROW.weather=getWeatherLnk(ROW);
 if (!ROW.map) ROW.map=getMapLnk(ROW);
 if (QueryString.jmp=='map') location.href=ROW.map;
 ROW.address=ROW.address.replace(/\n/g,'<br>');
 if ((ROW.web) && (ROW.web.search(/^https?:\/\//) != 0)) ROW.web='http://' + ROW.web;
 if (ROW.situation != null) ROW.situation=ROW.situation.replace(/(\d+)/g,function (cero,uno) { return LOCATIONS[uno] });
 if (ROW.roomsfac) ROW.roomsfac=ROW.roomsfac.replace(/(\d+),?/g,function (cero,uno) { return '<br> <b>·</b> ' +ROOMSFAC[uno] });
 if (ROW.meetingfac) ROW.meetingfac=ids2names(ROW.meetingfac,MEETINGFAC);
 if (ROW.ratesonreq != null) 
 	if (ROW.ratesonreq=='1') {
 		ROW.ratesonreq=getObjContent('i18n_ratesOnRequest');
 		setObjContent('rates','');
 	} else
 		ROW.ratesonreq='';
 	
 if (ROW.cuisines) ROW.cuisines=ROW.cuisines.replace(/(\d+)/g,function (cero,uno) { return ' ' + CUISINES[uno] });
 C=0;
 if (ROW.activities) ROW.activities='<table width=100% border=0 cellspacing=0 cellpadding=1>' +
			ROW.activities.replace(/(\d+),?/g,function (cero,uno) { 
				if (!ACTIVITIES[uno]) return '';
				return (C++%2?'':'<tr>') + '<td width=50% valign=top style="padding-left:8px"><b>·</b> ' + ACTIVITIES[uno] 
			}) + '</table>';
			

 var Pics=[ ], ixPics={ }, ixPicsB={ };
 ROW.pictures.replace(/(\d+):(\d+)/g,function(cero,uno,dos) {
		ixPicsB[dos]=ixPics[dos]=ROW.pclass+'-'+ROW.id+'-'+uno+'.jpg';
		Pics.push( { id: uno, t: dos, n: ixPics[dos] } );
	});
 for (var i=0; i<7; i++) if (!ixPics[i]) { ixPics[i]='none2.jpg'; ixPicsB[i]='none3.jpg' }

 ROW.pics=Pics;
 ROW.ixPics=ixPics;
 ROW.ixPicsB=ixPicsB;
 ROW.firstPic=Pics[0]?Pics[0].n:'none2.jpg';
 
 if (!ROW.factsheet)
 	ROW.factsheet='javascript:void(0)';
 else
 	ROW.factsheet='/files/'+ROW.factsheet;

 if (!ROW.ebrochure)
 	ROW.ebrochure='javascript:void(0)';
 else
 	ROW.ebrochure='/files/'+ROW.ebrochure;

 ROW.languages=ROW.languages.replace(/[a-z][a-z]/g,function(cero) { return cero.substr(0,1).toUpperCase() + cero.substr(1) });
 ROW.languages=ROW.languages.replace(/,/g,' | ');

// var MeetingRooms=xSplit(ROW.meetingdet);
// ROW.meetingdet=getMeetingRoomList(MeetingRooms);
 if (ROW.meetingdet != null) ROW.meetingdet=getDataList(ROW.meetingdet,getObjContent('meetingdetHeaders'));
 if (ROW.eventsdet != null) ROW.eventsdet=getDataList(ROW.eventsdet,getObjContent('eventsdetHeaders'));

 if (ROW.suitablefor) ROW.suitablefor=ids2names(ROW.suitablefor,EVENTTYPES);
 	
 if (ROW.services) ROW.services=ids2names(ROW.services,SERVICES);
 if (ROW.owncatering != null) ROW.owncatering=YESNO[ROW.owncatering];
 
 if (ROW.tenreasonstxt_xx != null)
 	ROW.tenreasonstxt_xx=ROW.tenreasonstxt_xx.replace(/\*\*(.+)/g,'<p><b>$1</b><br>');

// if (ROW.specialities != null) ROW.specialities=ids2names(ROW.specialities,SPECIALITIES,7);

 for (var i in ROW) if ((i!='tenreasonstxt_xx') && (i.search(/_xx$/)>=0))
 	ROW[i]=txtMakeup(ROW[i]);
// if (ROW.soffer_descr_xx) ROW.soffer_descr_xx=txtMakeup(ROW.soffer_descr_xx);
 	
 if (ROW.pclass==2) { 
	for (var i=1; i<=3; i++)  {
		var doc=ROW['prog'+1+'doc'];
		ROW['prog'+i+'link']=doc ? '/files/'+doc : 'javascript:void(0)';
	}
 }
 
 if (m=ROW.mmfiles.match(/[0-9]:([0-9].mpg)/)) 
 	ROW.videofile='/files/video-'+ROW.pclass+'-'+ROW.id+'-'+m[1];
 	
 if (m=ROW.mmfiles.match(/[0-9]:([0-9].jpg)/)) 
 	ROW.panofile='/files/pano-'+ROW.pclass+'-'+ROW.id+'-'+m[1];

 var FIELDS='bfincluded,offer_1paxeverypax,soffer_from,supp_bf,supp_hb,supp_fb,supp_ai,prog2days,prog3days'.split(',');

 for (var i=0; i<FIELDS.length; i++) { // Disabling display of unwanted empty fields
	var n=FIELDS[i];
//	alert(n);
	if ((obj=getObj(n)) && ((!ROW[n]) || (ROW[n]==0))) obj.innerHTML='';
//	if (QueryString.xx) alert(n+': '+obj);
 }
	
 if ((ROW.pclass==2) && ((','+htype+',').indexOf(',24,')<0)) ROW.pclass=3;
 if ((ROW.chain) && (ROW.chain_name)) ROW.chain=ROW.chain_name;
 
 if (ROW.destinations != null) ROW.destinations=strListInCols(ROW.destinations,1,6);
 
 switch(ROW.citycentrekm) {
 	case '': ROW.citycentrekm='?'; break;
 	case '0': ROW.citycentrekm='< 0.5'; break;
 	case '1': ROW.citycentrekm='< 1'; break;
 }

 if (window.ROW_postInitialize) window.ROW_postInitialize();
 
// if (!window.SEO_MODE) 
	parseObjContent('mainDiv',ROW);

 var nTab=QueryString.t;
 
 swTab(1);
 if ((nTab) && (nTab!=1)) swTab(nTab);
}

chainOnload(initialize);

