HIDE_FLASH_TIMEOUT = 7000
function hideFlash() {
  $('.flash').fadeOut("slow");
}
function changeInvoiceCheckbox() {
	var value = $('select#customer_customer_type')[0].value;
	var check = ((value == 'C') && ($('input#customer_has_billing_address')[0].checked));
	$('#frm-account fieldset.adr2').css({display:(check)?'block':'none'});
}
function changeCustomerType() {
	var value = $('select#customer_customer_type')[0].value;
	$('#frm-account p.company_name').css({display:(value == 'C')?'block':'none'});
	$('#frm-account p.has_billing_address').css({display:(value == 'C')?'block':'none'});
	changeInvoiceCheckbox();
}
function changeSubscriptionId() {
	var value = $('select#subscribe_subscription_id').val();
	$.ajax({
		url: '/subscribe/period',
		data: 'subscription_id='+value, 
		success: function(request) { $('#subscription_detail').html(request); }
	});
}
function initAccount() {
    if ($('#frm-account').length == 0) return;
	$('select#customer_customer_type').bind( 'change', changeCustomerType );
	$('input#customer_has_billing_address').bind( 'change', changeInvoiceCheckbox );
	changeCustomerType();
}
function initUpgrade() {
    if ($('#frm-upgrade').length == 0) return;
	$('select#subscribe_subscription_id').bind( 'change keyup', changeSubscriptionId );
}
function initApplication() {
  setTimeout('hideFlash();',HIDE_FLASH_TIMEOUT);
  $('a.print').bind('click', function() {
	window.print();
	return false
  });
  initAccount();
  initUpgrade();
}
$(document).ready( initApplication );
