function open_page(targetlocation)
{
        return window.open(targetlocation);
}

function kontrolaObjednavky()
{

	var polozky = new Array();
	var balicek = jQuery("input[name=zaslat_balicek]:checked").val();

    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;	
	
	var text = "";
	
	var email = jQuery("input[name=email]").val();
	var emailObj = jQuery("input[name=email_objednavajiciho]").val();
	
	polozky[0] = jQuery("input[name=jmeno]");
	polozky[1] = jQuery("input[name=prijmeni]");
	polozky[2] = jQuery("input[name=telefon]");
	polozky[3] = jQuery("input[name=email]");		
	
	if(balicek != 'Nezasílat'){
		polozky[4] = jQuery("input[name=jmeno_objednavajiciho]");
		polozky[5] = jQuery("input[name=prijmeni_objednavajiciho]");
		polozky[6] = jQuery("input[name=telefon_objednavajiciho]");
		polozky[7] = jQuery("input[name=email_objednavajiciho]");				
	}
	
	for(var i = 0; i < polozky.length; i++){
	
		polozky[i].css('background-color','white');
		
		if(polozky[i].val() == ""){		
			if(polozky[i].parent().prev(".kontakttd").html() == null){
				text = text + "- Vyplňtě poloku \"Jméno účastníka kurzu\"\n";
				polozky[i].css('background-color','red');
			}
			else {
				text = text + "- Vyplňtě poloku \"" + polozky[i].parent().prev(".kontakttd").html() + "\"\n";
				polozky[i].css('background-color','red');				
			}
		}
	}

	
    if(email == '') {
		// do nothing
	}
    else if(!emailReg.test(email)) {
		text = text + "- Zadaný email účastníka je ve patném formátu";
	}
	
    if(emailObj == '') {
		// do nothing
	}
    else if(!emailReg.test(emailObj)) {
		text = text + "- Zadaný email objednávajícího je ve patném formátu";
	}	
	
	if(text != ""){
		alert(text);	
		return false;
	}
	else {
		return true;
	}
}

jQuery(document).ready(function(){
	jQuery('.balicek').change(function(){
		var val = jQuery(this).attr('value');
		if(val == 'Nezasílat'){
			jQuery("#objednavajici").hide();
		}
		else {
			jQuery("#objednavajici").show();		
		}
	});
	
	// zobrazeni odkazu
	jQuery('#footerOdkazy').show();
	
	
	// scrollovani partneru v paticce
	function mycarousel_initCallback(carousel)
	{
		// Disable autoscrolling if the user clicks the prev or next button.
		carousel.buttonNext.bind('click', function() {
			carousel.startAuto(0);
		});

		carousel.buttonPrev.bind('click', function() {
			carousel.startAuto(0);
		});

		// Pause autoscrolling if the user moves with the cursor over the clip.
		carousel.clip.hover(function() {
			carousel.stopAuto();
		}, function() {
			carousel.startAuto();
		});
	};

    jQuery('#footerOdkazy').jcarousel({
        auto: 2,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
	
	// top akordeon
	lastBlock = $("#acc_2");
    maxWidth = 550;
    minWidth = 58;	

	lastBlock.css({width:maxWidth});
	
    $("#top_acc li div").hover(
      function(){
        $(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:400 });
	$(this).animate({width: maxWidth+"px"}, { queue:false, duration:400});
	lastBlock = this;
      }
    );
	
	
});
