// JavaScript Document

$(document).ready(function(){

    $('#ToggleSiteMap').click(function() {
        if ( $(this).hasClass('active') )
        {
            $('#SiteMap').slideUp('normal', function() {
                $(this).removeClass('active');
                $('#ToggleSiteMap').removeClass('active');
            });
        }
        else
        {
            $('#SiteMap').slideDown('normal', function() {
                $(this).addClass('active');
                $('#ToggleSiteMap').addClass('active');
            });
        }
        return false;
    });

    $('a[href*="#CallBackBox"]').click(function() {
        if ( $(this).hasClass('active') )
        {
            $('#CallBackBox').slideUp('fast', function() {
                $('a[href*="#CallBackBox"]').removeClass('active');
            });
        }
        else
        {
            $('#CallBackBox').slideDown('fast', function() {
                $('a[href*="#CallBackBox"]').addClass('active');
            });
        }
        return false;
    });
    
    $('a[href*="#BrochureBox"]').click(function() {
        if ( $(this).hasClass('active') )
        {
            $('#BrochureBox').slideUp('fast', function() {
                $('a[href*="#BrochureBox"]').removeClass('active');
            });
        }
        else
        {
            $('#BrochureBox').slideDown('fast', function() {
                $('a[href*="#BrochureBox"]').addClass('active');
            });
        }
        return false;
    });
    
    $('a[href*="#PressBox"]').click(function() {
        if ( $(this).hasClass('active') )
        {
            $('#PressBox').slideUp('fast', function() {
                $('a[href*="#PressBox"]').removeClass('active');
            });
        }
        else
        {
            $('#PressBox').slideDown('fast', function() {
                $('a[href*="#PressBox"]').addClass('active');
            });
        }
        return false;
    });

    $('a[href*="#NewsSubsrcibeBox"]').click(function() {
        if ( $(this).hasClass('active') )
        {
            $('#NewsSubsrcibeBox').slideUp('fast', function() {
                $('a[href*="#NewsSubsrcibeBox"]').removeClass('active');
            });
        }
        else
        {
            $('#NewsSubsrcibeBox').slideDown('fast', function() {
                $('a[href*="#NewsSubsrcibeBox"]').addClass('active');
            });
        }
        return false;
    });
    
    
        $('a[href*="#BroOrderBox"]').click(function() {
        if ( $(this).hasClass('active') )
        {
            $('#BroOrderForm').slideUp('fast', function() {
                $('a[href*="#BroOrderBox"]').removeClass('active');
            });
        }
        else
        {
            now = new Date();
            $('#BroOrderForm').load('/miniforms/brochureorderform?' + now.getTime(), function() {
                    $('#BroOrderForm').slideDown('fast', function() {
                        $('a[href*="#BroOrderBox"]').addClass('active');
                })});
        }
        return false;
    });
    
    
    /*$('#MapBRDMap area').tooltip({
            track : true,
            top : -48, 
            left : -115,
            showURL: false, 
            extraClass: "map-tip"
    });*/


    $('.account-subscribe-content .ico-info').tooltip({
            track : true,
            top : -48, 
            left : 10,
            showURL: false, 
            showBody: " || ", 
            extraClass: "subscribe-tip"
    });

    $('.radio-float-box img[alt*="Info"]').tooltip({ 
        delay: 0, 
        showURL: false, 
        top : -170, 
        left : -77,
        bodyHandler: function() { 
            return $("<img/>").attr("src", $(this).attr('dynsrc')); 
        } 
    });

    NOA.fadeMenu.init();
    
    
    $('#XmasTeaser a.close').click(function() {
        
        $('#XmasTeaser').fadeOut(800);
        
        return false;
    });
    
    
    
    /* Capital Allocation */
    $('#fp-overview-allocation').click(function() {
        
        if($('#allocationLayer').is(':visible')) {
            return false;
        }
        
        $('#private').animate({height: 0}, 0);
        $('#business').animate({height: 0}, 0);
        $('#freeCapital').animate({height: 0}, 0);
        $('#allocationLayer span').hide(0);
        $('#business .arrow').hide(0);
        $('#allocationLayer h3').hide(0);
        
        alignLayer('#allocationLayer');
        
        $iFadeSpeed = (NOA.isIE()) ? 0 : 500;
        
        $('#allocationLayer').fadeIn($iFadeSpeed, function() {
            
            $iPrivateHeight = parseInt($('#private').attr('rel'));
            
            $iBusinessHeight = $('#business').attr('rel');
            $iFreeCapitalHeight = $('#freeCapital').attr('rel');
            
            $iSmallSize = $iBusinessHeight - $iFreeCapitalHeight;
            
            
            if($iSmallSize < 18) {
                
                $('#business>span').addClass('store-alternative');
                
            }
            
            $('#private').animate({height: $iPrivateHeight}, 850, 'easeOutBounce', function() {
                
                $('#private>span').css('margin-top', ($iPrivateHeight/2-10) + 'px');
                $('#business>span').css('margin-top', (($iBusinessHeight-$iFreeCapitalHeight)/2-8) + 'px');
                $('#freeCapital>span').css('padding-top', ($iFreeCapitalHeight/2-8) + 'px');
                
                $('#allocationLayer h3').show(0);
                
                $('#allocationLayer span').css('display', 'block');
                
                if($iSmallSize < 18) {
                    $('#business .arrow').css('display', 'block');
                }
                
            });
            
            $('#business').animate({height: $iBusinessHeight}, 850, 'easeOutBounce');
            $('#freeCapital').animate({height: $iFreeCapitalHeight}, 850, 'easeOutBounce');
            
        });
        
        
        return false;
        
    });
    
    $('#allocationLayer .close').click(function() {
        
        $('#allocationLayer').hide();
    
        return false;
    });
    
    
    
    /* Capital Sum Src */
    $('#fp-overview-capital').click(function() {
        
        $('#csSum, #csRegion, #csPlanet, #csLeben, #csKultur').css('height', 0);
        
        alignLayer('#capitalSum');
        
        $iFadeSpeed = (NOA.isIE()) ? 0 : 500;
        
        $('#capitalSum').fadeIn($iFadeSpeed, function() {
            
            $('#csSum, #csRegion, #csPlanet, #csLeben, #csKultur').css('height', 0);
            
            $iRegion = $('#csRegion').attr('rel');
            $iPlanet = $('#csPlanet').attr('rel');
            $iLeben = $('#csLeben').attr('rel');
            $iKultur = $('#csKultur').attr('rel');
            
            /* Capital All over */
            $('#csSum').animate({height: 162}, 250, function() {
                
                $('#csRegion').animate({height: $iRegion}, 250, function() {
                
                    $('#csPlanet').animate({height: $iPlanet}, 250, function() {
                        
                        $('#csLeben').animate({height: $iLeben}, 250, function() {
                            
                            $('#csKultur').animate({height: $iKultur}, 250, function() {
                                
                                $('#capitalSum h3').fadeIn($iFadeSpeed);
                
                            });
                            
                        });
                
                    });
                    
                });
                
            });
            
            
        });
        
        return false;
    
        
    });
    
    $('#capitalSum .close').click(function() {
        
        $('#capitalSum').hide();
        $('#capitalSum h3').hide();
    
        return false;
    });
    
    
    
    
    /* Region */
    $('#fp-region').click(function() {
        
        $('#fpLayerRegion .region-row .region-bar').css('width', 0);
        
        alignLayer('#fpLayerRegion');
        
        $iFadeSpeed = (NOA.isIE()) ? 0 : 500;
        
        $('#fpLayerRegion').fadeIn($iFadeSpeed, function() {
            
            $('#fpLayerRegion .region-row .region-bar').each(function(i,e) {
                
                $iWidth = $(this).attr('rel');
                
                $(this).animate({width: $iWidth}, 500);
                
            });
            
            $('#fpLayerRegion h3').fadeIn($iFadeSpeed);
            
        });
        
        
        return false;
        
        
    });
    
    $('#fpLayerRegion .close').click(function() {
        
        $('#fpLayerRegion').hide();
        $('#fpLayerRegion h3').hide();
    
        return false;
    });
    
    
    $('form#subscribe input[name="getnl"]').change(function() {
        
        if($(this).val() == 'optout') {
            $('form#subscribe').attr('action', 'http://redirect2.mailingwork.de/delete_abo.php');
        }
        else {
            $('form#subscribe').attr('action', 'http://redirect2.mailingwork.de/addabo.php');
        }
        
    });
    
    
    
});


