// ets.js v2.0.0 Copyright (c) 2006-2010 by BT-Group (info@bt-group.lt)
// All Rights Reserved.

// globalus kintamieji
var __ets_hotels = null;
var __ets_ie6 = navigator.appVersion.search('/MSIE 6.0/') >= 0;
var __ets_regions = null;
var __ets_list = null; // kintamasis i kuri saugomas variantu sarashas
var __ets_dates = null;
var __ets_infants = 0;
var __ets_def_lang = 'ln';

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function etsNumberFormat( number,decimals,dp,tsp ) {
    number = ( number + '' ).replace( ',', '' ).replace( ' ', '' );
    var n = !isFinite( +number ) ? 0 : +number, 
        prec = !isFinite( +decimals ) ? 0 : Math.abs( decimals ),
        sep = ( typeof tsp === 'undefined' ) ? ',' : tsp,
        dec = ( typeof dp === 'undefined' ) ? '.' : dp,
        s = '',
        fix = function ( n,prec ) {
            var k = Math.pow( 10, prec );
            return '' + Math.round(n * k) / k;
        };
    // fix for IE parseFloat(0.55).toFixed(0) = 0;
    s = (prec ? fix(n, prec) : '' + Math.round(n)).split('.');
    if( s[ 0 ].length > 3 ) {
        s[ 0 ] = s[ 0 ].replace( /\B(?=(?:\d{3})+(?!\d))/g,sep );
    } // if
    if( ( s[ 1 ] || '' ).length < prec ) {
        s[ 1]  = s[ 1 ] || '';
        s[ 1 ] += new Array(prec - s[1].length + 1).join( '0' );
    } // if
    return s.join(dec);
}

function etsF( number ) {
	return etsNumberFormat( number,0,'.',' ' );
}

function addClass(obj,className){
	if(!className || !obj)	
		return false;
	var classes = obj.className.split(' ');
	var is = false;
	for(var i = classes.length; i--; ){
		if(classes[i] == className){
			is = true;
			break;
		}
	}
	if(!is){
		classes.push(className);
		obj.className = classes.join(' ');
	}
	return true;
}

function delClass(obj,className){
	if(!obj)
		return false;
	var classes = obj.className.split(' ');
	if(!className){
		var removed = obj.className;
		obj.className = '';
		return removed;
	}
	for(var i = classes.length; i--; ){
		if(classes[i] == className){
			var removed = classes.splice(i,1);
			obj.className = classes.join(' ');
			return removed;
		}
	}
	return false;	
}

var base64 = {
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = base64._utf8_encode(input);
		while (i < input.length) {
 
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
 
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
 
			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}
			output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
				this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
		}
		return output;
	},
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
 
		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		while (i < input.length) {
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
		}
		output = base64._utf8_decode(output);
 
		return output;
 
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {		
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}
function etsAjax( url,callback,params ) {			
	var __ajax = {
		got : false,
		url : url,
		callback : callback,
		xmlHttp : null,
		__getXmlHttp : function() {
			var xmlHttp = null;
			try {	// Firefox, Opera 8.0+, Safari
				xmlHttp = new XMLHttpRequest();
			} catch( e ) {	// Internet Explorer
				try {	
					xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP" );	
				} catch ( e ) {	
					xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );	
				}
			}
			return xmlHttp;
		},			
		__init : function() {
			this.xmlHttp = this.__getXmlHttp();
			var self = this;
			this.xmlHttp.onreadystatechange = function() {
				if( self.xmlHttp.readyState == 4 || self.xmlHttp.readyState == 'complete' ) {	
					self.callback( self.xmlHttp.responseText );	
					self.got = true;
				}
			};
			self.xmlHttp.open( 'GET', this.url, true );
			self.xmlHttp.send( null );
		}
	}
	__ajax.__init();
	return __ajax;
}

// ONLOAD funkcija
function etsLoad( fun ) {
	if ( document.addEventListener )
		window.addEventListener( 'load',fun,false );
	else if ( document.attachEvent ) {		
		document.attachEvent( 'onreadystatechange',function(){
			if ( document.readyState === 'complete' ) {	
				fun();
			}
			return false;
		});
	}
	return false;
}

// funkcija eventams prisegti
function etsAddEvent(obj,name,callback) {
	if( document.addEventListener )	
		obj.addEventListener( name,callback,false );
	else if( document.attachEvent )
		obj.attachEvent( 'on' + name,callback );
	return false;
}
// detach
function etsRemoveEvent( obj,name,callback ) {
	if( document.addEventListener )	
		obj.removeEventListener( name,callback,false );
	else if ( document.attachEvent )
		obj.detachEvent( 'on' + name,callback );	
	return false;
}
// funkcija is JSON objekto istraukia tinkamus variantus ir 
// isspausdina radiobutonus
function etsRoomChanged( obj,group_id,upd,template ) {	
	if( __ets_list && group_id ) {
		var room = ( !obj ? __ets_list[ group_id ].cr : obj.value );
		var cp = __ets_list[ group_id ].cp;
		var ei = 0;
		var pansions = __ets_list[ group_id ][ room ].p;
		var block = $$( 'ets_pansion_block_' + group_id );
		block.innerHTML = '\n';
		var nc = '';	
		var one = true;
		
		for( var i = 0; i < pansions.s; i++ ) {
			if( pansions[ i ].pi == cp ) {
				ei = i;
				break;
			} // if
		}
		if( pansions.s == 1 )		
			nc = "<div class=\"only\">" + pansions[ 0 ].pn + "</div>\n";	
		else {
			one = false
			for( var i = 0; i < pansions.s; i++ ) {
				nc += '<table cellpadding="0" cellspacing="0" border="0"><tr>'
					+ "<td><input class=\"radio\" type=\"radio\" name=\"ets_pansion_" + group_id + "\" "
					+ "id=\"ets_pansion_" + group_id + "_" + pansions[ i ].pi + "\" "
					+ "value=\"" + pansions[ i ].pi + "\" " + ( ei == i ? "checked " : "" ) 
					+ "onclick=\"etsPansionChanged(this,'" + group_id + "',null,null" 
					+ (template ? ",'" + template + "'" : "" ) + ")\"  /></td>"
					+ "<td><label for=\"ets_pansion_" + group_id + "_" + pansions[ i ].pi + "\">"
					+ pansions[ i ].pn + "</label></td>"
					+ "<td><label for=\"ets_pansion_" + group_id + "_" + pansions[ i ].pi + "\">"
					+ "<span id=\"ets_label_" + group_id + "_" + pansions[ i ].pi + "\"></span></label></td>"
					+ '</tr></table>';
			} // for
		} // if
		block.innerHTML = nc;
		__ets_list[ group_id ].cr = room;
		etsPansionChanged( pansions[ ei ].pi,group_id,one,upd,template );
	} // if
	return false;
}

function etsBuyLinkChange( group_id,id ) {
	var j;
	if( j = $$( 'ets_buy_' + group_id ) ) {
		j.onclick = function() {
			
			switch( __ets_mode ) {
				case 3://panelis	
					if (typeof(__ets_reseller_iframe) == "undefined")
						__ets_reseller_iframe = '';						
					etsLocation( 'http://'+__ets_reseller_iframe+'#ets:order:'+id+':'+__ets_infants+'@order' );
				break;
				
				default:
					etsInitLoader(true);
					js('ets_page=order&ets_infants=' + __ets_infants + '&ets_et=' + id + '&ac=order_go#iframe');
				break;
			}//switch			
		} // if
	} // if
	return false;
}

