/* ********************************************* */
/* #inc/effective-dimensions.html - stark slider */
/* ********************************************* */

function mapShowStrongChart(divnum){
    showStrongChart(parseInt(divnum));
    initCufon();
}

function showStrongChart(divnum) {						
    $('.strong_chart').removeClass('active');
    $('.strong_story').css('display', 'none');						
    if (divnum == 1) {
        $('span.start_strong').css('display', 'block');
        $('li.start_strong').addClass('active');	
    } else if (divnum == 2) {
        $('span.get_strong').css('display', 'block');
        $('li.get_strong').addClass('active');	
    } else {
        $('span.stay_strong').css('display', 'block');
        $('li.stay_strong').addClass('active');	
    }	
  
}		 

function showMore(divnum) {		
    var speed = jQuery.browser.msie && jQuery.browser.version < 9 ? 0 : 500;
    $('div.info-blocks').find('div.moreSpan:eq('+ divnum +')').fadeOut(speed, function() {
        $('div.info-blocks').find('div.moreSpan:eq('+ (divnum + 1) +')').fadeIn(speed);
    });
}	 

function initDatatransForm(){
    // Validation CCPayment
    var container = $('#planccpayment td.errorcontainer');
	
    $("#datatransform").validate({
        debug: false,
        errorContainer: container,
        errorLabelContainer: $("ol", container),
        errorClass: 'hasError',
        wrapper: 'li',				
        rules: {
            cardno: {
                required: true,				
                minlength: 16,
                maxlength: 16,
                number: true
            },							
            cvv: {
                required: true,				
                minlength: 3,
                number: true
            }	
        },		
        highlight: function(element, errorClass) {
            $(element).addClass(errorClass);
            $(element).parents('td:first').prev().addClass(errorClass);
        },
        unhighlight: function(element, errorClass) {
            $(element).removeClass(errorClass);
            $(element).parents('td:first').prev().removeClass(errorClass);		
        }
    });	
};


function initPaymentForm() {	
    $('span.tree-expander').click(function() {
        if($(this).parent('li').find('ul:first').css('display') == 'none') {
            $(this).html('&ndash;');
            $(this).parent('li').find('ul:first').slideDown('fast');
        } else {
            $(this).html('+');
            $(this).parent('li').find('ul:first').slideUp('fast');	
        }
    });

    $('input.tree-expander').click(function() {
        if ($(this).parent('li').find('ul:first').css('display') == 'none') {
            $(this).prev('span').click();
        }
    });

    $('input.payment_type').click(function() {
        // die nummer der einzahlungsscheine nie anzeigen.
        if ($(this).hasClass('show_slips')) {
            $('div.slips_amount').slideUp('fast');
            $('div.slips_amount').attr('value', 1);					
        }
        
        if ($(this).hasClass('show_creditcard')) {
            $('div.creditcard_mode').slideDown('fast');
        } else {
            $('div.creditcard_mode').slideUp('fast');
        }        
    });			
	
        
    // bei einer anonymen spende, alle werte reseten oder andersherum
    $('input.anon').click(function() {		
        if ($(this).hasClass('no_private_data')) {			
            $("input[name=firstname]").attr('value', '');
            $("input[name=lastname]").attr('value', '');
            $("input[name=street]").attr('value', '');
            $("input[name=zip]").attr('value', '');
            $("input[name=city]").attr('value', '');			
            $("input[name=email]").attr('value', '');
            $("input[name=email2]").attr('value', '');		
            $(".disclaimer").attr('checked', '');			
            $('.private_data').slideDown('fast');								
        } else {		
            $('.private_data').slideUp('fast', function() {
                $("input[name=firstname]").attr('value', 'anonym');
                $("input[name=lastname]").attr('value', 'anonym');
                $("input[name=street]").attr('value', 'anonym');
                $("input[name=zip]").attr('value', 'anonym');
                $("input[name=city]").attr('value', 'anonym');
                $("input[name=birthdate]").attr('value', '');
                $("input[name=email]").attr('value', 'anonym@anonym.ch');
                $("input[name=email2]").attr('value', 'anonym@anonym.ch');		
                $(".disclaimer").attr('checked', 'checked');			
            });												
        }
    });		
	
    /**
     *  Art  Fördermitgliedschaft / Spende  wechseln
     */
    $('input.chooseType').click(function() {	
        $('.biaagform').attr('class', 'biaagform paymentform '+$('input.chooseType:checked').val());
        // Den aktuellen Betrag setzen
        initAmount();
        // Die erste Zahlungsmethode auswaehlen
        $('.amountSelector:visible:eq(0)').click();
        $('.payment_type:visible:eq(0)').click();
    });
    // Fördermitgliedschaft als default setzen
    $('input.chooseType[value=fundMem]').click();
	
    $('input.amountSelector').click(function() {
        if ($(this).hasClass('show_other_amount')) {
            $('div.other_pay_amount').slideDown('fast');
        } else {
            $('div.other_pay_amount').slideUp('fast');
        }
    });	

    
    
    
    function initAmount(){
        var amountsetter = $('input.amountSelector[amount]:checked:visible');
        setAmount(amountsetter.attr('amount'))
    }
    
    function setAmount(amount){
        $('input[name=amount]').val(amount); 
    }
	
    // whoher kennen sie plan
    $('option.source').click(function() {
        if ($(this).hasClass('show_other_source')) {
            $('div.other_source').slideDown('fast');
        } else {
            $('div.other_source').slideUp('fast');
        }
    });			
	
    // fuer radio buttons mit amount selektor benoetigt
    $('.biaagform input[name=paymentIteration][amount], .amountSelector[amount]').change(function(){
        setAmount($(this).attr('amount'))
    })

    // Validation Kinderpatenschaften
    var container = $('td.errorcontainer');

    $(".paymentform").validate({
        debug: false,
        errorContainer: container,
        errorLabelContainer: $("ol", container),
        errorClass: 'hasError',
        wrapper: 'li',				
        rules: {
            sponsoredChildCountry:{
                required: true						
            },
            gender: {
                required: true						
            },		
            country: {
                required: true						
            },						
            amount: {
                required: true	,
                min: 20
            },
            paymentType: {
                required: true
            },	
            title: {
                required: true						
            },					
            firstname: {
                required: true,
                minlength: 3
            },
            lastname: {
                required: true,
                minlength: 3
            },					
            street: {
                required: true,
                minlength: 3
            },
            zip: {
                required: true,
                minlength: 3
            },
            city: {
                required: true,
                minlength: 3
            },	
            birthdate: {
                required: false,
                dateDE: true
            },										
            email: {
                required: true,
                minlength: 3,
                email: true
            },	
            email2: {
                required: true,
                email: true,
                equalTo: "#email"
            },
            disclaimer: {
                required: true
            }	
        },
        highlight: function(element, errorClass) {
            $(element).addClass(errorClass);
            $(element).parents('td:first').prev().addClass(errorClass);
        },
        unhighlight: function(element, errorClass) {
            $(element).removeClass(errorClass);
            $(element).parents('td:first').prev().removeClass(errorClass);		
        },
        submitHandler: function(form) {		
            $(form).find('input[name=submitted]').val(1);
            $(form).attr({
                method: "post",
                action: "de/forms/mode-payment.php"
            }).ajaxSubmit({
                error: function(html){
                    $('.content').html(html);
                },
                success: function(html){
                    $('.content').html(html);
                }
            });		
        }
    });
}

