﻿function CmsQuotation() {
}

CmsQuotation.prototype = {
    init: function() {
        this.revisions = $('.cms .revisions');
        this.revisions.bind('change', this.update);
        
        this.concepts = $('.cms .concepts');
        this.concepts.bind('change', this.update);
        
        this.trademarks = $('.cms .hosting');
        this.trademarks.bind('click', this.update);
        
        this.project_man = $('.cms .project_man');
        this.project_man.bind('click', this.update);
        
        this.timeframe = $('.cms .timeframe');
        this.timeframe.bind('change', this.update);
        
        this.webpages = $('.cms .pages');
        this.webpages.bind('change', this.update);
        
        this.maintenance = $('.cms .maintenance');
        this.maintenance.bind('change', this.update);
        
        this.update();
    },
    update: function() {
        var price = 0;
        
        // Revisions
        var revisions_quote = 0;
        var revisions_type = $('.cms .revisions').attr('value');
        var revisions_prices = {'Standard': 175, 'More': 350, 'Most': 500};
        if (revisions_prices[revisions_type] != 'undefined')
            revisions_quote = revisions_prices[revisions_type];
        else {
            alert('Invalid revisions type: ' + revisions_type);
        }
        
        // Concepts
        var concepts_quote = 0;
        var concepts_type = $('.cms .concepts').attr('value');
        var concepts_prices = {'Standard': 225, 'More': 450, 'Most': 750};
        if (concepts_prices[concepts_type] != 'undefined')
            concepts_quote = concepts_prices[concepts_type];
        else {
            alert('Invalid concepts type: ' + concepts_type);
        }
        
        // Hosting
        var hosting_quote = 0;
        var hosting_type = $('.cms .hosting[@checked]').attr('value');
        var hosting_prices = {'Optional': 0, 'Hosting Yes': 10};
        if (hosting_prices[hosting_type] != 'undefined')
            hosting_quote = hosting_prices[hosting_type];
        else {
            alert('Invalid hosting type: ' + hosting_type);
        }

        // Project Managements
        var project_man_quotes = 0;
        var project_man_items = $('.cms .project_man[@checked]');
        var project_man_prices = 250;
        if (project_man_items != 'undefined')
            project_man_items.each(function(i) {project_man_quotes += project_man_prices});
        else {
            alert('Invalid project_man type: ' + project_man_type);
        }

        // TimeFrame
        var timeframe_quote = 0;
        var timeframe_type = $('.cms .timeframe').attr('value');
        var timeframe_prices = {'Standard': 0, 'Quick': 75, 'Quicker': 150, 'Quickest': 250};
        if (timeframe_prices[timeframe_type] != 'undefined')
            timeframe_quote = timeframe_prices[timeframe_type];
        else {
            alert('Invalid timeframe type: ' + timeframe_type);
        }

        // Website
        var webpages_quote = 0;
        var webpages_type = $('.cms .pages').attr('value');
        var webpages_prices = {'Standard': 100, 'More': 200, 'More2': 350, 'Most': 500};
        if (webpages_prices[webpages_type] != 'undefined')
            webpages_quote = webpages_prices[webpages_type];
        else {
            alert('Invalid webpages type: ' + webpages_type);
        }
        
        // Maintenance
        var maintenance_quote = 0;
        var maintenance_type = $('.cms .maintenance').attr('value');
        var maintenance_prices = {'Optional': 0, '2Year': 300, '6Year': 800, '12Year': 1500, '24Year': 2800};
        if (maintenance_prices[maintenance_type] != 'undefined')
            maintenance_quote = maintenance_prices[maintenance_type];
        else {
            alert('Invalid maintenance type: ' + maintenance_type);
        }
        
        price =  revisions_quote + concepts_quote + hosting_quote + project_man_quotes + webpages_quote + maintenance_quote;

        price += (timeframe_quote/100)*price;
        $('#cms_quote').html('$' + price);
        //console.log(price);
    }
}

var Cms = new CmsQuotation();
Cms.init();
