
var activePayment = "";
var bookingSent = false;

  $(document).ready(function(){
  
  $('.bubbleInfo').each(function () {
    var distance = 10;
    var time = 250;
    var hideDelay = 500;

    var hideDelayTimer = null;
    var beingShown = false;
    var shown = false;
    
    var trigger = $('.half_trigger', this);
    var popup = $('.popup').css('opacity', 0);

    $([trigger.get(0), popup.get(0)]).focus(function () {
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      if (beingShown || shown) {
        return;
      } else {
        beingShown = true;

        popup.css({
          top: 180,
          left: 350,
		'z-index': '99999',
          display: 'block'
        })

        .animate({
          top: '-=' + distance + 'px',
          opacity: 1
        }, time, 'swing', function() {
          beingShown = false;
          shown = true;
        });
      }
    }).blur(function () {
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        popup.animate({
          top: '-=' + distance + 'px',
          opacity: 0
        }, time, 'swing', function () {
          shown = false;
          popup.css('display', 'none');
        });
      }, hideDelay);
    });
  });
  

	 $('#slides').cycle({
		 fx: 'scrollDown', 
		 speed: 1000 
	 });    
	
  
  	$.datepicker.setDefaults($.datepicker.regional['de']);
	$("#OutArrDate").datepicker({
		altField	:	'#InArrDate',
		minDate		:	new Date(),
		onClose		:	function(date){
				$('#InArrDate').datepicker('option', 'setDate', date);			
			}
		});
  });
  
  $(document).ready(function(){
  	$.datepicker.setDefaults($.datepicker.regional['de']);
	$("#InArrDate").datepicker({
		beforeShow	:	function(input){
				$('#InArrDate').datepicker('option', 'minDate', $('#InArrDate').datepicker('getDate'));
				$('#InArrDate').datepicker('option', 'maxDate', '+9m');
			}
	});
  });
	
	$(document).ready(function() {		
		$("#trivia").load("/index.php?page=app|trivia");	
	});

