$(document).ready(function() {
	function contact_submit(type) {
		    text = $('#cf_text'+type).val();
			  name = $('#cf_name'+type).val();
			  phone = $('#cf_phone'+type).val();
			  email = $('#cf_email'+type).val();
			  subject = $('#cf_subject'+type).val();
			  url = $('#cf_url'+type).val();
			  
		    var msg = '';
		    if(!name) { 
		      msg = msg + 'Musíte zadat Vaše jméno\n';
		    }
		    if(!email) { 
		      msg = msg + 'Musíte zadat Váš email\n';
		    }
		    if(!text) { 
		      msg = msg + 'Musíte zadat text dotazu\n';
		    }
		    if(msg) {
		      alert(msg);
		      return false;
		    }
		    
		    $.get(base_url + '/jquery_php/contact_form_send_email.php', 
		      {text: text, name: name, phone: phone, email: email, subject: subject, url: url },
		      function(data) {       
		        
		         if(data) {
		           $('#ok_row'+type).show();          
		           $('#cf_text'+type).val('');
		           $('#cf_contact_form_ext'+type).hide();
		           $('#contact_form_content' + type + ' .submit_cover').hide();
		         //  $('#cf_text').hide();
		         }
			    } 
		    );
		  }
		  //contact_submit
			
		  $('#contact_submit').click(function(event) { 
		    contact_submit('');
		    return false;
			}); //#contact_submit
			
			
		  $('#contact_submit_footer').click(function(event) { 
		      contact_submit('_footer');
		      return false;
		  }); //#contact_submit2

		  $('#cf_send_again_footer').click(function(event) { 
				$('#ok_row_footer').hide();
				$('#cf_contact_form_ext_footer').show();  
				$('#contact_form_content_footer .submit_cover').show();
				return false;
		  });
			
		$('a.minus').click(function(event) {
			minus_plus_click($(this).attr('id'));
			return false;
		});

		$('a.plus').click(function(event) {
			minus_plus_click($(this).attr('id'));
			return false;
		});

		function minus_plus_click(id) {
			$('#' + id + '_cov').toggle();
			var curr_class = $('#' + id).attr('class');

			var new_class = 'minus';
			if (curr_class == 'minus') {
				var new_class = 'plus';
			}
			$('#' + id).removeClass(curr_class).addClass(new_class);
		}

		$('#g_input').click(function(event) { 
			if($('#g_input').val() == 'Zde zadejte hledaný text') {
				$('#g_input').val('');
		    }
		});
		$('#g_input').blur(function(event) { 
			if($('#g_input').val() == '') {
				$('#g_input').val('Zde zadejte hledaný text');
			}
		});
		  
		$('#ef_group').change(function(event) { 
			if($(this).val() == '') return false;
			window.location = $(this).val();
		});
		

		$('#cf_send_again').click(function(event) {
			$('#ok_row').hide();
			$('#cf_contact_form_ext').show();
			$('#contact_form_content .submit_cover').show();
			return false;
		});

		$('#cms_send_email').click(function(event) {
			$('#form_email2friend').toggle();
			return false;
		});

		$('#cf_title_toggle').click(function(event) { 
			$('#contact_form_content').toggle();  
		    return false;
		});

		$('#e2f_send_again').click(function(event) {
			$('#e2f_cover').show();
			$('#ok_row_e2f').hide();
			return false;
		});

		$('#email2friend_submit').click(function(event) {
			name = $('#e2f_name').val();
			email = $('#e2f_email').val();
			name_recip = $('#e2f_name_recipient').val();
			email_recip = $('#e2f_email_recipient').val();
			subject = $('#e2f_subject').val();
			url = $('#e2f_url').val();

			var msg = '';
			if (!name) {
				msg = msg + 'Musíte zadat Vaše jméno\n';
			}
			if (!email) {
				msg = msg + 'Musíte zadat Váš email\n';
			}
			if (!name_recip) {
				msg = msg + 'Musíte zadat jméno příjemce\n';
			}
			if (!email_recip) {
				msg = msg + 'Musíte zadat email příjemce\n';
			}
			if (msg) {
				alert(msg);
				return false;
			}
			$.ajax({
				type : 'GET',
				url : base_url + 'required/php/email2friend_send.php',
				data : ({
					name : name,
					email : email,
					name_recip : name_recip,
					email_recip : email_recip,
					subject : subject,
					url : url
				}),
				dataType : 'text',
				success : function(data) {
					$('#e2f_cover').hide();
					$('#e2f_name_recipient').val('');
					$('#e2f_email_recipient').val('');
					$('#ok_row_e2f').show();
				}
			});

			return false;
		});

		$('.cp_jquery_save').change(function(event) {
			name = $(this).attr('name');
			value = $(this).val();
			id = $('#id').val();

			$.get(base_url + 'jquery_php/online_jquery_save.php', {
				id : id,
				name : name,
				value : value,
				table : 'ti_data',
				step : 4
			}, function(data) {

			});

		});

		$('.cp_jquery_ch_save').click(function(event) {
			if ($(this).attr("checked")) {
				value = 1;
			} else {
				value = 0;
			}
			name = $(this).attr('name');
			id = $('#id').val();
			$.get(base_url + 'jquery_php/online_jquery_save.php', {
				id : id,
				name : name,
				value : value,
				table : 'ti_data',
				step : 4
			}, function(data) {
			});

		});

		// prepinac subjektu
		$('#subject').change(function(event) {
			if ($(this).val() == 'po') {
				$('#fo_cover').hide();
				$('#po_cover').show();
			} else {
				$('#fo_cover').show();
				$('#po_cover').hide();
			}
		});

		// END CP -----------

		$('.show_dialog_box_help').click(function(event) {
			var a_title = $(this).attr('title');
			$("#dialog_box_help").dialog({
				title : a_title,
				modal : true,
				width : 600,
				closeOnEscape : true
			});
			return false;
		});

		$(".product_box_wide_left .bw_pz_box").hover(function() {
			product_wide_box_ins_change($(this), 'left');

		}, function() {
		});
		$(".product_box_wide_left .bw_pz_box_active").hover(function() {
			product_wide_box_ins_change($(this), 'left');
		}, function() {
		});

		$(".product_box_wide_right .bw_pz_box").hover(function() {
			product_wide_box_ins_change($(this), 'right');
		}, function() {
		});
		$(".product_box_wide_right .bw_pz_box_active").hover(function() {
			product_wide_box_ins_change($(this), 'right');
		}, function() {
		});

		$('#products_slider_right').click(function(event) {
			$(".box_wide_products_zone").hide();
			$(".box_wide_products_zone2").show();
			$(".count_nav").html('5-8 z 8');
		});
		$('#products_slider_left').click(function(event) {
			$(".box_wide_products_zone2").hide();
			$(".box_wide_products_zone").show();
			$(".count_nav").html('1-4 z 8');

		});

		// kalendar JQuery UI
		$('#datumPrvniRegistrace').datepicker(
				{
					showOn : 'button',
					buttonImage : '/images/icons/calendar-green.jpg',
					buttonImageOnly : true,
					monthNames : [ 'Leden', 'Únor', 'Březen', 'Duben',
							'Květen', 'Červen', 'Červenec', 'Srpen',
							'Září', 'Říjen', 'Listopad', 'Prosinec' ],
					dayNames : [ 'Neděle', 'Pondělí', 'Úterý', 'Středa',
							'Čtvrtek', 'Pátek', 'Sobota' ],
					dayNamesMin : [ 'Ne', 'Po', 'Ut', 'St', 'Čt', 'Pa',
							'So' ],
					firstDay : 1
				});

		$('#first_registration').datepicker(
				{
					showOn : 'button',
					buttonImage : '/images/icons/calendar-green.jpg',
					buttonImageOnly : true,
					monthNames : [ 'Leden', 'Únor', 'Březen', 'Duben',
							'Květen', 'Červen', 'Červenec', 'Srpen',
							'Září', 'Říjen', 'Listopad', 'Prosinec' ],
					dayNames : [ 'Neděle', 'Pondělí', 'Úterý', 'Středa',
							'Čtvrtek', 'Pátek', 'Sobota' ],
					dayNamesMin : [ 'Ne', 'Po', 'Ut', 'St', 'Čt', 'Pa',
							'So' ],
					firstDay : 1
				});

		var day = new Date();
		day.setDate(day.getDate() + 1);
		var den_tyden = day.getDay();
		if (den_tyden == 6) {
			day.setDate(day.getDate() + 2);
		} else if (den_tyden == 0) {
			day.setDate(day.getDate() + 1);
		}
		$('#pocatek').datepicker(
				{
					showOn : 'button',
					buttonImage : '/images/icons/calendar-green.jpg',
					buttonImageOnly : true,
					monthNames : [ 'Leden', 'Únor', 'Březen', 'Duben',
							'Květen', 'Červen', 'Červenec', 'Srpen',
							'Září', 'Říjen', 'Listopad', 'Prosinec' ],
					dayNames : [ 'Neděle', 'Pondělí', 'Úterý', 'Středa',
							'Čtvrtek', 'Pátek', 'Sobota' ],
					dayNamesMin : [ 'Ne', 'Po', 'Ut', 'St', 'Čt', 'Pa',
							'So' ],
					firstDay : 1,
					minDate : day
				});
		// $('#datumPrvniRegistrace').datepicker('option', {minDate: day});
		// -----------------

	})

setInterval("test_timer()", 15000);
function product_wide_box_ins_change(curr_id, type) {
	if (curr_id.attr('class') == 'bw_pz_box_active') {
		return false;
	}
	var id2show = curr_id.attr('id').substring(3);
	var id2hide = $(".product_box_wide_" + type + " .bw_pz_box_active").attr(
			'id').substring(3);

	$(".product_box_wide_" + type + " .bw_pz_box_active .bw_pz_box_sipka")
			.hide();
	$(".product_box_wide_" + type + " .bw_pz_box_active").attr('class',
			'bw_pz_box');
	curr_id.attr('class', 'bw_pz_box_active');

	$(".bw_pz_box_active .bw_pz_box_sipka").show();

	if ($("#" + id2show)) {
		// $(".ins_box_active").attr('class','hide');
		$("#" + id2hide).attr('class', 'hide');
		$("#" + id2show).attr('class', 'ins_box_active');

	}
}

function test_timer() {
	if ($('#companies_logos_1').css('display') == 'none') {
		$('#companies_logos_2').hide();
		$('#companies_logos_1').toggle(1000);
	} else {
		$('#companies_logos_1').hide();
		$('#companies_logos_2').toggle(1000);
	}
}

