
//-------------- document ready ---------------
$(document).ready(function(){
	initCastomForms();
	VSA_initScrollbars();
	$('div.gallery-slide').gallery({
		duration: 700,
		autoSlide: 3000
	});
	$('div.gallery-fade').gallery({
		duration: 500,
		autoRotation: 4000,
		fadeEl: 'ul.list > li',
		switcher: 'ul.control > li',
		effect: 'fade'
	});
	openPost();
	openSlideBlock();
	clearBlock();
	if ($('a').hasClass('hold-lightbox')) {
        $('.gallery a.hold-lightbox').lightBox();
        $('.extrait a.hold-lightbox').lightBox();
    }
	if ($("#datepicker").length > 0) $("#datepicker").datepicker({
		showOn: 'button',
		buttonImage: '/images/ico10.gif',
		buttonImageOnly: true
	});
	$('body').myPopup();

    if ($("#autocomplete_cepages").length > 0){
        $("#autocomplete_cepages").autocomplete(cepagesdata, {
		minChars: 1,
		width: 310,
		matchContains: "word",
		autoFill: false,
		formatItem: function(row, i, max) {
            return row.name;
		},
		formatMatch: function(row, i, max) {
            return row.name;
		},
		formatResult: function(row) {
            return row.name;
		}
    });

    $("#autocomplete_cepages").result(function(event, data, formatted) {
		var hidden = $('#cepage_id');
        hidden.val(data.id);
	});
    }

    if ($("#autocomplete_countries").length > 0){
        $("#autocomplete_countries").autocomplete(countrydata, {
        minChars: 1,
        width: 310,
        matchContains: "word",
        autoFill: false,
        formatItem: function(row, i, max) {
            return row.name;
        },
        formatMatch: function(row, i, max) {
            return row.name;
        },
        formatResult: function(row) {
            return row.name;
        }
    });

    $("#autocomplete_countries").result(function(event, data, formatted) {
        var hidden = $('#country');
        hidden.val(data.id);
    });
    }

    regionPopup();
	choicePopup();
	nezPopup();
	initSlider();
	initTabs();
	initAlfabet();
	initBox();
//	initClose();
	initHoverBox();
//	initCounter();
	openSlideBox();
	initOpenCkeck();
	openRadios();

});
function openRadios(){
	$('div.open-radios').each(function(){
		var hold = $(this);
		var radio = hold.find('input:radio');
		var box = hold.find('> div.block');
		var _h = box.outerHeight(true);

		box.css({
			<!--display: 'block',-->
			overflow: 'hidden'
		});
		radio.eq(0).bind('openRad', function(){
			box.animate({
				height:0
			}, {queue:false, duration: 500, complete: function(){
				$(this).css({overflow: 'hidden', position: 'relative'});
			}});
		});
		radio.eq(1).bind('openRad', function(){
			box.animate({
				height: _h
			}, {queue:false, duration: 500, complete: function(){
				$(this).css({overflow: 'visible'});
			}});
		});
	});
}
function initOpenCkeck(){
	$('div.open-checkbox').each(function(){
		var hold = $(this);
		var input = hold.find('input.opener');
		var block = hold.find('> div.block');
		var _h = block.outerHeight(true);

		block.css({
			height:0,
			overflow: 'hidden',
			position: 'relative'
		});
		input.bind('chengeChek', function(){
			$('div.optionsDivVisible').removeClass('optionsDivVisible').addClass('optionsDivInvisible');
			setTimeout(function(){
				if (input.attr('checked') != true){
					block.animate({
						height:0
					}, {queue:false, duration: 500, complete: function(){
						$(this).css({overflow: 'hidden'});
					}});
					hold.removeClass('expand-options');
					$(this).removeClass('open');
				}
				else{
					block.animate({
						height: _h
					}, {queue:false, duration: 500, complete: function(){
						$(this).css({overflow: 'visible'});
					}});
					hold.addClass('expand-options');
					$(this).addClass('open');
				}
			}, 100);
		});
	});
}
function openSlideBox(){
	$('div.propose-box').each(function(){
		var hold = $(this);
		var slider = hold.find('> div.block > div.scrollable');
		var btn = hold.find('> a.opener');
		var _h = slider.outerHeight(true);

		slider.css({
			height:0,
			overflow: 'hidden'
		});
		btn.click(function(){
			$('div.optionsDivVisible').removeClass('optionsDivVisible').addClass('optionsDivInvisible');
			if (hold.hasClass('expand-options')){
				slider.animate({
					height:0
				}, {queue:false, duration: 500, complete: function(){
					$(this).css({overflow: 'hidden'});
				}});
				hold.removeClass('expand-options');
				$(this).removeClass('open');
			}
			else{
				slider.animate({
					height: _h
				}, {queue:false, duration: 500, complete: function(){
					$(this).css({overflow: 'visible'});
				}});
				hold.addClass('expand-options');
				$(this).addClass('open');
			}
			return false;
		});
	});
}
function openSlideBox(){
    $('div.propose-box').each(function(){
		var hold = $(this);
		var slider = hold.find('> div.block > div.block-holder');
		var btn = hold.find('> div.opener-box > a');
		var _h = slider.outerHeight(true);

		slider.css({
			height:0,
			overflow: 'hidden'
		});
		btn.click(function(){
			$('div.optionsDivVisible').removeClass('optionsDivVisible').addClass('optionsDivInvisible');
			if (hold.hasClass('expand-options')){
				slider.animate({
					height:0
				}, {queue:false, duration: 500, complete: function(){
					$(this).css({overflow: 'hidden'});
				}});
				hold.removeClass('expand-options');
				$(this).removeClass('open');
			}
			else{
				slider.animate({
					height: _h
				}, {queue:false, duration: 500, complete: function(){
					$(this).css({overflow: 'visible'});
				}});
				hold.addClass('expand-options');
				$(this).addClass('open');
			}
			return false;
		});
	});
}

