$(document).ready(function() {
	loadLinks();
});

var fileCounter = 1;
var shadowActive = 0;

function loadLinks() {
	// "Popups"
	if(!(jQuery.browser.msie && jQuery.browser.version==6.0)) {
		$('.shadowLink').click(function() {
			$('#shadow').load('/ajax'+$(this).attr('href'), {}, function() {
				$('#shadowBack').show();
				window.scrollTo(0, 0);
				loadLinks();
				$('input[tabindex=1], select[tabindex=1], textarea[tabindex=1]').focus();
				shadowActive = 1;
			});
			return false;
		});
	}
	// Seiten laden
	// $('.ajax').click(function() {
	// 	$('#content').load('/ajax'+$(this).attr('href'), {}, function() {
	// 		window.scrollTo(0, 0);
	// 		loadLinks();
	// 	});
	// 	return false;
	// });
	$('.customerFilter').click(function() {
		var customerId = $(this).attr('id').replace('customerFilter', '');
		if(customerId==0) {
			$('.userItem').show();
		} else {
			$('.userItem').hide();
			$('.customer'+customerId).show();
		}
		return false;
	});
	// Einblendung schliessen
	$('.shadowClose').click(function() {
		if(shadowActive) {
			$('#shadowBack').hide();
			shadowActive = 0;
			return false;
		}
	});
	// Job-Detail: Mehr Dateien
	$('#JobDetailAddFile').show().click(function() {
		fileCounter++;
		$('#JobDetailFiles').append('<p class="noLabel">'+fileCounter+'. <input type="file" name="data[JobDetail][file'+fileCounter+']" id="JobDetailFile'+fileCounter+'" class="file" /></p>');
		$('#JobDetailJobFileCount').attr('value', fileCounter);
	});
	// Absenden von Formularen
	$('form').submit(function() {
		$('input[type=submit]').attr('disabled', 'disabled').attr('value', 'Sende, bitte warten...');
	})
	// Bearbeitungshinweise
	$('.infoBox h2').toggle(function() {
		$(this).next().slideDown();
	}, function() {
		$(this).next().slideUp();
	});
}
