function Metal_Strategy_Blank()
{
	this.visibility =  {width:1, height:1, diametr:0, length: 1};
}


/* Strategy definitions */
function Metal_Strategy_Square ()
{
	Metal_Strategy_Square.superclass.constructor.apply(this, []);
	this.visibility.height = 0;
}

extend(Metal_Strategy_Square, Metal_Strategy_Blank);


function Metal_Strategy_Circle ()
{
	Metal_Strategy_Circle.superclass.constructor.apply(this, []);
	this.visibility.width = 0;
	this.visibility.height = 0;
	this.visibility.diametr = 1;
}

extend(Metal_Strategy_Circle, Metal_Strategy_Blank);

function Metal_Strategy_Poligon ()
{
	Metal_Strategy_Poligon.superclass.constructor.apply(this, []);
	this.visibility.height = 0;
}

extend(Metal_Strategy_Poligon, Metal_Strategy_Blank);

function Metal_Strategy_Sheet ()
{
	Metal_Strategy_Sheet.superclass.constructor.apply(this, []);
}

extend(Metal_Strategy_Sheet, Metal_Strategy_Blank);

function Metal_Strategy_Angle ()
{
	Metal_Strategy_Angle.superclass.constructor.apply(this, []);
}

extend(Metal_Strategy_Angle, Metal_Strategy_Blank);

function Metal_Strategy_Tube ()
{
	Metal_Strategy_Tube.superclass.constructor.apply(this, []);
	this.visibility.width = 0;
	this.visibility.diametr = 1;
}

extend(Metal_Strategy_Tube, Metal_Strategy_Blank);

function Metal_Strategy_Rectangle ()
{
	Metal_Strategy_Rectangle.superclass.constructor.apply(this, []);
}

extend(Metal_Strategy_Rectangle, Metal_Strategy_Blank);




/* system methods */

Metal_Strategy_Blank.prototype.width = function ()
{
	return this.prepareValue($('#mass_width').val())/1000;
}

Metal_Strategy_Blank.prototype.height = function ()
{
	return this.prepareValue($('#mass_height').val())/1000;
}

Metal_Strategy_Blank.prototype.diametr = function ()
{
	return this.prepareValue($('#mass_diametr').val())/1000;
}

Metal_Strategy_Blank.prototype.length = function ()
{
	return this.prepareValue($('#mass_length').val())/1000;
}

Metal_Strategy_Blank.prototype.density = function ()
{
	return this.prepareValue($('input[@type=radio][@name=rad_material][@checked=1]').attr('density'));
}

Metal_Strategy_Blank.prototype.prepareValue = function (value)
{
	if(value)
		return value.replace( /,/g, "." );
	return value;
}

Metal_Strategy_Blank.prototype.changeVisisbility = function()
{
	for(var i in this.visibility)
	{
		if(this.visibility[i])
			$('#mass_'+i+'_td').removeClass('hide_dimension');
		else
		    $('#mass_'+i+'_td').addClass('hide_dimension');
	}
}

Metal_Strategy_Blank.prototype.getValue = function()
{
	var value = this.calculate();
	if(isNaN(value))
		return this.getSpecifyString();
	value = Math.round(value*1000)/1000;
	return "Масса изделия: " + value + " кг";
}

/*Calculate strategies */
Metal_Strategy_Blank.prototype.calculate = function()
{
	
}

Metal_Strategy_Blank.prototype.getSpecifyString = function()
{
	return "Укажите параметры для расчета";
}


Metal_Strategy_Square.prototype.calculate = function()
{
	return this.width()*this.width()*this.length()*this.density();
}


Metal_Strategy_Circle.prototype.calculate = function()
{
	return this.diametr()*this.diametr()*this.length()*this.density()*Math.PI/4;
}

Metal_Strategy_Poligon.prototype.calculate = function()
{
	return this.width()*this.width()*Math.sqrt(3)*this.length()*this.density();	
}

Metal_Strategy_Sheet.prototype.calculate = function()
{
	return this.width()*this.height()*this.length()*this.density();
}

Metal_Strategy_Angle.prototype.calculate = function()
{
	return (this.width()+this.height())*this.length()*this.density();
}

Metal_Strategy_Tube.prototype.calculate = function()
{
	return Math.PI*(this.diametr()*this.height() - this.height()*this.height())*this.length()*this.density();
}
Metal_Strategy_Rectangle.prototype.calculate = function()
{
	return this.width()*this.height()*this.length()*this.density();
}