	/*****************************************************************************
	*  clearLogin(id, tip)
	*  Clear login function
	*
	*****************************************************************************/
	
	function clearLogin(id, tip){
		
		var value = 'User';
		if(tip=='click'){
			document.getElementById(id).value = '';
		}
		else if(tip=='blur'){
			if(document.getElementById(id).value==''){
				if(id!='name'){
					value = "Password";
				}
				document.getElementById(id).value = value;
			}
		}
	}
	
	/*****************************************************************************
	*
	*****************************************************************************/
	
	function doLogin(){
		
		if(document.loginform.name.value=='' || document.loginform.password.value==''){
			return;
		}
		newvin = window.open('','adminWindow','width=900, height=700, toolbar=no, location=no, directories = no, status=no, statusbar=no, menubar=no, copyhistory=no, scrollbars=yes, resizable=yes');
		document.loginform.submit();
		document.loginform.name.value='';
		document.loginform.password.value='';
	}
	/*****************************************************************************
	*
	*****************************************************************************/
	

	function swapWebcam(tip, elem_id){
		for(var x=1; x<=2; x++){
			var _id = 'webcam_' + x;
			$(_id).setStyle('color', '#456502');
		}
		$(elem_id).setStyle('color', '#ffffff');
		
		$('ct_webcam').setStyle('display', 'none');
		$('ct_harti').setStyle('display', 'none');
		$(tip).setStyle('display', '');
	}
	/*****************************************************************************
	*
	*
	*****************************************************************************/
	var myMooFlowPage = {
		start: function(){
			// MooFlow instance with the complete UI and Viewer 
			var els = $('MooFlow').getChildren();
			var mf = new MooFlow($('MooFlow'), {
				bgColor: '#fff',
				useSlider: (els.length > 2)?true:false,
				useAutoPlay: false,
				useCaption: false,
				useResize: false,
				useMouseWheel: false,
				useKeyInput: true,
				startIndex: (els.length > 1)?1:0,
			//	heightRatio: 0.55,
				useViewer: true
			});
			mf.attachViewer();
		}
	};
	
	window.addEvent('domready', function() {		
		if ($('MooFlow')) myMooFlowPage.start(); 
	});
		
	/**************************************************************************************
	 * Ajax request for nume, description !
	 * @param src
	 * @return
	 **************************************************************************************/
	function emptyUpdate( src ){
		
		var index = src.indexOf("slide-show");
		if(index >= 0){
			return;
		}
		
		//alert('unit detail ! ' + src); /* in src adresa imaginii afisate */
		var categ = $('cat').get('value');
		
		var votingPath = appPath + 'ajax/updateunitate';
		
		var request = new Request/*.JSON*/({
			url: votingPath,
			onRequest: function (){
				$('unit_den_area').innerHTML = 'Please wait...';
			},
			onComplete: function(jsonObj) {
				$('unit_den_area').innerHTML = jsonObj;
			}
		}).send('src=' + src + '&categ=' + categ);
		
	//	mf.clickEl();
	}
	/********************************************************************************
	*
	*
	********************************************************************************/
	function changeCateg(categ, elem_id){
		for(var x=1; x<=4; x++){
			var _id = 'el_tab_' + x;
			$(_id).setStyle('color', '#456502');
			$(_id + 'b').setStyle('color', '#456502');
		}
		$(elem_id).setStyle('color', '#ffffff');
		if (elem_id.length == 8)
			$(elem_id + 'b').setStyle('color', '#ffffff');
		else
			$(elem_id.substr(0,8)).setStyle('color', '#ffffff');
		$('cat').set('value', categ);
		oferteAjax();
	}
	/********************************************************************************
	*
	*
	********************************************************************************/
	function changeOras(oras, elem_id){
		for(var x=0; x<=12; x++){
			var _id = 'links_loc_' + x;
			if ($(_id))
				$(_id).setStyle('font-weight', 'normal');
		}
		$(elem_id).setStyle('font-weight', 'bold');
		$('oras_default').set('value', oras);
		oferteAjax();
	}
	/********************************************************************************
	*
	*
	********************************************************************************/
	function oferteAjax(){
		var oras = $('oras_default').get('value');
		var categ = $('cat').get('value');
		var votingPath = appPath + 'ajax/updatetabarea';
		var request = new Request/*.JSON*/({
			url: votingPath,
			onRequest: function (){
				$('tab_area_update').innerHTML = '<span style="padding-top: 35px">Please wait...</span>';
			},
			onComplete: function(jsonObj) {
				$('tab_area_update').innerHTML = jsonObj;
				//	console.log(myMooFlowPage);
				myMooFlowPage.start();
			}
		}).send('oras=' + oras + '&categ=' + categ);
	}
	
	/*****************************************************************************
	*
	*
	*
	*****************************************************************************/
	
	var el_default = 1;

	function stepNews(){
		if(el_default < 5){
			el_default = el_default + 1;
		}
		else{
			el_default = 1;
		}
		changeNews(el_default);
	}
	
	/*****************************************************************************
	*
	*
	*
	*****************************************************************************/
	
	function changeNews(el){
		el_default = el;
		document.getElementById('flash_news_ct').innerHTML = '';
		var flash_el = appPath + 'web_root/flash/master-pg-'+el+'.swf';
		document.getElementById('flash_news_ct').innerHTML = '<object '+ 
			'width="296" height="223" type="application/x-shockwave-flash" data="'+flash_el+'">' + 
			'<param value="'+flash_el+'" name="movie"><p>You need Flash to see this.</p></object>';
	}
	

	
	/*****************************************************************************
	*
	*   INFORMATOR TURISTIC TAB  - UPDATE FOR CITY.
	*	FOR THE SELECTED COUNTRY  GET THE CITIES
	*
	*****************************************************************************/
	var cache_last_country = 1;
	
	function updateOrash(sel1, sel2, sel3, sel4){
		
		var functionPath = appPath + 'ajax/updateselectoras';
		
		var country = $(sel1).getSelected().getProperty('value');
		
		var request = new Request/*.JSON*/({
			url: functionPath,
			onRequest: function (){ 	$(sel2).innerHTML = '<option>Please wait...</option>';	},
			onComplete: function(jsonObj) {
				
				$('url_search_0').value = country;
				$('url_search_2').value = '';
			
				cache_last_country = country;
				var pn = document.getElementById(sel2).parentNode; 
				$(sel2).destroy();
				
				pn.innerHTML = '';
				pn.innerHTML += '<select id="sel_1" onchange="updateElement(this.id, \'sel_2\' );"><option value="0">Toate...</option>'+ jsonObj +'</select>';				
				
				var pn3 = document.getElementById(sel3).parentNode; 
				$(sel3).destroy();
				
				pn3.innerHTML = '';
				pn3.innerHTML += '<select id="sel_2" onchange="updateTip1( \'sel_1\', this.id, \'sel_3\' );"><option value="0">Toate...</option></select>';
				
				var pn4 = document.getElementById(sel4).parentNode; 
				$(sel4).destroy();
				
				pn4.innerHTML = '';
				pn4.innerHTML += '<select id="sel_3" onchange="updateTip2(this.id);"><option value="0">Toate...</option></select>';
				
				updateLinkCautare();
			}
		}).send('country=' + country);
	}
	
	/*****************************************************************************
	*
	*	Update Element - 
	*
	*****************************************************************************/
	var cache_last_city = 'arad';
		
	function updateElement(sel1, sel2){
		
		var votingPath = appPath + 'ajax/updateselect';
		
		var oras = $(sel1).getSelected().getProperty('value');
		var request = new Request/*.JSON*/({
			url: votingPath,
			onRequest: function (){
				$(sel2).innerHTML = '<option>Please wait...</option>';
			},
			onComplete: function(jsonObj) {
				
				$('url_search_0').value = $('sel_0').getSelected().getProperty('value');
				
				$('url_search_2').value = oras;
				var str = $('url_search_3').value;
				$('url_search_3').value = str.replace(cache_last_city, oras);
				 
				var str1 = $('url_search_3_cache').value;
				$('url_search_3_cache').value = str1.replace(cache_last_city, oras);
				
				$('url_search_3').value =  $('url_search_3_cache').value;
				
				$('url_search_4').value = '';
				cache_last_city = oras;
				
				var pn = document.getElementById(sel2).parentNode; 
				$(sel2).destroy();
				
				pn.innerHTML = '';
				pn.innerHTML += '<select id="sel_2" onchange="updateTip1( \'sel_1\', this.id, \'sel_3\' );"><option value="0">Toate...</option>'+ jsonObj +'</select>';
				
				var pn1 = document.getElementById('sel_3').parentNode; 
				$('sel_3').destroy();
				
				pn1.innerHTML = '';
				pn1.innerHTML += '<select id="sel_3" onchange="updateTip2( this.id );"><option value="0">Toate...</option></select>';
				
				
				updateLinkCautare();
			}
		}).send('oras=' + oras);
		
		showOras(oras);
	}
	
	
	/*****************************************************************************
	*
	*****************************************************************************/
	
	function updateLinkCautare(){
		
		var url0 = document.getElementById('url_search_0').value;
		var url1 = document.getElementById('url_search_1').value;
		var url2 = document.getElementById('url_search_2').value;
		var url3 = document.getElementById('url_search_3').value;
		var url4 = document.getElementById('url_search_4').value;
		
		
		var url = url0 + '/';
		
		if (url2.length > 0){
			
			url += url2;
			
			if(url3.length > 0){
				if(url4.length>0){
					url += '/' + url3 + '-' + url4 + '-' + url2 + '/';
				}
				else{
					url += '/' + url3 + '-' + url2 + '/';
				}
			}
			else{
				url += '/';
			}
		}
		
		if (document.getElementById('cautare_url')) document.getElementById('cautare_url').href = prefix_link  + url;
		if (document.getElementById('cautare_url2')) document.getElementById('cautare_url2').href = prefix_link + url;
		if (document.getElementById('cautare_url3')) document.getElementById('cautare_url3').href = prefix_link + url;
	}
	
	function makeSeoUrl(str){
		str = str.toLowerCase();
		str = str.split('/').join('_');
		str = str.split(', ').join('_');
		str = str.split(',').join('_');
		//str = str.split('. ').join('_');
		//str = str.split('.').join('_');
		str = str.split(' ').join('_');
		str = str.split('&nbsp;').join('_');
		str = str.split('\u00A0').join('_');
		return replaceDiacritics(str);
	}
	
	function replaceDiacritics(s){
		var s;

		var diacritics =[
			/[\300-\306]/g, /[\340-\346]/g, // A, a
			/[\310-\313]/g, /[\350-\353]/g, // E, e
			/[\314-\317]/g, /[\354-\357]/g, // I, i
			/[\322-\330]/g, /[\362-\370]/g, // O, o
			/[\331-\334]/g, /[\371-\374]/g,  // U, u
			/[\321]/g, /[\361]/g, // N, n
			/[\307]/g, /[\347]/g, // C, c
		];
	
		var chars = ['A','a','E','e','I','i','O','o','U','u','N','n','C','c'];
	
		for(var i = 0; i < diacritics.length; i++){
			s = s.replace(diacritics[i],chars[i]);
		}
		
		return s;
	}
	
	//var cache_tip1 = 'cazari-arad';
	/*****************************************************************************************************************************************
	*   updateTip1 apelata in oferte_tabs pentru a face update la cautare categoriilor pentru orashe
	*****************************************************************************************************************************************/	
	function updateTip1(oras, sel, elem){
		
		$('url_search_4').value = '';
		
		var votingPath = appPath + 'ajax/updateselect';
		var tip1 = $(sel).getSelected().getProperty('value');
		var oras = $(oras).getSelected().getProperty('value');
		
		var request = new Request/*.JSON*/({
			url: votingPath,
			onRequest: function (){
				$(elem).innerHTML = '<option>Please wait...</option>';
			},
			onComplete: function(jsonObj) {
				
				var cache_tip1 = ("" + $(sel).getSelected().getProperty('value')).replace(/^[0-9]+_/, '');//get('text');
				//cache_tip1 = cache_tip1[0];
				//cache_tip1 = makeSeoUrl(cache_tip1);
				$('url_search_3').value = cache_tip1; // + '-' +cache_last_city;
				
			//	$(elem).innerHTML = '<option value="0">Toate...</option>' + jsonObj;
				var pn1 = document.getElementById(elem).parentNode; 
				$(elem).destroy();
				
				pn1.innerHTML = '';
				pn1.innerHTML += '<select id="sel_3" onchange="updateTip2( this.id );"><option value="0">Toate...</option>' + jsonObj + '</select>';				
				var opts = $$('option.sel_3');
				var toate = '';
				
				var lung = opts.length;
				var i=0;
				opts.each(function(el){
					var lit_toate = el.get('text');
					lit_toate = makeSeoUrl(lit_toate);
					i++;
					toate += lit_toate + (i<lung ? '-' : '');
				});
				
				var sel_3_v = $('sel_3').getSelected().getProperty('value');
			//	$('url_search_4').value = toate;
			
				if(tip1==0){
					$('url_search_3').value = '';//$('url_search_3_cache').value;
				}
				
				updateLinkCautare();
			}
		}).send( 'oras='+oras+'&tip1=' + tip1);
	}
	
	/************************************************************************************************************
	*   updateTip2 apelata in oferte_tabs pentru a face update la cautare categoriilor pentru orashe
	*
	*
	***************************************************************************************************************/	
	function updateTip2(elemId){
		
		if($(elemId).getSelected().getProperty('value')==0){
			$('url_search_4').value = '';
			updateLinkCautare();
			return;
		}
		
		//if($('sel_2').getSelected().getProperty('value')==0){
		//	$('sel_2').selectedIndex = 1;
		//}
		
		var sel_3_v = $(elemId).getSelected().getProperty('value');
		if(sel_3_v==0){
			var opts = $$('option.sel_3');
			var toate = '';
			
			var lung = opts.length;
			var i=0;
			opts.each(function(el){
				var lit_toate = el.get('text');
				lit_toate = makeSeoUrl(lit_toate);
				i++;
				toate += lit_toate + (i<lung ? '-' : '');
			});
			//$('url_search_4').value = toate;
		}
		else{
			//sel_3_v = sel_3_v[0];
			//sel_3_v = makeSeoUrl(sel_3_v);
			$('url_search_4').value = sel_3_v; // + '-' +cache_last_city;
		}
		updateLinkCautare();
	}
	
	
		/**
		* Helper Function for mootools - ajax stuff
		* 	Author: Ancuta Florin Vasile : achebv[at]yahoo[dot]com, achebv[at]gmail[dot]com
		*/

		/**
		 * start Voting functions here !
		 */

		var votingPath = '';
		if (typeof(appPath) != "undefined") votingPath = appPath + 'ajax/voting'; else votingPath = '/ajax/voting';
			
		/**
		 * voteazaItem : functoin call after select 1 radio option from form !
		 * @param {Object} val : the value of items !
		 */
		function voteazaItem(val){
			document.getElementById('votchoice').value = val;
		}
		
		
		/**
		 * Function for show the result from database !
		 */
		function showVoturi(){
			
			var spans = $$('#vot_content span.op');
			if(spans.length>0){
				var i = 0;
				spans.each(function(span) {
					var parent = span.getParent();
					span.destroy();
					var parentText = parent.innerHTML;
					parent.innerHTML = '';
					parent.grab(inputs[i]);
					parent.innerHTML = parent.innerHTML + parentText;
					document.getElementById(inputs[i].id).checked = false;
					i++;
				});
				return;
			}
			
			var request = new Request.JSON({
				url: votingPath,
				onComplete: function(jsonObj) {
					if(jsonObj.eroare){
						alert(jsonObj.mesaj);
					}
					else{
						inputs = $$('#vot_content input.op');
						inputs.each(function(input) {
							var parent = input.getParent();
							input.destroy();
							parent.innerHTML = parent.innerHTML + "<span id='"+input.id+"' class='op' style='font-size: 11px;'>" + jsonObj.data[input.id] + "</span>";
						});
						document.getElementById('votchoice').value = 0;
					}
				}
			}).send('votchoice=' + 0);
				
		}

		var inputs = '';
		
		/**
		 * Function for add new value in the database !
		 */
		function doVot(){
			var votchoice = document.getElementById('votchoice').value;
			if(votchoice<1){
				var spans = $$('#vot_content span.op');
				if(spans.length<1){
					alert('Alegeti o optiune !');
				} 
				else {
					var i = 0;
					spans.each(function(span) {
						var parent = span.getParent();
						span.destroy();
						var parentText = parent.innerHTML;
						parent.innerHTML = '';
						parent.grab(inputs[i]);
						parent.innerHTML = parent.innerHTML + parentText;
						document.getElementById(inputs[i].id).checked = false;
						i++;
					});
				}
				return;
			}
			else{
				var request = new Request.JSON({
					url: votingPath,
					onComplete: function(jsonObj) {
						if(jsonObj.eroare){
							alert(jsonObj.mesaj);
						}
						else{
							inputs = $$('#vot_content input.op');
							inputs.each(function(input) {
								var parent = input.getParent();
								input.destroy();
								parent.innerHTML = parent.innerHTML + "<span id='"+input.id+"' class='op' style='font-size: 11px;'>" + jsonObj.data[input.id] + "</span>";
							});
							document.getElementById('votchoice').value = 0;
						}
					}
				}).send('votchoice=' + votchoice);
			}
		}
		
		/**
		 * End Voting functions here !
		 */
		
		// News Ticker
		window.addEvent('domready', function(){
			if (!$('news_ticker')) return;
			var ticker = new NewsTicker(
				'news_ticker',
				{
					width: 296, 
					height: 26, 
					charWidth: 10, 
					paddingMultiplier: 8 
				}
			);
			ticker.start.delay(50, ticker); // Start after 0.1 second.
		});
		
		/*var homeImages = [];
		window.addEvent('load', function(){
			Array.each.delay(3000,this,[
			    ['arad', 'balti', 'branmoeciu','brasov','bucuresti', 'busteni', 'chisinau', 'glodeni', 'mamaia', 'mciuc', 'oradea' , 'orhei',
				 'piatraneamt','poiana','predeal','sinaia','stefanvoda','timisoara', 'vadulvoda'],
			    function(src){
			    	homeImages[src] = new Image();
			    	homeImages[src].src = appPath+'web_root/img/towns_home/'+src+'.jpg';
			    }
			]);
		});  */
		
	/**********************************************************************************************
	*    SHOW ORASH efectul de tranzitiie din cmpInformator din prima pagina
	**********************************************************************************************/
	var wichOne = 2;
	function showOras(oras){
		if(wichOne == 1){
			tDiv = "div1";
			vDiv = "div2";
			im = "im1";
			wichOne = 2;
		} 
		else {
			tDiv = "div2";
			vDiv = "div1";
			im = "im2";
			wichOne = 1;
		}
			
		$(im).set('src',appPath+'web_root/img/towns_home/'+oras+'.jpg'); //homeImages[oras].src);
			
		var dur = 5000;
		
		var myEffect1 = new Fx.Morph(tDiv, {duration: dur, transition: Fx.Transitions.Sine.easeOut});
		myEffect1.start({
		    'opacity': [0, 1]
		});
			
		var myEffect2 = new Fx.Morph(vDiv, {duration: dur, transition: Fx.Transitions.Sine.easeOut});
		myEffect2.start({
		    'opacity': [1, 0]
		});
	}
	
	/**********************************************************************************************
	*
	*    // Carousel Oferte speciale
	*
	*
	**********************************************************************************************/
	window.addEvent('domready', function(){
		if ($('carousel_content'))
		new iCarousel("carousel_content", {  
			idPrevious: "carousel_previous",  
			idNext: "carousel_next",  
			idToggle: "undefined",  
			item: {  
				klass: "carousel_item",  
				size: 255  
			},  
			animation: {  
				duration: 1000,  
				amount: 1,
				rotate: {
				    type: "auto"
				}   
			} 
		});}
	);
			
	/**********************************************************************************************
	*
	*    // Calculator distante
	*
	*
	**********************************************************************************************/
			
	function calcdist(){
		dela = document.getElementById('delaoras').value;
		panala = document.getElementById('panalaoras').value;
	
		if(dela > panala){
			document.getElementById('calculdisthere').innerHTML='<?=iconv("WINDOWS-1250", "UTF-8", $multilanguage_text_distanta)?><br />' + dist[dela-1][panala-1] + ' km';
		}
		else{
			document.getElementById('calculdisthere').innerHTML='<?=iconv("WINDOWS-1250", "UTF-8", $multilanguage_text_distanta)?><br />' + dist[panala-1][dela-1] + ' km';
		}
	}

	dist=new Array();
	dist[0]=new Array(0, 169, 255, 185, 87, 136, 34, 39, 126, 79, 116, 37, 63, 221, 237, 201, 61, 233, 170,	160, 198, 69, 60, 37, 125, 106,	82, 136, 140, 204, 142,	141, 187, 66, 60, 160, 116,	24,	42,	155, 44); 
	dist[1]=new Array(169, 0, 93, 251, 82, 201,	209, 124, 265, 207,	230, 71, 128, 59, 81, 42, 145, 68, 28, 35, 33, 164, 152, 142, 174, 100,	87,	102, 111, 38, 24, 84, 58, 227, 104,	268, 50, 177, 188, 80, 132);
	dist[2]=new Array(225, 93, 0, 331, 161,	281, 289, 211, 342,	278, 307, 83, 238, 48, 20, 51, 234,	45,	106, 92, 79, 222, 241, 225,	280, 203, 171, 155,	153, 57, 112, 129, 63, 316,	194, 380, 148, 262,	278, 153, 217);
	dist[3]=new Array(185, 251,	331, 0, 215, 51, 158, 186, 67, 101,	71,	271, 214, 306, 318,	298, 218, 317, 222,	304, 256, 228, 130, 170, 74, 145, 227, 292,	285, 285, 249, 289,	329, 191, 206, 49, 241,	177, 198, 175, 195);
	dist[4]=new Array(87, 82, 161, 215, 0, 168, 121, 51, 184, 119, 148, 130, 90, 140, 153, 117,	86,	144, 64, 109, 113, 93, 63, 66, 115,	38,	62,	105, 109, 114, 61, 106,	127, 148, 28, 202, 42, 117,	128, 54, 69);	
	dist[5]=new Array(136, 201,	281, 51, 168, 0, 114, 126, 62, 74, 41, 220, 170, 255, 267, 247,	174, 263, 172, 256,	203, 185, 79, 119, 23, 95, 176,	233, 234, 234, 198,	239, 278, 142, 155,	85,	210, 134, 150, 124, 151);
	dist[6]=new Array(34, 209, 289,	158, 121, 114, 0, 70, 91, 57, 87, 271, 91, 256,	266, 235, 99, 267, 207, 194, 226, 76, 95, 71, 114, 149,	119, 162, 157, 237, 176, 187, 218, 28, 93, 140, 150, 24, 36, 184, 78);
	dist[7]=new Array(39, 124, 211, 186, 51, 126, 70, 0, 133, 69, 98, 211, 38, 199, 196, 165, 45, 207, 127, 122, 168, 44, 31, 14, 87, 70, 44, 102, 102, 177, 118, 107, 146, 97, 23, 151, 78, 63, 76, 104, 19);
	dist[8]=new Array(126, 265,	342, 67, 184, 62, 91, 133, 0, 65, 36, 288, 172,	322, 330, 298, 175,	331, 240, 260, 289,	186, 103, 126, 103,	158, 177, 242, 242,	296, 243, 239, 284,	104, 161, 28, 210, 120,	127, 197, 152);
	dist[9]=new Array(79, 207, 278,	101, 119, 74, 57, 69, 65, 0, 30, 223, 107, 257,	264, 233, 110, 265,	175, 190, 210, 113,	38,	62,	51,	88,	113, 169, 182, 236,	177, 176, 215, 86, 92, 83, 146,	81,	90,	127, 88);
	dist[10]=new Array(116, 230, 307, 71, 148, 41, 87, 98, 36, 30, 0, 240, 137,	282, 294, 262, 139,	290, 192, 219, 221,	151, 74, 91, 43, 115, 142, 206,	206, 261, 207, 204,	258, 114, 121, 54, 175,	106, 119, 144, 117);
	dist[11]=new Array(237,	71,	83,	271, 130, 220, 271,	211, 288, 223, 240,	0, 214,	36,	59,	56,	217, 45, 60, 106, 28, 228, 186,	226, 197, 138, 158,	169, 172, 34, 95, 151, 101,	303, 181, 291, 129,	248, 259, 96, 204);
	dist[12]=new Array(63, 128,	238, 214, 90, 170, 91, 38, 172,	107, 137, 214, 0, 202, 214, 182, 7,	210, 142, 121, 174,	18,	69,	51,	149, 103, 41, 67, 67, 180, 104,	85,	140, 117, 50, 190, 89, 66, 64, 135,	18);
	dist[13]=new Array(221, 59,	48,	306, 140, 255, 256,	199, 322, 257, 282,	36,	202, 0,	36,	44,	212, 9,	80,	94,	49,	216, 215, 214, 232,	173, 146, 154, 157,	26,	89,	135, 86, 286, 169, 333,	117, 236, 247, 133, 192);
	dist[14]=new Array(237,	81,	20,	318, 153, 267, 266,	196, 330, 264, 294,	59,	214, 36, 0,	33,	202, 33, 92, 85, 61, 231, 227, 216,	244, 216, 165, 147,	156, 38, 99, 131, 61, 296, 185,	361, 128, 257, 259,	141, 203);
	dist[15]=new Array(201,	42,	51,	298, 117, 247, 235,	165, 298, 233, 262,	56,	182, 44, 33, 0,	193, 52, 72, 57, 43, 196, 196, 180,	216, 154, 139, 119,	122, 22, 76, 98, 45, 261, 149, 230,	97,	216, 227, 120, 172);
	dist[16]=new Array(61, 145,	234, 218, 86, 174, 99, 45, 175,	110, 139, 217, 7, 212, 202, 193, 0,	221, 145, 118, 170,	18,	73,	55,	128, 123, 44, 59, 60, 183, 107,	76,	142, 110, 54, 193, 99, 72, 64, 138,	26);
	dist[17]=new Array(233,	68,	45,	317, 144, 263, 267,	207, 331, 265, 290,	45, 210, 9,	33,	52,	221, 0,	89,	102, 68, 224, 224, 222,	241, 182, 154, 166, 169, 35, 95, 147, 94, 294, 177,	332, 130, 244, 254,	136, 200);
	dist[18]=new Array(170, 28,	106, 222, 64, 172, 207,	127, 240, 175, 192,	60,	142, 80, 92, 72, 145, 89, 0, 200, 31, 169, 141,	135, 149, 135, 105,	130, 134, 52, 54, 117, 91, 222,	92,	255, 57, 176, 188, 48, 145);
	dist[19]=new Array(160,	35,	92,	304, 109, 256, 194,	122, 260, 190, 219,	106, 121, 94, 85, 57, 118, 102,	200, 0,	69,	135, 152, 135, 231, 156, 80, 60, 63, 73, 43, 43, 36, 223, 116, 273,	55,	173, 184, 120, 129);
	dist[20]=new Array(198,	33,	79,	256, 113, 203, 226,	168, 289, 210, 221,	28,	174, 49, 61, 43, 170, 68, 31, 69, 0, 188, 152, 174,	180, 102, 124, 135, 144, 24, 57, 117, 90, 253, 136,	282, 83, 217, 218, 82, 159);
	dist[21]=new Array(69, 164,	222, 228, 93, 185, 76, 44, 186, 113, 151, 228, 18, 216,	231, 196, 18, 224, 169, 135, 188, 0, 84, 58, 145, 118, 55, 78, 79, 194, 118, 93, 160, 92, 65, 204, 110, 55,	46,	151, 26);
	dist[22]=new Array(60, 152,	241, 130, 63, 79, 95, 31, 103, 38, 74, 186, 69,	215, 227, 196, 73, 224, 141, 152, 152, 84, 0, 24, 56, 51, 75, 133, 134,	204, 122, 137, 177,	127, 50, 121, 99, 85, 86, 96, 50);
	dist[23]=new Array(37, 142,	225, 170, 66, 119, 71, 14, 126,	62,	91,	226, 51, 214, 216, 180,	55,	222, 135, 135, 174,	58,	24,	0, 84, 71, 57, 117,	118, 192, 124, 120,	160, 97, 39, 144, 93, 63, 74, 113, 32);
	dist[24]=new Array(125,	174, 280, 74, 115, 23, 114,	87,	103, 51, 43, 197, 149, 232, 244, 216, 128, 241,	149, 231, 180, 145,	56,	84,	0, 72, 139,	189, 189, 211, 166, 201, 256, 135, 108,	96,	158, 118, 130, 101, 114);
	dist[25]=new Array(106,	100, 203, 145, 38, 95, 149,	70,	158, 88, 115, 138, 103,	173, 216, 154, 123,	182, 135, 156, 102,	118, 51, 71, 72, 0,	120, 183, 161, 152,	95,	187, 179, 166, 45, 161,	79,	140, 152, 42, 87);
	dist[26]=new Array(82,  87,  171, 227, 62, 176, 119, 44, 177,	113, 142, 158, 41, 146,	165, 139, 44, 154, 105,	80,	124, 55, 75, 57, 139, 120, 0, 57, 60, 124, 63, 63, 105,	140, 38, 195, 48, 99, 111, 110,	55);
	dist[27]=new Array(136, 102, 155, 292, 105,	233, 162, 102, 242,	169, 206, 169, 67, 154, 147, 119, 59, 166, 130,	60,	135, 78, 133, 117, 189, 183, 57, 0,	3, 133,	91,	18,	84,	180, 94, 266, 70, 142 , 150, 157, 85);
	dist[28]=new Array(140, 111, 153, 185, 109,	234, 157, 102, 242,	182, 206, 172, 67, 157,	156, 122, 60, 169, 134,	63,	144, 79, 134, 118, 189,	161, 60, 3, 0, 136,	94,	21,	87,	178, 97, 254, 73, 141, 131,	151, 85);
	dist[29]=new Array(204, 38,  57,  285, 114, 234, 237,	177, 296, 236, 261,	34,	180, 26, 38, 22, 183, 35, 52, 73, 24, 194, 204, 192, 211, 152, 124,	133, 136, 0, 66, 114, 67, 265, 147,	311, 95, 215, 225, 107, 170);
	dist[30]=new Array(142, 24,  112, 249, 61, 198, 176,	118, 243, 177, 207,	95,	104, 89, 99, 76, 107, 95, 54, 43, 57, 118, 122,	124, 166, 95, 63, 91, 94, 66, 0, 75, 79, 207, 91, 261, 27, 156,	167, 75, 111);
	dist[31]=new Array(141, 84,  129, 289, 106, 239,	187, 107, 239, 176,	204, 151, 85, 135, 131,	98,	76,	147, 117, 43, 117, 93, 137,	120, 201, 187, 63, 18, 21, 114,	75, 0, 67, 202,	100, 258, 70, 156, 143,	142, 102);
	dist[32]=new Array(187, 58,  63,  329, 127, 278, 218,	146, 284, 215, 258,	101, 140, 86, 61, 45, 142, 94, 91, 36, 90, 160,	177, 160, 256, 179, 105, 84, 87, 67, 79, 67, 0,	248, 140, 297, 90, 198,	209, 139, 154);
	dist[33]=new Array(66, 227,  316, 191, 148, 142,	28,	97,	104, 86, 114, 303, 117,	286, 296, 261, 110,	294, 222, 223, 253,	92,	127, 97, 135, 166, 140,	180, 178, 265, 207,	202, 248, 0, 129, 165, 191,	45,	51,	213, 98);
	dist[34]=new Array(60, 104,194, 206, 28, 155, 93, 23, 161,	92,	121, 181, 50, 169, 185,	149, 54, 177, 92, 116, 136,	65,	50,	39,	108, 45, 38, 94, 97, 147, 91, 100, 140,	129, 0,	174, 62, 89, 100, 81, 41);
	dist[35]=new Array(160,	268, 380, 49, 202, 85, 140,	151, 28, 83, 54, 291, 190, 333,	361, 230, 193, 332,	255, 273, 282, 204,	121, 144, 96, 161, 195,	266, 254, 311, 261,	258, 297, 165, 174,	0, 229,	159, 173, 207, 177);
	dist[36]=new Array(116,	50,148, 241, 42, 210, 150,	78,	210, 146, 175, 129,	89,	117, 128, 97, 99, 130, 57, 55, 83, 110,	99,	93,	158, 79, 48, 70, 73, 95, 27, 70, 90, 191, 62, 229, 0, 129, 140,	70,	85);
	dist[37]=new Array(24, 177,262, 177, 117, 134,	24,	63,	120, 81, 106, 248, 66, 236,	257, 216, 72, 244, 176, 173, 217, 55, 85, 63, 118, 140,	99,	142, 141, 215, 156,	156, 198, 45, 89, 159, 129,	0, 14, 170,	48);
	dist[38]=new Array(42, 188,278, 198, 128, 150,	36,	76,	127, 90, 119, 259, 64, 247,	259, 227, 64, 254, 188,	184, 218, 46, 86, 74, 130, 152,	111, 150, 131, 225,	167, 143, 209, 51, 100,	173, 140, 14, 0, 182, 59);
	dist[39]=new Array(155,	80,153, 175, 54, 124, 184,	104, 197, 127, 144,	96,	135, 133, 141, 120, 138, 136, 48, 120, 82, 151, 96, 113, 101, 42, 110, 157,	151, 107, 75, 142, 139,	213, 81, 207, 70, 170, 182,	0, 126);
	dist[40]=new Array(44, 132,	217, 195, 69, 151, 78, 19, 152,	88,	117, 204, 18, 192, 203,	172, 26, 200, 145, 129,	159, 26, 50, 32, 114, 87, 55, 85, 85, 170, 111,	102, 154, 98, 41, 177, 85, 48, 59, 126, 0);	
	
	
	
	
	/****************** BOOKING.COM Functions******************************************************************/
	/**********************************************************************************************************/

	/* Login */
	window.addEvent('domready', function(){
		$('login').setStyle('height','auto');
			var mySlide = new Fx.Slide('login').hide();  //starts the panel in closed state  

			$('toggleLogin').addEvent('click', function(e){
				e = new Event(e);
				mySlide.toggle();
				e.stop();
			});

			$('closeLogin').addEvent('click', function(e){
				e = new Event(e);
				mySlide.slideOut();
				e.stop();
			});
	});
			
	/* Explore */
	window.addEvent('domready', function(){
		$$('#explore_header a.explore_country_tab').addEvent('click',function() {
			if ($(this).hasClass('explore_country_active')) return false;
			
			var chosen = $(this).className.replace(/.*ec_/, '').replace(/\s.*/, '');
			var cid = chosen.replace(/_.*/, '');
			var station = chosen.replace(/[0-9]+_/, '');

			$$('#explore_contry li.active_station').removeClass('active_station');
			$$('#explore_contry li.station').setStyle('display', 'none');
			$$('#explore_contry li.cid_' + cid).setStyle('display', 'list-item');
			$$('#explore_contry li.station_' + station).addClass('active_station');
			
			$$('#explore_contry table.categories').setStyle('display', 'none');
			$$('#explore_contry table.categories_' + station).setStyle('display', 'table');
			
			$$('#explore_header a.explore_country_tab').removeClass('explore_country_active').addClass('explore_country_inactive');
			$(this).removeClass('explore_country_inactive').addClass('explore_country_active');
			return false;
		});
			
		$$('.explore_country_box li.station a').addEvent('click', function(e){
			$$('#explore_contry table.categories').setStyle('display', 'none');
			$$('#explore_contry li.active_station').removeClass('active_station');
			var station = $(this).getParent('li').get('class').replace(/cid_[0-9]*/, '').replace(/station.?/g,'').trim();
			$$('#explore_contry table.categories_' + station).setStyle('display', 'table');
			$(this).getParent('li').addClass('active_station');
			return false;
		});
	});
	
	/* Destinations */
	window.addEvent('domready', function(){
		$$('#dest_link_list a').addEvent('click', function() {
			$$('#dest_link_list a').setStyle('font-weight', 'normal');
			var a = $(this);
			var ct = $('dest_list');
			if (!a || !ct) return true;
			a.setStyle('font-weight', 'bold');
			ct.set('html', '<img src="' + appPath + 'web_root/img/ajax-loader.gif" alt="" style="display: block; position: absolute; top: 100px; left: 150px;" />');
			
			var key = a.href.replace(appPath, '').replace(/\//g, '__').replace(/-/g, '___').replace(/\W/g, '');
			var cache = eval('window.' + key);
			if (cache) {
				showDests(cache);
			}
			else {			
				var jsonRequest = new Request.JSON({
					url: a.href,
					onSuccess: function(r) {
						if (!r) location.href = a.href;
						showDests(r);
						eval('window.' + key + ' = r');
					},
					onFailure: function(){
						location.href = a.href;
					}
				}).get({'js' :1});
			}
			return false;
		});
	});

	function getXpxForG(g) {
		return (g - 26.4783063616) / 0.00982491629466;
	}
	
	function getYpxForG(g) {
		return (48.4796979886 - g) / 0.00679388204047;
	}
	
	function showDests(r) {
		var ct = $('dest_list');
		ct.set('html', '');
		$each(r.destinations, function(d) {
			if (d.dest_long == "0" || d.dest_lat == "0") return;
			ct.adopt(new Element('div', {
				'id': 'dest_wrap_' + d.dest_id,
				'styles': {
					'background-image': 'url("/web_root/img/destinatiituristice/' + d.dest_tip_id + '.png")',
					'background-repeat': 'no-repeat',
					'width': '27px',
					'height': '27px',
					'position': 'absolute',
					'left': getXpxForG(d.dest_long) - 5,
					'top': getYpxForG(d.dest_lat) - 5,
					'cursor': 'pointer',
					'z-index': 2004
				},
				'alt': d.dest_title,
			    'events': {
			        'click': function(){
			            location.href = d.dest_link;
			        },
			        'mouseenter': function(){
			        	var info = $('dest_info_' + d.dest_id);
			        	if (info) {
			        		
			        	}
			        	else {
				            var info = new Element('div', {
					            'id': 'dest_info_' + d.dest_id,
								'styles': {
									'position': 'absolute',
									'padding' : '5px',
									'width': '270px',
									'height': '145px',
									'border': 'none',
									'background-image':  'url("/web_root/img/explore_box/calota_dreapta.png")', 	
									'opacity': 0,
									'left': -280,
									'top': -65
								}
				            });
				            info.set('html', d.dest_info);
				            $(this).adopt(info);
			        	}
			            $(this).setStyle('z-index', 2005);
			            info.morph({
			            	'opacity': 1
			            });
			        },
			        'mouseleave': function(){
			        	var wrap = $(this);
			            ct.getElements('div[id^=dest_info_]').morph({
			            	'duration': 'short',
			            	'complete': function(){ wrap.setStyle('z-index', 2004);},
			            	'opacity': 0
			            });
			        }
			    }
			}));
		});
	}

	/* Events */
	window.addEvent('domready', function(){
		var mid = new Date(), mad = new Date();
		mad.setDate(mad.getDate() + 30);
		
		var d = $('upcoming_events_date').getCoordinates(),
		mids = (mid.getFullYear() * 100 + (mid.getMonth() + 1)) * 100 + mid.getDate(),
		mads = (mad.getFullYear() * 100 + (mad.getMonth() + 1)) * 100 + mad.getDate(),
		picker = new DatePicker($('upcoming_events_date'), {
			pickerClass: 'datepicker_vista datepicker_vista_calendar radius5',
			allowEmpty: true,
			useFadeInOut: false,
			calendarMode: true,
			minDate: { date: mids, format: 'Ymd'},
			maxDate: { date: mads, format: 'Ymd'},
			onSelect: function(d) {
				$('upcoming_events_sel_date').set('text', d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear());
				$('upcoming_events_sel_date').int_date = (d.getFullYear() * 100 + (d.getMonth() + 1)) * 100 + d.getDate();
				$('upcoming_events_clear_date').setStyle('display', 'block');
				updateEventList();
			},
			onPrevious: function() {
				if (!$('upcoming_events_sel_date').int_date) picker.newContents.getElements('div.selected').removeClass('selected');
			},
			onNext: function() {
				if (!$('upcoming_events_sel_date').int_date) picker.newContents.getElements('div.selected').removeClass('selected');
			}
		});
		picker.newContents.getElements('div.selected').removeClass('selected');
		$('upcoming_events_clear_date').addEvent('click', function(){
			$('upcoming_events_sel_date').set('text', '');
			$('upcoming_events_sel_date').int_date = null;
			this.setStyle('display', 'none');
			picker.newContents.getElements('div.selected').removeClass('selected');
			updateEventList();
		});
		
		$$('#upcoming_events_types a').addEvent('click', function(){
			if ($(this).getParent().hasClass('upcoming_event_type_active')) return false;
			$$('#upcoming_events_types div').removeClass('upcoming_event_type_active');
			$(this).getParent().addClass('upcoming_event_type_active');
			updateEventList();
			return false;
		});
		var evnt_station_select = new MavSelectBox({
			elem: $('upcoming_events_stations'),
			alternate: true,
			onSelect: function(elem) {
				updateEventList();
			}
		});
		var evnt_cntry_select = new MavSelectBox({
			elem: $('upcoming_events_countries'),
			alternate: true,
			onSelect: function(elem) {
				evnt_station_select.elementOptions.getChildren().dispose();
				var cnt = 0, cid = this.element.value.replace('event_country_', '');
				var st = $('upcoming_events_stations').value;
				$each(stations, function(s, i) {
					if (cid != 'all' && cid != s.c && s.n != 'all') return;
					var o = new Element('option', {
						'value': 'event_station_' + s.n,
						'text': s.rn
					});
					if (s.c == '0') o.setStyle('font-weight', 'bold');
					if (st == o.value) o.selected = true;
					evnt_station_select.create_option(o, cnt++);
				});
				var sli = evnt_station_select.elementOptions.getElement('li.' + evnt_station_select.options.selectClass);
				if (!sli) sli = evnt_station_select.elementOptions.getElements('li')[0];
				evnt_station_select.select(sli);
				updateEventList();
			}
		});
		evnt_station_select.elementSelect.addClass('radius5');
		evnt_cntry_select.elementSelect.addClass('radius5');
		var cid = $('upcoming_events_countries').value.replace('event_country_', ''),
		stn = $('upcoming_events_stations').value.replace('event_station_', '');
		window.events_loaded = {};
		if (cid == 'all') {
			window.events_loaded.all = true;
		}
		else if (stn == 'all') {
			eval('window.events_loaded.c' + cid + '_all = true;');
		}
		else {
			eval('window.events_loaded.c' + cid + '_' + stn + ' = true;');
		}
	});

	function loadMissingEvents() {
		var cid = $('upcoming_events_countries').value.replace('event_country_', ''),
		stn = $('upcoming_events_stations').value.replace('event_station_', '');
		
		if (window.events_loaded.all ||
				eval('window.events_loaded.c' + cid + '_all') ||
				eval('window.events_loaded.c' + cid + '_' + stn)) return false;
		showEventsOverlay();
		new Request.JSON({
			url: appPath + 'ajax/events/',
			onSuccess: function(r) {
				if (!r) return;
				if ($('upcoming_events_list')) $('upcoming_events_list').set('html', $('upcoming_events_list').get('html') + r.data);
				updateEventList();
				hideEventsOverlay();
			},
			onFailure: function(){
				hideEventsOverlay();
			}
		}).post({'country': cid, 'station': stn, 'loaded': window.events_loaded});
		
		if (cid == 'all') window.events_loaded.all = true;
		else if (stn == 'all') eval('window.events_loaded.c' + cid + '_all = true;');
		else eval('window.events_loaded.c' + cid + '_' + stn + ' = true;');
		return true;
	}
	
	function updateEventList() {
		var c = $('upcoming_events_countries').value,
		s = $('upcoming_events_stations').value,
		t = $('upcoming_events_types').getElement('div.upcoming_event_type_active a').className,
		d = $('upcoming_events_sel_date').int_date;
		
		if (!c || !s || !t || loadMissingEvents()) return;
		
		$$('#upcoming_events_list li').setStyle('display', 'none');
		
		$$('#upcoming_events_list li').each(function(l){
			if ((c != 'event_country_all' && !l.hasClass(c)) || (s != 'event_station_all' && !l.hasClass(s)) || (t != 'event_all' && !l.hasClass(t))) return;
			if (!d) {
				l.setStyle('display', 'list-item');
				return;
			}
			
			var m = false, i;
			if (/event_date_permanent/.test(l.className)) {
				m = true;
			}
			else if (/event_date_/.test(l.className)) {
				i = l.className.match(/event_date_\d+_\d+/g);
				if (i) for(var x = 0, sed = null; x < i.length; x ++) {
					sed = i[x].match(/\d+/g);
					if (i && d >= sed[0] && d <= sed[1]) {
						m = true;
						break;
					}
				}				
			}
			if (m) l.setStyle('display', 'list-item');
		});
		
		if ($('upcoming_events_list')) $('upcoming_events_list').scrollTo(0,0);
	}
	
	function showEventsOverlay() {
		var l = $('upcoming_events_list'), c = $('upcoming_events');
		if (!l || !c) return;
		var p = l.getPosition();
		c.adopt( (new Element('div', {
				'class': 'events_overlay',
				'styles': {
					'position': 'absolute',
					'top': p.y,
					'left': p.x,
					'width': c.getStyle('width'),
					'height': l.getStyle('height'),
					'margin-top': 1,
					'background-color': 'black',
					'opacity': 0.3,
					'z-index': 5
				},
				'events': {
					'mousedown': function(e) {
						return false;
					}
				}
			})).adopt(new Element('img', {
				'src': appPath + 'web_root/img/ajax-loader.gif',
				'styles': {
					'display': 'block',
					'margin': '0 auto',
					'margin-top': l.getStyle('height').toInt() / 2 - 50 
				}
			}))
		);
	}
	
	function hideEventsOverlay() {
		$$('#upcoming_events div.events_overlay').dispose();
	}
	
	/* Welcome */
	window.addEvent('domready', function(){
		$$('#welcome_container div.progress_image_layout').addEvent('mouseenter', function(){
			$$('#welcome_container div.progress_tip').setStyle('display', 'none');
			var p = $(this).getChildren('div.progress_tip')[0];
			$(this).setStyle('z-index', '2006');
			if (p) {
				p.setStyles({
					'display': 'block',
					'opacity': 0
				});
				p.morph({ 'opacity': 1});
			}
		});
		
		$$('#welcome_container div.progress_image_layout').addEvent('mouseleave', function(){
			$(this).setStyle('z-index', '2005');
			$$('#welcome_container div.progress_tip').setStyle('display', 'none');
		});
	});
	