// function initCounter(){
// 	$('div.counter').each(function(){
// 		var hold = $(this);
// 		var input = hold.find('input.text');
// 		var decrease = hold.find('a.decrease');
// 		var increase = hold.find('a.increase');
//
// 		decrease.click(function(){
// 			var d = input.val()*1;
// 			d--;
// 			if (d < 0) d = 0;
// 			input.val(d);
// 			return false;
// 		});
// 		increase.click(function(){
// 			var d = input.val()*1;
// 			d++;
// 			input.val(d);
// 			return false;
// 		});
// 	});
// }
//
function initHoverBox(){
	$('div.rate').each(function(){
		var hold = $(this);
		var link = hold.find('img');
		var box = hold.find('div.tool-tip');

		link.hover(function(){
			box.show();
		}, function(){
			box.hide();
		});
	});
}
function initClose(){
	$('li.newsletter-hold').each(function(){
		var hold = $(this);
		var link = hold.find('a.close');

		link.click(function(){
			hold.removeClass('open')
			return false;
		});
	});
}
function initBox(){
	$('div.info-place, div.password-place').each(function(){
		var hold = $(this);
		var link = hold.find('a.btn-modifier');
		var box = hold.find('div.block');
		var h = box.outerHeight(true);
		var fer = $('div.clubs-area div.btn-holder');

		box.css({
			overflow: 'hidden',
			height:0
		});
		link.click(function(){
			if (hold.hasClass('info-place')) hold.css({background: 'none'});
			box.animate({height:h}, 500);
			$(this).hide();
			fer.show();
			return false;
		});
	});
}
function initAlfabet(){
	$('ul.alphabet').each(function(){
		var hold = $(this);
		var link = hold.find('a');

		link.click(function(){
			$.scrollTo( $($(this).attr('href')), 500);
			return false;
		});
	});
	$('div.letter > a.top').click(function(){
		$.scrollTo( $($(this).attr('href')), 500);
		return false;
	})
}
/* Gallery */
jQuery.fn.gallery = function(_options){
	// defaults options
	var _options = jQuery.extend({
		duration: 700,
		autoRotation: false,
		slideElement: 1,
		effect: false,
		fadeEl: 'ul',
		switcher: 'ul > li',
		disableBtn: false,
		next: 'a.link-next, a.btn-next, a.next',
		prev: 'a.link-prev, a.btn-prev, a.prev',
		circle: true,
		direction: false
	},_options);

	return this.each(function(){
		var _hold = $(this);
		if (!_options.effect) var _speed = _options.duration;
		else var _speed = $.browser.msie ? 0 : _options.duration;
		var _timer = _options.autoRotation;
		var _sliderEl = _options.slideElement;
		var _wrap = _hold.find(_options.fadeEl);
		var _el = _hold.find(_options.switcher);
		var _next = _hold.find(_options.next);
		var _prev = _hold.find(_options.prev);
		var _count = _el.index(_el.filter(':last'));
		var _w = _el.outerWidth(true);
		var _h = _el.outerHeight(true);
		if (!_options.direction) {
			var _wrapHolderW = Math.ceil(_wrap.parent().width() / _w);
			if (((_wrapHolderW - 1) * _w + _w / 2) > _wrap.parent().width()) _wrapHolderW--;
		}
		else{
			var _wrapHolderW = Math.ceil(_wrap.parent().height()/_h);
			if (((_wrapHolderW-1)*_h + _h/2) > _wrap.parent().height()) _wrapHolderW--;
		}
		if (_timer) var _t;
		var _active = _el.index(_el.filter('.active:eq(0)'));
		if (_active < 0) _active = 0;
		var _last = _active;
		if (!_options.effect) var rew = _count - _wrapHolderW + 1;
		else var rew = _count;

		if (!_options.effect) {
			if (!_options.direction) _wrap.css({marginLeft: -(_w * _active)})
			else _wrap.css({marginTop: -(_h * _active)})
		}
		else {
			_wrap.css({
				opacity: 0
			}).removeClass('active').eq(_active).addClass('active').css({
				opacity: 1
			}).css('opacity', 'auto');
			_el.removeClass('active').eq(_active).addClass('active');
		}
		if (_options.disableBtn) {
			if (_count < _wrapHolderW) _next.addClass(_options.disableBtn);
			_prev.addClass(_options.disableBtn);
		}

		function fadeElement(){
			_wrap.eq(_last).animate({opacity:0}, {queue:false, duration: _speed});
			_wrap.removeClass('active').eq(_active).addClass('active').animate({
				opacity:1
			}, {queue:false, duration: _speed, complete: function(){
				$(this).css('opacity','auto');
			}});
			_el.removeClass('active').eq(_active).addClass('active');
			_last = _active;
		}
		function scrollEl(){
			if (!_options.direction) _wrap.animate({marginLeft: -(_w * _active)}, {queue:false, duration: _speed})
			else _wrap.animate({marginTop: -(_h * _active)}, {queue:false, duration: _speed})
		}
		function toPrepare(){
			if ((_active == rew) && _options.circle) _active = -_sliderEl;
			for (var i = 0; i < _sliderEl; i++){
				_active++;
				if (_active > rew) {
					_active--;
					if (_options.disableBtn &&(_count > _wrapHolderW)) _next.addClass(_options.disableBtn);
				}
			};
			if (_active == rew) if (_options.disableBtn &&(_count > _wrapHolderW)) _next.addClass(_options.disableBtn);
			if (!_options.effect) scrollEl();
			else fadeElement();
		}
		function runTimer(){
			_t = setInterval(function(){
				toPrepare();
			}, _timer);
		}
		_next.click(function(){
			if(_t) clearTimeout(_t);
			if (_options.disableBtn &&(_count > _wrapHolderW)) _prev.removeClass(_options.disableBtn);
			toPrepare();
			if (_timer) runTimer();
			return false;
		});
		_prev.click(function(){
			if(_t) clearTimeout(_t);
			if (_options.disableBtn &&(_count > _wrapHolderW)) _next.removeClass(_options.disableBtn);
			if ((_active == 0) && _options.circle) _active = rew + _sliderEl;
			for (var i = 0; i < _sliderEl; i++){
				_active--;
				if (_active < 0) {
					_active++;
					if (_options.disableBtn &&(_count > _wrapHolderW)) _prev.addClass(_options.disableBtn);
				}
			};
			if (_active == 0) if (_options.disableBtn &&(_count > _wrapHolderW)) _prev.addClass(_options.disableBtn);
			if (!_options.effect) scrollEl();
			else fadeElement();
			if (_timer) runTimer();
			return false;
		});
		if (_options.effect) _el.click(function(){
			_active = _el.index($(this));
			if(_t) clearTimeout(_t);
			fadeElement();
			if (_timer) runTimer();
			return false;
		});
		if (_timer) runTimer();
	});
}
// ----------- openPost ----------
function openPost(){
	$('div.open-post').each(function(){
		var hold = $(this);
		var slide = hold.find('div.slide');
		var p = slide.find('p:first');
		var btn = hold.find('a.btn-more');
		var h_max = slide.outerHeight();
		var txt = p.text();
		var holdTxt = p.text().substr(0, 350) + '...';
		p.text(holdTxt);
		var h_min = p.outerHeight(true);

		slide.css({
			height: h_min
		});
		btn.click(function(){
			if (hold.hasClass('opened')){
				slide.animate({
					height: h_min
				}, {queue:false, duration: 500, complete: function(){
					p.text(holdTxt);
				}});
				hold.removeClass('opened');
			}
			else{
				p.text(txt);
				slide.animate({
					height: h_max
				}, {queue:false, duration: 500});
				hold.addClass('opened');
			}
			return false;
		});
	});
}
// ----------- openSlideBlock ----------
function openSlideBlock(){
	$('form.search-area div.options, div.identification-holder div.slide-block').each(function(){
		var hold = $(this);
		var slider = hold.find('div.info, div.block');
		var btn = hold.find('div.more > a, div.btn-slider > a.opener');
		var _h = slider.outerHeight(true);

		slider.css({
			height:0,
			overflow: 'hidden'
		});
		btn.click(function(){
			$('div.optionsDivVisible').removeClass('optionsDivVisible').addClass('optionsDivInvisible');
			if (hold.hasClass('expand-options')){
				slider.animate({
					height:0
				}, {queue:false, duration: 500, complete: function(){
					$(this).css({overflow: 'hidden'});
				}});
				hold.removeClass('expand-options');
				$(this).removeClass('open');
			}
			else{
				slider.animate({
					height: _h
				}, {queue:false, duration: 500, complete: function(){
					$(this).css({overflow: 'visible'});
				}});
				hold.addClass('expand-options');
				$(this).addClass('open');
			}
			return false;
		});
	});
}
// ----------- clearBlock ----------
function clearBlock(){
	$('div.clear-input').each(function(){
		var hold = $(this);
		var input = hold.find('input');
		var btn = hold.find('a.close');

		btn.click(function(){
			input.attr('value','');
			return false;
		});
	});
}
// -------------- popup -----------
jQuery.fn.myPopup = function(_options){
	// defaults options
	var _options = jQuery.extend({
		duration: 700,
		linkOpenName: '.link-popup',
		linkCloseName: 'a.btn-close, a.close, a.btn-validity,a.cuisine_close',
		divFader: 'fader'
	},_options);

	return this.each(function(){
		var _hold = $(this);
		var _speed = _options.duration;
		var _IE = ((navigator.appName.indexOf('Microsoft Internet Explorer') != -1) && (parseInt(navigator.appVersion) < 9)) ? true : false;
		var _IE7 = ((navigator.appName.indexOf('Microsoft Internet Explorer') != -1) && (parseInt(navigator.appVersion.substr(navigator.appVersion.indexOf("MSIE")+4)) <= 7)) ? true : false;
		var links = _hold.find(_options.linkOpenName);
		var _fader = $('<div class="'+_options.divFader+'"></div>');
		var popup;
		$('body > div.outtaHere').css({zIndex: 1001});
        if(!_IE7) {
            $('body').append(_fader);
        }
		_fader.css({
			position: 'absolute',
			top: '0px',
			left: '0px',
			zIndex: 999,
			background: '#fff',
			opacity: 0.85
		});
		function init(_obj){
			popup = $(_obj);
			var btnClose = popup.find(_options.linkCloseName);
			var submitBtn = popup.find('.submit');
			if (_IE){
				$('select').css({visibility: 'hidden'});
				popup.find('select').css({visibility: 'visible'});
			}
			var w = $('body').width();
			var h = $(window).height();
			var _offset = 0;
			if(document.body && document.body.scrollTop) _offset = document.body.scrollTop;
			if(document.documentElement && document.documentElement.scrollTop) _offset = document.documentElement.scrollTop;
			if(window.pageYOffset) _offset =  window.pageYOffset;
			var ret = _offset+(h/2) - popup.outerHeight(true)/2;
			if (ret < 0) ret = 0;
			//popup.css({
			//	top: ret,
			//	left: w/2 - popup.outerWidth(true)/2
			//}).hide();
            <!--TODO Modified by ENCIMA underneath (previous implementation is above)-->
			popup.css({
				top: '200px',
				left: 'auto'
			}).hide();
            <!--TODO Modified by ENCIMA underneath (getDocHeight() was originally $('body').height())-->
			if ($(window).height()<getDocHeight()){
				_fader.css({
					width: w,
					height: getDocHeight()
				}).fadeIn(300, function(){popup.fadeIn(300)});
			}
			else{
				_fader.css({
					width: w,
					height: $(window).height()
				}).fadeIn(300, function(){popup.fadeIn(300)});
			}

			$(window).resize(function(){
				w = $('body').width();
                <!--TODO Modified by ENCIMA underneath (next line is placed in comment)-->
				//popup.css({left: w/2 - popup.outerWidth(true)/2});
				_fader.css({width: w});
			});

			btnClose.click(function(){
				popup.css({left: '-9999px'});
				_fader.hide();
				if (_IE) $('select').css({visibility: 'visible'});
				$('body > div.outtaHere').css({zIndex: 1});
				$(window).unbind('resize');
				return false;
			});
			submitBtn.click(function(){
				popup.css({left: '-9999px'});
				if (_IE) $('select').css({visibility: 'visible'});
				init($(this).attr('title'));
				return false;
			})
			_fader.click(function(){
				popup.css({left: '-9999px'});
				_fader.hide();
				if (_IE) $('select').css({visibility: 'visible'});
				$('body > div.outtaHere').css({zIndex: 1});
				$(window).unbind('resize');
				return false;
			});
		}
		links.click(function(){
			if ($(this).attr('href')){
				init($(this).attr('href'));
			}
			else{
				init($(this).attr('title'));
			}
			return false;
		});
	});
}
// -------------- regionPopup select contents-----------
function regionPopupSelectDeselect(){
$('div.region-popup').each(function(){
		var hold = $(this);
		var btn02 = $('div.region-select').find('a.btn02');
		var regionPopup = $(this);
		var li1 = hold.find('ul.list:first > li');
		var li2 = hold.find('ul.list:last > li');
		var txt;
		var desel = hold.find('div.deselect > a');
        var regionId = '#region_id_' + document.getElementById('region_id').value;
        var appellationId = '#appellation_id_' + document.getElementById('appellation_id').value;
        if ($('#region_id').value!='') {
            desel.eq(0).show(); $(regionId).addClass('active');}  else {desel.eq(0).hide();
        }
        if ($('#appellation_id').value!='') {desel.eq(1).show(); $(appellationId).addClass('active');} else {desel.eq(1).hide(); }
    });
    
}
function regionPopupInit(){
$('div.region-popup').each(function(){
        var myregionid=document.getElementById('region_id').value;
        var amyregion=document.getElementById('a_region_id_'+myregionid);
        var myregionname='';
        if(amyregion!=null){
            myregionname=document.getElementById('a_region_id_'+myregionid).innerHTML;
        }
        if (myregionid!='') {
            $.get('/ajax_wine_appellations_results.jsp?regionid='+myregionid+'&regionname='+myregionname, function(data) {$('#apps_list').html(data);VSA_initScrollbars_apps();});
        }
        
        regionPopupSelectDeselect();
    });
}
// -------------- regionPopup -----------
function regionPopup(){
	$('div.region-popup').each(function(){
		var hold = $(this);
		var btn02 = $('div.region-select').find('a.btn02');
		var regionPopup = $(this);
		var li1 = hold.find('ul.list:first > li');
		var li2 = hold.find('ul.list:last > li');
		var txt;
		var desel = hold.find('div.deselect > a');

		desel.hide();
        regionPopupInit();

		btn02.click(function(){
			$('body > div.outtaHere').removeClass('optionsDivVisible').addClass('optionsDivInvisible');
			$('div.choice-popup').find('div.choice-box-hold').css({left:-9999});
			$('div.choice-popup').css({zIndex:0});
			$('div.nez-popup-hold').find('div.nez-popup').removeClass('opened').css({left:-9999});
			$('div.nez-popup-hold').css({zIndex:0});
			return false;
		});
		li1.click(function(){
			desel.eq(0).show();
			li1.removeClass('active');
			$(this).addClass('active');
			return false;
		});
		li2.click(function(){
			desel.eq(1).show();
			li2.removeClass('active');
			$(this).addClass('active');
			return false;
		});
		desel.click(function(){
			txt = desel.index($(this));
            if (txt == 0){
                $('#region_id').val('');
                $('#appellation_id').val('');
                li1.removeClass('active');
                desel.eq(0).hide();
                $('#unselect_appellation').hide();
                reloadLabelRegionAppellation();
            }
			else{
                $('#appellation_id').val('');
                $('#unselect_appellation').hide();
                $('#appsul > li').removeClass('active');
                reloadLabelRegionAppellation();
            }
			return false;
		});
	});
}
// -------------- choicePopup -----------
function choicePopup(){
	$('div.choice-popup').each(function(){
		var hold = $(this);
		var btn02 = hold.find('a.btn02');
		var regionPopup = hold.find('div.choice-box-hold');
		var li = hold.find('ul > li');
		var input = hold.find('> input');

		btn02.click(function(){
			$('body > div.outtaHere').removeClass('optionsDivVisible').addClass('optionsDivInvisible');
			$('div.nez-popup-hold').find('div.nez-popup').removeClass('opened').css({left:-9999});
			$('div.nez-popup-hold').css({zIndex:0});
			regionPopup.css({left:0});
			hold.css({zIndex:20});
			return false;
		});
		hold.hover(function(){
			$(this).addClass('choice-popup-hover');
		}, function(){
			$(this).removeClass('choice-popup-hover');
		});
		li.click(function(){
			regionPopup.css({left:-9999});
			btn02.text($(this).find('a').text());
			hold.css({zIndex:0});
			input.attr('value', $(this).find('a').text());
			return false;
		});
		$('body').click(function(){
			if (!hold.hasClass('choice-popup-hover')){
				regionPopup.css({left:-9999});
				hold.css({zIndex:0});
			}
		});
	});
}
// -------------- nezPopup -----------
function nezPopup(){
	$('div.nez-popup-hold').each(function(){
		var hold = $(this);
		var btn02 = hold.find('a.btn02');
		var regionPopup = hold.find('div.nez-popup');
		var close = hold.find('a.close');

		hold.hover(function(){
			hold.addClass('hold-hover');
		}, function(){
			hold.removeClass('hold-hover');
		});
		$('body').click(function(){
			if (!hold.hasClass('hold-hover')){
				hold.css({zIndex:0});
				regionPopup.removeClass('opened').css({left:-9999});
			}
		});
		btn02.click(function(){
			$('body > div.outtaHere').removeClass('optionsDivVisible').addClass('optionsDivInvisible');
			$('div.choice-popup').find('div.choice-box-hold').css({left:-9999});
			$('div.choice-popup').css({zIndex:0});
			hold.css({zIndex:20});
			regionPopup.addClass('opened').css({left:0});
			return false;
		});
		close.click(function(){
			hold.css({zIndex:0});
			regionPopup.removeClass('opened').css({left:-9999});
			return false;
		});
	});
}
// -------------- initSlider -----------
function initSlider(){
	function runSlider(_obj,_min, _max, _str, _minValue, _maxValue){
        $(_obj).each(function(){
			var hold = $(this);
			var range1 = hold.find('input.range1-1');
			var range2 = hold.find('input.range1-2');
			var close1 = hold.find('a.close');
			var _slider = hold.find('div.slider-range1');
			_slider.slider({
				range: true,
				min: _min,
				max: _max,
				values: [_minValue, _maxValue],
				slide: function(event, ui) {
					range1.attr('value', ui.values[0] + _str);
					range2.attr('value', ui.values[1] + _str);
				}
			});
			range1.keyup(function(e){
				var tey = ''
				e = e || window.event;
				charCode = e.which ? e.which : e.keyCode;
				if ((charCode< 58 && charCode > 47) || charCode == 8){
					chengData($(this).val()-0, range2.val().slice(0, range2.val().length-_str.length)-0);
				}
			});
			range1.blur(function(){
				range1.attr('value', _slider.slider("values", 0) + _str);
			});
			range2.keyup(function(e){
				var tey = ''
				e = e || window.event;
				charCode = e.which ? e.which : e.keyCode;
				if ((charCode< 58 && charCode > 47) || charCode == 8){
					chengData(range1.val().slice(0, range1.val().length-_str.length)-0, $(this).val()-0);
				}
			});
			range2.blur(function(){
				range2.attr('value', _slider.slider("values", 1) + _str);
			});
			function chengData(_numMin, _numMax){
				if((_numMax>_numMin) && (_numMax<= _max)) {
					_slider.slider( "destroy" )
					_slider.slider({
						range: true,
						min: 1,
						max: _max,
						values: [_numMin, _numMax],
						slide: function(event, ui) {
							range1.attr('value', ui.values[0] + _str);
							range2.attr('value', ui.values[1] + _str);
						}
					});
				}
			}
			close1.click(function(){
				chengData(_min, _max);
				range1.attr('value', _slider.slider("values", 0) + _str);
				range2.attr('value', _slider.slider("values", 1) + _str);
				return false;
			});
		});
	}

    runSlider('#slider_hotel_price',0, 1000, '€', 0, 1000);
    runSlider('#slider_hotel_quotation',1, 5, '', 1, 5);
    runSlider('#slider_wine_price',0, 723, '€',  0, 723);
    runSlider('#slider_wine_quotaton',1, 20, '', 1, 20);
    runSlider('#slider_restaurant_price',11, 360, '€', 11, 360);
    runSlider('#slider_restaurant_quotaton',0, 5, '', 0, 5);
}