$(window).load(function() {
    
    
});





NOA = {
    fadeMenu : {
        
        oActive : null,    
        init : function()
        {
            $('#MainNav > li').hover(function()
            {
                if (NOA.fadeMenu.oActive)
                {
                    NOA.fadeMenu.showHideMenu(0);
                    NOA.fadeMenu.oActive = null;
                }
                
                NOA.fadeMenu.showHideMenu(1,this);
            }, function()
            {
                NOA.fadeMenu.oActive = $(this);
                window.setTimeout( function(){ NOA.fadeMenu.checkMenu(); }, 250);
            });
        },
        
        showHideMenu : function(bShow,oObj)
        {
            if (bShow == 1 && oObj)
            {
                if (document.all && !window.opera)
                    $(oObj).find('div').slideDown('fast');
                else
                    $(oObj).find('div').fadeIn();
                    
                $(oObj).find('a').addClass('active');
            }
            else
            {
                if (document.all && !window.opera)
                    NOA.fadeMenu.oActive.find('div').slideUp('fast');
                else
                    NOA.fadeMenu.oActive.find('div').fadeOut('fast');
                NOA.fadeMenu.oActive.find('a').removeClass('active');
            }
        },
        
        checkMenu : function()
        {
            if (NOA.fadeMenu.oActive)
            {
                NOA.fadeMenu.showHideMenu(0);
            }
        }
    },
    
    isIE : function() {
        
        return (document.all && ! window.opera);
        
    }
};



