function changeAdress(dir, this_el)
{
    if(dir == false){
        jQuery(this_el).parent().parent().parent().parent().parent().parent().parent().find(".firm_hide").slideUp();
    jQuery(".packstation").find("label").html("Straße<em>*</em>");
    jQuery(".postnr").find("label").html("Addresszusatz").parent().parent().find('input').removeClass('required-entry');
        return false;
    }
    
    jQuery(this_el).parent().parent().parent().parent().parent().parent().parent().find(".firm_hide").slideDown(500);
    jQuery(".packstation").find("label").html("Straße<em>*</em>");
    jQuery(".postnr").find("label").html("Addresszusatz").parent().parent().find('input').removeClass('required-entry');
    
}

function adressbuch(this_input){
    
    if(jQuery(this_input).hasClass('checked'))
    {
        jQuery(this_input).parent().parent().find(".msg_address").animate({'height' : 'toggle'}, 500);
        jQuery(this_input).removeClass('checked');
        jQuery(".postnr").find("label").html("Addresszusatz").parent().parent().find('input').removeClass('required-entry');
    }else{
        jQuery(this_input).parent().parent().find(".msg_address").animate({'height' : 'toggle'}, 500);
        jQuery(this_input).addClass('checked');
        jQuery(".postnr").find("label").html("Addresszusatz").parent().parent().find('input').removeClass('required-entry');
    }

    jQuery(".packstation").find("label").html("Straße<em>*</em>");
    jQuery(".postnr").find("label").html("Addresszusatz").parent().parent().find('input').removeClass('required-entry');
    
}

function changeLabels(this_el)
{
    jQuery(this_el).parent().parent().parent().parent().parent().parent().parent().find(".firm_hide").slideUp();
    jQuery(".postnr").find("label").html("Postnummer<em>*</em>").parent().parent().find('input').addClass('required-entry');;
    jQuery(".packstation").find("label").html("Packstation<em>*</em>");
         
}


function renewForm(this_class){
    //shippingMethod.save();
    if (typeof shippingMethod == 'undefined')
    {
        extForm();
    } else {
        shippingMethod.save();
        setTimeout('extForm()', 1000);
        setTimeout('extForm()', 2000);
        setTimeout('extForm()', 3000);
        setTimeout('extForm()', 5000);
    }
    
   
}

function showCurHid(this_el, dir){
    if(dir == true){
        jQuery(this_el).parent().parent().find('.curHid').slideDown(500);
        jQuery(".itmCheckout_delivery").val(jQuery("#year").val() + '-' + jQuery("#month").val() + '-' + jQuery("#day").val());
    }
    else{
       jQuery(this_el).parent().parent().parent().find('.curHid').slideUp(500);
       jQuery(".itmCheckout_delivery").val(year_o + "-" + month_o + "-" + day_o);
    }
}

function onFocusValue(this_el, def_v){
    if(jQuery(this_el).val() == def_v)
    {
       jQuery(this_el).val('');
       jQuery(this_el).css({'color' : '#5C1A12'});
    }
}

function onBlurValue(this_el, def_v){
    if(jQuery(this_el).val() == ''){
       jQuery(this_el).val(def_v);
       jQuery(this_el).css({'color' : '#ccc'});
    }
}

function grussKarteBlur(this_el){
    if(jQuery(this_el).val() == ''){
        jQuery(this_el).removeClass('valueNotNull');
    }
}

function grussKarteFocus(this_el){
    jQuery(this_el).addClass('valueNotNull');
}