function initTabs(){
	$('ul.tabset').each(function(){
		var btn_h = $(this);
		var _btn = $(this).find('a.tab');
		var _a = _btn.index(_btn.filter('.active:eq(0)'));
		if(_a == -1) _a = 0;
		_btn.parents('div.tweet-box').removeClass('active').eq(_a).addClass('active');
		_btn.each(function(_i){
			this._box = this.href.substr(this.href.indexOf("#") + 1);
			if(this._box){
				this._box = $('#'+this._box);
				if(_i == _a) this._box.show();
				else this._box.hide();
			}
			this.onclick = function(){
				changeTab(_i);
				return false;
			}
		});
		function changeTab(_ind){
			if(_ind != _a){
				if(_btn.get(_a)._box) _btn.get(_a)._box.hide();
				if(_btn.get(_ind)._box) _btn.get(_ind)._box.show();
				_btn.eq(_a).removeClass('active');
				_btn.eq(_ind).addClass('active');
				_a = _ind;
			}
		}
	});
}
// --------------------------------- initSlider ---------------------------------
var VSA_scrollAreas = new Array();
var VSA_scrollAreas_apps = new Array();

var VSA_default_imagesPath = "/images";
var VSA_default_btnUpImage = "button-up.gif";
var VSA_default_btnDownImage = "button-down.gif";
var VSA_default_scrollStep = 5;
var VSA_default_wheelSensitivity = 10;
var VSA_default_scrollbarPosition = 'right';//'left','right','inline';
var VSA_default_scrollButtonHeight = 11;
var VSA_default_scrollbarWidth = 11;

