function initChecker(){
/*
	$('#startdate').datepicker({
		showOn: 'both',
		buttonImage: '/typo3conf/ext/rk_camperchecker/Resources/Public/Icons/start.png',
		showAnim: 'slideDown',
		showButtonPanel: true,
		stepMonths: 3,
		numberOfMonths: 3
	});
	

	$('#enddate').datepicker({});
	$( "#enddate" ).datepicker( "option", "showAnim", 'slideDown' );
	$( "#enddate" ).datepicker( "option", "showButtonPanel", 'true' );
	$( "#enddate" ).datepicker( "option", "stepMonths", 3 );
	$( "#enddate" ).datepicker( "option", "numberOfMonths", 3 );
	$( "#enddate" ).datepicker( "option", "showOn", 'both' );
	$( "#enddate" ).datepicker( "option", "buttonImage", '/typo3conf/ext/rk_camperchecker/Resources/Public/Icons/end.png' );
*/
}
$(document).ready(function(){
	var dates = $( "#from, #to" ).datepicker({
		changeMonth: false,
		showOn: 'both',
		buttonImage: '/typo3conf/ext/rk_camperchecker/Resources/Public/Icons/startcal.png',
		showAnim: 'slideDown',
		showButtonPanel: true,
		stepMonths: 3,
		numberOfMonths: 3,
		minDate: '+7',
		onSelect: function( selectedDate ) {
			var option = this.id == "from" ? "minDate" : "maxDate",
				instance = $( this ).data( "datepicker" );
				date = $.datepicker.parseDate(
					instance.settings.dateFormat ||
					$.datepicker._defaults.dateFormat,
					selectedDate, instance.settings );
			dates.not( this ).datepicker( "option", option, date );
		}
	});
});

function correctFB(fh)
{
	var isiPad = navigator.userAgent.match(/iPad/i) != null;
	var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
	
	if( (isiPad!=false) || (isiPhone!=false) )
	{
		console.log(isiPad);
		$("#fancybox-wrap").height(fh+60);	
		$("#fancybox-inner").height(fh+40);
	}
}

function resetForm() {
	$("#CCLand").val("0");
	$("#CCCategory").val("0").attr("disabled","disabled");
	$("#CCStartStation").val("0").attr("disabled","disabled");
	$("#CCEndStation").val("0").attr("disabled","disabled");
	$("#from").val("");
	$("#to").val("");
	
	return false;
}


function checkCCForm () {
	var error = false;
	var message ="";
	var land = $('#CCLand').val();
	var typ = $('#CCCategory').val();
	var sstart = $('#CCStartStation').val();
	var send = $('#CCEndStation').val();
	var dstart = $('#from').val();
	var dend = $('#to').val();

	if (land == 0) { error = true; message=message+Mland  };
	if (typ == 0) { error = true; message=message+Mtyp  };
	if (sstart == 0) { error = true; message=message+Mstartstation  };
	if (send == 0) { error = true; message=message+Mendstation  };
	if (dstart.length < 10) { error = true; message=message+Mstartdate  };
	if (dend.length < 10) { error = true; message=message+Menddate };

	if (error == true) {
		alert(Mcheckform+message);
		return false;
	} else {
		$('#from').removeAttr("disabled");
		$('#to').removeAttr("disabled");

			/*
		  var form = $('#ccheckerform');
		  //e.preventDefault(); // disable the default submit action
		
		  _gaq.push('_trackEvent', 'Konfigurator', 'Ergebnisse', 'anzeigen', '1');
		
		  $(':input', this).attr('disabled', true); // disable all elements in the form, to avoid multiple clicks
		
		  setTimeout(function() { // after 1 second, submit the form
		    form.submit();
		  }, 1000);
			*/

		return true;
	}
}


function setMiniloader(){
	$('.miniloader').fadeIn("fast");
}
function removeMiniloader(){
	$('.miniloader').fadeOut('slow');
}

function getStationByLandAndFahrzeug(){
	var lvalue = $('#CCLand option:selected').val(); 
	var cvalue = $('#CCCategory option:selected').val();
	var startStationValue =  $('#CCStartStation option:selected').val();
	var endStationValue =  $('#CCEndStation option:selected').val();
	setMiniloader();
	$.ajax({
		url: "index.php",
		global: false,
		type: "GET",
		data: ({
			id :1,
			type:1284618331,
			'tx_rkcamperchecker_pi1[controller]': 'Checker',
			'tx_rkcamperchecker_pi1[action]': 'getstations',
			'tx_rkcamperchecker_pi1[landid]': lvalue,
			'tx_rkcamperchecker_pi1[fahrzeugkategorie]': cvalue
		}),
		dataType: "json",
		async:true,
		success: function(json){
			$('#CCStartStation').html("").append(json.html).removeAttr("disabled");
			$("#CCStartStation option[value='"+startStationValue+"']").attr("selected","selected");
			$('#CCEndStation').html("").append(json.html).removeAttr("disabled");
			$("#CCEndStation option[value='"+endStationValue+"']").attr("selected","selected");
			removeMiniloader();
		}
	});
	
	
}

function getFahrzeugByLand(){
	setMiniloader();
	$('#CCCategory').attr("disabled","disabled");
	$('#CCStartStation').attr("disabled","disabled");
	$('#CCEndStation').attr("disabled","disabled");
	
	var value = $('#CCLand option:selected').val(); 
	$.ajax({
		url: "index.php",
		global: false,
		type: "GET",
		data: ({
			id :1,
			type:1284618331,
			'tx_rkcamperchecker_pi1[controller]': 'Checker',
			'tx_rkcamperchecker_pi1[action]': 'getfahrzeugcategories',
			'tx_rkcamperchecker_pi1[landid]': value
		}),
		dataType: "json",
		async:true,
		success: function(json){
			$('#CCCategory').html("");
			$('#CCCategory').append(json.html);
			$('#CCCategory').removeAttr("disabled");

			removeMiniloader();

		}
	});
}