jQuery(document).ready(function(){
    
    /*if(jQuery(".insert").length > 0 && jQuery(".inserthere").length > 0)
    {
        jQuery(".insert").keyup(function(){
            jQuery(".inserthere").val(jQuery(this).val());
        });
    }*/
    
    if(jQuery("#checkoutSteps").length > 0)
    {
        setInterval('extForm()', 1000);
    }
        
   var original = false;
    
   if(jQuery("#opc-login").hasClass('active'))
   {
       jQuery("#checkout-progress-wrapper").hide();
   }
   
   
   if(jQuery('.my-account').length > 0){
       
   }
   
   if(jQuery(".styleForm").length > 0)
   {
        
        // Checkout Payment
        
        if(jQuery('#opc-payment').length > 0){
            jQuery(".changeDate").live('keyup', function(){
                jQuery(".itmCheckout_delivery").val(jQuery("#year").val() + '-' + jQuery("#month").val() + '-' + jQuery("#day").val());
            });

            jQuery("#p_method_bemerkung").live('keyup', function(){
                jQuery(".itmCheckout_bemerkung").val(jQuery(this).val());
            });

            jQuery('#gift-message-whole-message').live('keyup', function(){
                jQuery(".itmCheckout_card").val(jQuery(this).val());
            });

            jQuery('.payment_first_').live('click', function(){
                if(jQuery(this).hasClass('value_1000')){
                   jQuery(".itmCheckout_firstpackage").val('welcome');
                }else if(jQuery(this).hasClass('value_1001')){
                   jQuery(".itmCheckout_firstpackage").val('collection'); 
                }else{
                    //alert('STOP IT!');
                }
            });

            jQuery('.payment_forward_').live('click', function(){
                if(jQuery(this).hasClass('value_year')){
                    jQuery('.itmCheckout_payment').val('1000');
                }else if(jQuery(this).hasClass('value_ship')){
                    jQuery('.itmCheckout_payment').val('1001');
                }else{
                    //alert('STOP IT !');
                }
            });
        }
        
        // Forms auswählen 
        jQuery('.styleForm').each(function()
        {
            if(jQuery(this).hasClass('original'))
            {
                original = true;    
            }
            
            // Number of items
            var count_select = jQuery(this).find('select').length;
            var count_input = jQuery(this).find('input').length;
            var count_radio = jQuery(this).find('input[type=radio]').length;
            var count_checkbox = jQuery(this).find('input[type=checkbox]').length;
                    
            //Selectbox anpassen
            if(count_select > 100)
            {
                
                jQuery(this).find('select').each(function(){    
                    if(jQuery(this).hasClass('exception') == false){
                            
                        jQuery(this).hide();
                        var counter = 0;
                        
                        jQuery(this).wrap('<div class="select_box_js"></div>');
                        jQuery(this).parent().append('<div class="wrap_top"><div class="select_border_left_top"></div><div class="select_border_mid_top"></div><div class="select_border_right_top"></div></div><div class="wrap_mid"><div class="select_mid"><div class="border_mid_left"><div class="options"></div></div></div></div><div class="wrap_bottom"><div class="select_border_left"></div><div class="select_border_mid"></div><div class="select_border_right"></div></div>');
                        jQuery(this).parent().find('option').each(function()
                        {
                            if(counter == 0){
                                jQuery(this).parent().parent().find(".options").append('<div class="item first_opt" title="0">' + jQuery(this).html() + '</div><div class="break"></div>');    
                            }else{
                                jQuery(this).parent().parent().find(".options").append('<div class="item" title="' + jQuery(this).attr('value') + '">' + jQuery(this).html() + '</div>');
                            }
                            
                            counter++;
                        });
                        
                        jQuery(this).parent().parent().find('.item').click(function(){
                            
                            var this_val = jQuery(this).attr('title');
                            var this_html = jQuery(this).html();
                            
                            jQuery(this).parent().find('.first_opt').attr('title', this_val);
                            jQuery(this).parent().find('.first_opt').html(this_html); 
                        });
                        
                        jQuery(this).parent().click(function()
                        {
                            jQuery('.options').css({'z-index' : 100});
                            
                            jQuery(this).find('.options').css({'z-index' : 200}).animate({'height' : (counter * 20)}); 
                            
                        });
                        
                        jQuery(this).parent().css({'position' : 'absolute'});
                        
                        jQuery(this).parent().hover(function(){}, function(){
                             jQuery(".options").animate({'height' : '0px'}).css({'z-index' : 100});
                        });
                    }
                });                
            }
            
            //input boxen anpassen
            if(count_input > 0)
            {        
                jQuery(this).find('input').each(function()
                {
                    if(jQuery(this).hasClass('exception') == false && jQuery(this).css('display') != 'none'){
                        if(jQuery(this).attr('type') == 'text' || jQuery(this).attr('type') == 'password')
                        {
                            var this_id = jQuery(this).attr('id');
                            var this_width = jQuery(this).width();
                            
                            if(original == true)
                            {
                                this_width = this_width - 40;
                            }
                            
                            jQuery(this).wrap('<div class="input_c" style="width:' + this_width + 'px"></div>');
                            jQuery(this).parent().wrap('<div class="round_input"></div>');    
                            jQuery(this).parent().parent().prepend('<div class="round_left" />');
                            jQuery(this).parent().parent().append('<div class="round_right" />');
                            
                            if(original == true)
                            {
                                jQuery(this).parent().parent().find('input').css({'width' : this_width});
                            }                
                        } 
                    }   
                });
            }
            
            //Radio Buttons
            if(count_radio > 0){
                jQuery(this).find('input[type=radio]').each(function(){
                     if(jQuery(this).hasClass('exception') == false && jQuery(this).css('display') != 'none')
                     {
                        var this_name = jQuery(this).attr('name').replace("[", "_");
                            this_name = this_name.replace("]", "_");
                            
                        var this_value = jQuery(this).attr('value');
                        
                        if(jQuery(this).attr('onchange') != '' && typeof jQuery(this).attr('onchange') != undefined)
                        {
                            var this_onchange = jQuery(this).attr('onchange');   
                        }
                       
                        jQuery(this).wrap('<div class="round_radio"></div>');
                        jQuery(this).parent().append('<div class="' + this_name + ' ' + 'value_' + this_value + ' round_radio_input">&nbsp;</div>');
                        
                        jQuery(this).addClass('value_' + this_value);
                        
                        
                        if(jQuery(this).attr('checked') == 'checked')
                        {
                            jQuery(this).parent().find('.round_radio_input').addClass('checked');
                        }else{
                            jQuery(this).parent().find(".round_radio_input").removeClass('checked');
                        }
                        
                        if(this_onchange != '' && typeof this_onchange != undefined)                        
                        {
                            jQuery(this).parent().find('.round_radio_input').attr('onclick', this_onchange);
                        }         
                        
                        jQuery(this).hide();
                        
                        jQuery(this).parent().find('.round_radio_input').click(function(){
                            // Input
                            jQuery("div." + this_name).parent().find('input').removeAttr('checked');
                            jQuery(this).parent().find('input').attr('checked', 'checked');
                            
                            // div
                            jQuery("div." + this_name).removeClass('checked');
                            jQuery(this).addClass('checked');                              
                        });                                 
                     }
                });     
            } 
            
            // Checkboxen
            if(count_checkbox > 0){
                jQuery(this).find('input[type=checkbox]').each(function()
                {
                    jQuery(this).wrap('<div class="round_checkbox"></div>');
                    jQuery(this).parent().append('<div class="round_checkbox_input"></div>');
                    jQuery(this).hide()
                    
                    jQuery(this).parent().find('.round_checkbox_input').click(function(){
                        if(jQuery(this).hasClass('checked'))
                        {
                            jQuery(this).removeClass('checked');
                            jQuery(this).parent().find('input').attr('checked', false);
                            jQuery(this).parent().find('input').change();
                            jQuery(this).parent().find('input').removeClass('checked');
                        }else
                        {
                            jQuery(this).addClass('checked');
                            jQuery(this).parent().find('input').attr('checked', true);
                            jQuery(this).parent().find('input').change();
                            jQuery(this).parent().find('input').addClass('checked');
                        }
                    });   
                    
                    if(jQuery(this).attr("checked") == "checked" || jQuery(this).checked == true && jQuery(this).hasClass("checked") == false)
                    {
                        jQuery(this).parent().find(".round_checkbox_input").addClass("checked");
                        jQuery(this).parent().parent().find(".msg_address").animate({'height' : 'toggle'});
                    }

                });
            }
            
            jQuery('label').attr('for','');
            
        });
    }
});