var VSA_resizeTimer = 2000;

function VSA_initScrollbars()
{
    var scrollElements = VSA_getElements("scrollable", "DIV", document, "class");
	for (var i=0; i<scrollElements.length; i++)
	{
        VSA_scrollAreas[i] = new ScrollArea(i, scrollElements[i]);
	}
}

function VSA_initScrollbars_apps(){
    var scrollElements_apps = VSA_getElements("scrollable_apps", "DIV", document, "class");
    for (var i=0; i<scrollElements_apps.length; i++)
    {
        VSA_scrollAreas[VSA_scrollAreas.length] = new ScrollArea(VSA_scrollAreas.length, scrollElements_apps[i]);
    }
}


function ScrollArea(index, elem) //constructor
{
	this.index = index;
	this.element = elem;
	var attr = this.element.getAttribute("imagesPath");
	this.imagesPath = attr ? attr : VSA_default_imagesPath;

	attr = this.element.getAttribute("btnUpImage");
	this.btnUpImage = attr ? attr : VSA_default_btnUpImage;

	attr = this.element.getAttribute("btnDownImage");
	this.btnDownImage = attr ? attr : VSA_default_btnDownImage;

	attr = Number(this.element.getAttribute("scrollStep"));
	this.scrollStep = attr ? attr : VSA_default_scrollStep;

	attr = Number(this.element.getAttribute("wheelSensitivity"));
	this.wheelSensitivity = attr ? attr : VSA_default_wheelSensitivity;

	attr = this.element.getAttribute("scrollbarPosition");
	this.scrollbarPosition = attr ? attr : VSA_default_scrollbarPosition;

	attr = this.element.getAttribute("scrollButtonHeight");
	this.scrollButtonHeight = attr ? attr : VSA_default_scrollButtonHeight;

	attr = this.element.getAttribute("scrollbarWidth");
	this.scrollbarWidth = attr ? attr : VSA_default_scrollbarWidth;

	this.scrolling = false;

	this.iOffsetY = 0;
	this.scrollHeight = 0;
	this.scrollContent = null;
	this.scrollbar = null;
	this.scrollup = null;
	this.scrolldown = null;
	this.scrollslider = null;
	this.scroll = null;
	this.enableScrollbar = false;
	this.scrollFactor = 1;
	this.scrollingLimit = 0;
	this.topPosition = 0;

	//functions declaration
	this.init = VSA_init;
	this.scrollUp = VSA_scrollUp;
	this.scrollDown = VSA_scrollDown;
	this.createScrollBar = VSA_createScrollBar;

    this.scrollIt = VSA_scrollIt;

	this.init();

}


function VSA_init()
{

	this.scrollContent = document.createElement("DIV");
	this.scrollContent.style.position = "absolute";
	this.scrollContent.innerHTML = this.element.innerHTML;
	this.scrollContent.style.overflow = "hidden";

	this.scrollContent.style.width = this.element.offsetWidth + "px";
	this.scrollContent.style.height = this.element.offsetHeight + "px";


	this.element.innerHTML = "";
	this.element.style.overflow = "hidden";
	this.element.style.display = "block";
	this.element.style.visibility = "visible";
	this.element.style.position = "relative";
	this.element.appendChild(this.scrollContent);

	this.scrollContent.className = 'scroll-content';

	this.element.index = this.index;
	this.element.over = false;

	var _this = this;
	this.element.onmouseover = function(){
        _this.element.over = true;
    };
    this.element.onmouseout = function(){
        _this.element.over = false;
    }

	if (document.all)
	{
		this.element.onscroll = VSA_handleOnScroll;
		this.element.onresize = VSA_handleResize;
	}
	else
	{
		window.onresize = VSA_handleResize;
	}

	this.createScrollBar();

	if (window.addEventListener)
        /** DOMMouseScroll is for mozilla. */
        this.element.addEventListener('DOMMouseScroll', VSA_handleMouseWheel, false);
	/** IE/Opera. */
	this.element.onmousewheel = document.onmousewheel = VSA_handleMouseWheel;

}

