function CheckSelToTxt(obj)
{
	name_str=obj.name;
	name_str=name_str.substr(0,name_str.length-1)+'_t]';
	if ($(obj).val()>0)
	{
		$('input[name='+name_str+']').val('');
	}
}

jQuery.fn.movableLabel = function () {
	return this.each( function (index) {
		if ( this.htmlFor ) {
			var label = jQuery ( this );
			var input = jQuery ( '#' + this.htmlFor);
			
			if ( !input ) {
				return false;	
			}

			label.hide ();

			inputPosition = input.position();
			
			positionX = inputPosition.left;
			positionY = inputPosition.top;

			plusX = 0;
			plusY = 0;

			label.css({
				'position': 'absolute',
				'left':     positionX + plusX + 'px',
				'top':      positionY + plusY + 'px',
				'cursor':  'text'
			});
			input.focus(function(){
				label.hide();
			});
			
			input.change(function() {
				if ( this.value == '')
					label.show();								  
			});
			input.blur(function(){
				if ( this.value == '')
					label.show();
			});
			
			label.click(function() {
				label.hide();
			});
			
			if ( input.val() == '')
				label.show();

		}
	} );
}

var checkboxesChecked = false;
var googleMaps = new Array();

function openWindow(blockId) {
	$('.window-overlay').show();
	$('select').hide();
	return false;
}

function closeWindow () {
	$('.window-overlay').hide();
	$('select').show();
}


$(document).ready (function () {

	$('a.window-opener').click (function() {
		openWindow();
		$('.window-background').fadeTo(1, 0.5);
		return false;
		
	});
	
	$('a.window-check-all').click (
		function () {
			$(".window-content input[type='checkbox']").each(function(){
				this.checked = true;
				setFlag(this);
			});
			return false;
		}
	);

	$('a.window-check-none').click (
		function () {
			$(".window-content input[type='checkbox']").each(function(){
				this.checked = false;
				setFlag(this);
			});
			return false;
		}
	);
	
	$('a.window-close-link').click (function() {
		closeWindow();	
		return false;
	});
	
	$('a.window-close').click (function() {
		closeWindow();	
		return false;
	});
	
	
	$('.tabs').each(
		function () {
			var _this = this;
			$('a', this).click (
				function () {
					$('a', _this).each (function () {
						$(this.hash).hide();
					});
					$(this.hash).show();
					$('td', _this).removeClass('active');
					$(this).parent('td').addClass('active');
					$('.movable').movableLabel();
					$(this).blur();
					return false;
				}
			);	
		}
	);
	
	$('select').change(function() {
		if ( $(this).val() == '' ) {
			$(this).css({color: '#999999'});
		}
		else {
			$(this).css({color: '#333333'});
		}
	});
	
	if ($(document.body).hasClass('has-calendar')) {
		$(".search-table-ldate, .search-table-rdate").datepicker({showOn: 'button', onSelect: function () {
			$('label.movable[for=' + this.id + ']').hide();
		}, buttonImage: '/images/common/calendar.gif', buttonImageOnly: true});
		$('#ui-datepicker-div').css({display: 'none'});
	}

	if ($.browser.msie && $.browser.version < 7) {
		$(window).bind('resize', function () {
			if (document.documentElement.offsetWidth<1005) {
				document.body.style.width='1000px';
			}
			else if (document.documentElement.offsetWidth>1250) {
				document.body.style.width='1240px';
			}
			else {
				document.body.style.width='auto';
			}
		});
	}
	$('.movable').movableLabel();
});