$(document).ready(function(){

  var error_icon = '<img src="../files/css/001/a/img/icon-error.png">';
  var loading_icon = '<img src="../files/css/001/a/img/icon-loading.gif">';

 default_form_values['FQSCustomer_Email_2_EmailAddress'] = 'Email';
 default_form_values['login_username'] = 'Email';
 default_form_values['login_password'] = 'Passwort';
 default_form_values['INVALID USER OR PASSWD'] = 'Ungültiger Benutzer';
 
$(".trivia").load("/index.php?page=app|trivia");

$("#cardlogo-visa").click(function(){
	var list = document.getElementById("FQSCompany_PaymentForm_CreditCard_0_CardCode");// $("#FQSCompany_PaymentForm_CreditCard_0_CardCode");
	for(var i=0;i<list.options.length;i++){
		if(list[i].value=="VISA"){
			list[i].selected = true;
			break;
		}
	}
});

$("#cardlogo-master").click(function(){
	var list = document.getElementById("FQSCompany_PaymentForm_CreditCard_0_CardCode");// $("#FQSCompany_PaymentForm_CreditCard_0_CardCode");
	for(var i=0;i<list.options.length;i++){
		if(list[i].value=="MASTER"){
			list[i].selected = true;
			break;
		}
	}
});

$("#cardlogo-amex").click(function(){
	var list = document.getElementById("FQSCompany_PaymentForm_CreditCard_0_CardCode");// $("#FQSCompany_PaymentForm_CreditCard_0_CardCode");
	for(var i=0;i<list.options.length;i++){
		if(list[i].value=="AMEX"){
			list[i].selected = true;
			break;
		}
	}
});
 
 $("a#quick_login").fancybox({
	 'hideOnContentClick'	: false,
	 'zoomSpeedIn'			: 200,
	 'zoomSpeedOut'			: 200,
	 'easingIn'				: 'swing',
	 'easingOut'			: 'swing',
	 'frameHeight'			: 250	
 });
 
 $("a#searchbutton").fancybox({
	 'hideOnContentClick'	: false,
	 'zoomSpeedIn'			: 200,
	 'zoomSpeedOut'			: 200,
	 'easingIn'				: 'swing',
	 'easingOut'			: 'swing',
	 'frameHeight'			: 370,
	 'frameWidth'			: 400,
	 'callbackOnStart'		: doSearch
 });
 
 $("a#carrierlink").fancybox({
	 'hideOnContentClick'	: true,
	 'zoomSpeedIn'			: 200,
	 'zoomSpeedOut'			: 200,
	 'easingIn'				: 'swing',
	 'easingOut'			: 'swing',
	 'frameWidth'			: 300,
	 'frameHeight'			: 150
 });

$("a#displayCheckResult").fancybox({
	 'hideOnContentClick'	: false,
	 'zoomSpeedIn'			: 200,
	 'zoomSpeedOut'			: 200,
	 'easingIn'				: 'swing',
	 'easingOut'			: 'swing',
	 'frameWidth'			: 350,
	 'frameHeight'			: 350
 });

 if($("#cvc_desc")){
 	$("#cvc_desc").tooltip();
 }

	
   $("#mode_rail_ad").click(function(event){
	if($("#mode_rail_ad:checked").length == 0)
	{
		if($("#mode_air_ad:checked").length == 0){
			$("#mode_rail_ad").attr('checked',true);
			$('a#carrierlink').click();			
		}else{
			$('#div_bims').fadeOut();
			switch_mode('rail','N');		
		}
	}
	else
	{
		$('#div_bims').fadeIn();
		switch_mode('rail','Y');
	}
  }); 
 $("#icon_rail").click(function(event){
	$("#div_more_options").fadeIn();
	if($("#mode_rail_ad:checked").length == 0)
	{
		switch_mode('rail','Y');
		$("#mode_rail_ad").attr('checked',true);
		$('#div_bims').fadeIn();
	}
	else
	{
		if($("#mode_air_ad:checked").length == 0){
			$('a#carrierlink').click();
		}else{
			switch_mode('rail','N');
			$("#mode_rail_ad").attr('checked',false);
			$('#div_bims').fadeOut();
		}
	}  
  });
  
   $("#mode_air_ad").click(function(event){
	if($("#mode_air_ad:checked").length == 0)
	{
		if($("#mode_rail_ad:checked").length == 0){
			$("#mode_air_ad").attr('checked',true);
			$('a#carrierlink').click();				
		}else{
			switch_mode('air','N');	
		}
	}
	else
	{
		switch_mode('air','Y');
	}
  });
 
 $("#icon_air").click(function(event){
	if($("#mode_air_ad:checked").length == 0)
	{
		switch_mode('air','Y');
		$("#mode_air_ad").attr('checked',true);
	}
	else
	{
		if($("#mode_rail_ad:checked").length == 0){
			$('a#carrierlink').click();
		}else{
			switch_mode('air','N');
			$("#mode_air_ad").attr('checked',false);
		}
	}  
  });
  
   $("#mode_car_ad").click(function(event){
   	$("#div_more_options").fadeIn();
	if($("#mode_car_ad:checked").length == 0)
	{
		switch_mode('car','N');	
	}
	else
	{
		switch_mode('car','Y');
	}
  }); 
 $("#icon_car").click(function(event){
 	$("#div_more_options").fadeIn();
	if($("#mode_car_ad:checked").length == 0)
	{
		switch_mode('car','Y');
		$("#mode_car_ad").attr('checked',true);
	}
	else
	{
		switch_mode('car','N');
		$("#mode_car_ad").attr('checked',false);
	}  
  });  
  
  
   $("#mode_hotel_ad").click(function(event){
	if($("#mode_hotel_ad:checked").length == 0)
	{
		switch_mode('hotel','N');		
	}
	else
	{
		switch_mode('hotel','Y');
	}
  }); 
 $("#icon_hotel").click(function(event){
	$("#div_more_options").fadeIn();
	if($("#mode_hotel_ad:checked").length == 0)
	{
		switch_mode('hotel','Y');
		$("#mode_hotel_ad").attr('checked',true);
	}
	else
	{
		switch_mode('hotel','N');
		$("#mode_hotel_ad").attr('checked',false);
	}  
  });  

	function switch_mode(modetype,direction)
	{
			$('#FQSmode_'+modetype).val(direction);
			$('#icon_'+modetype).attr('src','/files/css/001/a/img/stage2-top_'+direction+'_'+modetype+'.jpg');
	}
    
  
   $("#more_options").click(function(event){
	$("#div_more_options").fadeIn(100);
	$("#more_options").fadeOut(1);
  });    
   $("#less_options").click(function(event){
	$("#div_more_options").fadeOut(100);
	$("#more_options").fadeIn(110);
  });  
  
 
  $("#login_username").focus(function(event){
	if(this.value == default_form_values['login_username']) this.value = '';
  });  
  $("#login_password").focus(function(event){
	if(this.value == default_form_values['login_password']) this.value = '';
  }); 
  $("#login_password").live("keypress",function(event){
		var code = (event.keyCode ? event.keyCode : event.which);
		 if(code == 13) {
			document.forms[0].submit();
		 }
	});


 
  
  $("#FQS_login_username").focus(function(event){
	if(this.value == default_form_values['login_username']) this.value = '';
  });  
  $("#FQS_login_password").focus(function(event){
	if(this.value == default_form_values['login_password']) this.value = '';
  }); 
  
  $("#FQS_from").focus(function(event){
	if(is_default_value(this.value)||this.value == 'Strasse, PLZ, Ort') this.value = '';
  });  
  $("#FQS_to").focus(function(event){
	if(is_default_value(this.value)||this.value == 'Strasse, PLZ, Ort') this.value = '';
  });
  $("#FQS_from").blur(function(event){
	if(this.value=='') this.value = 'Strasse, PLZ, Ort';
  });  
  $("#FQS_to").blur(function(event){
	  if(this.value=='') this.value = 'Strasse, PLZ, Ort';
  });
  $("#OutArrDate").focus(function(event){
	if(is_default_value(this.value)) this.value = '';
  });  
  $("#InArrDate").focus(function(event){
	if(is_default_value(this.value)) this.value = '';
  });  
  $("#OutArrDate").blur(function(event){
	//validate_dateformat(this);
	$("#InArrDate").val(this.value);
  });  
  $("#InArrDate").blur(function(event){
	//validate_dateformat(this);
  });  
  $("#termslink").click(function(event){

		data = {
		page:"service|content",
		ident : 'terms',
		stoplayout: 1
		};
		
		$.post('/index.php', data, display_terms_callback, "text");
  });  
   

   
	 $("#search_sm").fancybox({
		 'hideOnContentClick'	: false,
		 'zoomSpeedIn'			: 200,
		 'zoomSpeedOut'			: 200,
		 'easingIn'				: 'swing',
		 'easingOut'			: 'swing',
		 'frameHeight'			: 400,
		 'callbackOnStart'		: doAdvancedSearch
	 });
	 $("#search_bc").fancybox({
		 'hideOnContentClick'	: false,
		 'zoomSpeedIn'			: 200,
		 'zoomSpeedOut'			: 200,
		 'easingIn'				: 'swing',
		 'easingOut'			: 'swing',
		 'frameHeight'			: 400,
		 'callbackOnStart'		: doBroadcastSearch
	 });

 $("#fee").click(function(event){
	$("#flsh2").fadeIn(1);
	$("#victim").fadeIn(1);
	$("#victim").fadeTo(1,0.6);
	 so.write('flsh2');
	 /*
		 'hideOnContentClick'	: false,
		 'zoomSpeedIn'			: 200,
		 'zoomSpeedOut'			: 200,
		 'easingIn'				: 'swing',
		 'easingOut'			: 'swing',
		 'frameHeight'			: 280,
		 'frameWidth'			: 730,
		 'callbackOnStart'		: doFee
		 */
	 });
	 
$("#victim").click(function(event){
	$("#victim").fadeOut(1);
	$('#flsh2').html('');	
});
	 
   function doFee()
	{
		$("#fancy_content").css({
			'display'		: 'none'
		});
		$("#flsh2").attr('zindex','99999');		
		so.write('flsh2');
	}   
 
   $("#button_allow_gatekeeper").click(function(event){

	$("#message").html('');
	var form_data = $("#form_allow_gatekeeper").serialize();

	data = {
	page:"fqs|allow_gatekeeper_layout",
	FQS_serialized : form_data
	};

	$.post('/index.php', data, ALLOW_GATEKEEPER_callback, "text");
  });
 
function ALLOW_GATEKEEPER_callback(data)
{

	var split_data = data.split(':');
	
	if(split_data[0] == 'error')
	{
		$("#message").prepend("<div class='error'>"+data+"</div>");
		$("#message").fadeIn("slow");
	}
	else
	{	
		//$("#upd_traveler").remove();
		//$("#upd_traveler_div").html(data);
		
		alert('data');
	}
	
}




    $("#button_create_company").click(function(event){

	
	// letzte validierung
	
		err = false;

		var non_empties = new Array('FQSCompanyInfo_AddressInfo0AddressLine','FQSCompanyInfo_AddressInfo0PostalCode','FQSCompanyInfo_AddressInfo0PostalCode',
		'FQSCompanyInfo_AddressInfo0CityName','FQSCompanyInfo_ContactPerson_PersonName_GivenName','FQSCompanyInfo_ContactPerson_PersonName_Surname','FQSCompanyInfo_ContactPerson_TelephoneInfo0PhoneNumber',
		'FQSCompanyInfo_ContactPerson_Email0EmailAddress','FQSAccessData_Passwd');

		for(i=0; i < non_empties.length; i++)
		{
			fieldname = non_empties[i];
			$("#"+fieldname+" ~ img").remove();
			$("#"+fieldname).removeClass("error");
				
				if( $("#"+fieldname).val() == "")
				{
				$("#"+fieldname).after(error_icon);
				$("#"+fieldname+" ~ img").addClass('cursor');
				$("#"+fieldname+" ~ img").attr( 'title', '' );
				$("#"+fieldname).addClass("error");
				err  = true;
				}	
		}

		if($("#terms:checked").length == 0)
		{
			err  = true;
			$("#divcheckbox").addClass('error');
		}
		else{$("#divcheckbox").removeClass('error');}
		if($("#conditions:checked").length == 0)
		{
			err  = true;
			$("#divcheckboxconditions").addClass('error');
		}else{$("#divcheckboxconditions").removeClass('error');}




		if(err === false)
		{
		$("#message").html('');
		var form_data = $("#form_create_company").serialize();

		data = {
		page:"fqs|create_company_profile_layout",
		FQS_serialized : form_data
		};

		$.post('/index.php', data, create_company_callback, "text");
		}	
	
	
	

  });
 
 
function create_company_callback(data)
{
	var split_data = data.split(':');

	if(split_data[0] == 'error')
	{
		$("#message").prepend("<div class='error'>"+data+"</div>");
		$("#message").fadeIn("slow");
	}
	else
	{	
		$("#message").prepend("<div class='success'>"+default_form_values["Register_success_check_mails"]+"</div>");
		$("#message").fadeIn("slow");
	}
	
} 
 
 
 
  $("#FQSPersonName_GivenName").focus(function(event){

	if(this.value == default_form_values['FQSPersonName_GivenName']) this.value = '';
  });
  $("#FQSPersonName_Surname").focus(function(event){

	if(this.value == default_form_values['FQSPersonName_Surname']) this.value = '';
  });
  $("#FQSCustomer_AddressInfo_AddressLine").focus(function(event){

	if(this.value == default_form_values['FQSCustomer_AddressInfo_AddressLine']) this.value = '';
  });
  $("#FQSCustomer_AddressInfo_PostalCode").focus(function(event){

	if(this.value == default_form_values['FQSCustomer_AddressInfo_PostalCode']) this.value = '';
  });
  $("#FQSCustomer_AddressInfo_CityName").focus(function(event){

	if(this.value == default_form_values['FQSCustomer_AddressInfo_CityName']) this.value = '';
  });
  $("#FQSCustomer_Email_2_EmailAddress").focus(function(event){

	if(this.value == default_form_values['FQSCustomer_Email_2_EmailAddress']) this.value = '';
  });
  $("#FQSCustomer_TelephoneInfo_3_PhoneNumber").focus(function(event){

	if(this.value == default_form_values['FQSCustomer_TelephoneInfo_3_PhoneNumber']) this.value = '';
  });
  $("#FQSCustomer_TelephoneInfo_4_PhoneNumber").focus(function(event){

	if(this.value == default_form_values['FQSCustomer_TelephoneInfo_4_PhoneNumber']) this.value = '';
  });
  $("#FQSAccessData_Passwd").focus(function(event){

	if(this.value == default_form_values['FQSAccessData_Passwd']) this.value = '';
  });
  
$("#FQSPersonName_GivenName").blur(function(event){
	validate_empty(this,'FQSPersonName_GivenName');	
});
$("#FQSPersonName_Surname").blur(function(event){
	validate_empty(this,'FQSPersonName_Surname');	
});
$("#FQSCustomer_AddressInfo_AddressLine").blur(function(event){
	validate_empty(this,'FQSCustomer_AddressInfo_AddressLine');	
});
$("#FQSCustomer_AddressInfo_PostalCode").blur(function(event){
	validate_empty(this,'FQSCustomer_AddressInfo_PostalCode');	
});
$("#FQSCustomer_AddressInfo_CityName").blur(function(event){
	validate_empty(this,'FQSCustomer_AddressInfo_CityName');	
});
$("#FQSCustomer_Email_2_EmailAddress").blur(function(event){
	validate_empty(this,'FQSCustomer_Email_2_EmailAddress');	
});




function validateEmail(emailAddress) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = emailAddress;
   if(reg.test(address) == false) {
      return false;
   }else{
      return true;
   }
}



/**********************************************************************
 * validations for from "order_gift_form"
 **********************************************************************/
/* instant validations */
$("#COFcompany").blur(function(event) {
	validate_empty(this,'#COFcompany');
	if(this.value=='') $(this).after(error_icon);
});
$("#COFgender").blur(function(event) {
	validate_empty(this,'#COFgender');
	if(this.value=='') $(this).after(error_icon);
});
$("#COFgivenname").blur(function(event) {
	validate_empty(this,'#COFgivenname');
	if(this.value=='') $(this).after(error_icon);
});
$("#COFsurname").blur(function(event) {
	validate_empty(this,'#COFsurname');
	if(this.value=='') $(this).after(error_icon);
});
$("#COFstreet").blur(function(event) {
	validate_empty(this,'#COFstreet');
	if(this.value=='') $(this).after(error_icon);
});
$("#COFzip").blur(function(event) {
	validate_empty(this,'#COFzip');
	if(this.value=='') $(this).after(error_icon);
});
$("#COFcity").blur(function(event) {
	validate_empty(this,'#COFcity');
	if(this.value=='') $(this).after(error_icon);
});
$("#COFcountry").blur(function(event) {
	validate_empty(this,'#COFcountry');
	if(this.value=='') $(this).after(error_icon);
});

/* submit validations */
$("#button_order_gift_form").click(function(event){
	err = false;
	$('#order_gift_form .required').each(function(){
		validate_empty(this,this.id);
		if(this.value=='') {
			$(this).after(error_icon);
			err = true;
		}
	});
	if(false === err) {
		document.order_gift_form.submit();
	}else{
		if(!document.getElementById('advice_displayed')) {
			$("#message").prepend("<div class='error' id='advice_displayed'>Bitte f&uuml;llen Sie alle Felder aus.</div>");
			$("#message").fadeIn("slow");
		}
	}
});
/**********************************************************************/



/**********************************************************************
 * validations for from "form_bahncorporate"
 **********************************************************************/
/* instant validations */
$("#BCFcompany_name").blur(function(event) {
	validate_empty(this,'#BCFcompany_name');
	if(this.value=='') $(this).after(error_icon);
});
$("#BCFstreet_no").blur(function(event) {
	if($("#BCFstreet_no").hasClass('required')) {
		validate_empty(this,'#BCFstreet_no');
		if(this.value=='') $(this).after(error_icon);
	}
});
$("#BCFZIP").blur(function(event) {
	if($("#BCFZIP").hasClass('required')) {
		validate_empty(this,'#BCFZIP');
		if(this.value=='') $(this).after(error_icon);
	}
});
$("#BCFCity").blur(function(event) {
	if($("#BCFCity").hasClass('required')) {
		validate_empty(this,'#BCFCity');
		if(this.value=='') $(this).after(error_icon);
	}
});
$("#BCFpobox").blur(function(event) {
	if($("#BCFpobox").hasClass('required')) {
		validate_empty(this,'#BCFpobox');
		if(this.value=='') $(this).after(error_icon);
	}
});
$("#BCFpobox_ZIP").blur(function(event) {
	if($("#BCFpobox_ZIP").hasClass('required')) {
		validate_empty(this,'#BCFpobox_ZIP');
		if(this.value=='') $(this).after(error_icon);
	}
});
$("#BCFpobox_City").blur(function(event) {
	if($("#BCFpobox_City").hasClass('required')) {
		validate_empty(this,'#BCFpobox_City');
		if(this.value=='') $(this).after(error_icon);
	}
});
$("#BCFUsername").blur(function(event) {
	validate_empty(this,'#BCFUsername');
	if(this.value=='') $(this).after(error_icon);
});
$("#BCFGivenName").blur(function(event) {
	validate_empty(this,'#BCFGivenName');
	if(this.value=='') $(this).after(error_icon);
});
$("#BCFSurName").blur(function(event) {
	validate_empty(this,'#BCFSurName');
	if(this.value=='') $(this).after(error_icon);
});
$("#BCFPhone_business").blur(function(event) {
	validate_empty(this,'#BCFPhone_business');
	if(this.value=='') $(this).after(error_icon);
});
$("#BCFEmail").blur(function(event) {
	validate_empty(this,'#BCFEmail');
	if(this.value=='') $(this).after(error_icon);
});
$("#BCFPassword").blur(function(event) {
	validate_empty(this,'#BCFPassword');
	if(this.value=='') $(this).after(error_icon);
});
$("#RepeatPassword").blur(function(event) {
	validate_empty(this,'#RepeatPassword');
	if(this.value=='') $(this).after(error_icon);
});




/* submit validations */
$("#button_bahncorporate").click(function(event){
	err = false;
	$('#form_bahncorporate .required').each(function(){
		validate_empty(this,this.id);
		if(this.value=='') {
			$(this).after(error_icon);
			err = true;
		}
	});



	if(document.getElementById('BCFPassword').value!=document.getElementById('RepeatPassword').value) {

		document.getElementById('BCFPassword').value = '';
		document.getElementById('RepeatPassword').value = '';

		$('#BCFPassword').addClass("error");
		$('#BCFPassword').after(error_icon);

		$('#RepeatPassword').addClass("error");
		$('#RepeatPassword').after(error_icon);
		
		err = true;
	}

	if(false === err) {
		document.form_bahncorporate.submit();
	}else{
		if(!document.getElementById('advice_displayed')) {
			$("#message").prepend("<div class='error' id='advice_displayed'>Bitte f&uuml;llen Sie alle Felder aus.</div>");
			$("#message").fadeIn("slow");
		}
	}
});


$("#use_adresstype_street").click(function(event){
	$("#BCFpobox").removeClass('required');
	$("#BCFpobox_ZIP").removeClass('required');
	$("#BCFpobox_City").removeClass('required');
	$("#BCFpobox").removeClass('error');
	$("#BCFpobox_ZIP").removeClass('error');
	$("#BCFpobox_City").removeClass('error');
	$("#BCFpobox ~ img").remove();
	$("#BCFpobox_ZIP ~ img").remove();
	$("#BCFpobox_City ~ img").remove();


	$("#BCFstreet_no").addClass('required');
	$("#BCFZIP").addClass('required');
	$("#BCFCity").addClass('required');
});

$("#use_adresstype_pobox").click(function(event){
	$("#BCFpobox").addClass('required');
	$("#BCFpobox_ZIP").addClass('required');
	$("#BCFpobox_City").addClass('required');

	$("#BCFstreet_no").removeClass('required');
	$("#BCFZIP").removeClass('required');
	$("#BCFCity").removeClass('required');
	$("#BCFstreet_no").removeClass('error');
	$("#BCFZIP").removeClass('error');
	$("#BCFCity").removeClass('error');
	$("#BCFstreet_no ~ img").remove();
	$("#BCFZIP ~ img").remove();
	$("#BCFCity ~ img").remove();

});


/**********************************************************************/






/**********************************************************************
 * validations for from "form_private_contact"
 **********************************************************************/

/* instant validations */
$("#PCFgivenName").blur(function(event) {
	validate_empty(this,'#PCFgivenName');
	if(this.value=='') $(this).after(error_icon);
});
$("#PCFsurName").blur(function(event) {
	validate_empty(this,'#PCFsurName');
	if(this.value=='') $(this).after(error_icon);
});
$("#PCFemail").blur(function(event) {
	if(!validateEmail(this.value)) {
		if(!$("#PCFemail").hasClass('error')) {
			$(this).after(error_icon);
			$(this).addClass('error');
		}
	}else{
		$("#PCFemail ~ img").remove();
		$("#PCFemail").removeClass("error");
	}
});

/* submit validations */
$("#button_private_contact_form").click(function(event){
	err = false;
	$('#form_private_contact .required').each(function(){
		validate_empty(this,this.id);
		if(this.value=='') {
			$(this).after(error_icon);
			err = true;
		}
	});

	if(!validateEmail(document.getElementById("PCFemail").value)) {
		if(!$("#PCFemail").hasClass('error')) {
			$("#PCFemail").after(error_icon);
			$("#PCFemail").addClass('error');
		}
		err = true;
	}

	if(false === err) {
		document.form_private_contact.submit();
	}else{
		if(!document.getElementById('advice_displayed')) {
			$("#message").prepend("<div class='error' id='advice_displayed'>Bitte f&uuml;llen Sie alle Felder aus.</div>");
			$("#message").fadeIn("slow");
		}
	}
});
/**********************************************************************/




/**********************************************************************
 * validations for from "form_company_contact"
 **********************************************************************/

/* instant validations */
$("#CCFcompany").blur(function(event) {
	validate_empty(this,'#CCFcompany');
	if(this.value=='') $(this).after(error_icon);
});
$("#CCFstreet").blur(function(event) {
	validate_empty(this,'#CCFstreet');
	if(this.value=='') $(this).after(error_icon);
});
$("#CCFzip").blur(function(event) {
	validate_empty(this,'#CCFzip');
	if(this.value=='') $(this).after(error_icon);
});
$("#CCFcity").blur(function(event) {
	validate_empty(this,'#CCFcity');
	if(this.value=='') $(this).after(error_icon);
});


$("#CCFcp_givenName").blur(function(event) {
	validate_empty(this,'#CCFcp_givenName');
	if(this.value=='') $(this).after(error_icon);
});
$("#CCFcp_surName").blur(function(event) {
	validate_empty(this,'#CCFcp_surName');
	if(this.value=='') $(this).after(error_icon);
});
$("#CCFcp_email").blur(function(event) {
	if(!validateEmail(this.value)) {
		if(!$("#CCFcp_email").hasClass('error')) {
			$(this).after(error_icon);
			$(this).addClass('error');
		}
	}else{
		$("#CCFcp_email ~ img").remove();
		$("#CCFcp_email").removeClass("error");
	}
});

/* submit validations */
$("#button_company_contact_form").click(function(event){
	err = false;
	$('#form_company_contact .required').each(function(){
		validate_empty(this,this.id);
		if(this.value=='') {
			$(this).after(error_icon);
			err = true;
		}
	});

	if(!validateEmail(document.getElementById("CCFcp_email").value)) {
		if(!$("#CCFcp_email").hasClass('error')) {
			$("#CCFcp_email").after(error_icon);
			$("#CCFcp_email").addClass('error');
		}
		err = true;
	}

	if(false === err) {
		document.form_company_contact.submit();
	}else{
		if(!document.getElementById('advice_displayed')) {
			$("#message").prepend("<div class='error' id='advice_displayed'>Bitte f&uuml;llen Sie alle Felder aus.</div>");
			$("#message").fadeIn("slow");
		}
	}
});
/**********************************************************************/




$("#button_book").click(function(event){
if(bookingSent==false){
 err = false;
 dsp_price_tab();

	$('#form_booking_details .required').each(function(){$(this).removeClass("error");});
	
	var arrErrors = new Array();
	
	//check all normal fields for correct values
	var fieldIds = new Array(
		new Array('Adresse des Unternehmens','FQSCompanyInfo_AddressInfo0AddressLine'),
		new Array('Postleitzahl','FQSCompanyInfo_AddressInfo0PostalCode'),
		new Array('Stadt','FQSCompanyInfo_AddressInfo0CityName'),
		new Array('Vorname des Ansprechpartners','FQSCompanyInfo_ContactPerson_PersonName_GivenName'),
		new Array('Nachname des Ansprechpartners','FQSCompanyInfo_ContactPerson_PersonName_Surname'),
		new Array('Telefonnummer des Ansprechpartners','FQSCompanyInfo_ContactPerson_TelephoneInfo0PhoneNumber'),
		new Array('E-Mail des Ansprechpartners','FQSCompanyInfo_ContactPerson_Email0EmailAddress')
		);
	
	for(var f=0;f<fieldIds.length;f++){
		//alert($('#'+fieldIds[f][1]).val());
		if($('#'+fieldIds[f][1]).val()==""){
			arrErrors.push(fieldIds[f][0]);
			$('#'+fieldIds[f][1]).addClass("error");
			err  = true;
		}
	}

	if($("#terms:checked").length == 0)
	{
		err  = true;
		$("#divcheckbox").addClass('error');
		arrErrors.push('Sie m&uuml;ssen die AGB akzeptieren. Bitte setzen Sie den Haken f&uuml;r eine Zustimmung.');
	}
	
	if($("#conditions:checked").length == 0)
	{
		err  = true;
		$("#divcheckboxconditions").addClass('error');
		arrErrors.push('Sie m&uuml;ssen den Datenschutzbestimmungen zustimmen. Bitte setzen Sie den Haken f&uuml;r eine Zustimmung.');
	}
	
	var paymentPage = "";
	switch(activePayment){
		
		case "":
			paymentPage = "app|prepare_booking_novalnet";
			var fieldIdsNovalnet = new Array(
				new Array('Inhaber der Kreditkarte','FQSCompany_PaymentForm_CreditCard_0_CardHolderName'),
				new Array('Kreditkartennummer','FQSCompany_PaymentForm_CreditCard_0_CardNumber'),
				new Array('Sicherheitscode der Kreditkarte','FQSCompany_PaymentForm_CreditCard_0_CardCSV')
				);

			for(var f=0;f<fieldIdsNovalnet.length;f++){
				if($('#'+fieldIdsNovalnet[f][1]).val()==""){
					arrErrors.push(fieldIdsNovalnet[f][0]);
					$('#'+fieldIdsNovalnet[f][1]).addClass("error");
					err  = true;
				}
			}
			break;
		case 0:
			paymentPage = "app|prepare_booking_novalnet";
			var fieldIdsNovalnet = new Array(
				new Array('Inhaber der Kreditkarte','FQSCompany_PaymentForm_CreditCard_0_CardHolderName'),
				new Array('Kreditkartennummer','FQSCompany_PaymentForm_CreditCard_0_CardNumber'),
				new Array('Sicherheitscode der Kreditkarte','FQSCompany_PaymentForm_CreditCard_0_CardCSV')
				);

			for(var f=0;f<fieldIdsNovalnet.length;f++){
				if($('#'+fieldIdsNovalnet[f][1]).val()==""){
					arrErrors.push(fieldIdsNovalnet[f][0]);
					$('#'+fieldIdsNovalnet[f][1]).addClass("error");
					err  = true;
				}
			}
			break;
		case 1:
			paymentPage = "app|prepare_booking_ogone";
			var fieldIdsOgone = new Array(
				new Array('Inhaber der AirPlus Karte','FQSCompany_PaymentForm_Airplus_0_CardHolderName'),
				new Array('Nummer der AirPlus Karte','FQSCompany_PaymentForm_Airplus_0_CardNumber'),
				new Array('Sicherheitscode der AirPlus Karte','FQSCompany_PaymentForm_Airplus_0_CardCSV')
				);

			for(var f=0;f<fieldIdsOgone.length;f++){
				if($('#'+fieldIdsOgone[f][1]).val()==""){
					arrErrors.push(fieldIdsOgone[f][0]);
					$('#'+fieldIdsOgone[f][1]).addClass("error");
					err  = true;
				}
			}
			break;
		case 2:
			paymentPage = "app|prepare_booking_elv";
			var fieldIdsELV = new Array(
				new Array('Kontoinhaber','FQSCompany_PaymentForm_EC_0_OwnerName'),
				new Array('Kontonummer','FQSCompany_PaymentForm_EC_0_Number'),
				new Array('Bankleitzahl','FQSCompany_PaymentForm_EC_0_BankId')
				);

			for(var f=0;f<fieldIdsELV.length;f++){
				if($('#'+fieldIdsELV[f][1]).val()==""){
					arrErrors.push(fieldIdsELV[f][0]);
					$('#'+fieldIdsELV[f][1]).addClass("error");
					err  = true;
				}
			}
			break;
		default:
			err = true;
			arrErrors.push('Bitte w&auml;hlen Sie eine Zahlungsmethode aus und geben Sie die entsprechenden Daten ein.');
			break;
	}
	
	/*
	if($("#rail"))
	{
		if($("#rail:checked").length == 0)
		{
			err  = true;
			$("#divcheckboxrail").addClass('error');
		}else{$("#divcheckboxrail").removeClass('error');}
	}	
	*/
	if(false === err)
	{
		//global_target_container = 'button_book_container';
		//$("#"+global_target_container).html('');
		$("#message").html('');
		var form_data = $("#form_results").serialize()+"&"+$("#form_booking_details").serialize();
		data = {
		page: paymentPage,
		FQS_serialized : form_data
		};
		
		bookingSent = true;
		
		switch(activePayment){

			case 0, "": //novalnet
				$.post('/index.php', data, BOOKING_callback_step_one, "text");
				break;
			case 1: //ogone
				$.post('/index.php', data, BOOKING_callback_ogone, "text");
				break;
			case 2: //elv
				$.post('/index.php', data, BOOKING_callback_step_one, "text");
				break;
		}
			
	}
	else{ //errors occurred during check
		$('.fancybookerror').html('');
		for(var i=1; i<arrErrors.length; i++){
			$('.fancybookerror').append(arrErrors[i]+"<br/>");
		}
		bookingSent = false;
		$('a#displayCheckResult').click();
	}
	
}//if bookingSent
	
});


$('#button_forgot_password').click(function(event){

			$("#forgot_password").bind("submit", function() { return false; })
			
			$("#message").html('');
			var form_data = $("#forgot_password").serialize();
			
			data = {
			page:"fqs|get_new_password",
			FQS_serialized : form_data
			};
			$.post('/index.php', data, FORGOT_PASSWORD_callback, "text");

});
 function FORGOT_PASSWORD_callback(data)
 {
	var split_data = data.split(':');

	if(split_data[0] == 'error')
	{
		$("#message").prepend("<div class='error'>"+split_data[1]+"</div>");
		$("#message").fadeIn("slow");
	}
	else
	{	
		$("#message").prepend("<div class='success'>"+split_data[1]+"</div>");
		$("#message").fadeIn("slow");
	}
	
 }




  
 $("#FQSCustomer_Email_2_EmailAddress").blur(function(event){
	
	if(this.value == '')
	{
		$("#FQSCustomer_Email_2_EmailAddress ~ img").remove();	
	}
	else
	{
		$("#FQSCustomer_Email_2_EmailAddress ~ img").remove();
		$("#FQSCustomer_Email_2_EmailAddress").after(error_icon);

		$("#FQSCustomer_Email_2_EmailAddress").addClass("error");
	}


   event.preventDefault();
 });

	if($('#slideBonus').cycle)
	{
		$('#slideBonus').cycle({ 
			fx:     'fade', 
			speed:  'fast', 
			timeout: 0, 
			next:   '#next2', 
			prev:   '#prev2' 
		});
	};
	if($('#slideBonus1').cycle)
	{
		$('#slideBonus1').cycle();
	};
	if($('#slideBonus2').cycle)
	{
		$('#slideBonus2').cycle();
	};
	
 
 });
