var invoice_active = false;
var invoice_different_language = false;

// Load when document finished loading
jQuery(document).ready(function (){
    klarna_invoiceReady();
});
	
function klarna_invoiceReady ()
{      
    var foundBox = false;
    currentMinHeight_invoice = jQuery('#klarna_box_invoice').height();	
	
    // Chosing the active language
    jQuery('#box_active_language').live('click', function () {
        jQuery('.klarna_box_top_flag_list').slideToggle('fast', function () {
            if (jQuery(this).is(':visible'))
            {
                jQuery('.klarna_box_top_flag').animate({
                    opacity: 1.0
                }, 'fast');
            }
            else {
                jQuery('.klarna_box_top_flag').animate({
                    opacity: 0.4
                }, 'fast');
            }
        });
    });   
	
    jQuery('.klarna_box_bottom_languageInfo').live('mousemove', function (e) {
        showBlueBaloon(e.pageX, e.pageY, jQuery(this).find('img').attr("alt"));
    });
	
    jQuery('.klarna_box_bottom_languageInfo').live('mouseout', function () {
        hideBlueBaloon();
    });

    if(typeof invoice_ITId != "undefined") {
        jQuery('input[name="'+invoice_ITId+'"]').live('change', function (){
            var val = jQuery(this).val();
			
            if (val == "private")
            {
                jQuery('#invoice_perOrg_title').text(lang_personNum);
                jQuery('#invoice_box_private').slideDown('fast');
                jQuery('#invoice_box_company').slideUp('fast');
            }
            else if (val == "company")
            {
                jQuery('#invoice_perOrg_title').text(lang_orgNum);
                jQuery('#invoice_box_company').slideDown('fast');
                jQuery('#invoice_box_private').slideUp('fast');
            }
        });
    }
    
    if(typeof global_countryCode != 'undefined'){
        if (global_countryCode == "de" || global_countryCode == "nl")
        {
            if(typeof select_bday != 'undefined' && typeof select_bmonth != 'undefined' && typeof select_byear != "undefined") {
                jQuery('[name="payment[klarna_invoice_dob_day]').val(select_bday);
                jQuery('[name="payment[klarna_invoice_dob_month]').val(select_bmonth);
                
                // Years box
                var date = new Date();
                for (i = date.getFullYear(); i >= 1900; i--) {
                    jQuery('<option/>').val(i).text(i).appendTo('#klarna_box_invoice .selectBox_year');
                }
                jQuery('[name="payment[klarna_invoice_dob_year]').val(select_byear);
                
            }            
        }        
    }

}

function resetListBox (listBox)
{
    listBox.find('li').each(function (){
        if (jQuery(this).attr("id") == "click")
        {
            jQuery(this).attr("id", "");
        }
		
        jQuery(this).find('div').find('img').remove();
    });
}
