function ToolChart()
{
    this.compare = new Array();
    this.typ = null;
    this.zeitraum = null;
    this.template = null;
    this.isin = null;
    this.currency = null;
    this.boersenplatz = null;

    this.setZeitraum = function(zeitraum)
    {
        this.zeitraum = zeitraum;
    }

    this.getZeitraum = function()
    {
        return this.zeitraum;
    }

    this.setChartTyp = function(typ)
    {
        this.typ = typ;
    }

    this.getChartTyp = function()
    {
        return this.typ;
    }

    this.setChartTemplate = function(template)
    {
        this.template = template;
    }

    this.getChartTemplate = function()
    {
        return this.template;
    }

    this.setCompare = function(isin)
    {
        this.compare.push(isin);
    }

    this.getCompare = function()
    {
        return this.compare;
    }

    this.setISIN = function(isin)
    {
        this.isin = isin;
    }

    this.getISIN = function()
    {
        return this.isin;
    }
    
    this.setCurrency = function(currency)
    {
        this.currency = currency;
    }

    this.getCurrency = function()
    {
        return this.currency;
    }
    
    this.setBoersenplatz = function(boersenplatz)
    {
        this.boersenplatz = boersenplatz;
    }

    this.getBoersenplatz = function()
    {
        return this.boersenplatz;
    }

    this.buildPost = function()
    {
        var url = '';

        if(this.typ != null)
        {
            url += 'typ='+this.getChartTyp();
        }

        if(this.zeitraum != null)
        {
            url += '&zeitraum='+this.getZeitraum();
        }

        if(this.template != null)
        {
            url += '&ChartTemplate='+this.getChartTemplate();
        }

        if(this.isin != null)
        {
            url += '&ISIN='+this.getISIN();
        }
        
        if(this.currency != null)
        {
            url += '&currency='+this.getCurrency();
        }
        
        if(this.boersenplatz != null)
        {
            url += '&stockId='+this.getBoersenplatz();
        }

        if(this.compare.length != 0)
        {
            for(key in this.compare)
            {
                url += '&compare[]='+this.compare[key];
            }
        }
        
        return url;
    }
}

chart = new Array();

$(function()
{
    $.each($('.Zeitraum'),function(key,val)
    {
        var integer = $(val).attr('id').replace(/\D+/,'');
        chart[integer] = new ToolChart();
        chart[integer].setZeitraum($(val).find('.active').find('a').text());
        //console.log(chart[integer].getZeitraum());
    }
    );
    $.each($('.ChartTyp'),function(key,val)
    {
        var integer = $(val).attr('id').replace(/\D+/,'');
        chart[integer].setChartTyp($(val).find('.active').find('a').text());

        var params = $(val).find('img').attr('class').split(',');

        for(para in params)
        {
            var el = params[para].toString();
            
            if(el.indexOf('='))
            {
                var element = el.split('=');
                if(element[0].toString() == "type")
                {
                    chart[integer].setChartTemplate(element[1].toString());
                }
                else if (element[0].toString() == "compare1")
                {
                    chart[integer].setCompare(element[1].toString());
                }
                else if (element[0].toString() == "isin")
                {
                    chart[integer].setISIN(element[1].toString());
                }
                else if (element[0].toString() == "currency")
                {
                    chart[integer].setCurrency(element[1].toString());
                }
                else if (element[0].toString() == "boersenplatz")
                {
                    chart[integer].setBoersenplatz(element[1].toString());
                }
            }
        }
    }
    );
    
    $('.Zeitraum').find('a').click
    (
        function(e)
        {
            e.preventDefault();
            
            if(typeof ET_Event !== 'undefined')
                ET_Event.eventStart('Zeitraum',$(this).text(),'Klick');
            
            var integer = $(this).parent().parent().parent().parent().attr('id').replace(/\D+/,'');
            chart[integer].setZeitraum($(this).text());
            $(this).parent().parent().find('td').removeClass('active');
            $(this).parent().addClass('active');
            $.ajax(
                {
                    type:"POST",
                    url:"/ajax/chart.php",
                    data:chart[integer].buildPost(),
                    beforeSend: function()
                    {
                        $('#chart'+integer).parent().css('height',$('#chart'+integer).css('height'));
                        $('#chart'+integer).attr('src',IMAGES_URL+'Symbole/waiter.gif');
                    },
                    success: function(msg)
                    {
                        $('#chart'+integer).attr('src',msg.replace(/[^A-Za-z0-9\/:\._-]/,'')+'?'+$.now());
                        ReloadIVW();
                    }
                }
            );
        }
    );

    $('.ChartTyp').find('a').click
    (
        function(e)
        {
            e.preventDefault();
            
            if(typeof ET_Event !== 'undefined')
                ET_Event.eventStart('Charttyp',$(this).text(),'Klick');
            
            var integer = $(this).parent().parent().parent().parent().attr('id').replace(/\D+/,'');
            chart[integer].setChartTyp($(this).text());
            $(this).parent().parent().find('td').removeClass('active');
            $(this).parent().addClass('active');
            $.ajax(
                {
                    type:"POST",
                    url:"/ajax/chart.php",
                    data:chart[integer].buildPost(),
                    beforeSend: function()
                    {
                        $('#chart'+integer).parent().css('height',$('#chart'+integer).css('height'));
                        $('#chart'+integer).attr('src',IMAGES_URL+'Symbole/waiter.gif');
                    },
                    success: function(msg)
                    {
                        $('#chart'+integer).attr('src',msg.replace(/[^A-Za-z0-9\/:\._-]/,'')+'?'+$.now());
                        ReloadIVW();
                    }
                }
            );
        }
    );
});
