// KONTROLA FORMULÁŘŮ

function getObj(id) {
	if (typeof id != 'string') return id;
	else return document.getElementById(id);
}

var DOM = (document.getElementById);

function testInput(obj) {
	objType = obj.type;
	switch (objType) {
		case 'checkbox':
		case 'radio': return obj.checked;
		default: return obj.value!='';
	}
}

function checkForm(msg, objArray) {
	var okStatus = true;
	for (i=0; i<objArray.length; i++) {
		if (typeof(objArray[i])=='string') {
			obj = getObj(objArray[i]);
			if (testInput(obj)) {
			} else {
				okStatus = false;
			}
		} else {
			var localOkStatus = false;
			for (j=1; j<objArray[i].length; j++) {
				obj2 = getObj(objArray[i][j]);
				if (testInput(obj2)) {
					localOkStatus = true;
				}
			}
			if (localOkStatus) {
			} else {
			}
			okStatus = (okStatus && localOkStatus);
		}
	}

	if (!okStatus) {
		alert(msg);
		return false;
	} else {
		return true;
	}
}

// NÁHLED OBRÁZKŮ PRODUKTŮ

/*
$(document).ready(function() {
	$('.nahled').mousemove(function(e) {
		$(this).find('span').css('display', 'block').css('top', e.clientY - 60).css('left', e.clientX + 20);
	});
	$('.nahled').mouseout(function() {
		$(this).find('span').css('display', 'none');
	});
});
*/

$(document).ready(function() {
	$('.nahled').hover(function() {
		var src = $(this).find('span img').attr('data-src');
		$(this).find('span img').attr('src', src);
		$(this).find('span').show();
	}, function() {
		$(this).find('span').hide();
	});
});

// AUTOMATICKÝ TISK

function printPage() {
	if (typeof(customPrintService) == 'undefined') {
	}
	else {
		var printOptions = {
			'print_footerleft':'',
			'print_footercenter':'',
			'print_footerright':'',
			'print_headerleft':'',
			'print_headercenter':'',
			'print_headerright':'',
			'print_margin_top':'0',
			'print_margin_bottom':'0',
			'print_margin_left':'0',
			'print_margin_right':'0',
			'printerName':''
		};
		printOptions['print_orientation'] = 0;
		customPrintService.printDocument(printOptions);
	}
}

// SKRÝVÁNÍ KATEGORIÍ V MENU

$(document).ready(function() {
	$('.menu').click(function() {
		$('#'+$(this).attr('rel')).slideToggle('fast');
		return false;
	});
});

// FANCYBOX

$(document).ready(function() {
	$('a.fancybox').fancybox({
		'overlayOpacity' : 0.7,
		'overlayColor' : '#000',
		'autoScale' : false,
		'titleShow' : false
	});
});

// SEŘAZENÍ DAT V TABULKÁCH

$(document).ready(function() {
	$('.tablesorter').tablesorter();
});