function CurrencyFormat(num) {

    if (num == '')
        return '';

    num = num.toString().replace(/[^\d.,-]/g,'');
    if (num.substring(0,1) == '-') sign = '-';
    else sign = '';
    
    decimalsign = ',';
    if (num.substring(num.length - 2,num.length - 1) == '.' || num.substring(num.length - 3,num.length - 2) == '.')
        decimalsign = '.';
    
    if (decimalsign == ',') num = num.replace(/[^\d,]/g,'');
    if (decimalsign == ',') num = num.replace(/[,]/g,'.');
    num = num.replace(/[^\d.]/g,'');
    if(isNaN(num))
    num = "0";
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)                            
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+'.'+
    num.substring(num.length-(4*i+3));
    
    sreturn = (sign + num + ',' + cents);
   
    return sreturn;



}

function CurrencyUnformat(num) {
    num = num.toString().replace(/[.]/g,'');
    num = num.toString().replace(/[,]/g,'.');
    
    return num;

}

function PopupWin(sUrl) {
    var winPopUp = window.open(sUrl,'winPopUp','width=400,height=400,scrollbars=1,resizable=1');

}


function submitbrochureorderform() {
    
    haserror = 0;
    
    $("#brochureorderform *").removeClass("error");
    
    
    if($("#brochureorderform #gender").val() == '') {
        $("#brochureorderform #lblgender").addClass('error');
        haserror = 1;
    }
    if($("#brochureorderform #firstname").val() == '') {
        $("#brochureorderform #lblfirstname").addClass('error');
        haserror = 1;
    }
    if($("#brochureorderform #lastname").val() == '') {
        $("#brochureorderform #lbllastname").addClass('error');
        haserror = 1;
    }
    if($("#brochureorderform #address").val() == '') {
        $("#brochureorderform #lbladdress").addClass('error');
        haserror = 1;
    }
    if($("#brochureorderform #city").val() == '') {
        $("#brochureorderform #lblcity").addClass('error');
        haserror = 1;
    }
    if($("#brochureorderform #email").val() == '') {
        $("#brochureorderform #lblemail").addClass('error');
        haserror = 1;
    }
    if($("#brochureorderform #birthdateday").val() == ''
            || $("#brochureorderform #birthdatemonth").val() == ''
            || $("#brochureorderform #birthdateyear").val() == '') {
        $("#brochureorderform #lblbirthdate").addClass('error');
        haserror = 1;
    }
    
    now = new Date();
    
    if (! haserror) {
    
        $('#BroOrderForm').load(
            '/miniforms/brochureorderform?' + now.getTime(),
            {
                'gender' : $("#brochureorderform #gender").val(),
                'firstname' : $("#brochureorderform #firstname").val(),
                'lastname' : $("#brochureorderform #lastname").val(),
                'address' : $("#brochureorderform #address").val(),
                'city' : $("#brochureorderform #city").val(),
                'country' : $("#brochureorderform #country").val(),          
                'phone' : $("#brochureorderform #phone").val(),
                'email' : $("#brochureorderform #email").val(),
                'birthdate' : ($("#brochureorderform #birthdateday").val() + '.' +  $("#brochureorderform #birthdatemonth").val() + '.' +  $("#brochureorderform #birthdateyear").val()),
                'brochure' : $("#BroOrderFormBroName").text()
            
            }
        
        );
    
    }
    

}


function alignLayer($sIdent) {
    
    $($sIdent).css('left', '75px').css('top', '20px').css('z-index', 50);
    
}



var currentFormElem = null;
var showHideValue = function(obj,val)
{
    if (obj != currentFormElem)
    {
        currentFormElem = obj;
        if (obj.value == val)
            obj.value = '';
            
        obj.onblur = function()
        {
            showHideValue(obj,val);
        }
    }
    else
    {
        if (obj.value == '')
            obj.value = val;
        
        obj.onblur = null;
        
        currentFormElem = null;
    }
};