function extForm(){
    jQuery('#checkout-payment-method-load dt').each(function(){
        
        if(jQuery(this).find(".checked").length > 0)
        {
            return false;
        }
        
        if(jQuery(this).hasClass('original'))
        {
            original = true;
        }
        

        // Number of items
        var count_select = jQuery(this).find('select').length;
        var count_input = jQuery(this).find('input').length;        
        var count_radio = jQuery(this).find('input[type=radio]').length;
        var count_checkbox = jQuery(this).find('input[type=checkbox]').length;
        
        //Selectbox anpassen
        if(count_select > 100)
        {
            jQuery(this).find('select').each(function(){    
                if(jQuery(this).hasClass('exception') == false){

                    jQuery(this).hide();
                    var counter = 0;

                    jQuery(this).wrap('<div class="select_box_js"></div>');
                    jQuery(this).parent().append('<div class="wrap_top"><div class="select_border_left_top"></div><div class="select_border_mid_top"></div><div class="select_border_right_top"></div></div><div class="wrap_mid"><div class="select_mid"><div class="border_mid_left"><div class="options"></div></div></div></div><div class="wrap_bottom"><div class="select_border_left"></div><div class="select_border_mid"></div><div class="select_border_right"></div></div>');
                    jQuery(this).parent().find('option').each(function()
                    {
                        if(counter == 0){
                            jQuery(this).parent().parent().find(".options").append('<div class="item first_opt" title="0">' + jQuery(this).html() + '</div><div class="break"></div>');    
                        }else{
                            jQuery(this).parent().parent().find(".options").append('<div class="item" title="' + jQuery(this).attr('value') + '">' + jQuery(this).html() + '</div>');
                        }

                        counter++;
                    });

                    jQuery(this).parent().parent().find('.item').click(function(){

                        var this_val = jQuery(this).attr('title');
                        var this_html = jQuery(this).html();

                        jQuery(this).parent().find('.first_opt').attr('title', this_val);
                        jQuery(this).parent().find('.first_opt').html(this_html); 
                    });

                    jQuery(this).parent().click(function()
                    {
                        jQuery('.options').css({'z-index' : 100});

                        jQuery(this).find('.options').css({'z-index' : 200}).animate({'height' : (counter * 20)}); 

                    });

                    jQuery(this).parent().css({'position' : 'absolute'});

                    jQuery(this).parent().hover(function(){}, function(){
                         jQuery(".options").animate({'height' : '0px'}).css({'z-index' : 100});
                    });
                }
            });                
        }

        //input boxen anpassen
        if(count_input > 0)
        {
            jQuery(this).find('input').each(function()
            {
                if(jQuery(this).hasClass('exception') == false && jQuery(this).css('display') != 'none'){
                    if(jQuery(this).attr('type') == 'text' || jQuery(this).attr('type') == 'password')
                    {
                        var this_id = jQuery(this).attr('id');
                        var this_width = jQuery(this).width();

                        if(original == true)
                        {
                            this_width = this_width - 40;
                        }

                        jQuery(this).wrap('<div class="input_c" style="width:' + this_width + 'px"></div>');
                        jQuery(this).parent().wrap('<div class="round_input"></div>');    
                        jQuery(this).parent().parent().prepend('<div class="round_left" />');
                        jQuery(this).parent().parent().append('<div class="round_right" />');

                        if(original == true)
                        {
                            jQuery(this).parent().parent().find('input').css({'width' : this_width});
                        }                
                    } 
                }   
            });
        }

        //Radio Buttons
        if(count_radio > 0){
            jQuery(this).find('input[type=radio]').each(function(){
                 if(jQuery(this).hasClass('exception') == false && jQuery(this).css('display') != 'none')
                 {
                    var this_name = jQuery(this).attr('name').replace("[", "_");
                        this_name = this_name.replace("]", "_");

                    var this_value = jQuery(this).attr('value');

                    if(jQuery(this).attr('onchange') != '' && typeof jQuery(this).attr('onchange') != undefined)
                    {
                        var this_onchange = jQuery(this).attr('onchange');   
                    }

                    jQuery(this).wrap('<div class="round_radio"></div>');
                    jQuery(this).parent().append('<div class="' + this_name + ' ' + 'value_' + this_value + ' round_radio_input">&nbsp;</div>');

                    jQuery(this).addClass('value_' + this_value);


                    if(jQuery(this).attr('checked') == 'checked')
                    {
                        jQuery(this).parent().find('.round_radio_input').addClass('checked');
                    }else{
                        jQuery(this).parent().find(".round_radio_input").removeClass('checked');
                    }

                    if(this_onchange != '' && typeof this_onchange != undefined)                        
                    {
                        jQuery(this).parent().find('.round_radio_input').attr('onclick', this_onchange);
                    }         

                    jQuery(this).hide();

                    jQuery(this).parent().find('.round_radio_input').click(function(){
                        // Input
                        jQuery("div." + this_name).parent().find('input').removeAttr('checked');
                        jQuery(this).parent().find('input').attr('checked', 'checked');

                        // div
                        jQuery("div." + this_name).removeClass('checked');
                        jQuery(this).addClass('checked');                              
                    });                                 
                 }else
                     {
                        if(jQuery(".payment_method_").length > 0)
                         {
                            jQuery(".payment_method_").click(function(){
                                // Input
                                jQuery("div.payment_method_").parent().find('input').removeAttr('checked');
                                jQuery(this).parent().find('input').attr('checked', 'checked');

                                // div
                                jQuery("div.payment_method_").removeClass('checked');
                                jQuery(this).addClass('checked');                              
                            });                                       
                         }                           
                     }                                         
            });     
        } 

        // Checkboxen
        if(count_checkbox > 0){
            jQuery(this).find('input[type=checkbox]').each(function()
            {
                jQuery(this).wrap('<div class="round_checkbox"></div>');
                jQuery(this).parent().append('<div class="round_checkbox_input"></div>');
                jQuery(this).hide()

                jQuery(this).parent().find('.round_checkbox_input').click(function(){
                    if(jQuery(this).hasClass('checked'))
                    {
                        jQuery(this).removeClass('checked');
                        jQuery(this).parent().find('input').attr('checked', false);
                        jQuery(this).parent().find('input').change();
                        jQuery(this).parent().find('input').removeClass('checked');
                    }else
                    {
                        jQuery(this).addClass('checked');
                        jQuery(this).parent().find('input').attr('checked', true);
                        jQuery(this).parent().find('input').change();
                        jQuery(this).parent().find('input').addClass('checked');
                    }
                });   

                if(jQuery(this).attr("checked") == "checked" || jQuery(this).checked == true && jQuery(this).hasClass("checked") == false)
                {
                    jQuery(this).parent().find(".round_checkbox_input").addClass("checked");
                    jQuery(this).parent().parent().find(".msg_address").animate({'height' : 'toggle'});
                }

            });
        }

        jQuery('label').attr('for','');    
    });    
}