function VSA_createScrollBar()
{

	if (this.scrollbar != null)
	{
		this.element.removeChild(this.scrollbar);
		this.scrollbar = null;
	}

	if (this.scrollContent.scrollHeight <= this.scrollContent.offsetHeight)
		this.enableScrollbar = false;
	else if (this.element.offsetHeight > 2*this.scrollButtonHeight)
		this.enableScrollbar = true;
	else
		this.enableScrollbar = false;

	if (this.scrollContent.scrollHeight - Math.abs(this.scrollContent.scrollTop) < this.element.offsetHeight)
		this.scrollContent.style.top = 0;

	if (this.enableScrollbar)
	{

		this.scrollbar = document.createElement("DIV");
		this.element.appendChild(this.scrollbar);
		this.scrollbar.style.position = "absolute";
		this.scrollbar.style.top = "0px";
		this.scrollbar.style.height = this.element.offsetHeight+"px";
		this.scrollbar.style.width = this.scrollbarWidth + "px";

		this.scrollbar.className = 'vscroll-bar';

		if(this.scrollbarWidth != this.scrollbar.offsetWidth)
		{
			this.scrollbarWidth = this.scrollbar.offsetHeight;
		}

		this.scrollbarWidth = this.scrollbar.offsetWidth;

		if(this.scrollbarPosition == 'left')
		{
			this.scrollContent.style.left = this.scrollbarWidth + 5 + "px";
			this.scrollContent.style.width = this.element.offsetWidth - this.scrollbarWidth - 5 + "px";
		}
		else if(this.scrollbarPosition == 'right')
		{
			this.scrollbar.style.left = this.element.offsetWidth - this.scrollbarWidth  + "px";
			this.scrollContent.style.width = this.element.offsetWidth - this.scrollbarWidth - 5 + "px";
		}

		//create scroll up button
		this.scrollup = document.createElement("DIV");
		this.scrollup.index = this.index;
		this.scrollup.onmousedown = VSA_handleBtnUpMouseDown;
		this.scrollup.onmouseup = VSA_handleBtnUpMouseUp;
		this.scrollup.onmouseout = VSA_handleBtnUpMouseOut;
		this.scrollup.style.position = "absolute";
		this.scrollup.style.top = "0px";
		this.scrollup.style.left = "0px";
		this.scrollup.style.height = this.scrollButtonHeight + "px";
		this.scrollup.style.width = this.scrollbarWidth + "px";

		this.scrollup.innerHTML = '<img src="' + this.imagesPath + '/' + this.btnUpImage + '" border="0"/>';
		this.scrollbar.appendChild(this.scrollup);

		this.scrollup.className = 'vscroll-up';

		if(this.scrollButtonHeight != this.scrollup.offsetHeight)
		{
			this.scrollButtonHeight = this.scrollup.offsetHeight;
		}

		//create scroll down button
		this.scrolldown = document.createElement("DIV");
		this.scrolldown.index = this.index;
		this.scrolldown.onmousedown = VSA_handleBtnDownMouseDown;
		this.scrolldown.onmouseup = VSA_handleBtnDownMouseUp;
		this.scrolldown.onmouseout = VSA_handleBtnDownMouseOut;
		this.scrolldown.style.position = "absolute";
		this.scrolldown.style.left = "0px";
		this.scrolldown.style.top =  this.scrollbar.offsetHeight - this.scrollButtonHeight + "px";
		this.scrolldown.style.width = this.scrollbarWidth + "px";
		this.scrolldown.innerHTML = '<img src="' + this.imagesPath + '/' + this.btnDownImage + '" border="0"/>';
		this.scrollbar.appendChild(this.scrolldown);

		this.scrolldown.className = 'vscroll-down';

		//create scroll
		this.scroll = document.createElement("DIV");
		this.scroll.index = this.index;
		this.scroll.style.position = "absolute";
		this.scroll.style.zIndex = 0;
		this.scroll.style.textAlign = "center";
		this.scroll.style.top = this.scrollButtonHeight + "px";
		this.scroll.style.left = "0px";
		this.scroll.style.width = this.scrollbarWidth + "px";

		var h = this.scrollbar.offsetHeight - 2*this.scrollButtonHeight;
		this.scroll.style.height = ((h > 0) ? h : 0) + "px";

		this.scroll.innerHTML = '';
		this.scroll.onclick = VSA_handleScrollbarClick;
		this.scrollbar.appendChild(this.scroll);
		this.scroll.style.overflow = "hidden";

		this.scroll.className = "vscroll-line";

		//create slider
		this.scrollslider = document.createElement("DIV");
		this.scrollslider.index = this.index;
		this.scrollslider.style.position = "absolute";
		this.scrollslider.style.zIndex = 1000;
		this.scrollslider.style.textAlign = "center";
        this.scrollslider.innerHTML = '<div id="scrollslider' + this.index + '" style="padding:0;margin:0;"><div class="scroll-bar-top"></div><div class="scroll-bar-bottom"></div></div>';

        this.scrollbar.appendChild(this.scrollslider);

		this.subscrollslider = document.getElementById("scrollslider"+this.index);
		this.subscrollslider.style.height = Math.round((this.scrollContent.offsetHeight/this.scrollContent.scrollHeight)*(this.scrollbar.offsetHeight - 2*this.scrollButtonHeight)) + "px";

		this.scrollslider.className = "vscroll-slider";

		this.scrollHeight = this.scrollbar.offsetHeight - 2*this.scrollButtonHeight - this.scrollslider.offsetHeight;
		this.scrollFactor = (this.scrollContent.scrollHeight - this.scrollContent.offsetHeight)/this.scrollHeight;
		this.topPosition = getRealTop(this.scrollbar) + this.scrollButtonHeight;
		/* this.scrollbarHeight = this.scrollbar.offsetHeight - 2*this.scrollButtonHeight - this.scrollslider.offsetHeight; */

        this.scrollslider.style.top = 1 / this.scrollFactor * Math.abs(this.scrollContent.scrollTop) + this.scrollButtonHeight + "px";
		this.scrollslider.style.left = "0px";
		this.scrollslider.style.width = "100%";
		this.scrollslider.onmousedown = VSA_handleSliderMouseDown;
        if (document.all)
			this.scrollslider.onmouseup = VSA_handleSliderMouseUp;


    }
	else
		this.scrollContent.style.width = this.element.offsetWidth + "px";


}

function VSA_handleBtnUpMouseDown()
{
	var sa = VSA_scrollAreas[this.index];
	sa.scrolling = true;
	sa.scrollUp();
}

function VSA_handleBtnUpMouseUp()
{
	VSA_scrollAreas[this.index].scrolling = false;
}

function VSA_handleBtnUpMouseOut()
{
	VSA_scrollAreas[this.index].scrolling = false;
}

function VSA_handleBtnDownMouseDown()
{
	var sa = VSA_scrollAreas[this.index];
	sa.scrolling = true;
	sa.scrollDown();
}

function VSA_handleBtnDownMouseUp()
{
	VSA_scrollAreas[this.index].scrolling = false;
}

function VSA_handleBtnDownMouseOut()
{
	VSA_scrollAreas[this.index].scrolling = false;
}

function VSA_scrollIt()
{
    this.scrollContent.scrollTop = this.scrollFactor * ((this.scrollslider.offsetTop + this.scrollslider.offsetHeight/2) - this.scrollButtonHeight - this.scrollslider.offsetHeight/2);
}

