$(document).ready(function(){	
	
	$(".datepicker").datepicker();
	$('.datepicker').datepicker('option', {dateFormat: 'yy-mm-dd'}); 
	
	$("#datepicker2").datepicker();
	$("#datepicker3").datepicker();
	$("#datepicker4").datepicker();
	
	$('.invite_input').attr('disabled',true);
	$('.invite_label').css('font-weight','normal');
	$('#invite_check').change(function(){
		if ( $('#invite_check').attr('checked') ) {
			$('.invite_input').attr('disabled',false);
			$('.invite_label').css('font-weight','bold');
		} else {
			$('.invite_input').attr('disabled',true);
			$('.invite_label').css('font-weight','normal');
		}
	});
	
	$('.make_delete').click(function(){
		if ( ! confirm( 'Подтвердить удаление?' ) ) 
			return false;
		return true;
	});
	
	/* For payment method choise */
	$('.rl_person_type').change(function(){
		renewPaymentMethods();
	});
	$('.rl_currency').change(function(){
		renewPaymentMethods();
	});
});

function checkAllCheckboxes( class_name ) {
	$('.' + class_name ).attr('checked', true);
}

function uncheckAllCheckboxes( class_name ) {
	$('.' + class_name ).attr('checked', false);
}

function showHideDiv( id_name ) {
	if ( $('#' + id_name ).css('display') == 'none' ) {
		$('#' + id_name ).slideDown();
	} else {
		$('#' + id_name ).slideUp();
	}
}

function renewPaymentMethods() {
	person_type = $('.rl_person_type:checked').val();
	if ( 0 == person_type ){
		$('#currency_tr').show();
		$('#jur_data').hide();
	} else {
		$('#currency_tr').hide();
		$('#jur_data').show();
	}
	
	person_type = $('.rl_person_type:checked').val();
	currency = $('.rl_currency:checked').val();
	pm_div = $('#payment_methods');
	pm_div.empty();
	
	j = 0;
	check = false;
	k = -1;
	for ( i = 0; i < payment_methods.length; i ++ ) {
		pm = payment_methods[i];
		if ( pm['person_type'] == person_type ) {
			if ( 0 == person_type ) {
				if ( pm['currency'] != currency ) {
					continue;
				}
			}
			checked = '';
			if (  choosen_payment_method != '') {
				if ( choosen_payment_method == pm['id'] ) {
					checked = ' checked';
					check = true;
				}
			}
			if ( -1 == k ) {
				k = i;
			}
			pm_div.append( '<input id="rl_payment_method_'+i+'" type="radio" name="payment_method" value="'+pm['id']+'"'+checked+' /><label for="rl_payment_method_'+i+'">'+pm['name']+'</label></br>'  );
			j ++;
		}
	}
	if ( ! check ) {
		$('#rl_payment_method_' + k).attr('checked', true);
	}
}
