

	String.prototype.is_string	= true;
	Array.prototype.is_array	= true;

	// DD.MM.YYYY
	String.prototype.checkdate	= function( SEPARATOR ) {
		if( typeof SEPARATOR == 'undefined' )
			throw new Error('parameter required');

		var date	= this.split( SEPARATOR );

		if( date.length != 3 )
			return false;

		var d	= date[0] * 1;
		var m	= date[1] * 1;
		var y	= date[2] * 1;

	    return m > 0 && m < 13 && y > 0 && y < 32768 && d > 0 && d <= (new Date(y, m, 0)).getDate() && new Date(y, m-1, d).getTime()-1 >= new Date().getTime();
	}

	// false = invalid date, -1 = lower than, 0 = equal, 1 = greater then
	String.prototype.compareDate	= function( DATE_STRING, SEPARATOR ) {
		if( typeof SEPARATOR == 'undefined' )
			throw new Error('parameter required (SEPARATOR)');

		if( typeof DATE_STRING == 'undefined' )
			throw new Error('parameter required (DATE_STRING)');

		if( this.checkdate( SEPARATOR ) && DATE_STRING.checkdate( SEPARATOR ) ) {
			var date1	= this.split( SEPARATOR );
			var date2	= DATE_STRING.split( SEPARATOR );

			if( date1.length != 3 || date2.length != 3 )
				return false;

			date1	= new Date( date1[2]*1, date1[1]*1, date1[0]*1 ).getTime();
			date2	= new Date( date2[2]*1, date2[1]*1, date2[0]*1 ).getTime();

			if( date1 < date2 )
				return 1;

			if( date1 == date2 )
				return 0;

			return -1;
		}

		return false;
	}

	fixed_width = 0;

	function $( ID ) { return document.getElementById( ID ); }

	function Elements( o, t ) {
		if( !t ) { t	= o; o	= document.body; }
		else o = o.is_string ? $( o ) : o;

		return o.getElementsByTagName( t.toUpperCase() );
	}

	function El( TAG, PARAMS ) {
		if( TAG.is_string )
			var obj	= document.createElement( TAG );
		else
			obj		= TAG;

		if( PARAMS ) {
			if( PARAMS.hasOwnProperty('class') )
				obj.className	= PARAMS['class'];
			if( PARAMS.hasOwnProperty('id') )
				obj.setAttribute( 'id', PARAMS['id'] );
			if( PARAMS.hasOwnProperty('parent') ) {
				if( PARAMS['parent'].is_string )
					PARAMS['parent'] = $( PARAMS['parent'] );
				PARAMS['parent'].appendChild( obj );
			}
			if( PARAMS.hasOwnProperty('insertBefore') ) {
				if( PARAMS['insertBefore'].is_string )
					PARAMS['insertBefore'] = $( PARAMS['insertBefore'] );

				PARAMS['insertBefore'].parentNode.insertBefore( obj, PARAMS['insertBefore'] );
			}
		}

		return obj;
	}

	function TextNode( str ) { return document.createTextNode( str ); }

	function removeChildren( o ) {
		for( var i = 0; i < o.childNodes.length; i++ )
			o.removeChild( o.childNodes[i] );
	}

	function RadioBeauty() {
		var inps	= Elements( 'input' );

		for( var i = 0; i < inps.length; i++ ) {
			if( inps[i].getAttribute( 'type' ) == 'radio' ) {
				var sex	= new SexyForms( 'radio', inps[i] ).init();

				sex.addEvent( [ sex.sexy, sex.label ], 'click', function() {
					var g	= Sexy['radio']['groups'],
						n	= this.o.getAttribute('name');

					if( g[n].prev )
						g[n].prev.label.className	= '';

					this.label.className	= 'label_active';
				} );

				sex.addEvent( [ sex.sexy, sex.label ], 'mouseover', function() {
					this.sexy.className = this.o.checked ? 'sexy_radio_checked mchecked' : 'sexy_radio munchecked';
				} );

				sex.addEvent( [ sex.sexy, sex.label ], 'mouseout', function() {
					this.sexy.className = this.o.checked ? 'sexy_radio_checked' : 'sexy_radio';
				} );
			}
		}
	}

	function InputBeauty() {
		var inps	= Elements( 'input' ), calendar;

		for( var i = 0; i < inps.length; i++ ) {
			if( inps[i].getAttribute( 'type' ) == 'text' ) {
				calendar = inps[i].className.match(/(^| )calendar($| )/);
				var sex	= new SexyForms( 'input', inps[i] );

				if( calendar )
					sex.use_pattern	= 'calendar_pattern';

				sex.init();

				if( calendar ) {
					sex.o.calendar	= new Calendar( sex.o, {
						'obj'		: sex.sexy.pseudo.icon,
						'parent'	: document.body,
						'offset'	: [-32,17]
					} );

					sex.addEvent( sex.o, 'keyup', function() {
						this.o.calendar.appear();
					} );

					sex.addEvent( [ sex.sexy, sex.sexy.pseudo.icon ], 'click', function() {
						this.o.calendar.appear();
					} );
				}
			}
		}
	}

	function SelectBeauty() {
		var sels	= Elements( 'select' );

		for( var i = 0; i < sels.length; i++ ) {
			var sex	= new SexyForms( 'select', sels[i] );

			if( sels[i].name == 'city-list' ) {
				fixed_width				= sels[i].offsetWidth;
//				sex.use_pattern			= 'cities_pattern';
				sex.use_pattern			= 'TYPE_IN_PATTERN2';
				sex.dropper_auto_width	= false;
			}

			if( sels[i].name == 'country-list' ) {
				sex.use_pattern			= 'TYPE_IN_PATTERN';
			}

			sex.init();

			sels[i].sexy_obj	= sex;

			if( sels[i].name == 'city-list' ) {
				sex.value_box.id		= 'cl-val-box';
			}

			sex.addEvent( sex.sexy, 'mouseover', function() {
				this.sexy.pseudo.arrow.style.backgroundPosition	= '-26px -190px';
			} );
			sex.addEvent( sex.sexy, 'mouseout', function() {
				this.sexy.pseudo.arrow.style.backgroundPosition	= '-26px -181px';
			} );
		}
	}

	function starControlers() {
		var inps	= Elements( 'input' ), val, j, a,
			stars = [ 'Една звезда', 'Две звезди', 'Три звезди', 'Четири звезди', 'Пет звезди' ]
		;

		for( var i = 0; i < inps.length; i++ ) {
			if( inps[i].getAttribute('type') != 'hidden' )
				continue;

			if( inps[i].className.match(/(^| )hotel-stars-control($| )/) ) {
				val	= parseInt( inps[i].value );

				if( val < 0 ) val = 0;
				if( val > 5 ) val = 5;

				inps[i].value	= val;

				var controler	= new El( 'span', {
					'class' : 'hotel-stars-control value-' + val,
					'insertBefore' : inps[i]
				} );

				controler.selectedIndex	= val;

				for( j = 1; j <= 5; j++ ) {
					a = new El( 'a', { 'parent' : controler } );
					a.setAttribute( 'href', 'javascript://' + j );
					a.setAttribute( 'title', stars[j - 1] );

					AttachEvent( 'mouseover', a, passFunc( a, function( o, i ) {
						o.className = 'hotel-stars-control value-' + i;
					}, controler, j ) );

					AttachEvent( 'mouseout', a, passFunc( a, function( o ) {
						o.className = 'hotel-stars-control value-' + o.selectedIndex;
					}, controler ) );

					AttachEvent( 'click', a, passFunc( a, function( o, i, inp ) {
						o.className = 'hotel-stars-control value-' + i;
						o.selectedIndex	= i;
						inp.value	= i;
					}, controler, j, inps[i] ) );
				}
			}
		}
	}

	function makeRowsGlow() {
		if( !$('results-table') )
			return;

		var rows	= Elements( 'results-table', 'tr' );

		for( var i = 0; i < rows.length; i++ ) {
			rows[i].onmouseover	= function() { this.className = 'glow'; }
			rows[i].onmouseout	= function() { this.className = ''; }
		}
	}

	function Start() {
		new El( 'span', { 'id' : 'header-left-top', 'parent' : 'header' } );
		new El( 'span', { 'id' : 'header-right-top', 'parent' : 'header' } );
		new El( 'span', { 'id' : 'header-left-bot', 'parent' : 'header' } );
		new El( 'span', { 'id' : 'header-right-bot', 'parent' : 'header' } );
		new El( 'span', { 'id' : 'footer-right', 'parent' : 'rights-and-created' } );
		new El( 'span', { 'id' : 'footer-left', 'parent' : 'rights-and-created' } );
		new El( 'span', { 'id' : 'header-banner-right', 'parent' : 'header-banner' } );
		new El( 'span', { 'id' : 'header-banner-left', 'parent' : 'header-banner' } );

		if( $('results-wrapper') )
			new El( 'div', { 'id' : 'last-curve', 'parent' : 'results-wrapper' } );

		if( $('green-title-bar') )
			new El( 'span', { 'id' : 'green-title-bar-corner', 'parent' : 'green-title-bar' } );

		makeRowsGlow();
		starControlers();

		if( typeof SexyForms != 'undefined' ) {
			SelectBeauty();
			RadioBeauty();
			InputBeauty();
		}

		if( $('major-city') ) {
			var majorCity	= $('major-city').sexy_obj;
			var country		= $('country-list').sexy_obj;
			var city		= $('city-list').sexy_obj;

			majorCity.addEvent(
				majorCity.sexy.pseudo.value_box,
				'mousedown', function() {
					if( !IE ) {
						var clickEvent = window.document.createEvent("MouseEvent");
						clickEvent.initEvent("click", false, true);
						$('city-radio').sexy.sexy.dispatchEvent( clickEvent );
					}
					else
						$('city-radio').sexy.sexy.fireEvent('onclick');
				}
			);

			country.addEvent(
				country.sexy.pseudo.value_box,
				'mousedown', function() {
					if( !IE ) {
						var clickEvent = window.document.createEvent("MouseEvent");
						clickEvent.initEvent("click", false, true);
						$('country-radio').sexy.sexy.dispatchEvent( clickEvent );
					}
					else
						$('country-radio').sexy.sexy.fireEvent('onclick');
				}
			);

			city.addEvent(
				city.sexy.pseudo.value_box,
				'mousedown', function() {
					if( !IE ) {
						var clickEvent = window.document.createEvent("MouseEvent");
						clickEvent.initEvent("click", false, true);
						$('country-radio').sexy.sexy.dispatchEvent( clickEvent );
					}
					else
						$('country-radio').sexy.sexy.fireEvent('onclick');
				}
			);
		}


		if( $('country-list') )
			$('country-list').sexy_obj.addEvent(
				'change', function() {
					var ajax	= new Ajax();

					var sel	= $('city-list');

					sel.style.display = 'block';

					sel.style.position = 'absolute';
					sel.style.left = '-200px';
					sel.style.top = '-200px';

					sel.options.length = 0;

					sel.options[0] = new Option( 'Моля, изчакайте...', '-' );

//					$('city-list').innerHTML = '<option>Моля изчакайте...</option>';
//					$('city-list').style.display	= 'none';
					$('city-list').sexy_obj.getOptions();

					ajax.sendRq( 'GET', 'ajax.php?country=' + this.o.value, function( response ) {
						if( !/^<afs>(.+?)<\/afs>$/.test( response ) )
							response = '<afs>' + response + '</afs>';

						var XMLDoc	= parseXML( response );

						$('city-list').innerHTML = '';

						var opts	= XMLDoc.getElementsByTagName('optgroup');

						for( var i = 0; i < opts.length; i++ ) {
							var optgroup = new El( 'optgroup', { 'parent' : $('city-list') } );
							optgroup.setAttribute( 'label', opts[i].getAttribute( 'label' ) );

							var optis	= opts[i].getElementsByTagName( 'option' );

							for( var j = 0; j < optis.length; j++ ) {
								var opti	= document.createElement( 'option' );

								optgroup.appendChild( opti );
								opti.text	= optis[j].firstChild.nodeValue;
								opti.value	= optis[j].getAttribute( 'value' );

							}
						}

//						$('city-list').innerHTML = response;
						$('city-list').sexy_obj.getOptions();

						$('city-list').sexy_obj.dropper.style.visibility	= 'hidden';
						$('city-list').sexy_obj.dropper.style.display 		= 'block';
						$('city-list').sexy_obj.dropper.scrollTop			= 0;
						$('city-list').sexy_obj.dropper.style.display		= 'none';
						$('city-list').sexy_obj.dropper.style.visibility	= 'visible';
					} );
				
				}
			);

		if( $('fieldset-rooms') )
			addRoom();
	}

	function checkin_change( o ) {
		if( o.value.match(/^\d{1,2}$/) ) {
			var date	= $('calendar-from').calendar.cDate;
			var t		= new Date();
			t.setTime( date.getTime() + o.value * 86400000 );

			var day		= t.getDate();
			var month	= t.getMonth() + 1;

			if( day < 10 )
				day = '0' + day;
			if( month < 10 )
				month = '0' + month;

			$('calendar-to').value	= day + '.' + month + '.' + t.getFullYear();
		}
	}

	function addOptionsToSelect( SEL, OPTS ) {
		SEL.options.length = 0;

		for( var i = 0; i < OPTS.length; i++ )
			SEL.options[i]	= new Option( OPTS[i]['value'], OPTS[i]['key'] );
	}

	var Rooms	= 0;

	function removeChildrenSelect( PARENT, NUM ) {
		var els			= Elements( PARENT, 'select' );

		for( var i = 0; i < els.length; i++ )
			if( els[i].name == 'children[' + NUM + ']' )
				els[i].sexy_obj.parentElement.parentNode.parentNode.removeChild( els[i].sexy_obj.parentElement.parentNode );
	}

	function addChildrenSelect( PARENT, NUM ) {
		var Children	= new El( 'select', {
			'parent' : new El( 'span', { 'parent' : PARENT, 'class' : 'children' } )
		} );
		Children.setAttribute( 'name', 'children[' + NUM + ']' );

		addOptionsToSelect(
			Children, [
				{ 'key' : '-', 'value' : 'Без деца' },
				{ 'key' : '1', 'value' : '1 дете' },
				{ 'key' : '2', 'value' : '2 деца' }
			]
		);

		var sex	= new SexyForms( 'select', Children ).init();
		Children.sexy_obj	= sex;

		sex.addEvent( sex.sexy, 'mouseover', function() {
			this.sexy.pseudo.arrow.style.backgroundPosition	= '-26px -190px';
		} );
		sex.addEvent( sex.sexy, 'mouseout', function() {
			this.sexy.pseudo.arrow.style.backgroundPosition	= '-26px -181px';
		} );
		sex.addEvent( 'change', function() {
			var children_count	= this.o.value;

			removeCot( PARENT, 'cot[' + NUM + ']' );

			removeChildrenAge( PARENT, 'age1[' + NUM + ']' );
			removeChildrenAge( PARENT, 'age2[' + NUM + ']' );

			if( children_count == 0 )
				addCot( PARENT, 'cot[' + NUM + ']', 'Походно легло' );
			else {
				addChildrenAge( PARENT, 'age1[' + NUM + ']', 'Възраст на дете' );

				if( children_count	== 2 )
					addChildrenAge( PARENT, 'age2[' + NUM + ']', 'Възраст на дете' );
			}
		} );

		addCot( PARENT, 'cot[' + NUM + ']', 'Походно легло' );
	}

	function removeChildrenAge( PARENT, NAME ) {
		var els			= Elements( PARENT, 'select' );

		for( var i = 0; i < els.length; i++ )
			if( els[i].name == NAME )
				els[i].sexy_obj.parentElement.parentNode.parentNode.removeChild( els[i].sexy_obj.parentElement.parentNode );
	}

	function addChildrenAge( PARENT, NAME, TITLE ) {
		var AGE	= new El( 'select', {
			'parent' : new El( 'span', { 'parent' : PARENT, 'class' : 'age' } )
		} );
		AGE.setAttribute( 'name', NAME );

		addOptionsToSelect(
			AGE, [
				{ 'key' : '-', 'value' : TITLE },
				{ 'key' : '0', 'value' : '< 1' },
				{ 'key' : '1', 'value' : '1' },
				{ 'key' : '2', 'value' : '2' },
				{ 'key' : '3', 'value' : '3' },
				{ 'key' : '4', 'value' : '4' },
				{ 'key' : '5', 'value' : '5' },
				{ 'key' : '6', 'value' : '6' },
				{ 'key' : '7', 'value' : '7' },
				{ 'key' : '8', 'value' : '8' },
				{ 'key' : '9', 'value' : '9' },
				{ 'key' : '10', 'value' : '10' },
				{ 'key' : '11', 'value' : '11' },
				{ 'key' : '12', 'value' : '12' },
				{ 'key' : '13', 'value' : '13' },
				{ 'key' : '14', 'value' : '14' },
				{ 'key' : '15', 'value' : '15' },
				{ 'key' : '16', 'value' : '16' },
				{ 'key' : '17', 'value' : '17' }
			]
		);

		var sex	= new SexyForms( 'select', AGE ).init();
		sex.o.sexy_obj	= sex;

		sex.addEvent( sex.sexy, 'mouseover', function() {
			this.sexy.pseudo.arrow.style.backgroundPosition	= '-26px -190px';
		} );
		sex.addEvent( sex.sexy, 'mouseout', function() {
			this.sexy.pseudo.arrow.style.backgroundPosition	= '-26px -181px';
		} );
	}

	function addCot( PARENT, NAME, TITLE ) {
		var COT	= new El( 'select', {
			'parent' : new El( 'span', { 'parent' : PARENT, 'class' : 'cot' } )
		} );
		COT.setAttribute( 'name', NAME );

		addOptionsToSelect(
			COT, [
				{ 'key' : '-', 'value' : TITLE },
				{ 'key' : '0', 'value' : '0' },
				{ 'key' : '1', 'value' : '1' }
			]
		);

		var sex	= new SexyForms( 'select', COT ).init();
		sex.o.sexy_obj	= sex;

		sex.addEvent( sex.sexy, 'mouseover', function() {
			this.sexy.pseudo.arrow.style.backgroundPosition	= '-26px -190px';
		} );
		sex.addEvent( sex.sexy, 'mouseout', function() {
			this.sexy.pseudo.arrow.style.backgroundPosition	= '-26px -181px';
		} );
		sex.addEvent( 'change', function() {
			
		} );
	}

	function removeCot( PARENT, NAME ) {
		var els			= Elements( PARENT, 'select' );

		for( var i = 0; i < els.length; i++ )
			if( els[i].name == NAME )
				els[i].sexy_obj.parentElement.parentNode.parentNode.removeChild( els[i].sexy_obj.parentElement.parentNode );
	}

	function addRoom( REMOVE ) {
		if( Rooms == 3 ) {
//			alert( 'Достигнат е максимумът стаи за заявка.' );
			return;
		}

		var fset	= $('fieldset-rooms');

		if( REMOVE )
			new El( 'br', { 'parent' : fset } );

		var fset = new El( 'div', { 'parent' : fset } );

		var remove_button	= new El( 'a', { 'parent' : fset, 'class' : 'remove-button' } );
		remove_button.setAttribute( 'href', 'javascript://' );
		var button_text		= 'премахни';

		if( REMOVE )
			remove_button.onclick	= function() {
				var p	= this.parentNode.parentNode;

				p.removeChild( this.parentNode.previousSibling );
				p.removeChild( this.parentNode );

				var s	= Elements( p, 'span' ), c = 0;

				for( var i = 0; i < s.length; i++ )
					if( s[i].className == 'green' )
						s[i].firstChild.data	= '#' + ++c + ' ';

				Rooms--;
			}
		else {
			remove_button.setAttribute( 'href', "javascript:addRoom('remove');" );
			remove_button.setAttribute( 'id', "add-button" );
			remove_button.className	= '';
			button_text		= 'добави';
		}

		new El( TextNode( button_text ), { 'parent' : remove_button } );
		new El( TextNode('Стая '), { 'parent' : fset } );
		new El( TextNode('#' + ++Rooms + ' '), {
			'parent' : new El( 'span', { 'class' : 'green', 'parent' : fset } )
		} );

		var RoomType	= new El( 'select', {
			'parent' : new El( 'span', { 'parent' : fset, 'class' : 'roomtype' } )
		} );
		RoomType.setAttribute( 'name', 'room_type[' + Rooms + ']' );

		addOptionsToSelect(
			RoomType, [
				{ 'key' : '-', 'value' : 'Изберете вид стая' },
				{ 'key' : '1', 'value' : 'Единична' },
				{ 'key' : '2', 'value' : 'Двойна' },
				{ 'key' : '3', 'value' : 'Twin' },
				{ 'key' : '4', 'value' : 'Тройна' },
				{ 'key' : '5', 'value' : 'Четворна' },
				{ 'key' : '6', 'value' : 'Двойна за единична' }
			]
		);

		var sex	= new SexyForms( 'select', RoomType ).init();
		sex.rooms_index	= Rooms;
		sex.fset		= fset;
		sex.o.sexy_obj	= sex;

		sex.addEvent( sex.sexy, 'mouseover', function() {
			this.sexy.pseudo.arrow.style.backgroundPosition	= '-26px -190px';
		} );
		sex.addEvent( sex.sexy, 'mouseout', function() {
			this.sexy.pseudo.arrow.style.backgroundPosition	= '-26px -181px';
		} );

		var NUM	= Rooms;

		sex.addEvent(
			'change', function() {
				var room_type	= this.o.value;

				removeChildrenAge( this.fset, 'age1[' + NUM + ']' );
				removeChildrenAge( this.fset, 'age2[' + NUM + ']' );
				removeCot( this.fset, 'cot[' + NUM + ']' );
				removeChildrenSelect( this.fset, NUM );

				if( room_type == 2 || room_type == 3 )
					addChildrenSelect( this.fset, NUM );
				if( room_type == 6 )
					addCot( this.fset, 'cot[' + NUM + ']', 'Походно легло' );

			}
		);

		new El( TextNode(' '), { 'parent' : fset } );
	}

      function RegExpescape(str) {
	      var specials = new RegExp("[.*+?|()\\[\\]{}\\\\]", "g"); // .*+?|()[]{}\
	      return str.replace(specials, "\\$&");
      }

	function validate( FORM ) {
		var FE	= FORM.elements;

		var DestinationId = false;

		if( FE['major-city'].value != '-' && getRadioValue(FE['city-country']) == 'major' )
			DestinationId	= FE['major-city'].value;

		if( FE['city-list'].value != '-' && !DestinationId ) {
			var clvb	= $('cl-val-box').value.toLowerCase();

			var reg		= new RegExp( '^' + RegExpescape(clvb), "i" );

			for( var i = 0; i < FE['city-list'].options.length; i++ ) {
				if( reg.test( FE['city-list'].options[i].text.toLowerCase() ) ) {
					DestinationId	= FE['city-list'].options[i].value;
					FE['city-list'].options[i].selected = true;
					break;
				}
			}
			DestinationId	= FE['city-list'].value;
		}

		if( !DestinationId && FE['major-city'].value != '-' )
			DestinationId	= FE['major-city'].value;

		if( !DestinationId ) {
			alert( 'Трябва да изберете град' );
			return false;
		}

		if( FE['calendar-from'].value.compareDate( FE['calendar-to'].value, '.' ) === false ) {
			alert('Невалидни дати за check-in / check-out');
			return false;
		}

		if( FE['calendar-from'].value.compareDate( FE['calendar-to'].value, '.' ) <= 0 ) {
			alert('Невалидни дати за check-in / check-out. Check-out събитието трябва да бъде след check-in събитието.');
			return false;
		}

		return true;
	}

	var Translate = function() {
		var flag	= false;

		return function( LINK ) {
			if( flag ) {
				$('translated-text').style.display	= 'none';
				$('original-text').style.display	= 'inline';
			}
			else {
				$('translated-text').style.display	= 'inline';
				$('original-text').style.display	= 'none';
			}

			flag = !flag;

			LINK.setAttribute( 'id', flag ? 'otgt' : 'gtot' );
		}
	}();

	function getViewportHeight() {
		var viewportheight;

		if( typeof window.innerWidth != 'undefined' )
			viewportheight = window.innerHeight;
		else if(
			typeof document.documentElement != 'undefined' &&
			typeof document.documentElement.clientWidth != 'undefined' &&
			document.documentElement.clientWidth != 0
		)
			viewportheight = document.documentElement.clientHeight;
		else
			viewportheight = document.getElementsByTagName('body')[0].clientHeight;

		return viewportheight;
	}

	function parseXML( XMLString ) {
		if( window.DOMParser )
			xmlDoc	= new DOMParser().parseFromString( XMLString, 'text/xml' );
		else {
			xmlDoc			= new ActiveXObject( "Microsoft.XMLDOM" );
			xmlDoc.async	= 'false';
			xmlDoc.loadXML( XMLString );
		}

		return xmlDoc;
	}

	function BookAHotel( SYSTEM ) {
		var Fader	= $('fader');

		if( !Fader ) {
			Fader = El( 'div', { 'parent' : document.body, 'id' : 'fader' } );

			Fader.onclick	= function() {
				if( !IE ) {
					document.documentElement.style.overflow		= 'auto';
				}

				this.style.display 				= 'none';
				$('floating-box').style.display	= 'none';
				showusloviq('none');
			}
		}

		Fader.style.height				= document.documentElement.scrollHeight + 'px';
		Fader.style.display				= 'block';

		var sct	= document.documentElement.scrollTop || document.body.scrollTop;

		$('floating-box').style.top		= ( sct + ( getViewportHeight() / 2 ) - 202 ) + 'px';
		$('floating-box').style.display	= 'block';
		if( !IE ) {
			document.documentElement.style.overflow		= 'hidden';
		}

		$('info').innerHTML = '<span id="loader"><img src="images/ajax-loader.gif" alt="loader" id="img-loader" /> Моля, изчакайте...</span>';

		switch( SYSTEM.type ) {
			case 'hp':
				new Ajax().sendRq(
					'GET',
					'ajax.php?action=CheckHotelDeadline&system=' + SYSTEM.type +
					'&ProcessId=' + SYSTEM.processid +
					'&HotelCode=' + SYSTEM.hotelcode +
					'&CheckIn=' + SYSTEM.checkin,

					function( response ) {
						var XMLDoc	= parseXML( response );

						if( !XMLDoc || XMLDoc.getElementsByTagName('status').length == 0 ) {
							$('info').innerHTML = 'Грешка. Моля, презаредете страницата.';
							return false;
						}

						CANCELATIONPOLICY	= '';
						$('info').innerHTML	= '';

						if( XMLDoc.getElementsByTagName('message').length == 1 )
							$('info').innerHTML = XMLDoc.getElementsByTagName('message')[0].firstChild.nodeValue;

						if(
							XMLDoc.getElementsByTagName('status')[0].firstChild.nodeValue == 'OK' &&
							XMLDoc.getElementsByTagName('HotelCode')[0].firstChild.nodeValue != '' &&
							XMLDoc.getElementsByTagName('ProcessId')[0].firstChild.nodeValue != ''
						) {
							if( XMLDoc.getElementsByTagName('cancelationpolicy').length == 1 )
								CANCELATIONPOLICY	= XMLDoc.getElementsByTagName('cancelationpolicy')[0].firstChild.nodeValue;

							$('info').innerHTML = JAVASCRIPTFORM;

							HotelCode	= XMLDoc.getElementsByTagName('HotelCode')[0].firstChild.nodeValue;
							ProcessId	= XMLDoc.getElementsByTagName('ProcessId')[0].firstChild.nodeValue;

							if( $('usloviq') )
								$('usloviq').innerHTML = CANCELATIONPOLICY;
						}
					}
				);
			break;
		}

//			$('info').innerHTML	= 'Моля, свържете се с нас чрез нашата <a href="contacts.html" target="_blank">страница за контакти</a>.';
	}

	function closeFloatingBox() {
		if( !IE ) {
			document.documentElement.style.overflow		= 'visible';
		}
		$('fader').style.display 		= 'none';
		$('floating-box').style.display	= 'none';
		showusloviq('none');
	}

	function ActiveSearch( OBJ, state ) {
		var Value	= OBJ.value;

		if( !state && OBJ.value == OBJ.defaultValue )
			Value	= '';
		else if( OBJ.value == '' )
			Value	= OBJ.defaultValue;

		OBJ.value		= Value;
	}

	function disable( CHECKBOX ) { $('booking-submit').disabled	= !CHECKBOX.checked; }

	var showusloviq = function( state ) {
		var __hidden	= true;

		return function() {
			if( state) {
				$('usloviq').style.display = state;
				__hidden	= state == 'block' ? true : false;
				return;
			}

			$('usloviq').style.display = __hidden ? 'block' : 'none';

			if( __hidden )
				$('info').scrollTop	= $('info').scrollHeight;

			__hidden = !__hidden;
		}
	}();

	function bookingform( FORM ) {
		if( FORM.elements['firstname'].value == '' ) {
			alert( 'Трябва да въведете име на лицето за контакти' );
			return false;
		}
		if( FORM.elements['lastname'].value == '' ) {
			alert( 'Трябва да въведете фамилия на лицето за контакти' );
			return false;
		}
		if( !FORM.elements['firstname'].value.match( /^[a-zA-Z\- ]+$/ ) ) {
			alert( 'Името на лицето за контакти трябва да бъде изписано на латиница' );
			return false;
		}
		if( !FORM.elements['lastname'].value.match( /^[a-zA-Z\- ]+$/ ) ) {
			alert( 'Фамилията на лицето за контакти трябва да бъде изписана на латиница' );
			return false;
		}
		if( FORM.elements['email'].value == '' || !FORM.elements['email'].value.match( /^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]+)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$/ ) ) {
			alert( 'Невалиден email адрес' );
			return false;
		}
		if( FORM.elements['phone'].value == '' ) {
			alert( 'Трябва да въведете телефонен номер' );
			return false;
		}
		if( !FORM.elements['agree'].checked ) {
			alert( 'Трябва да потвърдите, че сте съгласен(а) с условията за резервация' );
			return false;
		}

		var NAMES	= FORM.getElementsByTagName( 'INPUT' );

		for( var i = 0; i < NAMES.length; i++ ) {
			if( !NAMES[i].getAttribute('name') || !NAMES[i].getAttribute('name').match( /p(first|last)name\[\d+\.\d+\]/ ) )
				continue;

			if( NAMES[i].value == '' ) {
				alert( 'Трябва да въведете имена на всички гости' );
				return false;
			}
			if( !NAMES[i].value.match( /^[a-zA-Z\- ]+$/ ) ) {
				alert( 'Имената на гостите трябва да бъдат изписани на латиница' );
				return false;
			}
		}

		return true;
	}

	function getRadioValue( RADIOS ) {
		for( var i = 0; i < RADIOS.length; i++ )
			if( RADIOS[i].checked )
				return RADIOS[i].value;
	}

	function makeabooking() {
		var ajax	= new Ajax();

		var FORM		= document.forms['bookingform'];
		var DATA		= new Object();
		var parameters	= '', i, j;

		DATA['ProcessId']	= ProcessId;
		DATA['HotelCode']	= HotelCode;
		DATA['CheckIn']		= CheckIn;
		DATA['CheckOut']	= CheckOut;
		DATA['Rooms']		= PeopleInRooms.length;

		DATA['title']		= getRadioValue( FORM.elements['title'] );
		DATA['firstname']	= FORM.elements['firstname'].value;
		DATA['lastname']	= FORM.elements['lastname'].value;
		DATA['phone']		= FORM.elements['phone'].value;
		DATA['email']		= FORM.elements['email'].value;
		DATA['payment']		= FORM.elements['paymenttype'].value;
		DATA['dest']		= Destination;

		for( i = 1; i <= PeopleInRooms.length; i++ ) {
			for( j = 0; j < PeopleInRooms[i-1]; j++ ) {
				DATA['PeopleInRoomsFN[' + i + '][' + j + ']'] = FORM.elements['pfirstname[' + i + '.' + j + ']'].value;
				DATA['PeopleInRoomsLN[' + i + '][' + j + ']'] = FORM.elements['plastname[' + i + '.' + j + ']'].value;
				DATA['Titles[' + i + '][' + j + ']'] = getRadioValue( FORM.elements['ptitle[' + i + '.' + j + ']'] );
			}
			DATA['Adults[' + i + ']']	= Adults;
			DATA['Children[' + i + ']']	= Children;
		}

		for( i in DATA )
			if( DATA.hasOwnProperty( i ) )
				parameters	+= i + '=' + escape( DATA[i] ) + '&';

		parameters	= parameters.substring( 0, parameters.length - 1 );

		$('info').innerHTML = '<span id="loader"><img src="images/ajax-loader.gif" alt="loader" id="img-loader" /> Моля, изчакайте...</span>';

		ajax.sendRq( 'POST', 'ajax.php?action=MakeHotelBooking&system=hp', function( response ) {
			var xmlDoc	= parseXML( response );
			$('info').innerHTML = xmlDoc.getElementsByTagName('answer')[0].firstChild.nodeValue;
		}, parameters );
	}

	function getCruises() {
		if( cruises )
			return;

		$('category').style.visibility	= 'hidden';
		$('category').style.display		= 'block';
		$('category').style.height		= '0';

		$('ar-1').className	= $('category-options').scrollWidth > 731 ? 'arrright-active' : 'arrright';
		$('al-1').className	= $('category-options').scrollLeft > 0 ? 'arrleft-active' : 'arrleft';

		var M = new MotionTween( $('category'), 0, 35, .1 );

		M.onStateChange	= function() {
			this.obj.style.height = ( this.from + this.getPercentage() * this.path / 100 ) + 'px';
			this.nextFrame();
		}

		M.onMotionFinished	= function() {
			new MotionTween( $('category'), 0, 100, .4, 'opacity' ).start();
			$('category').style.visibility	= 'visible';
		}

		M.start();

		cruises = true;
	}
	function setScroller( AL, AR, CONT, A, AB ) {
		var flag = ( CONT.id == 'category-options' );

		flag2 = A ? true : false;

		if( flag2 ) {
			if( CONT.id == 'subcategory-options' ) {
				$('subcategory').style.filter = 'alpha(opacity=100)';
				$('subcategory').style.display = 'block';
				$('subcategory').style.opacity = 1;
			}
			$('category').style.filter = 'alpha(opacity=100)';
			$('category').style.display = 'block';
			$('category').style.opacity = 1;
		}

		var Links	= Elements( CONT, 'a' ), SPAN, EM;
		var ACTIVE	= A;
		var ACT;
		var mflag = false;

		for( var i = 0; i < Links.length; i++ ) {
			SPAN	= new El( 'span' );
			EM		= new El( 'em', { 'parent' : SPAN } );

			new El( TextNode( Links[i].firstChild.nodeValue ), { 'insertBefore' : EM } );
			new El( TextNode( Links[i].firstChild.nodeValue ), { 'parent' : EM } );

			Links[i].replaceChild( SPAN, Links[i].firstChild );

			if( i == Links.length - 1 ) {
				Links[i].style.marginRight = '15px';
			}

			if( new RegExp( "(^| )category\." + ACTIVE + "($| )" ).test( Links[i].rel ) ) {
				Links[i].className += ' active';
				ACT	= Links[i];
				if( Links[i].offsetLeft + Links[i].offsetWidth > CONST_WIDTH ) {
					CONT.scrollLeft = Links[i].offsetLeft + Links[i].offsetWidth - CONST_WIDTH + 15;
					mflag = true;
				}
			}

			if( flag ) {
				//if( cats_only )
					Links[i].setAttribute( 'href', 'cruises' + Links[i].rel.match( /category\.([0-9]+)/ )[1] + '.html' );
				//else
				//	Links[i].setAttribute( 'href', 'javascript://' + Links[i].firstChild.firstChild.nodeValue );
			}

			if( !flag || !cats_only )
			Links[i].onclick	= function() {
				//if( CONT.id != 'subcategory-options' ) {
				//	if( ACT )
				//		ACT.className = ACT.className.replace( /( )?active/, '' );
				//	this.className	+= 'active';
				//	ACT	= this;
				//}

				var newCat	= this.rel.match( /category\.([0-9]+)/ )[1];

				//if( flag ) {
				//	var MT	= new MotionTween( $('subcategory-options'), 100, 0, .1, 'opacity' );
				//	MT.onMotionFinished	= function() {
				//		$('subcategory-options').innerHTML	= CATS[newCat];
				//		if( !mflag )
				//			$('subcategory-options').scrollLeft	= 0;
				//		mflag = false;
				//		setScroller( $('al-2'), $('ar-2'), $('subcategory-options'), AB );
				//
				//		new MotionTween( $('subcategory-options'), 0, 100, .3, 'opacity' ).start();
				//	}
				//	MT.start();
				//}
			}
		}

		AR.className	= CONT.scrollWidth - CONT.scrollLeft != CONST_WIDTH ? 'arrright-active' : 'arrright';
		AL.className	= CONT.scrollLeft > 0 ? 'arrleft-active' : 'arrleft';

		AL.setAttribute( 'href', 'javascript://Scroll Left' );
		AR.setAttribute( 'href', 'javascript://Scroll Right' );

		var interval, step = 15;

		AR.onmousedown	= function() {
			document.onmouseup = this.onmouseout = this.onclick = function() { if( interval ) window.clearInterval( interval ); document.onmouseup = null; }

			interval = window.setInterval( function() {
				CONT.scrollLeft += step;

				if( AR.className == 'arrright' ) {
					if( CONT.scrollWidth - CONT.scrollLeft > CONST_WIDTH )
						AR.className = 'arrright-active';
				}
				else if( CONT.scrollWidth - CONT.scrollLeft == CONST_WIDTH ) {
					AR.className = 'arrright';
				}

				if( AL.className == 'arrleft' ) {
					if( CONT.scrollLeft > 0 )
						AL.className = 'arrleft-active';
				}
				else if( CONT.scrollLeft == 0 )
					AL.className = 'arrleft';

				if( CONT.scrollWidth - CONT.scrollLeft == CONST_WIDTH ) {
					window.clearInterval( interval );
					document.onmouseup = null;
				}
			}, 50 );
			return false;
		}

		AL.onmousedown	= function() {
			document.onmouseup = this.onmouseout = this.onclick = function() { if( interval ) window.clearInterval( interval ); document.onmouseup = null; }

			interval = window.setInterval( function() {
				CONT.scrollLeft -= step;

				if( AR.className == 'arrright' ) {
					if( CONT.scrollWidth - CONT.scrollLeft > CONST_WIDTH )
						AR.className = 'arrright-active';
				}
				else if( CONT.scrollWidth - CONT.scrollLeft == CONST_WIDTH )
					AR.className = 'arrright';

				if( AL.className == 'arrleft' ) {
					if( CONT.scrollLeft > 0 )
						AL.className = 'arrleft-active';
				}
				else if( CONT.scrollLeft == 0 )
					AL.className = 'arrleft';

				if( CONT.scrollLeft == 0 ) {
					window.clearInterval( interval );
					document.onmouseup = null;
				}
			}, 50 );
			return false;
		}
	}
	var CONST_WIDTH = 731;