function VSA_scrollUp()
{
	if (this.scrollingLimit > 0)
	{
		this.scrollingLimit--;
		if (this.scrollingLimit == 0) this.scrolling = false;
	}
	if (!this.scrolling) return;
	if ( this.scrollContent.scrollTop - this.scrollStep > 0)
	{
		this.scrollContent.scrollTop -= this.scrollStep;
		this.scrollslider.style.top = 1 / this.scrollFactor * Math.abs(this.scrollContent.scrollTop) + this.scrollButtonHeight + "px";
	}
	else
	{
		this.scrollContent.scrollTop = "0";
		this.scrollslider.style.top = this.scrollButtonHeight + "px";
		return;
	}
	setTimeout("VSA_Ext_scrollUp(" + this.index + ")", 30);
}

function VSA_Ext_scrollUp(index)
{
	VSA_scrollAreas[index].scrollUp();
}

function VSA_scrollDown()
{
	if (this.scrollingLimit > 0)
	{
		this.scrollingLimit--;
		if (this.scrollingLimit == 0) this.scrolling = false;
	}
	if (!this.scrolling) return;


	this.scrollContent.scrollTop += this.scrollStep;
	this.scrollslider.style.top =  1 / this.scrollFactor * Math.abs(this.scrollContent.scrollTop) + this.scrollButtonHeight + "px";

	if (this.scrollContent.scrollTop >= (this.scrollContent.scrollHeight - this.scrollContent.offsetHeight))
	{
		this.scrollContent.scrollTop = (this.scrollContent.scrollHeight - this.scrollContent.offsetHeight);
		this.scrollslider.style.top = this.scrollbar.offsetHeight - this.scrollButtonHeight - this.scrollslider.offsetHeight + "px";
		return;
	}

	setTimeout("VSA_Ext_scrollDown(" + this.index + ")", 30);
}

function VSA_Ext_scrollDown(index)
{
	VSA_scrollAreas[index].scrollDown();
}

function VSA_handleMouseMove(evt)
{
	var sa = VSA_scrollAreas[((document.all && !window.opera) ? this.index : document.documentElement.scrollAreaIndex)];
	var posy = 0;
	if (!evt) var evt = window.event;

	if (evt.pageY)
		posy = evt.pageY;
	else if (evt.clientY)
		posy = evt.clientY;

		/*if (document.all && !window.opera)
		{
			posy += document.documentElement.scrollTop;
		}*/

	var iNewY = posy - sa.iOffsetY - getRealTop(sa.scrollbar);
		iNewY += sa.scrollButtonHeight;

	if (iNewY < sa.scrollButtonHeight)
		iNewY = sa.scrollButtonHeight;
if(sa.scrollbar){
    if ( iNewY > (sa.scrollbar.offsetHeight - sa.scrollButtonHeight) - sa.scrollslider.offsetHeight)
		iNewY = (sa.scrollbar.offsetHeight - sa.scrollButtonHeight) - sa.scrollslider.offsetHeight;

	sa.scrollslider.style.top = iNewY + "px";
}
	sa.scrollIt();
}

function VSA_handleSliderMouseDown(evt)
{
	if (!(document.uniqueID && document.compatMode && !window.XMLHttpRequest))
	{
		document.onselectstart = function() { return false; }
		document.onmousedown = function() { return false; }
	}

	var sa = VSA_scrollAreas[this.index];
	if (document.all && !window.opera)
	{
		sa.scrollslider.setCapture()
		sa.iOffsetY = event.offsetY;
		sa.scrollslider.onmousemove = VSA_handleMouseMove;
	}
	else
	{
		if(window.opera)
		{
			sa.iOffsetY = event.offsetY;
		}
		else
		{
			sa.iOffsetY = evt.layerY;
		}
		document.documentElement.scrollAreaIndex = sa.index;
		document.documentElement.addEventListener("mousemove", VSA_handleMouseMove, true);
		document.documentElement.addEventListener("mouseup", VSA_handleSliderMouseUp, true);
	}
	return false;
}

function VSA_handleSliderMouseUp()
{
	if (!(document.uniqueID && document.compatMode && !window.XMLHttpRequest))
	{
		document.onmousedown = null;
		document.onselectstart = null;
	}

	if (document.all && !window.opera)
	{
		var sa = VSA_scrollAreas[this.index];
		sa.scrollslider.onmousemove = null;
		sa.scrollslider.releaseCapture();
		sa.scrollIt();
	}
	else
	{
		var sa = VSA_scrollAreas[document.documentElement.scrollAreaIndex];
		document.documentElement.removeEventListener("mousemove", VSA_handleMouseMove, true);
		document.documentElement.removeEventListener("mouseup", VSA_handleSliderMouseUp, true);
		sa.scrollIt();
	}
	return false;
}

function VSA_handleResize()
{
	if (VSA_resizeTimer)
	{
		clearTimeout(VSA_resizeTimer);
		VSA_resizeTimer = 0;
	}
	VSA_resizeTimer = setTimeout("VSA_performResizeEvent()", 100);
}

function VSA_performResizeEvent()
{
	for (var i=0; i<VSA_scrollAreas.length; i++)
		VSA_scrollAreas[i].createScrollBar();
}
function VSA_handleMouseWheel(event){
	if (this.index != null) {
		var sa = VSA_scrollAreas[this.index];

		if (sa.scrollbar == null) return;
		sa.scrolling = true;
		sa.scrollingLimit = sa.wheelSensitivity;

        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;

                /*if (window.opera)
                        delta = -delta;*/
        } else if (event.detail) { /** Mozilla case. */
                delta = -event.detail/3;
        }
        if (delta && sa.element.over) {
                if (delta > 0)
			        sa.scrollUp();
				else
			        sa.scrollDown();

                if (event.preventDefault)
                        event.preventDefault();
                event.returnValue = false;
        }
	}
}

function VSA_handleSelectStart()
{
	event.returnValue = false;
}

function VSA_handleScrollbarClick(evt)
{
	var sa = VSA_scrollAreas[this.index];
    var offsetY = (document.all ? event.offsetY : evt.layerY);

	if (offsetY < (sa.scrollButtonHeight + sa.scrollslider.offsetHeight/2))
		sa.scrollslider.style.top = sa.scrollButtonHeight + "px";
	else if (offsetY > (sa.scrollbar.offsetHeight - sa.scrollButtonHeight - sa.scrollslider.offsetHeight))
		sa.scrollslider.style.top = sa.scrollbar.offsetHeight - sa.scrollButtonHeight - sa.scrollslider.offsetHeight + "px";
	else
	{
		sa.scrollslider.style.top = offsetY + sa.scrollButtonHeight - sa.scrollslider.offsetHeight/2 + "px";
	}
	sa.scrollIt();
}

function VSA_handleOnScroll()
{
	//event.srcElement.doScroll("pageUp");
}

//--- common functions ----

function VSA_getElements(attrValue, tagName, ownerNode, attrName) //get Elements By Attribute Name
{
	if (!tagName) tagName = "*";
	if (!ownerNode) ownerNode = document;
	if (!attrName) attrName = "name";
	var result = [];
	var nl = ownerNode.getElementsByTagName(tagName);
	for (var i=0; i<nl.length; i++)
	{
	//	if (nl.item(i).getAttribute(attrName) == attrValue)
//		result.push(nl.item(i));
		if (nl.item(i).className.indexOf(attrValue) != -1)
		result.push(nl.item(i));
	}
	return result;
}

var _ie = false;
if(navigator.userAgent.toLowerCase().indexOf("msie") != -1 && navigator.userAgent.toLowerCase().indexOf("opera") == -1) _ie = true;

function getRealTop(elem)
{
	if(_ie) {
		var nTop = 0;
		if(elem)
		{
			do
			{
				nTop += elem.offsetTop - elem.scrollTop;
				elem = elem.offsetParent;
			}
			while(elem)
		}
		return nTop;
	}
	else {
		var posTop = 0;
    if(elem){
        while (elem.offsetParent) {
			posTop += elem.offsetTop;
			elem = elem.offsetParent;
		}
    }
        var _res = new Object();
		return posTop;
	}
}

//---------------------------------------- init custom form -----------------------------------
var _selectHeight = 22;

