﻿function WebsiteQuotation() {
}

WebsiteQuotation.prototype = {
    init: function() {
        this.revisions = $('.website .revisions');
        this.revisions.bind('change', this.update);
        
        this.concepts = $('.website .concepts');
        this.concepts.bind('change', this.update);
        
        this.trademarks = $('.website .trademarks');
        this.trademarks.bind('click', this.update);
        
        this.trademarks = $('.website .hosting');
        this.trademarks.bind('click', this.update);
        
        this.timeframe = $('.website .timeframe');
        this.timeframe.bind('change', this.update);
        
        this.webpage = $('.website .pages');
        this.webpage.bind('change', this.update);
        
        this.maintenance = $('.website .maintenance');
        this.maintenance.bind('change', this.update);
        
        this.update();
    },
    update: function() {
        var price = 0;
        
        // Revisions
        var revisions_quote = 0;
        var revisions_type = $('.website .revisions').attr('value');
        var revisions_prices = {'Standard': 75, 'More': 225, 'Most': 375};
        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 = $('.website .concepts').attr('value');
        var concepts_prices = {'Standard': 100, 'More': 250, 'Most': 400};
        if (concepts_prices[concepts_type] != 'undefined')
            concepts_quote = concepts_prices[concepts_type];
        else {
            alert('Invalid concepts type: ' + concepts_type);
        }
        
        // Trademarks
        var trademarks_quote = 0;
        var trademarks_type = $('.website .trademarks[@checked]').attr('value');
        var trademarks_prices = {'Optional': 0, 'Trademark Yes': 350};
        if (trademarks_prices[trademarks_type] != 'undefined')
            trademarks_quote = trademarks_prices[trademarks_type];
        else {
            alert('Invalid trademarks type: ' + trademarks_type);
        }
        
        // Hosting
        var hosting_quote = 0;
        var hosting_type = $('.website .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);
        }

        // TimeFrame
        var timeframe_quote = 0;
        var timeframe_type = $('.website .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 = $('.website .pages').attr('value');
        var webpages_prices = {'Standard': 75, 'More': 150, 'More2': 250, 'Most': 350};
        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 = $('.website .maintenance').attr('value');
        var maintenance_prices = {'Optional': 0, '2Year': 250, '6Year': 650, '12Year': 1200, '24Year': 2000};
        if (maintenance_prices[maintenance_type] != 'undefined')
            maintenance_quote = maintenance_prices[maintenance_type];
        else {
            alert('Invalid maintenance type: ' + maintenance_type);
        }
        
        price = revisions_quote + concepts_quote + trademarks_quote + maintenance_quote + webpages_quote + hosting_quote;
        
        price += (timeframe_quote/100)*price;
        $('#website_quote').html('$' + price);
        //console.log(price);
    }
}

var Website = new WebsiteQuotation();
Website.init();