function etsPansionChanged( obj,group_id,one,upd,template ) {	
	var pansion;
	if( __ets_list && group_id ) {
		pansion = isNaN( obj ) ? obj.value : obj;
		var sr = __ets_list[ group_id ].cr;
		var id = 0;
		
		var ap = __ets_list[ group_id ][ sr ].p;
		for( var i = 0; i < ap.s; i++ ) {
			if( ap[ i ].pi == pansion ) {				
				if( __ets_list[ group_id ].rez_cost )
					__ets_list[ group_id ].rez_cost = ap[ i ].rez_cost;												
				__ets_list[ group_id ].cc = ap[ i ].c;								
				__ets_list[ group_id ].cd = ap[ i ].d;
				__ets_list[ group_id ].cdn = ap[ i ].dn;
				__ets_list[ group_id ].cdv = ap[ i ].dv;
				__ets_list[ group_id ].ccp = ap[ i ].cp;
				__ets_list[ group_id ].cac = ap[ i ].ac;
				id = ap[ i ].id;
				break;
			} // if
		} // for
		
		if( !one ) {
			for( var i = 0; i < ap.s; i++ ) {
				var label = $$( 'ets_label_' + group_id + '_' + ap[ i ].pi );
				if( ap[ i ].pi == pansion )
					label.innerHTML = '';				
				else {
					var po = Math.round( ( ap[ i ].c - __ets_list[ group_id ].cc ) / __ets_list[ group_id ].t );
					if( Math.abs( po ) < 1 )
						continue;
					label.innerHTML = '&nbsp;&nbsp;' + ( po > 0 ? '+' + po : po ) 
						+ '&nbsp;Lt ';
				} // if
			} // for
		} // if
		
		if( __ets_list[ group_id ].s > 1 ) {
			for( var i in __ets_list[ group_id ] ) {
				if( isNaN( i ) )
					continue;
				var label = $$( 'ets_labelr_' + group_id + '_' + i );
				if( i == sr )
					label.innerHTML = '';
				else {
					var rp = __ets_list[ group_id ][ i ].p;
					var rpc = rp[ 0 ].c;
					for( var j = 0; j < rp.s; j++ ) {
						if( rp[j].pi == pansion ) {
							rpc = rp[ j ].c;
							break;
						} // if
					} // for
					rpco = Math.round( ( rpc - __ets_list[ group_id ].cc  ) / __ets_list[ group_id ].t );
					if( Math.abs( rpco ) < 1 )
						continue;
					label.innerHTML = '&nbsp;&nbsp;' + ( rpco > 0 ? '+' + rpco : rpco ) 
						+ '&nbsp;Lt ';
				} // if
			} // for
		} // if
		__ets_list[ group_id ].cp = pansion;
		etsPriceChange( group_id );	
		etsBuyLinkChange( group_id,id );
		etsDceLinkChange( group_id,id);

		etsDatesChange( group_id,upd,template );
	} // if
	return false;
}

function etsDceLinkChange( group_id,id) {
	var j;
	if( j = $$( 'dce_' + group_id ) )
		j.innerHTML = '<img src="/img/dce/items.png" alt="" title="Kelionės informacija" '
					+ 'onclick="popup.jbd(\'/admin/popup/dce_ets_teztour_travel_info?etid='+id+'\',430,400)" />'
					+ '<img src="/img/dce/page_link.png" alt="" title="Nuoroda į kelionę" '
					+ 'onclick="popup.jbd(\'/admin/popup/ets_tour_link?etid='+id+'\',560,200)" />';
	return false;
}

function etsGetDataChangeLoader() {
	return '<table width="247" height="80" border="0" cellpadding="0" cellspacing="2" style="margin-top:10px">'
		 + '<tr>'
		 + '<td width="47" height="47" align="right" valign="middle"><img src="/img/ajax_loader.gif" width="32" height="32" /></td>'
		 + '<td width="194" align="center" valign="middle"><b>Ieškome kelionių pasiulymų ...</b></td>'
		 + '</tr>'
		 + '</table>';
}

function etsDatesChangeWait( group_id ) {
	var j;
	if( j = $$( 'dates_' + group_id ) )
		j.innerHTML = etsGetDataChangeLoader();
	return false;
}

function etsDatesChange( group_id,upd,template ) {
	var j;
	
	if( upd )
		return;

	if( j = $$( 'dates_' + group_id ) ) {
		var room = __ets_list[ group_id ].cr;
		var accomodation = __ets_list[ group_id ].acm;
		var pansion = __ets_list[ group_id ].cp;
		var duration = __ets_flx ? __ets_flx.duration.join( ':' ) : null;
		var hotel = __ets_list[ group_id ].ho;
		// laukimo langas
		var wait = setTimeout( 'etsDatesChangeWait( ' + group_id + ')',1000 );
		if (typeof(template) == "undefined") 
			template = "";
		if (typeof(__ets_mode) == "undefined") 
			__ets_mode = "";
		
		var ajax = new etsAjax('/admin/bg/ets_ajax?idn=travel&ets_base=' + __ets_base + '&ets_etg=' + group_id + '&ets_hotel=' + hotel 
					+ '&ets_room=' + room + '&ets_accomodation=' + accomodation + '&ets_duration=' + duration + '&ets_tc=' + __ets_tcx
					+ '&ets_pansion=' + pansion + '&ac=update_dates' + '&template=' + template + '&mode=' + __ets_mode, 
			function( data ) { 
				clearTimeout( wait );
				j.innerHTML = data;
			}
		);
	} // if
	return false;
}

function etsPriceChange( group_id ) {
	var j;
	var disc;
	if( j = $$('ets_' + group_id + '_catalog_price_label') )
		j.innerHTML = etsF( __ets_list[ group_id ].ccp );
	
	if( j = $$('ets_' + group_id + '_catalog_price_label_nodiscount') )
		j.innerHTML = etsF( __ets_list[ group_id ].ccp );
	
	disc = __ets_list[ group_id ].cd;
	
	if( j = $$('ets_' + group_id + '_discount_tbody') )
		j.className = disc ? 'table-row-group' : 'table-row-group-none';
		
	if( j = $$('ets_' + group_id + '_nodiscount_tbody') )
		j.className = disc ? 'table-row-group-none' : 'table-row-group';
	
	if( j = $$('ets_' + group_id + '_discount_label') )
		j.innerHTML = etsF( disc );
		
	if( j = $$('ets_' + group_id + '_discount_value_label') )
		j.innerHTML = etsF( __ets_list[ group_id ].cdv );	
		
	if( j = $$('ets_' + group_id + '_full_price_label') )	
		j.innerHTML = etsF( __ets_list[ group_id ].cc );
		
	if( j = $$('ets_' + group_id + '_full_price_label_nodiscount') )	
		j.innerHTML = etsF( __ets_list[ group_id ].cc );
	
	if( j = $$('ets_' + group_id + '_average_price_label' ))
		j.innerHTML = etsF( __ets_list[ group_id ].cac );
	
	if( ( j = $$('ets_prom_info_' +  group_id) ) && ( p = $$('ets_prom_text_' +  group_id) ) ) {
		if( __ets_list[ group_id ].cdn ) {
			p.innerHTML = __ets_list[ group_id ].cdn;
			j.style.display = 'block';
		} else {
			p.innerHTML = '';
			j.style.display = 'none';		
		}
	} // if
	if( j = $$('ets_' + group_id + '_rez_cost') )	
		j.innerHTML = etsF( __ets_list[ group_id ].rez_cost );
	return false;
}