var inputs = new Array();
var selects = new Array();
var labels = new Array();
var radios = new Array();
var radioLabels = new Array();
var checkboxes = new Array();
var checkboxLabels = new Array();
var buttons = new Array();
var selects = new Array();
var all_selects = false;
var active_select = null;
var selectText = "please select";

function is_mac() {
	if (navigator.appVersion.indexOf("Safari") != -1)
	{
		if(!window.getComputedStyle)
		{
			return true;
		}
	}

	return false;
}

function initCastomForms() {
    if(!document.getElementById) {return false;}
	getElements();
	separateElements();
	replaceRadios();
	replaceCheckboxes();
	replaceSelects();

	var _selects = document.getElementsByTagName('select');
	var _SelctClassName = [];
	if (_selects) {
		for (var i = 0; i < _selects.length; i++) {
			if (_selects[i].className != '' && _selects[i].className != 'outtaHere')
				_SelctClassName[i] = ' drop-'+_selects[i].className;
		}
		for (var i = 0; i < _SelctClassName.length; i++) {
			var _selectDrop = document.getElementById('optionsDiv'+i);
			if (_selectDrop) {
				if (_SelctClassName[i])
					_selectDrop.className += _SelctClassName[i];
			}
		}
	}
}


// getting all the required elements
function getElements() {
	var _frms = document.getElementsByTagName("form");
	for (var nf = 0; nf < _frms.length; nf++) {
		if(_frms[nf].className.indexOf("default") == -1) {
			var a = document.forms[nf].getElementsByTagName("input");
			for(var nfi = 0; nfi < a.length; nfi++) {
				inputs.push(a[nfi]);
			}
			var b = document.forms[nf].getElementsByTagName("label");
			for(var nfl = 0; nfl < b.length; nfl++) {
				labels.push(b[nfl]);
			}
            var c = document.forms[nf].getElementsByTagName("select");
			for(var nfs = 0; nfs < c.length; nfs++) {
                if (c[nfs].id!="newsletter_select") {
                    selects.push(c[nfs]);
                }
            }
		}
	}
}

// separating all the elements in their respective arrays
function separateElements() {
	var r = 0; var c = 0; var t = 0; var rl = 0; var cl = 0; var tl = 0; var b = 0;
	for (var q = 0; q < inputs.length; q++) {
		if(inputs[q].type == "radio") {
			radios[r] = inputs[q]; ++r;
			for(var w = 0; w < labels.length; w++) {
				if((inputs[q].id) && labels[w].htmlFor == inputs[q].id)
				{
					radioLabels[rl] = labels[w];
					++rl;
				}
			}
		}
		if(inputs[q].type == "checkbox") {
			checkboxes[c] = inputs[q]; ++c;
			for(var w = 0; w < labels.length; w++) {
				if((inputs[q].id) && (labels[w].htmlFor == inputs[q].id))
				{
					checkboxLabels[cl] = labels[w];
					++cl;
				}
			}
		}
		if((inputs[q].type == "submit") || (inputs[q].type == "button")) {
			buttons[b] = inputs[q]; ++b;
		}
	}
}

//replacing radio buttons
function replaceRadios() {
	for (var q = 0; q < radios.length; q++) {
		radios[q].className += " outtaHere";
		var radioArea = document.createElement("div");
		if(radios[q].checked) {
			radioArea.className = "radioAreaChecked";
			radioLabels[q].className += "radioAreaCheckedLabel"
		}
		else
		{
			radioArea.className = "radioArea";
		}
		radioArea.id = "myRadio" + q;
		radios[q].parentNode.insertBefore(radioArea, radios[q]);
		radios[q]._ra = radioArea;

		radioArea.onclick = new Function('rechangeRadios('+q+')');
		if (radioLabels[q])
		{
			radioLabels[q].onclick = new Function('rechangeRadios('+q+')');
		}
	}
	return true;
}

//checking radios
function checkRadios(who) {
	var what = radios[who]._ra;
	for(var q = 0; q < radios.length; q++) {
		if((radios[q]._ra.className == "radioAreaChecked")&&(radios[q]._ra.nextSibling.name == radios[who].name))
		{
			radios[q]._ra.className = "radioArea";
			radioLabels[q].className = radioLabels[q].className.replace("radioAreaCheckedLabel", "");
		}
	}
	what.className = "radioAreaChecked";
	radioLabels[who].className += " radioAreaCheckedLabel";
    $(radios[who]).trigger('onclick');
}

//changing radios
function changeRadios(who) {
	if(radios[who].checked) {
		for(var q = 0; q < radios.length; q++) {
			if(radios[q].name == radios[who].name) {
				radios[q].checked = false;
			}
			radios[who].checked = true;
			$(radios[who]).trigger('openRad');
			checkRadios(who);
		}
	}
}

//rechanging radios
function rechangeRadios(who) {
	if(!radios[who].checked) {
		for(var q = 0; q < radios.length; q++) {
			if(radios[q].name == radios[who].name)	{
				radios[q].checked = false;
			}
			radios[who].checked = true;
			$(radios[who]).trigger('openRad');
			checkRadios(who);
		}
	}
}

//replacing checkboxes
function replaceCheckboxes() {
	for (var q = 0; q < checkboxes.length; q++) {
		checkboxes[q].className += " outtaHere";
		var checkboxArea = document.createElement("div");
		if(checkboxes[q].checked) {
			checkboxArea.className = "checkboxAreaChecked";
			checkboxLabels[q].className += "checkboxAreaCheckedLabel"
		}
		else {
			checkboxArea.className = "checkboxArea";
		}
		checkboxArea.id = "myCheckbox" + q;
		checkboxes[q].parentNode.insertBefore(checkboxArea, checkboxes[q]);
		checkboxes[q]._ca = checkboxArea;
		checkboxArea.onclick = checkboxArea.onclick2 = new Function('rechangeCheckboxes('+q+')');
		if (checkboxLabels[q])
		{
			checkboxLabels[q].onclick = new Function('changeCheckboxes('+q+')');
		}

		checkboxes[q].onkeydown = checkEvent;
	}
	return true;
}

//checking checkboxes
function checkCheckboxes(who, action) {
	var what = checkboxes[who]._ca;
	if(action == true) {
		what.className = "checkboxAreaChecked";
		what.checked = true;
		checkboxLabels[who].className += " checkboxAreaCheckedLabel";
	}
	if(action == false) {
		what.className = "checkboxArea";
		what.checked = false;
		checkboxLabels[who].className = checkboxLabels[who].className.replace("checkboxAreaCheckedLabel", "");
	}
	$(checkboxes[who]).trigger('chengeChek');
    $(checkboxes[who]).trigger('onclick');
}

//changing checkboxes
function changeCheckboxes(who) {
	if(checkboxes[who].checked) {
		checkCheckboxes(who, false);
	}
	else {
		checkCheckboxes(who, true);
	}
}

//rechanging checkboxes
function rechangeCheckboxes(who) {
	var tester = false;
	if(checkboxes[who].checked == true) {
		tester = false;
	}
	else {
		tester = true;
	}

	$(checkboxes[who]).trigger('chengeChek');
	checkboxes[who].checked = tester;
	checkCheckboxes(who, tester);
}

//check event
function checkEvent(e) {
	if (!e) var e = window.event;
	if(e.keyCode == 32) {for (var q = 0; q < checkboxes.length; q++) {if(this == checkboxes[q]) {changeCheckboxes(q);}}} //check if space is pressed
}