function restoreLogoLink() {
    // reset logo link after redirect
    if ($('a.logolink').length > 0) {
        $('a.logolink').attr('rel', '');
        $('a.logolink').removeClass('activeted');
        $('a.logolink').addClass('logo-link');
        $('a.logolink').attr('href', $('a.logolink').attr('href').replace('projects', 'index'));
        initHeaderLinks();
    }
}

function getHash() {
    var page = window.location.hash;
    if(page){
        return page.replace('#', '');
    }
    return null;
}


function guTrackPageVisit(page){
    if(page){
        page = cleanHash(page);
        if(typeof _gaq != "undefined"){
            _gaq.push(['_trackPageview', page]);
        }
    }
}

function cleanHash  (page) {
    return page.replace('#', '');
}



if (typeof console == "undefined") var console = {
    log: function() {}
};
else if (typeof console.log == "undefined") console.log = function() {};                    



function trackEcommerce(orderID , articleID , articleName ,articleVariation, amount, city, country ){
    
    if(typeof _gaq != "undefined"){
        console.log("_trackEcommerce(orderID: " +  orderID  + " articleID: " + articleID, 
            " articleName: "+articleName +" articleVariation: " + articleVariation +" amount: " +
            amount +" city: " + city + " country: " + country+")");
        
        _gaq.push(['_addTrans',
            orderID,           // order ID - required
            'www.maedchenplan.ch', // affiliation or store name
            amount,          // total - required
            0,           // tax
            0,          // shipping
            city,       // city
            '',     // state or province
            country             // country
            ]);
        _gaq.push(['_addItem',
            orderID,           // order ID - necessary to associate item with transaction
            articleID,           // SKU/code - required
            articleName,        // product name
            articleVariation,   // category or variation
            amount,          // unit price - required
            '1'               // quantity - required
            ]);
        _gaq.push(['_trackTrans']);
    }
}



function tf(){
    var form = $('form:visible');
    
    form.find('select[name=title]').val('m');
    form.find('input[name=firstname]').val('Oliver');
    form.find('input[name=lastname]').val('Strässer');
    form.find('input[name=company]').val('getunik ag');
    form.find('input[name=street]').val('Hardturmstrasse 101');
    form.find('input[name=zip]').val('8050');
    form.find('input[name=city]').val('Zürich');
    form.find('input[name=phone]').val('(0)44 388 55 88');
    form.find('input[name=birthdate]').val('06.03.1963');
    form.find('input[name=email], input[name=email2] ').val('osr@getunik.com');
    form.find('input[name=disclaimer]').attr('checked', 'checked');
    form.find('#cardno').val('4242424242424242');
    form.find('select[name=expm]').val('12');
    form.find('select[name=expy]').val('2015');
    form.find('select[name=cvv]').val('123');
}


function initSupportForm(){
    Cufon.replace('.support-form-title2 h2', {
        fontFamily: 'PlanStorytellingClean', 
        hover: true
    });
    Cufon.replace('.support-form-button h3', {
        fontFamily: 'PlanStorytellingClean', 
        hover: false
    });  
    
    var inactive = 'inactive';
    var buttons = $('.support-form-button');
    buttons.click(function(){
        var button = $(this);
        button.find('a').click();
    })
    var fadeTime = 500;
    buttons.mouseenter(function(){
        var button = $(this);
        if(button.hasClass(inactive) || $('.support-form-button.'+inactive).size() == 0 ){
            buttons.addClass(inactive);
            button.removeClass(inactive);
            var imgNew = $('.support-box-holder img.'+button.attr('rel'));
            var imgOld = $('.support-box-holder img:visible:not(.'+button.attr('rel')+')');
            if(imgNew.size()){
                imgNew.hide().fadeIn(fadeTime);
                imgOld.show().fadeOut(fadeTime, function(){
                    imgNew.show();
                });
            }
        }
    })
}