// is esamo urlo paema argumenta
// reikiamo argumento vardas nurodomas per parametra NAME
function getParam( name ) {
	var regex = new RegExp( "[\\?&]" + ( name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]") ) + "=([^&#]*)" );
	var r = regex.exec( window.location.href );
	return ( r == null ) ? null : results[ 1 ];
}

// iframe resizinimas
// funkcija uzdeda ant nematomo iframe'o url su kitu domenu ir per argumentus perduoda 
// auksti pagrindinio iframe'o
function etsIframeResize( newh ) {	
	var dd = $$('domains').value.split(',');
	var hh = newh ? newh : document.body.scrollHeight;
	for( var i = 0; i < dd.length; i++ ){
		var domain = dd[ i ].toString().trim();
		var pipe = $$( domain + '_if' );
		if( !pipe ) {
			pipe = document.createElement( 'iframe' );
			pipe.setAttribute( 'id', domain + '_if' );
			pipe.style.display = 'none';
			document.body.appendChild( pipe );
		} // if
		var j = 'http://' + domain + '/ets.html?function=resize&height=' + hh + '&cacheb=' + Math.random();
		try {
			if( !window.parent.location.host ) {
				if( domain && pipe )			
					pipe.src = j;
			} // if
		} catch( e ) { 
			if( domain && pipe )	
				pipe.src = j;
		}
	} // for
	
	return false;
}

function etsPopup( url,width,height ) {
	function __otherDomain() {
		var dd = document.getElementsByTagName('body').item(0).getAttribute('id');
		var pipe = $$('invframe2');
		if( dd && pipe && url ) {			
			url = base64.encode(url.toString());
			pipe.src = 'http://'+dd+'/ets.html?function=popup'
					 + '&url=' + url
					 + (!isNaN(width) ? '&width=' + width : '')
					 + (!isNaN(height) ? '&height=' + height : '')
					 + '&cacheb='+Math.random();			
		} // if
		return false;
	}
	function __currentDomain() {
		return false;
	}
	
	try {
		if( !window.parent.location.host ) {
			__otherDomain();	
			return false;
		} // if
		__currentDomain();
	} catch( e ) {
		__otherDomain();
	}
	return false;
}

// funkcija is ANCHOR paema paveikslelio url, preloadina ir pakeicia pagrindini 
var ets_change_pic = {
	images : new Array,
	curImg : null,
	set : function() {
		var links = document.links;
		for(var i = 0; i < links.length; i++) {
			if(links.item(i).className == 'gallery-img') {
				this.curImg = links.item(i).href;	
				break;
			}
		}
	},
	go :function(obj) {		
		// pajamam pagrindini paveiksleli
		var main_img = $$('main-img');
		var w = parseInt(main_img.style.width);
		var h = parseInt(main_img.style.height);		
		if(this.curImg == obj.href)
			return false;
		
		this.curImg = obj.href;
		// uzkraunam nauja paveikslei 
		var img = new Image();
		
		// isvalom pagrindinio paveikslelio konteinerio vidu
		main_img.innerHTML = '';

		// sukuriame tada pagrindiniame konteineryje musu uzdanga
		var main_img_cover = document.createElement('div');
		main_img_cover.style.width = w + "px";
		main_img_cover.style.height = h + "px";		
		main_img.appendChild(main_img_cover);
		
		var tempas = document.createElement("div");
		tempas.style.zIndex = 500;
		tempas.style.position = "absolute";					
		tempas.style.top = 0 + "px";
		tempas.style.left = 0 + "px";					
		tempas.style.width = w + "px";
		tempas.style.height = h + "px";
		tempas.style.backgroundPosition = "50% 50%";
		tempas.style.backgroundRepeat = "no-repeat";	
		main_img.appendChild(tempas);
		
		// funkcija uztamsinimui
		function __shadowIn(to) {			
			main_img_cover.style.backgroundColor = "#000000";
			main_img_cover.style.opacity = 0;
			main_img_cover.style.filter = 'alpha(opacity=0)';
			// jeigu yra timeoutas
			var timeout_set = false;
			// timeouto handleris
			var timeout;			
			var interval;
			var current = 0;
			interval = setInterval(function(){
				current++;
				if(current < to) {
					main_img_cover.style.opacity = current/10;
					main_img_cover.style.filter = 'alpha(opacity='+10*current+')';
				} else {
					timeout = setTimeout(function(){					
						tempas.style.backgroundImage = "url(/img/ets/loading.gif)";				
						timeout_set = true;					
					},500);																		
					img.onload = function(){	
						main_img.style.backgroundImage = 'url('+img.src+')';		
						if(timeout_set)
							tempas.style.backgroundImage = "";
						else {
							clearTimeout(timeout);
						}					
						__shadowOut();					
					}				
					img.src = obj.href;		
					clearInterval(interval);									
				}
			},50);			
		}
		function __shadowOut() {
			main_img_cover.style.backgroundColor = "#000000";		
			var interval;
			var current = main_img_cover.style.opacity * 10;		
			interval = setInterval(function(){
				current--;
				if(current >= 0) {
					main_img_cover.style.opacity = current/10;
					main_img_cover.style.filter = 'alpha(opacity='+10*current+')';
				}else{				
					clearInterval(interval);	
				}
			},50);			
		}	
		__shadowIn(5);					   						   
		return false;
	}
};

// galerijos valdymas
var ets_gallery = {
	// nustatymai
	__settings : {
		ok : false, // ar viskas gerai uzsetinta
		animated : false,
		total : 0, // nuotrauku skaicius ( aprasymo moduliui )
		current : 1, // esamai parinkta grupe
		shown: new Array, // rodomos grupes
		// ID ir Classes reikalginos
		curPageId : 'gallery-nav-sel', // esamas puslapis
		groupCl: 'group', // img grupes klase
		imageCont: 'div'
	},
	// funkcija pastumti nuotrauku navigacija 
	// per (nurodyta OFFSET)
	set : function() {					
		// gauna rodomas fotkes ir sukala i masyva			
		var groups = document.getElementsByTagName(this.__settings.imageCont);
		var shown = new Array();
		
		// nusiskaitom visas grupes ( kad galetume tarp ju naviguoti )
		for(var i = 0; i < groups.length; i++) {
			if(groups.item(i).className == this.__settings.groupCl) {				
				shown.push(groups.item(i))				
			} // if
		} // for
		this.__settings.shown = shown;
		this.__settings.ok = true;
		this.__settings.total = shown.length;
	},
	go : function(obj,page) { 
		// jeigu viskas ok ir siuo metu nevyksta jokia animacija 
		// tikriname kox offsetas duotas
		if(this.__settings.ok && !this.__settings.animated) {			
			// juda i prieki 
			if(page > this.__settings.current && page <= this.__settings.total) {										
				this.__settings.animated = true;
				// gaunam is desines nauja thumba					
				var img_new = this.__settings.shown[page-1];
				this.__animate(img_new,1,10,'show','left');					
				// pasaliname is rodomu pradzios imiga
				var img_old = this.__settings.shown[this.__settings.current-1];
				this.__animate(img_old,1,10,'hide','left');
				this.__settings.current = page;							
			} else if(page < this.__settings.current && page >= 1) {
				// juda atgal
				this.__settings.animated = true;
				// gauna is kaires thumba 
				var img_new = this.__settings.shown[page-1];
				this.__animate(img_new,1,10,'show','right');					
				var img_old = this.__settings.shown[this.__settings.current-1]				
				this.__animate(img_old,1,10,'hide','right');
				this.__settings.current = page;
			}
			var j;
			if( j = $$('gallery-nav-sel') ) {
				delClass(j,'sel');
				j.removeAttribute('id');
			} // if
			obj.setAttribute('id','gallery-nav-sel');
			addClass(obj,'sel');
		}
		// uzmusham hrefa		
		return false; 
	},
	__animate : function(obj,speed,step,anim,direction) {
		var original = parseInt(obj.style.width);
		var tick = function() {
			clearInterval()
		};
		var current_int;
		var self = this;
		switch(anim) {
			case 'show':		
				obj.style.display = 'block';				
				// jeigu i desine
				switch(direction) {
					case 'right':
						obj.style.left = -original + "px";												
						tick = function(){
							if(parseInt(obj.style.left) < 0){					
								var tmp = parseInt(obj.style.left) + step;
								if(tmp > 0)
									tmp = 0;
								obj.style.left = tmp + "px";
							} else {						
								self.__settings.animated = false;					
								clearInterval(current_int);					
							}
						}						
					break;	
					case 'left':
						obj.style.left = original + "px";												
						var tick = function(){
							if(parseInt(obj.style.left) > 0){						
								var tmp = parseInt(obj.style.left) - step;
								if(tmp < 0)
									tmp = 0;
								obj.style.left = tmp + "px";
							}
							else {						
								self.__settings.animated = false;					
								clearInterval(current_int);					
							}
						}						
					break;						
				}						
			break;
			case 'hide':		
				switch(direction) {
					case 'right':
						obj.style.left = 0 + "px";	
						var tick = function(){					
							if(parseInt(obj.style.left) < original) {				
								var tmp = parseInt(obj.style.left) + step;
								if(tmp > original)
									tmp = original;
								obj.style.left = tmp + "px";								
							} else {
								obj.style.display = 'none';
								obj.style.left = 0 + "px";	
								self.__settings.animated = false;
								clearInterval(current_int);					
							}
						}					
					break;
					case 'left':
						obj.style.left = 0 + "px";	
						var tick = function(){					
							if(parseInt(obj.style.left) > -original) {						
								var tmp = parseInt(obj.style.left) - step;
								if(tmp < -original)
									tmp = -original;
								obj.style.left = tmp + "px";
							} else {
								obj.style.display = 'none';
								obj.style.left = 0 + "px";	
								self.__settings.animated = false;
								clearInterval(current_int);					
							}
						}
					break;
				}
			break;
		}
		current_int = setInterval(tick,speed);
	}
};

// tooltips
var ets_tooltips  = {
	settings : {		
		offX : 10, 
		offY : 10,
		checkIn : new Array('img'),
		_offsetX : 2,
		_offsetY : 2,		
		_tooltip : null,
		_node : null
	},
	set : function (){
		// nustatome offseta tooltipo
		this.settings._offsetX = this.settings.offX;
		this.settings._offsetY = this.settings.offY;		
		// nuskaitome elementus
		for(var i = 0; i < this.settings.checkIn.length; i++) {
			var elements = document.getElementsByTagName(this.settings.checkIn[i]);
			for(var j = 0; j < elements.length; j++) {
				var element = elements[j];
				if(element.getAttribute('title')) {													
					var self = this;
					etsAddEvent(element,'mouseover',function(event) {self._over(this,event) });
					etsAddEvent(element,'mouseout',function(event) {self._out(this) });
					etsAddEvent(element,'mousemove',function(event) { self._move(event) });
				}										
			}
		}
	},
	_over : function(a,e) {				
		a = (window.event) ? window.event.srcElement : a;	
		if(!a)
			return false;
		if(!this.settings._tooltip && !this.settings._node) {
			this.settings._tooltip = a.getAttribute('title');
			a.setAttribute('title','');
			var XY = this._getCursorPos(e).split('x');				
			var tempas = document.createElement("div");
			tempas.className = "tooltip";	
			tempas.style.width = 250 + 'px';
			tempas.style.top = XY[1] + "px";
			tempas.style.left = XY[0] + "px";					
			tempas.innerHTML = this.settings._tooltip;
			document.body.appendChild(tempas);
			this.settings._node = tempas;
		}
	},	
	_out : function(a) {
		a = (window.event) ? window.event.srcElement : a;			
		if(!a)
			return false;
		
		if(this.settings._tooltip) {
			document.body.removeChild(this.settings._node);
			a.setAttribute('title',this.settings._tooltip);
			this.settings._node = null;
			this.settings._tooltip = null;
		}
	},
	_getCursorPos : function(e) {
		var x = (!window.event) ? e.pageX : window.event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		var y = (!window.event) ? e.pageY : window.event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);		
		x += this.settings._offsetX;
		y += this.settings._offsetY;		
		return x + "x" + y;				
	},
	_move : function(e) {
		var XY = this._getCursorPos(e).split('x'),				
			iebody = ( document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body,
			scrolledDown = document.all ? iebody.scrollTop : pageYOffset,							
			window_w = document.all ? iebody.clientWidth : window.innerWidth,
			window_h = document.all ? iebody.clientHeight : window.innerHeight;	
		
		var horizontal_pos = XY[0];
		if( ( parseInt(XY[0]) + 250) >= (window_w - 30) ){
			horizontal_pos = XY[0] - 30 - 250;
		}
		
		if(this.settings._tooltip) {
			var XY = this._getCursorPos(e).split('x');				
			this.settings._node.style.top = XY[1] + "px";
			this.settings._node.style.left = horizontal_pos + "px";			
		}
	}
}

// viesbuciu / zvaigsduciu JSON ir selectu spausdinimas
// papildymas json yra per AJAX. perdavus regiona
var ets_hotels = {
	__settings: {
		countrySelectName : 'ets_direction',
		regionSelectName : 'ets_region',		
		starSelectName : 'ets_hotel_stars',
		hotelSelectName : 'ets_hotel',
		dateSelectName : 'ets_departure',
		regionObj : null,
		countryObj :null,
		starObj : null,
		hotelsObj : null,
		dateSelectObj : null,
		stars : new Array(),
		url : '/admin/bg/ets_ajax?idn=filter',
		dates : []
	},
	set: function() {
		this.__settings.countryObj = $$$(this.__settings.countrySelectName).item(0);
		this.__settings.regionObj = $$$(this.__settings.regionSelectName).item(0);
		this.__settings.starObj = $$$(this.__settings.starSelectName).item(0);
		this.__settings.hotelsObj = $$$(this.__settings.hotelSelectName).item(0);
		this.__settings.dateSelectObj = $$$(this.__settings.dateSelectName).item(0);
		if(this.__settings.regionObj && this.__settings.starObj && this.__settings.hotelsObj) {
			for(var i = 1; i < this.__settings.starObj.length; i++) {
				this.__settings.stars.push(new Array(this.__settings.starObj.options[i].value,this.__settings.starObj.options[i].innerHTML))
			}
			var self = this;
			etsAddEvent(this.__settings.regionObj,'change',function(event){self.changeRegion(this,self)});
			etsAddEvent(this.__settings.countryObj,'change',function(event){self.changeCountry(this,self)});
			etsAddEvent(this.__settings.starObj,'change',function(event){self.changeStars(this,self)});
			this.init();		
		}
	},
	changeCountry: function(obj,self) {
		obj = (window.event) ? window.event.srcElement : obj;	
		if(!obj)
			return false;
		self.disable();
		var c = this.__settings.countryObj.value;
		var ajax = new etsAjax(self.__settings.url + '&ets_country=' + c, function( data ){ 
			// cia dadedu ir datas kad gautu ir i globalu kintamaji sukistu
			data = data.split( ' | ' );
			eval( '__ets_hotels = ' + data[ 0 ] + ';' ); 
			eval( '__ets_dates = ' + data[ 1 ] + ';' );
			eval( '__ets_regions = ' + data[ 2 ] + ';' );
			self.init(); 
			self.enable();
		});
	},
	changeRegion: function(obj,self) {
		obj = (window.event) ? window.event.srcElement : obj;	
		if(!obj)
			return false;
		self.disable();
		var s = this.__settings.starObj.value;
		var c = this.__settings.countryObj.value;
		var r = this.__settings.regionObj.value;
		var ajax = new etsAjax(self.__settings.url + '&ets_country=' + c + '&ets_region=' + r + '&ets_stars=' + s, function( data ){ 
			// cia dadedu ir datas kad gautu ir i globalu kintamaji sukistu
			data = data.split(' | ')
			eval('__ets_hotels = ' + data[ 0 ] + ';'); 
			eval('__ets_dates = ' + data[ 1 ] + ';'); 
			eval( '__ets_regions = ' + data[ 2 ] + ';' );
			self.init();
			self.enable();
		});
	},
	changeStars: function(obj,self) {
		obj = (window.event) ? window.event.srcElement : obj;	
		if(!obj)
			return false;
		self.disable();
		var s = this.__settings.starObj.value;
		var c = this.__settings.countryObj.value;
		var r = this.__settings.regionObj.value;
		var ajax = new etsAjax(self.__settings.url + '&ets_country=' + c + '&ets_region=' + r + '&ets_stars=' + s, function( data ){ 
			// cia dadedu ir datas kad gautu ir i globalu kintamaji sukistu
			data = data.split( ' | ' );
			eval( '__ets_hotels = ' + data[ 0 ] + ';' ); 
			eval( '__ets_dates = ' + data[ 1 ] + ';' );
			self.init(); 
			self.enable();
		});
	},
	disable: function() {
		this.__settings.countryObj.disabled = true;
		this.__settings.regionObj.disabled = true;
		this.__settings.starObj.disabled = true;
		this.__settings.hotelsObj.disabled = true;
		this.__settings.dateSelectObj.disabled = true;
	},
	enable: function() {
		this.__settings.countryObj.disabled = false;
		this.__settings.regionObj.disabled = false;
		this.__settings.starObj.disabled = false;
		this.__settings.hotelsObj.disabled = false;
		this.__settings.dateSelectObj.disabled = false;
	},
	isValidDate: function( date ) {
		var day = date.getDate();
		if( day < 10 )
			day = '0' + day;
		var month = date.getMonth() + 1;
		if(	month < 10 )
			month = '0' + month;
		var year = date.getFullYear();
		if( typeof( this.__settings.dates[ year + '-' + month + '-' + day ] ) == 'undefined' )			 
			return [false];				 
		return [true];
	},
	initDatePicker: function() {
		var j;
		var self = this;
		if( j = $$( 'ets_departure' ) ) {
			$( j ).datepick({
				changeYear: false,
				changeMonth: false,
				fixedWeeks: true,
				beforeShowDay : function( date ) {
					return self.isValidDate( date );
				}
			});
		} // if
		return false;
	},
	init: function() {	
		this.disable();
		// uztatom pradine rodoma data
		var same = false;
		var j = $$( 'ets_departure' );
		var c = 0;
		// greitos paieskos masyvas
		this.__settings.dates = [];
		for( var i in __ets_dates ) {
			this.__settings.dates[ __ets_dates[ i ] ] = true;
			c++;
		} // for
		// pradine data
		for( var i in __ets_dates ) {			
			if( __ets_dates[ i ] == j.value ) {
				same = true;
				break;
			} // if
		} // for
		if( !same && i ) {
			j.value = __ets_dates[ 0 ];
		} // if
		
		// regionai
		var fragment = document.createDocumentFragment();
		fragment.appendChild( this.__settings.regionObj.options[ 0 ] );
		this.__settings.regionObj.innerHTML = '';
		for( var i = 0; i < __ets_regions.length; i++ ){
			var option = document.createElement('option');
			option.value = __ets_regions[i].i;
			option.innerHTML = __ets_regions[i].n;
			if(__ets_regions[i].i == __ets_regions.selected)
				option.selected = true;
			fragment.appendChild( option );
		} // for
		this.__settings.regionObj.appendChild(fragment);
	
		// viezbuciai
		var fragment = document.createDocumentFragment();
		fragment.appendChild( this.__settings.hotelsObj.options[ 0 ] );
		this.__settings.hotelsObj.innerHTML = '';
		for(var i = 0; i < __ets_hotels.length; i++) {
			var option = document.createElement('option');
			option.value = __ets_hotels[i].i;			
			option.innerHTML = __ets_hotels[i].h;
			if(__ets_hotels[i].i == __ets_hotels.selected)
				option.selected = true;	
			fragment.appendChild(option);
		} // for
		this.__settings.hotelsObj.appendChild(fragment);
		
		this.enable();
		this.initDatePicker();
	}
};
// tikrinim
var ets_input_checker = {
	// blogo fieldo nuspalvinimas
	input_color: '#FFAFAF',
	mark_class: 'bad-input',
	// pranesimai erroru
	messages: {},
	__showErrors : '',
	// taisykles
	__rules: {
		notEqual:null,
		filled:null,
		emails:null,
		ak:null
	},
	// patikrinimo rezultatai
	__results: {
		notEqual:null,
		filled:null,
		emails:null,
		ak:null
	},
	// visi inputu vardai
	__allInputs: null,
	__ok: true,
	// uzstato taisykles
	setRules : function(rules) {
		var tmp_all_json = new Array();
		for(var rule in this.__rules) {
			if(rules[rule]) {
				if(rules[rule].length) {
					this.__rules[rule] = rules[rule];
					var tmp_json = new Array();
					
					for(var i in rules[rule]) {
						var name = rules[rule][i];
						tmp_json.push(name + ': false');
						if(tmp_all_json.join(',').search('/'+name+'/i')) {
							tmp_all_json.push(name + ': false');
						}
					}
					eval('tmp_json = ' + '{' + tmp_json.join(',') + '}');
					this.__results[rule] = tmp_json;
				}
			}
		}
		eval('tmp_all_json = ' + '{' + tmp_all_json.join(',') + '}');
		this.__allInputs = tmp_all_json;
	},
	_showErrorMesagges : function(){
		if(this.__showErrors){
			if($$('input-error')){
				$$('input-error').style.display = 'block';
				$$('input-error').innerHTML = this.__showErrors;
			}
		}else{
			if($$('input-error'))
				$$('input-error').style.display = 'none';				
		}
	},
	// patikrinimas
	check : function() {
		this.__showErrors = '';
		this.__ok = true;
		// jeigu yra tokiu lauku kurie turi buti uzpildyti
		if(this.__rules.filled && this.__rules.filled.length) {
			// paleidziam cikla per kiekviena elementa ir tikriname
			// rezultata saugom
			for(var name in this.__results.filled) {
				var elem = $$$(name).item(0);
				switch(elem.tagName) {
					case 'TEXTAREA':
					case 'textarea':
						if(elem.value != '') {
							this.__results.filled[name] = true;
							this.__allInputs[name] = false;
						} else {
							if(this.messages.filled && !this.__showErrors.match(this.messages.filled))
								this.__showErrors += this.messages.filled; 								
							this.__allInputs[name] = true;
							this.__results.filled[name] = false;
							this.__ok = false;
						}
					break;
					case 'SELECT':
					case 'select':
						if(elem.options[elem.selectedIndex].value) {
							this.__results.filled[name] = true;
							this.__allInputs[name] = false;							
						} else {
							if(this.messages.filled && !this.__showErrors.match(this.messages.filled))
								this.__showErrors += this.messages.filled; 								
							this.__allInputs[name] = true;
							this.__results.filled[name] = false;
							this.__ok = false;							
						}						
					break;
					case 'INPUT':
					case 'input':
						switch(elem.getAttribute('type')) {
							case 'radio':
								var wasChecked = false;
								var j = $$$(name);
								for( var i = 0; i < j.length; i++ ) {
									if(j[i].checked){										
										this.__results.filled[name] = true;
										this.__allInputs[name] = false;
										wasChecked = true;
										break;
									}									
								}								
								if(!wasChecked) {
									if(this.messages.filled && !this.__showErrors.match(this.messages.filled))
										this.__showErrors += this.messages.filled; 										
									this.__allInputs[name] = true;
									this.__results.filled[name] = false;
									this.__ok = false;		
								}
							break;
							case 'checkbox':								
								if(elem.checked) {
									this.__results.filled[name] = true;
									this.__allInputs[name] = false;
								} else {					
									if(this.messages.filled && !this.__showErrors.match(this.messages.filled))
										this.__showErrors += this.messages.filled; 									
									this.__allInputs[name] = true;
									this.__results.filled[name] = false;
									this.__ok = false;				
								}
							break;
							case 'text':
								if(elem.value != '') {
									this.__results.filled[name] = true;
									this.__allInputs[name] = false;
								}
								else {
									if(this.messages.filled && !this.__showErrors.match(this.messages.filled))
										this.__showErrors += this.messages.filled; 										
									this.__allInputs[name] = true;
									this.__results.filled[name] = false;
									this.__ok = false;																	
								}								
							break;
						}
					break;
				}			
			}
		}
		// tikrina ar nera lygiu lauku is nurodytu
		if(this.__rules.notEqual && this.__rules.notEqual.length) {
			for(var name in this.__results.notEqual) {
				var elem = $$$(name).item(0);
				for(var name2 in this.__results.notEqual) {
					var elem2 = $$$(name2).item(0);
					if(name != name2) {
						if(elem.value != elem2.value) {
							this.__results.notEqual[name] = true;							
							this.__allInputs[name] = this.__allInputs[name] ? true : false;
						} else {
							if(this.messages.notEqual && !this.__showErrors.match(this.messages.notEqual))
								this.__showErrors += this.messages.notEqual; 	
							this.__allInputs[name] = true;
							this.__results.notEqual[name] = false;
							this.__ok = false;
						}
					}
				}
			}
		}		
		// tikriname emailus
		if(this.__rules.emails && this.__rules.emails.length) {
			for(var name in this.__results.emails) {
				var elem = $$$(name).item(0);
				if(this._checkEmail(elem.value)) {
					this.__results.emails[name] = true;		
					this.__allInputs[name] = false;
				}
				else {
					if(this.messages.emails && !this.__showErrors.match(this.messages.emails))
						this.__showErrors += this.messages.emails; 							
					this.__allInputs[name] = true;
					this.__results.emails[name] = false;
					this.__ok = false;
				}
			}
		}
		
		if(this.__rules.ak && this.__rules.ak.length) {
			for(var name in this.__results.ak) {
				var elem = $$$(name).item(0);
				if(etsCheckAK(elem.value)) {		
					this.__results.ak[name] = true;		
					this.__allInputs[name] = this.__allInputs[name] ? true : false;
				} else {				
					if(this.messages.ak && !this.__showErrors.match(this.messages.ak))
						this.__showErrors += this.messages.ak; 	
					this.__allInputs[name] = true;
					this.__results.ak[name] = false;
					this.__ok = false;
				}
			}
		}
		// jeigu OK patapo FALSE tai pazymim kaltininkus ir grazinam FALSE
		this._mark();
		this._showErrorMesagges();
		if(!this.__ok)
			window.location.hash = "error";
		return this.__ok;		
	},
	_mark : function() {
		for(var i in this.__results.filled) {
			var elem = $$$(i).item(0);			
			if(!this.__allInputs[i]) {
				if(elem.getAttribute('type') && elem.getAttribute('type') == 'checkbox') {
					if(elem.parentNode.tagName == 'label' || elem.parentNode.tagName == 'LABEL')
						delClass(elem.parentNode.parentNode,this.mark_class);
					else delClass(elem.parentNode,this.mark_class);
				} else if(elem.getAttribute('type') && elem.getAttribute('type') == 'radio') {					
					var length_tmp =  $$$(i).length;
					for( var j = 0; j < length_tmp; j++ ) {								
						if(isNaN(j))
							continue;						
						delClass($$$(i).item(j).parentNode,this.mark_class);
					}
				} else delClass(elem,this.mark_class);
			}
			else {					
				if(elem.getAttribute('type') && elem.getAttribute('type') == 'checkbox'){									
					if(elem.parentNode.tagName == 'label' || elem.parentNode.tagName == 'LABEL')
						addClass(elem.parentNode.parentNode,this.mark_class);
					else addClass(elem.parentNode,this.mark_class);
				} else if(elem.getAttribute('type') && elem.getAttribute('type') == 'radio') {							
					var length_tmp =  $$$(i).length;
					for( var j = 0; j < length_tmp; j++ ) {													
						if(isNaN(j))
							continue;						
					
						$$$(i).item(j).parentNode.style.backgroundColor = this.input_color;							
						addClass($$$(i).item(j).parentNode, this.mark_class);							
					}
				} else addClass(elem, this.mark_class);							
			}
		}
		// suzymi inputus kur blogi emailai
		for(var i in this.__results.emails) {
			var elem = $$$(i).item(0);	
			if(!this.__allInputs[i]) {		
				delClass(elem, this.mark_class);
			} else {	
				addClass(elem, this.mark_class);
			}
		}
		// suzymi indentiskus, bet neleistinus inputus
		for(var i in this.__results.notEqual) {
			var elem = $$$(i).item(0);
			if(!this.__allInputs[i]) {
				if(elem.getAttribute('type') && elem.getAttribute('type') == 'checkbox')				
					delClass(elem.parentNode, this.mark_class);
				else delClass(elem, this.mark_class);
			} else {
				if(elem.getAttribute('type') && elem.getAttribute('type') == 'checkbox')				
					addClass(elem.parentNode, this.mark_class);
				else addClass(elem, this.mark_class);
			}
		}
		// suzymi inputus kur blogi ak
		for(var i in this.__results.ak) {
			var elem = $$$(i).item(0);	
			if(!this.__allInputs[i]){
				delClass(elem, this.mark_class);
			} else {	
				addClass(elem, this.mark_class);
			}
		}
	},
	_checkEmail : function( str ) {		
		var pat = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		return pat.test(str);				
	}
};
// LABEL fixas (onclick pazymi esama elementa)
function etsLabelFix() {
	var elems = document.getElementsByTagName('LABEL');
	for(var i = 0, len = elems.length; i < len; i++) {
		var elem = elems[ i ];
		etsAddEvent(elem,'click',function(event){etsLabelEvent(this)});
	}
	return false;
}

function etsLabelEvent(o) {
	var obj = window.event ? window.event.srcElement : o;
	if(obj.tagName != 'LABEL' && obj.parentNode.tagName == 'LABEL') {
		obj = obj.parentNode;
	}
	if(obj.htmlFor) {
		var input = $$(obj.htmlFor);
		input.click();
	}
	var children = obj.childNodes;
	for(var i in children) {
		if(children[i].tagName == 'INPUT') {
			switch(children[i].getAttribute('type')) {
				case 'checkbox':
				case 'radio':					
					children[i].click();	
				break;
				case 'text':
					children[i].focus();
				break;
			}
			break;				
		} // if
	} // for 
}
// pasilna value reiksme
function etsRemoveValue(obj,def) {
	if(obj.value == def) {
		obj.value = '';
	}
	return false;
}

function etsToogleShowInputs(id) {
	var block = $$( id );
	block.style.display = ( block.style.display == 'block' ) ? 'none' : 'block';
	return true;
}
// funkcija togglina slideDown, Up efekta
function etsToggleShowFilters(id) {
	var big_selects = $$$('ets_hotel').item(0);
	var block = $$(id);
	var offset = 12;
	if(block.className != 'animated') {
		// jeigu blokas nurodytas nerodomas
		if(block.style.display == 'none') { 
			var diff = 1;
			block.className = 'animated'; block.style.overflow = 'hidden';
			block.style.height = diff + 'px';
			block.style.display = 'block';			
			big_selects.style.display = 'none';
			var o_height = block.scrollHeight;			
			var interval = setInterval(function() {
				if((diff += offset) < o_height) {
					block.style.height = diff + 'px';
				} else {
					block.style.height = o_height + 'px';
					block.className = '';
					big_selects.style.display = 'inline';
					clearInterval(interval);
				}
			},1);
		} else { // jeigu rodomas (reik paslepti) 
			var diff = block.scrollHeight;
			var o_height = diff;
			block.className = 'animated'; block.style.overflow = 'hidden';
			big_selects.style.display = 'none';					
			var interval = setInterval(function(){
				if((diff -= offset) > 1) {
					block.style.height = diff + 'px';	
				} else {
					block.style.display = 'none';
					block.style.height = o_height + 'px';
					block.className = '';
					big_selects.style.display = 'inline';
					clearInterval(interval);
				}
			},1);
		}
	}
}
// padininamas stiklas ( ale )
// tooltips
var ets_magnifier = {
	settings : {		
		offX : 15, 
		offY : 15,
		checkIn : new Array('a'),
		_offsetX : 2,
		_offsetY : 2,		
		_tooltip : null,
		_node : null,
		_loader : null,
		_className : null
	},
	tempas : null,
	set : function (className){
		// nustatome offseta tooltipo
		var pat= new RegExp(className,"i");
		if(!$$('magnifierBlock')){
			this.tempas = document.createElement("div");			
			this.tempas.className = "magnifier";	
			this.tempas.id = 'magnifierBlock';
			this.tempas.style.display = 'none';
			this.tempas.innerHTML = '<div id="magn-content" ></div>';			
			document.body.appendChild(this.tempas);
		}
		this.settings._offsetX = this.settings.offX;
		this.settings._offsetY = this.settings.offY;		
		// nuskaitome elementus
		for(var i = 0; i < this.settings.checkIn.length; i++) {
			var elements = document.getElementsByTagName(this.settings.checkIn[i]);
			for(var j = 0; j < elements.length; j++) {
				var element = elements[j];
				if(pat.test(element.className) && element.getAttribute('rel')) {
					this.settings._className = className;
					var self = this;
					etsAddEvent(element,'mouseover',function(event) {self._over(this,event)});
					etsAddEvent(element,'mouseout',function(event) {self._out(this)});
					etsAddEvent(element,'mousemove',function(event) {self._move(event)});
				}
			}
		}				
	},
	_over : function(a,e) {				
		var pat= new RegExp(this.settings._className,"i");
		a = (window.event) ? window.event.srcElement : a;
		while(!pat.test(a.className)) {
			a = a.parentNode;			
			if(a.tagName == 'BODY')
				break;
		}
		if(!a) return false;
		if(!this.settings._tooltip) {
			this.settings._tooltip = a.rel ? a.rel : a.getAttribute('rel');			
			var image = new Image();
			var self = this;
			var XY = this._getCursorPos(e).split('x');				
		
			this.tempas.style.top = XY[1] + "px";
			this.tempas.style.left = XY[0] + "px";
			this.tempas.style.display = 'block';				
			image.onload = function(){ 				
				var obj = $$('magn-content');
				obj.style.backgroundImage = 'url(/' + self.settings._tooltip + ')';				
			}
			image.src = '/' + this.settings._tooltip;
		}
	},	
	_out : function(a) {
		a = (window.event) ? window.event.srcElement : a;			
		if(!a)
			return false;
		if(this.settings._tooltip) {
			this.tempas.style.display = 'none';
			$$('magn-content').style.backgroundImage = '';
			this.settings._tooltip = null;
		}
	},
	_getCursorPos : function(e) {
		var x = (!window.event) ? e.pageX : window.event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		var y = (!window.event) ? e.pageY : window.event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);		
		x += this.settings._offsetX;
		y += this.settings._offsetY;		
		return x + "x" + y;				
	},
	_move : function(e) {
		if(this.settings._tooltip) {
			var XY = this._getCursorPos(e).split('x'),				
				iebody = ( document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body,
				scrolledDown = document.all ? iebody.scrollTop : pageYOffset,							
				window_w = document.all ? iebody.clientWidth : window.innerWidth,
				window_h = document.all ? iebody.clientHeight : window.innerHeight;	
			
			var horizontal_pos = XY[0];
			if( ( parseInt(XY[0]) + 455) >= (window_w - 30) ){
				horizontal_pos = XY[0] - 30 - 455;
			}
			
			var vertical_pos = XY[1];					
			if((parseInt(XY[1]) - scrolledDown + 310) >= (window_h - 10) ){						
				if( XY[1] - scrolledDown - 30 - 310 > 0 )					
					vertical_pos = XY[1] - 30 - 310;			
			}			
		
			this.tempas.style.top = vertical_pos + "px";
			this.tempas.style.left = horizontal_pos + "px";			
		}
	}
}

// page loader
function etsInitLoader(jumpto) {
	if($$('loader')){		
		var loader = $$('loader');
		if(loader.style.display == 'none'){
			loader.style.display = 'block';
			$$('page_content').style.display = 'none';
		}else{
			loader.style.display = 'none';
			$$('page_content').style.display = 'block';	
		}
		if(jumpto)
			window.location.hash = 'iframe';
	}
}
// popup parent control
function etsReload(href){
	if(window.opener) {	
		window.opener.location = href;
		window.opener.focus();	
	} // if
	return false;
};

// popup parent control
function etsReloadParent(href){
	if(window.opener && window.opener.parent) {	
		window.opener.parent.location = href;
		window.opener.parent.focus();	
	} // if
	return false;
};


function jbd( href,ow,oh,sc ) {
	var dw = screen.width;
	var dh = screen.height;

	var x = (dw - ow)/2;
	var y = (dh - oh)/2;

	var ww = window.open( href,'','width=' 
		+ ow + ',height=' + oh + ',toolbar=no,left=' + x + ',top=' + y + ','
		+ 'location=no,directories=no,personalbar=no,status=no,menubar=no,scrollbars=' + ( sc ? 'yes' : 'no' ) + ',titlebar=no,'
		+ 'resizable=yes,dependent=yes,dialog=yes,close=no,chrome=yes' 
	);
	if( !ww ) return false;
	ww.focus();
	return false;
}

function etsChangeSpecs( a,country_id,rl, template ){	
	var specs;

	if( specs = $$('specs') ) {			
		if( a && a.className == 'sel' )
			return false;
		
		if( rl ) {			
			if( specs.className == 'loader' )
				return false;
			specs.innerHTML = '';
			specs.className = 'loader';		
		}
		
		if( a ) {
			var link_length = $$$('country_tab').length;
			for( var i = 0; i < link_length; i++ ) {
				$$$('country_tab').item(i).className = '';	
			}
			a.className = 'sel';
		}
		
		if (typeof(__ets_mode) == "undefined") 
			__ets_mode = '';
		
		var t = base64.encode(location.href);
		var url = '/admin/bg/ets_ajax?idn=specs&ln=' + __ets_def_lang 
				+'&baseo=' + t + (country_id ? '&country_id=' + country_id : '')
				+( template ? '&template=' + template : '' )
				+( __ets_sid ? '&sid=' + __ets_sid : '' )
				+ '&mode=' + __ets_mode;			
		etsAjax(url, function(data){													   																					
			specs.className = '';	
			var fragment = document.createDocumentFragment();
			var temp = document.createElement('div');
			temp.innerHTML = data;
			fragment.appendChild(temp);
			specs.appendChild(fragment);
			var j = temp.getElementsByTagName('script');
			var len = j.length;
			for( var i = 0; i < len; i++ ) {				
				if( window.eval ) window.eval( j[i].innerHTML );
				else eval( j[i].innerHTML );	
			} // for
			if( __ets_ie6 )	
				etsLabelFix();
			// uzloadinam tooltipus
			ets_tooltips.set();
			// gauna auksti ir perduoda	kitame iframe
			etsIframeResize();	
			ets_magnifier.set('magnify');	
		})
	}	
	return false;
}

function etsCheckAK(personal_code){
	var pc = personal_code.toString();
	var valid = false;
	if(pc.length == 11){
		pc = pc.split('');
		if(pc[0] > 2 && pc[0]<7){

			var str = pc[0]*1 + pc[1]*2 + pc[2]*3 + pc[3]*4
					+ pc[4]*5 + pc[5]*6 + pc[6]*7 + pc[7]*8
					+ pc[8]*9 + pc[9]*1;
			str = str%11;
							
			if(str == 10){
				str = pc[0]*3 + pc[1]*4 + pc[2]*5 + pc[3]*6
					+ pc[4]*7 + pc[5]*8 + pc[6]*9 + pc[7]*1
					+ pc[8]*2 + pc[9]*3;
				str = str%11;
				if(str == 10 && pc[10] == 0)
					valid = true;
				else if(str == pc[10])
					valid = true;
				
			}else if(str == pc[10])
				valid = true;
		}
	}	
	return valid;
};

function etsLocation( url ) {	
	if( window.parent )	{
		window.parent.location.href = url;
	}
	return false;
}

function etsIsUnsignedInteger( s ) {
	return (s.toString().search(/^[0-9]+$/) == 0);
}

function etsIsYear( y ) {
	if( y > 1800 && y < 2200 )
		return true;
	return false;
}

function etsIsMonth( m ) {
	if( m > 0 && m < 13 )
		return true;
	return false;
}

function etsIsDay( d ) {
	if( d > 0 && d < 32 )
		return true;
	return false;
}			  

function etsExtractPc( pc, nr ){					
	var year = 0000;
	var month = 00;
	var day = 00;
	
	var year_s = 00;
	var year_e = 00;
	
	//jei latviskas kodas
	if( pc.match( /^[0-9]{6}-[0-9]{5}$/ ) ) {
		year_e = pc.substr( 4, 2 );
		month = pc.substr( 0, 2 );
		day = pc.substr( 2, 2 );
		
		var century = pc.substr( 7, 1 );
		if( century == 0 )
			year_s = 18;
		if( century == 1 )
			year_s = 19;
		if( century == 2 )
			year_s = 20;						
		
		year = year_s+year_e;
		
		if( etsIsUnsignedInteger( year ) && isYear( year ) && $$( 'byear_'+nr ).value.length == 0 )
			$$( 'byear_'+nr ).value = year;
		if( etsIsUnsignedInteger( month ) && isMonth( month ) && $$( 'bmonth_'+nr ).value.length == 0 )
			$$( 'bmonth_'+nr ).value = month;
		if( etsIsUnsignedInteger( day ) && isDay( day ) && $$( 'bday_'+nr ).value.length == 0 )
			$$( 'bday_'+nr ).value = day;
		return;						
	}//if()
	
	//estiskas/lietuviskas
	year_e = pc.substr( 1, 2 );
	month = pc.substr( 3, 2 );
	day = pc.substr( 5, 2 );
	
	century = pc.substr( 0, 1 );
	if( century == 1 || century == 2 )
		year_s = 18;
	if( century == 3 || century == 4 )
		year_s = 19;
	if( century == 5 || century == 6 )
		year_s = 20;
	if( century == 7 || century == 8 )
		year_s = 21;
	
	year = year_s+year_e;
		
	if( etsIsUnsignedInteger( year ) && etsIsYear( year ) &&
		etsIsUnsignedInteger( month ) && etsIsMonth( month ) &&
		etsIsUnsignedInteger( day ) && etsIsDay( day ) ) {
		
		if( $$( 'byear_'+nr ).value.length == 0 )
			$$( 'byear_'+nr ).value = year;		
		if( $$( 'bmonth_'+nr ).value.length == 0 )
			$$( 'bmonth_'+nr ).value = month;
		if( $$( 'bday_'+nr ).value.length == 0 )
			$$( 'bday_'+nr ).value = day;
		return;
	}//if()
	
	//lenkiskas	
	//http://pl.wikipedia.org/wiki/PESEL
	year_e = pc.substr( 0, 2 );
	month = pc.substr( 2, 2 );
	day = pc.substr( 4, 2 );
	
	century = month.substr( 0, 1 );
	if( century == 8 || century == 9 ) {
		year_s = 18;
		month = month - 80;
	}
	if( century == 0 || century == 1 )
		year_s = 19;
	if( century == 2 || century == 3 ) {
		year_s = 20;
		month = month - 20;
	}
	if( century == 4 || century == 5 ) {
		year_s = 21;
		month = month - 40;
	}
	
	if( etsIsUnsignedInteger( year ) && etsIsYear( year ) &&
		etsIsUnsignedInteger( month ) && etsIsMonth( month ) &&
		etsIsUnsignedInteger( day ) && etsIsDay( day ) ) {
			
		if( $$( 'byear_'+nr ).value.length == 0 )
			$$( 'byear_'+nr ).value = year;		
		if( $$( 'bmonth_'+nr ).value.length == 0 )
			$$( 'bmonth_'+nr ).value = month;
		if( $$( 'bday_'+nr ).value.length == 0 )
			$$( 'bday_'+nr ).value = day;
		return;
	}//if()					
}

// ONLOAD
etsLoad(function(){
	// loaderis	
	etsInitLoader();	
	// galerijos navigacija pashaunam
	ets_gallery.set();
	ets_change_pic.set();
	// uzloadinam tooltipus
	ets_tooltips.set();
	// gauna auksti ir perduoda	kitame iframe
	etsIframeResize();		
	ets_magnifier.set('magnify');
	if( __ets_ie6 )	
		etsLabelFix();
	// viesbuciu ir zvaigzduciu valdymas
	ets_hotels.set();		

});



