// Timer zaehlt die Tage bis zum Monatsende

var countDown = function() {
	var jetzt = new Date();
	var next = new Date();
	// next date:
	if (next.getMonth()<11) { next.setMonth(next.getMonth()+1); }
	else { next.setMonth(0); next.setFullYear(next.getFullYear()+1) }
	next.setDate(1);
	next.setHours(0);
	next.setMinutes(0);
	next.setSeconds(0);
	next.setMilliseconds(0);
	// rest:
	var rest = next.getTime() - jetzt.getTime();
	rest = Math.floor(rest/1000);
	var restdays = Math.floor(rest/86400);
	rest %= 86400;
	var resthours = Math.floor(rest/3600);
	if (resthours < 10) resthours = "0" + resthours;
	rest %= 3600;
	var restminutes = Math.floor(rest/60);
	if (restminutes < 10) restminutes = "0" + restminutes;
	rest %= 60;
	var restseconds = rest;
	if (restseconds < 10) restseconds = "0" + restseconds;
	// time data:
	var monthname=['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'];
	var day = jetzt.getDate();
	if (day < 10) day = "0" + day;
	var month = jetzt.getMonth()+1;
	if (month < 10) month = "0" + month;
	var year = jetzt.getFullYear();
	var hour = jetzt.getHours();
	if (hour < 10) hour = "0" + hour;
	var minute = jetzt.getMinutes();
	if (minute < 10) minute = "0" + minute;
	var second = jetzt.getSeconds();
	if (second < 10) second = "0" + second;
	// output rest:
	if ($("countdown")) {
		$("countdown").innerHTML = 'Vite, il vous reste ' + restdays + ' jours plus ' + resthours + ':' + restminutes + ':' + restseconds;
	}
	if ($("date_time")) {
		
		$("date_time").innerHTML = day + ' ' + monthname[jetzt.getMonth()] + ', '+ hour+':'+minute+':'+second;
	}
	
	setTimeout("countDown()",1000);
}


function gen_numb(min, max){  
  return (Math.floor(Math.random() * (max - min)) + min);  
}


function init_payment_form(){
  if( $('#radio_bank').is(':checked')){
    switch_payment('bank');
  }
  else {
    switch_payment('card');
  }
}


function switch_payment( type ){
  var active   = $('#card_payment');
  var inactive = $('#bank_payment');
  if( "bank" == type ){
    // switch active and inactive
    var temp = active;
    active   = inactive;
    inactive = temp
  }
  active.show();
  inactive.hide();
}


/**
 * type: 'iban' or 'swift'
 * value: value of iban or swift
 */
// function bank_check( type ){
// 	var value;
// 	if( 'iban' == type ){
// 		value = $('iban_input').value;
// 	}
// 	else{
// 		value = $('swift_input').value;
// 	}
// 	var jsonRequest = new Request.JSON(
// 		{
// 			url: '/cgi-bin/backoffice/authorize_cc.pl',
// 			onSuccess: function(success){
// 				alert('success: ' + success[0]);
// 			}
// 		}
// 	).get(
// 		{
// 			'todo': 'json_check_bank_data',
// 			type: value
// 		}
// 	);
// }