function replaceSelects() {
	for(var q = 0; q < selects.length; q++) {
	if (!selects[q].replaced && selects[q].offsetWidth && selects[q].className.indexOf("default") == -1)
	{
		selects[q]._number = q;
		//create and build div structure
		var selectArea = document.createElement("div");
		var left = document.createElement("span");
		left.className = "left";
		selectArea.appendChild(left);

		var disabled = document.createElement("span");
		disabled.className = "disabled";
		selectArea.appendChild(disabled);

		selects[q]._disabled = disabled;
		var center = document.createElement("span");
		var button = document.createElement("a");
		var text = document.createTextNode(selectText);
		center.id = "mySelectText"+q;

		var stWidth = selects[q].offsetWidth;
		selectArea.style.width = stWidth + "px";
		if (selects[q].parentNode.className.indexOf("type2") != -1){
			button.href = "javascript:showOptions("+q+",true)";
		} else {
			button.href = "javascript:showOptions("+q+",false)";
		}
		button.className = "selectButton";
		selectArea.className = "selectArea";

		selectArea.className += " " + selects[q].className;
		selectArea.id = "sarea"+q;
		center.className = "center";
		center.appendChild(text);
		selectArea.appendChild(center);
		selectArea.appendChild(button);

		//hide the select field
		selects[q].className += " outtaHere";
		//insert select div
		selects[q].parentNode.insertBefore(selectArea, selects[q]);
		//build & place options div

		var optionsDiv = document.createElement("div");
		var optionsListParent = document.createElement("div");
		optionsListParent.className = "select-center";
		var optionsList = document.createElement("ul");
		optionsDiv.innerHTML += "<div class='select-top'><div class='select-top-left'></div><div class='select-top-right'></div></div>";
		optionsListParent.appendChild(optionsList);
		optionsDiv.appendChild(optionsListParent);

		selects[q]._options = optionsList;

		optionsDiv.style.width = stWidth + "px";
		optionsDiv._parent = selectArea;

		optionsDiv.className = "optionsDivInvisible";
		optionsDiv.id = "optionsDiv"+q;


		populateSelectOptions(selects[q]);
		optionsDiv.innerHTML += "<div class='select-bottom'><div class='select-bottom-left'></div><div class='select-bottom-right'></div></div>";
		document.getElementsByTagName("body")[0].appendChild(optionsDiv);
		selects[q].replaced = true;
		}
	all_selects = true;
	}
}

//collecting select options
function populateSelectOptions(me) {
	me._options.innerHTML = "";

	for(var w = 0; w < me.options.length; w++) {
		if(me.options[w].title.indexOf("title") == -1) {
			var optionHolder = document.createElement('li');
			var optionLink = document.createElement('a');
			var optionTxt;
			if (me.options[w].title.indexOf('image') != -1) {
				optionTxt = document.createElement('img');
				optionSpan = document.createElement('span');
				optionTxt.src = me.options[w].title;
				optionSpan = document.createTextNode(me.options[w].text);
			} else {
				optionTxt = document.createTextNode(me.options[w].text);
			}

			optionLink.href = "javascript:showOptions("+me._number+"); selectMe('"+me.id+"',"+w+","+me._number+");";
			if (me.options[w].title.indexOf('image') != -1) {
				optionLink.appendChild(optionTxt);
				optionLink.appendChild(optionSpan);
			} else {
				optionLink.appendChild(optionTxt);
			}
			optionHolder.appendChild(optionLink);
			me._options.appendChild(optionHolder);
			//check for pre-selected items
			if(me.options[w].selected) {
				selectMe(me.id,w,me._number);
			}
		}
		else if(me.options[w].selected)
			selectMe(me.id,w,me._number);
	}
	if (me.disabled) {
		me._disabled.style.display = "block";
	}
	else {
		me._disabled.style.display = "none";
	}
}

//selecting me
function selectMe(selectFieldId,linkNo,selectNo) {
	selectField = selects[selectNo];
	for(var k = 0; k < selectField.options.length; k++) {
		if(k==linkNo) {
			selectField.options[k].selected = true;
		}
		else {
			selectField.options[k].selected = false;
		}
	}

	//show selected option
	textVar = document.getElementById("mySelectText"+selectNo);
	var newText;
	var optionSpan;
	if (selectField.options[linkNo].title.indexOf('image') != -1) {
		newText = document.createElement('img');
		newText.src = selectField.options[linkNo].title;
		optionSpan = document.createElement('span');
		optionSpan = document.createTextNode(selectField.options[linkNo].text);
	} else {
		newText = document.createTextNode(selectField.options[linkNo].text);
	}
	if (selectField.options[linkNo].title.indexOf('image') != -1) {
		if (textVar.childNodes.length > 1) textVar.removeChild(textVar.childNodes[0]);
		textVar.replaceChild(newText, textVar.childNodes[0]);
		textVar.appendChild(optionSpan);
	} else {
		if (textVar.childNodes.length > 1) textVar.removeChild(textVar.childNodes[0]);
		textVar.replaceChild(newText, textVar.childNodes[0]);
	}
	if (selectField.onchange && all_selects)
		{
			eval(selectField.onchange());
		}
}
//showing options
function showOptions(g) {
		_elem = document.getElementById("optionsDiv"+g);
		var divArea = document.getElementById("sarea"+g);
		if (active_select && active_select != _elem) {
			active_select.className = active_select.className.replace('optionsDivVisible','optionsDivInvisible');
			active_select.style.height = "auto";
			_active.className = _active.className.replace('selectAreaActive','');
		}
		if(_elem.className.indexOf("optionsDivInvisible") != -1) {
			_elem.style.left = "-9999px";
			_elem.style.top = findPosY(divArea) + _selectHeight + 'px';
			_elem.className = _elem.className.replace('optionsDivInvisible','');
			_elem.className += " optionsDivVisible";
			/*if (_elem.offsetHeight > 200)
			{
				_elem.style.height = "200px";
			}*/
			_elem.style.left = findPosX(divArea) + 'px';
			divArea.className += ' selectAreaActive';
			_active = divArea;

			active_select = _elem;
			if(document.documentElement)
			{
				document.documentElement.onclick = hideSelectOptions;
			}
			else
			{
				window.onclick = hideSelectOptions;
			}
		}
		else if(_elem.className.indexOf("optionsDivVisible") != -1) {
			_elem.style.height = "auto";
			_elem.className = _elem.className.replace('optionsDivVisible','');
			_elem.className += " optionsDivInvisible";
			divArea.className = divArea.className.replace('selectAreaActive','');
		}

		// for mouseout
		/*_elem.timer = false;
		_elem.onmouseover = function() {
			if (this.timer) clearTimeout(this.timer);
		}
		_elem.onmouseout = function() {
			var _this = this;
			this.timer = setTimeout(function(){
				_this.style.height = "auto";
				_this.className = _this.className.replace('optionsDivVisible','');
				if (_elem.className.indexOf('optionsDivInvisible') == -1)
					_this.className += " optionsDivInvisible";
			},200);
		}*/
}
_active = false;
function hideSelectOptions(e)
{
	if(active_select)
	{
		if(!e) e = window.event;
		var _target = (e.target || e.srcElement);
		if(isElementBefore(_target,'selectArea') == 0 && isElementBefore(_target,'optionsDiv') == 0)
		{
			active_select.className = active_select.className.replace('optionsDivVisible', '');
			active_select.className = active_select.className.replace('optionsDivInvisible', '');
			active_select.className += " optionsDivInvisible";
			_active.className = _active.className.replace('selectAreaActive','');
			active_select = false;

			if(document.documentElement)
			{
				document.documentElement.onclick = function(){};
			}
			else
			{
				window.onclick = null;
			}
		}
	}
}

function isElementBefore(_el,_class)
{
	var _parent = _el;
	do
	{
		_parent = _parent.parentNode;
	}
	while(_parent && _parent.className != null && _parent.className.indexOf(_class) == -1)

	if(_parent.className && _parent.className.indexOf(_class) != -1)
	{
		return 1;
	}
	else
	{
		return 0;
	}

}

function findPosY(obj) {
	var posTop = 0;
	while (obj.offsetParent) {posTop += obj.offsetTop; obj = obj.offsetParent;}
	return posTop;
}
function findPosX(obj) {
	var posLeft = 0;
	while (obj.offsetParent) {posLeft += obj.offsetLeft; obj = obj.offsetParent;}
	return posLeft;
}
function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

$(function(){
    $('.submitonenter').keydown(function(e){
        if (e.keyCode == 13) {
            $(this).parents('form').submit();
            return false;
        }
    });
});

