var calculator = {
	
	container : null,
	
	data : new Array(),
	
	start : false,
	
	init : function(container) {
        var self = this;
        self.container = container;
        $('select',self.container).change(function(){self.validation(false)});
        $('input[type=submit]',self.container).click(function(){return self.validation(true)});
        
    },
    validation : function(button) {
    	var self = this;
    	if($('select[name=type]',self.container).val()!='' && $('select[name=air]',self.container).val()!='' && $('select[name=district]',self.container).val()!='')
    	{   if(button!=false) self.start = true;
    	    if(self.start!=false) self.calculate();
    	}
    	else
    	   if(button!=false)
    	       alert('Выберите все поля');
    	   else
    	   {
    	   	   $('p.sum',self.container).hide();
               $('input[type=submit]',self.container).parent('p').show();
    	   }
    },
    calculate : function() {
        var self = this;
        var sum = self.data[$('select[name=type]',self.container).val()][$('select[name=air]',self.container).val()][$('select[name=district]',self.container).val()];
        $('p.sum',self.container).html('<span>'+sum+'</span> руб.');
        $('p.sum',self.container).show();
        $('input[type=submit]',self.container).parent('p').hide();
    }
}

$(function() {
    calculator.init('#calc');
});
