// BODY STYLE CONSTANTS
var BODY_STYLE_CLASSIC = 1;
var BODY_STYLE_SLIM = 0;
var BODY_STYLE_SUPER_SLIM = 2;

/* STANDART SIZES
sizes: 
	small		s
	medium		m
	large		l
	x-large		xl
	xx-large	xxl
fit type:
	super slim fit	ssf
	slim fit		sf
	classic fit		cf
*/
//								collar | sleeve | chest | shoulder | back len | middle | sleeve width | cuff
standart_size_s_ssf 	= new Array(14.5, 33, 20.25, 17, 31.5, 16.5, 	7.5, 	8.5);
standart_size_s_sf 		= new Array(14.5, 33, 21.25, 17, 31.5, 18, 		8.375, 	8.5);
standart_size_s_cf 		= new Array(14.5, 33, 21.25, 17, 31.5, 19.5, 	8.875, 	8.5);

standart_size_m_ssf 	= new Array(15.5, 34, 21.25, 18, 32.5, 18.5, 	6.875, 	9);
standart_size_m_sf 		= new Array(15.5, 34, 22.25, 18, 32.5, 20, 		8.75, 	9);
standart_size_m_cf 		= new Array(15.5, 34, 23.25, 18, 32.5, 21.5, 	9.625, 	9);

standart_size_l_ssf 	= new Array(16.5, 35, 23.25, 19, 33.5, 20.5,	8.625, 	9.25);
standart_size_l_sf 		= new Array(16.5, 35, 24.25, 19, 33.5, 22, 		9.5, 	9.25);
standart_size_l_cf 		= new Array(16.5, 35, 25.25, 19, 33.5, 23.5, 	10.375, 9.25);

standart_size_xl_ssf 	= new Array(17.5, 36, 25.25, 20, 34.5, 22.5, 	9.375, 	9.5);
standart_size_xl_sf 	= new Array(17.5, 36, 26.25, 20, 34.5, 24, 		10.25, 	9.5);
standart_size_xl_cf 	= new Array(17.5, 36, 27.25, 20, 34.5, 25.5, 	11.125, 9.5);

standart_size_xxl_ssf 	= new Array(18.5, 37, 27.25, 21, 35.5, 24.5, 	10.125, 10);
standart_size_xxl_sf 	= new Array(18.5, 37, 28.25, 21, 35.5, 26, 		11, 	10);
standart_size_xxl_cf 	= new Array(18.5, 37, 29.25, 21, 35.5, 27.5, 	11.875, 10);



// special functions
function excelCeil(value)
{
	if (value > 0)
		return Math.ceil(value);
	else
		return Math.floor(value);
}

function excelFloor(value)
{
	if (value > 0)
		return Math.floor(value);
	else
		return Math.ceil(value);
}

function excelRound(value)
{
	if (value % 1 == -0.5) return Math.floor(value);
	return Math.round(value);
}
// -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- -  -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- - -- - -- - - -- - -- - --
//-- - -- - - -- - -- - -- - -- - -	       TABLE CONTAINING SPECIAL VALUES (CLASS) 	      -- -- - --  - -- - - -- - -- - -- -- 
// -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- -  -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- - -- - -- - - -- - -- - --
function ChestWidthTable()
{
	this.table;
	this.init = function()
	{
		this.table = new Array();
		// 						   id	chest	2chest pleats fit mid-eqn 4chest body size
		this.table[0]  = new Array(1,  37.25,	74.5,	1,	0,	71,		149,	22.5);
		this.table[1]  = new Array(2,  36.75,	73.5,	0,	1,	71,		147,	22);
		this.table[2]  = new Array(3,  36.5,	73,		0,	0,	70,		146,	22.5);
		this.table[3]  = new Array(4,  36.25,	72.5,	1,	0,	69,		145,	22);
		this.table[4]  = new Array(5,  35.75,	71.5,	0,	1,	69,		143,	21.5);
		this.table[5]  = new Array(6,  35.5,	71,		0,	0,	68,		142,	22);
		this.table[6]  = new Array(7,  35.25,	70.5,	1,	0,	67,		141,	21.5);
		this.table[7]  = new Array(8,  34.75,	69.5,	0,	1,	67,		139,	21);
		this.table[8]  = new Array(9,  34.5,	69,		0,	0,	66,		138,	21.5);
		this.table[9]  = new Array(10, 34.25,	68.5,	1,	0,	65,		137,	21);
		this.table[10] = new Array(11, 33.75,	67.5,	0,	1,	65,		135,	20.5);
		this.table[11] = new Array(12, 33.5,	67,		0,	0,	64,		134,	21);
		this.table[12] = new Array(13, 33.25,	66.5,	1,	0,	63,		133,	20.5);
		this.table[13] = new Array(14, 32.75,	65.5,	0,	1,	63,		131,	20);
		this.table[14] = new Array(15, 32.5,	65,		0,	0,	62,		130,	20.5);
		this.table[15] = new Array(16, 32.25,	64.5,	1,	0,	61,		129, 	20);
		this.table[16] = new Array(17, 31.75,	63.5,	0,	1,	61,		127,	19.5);
		this.table[17] = new Array(18, 31.5,	63,		0,	0,	60,		126,	20);
		this.table[18] = new Array(19, 31.25,	62.5,	1,	0,	59,		125,	19.5);
		this.table[19] = new Array(20, 30.75,	61.5,	0,	1,	59,		123,	19);
		this.table[20] = new Array(21, 30.5,	61,		0,	0,	58,		122,	19.5);
		this.table[21] = new Array(22, 30.25,	60.5,	1,	0,	57,		121,	19);
		this.table[22] = new Array(23, 29.75,	59.5,	0,	1,	57,		119,	18.5);
		this.table[23] = new Array(24, 29.5,	59,		0,	0,	56,		118,	19);
		this.table[24] = new Array(25, 29.25,	58.5,	1,	0,	55,		117,	18.5);
		this.table[25] = new Array(26, 28.75,	57.5,	0,	1,	55,		115,	18);
		this.table[26] = new Array(27, 28.5,	57,		0,	0,	54,		114,	18.5);
		this.table[27] = new Array(28, 28.25,	56.5,	1,	0,	53,		113,	18);
		this.table[28] = new Array(29, 27.75,	55.5,	0,	1,	53,		111,	17.5);
		this.table[29] = new Array(30, 27.5,	55,		0,	0,	52,		110,	18);
		this.table[30] = new Array(31, 27.25,	54.5,	1,	0,	51,		109,	17.5);
		this.table[31] = new Array(32, 26.75,	53.5,	0,	1,	51,		107,	17);
		this.table[32] = new Array(33, 26.5,	53,		0,	0,	50,		106,	17.5);
		this.table[33] = new Array(34, 26.25,	52.5,	1,	0,	49,		105,	17);
		this.table[34] = new Array(35, 25.75,	51.5,	0,	1,	49,		103,	16.5);
		this.table[35] = new Array(36, 25.5,	51,		0,	0,	48,		102,	17);
		this.table[36] = new Array(37, 25.25,	50.5,	1,	0,	47,		101,	16.5);
		this.table[37] = new Array(38, 24.75,	49.5,	0,	1,	47,		99,		16);
		this.table[38] = new Array(39, 24.5,	49,		0,	0,	46,		98,		16.5);
		this.table[39] = new Array(40, 24.25,	48.5,	1,	0,	45,		97,		16);
		this.table[40] = new Array(41, 23.75,	47.5,	0,	1,	45,		95,		15.5);
		this.table[41] = new Array(42, 23.5,	47,		0,	0,	44,		94,		16);
		this.table[42] = new Array(43, 23.25,	46.5,	1,	0,	43,		93,		15.5);
		this.table[43] = new Array(44, 22.75,	45.5,	0,	1,	43,		91,		15);
		this.table[44] = new Array(45, 22.5,	45,		0,	0,	42,		90,		15.5);
		this.table[45] = new Array(46, 22.25,	44.5,	1,	0,	41,		89,		15);
		this.table[46] = new Array(47, 21.75,	43.5,	0,	1,	41,		87,		14.5);
		this.table[47] = new Array(48, 21.5,	43,		0,	0,	40,		86,		15);
		this.table[48] = new Array(49, 21.25,	42.5,	1,	0,	39,		85,		14.5);
		this.table[49] = new Array(50, 20.75,	41.5,	0,	1,	39,		83,		14);
		this.table[50] = new Array(51, 20.5,	41,		0,	0,	38,		82,		14.5);
		this.table[51] = new Array(52, 20.25,	40.5,	1,	0,	37,		81,		14);
		this.table[52] = new Array(53, 19.5,	39,		0,	0,	36,		78,		14);
	}                           
	this.findNearIdByValue = function(field, value)
	{
		var min_distance = false;
		var target_element = 0;
		for (i = 0; i < this.table.length; i++)
		{
			if (min_distance === false || Math.abs(this.table[i][field] - value) < min_distance)
			{
				target_element = i;
				min_distance = Math.abs(this.table[i][field] - value);
			}
		}
		return target_element;
	}
	this.getElementById = function(id)
	{
		return this.table[id];
	}
	this.getNextElement = function(id)
	{
		if (this.table[++id] == undefined)
			return false;
		else
			return this.table[id];
	}
	this.getPrevElement = function(id)
	{
		if (this.table[--id] == undefined)
			return false;
		else
			return this.table[id];
	}
	this.getFirstElement = function()
	{
		return this.table[0];
	}
	this.getLastElement = function()
	{
		return this.table[this.table.length - 1];
	}
	this.init();
}

// -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- -  -- - -- - - -- - -- - -- - -- - -- - -- - -- -- -
// -- - -- - - -- - -- - -- - -- - -           MEASUREMENTS CHEST LIMITS TABLE 		     -- -- - --  - -- - - -- - -- - -- - -
// -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- -  -- - -- - - -- - -- - -- - -- - -- - -- - -- -- -
function ChestLimitsTable()
{
	this.table;
	this.init = function()
	{
		this.table = new Array();
//								Sleeve width | min | max
		this.table.push( { "sleeveWidth": 6.25,  "min": 16.50, "max": 16.50 } );
		this.table.push( { "sleeveWidth": 6.50,  "min": 16.50, "max": 17.50 } );
		this.table.push( { "sleeveWidth": 6.75,  "min": 16.50, "max": 18.00 } );
		this.table.push( { "sleeveWidth": 7.00,  "min": 16.50, "max": 19.00 } );
		this.table.push( { "sleeveWidth": 7.25,  "min": 16.50, "max": 19.50 } );
		this.table.push( { "sleeveWidth": 7.50,  "min": 16.50, "max": 20.00 } );
		this.table.push( { "sleeveWidth": 7.75,  "min": 16.50, "max": 21.00 } );
		this.table.push( { "sleeveWidth": 8.00,  "min": 16.50, "max": 21.50 } );
		this.table.push( { "sleeveWidth": 8.25,  "min": 17.50, "max": 22.00 } );
		this.table.push( { "sleeveWidth": 8.50,  "min": 18.00, "max": 23.00 } );
		this.table.push( { "sleeveWidth": 8.75,  "min": 19.00, "max": 23.50 } );
		this.table.push( { "sleeveWidth": 9.00,  "min": 19.50, "max": 24.00 } );
		this.table.push( { "sleeveWidth": 9.25,  "min": 20.00, "max": 25.00 } );
		this.table.push( { "sleeveWidth": 9.50,  "min": 21.00, "max": 25.50 } );
		this.table.push( { "sleeveWidth": 9.75,  "min": 21.50, "max": 26.00 } );
		this.table.push( { "sleeveWidth": 10.00, "min": 22.00, "max": 27.00 } );
		this.table.push( { "sleeveWidth": 10.25, "min": 23.00, "max": 27.50 } );
		this.table.push( { "sleeveWidth": 10.50, "min": 23.50, "max": 28.00 } );
		this.table.push( { "sleeveWidth": 10.75, "min": 24.00, "max": 29.00 } );
		this.table.push( { "sleeveWidth": 11.00, "min": 25.00, "max": 29.50 } );
		this.table.push( { "sleeveWidth": 11.25, "min": 25.50, "max": 30.00 } );
		this.table.push( { "sleeveWidth": 11.50, "min": 26.00, "max": 31.00 } );
		this.table.push( { "sleeveWidth": 11.75, "min": 27.00, "max": 31.50 } );
		this.table.push( { "sleeveWidth": 12.00, "min": 27.50, "max": 32.00 } );
		this.table.push( { "sleeveWidth": 12.25, "min": 28.00, "max": 32.50 } );
		this.table.push( { "sleeveWidth": 12.50, "min": 29.00, "max": 32.50 } );
		this.table.push( { "sleeveWidth": 12.75, "min": 29.50, "max": 32.50 } );
		this.table.push( { "sleeveWidth": 13.00, "min": 30.00, "max": 32.50 } );
		this.table.push( { "sleeveWidth": 13.25, "min": 31.00, "max": 32.50 } );
		this.table.push( { "sleeveWidth": 13.50, "min": 31.50, "max": 32.50 } );
		this.table.push( { "sleeveWidth": 13.75, "min": 32.00, "max": 32.50 } );
		this.table.push( { "sleeveWidth": 14.00, "min": 32.50, "max": 32.50 } );
	}

	this.getNearestObject = function( sleeveWidth ){
		var nearestObject;
		var nearestValue;
		for ( var index in this.table ){
			if ( undefined == nearestValue || nearestValue > Math.abs( this.table[index]["sleeveWidth"] - sleeveWidth ) ){
				nearestObject = this.table[index];
				nearestValue = Math.abs( this.table[index]["sleeveWidth"] - sleeveWidth );
			}
		}
		return nearestObject;
	}

	this.getMinChestByNearestSleeveWidth = function( sleeveWidth ){
		var obj = this.getNearestObject( sleeveWidth );
		return obj.min;
	}

	this.getMaxChestByNearestSleeveWidth = function( sleeveWidth ){
		var obj = this.getNearestObject( sleeveWidth );
		return obj.max;
	}
	this.init();
}

// -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- -  -- - -- - - -- - -- - -- - -- - -- - -- - -- -- -
// -- - -- - - -- - -- - -- - -- - -         MEASUREMENTS SLEEVE WIDTH LIMITS TABLE	     -- -- - --  - -- - - -- - -- - -- - -
// -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- -  -- - -- - - -- - -- - -- - -- - -- - -- - -- -- -
function SleeveWidthLimitsTable()
{
	this.table;
	this.init = function()
	{
		this.table = new Array();
//								Sleeve width | min | max
		this.table.push( { "chestWidth": 16.5,	"min": 6.25,	"max": 8.00}  );
		this.table.push( { "chestWidth": 17,	"min": 6.25,	"max": 8.00}  );
		this.table.push( { "chestWidth": 17.5,	"min": 6.50,	"max": 8.25}  );
		this.table.push( { "chestWidth": 18,	"min": 6.75,	"max": 8.50}  );
		this.table.push( { "chestWidth": 18.5,	"min": 7.00,	"max": 8.75}  );
		this.table.push( { "chestWidth": 19,	"min": 7.00,	"max": 8.75}  );
		this.table.push( { "chestWidth": 19.5,	"min": 7.25,	"max": 9.00}  );
		this.table.push( { "chestWidth": 20,	"min": 7.50,	"max": 9.25}  );
		this.table.push( { "chestWidth": 20.5,	"min": 7.75,	"max": 9.50}  );
		this.table.push( { "chestWidth": 21,	"min": 7.75,	"max": 9.50}  );
		this.table.push( { "chestWidth": 21.5,	"min": 8.00,	"max": 9.75}  );
		this.table.push( { "chestWidth": 22,	"min": 8.25,	"max": 10.00} );
		this.table.push( { "chestWidth": 22.5,	"min": 8.50,	"max": 10.25} );
		this.table.push( { "chestWidth": 23,	"min": 8.50,	"max": 10.25} );
		this.table.push( { "chestWidth": 23.5,	"min": 8.75,	"max": 10.50} );
		this.table.push( { "chestWidth": 24,	"min": 9.00,	"max": 10.75} );
		this.table.push( { "chestWidth": 24.5,	"min": 9.25,	"max": 11.00} );
		this.table.push( { "chestWidth": 25,	"min": 9.25,	"max": 11.00} );
		this.table.push( { "chestWidth": 25.5,	"min": 9.50,	"max": 11.25} );
		this.table.push( { "chestWidth": 26,	"min": 9.75,	"max": 11.50} );
		this.table.push( { "chestWidth": 26.5,	"min": 10.00,	"max": 11.75} );
		this.table.push( { "chestWidth": 27,	"min": 10.00,	"max": 11.75} );
		this.table.push( { "chestWidth": 27.5,	"min": 10.25,	"max": 12.00} );
		this.table.push( { "chestWidth": 28,	"min": 10.50,	"max": 12.25} );
		this.table.push( { "chestWidth": 28.5,	"min": 10.75,	"max": 12.50} );
		this.table.push( { "chestWidth": 29,	"min": 10.75,	"max": 12.50} );
		this.table.push( { "chestWidth": 29.5,	"min": 11.00,	"max": 12.75} );
		this.table.push( { "chestWidth": 30,	"min": 11.25,	"max": 13.00} );
		this.table.push( { "chestWidth": 30.5,	"min": 11.50,	"max": 13.25} );
		this.table.push( { "chestWidth": 31,	"min": 11.50,	"max": 13.25} );
		this.table.push( { "chestWidth": 31.5,	"min": 11.75,	"max": 13.50} );
		this.table.push( { "chestWidth": 32,	"min": 12.00,	"max": 13.75} );
		this.table.push( { "chestWidth": 32.5,	"min": 12.25,	"max": 14.00} );
	}

	this.getNearestObject = function( chestWidth ){
		var nearestObject;
		var nearestValue;
		for ( var index in this.table ){
			if ( undefined == nearestValue || nearestValue > Math.abs( this.table[index]["chestWidth"] - chestWidth ) ){
				nearestObject = this.table[index];
				nearestValue = Math.abs( this.table[index]["chestWidth"] - chestWidth );
			}
		}
		return nearestObject;
	}

	this.getMinSleeveWidthByNearestChest = function( chestWidth ){
		var obj = this.getNearestObject( chestWidth );
		return obj.min;
	}

	this.getMaxSleeveWidthByNearestChest= function( chestWidth ){
		var obj = this.getNearestObject( chestWidth );
		return obj.max;
	}
	this.init();
}

// -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- -  -- - -- - - -- - -- - -- - -- - -- - -- - -- -- -
// -- - -- - - -- - -- - -- - -- - -			    SHIRT MEASUREMENTS CLASS 		      -- -- - --  - -- - - -- - -- - -- --
// -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- -  -- - -- - - -- - -- - -- - -- - -- - -- - -- -- -
function ShirtMeasurement()
{
	// input values
	this.collar_Shirt 	= 0;
	this.sleeve_Shirt 	= 0;
	this.shoulder_Shirt = 0;
	this.chest_Shirt	= 0;
	this.mid_Shirt 		= 0;
	this.sleeveW_Shirt	= 0;
	this.length_Shirt	= 0;
	this.cuff_Shirt		= 0;
	this.washes_Shirt  	= 0;
	 
	//output values
	this.fit			= 0;
	this.model_Ord  	= 0;
	this.size_Ord  		= 0;
	this.neck_Ord  		= 0;
	this.length_Ord  	= 0;
	this.rSleeve_Ord  	= 0;
	this.lSleeve_Ord  	= 0;
	this.waist_Ord  	= 0;
	this.rCuff_Ord	 	= 0;
	this.lCuff_Ord		= 0;
	this.bicep_adj_Ord  = 0;
	this.yokeadj_Ord  	= 0;
	this.backDetail_Ord	= 0;
	this.rear_side_pleats = 1;

	this.bicepStdDum;
	this.yokeStandard;
	this.waistStdDum;
	this.waistDesDum;
	
	this.sleeveWDesDum;
	this.chestDesDum;
	this.collarDesDum;
	this.lengthStd;
	this.lengthDesDum;
	
	this.adjCollar;
	this.adjChest;
	this.adjMiddle;
	this.adjShoulder;
	this.adjBackLen;
	this.adjSleeveWidth;
	this.adjSleeveLen;
	this.adjCuff;

	// limits
	this.min_collar		= 0;
	this.min_sleeve		= 0;
	this.min_shoulder	= 0;
	this.min_chest		= 0;
	this.min_mid		= 0;
	this.min_sleeveW	= 0;
	this.min_length		= 0;
	this.min_cuff		= 0;

	this.max_collar		= 0;
	this.max_sleeve		= 0;
	this.max_shoulder	= 0;
	this.max_chest		= 0;
	this.max_mid		= 0;
	this.max_sleeveW	= 0;
	this.max_length		= 0;
	this.max_cuff		= 0;

	//setter functions
	this.setCollarShirt 	= function(value) {value = value.toString(); value = value.replace(',', '.'); this.collar_Shirt = parseFloat(value);};
	this.setSleeveShirt 	= function(value) {value = value.toString(); value = value.replace(',', '.'); this.sleeve_Shirt = parseFloat(value);};
	this.setShoulderShirt 	= function(value) {value = value.toString(); value = value.replace(',', '.'); this.shoulder_Shirt = parseFloat(value);};
	this.setChestShirt		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.chest_Shirt = parseFloat(value);};
	this.setMidShirt 		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.mid_Shirt = parseFloat(value);};
	this.setSleeveWShirt	= function(value) {value = value.toString(); value = value.replace(',', '.'); this.sleeveW_Shirt = parseFloat(value);};
	this.setLengthShirt		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.length_Shirt = parseFloat(value);};
	this.setCuffShirt		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.cuff_Shirt = parseFloat(value);};
	this.setWashesShirt  	= function(value) {value = value.toString(); value = value.replace(',', '.'); this.washes_Shirt = parseFloat(value);};
	this.setRearSidePleats 	= function(value) {this.rear_side_pleats = (value == true);};

	this.setAdjCollar		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjCollar = parseFloat(value);};
	this.setAdjChest		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjChest = parseFloat(value);};
	this.setAdjShoulder		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjShoulder = parseFloat(value);};
	this.setAdjMiddle		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjMiddle = parseFloat(value);};
	this.setAdjBackLen		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjBackLen = parseFloat(value);};
	this.setAdjSleeveW		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjSleeveWidth = parseFloat(value);};
	this.setAdjSleeveL		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjSleeveLen = parseFloat(value);};
	this.setAdjCuff			= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjCuff = parseFloat(value);};

	this.setAdjParamsArr	= function(arr)
	{
		this.setCollarShirt(arr[0]); 
		this.setSleeveShirt(arr[1]);
		this.setShoulderShirt(arr[3]);
	    this.setChestShirt(arr[2]);
	    this.setMidShirt(arr[5]);
	    this.setSleeveWShirt(arr[6]);
	    this.setLengthShirt(arr[4]);
	    this.setCuffShirt(arr[7]);
		
 		this.setAdjCollar(arr[0]); 
		this.setAdjSleeveL(arr[1]);
		this.setAdjChest(arr[2]);
		this.setAdjShoulder(arr[3]);
		this.setAdjBackLen(arr[4]);
		this.setAdjMiddle(arr[5]);
		this.setAdjSleeveW(arr[6]);
		this.setAdjCuff(arr[7]); 
	}

	//getter functions
	this.getFitOrd			= function() {return this.fit};
	this.getModelOrd  		= function() {return this.model_Ord};
	this.getSizeOrd  		= function() {return this.size_Ord};
	this.getNeckOrd  		= function() {return this.neck_Ord};
	this.getLengthOrd  		= function() {return this.length_Ord};
	this.getRSleeveOrd  	= function() {return this.rSleeve_Ord};
	this.getLSleeveOrd 	 	= function() {return this.lSleeve_Ord};
	this.getWaistOrd  		= function() {return this.waist_Ord};
	this.getRCuffOrd  		= function() {return this.rCuff_Ord};
	this.getLCuffOrd  		= function() {return this.lCuff_Ord};
	this.getBicepAdjOrd  	= function() {return this.bicep_adj_Ord};
	this.getYokeAdjOrd  	= function() {return this.yokeadj_Ord};
	this.getBackDetailOrd	= function() {return this.backDetail_Ord};

	this.getMinCollar		= function() {return this.min_collar;};
	this.getMinSleeve		= function() {return this.min_sleeve;};
	this.getMinShoulder		= function() {return this.min_shoulder;};
	this.getMinChest		= function() {return this.min_chest;};
	this.getMinMid			= function() {return this.min_mid;};
	this.getMinSleveW		= function() {return this.min_sleeveW;};
	this.getMinLength		= function() {return this.min_length;};
	this.getMinCuff			= function() {return this.min_cuff;};

	this.getMaxCollar		= function() {return this.max_collar;};
	this.getMaxSleeve		= function() {return this.max_sleeve;};
	this.getMaxShoulder		= function() {return this.max_shoulder;};
	this.getMaxChest		= function() {return this.max_chest;};
	this.getMaxMid			= function() {return this.max_mid;};
	this.getMaxSleveW		= function() {return this.max_sleeveW;};
	this.getMaxLength		= function() {return this.max_length;};
	this.getMaxCuff			= function() {return this.max_cuff;};

	this.getAdjCollar		= function() {return Math.abs(this.adjCollar)};
	this.getAdjChest		= function() {return Math.abs(this.adjChest)};
	this.getAdjShoulder		= function() {return Math.abs(this.adjShoulder)};
	this.getAdjMiddle		= function() {return Math.abs(this.adjMiddle)};
	this.getAdjBackLen		= function() {return Math.abs(this.adjBackLen)};
	this.getAdjSleeveW		= function() {return Math.abs(this.adjSleeveWidth)};
	this.getAdjSleeveL		= function() {return Math.abs(this.adjSleeveLen)};
	this.getAdjCuff			= function() {return Math.abs(this.adjCuff)};

	this.table = new ChestWidthTable();
// limits
	this.correctByLimits		= function()
	{
		if (this.adjCollar > this.max_collar) this.adjCollar = this.max_collar;
		if (this.adjCollar < this.min_collar) this.adjCollar = this.min_collar;
		
		if (this.adjMiddle > this.max_mid) this.adjMiddle = this.max_mid;
		if (this.adjMiddle < this.min_mid) this.adjMiddle = this.min_mid;
		
		if (this.adjShoulder > this.max_shoulder) this.adjShoulder = this.max_shoulder;
		if (this.adjShoulder < this.min_shoulder) this.adjShoulder = this.min_shoulder;
		
		if (this.adjBackLen > this.max_length) this.adjBackLen = this.max_length;
		if (this.adjBackLen < this.min_length) this.adjBackLen = this.min_length;

		if (this.adjSleeveLen > this.max_sleeve) this.adjSleeveLen = this.max_sleeve;
		if (this.adjSleeveLen < this.min_sleeve) this.adjSleeveLen = this.min_sleeve;
		
		if (this.adjCuff > this.max_cuff) this.adjCuff = this.max_cuff;
		if (this.adjCuff < this.min_cuff) this.adjCuff = this.min_cuff;
	}
// limits
	this.calculateLimits 		= function()
	{
		var chestLimitsTable = new ChestLimitsTable();
		var sleeveWidthLimitsTable = new SleeveWidthLimitsTable();
		this.min_collar		= 12;
		this.min_chest		= chestLimitsTable.getMinChestByNearestSleeveWidth( this.adjSleeveWidth );
		this.min_mid		= 10;
		this.min_shoulder	= 10;
		this.min_length		= 25;
		this.min_sleeveW	= sleeveWidthLimitsTable.getMinSleeveWidthByNearestChest( this.adjChest );
		this.min_sleeve		= 28;
		this.min_cuff		= 8;
		this.min_bottom_width = this.adjMiddle;

		this.max_collar		= 24;
		this.max_chest		= chestLimitsTable.getMaxChestByNearestSleeveWidth( this.adjSleeveWidth );
		this.max_mid		= 80;
		this.max_shoulder	= 30;
		this.max_length		= 45;
		this.max_sleeveW	= sleeveWidthLimitsTable.getMaxSleeveWidthByNearestChest( this.adjChest );
		this.max_sleeve		= 40;
		this.max_cuff		= 11;
		this.max_bottom_width = this.adjChest;

		/*
		this.min_collar		= this.size_Ord - 2;
		// min chest
		var tmp1, tmp2, tmp3, tmp4;
		var slim_var;
		slim_var = 39;

		tmp1 = ((Math.max(this.adjCollar - 2, 14) - 14) * 4 + slim_var) / 2;
		tmp2 = this.adjChest + 2 * (this.yokeadj_Ord - 1.5);
		tmp3 = this.adjChest + (this.bicep_adj_Ord - 1) / 0.75;
		tmp4 = this.adjChest - ((6 - this.waist_Ord) / 2);
		this.min_chest		= Math.max(Math.max(tmp1, tmp2), Math.max(tmp3, tmp4));
		this.min_chest 		= this.table.getElementById(this.table.findNearIdByValue(1, this.min_chest))[1];
		this.min_mid		= (this.waistStdDum - 4) / 2;
		this.min_shoulder	= this.size_Ord + (this.fit == 0? 3 : 3.5) - 1.5;
		this.min_length		= 29;
		this.min_sleeveW	= roundTo(this.bicepStdDum - 1, 0.25);
		this.min_sleeve		= 28;
		this.min_cuff		= 8;

		this.max_collar		= this.size_Ord + 2;
		// max chest
		slim_var = 41.5;
		tmp1 = ((Math.min(this.adjCollar + 2, 22) - 14) * 4 + slim_var) / 2;
		tmp2 = this.adjChest + 2 * (this.yokeadj_Ord + 1.5);
		tmp3 = this.adjChest + (this.bicep_adj_Ord + 2) / 0.75;
		tmp4 = this.adjChest + ((this.waist_Ord + 4) / 2);
		this.max_chest		= Math.min(Math.min(tmp1, tmp2), Math.min(tmp3, tmp4));
		this.max_chest 		= this.table.getElementById(this.table.findNearIdByValue(1, this.max_chest))[1];
		this.max_mid		= (this.waistStdDum + 4) / 2;
		this.max_shoulder	= this.size_Ord + (this.fit == 0? 3 : 3.5) + 1.5;
		this.max_length		= 44;
		this.max_sleeveW	= roundTo(this.bicepStdDum + 1, 0.25);
		this.max_sleeve		= 40;
		this.max_cuff		= 11; 
		*/
	}

// general function
	this.calculate			= function(calculateAdjValues) 
	{
		if (calculateAdjValues == undefined) calculateAdjValues = true;

		if ( calculateAdjValues )
		{
			this.adjCollar 		= excelCeil(4 * this.collar_Shirt) / 4;

			this.adjChest = excelRound(2 * this.chest_Shirt) / 2;
			this.adjSleeveWidth = excelCeil( this.sleeveW_Shirt * 4 ) / 4;
			this.calculateLimits();
			this.correctByLimits();
			if (this.adjSleeveWidth > this.max_sleeveW) this.adjSleeveWidth = this.max_sleeveW;
			if (this.adjSleeveWidth < this.min_sleeveW) this.adjSleeveWidth = this.min_sleeveW;

			this.adjChest = excelRound(2 * this.chest_Shirt) / 2;
			this.calculateLimits();
			if (this.adjChest > this.max_chest) this.adjChest = this.max_chest;
			if (this.adjChest < this.min_chest) this.adjChest = this.min_chest;

			this.adjMiddle 		= excelCeil(2 * this.mid_Shirt) / 2;
			this.adjShoulder 	= excelCeil(4 * this.shoulder_Shirt) / 4;
			this.adjBackLen 	= excelCeil(2 * this.length_Shirt) / 2;

			this.adjSleeveLen = excelRound(4 * ( this.sleeve_Shirt ) ) / 4;
			this.adjCuff = excelCeil(4 * this.cuff_Shirt) / 4;

			this.calculateLimits();
			this.correctByLimits();
		}
		
		return;

		// adj variables 
		if (calculateAdjValues){
			if (this.chest_Shirt > 16.5)
				this.adjChest = excelRound(2 * this.chest_Shirt) / 2;
			else
				this.adjChest = 16.5;
			if (this.adjChest > this.min_chest) this.adjChest = this.min_chest;
			if (this.adjChest < this.max_chest) this.adjChest = this.max_chest;
		}
		// ord variables 
		switch (this.adjChest)
		{
			case 20.75: case 21.75: case 22.75: case 23.75: case 24.75: case 25.75: case 26.75: case 27.75: case 28.75: case 29.75:
			case 30.75: case 31.75: case 32.75: case 33.75: case 34.75: case 35.75: case 37.25: 
				this.fit = 1;
			break;
			default: this.fit = 0;
		}
		this.model_Ord = this.fit;
		if (this.adjChest > 19.5)
			this.size_Ord = this.table.getElementById(this.table.findNearIdByValue(6, 4 * this.adjChest))[7];
		else
			this.size_Ord = 14
		/*
		switch (this.adjChest)
		{
			case 20.25: case 21.25: case 22.25: case 23.25: case 24.25: case 25.25: case 26.25: case 27.25: case 28.25: case 29.25:
			case 30.25: case 31.25: case 32.25: case 33.25: case 34.25: case 35.25: case 36.25: 
				this.rear_side_pleats = 1;
			break;
			default: this.rear_side_pleats = 0;
		}
		*/

		// tmp variables
		this.bicepStdDum = ((this.size_Ord - 14) * 1.5 + 17) / 2;
		this.yokeStandard = this.size_Ord + (this.fit == 0? 3 : 3.5);
		this.waistStdDum = (this.fit == 0? 37 + 4 * (this.size_Ord - 14) : 40 + 4 * (this.size_Ord - 14));
		if (this.model_Ord == 0 && this.rear_side_pleats == 1)
			this.waistStdDum = 37 + 4 * (this.size_Ord - 14);
		else if(this.model_Ord == 1 && this.rear_side_pleats == 1)
			this.waistStdDum = 40 + 4 * (this.size_Ord - 14);
		else if(this.model_Ord == 0 && this.rear_side_pleats == 0)
			this.waistStdDum = 36 + 4 * (this.size_Ord - 14);
		else
			this.waistStdDum = 39 + 4 * (this.size_Ord - 14);
		var tmp2;
		var tmp1;
	
		if (calculateAdjValues)
			this.sleeveWDesDum = this.sleeveW_Shirt;
		else
			this.sleeveWDesDum = this.adjSleeveWidth;

		// adj variables
		if (calculateAdjValues)
		{
			this.adjSleeveWidth = excelCeil( this.sleeveW_Shirt * 4 ) / 4;
			if (this.adjSleeveWidth > this.bicepStdDum + 1) this.adjSleeveWidth = this.bicepStdDum + 1;
			if (this.adjSleeveWidth < this.bicepStdDum - 1) this.adjSleeveWidth = this.bicepStdDum - 1;
			this.adjCollar 		= excelCeil(4 * this.collar_Shirt) / 4;
			this.adjMiddle 		= excelCeil(2 * this.mid_Shirt) / 2;
			this.adjShoulder 	= excelCeil(4 * this.shoulder_Shirt) / 4;
			this.adjBackLen 	= excelCeil(2 * this.length_Shirt) / 2;

			{ // check for adj shoulder
				this.calculateLimits();
				this.correctByLimits();
			}
			
			this.adjSleeveLen = excelRound(4 * ( this.sleeve_Shirt + this.shoulder_Shirt / 2 ) ) / 4;
			this.adjCuff = excelCeil(4 * this.cuff_Shirt) / 4;
		}
		if (calculateAdjValues)
		{
			this.calculateLimits();
			this.correctByLimits();
//			this.calculateLimits();
//			this.correctByLimits();
		} 

		// ord files
		this.neck_Ord=this.length_Ord=this.rSleeve_Ord=this.lSleeve_Ord=this.bicepStdDum=this.yokeStandard=this.waist_Ord=this.rCuff_Ord=this.lCuff_Ord=
		this.bicep_adj_Ord=this.yokeadj_Ord=this.backDetail_Ord = 0;
		/*
		this.neck_Ord = this.adjCollar;
		this.length_Ord = excelRound(this.adjBackLen - (31.625 + (0.75 * (this.size_Ord - 14))));
		this.rSleeve_Ord = this.adjSleeveLen;
		this.lSleeve_Ord = this.adjSleeveLen;
		this.bicepStdDum = ((this.size_Ord - 14) * 1.5 + 17) / 2;
		this.yokeStandard = this.size_Ord + (this.fit == 0? 3 : 3.5);
		this.waist_Ord = this.adjMiddle * 2 - this.waistStdDum;
		this.rCuff_Ord = this.adjCuff + 1;
		this.lCuff_Ord = this.adjCuff + 1;
		this.bicep_adj_Ord = (this.adjSleeveWidth - this.bicepStdDum > 0? excelCeil((this.adjSleeveWidth - this.bicepStdDum) * 2) : excelFloor((this.adjSleeveWidth - this.bicepStdDum) * 2));
		this.yokeadj_Ord = this.adjShoulder - this.yokeStandard;
		this.backDetail_Ord = this.rear_side_pleats ? 1 : 0;
		*/
	};
	//	---------	--------	---------	---------	---------	----------	----------	----------
	this.debug_limits 		= function()
	{
		var str = '';
		str += 'collar: ' + this.min_collar + ' | ' + this.max_collar + '\n';
		str += 'sleeve: ' + this.min_sleeve + ' | ' + this.max_sleeve + '\n';
		str += 'shoulder: ' + this.min_shoulder + ' | ' + this.max_shoulder + '\n';
		str += 'chest: ' + this.min_chest + ' | ' + this.max_chest + '\n';
		str += 'midle: ' + this.min_mid + ' | ' + this.max_mid + '\n';
		str += 'sleeve_width: ' + this.min_sleeveW + ' | ' + this.max_sleeveW + '\n';
		str += 'shirt len: ' + this.min_length + ' | ' + this.max_length + '\n';
		str += 'cuff: ' + this.min_cuff + ' | ' + this.max_cuff + '\n';
		alert(str);
	}

	this.debug_adj			= function()
	{
		var str = 'Collar: ' + this.adjCollar + '\n';
		str += 'Chest: ' + this.adjChest + '\n';
		str += 'Shoulder: ' + this.adjShoulder	 + '\n';
		str += 'Middle: ' + this.adjMiddle	 + '\n';
		str += 'Length: ' + this.adjBackLen	 + '\n';
		str += 'Sleeve width: ' + this.adjSleeveWidth	 + '\n';
		str += 'Sleeve Len: ' + this.adjSleeveLen	 + '\n';
		str += 'Cuff: ' + this.adjCuff		 + '\n';
		alert(str);
	}

	this.debug_tmp			= function()
	{
		var str = 'bicep_std_dum: ' + this.bicepStdDum + '\n';
		str += 'yoke_standart: ' + this.yokeStandard + '\n';
		str += 'waist_std_dum: ' + this.waistStdDum + '\n';
		str += 'waist_des_bum: ' + this.waistDesDum + '\n';
		
		str += 'sleeve_w_des_dum: ' + this.sleeveWDesDum + '\n';
		str += 'chest_des_dum: ' + this.chestDesDum + '\n';
		str += 'collar_des_dum: ' + this.collarDesDum + '\n';
		str += 'length_std: ' + this.lengthStd + '\n';
		str += 'length_des_dum: ' + this.lengthDesDum + '\n';
		alert(str);
	}

	this.debug_ord			= function()
	{
		var str = '';
		str += 'getFitOrd: ' + this.getFitOrd() + '\n';
		str += 'getModelOrd: ' + this.getModelOrd() + '\n';
		str += 'getSizeOrd: ' + this.getSizeOrd() + '\n';
		str += 'getNeckOrd: ' + this.getNeckOrd() + '\n';
		str += 'getLengthOrd: ' + this.getLengthOrd() + '\n';
		str += 'getRSleeveOrd: ' + this.getRSleeveOrd() + '\n';
		str += 'getLSleeveOrd: ' + this.getLSleeveOrd() + '\n';
		str += 'getWaistOrd: ' + this.getWaistOrd() + '\n';
		str += 'getRCuffOrd: ' + this.getRCuffOrd() + '\n';
		str += 'getLCuffOrd: ' + this.getLCuffOrd() + '\n';
		str += 'getBicepAdjOrd: ' + this.getBicepAdjOrd() + '\n';
		str += 'getYokeAdjOrd: ' + this.getYokeAdjOrd() + '\n';
		str += 'getBackDetailOrd: ' + this.getBackDetailOrd() + '\n';
		str += '\n';
		str += 'explanations: \n';
		str += 'getBackDetailOrd: 1 or true = pleats ; 0 or false - no pleats\n';
		str += 'getFitOrd: 1 or true - regular ; 0 or false - slim\n';
		
		alert(str);
	}
}
// -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- -  -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- - -- - -- - - -- - -- - --
//-- - -- - - -- - -- - -- - -- - -			    BODY MEASUREMENTS CLASS 			      -- -- - --  - -- - - -- - -- - -- -- 
// -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- -  -- - -- - - -- - -- - -- - -- - -- - -- - -- -- - --  - -- - - -- - -- - -- - -- - - -- - -- - --
function BodyMeasurement()
{
// input values
	this.neck 			= 0;
	this.arm_len 		= 0;
	this.shoulder_W 	= 0;
	this.chest			= 0;
	this.waist_around 	= 0;
	this.length			= 0;
	this.wrist_around	= 0;
	this.bicep_around  	= 0;
	this.style_body		= 0;	
	this.rear_side_pleats = true;
//output values
	this.fit			= 0;
	this.model_Ord  	= 0;
	this.size_Ord  		= 0;
	this.neck_Ord  		= 0;
	this.length_Ord  	= 0;
	this.rSleeve_Ord  	= 0;
	this.lSleeve_Ord  	= 0;
	this.waist_Ord  	= 0;
	this.rCuff_Ord	 	= 0;
	this.lCuff_Ord		= 0;
	this.bicep_adj_Ord  = 0;
	this.yokeadj_Ord  	= 0;
	this.backDetail_Ord = false;
// adj values
	this.adjCollar;
	this.adjChest;
	this.adjShoulder;
	this.adjMiddle;
	this.adjBackLen;
	this.adjSleeveWidth;
	this.adjSleeveLen;
	this.adjCuff;
//tmp variables
	this.bicepStdDum;
	this.yokeStandard;
	this.waistStdDum;
	this.waistDesDum;
	this.bicepDesDum;
	this.chestDesDum;
	
	this.chest_tmp;
//limits
	this.min_collar		= 0;
	this.min_sleeve		= 0;
	this.min_shoulder	= 0;
	this.min_chest		= 0;
	this.min_mid		= 0;
	this.min_sleeveW	= 0;
	this.min_length		= 0;
	this.min_cuff		= 0;
	
	this.max_collar		= 0;
	this.max_sleeve		= 0;
	this.max_shoulder	= 0;
	this.max_chest		= 0;
	this.max_mid		= 0;
	this.max_sleeveW	= 0;
	this.max_length		= 0;
	this.max_cuff		= 0;
	
//setter functions
	// set input
	this.setNeck 		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.neck = parseFloat(value);};
	this.setArmLen 		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.arm_len = parseFloat(value);};
	this.setShoulderW 	= function(value) {value = value.toString(); value = value.replace(',', '.'); this.shoulder_W = parseFloat(value);};
	this.setChest		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.chest = parseFloat(value);};
	this.setWaist 		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.waist_around = parseFloat(value);};
	this.setLength		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.length = parseFloat(value);};
	this.setWrist		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.wrist_around = parseFloat(value);};
	this.setBicep  		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.bicep_around = parseFloat(value);};
	this.setStyleBody	= function(value) {value = value.toString(); value = value.replace(',', '.'); this.style_body = parseFloat(value);};
	// set adj values
	this.setAdjCollar		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjCollar = parseFloat(value);};
	this.setAdjChest		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjChest = parseFloat(value);};
	this.setAdjShoulder		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjShoulder = parseFloat(value);};
	this.setAdjMiddle		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjMiddle = parseFloat(value);};
	this.setAdjBackLen		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjBackLen = parseFloat(value);};
	this.setAdjSleeveW		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjSleeveWidth = parseFloat(value);};
	this.setAdjSleeveL		= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjSleeveLen = parseFloat(value);};
	this.setAdjCuff			= function(value) {value = value.toString(); value = value.replace(',', '.'); this.adjCuff = parseFloat(value);};
	this.setRearSidePleats 	= function(value) {this.rear_side_pleats = value == true;};
//getter functions
	// get ord variables
	this.getFitOrd			= function() {return this.fit};
	this.getModelOrd  		= function() {return this.model_Ord};
	this.getSizeOrd  		= function() {return this.size_Ord};
	this.getNeckOrd  		= function() {return this.neck_Ord};
	this.getLengthOrd  		= function() {return this.length_Ord};
	this.getRSleeveOrd  	= function() {return this.rSleeve_Ord};
	this.getLSleeveOrd 	 	= function() {return this.lSleeve_Ord};
	this.getWaistOrd  		= function() {return this.waist_Ord};
	this.getRCuffOrd  		= function() {return this.rCuff_Ord};
	this.getLCuffOrd  		= function() {return this.lCuff_Ord};
	this.getBicepAdjOrd		= function() {return this.bicep_adj_Ord};
	this.getYokeAdjOrd 		= function() {return this.yokeadj_Ord};
	this.getBackDetailOrd	= function() {return this.backDetail_Ord};
	// get adj variables
	this.getAdjCollar		= function() {return Math.abs(this.adjCollar)};
	this.getAdjChest		= function() {return Math.abs(this.adjChest)};
	this.getAdjShoulder		= function() {return Math.abs(this.adjShoulder)};
	this.getAdjMiddle		= function() {return Math.abs(this.adjMiddle)};
	this.getAdjBackLen		= function() {return Math.abs(this.adjBackLen)};
	this.getAdjSleeveW		= function() {return Math.abs(this.adjSleeveWidth)};
	this.getAdjSleeveL		= function() {return Math.abs(this.adjSleeveLen)};
	this.getAdjCuff			= function() {return Math.abs(this.adjCuff)};  

	this.table = new ChestWidthTable();
	
	// limits
	this.correctByLimits		= function()
	{
		if (this.adjCollar > this.max_collar) this.adjCollar = this.max_collar;
		if (this.adjCollar < this.min_collar) this.adjCollar = this.min_collar;
		
		if (this.adjMiddle > this.max_mid) this.adjMiddle = this.max_mid;
		if (this.adjMiddle < this.min_mid) this.adjMiddle = this.min_mid;
		
		if (this.adjShoulder > this.max_shoulder) this.adjShoulder = this.max_shoulder;
		if (this.adjShoulder < this.min_shoulder) this.adjShoulder = this.min_shoulder;
		
		if (this.adjBackLen > this.max_length) this.adjBackLen = this.max_length;
		if (this.adjBackLen < this.min_length) this.adjBackLen = this.min_length;
		
		if (this.adjSleeveLen > this.max_sleeve) this.sleeve_Shirt = this.max_sleeve;
		if (this.adjSleeveLen < this.min_sleeve) this.sleeve_Shirt = this.min_sleeve;
		
		if (this.adjCuff > this.max_cuff) this.adjCuff = this.max_cuff;
		if (this.adjCuff < this.min_cuff) this.adjCuff = this.min_cuff;
	}
	
	this.calculateLimits 		= function()
	{
		var chestLimitsTable = new ChestLimitsTable();
		var sleeveWidthLimitsTable = new SleeveWidthLimitsTable();
		this.min_collar		= 12;
		this.min_chest		= chestLimitsTable.getMinChestByNearestSleeveWidth( this.adjSleeveWidth );
		this.min_mid		= 10;
		this.min_shoulder	= 10;
		this.min_length		= 25;
		this.min_sleeveW	= sleeveWidthLimitsTable.getMinSleeveWidthByNearestChest( this.adjChest );
		this.min_sleeve		= 28;
		this.min_cuff		= 8;
		this.min_bottom_width = this.adjMiddle;
		
		this.max_collar		= 24;
		this.max_chest		= chestLimitsTable.getMaxChestByNearestSleeveWidth( this.adjSleeveWidth );
		this.max_mid		= 80;
		this.max_shoulder	= 30;
		this.max_length		= 45;
		this.max_sleeveW	= sleeveWidthLimitsTable.getMaxSleeveWidthByNearestChest( this.adjChest );
		this.max_sleeve		= 40;
		this.max_cuff		= 11;
		this.max_bottom_width = this.adjChest;

		/*
		this.min_collar		= this.size_Ord - 2;
		// min chest		
		var tmp1, tmp2, tmp3, tmp4;
		var slim_var;

		slim_var = 39;
		tmp1 = ((Math.max(this.adjCollar - 2, 14) - 14) * 4 + slim_var) / 2;
		tmp2 = this.adjChest + 2 * (this.yokeadj_Ord - 1.5);
		tmp3 = this.adjChest + (this.bicep_adj_Ord - 1) / 0.75;
		tmp4 = this.adjChest - ((6 - this.waist_Ord) / 2);
		
		this.min_chest		= Math.max(Math.max(tmp1, tmp2), Math.max(tmp3, tmp4));
		this.min_chest 		= this.table.getElementById(this.table.findNearIdByValue(1, this.min_chest))[1];
		this.min_mid		= (this.waistStdDum-4)/2;
		this.min_shoulder	= this.yokeStandard - 1.5;
		this.min_length		= 29;
		this.min_sleeveW	= (this.bicepStdDum - 1);
		this.min_sleeve		= 27;
		this.min_cuff		= 8;
		
		this.max_collar		= this.size_Ord + 2;
		// max chest

		slim_var = 41.5;
		tmp1 = ((Math.min(this.adjCollar + 2, 22) - 14) * 4 + slim_var) / 2;
		tmp2 = this.adjChest + 2 * (this.yokeadj_Ord + 1.5);
		tmp3 = this.adjChest + (this.bicep_adj_Ord + 2) / 0.75;
		tmp4 = this.adjChest + ((this.waist_Ord + 4) / 2);
		//alert(tmp1 + ' | ' + tmp2 + ' | ' + tmp3 + ' | ' + tmp4);

		this.max_chest		= Math.min(Math.min(tmp1, tmp2), Math.min(tmp3, tmp4));

		this.max_mid		= (this.waistStdDum+4)/2;
		this.max_shoulder	= this.yokeStandard + 1.5;
		this.max_length		= 44;
		this.max_sleeveW	= (this.bicepStdDum + 1);
		this.max_sleeve		= 43;
		this.max_cuff		= 11;
		*/
	}
// general function
	this.calculate			= function(calculateAdjValues) 
	{
		if (calculateAdjValues == undefined) calculateAdjValues = true;

		if ( calculateAdjValues )
		{
			this.adjCollar 		= excelRound( this.neck * 4 ) / 4;
			
			this.adjChest		= excelCeil( this.chest * ( BODY_STYLE_CLASSIC == this.style_body ? 1.14 : ( BODY_STYLE_SLIM == this.style_body ? 1.125 : 1.09 ) ) ) / 2;

			this.adjSleeveWidth	= excelCeil( 2 * ( this.bicep_around + ( BODY_STYLE_CLASSIC == this.style_body ? 5 : ( BODY_STYLE_SLIM == this.style_body ? 4.25 : 3.5 ) ) ) ) / 4;
//			this.calculateLimits();
//			if (this.adjSleeveWidth > this.max_sleeveW) this.adjSleeveWidth = this.max_sleeveW;
//			if (this.adjSleeveWidth < this.min_sleeveW) this.adjSleeveWidth = this.min_sleeveW;

//			this.adjChest		= excelCeil( this.chest * ( BODY_STYLE_CLASSIC == this.style_body ? 1.15 : ( BODY_STYLE_SLIM == this.style_body ? 1.13 : 1.1 ) ) ) / 2;
			this.adjChest		= excelCeil( this.chest * ( BODY_STYLE_CLASSIC == this.style_body ? 1.14 : ( BODY_STYLE_SLIM == this.style_body ? 1.125 : 1.09 ) ) ) / 2;

//			this.calculateLimits();
//			if (this.adjChest > this.max_chest) this.adjChest = this.max_chest;
//			if (this.adjChest < this.min_chest) this.adjChest = this.min_chest;

			this.adjShoulder	= excelRound( this.shoulder_W  * 4 ) / 4;

//			this.adjMiddle		= excelCeil( this.waist_around + ( BODY_STYLE_CLASSIC == this.style_body ? 7 : ( BODY_STYLE_SLIM == this.style_body ? 6 : 4 ) ) ) / 2;
			this.adjMiddle		= excelCeil( this.waist_around * ( BODY_STYLE_CLASSIC == this.style_body ? 1.14 : ( BODY_STYLE_SLIM == this.style_body ? 1.125 : 1.09 ) ) ) / 2;


			this.adjBackLen		= excelRound( this.length * 2 ) / 2;

			this.adjSleeveLen	= excelCeil( 4 * this.arm_len ) / 4;
			this.adjCuff		= excelCeil( ( this.wrist_around + 2.25 <= 8? 8 : (this.wrist_around + 2.25 > 11? 11 : this.wrist_around + 2.25) ) * 4 ) / 4;
		}

		this.calculateLimits();
		this.correctByLimits();

		return;

		// adj valriable
		if (calculateAdjValues)
		{
			this.adjSleeveLen = excelCeil(4 * this.arm_len) / 4;
			this.adjCuff = (this.wrist_around + 1.5 <= 8? 8 : (this.wrist_around + 1.5 > 11? 11 : this.wrist_around + 1.5));
		}

		// tmp variables
		this.waistDesDum = this.waist_around + (this.style_body == 0? 5 : 7);
//		this.bicepDesDum = (this.style_body == 0? this.bicep_around + 3.5 : this.bicep_around + 5) / 2;
		this.bicepDesDum = (this.style_body == 0? this.bicep_around + 2.5 : this.bicep_around + 5) / 2;
		this.chestDesDum = (this.waist_around > this.chest + 5? (this.waist_around + (this.style_body == 0? 2 : 4)) / 2 : (this.chest + (this.style_body == 0? 6 : 8)) / 2);

		// adj variables (with out limits)
		if (this.chestDesDum > 19.5)
			this.chest_tmp = (this.table.getElementById(this.table.findNearIdByValue(6, 4 * this.chestDesDum))[6]) /4;
		else
			this.chest_tmp = 19.5;
		if (calculateAdjValues)
		{
			this.adjChest = this.chest_tmp;
		}
		switch (this.adjChest)
		{
			case 20.25: case 21.25: case 22.25: case 23.25: case 24.25: case 25.25: case 26.25: case 27.25: case 28.25: case 29.25:
			case 30.25: case 31.25: case 32.25: case 33.25: case 34.25: case 35.25: case 36.25: 
				this.rear_side_pleats = 1;
			break;
			default: this.rear_side_pleats = 0;
		}
		
		// ord variables
		switch (this.adjChest)
		{
			case 20.75: case 21.75: case 22.75: case 23.75: case 24.75: case 25.75: case 26.75: case 27.75: case 28.75: case 29.75:
			case 30.75: case 31.75: case 32.75: case 33.75: case 34.75: case 35.75: case 36.75: this.model_Ord = 1; break;
			default: this.model_Ord = 0;
		}
		if (this.adjChest > 19.5)
			this.size_Ord = this.table.getElementById(this.table.findNearIdByValue(6, 4 * this.adjChest))[7];
		else
			this.size_Ord = 14
		this.rSleeve_Ord  	= this.adjSleeveLen;
		this.lSleeve_Ord  	= this.adjSleeveLen;
		this.rCuff_Ord	 	= this.adjCuff + 1;
		this.lCuff_Ord		= this.adjCuff + 1;

		// tmp variables
		this.bicepStdDum = ((this.size_Ord - 14) * 1.5 + 17)/2;
		this.yokeStandard = (this.model_Ord == 0? this.size_Ord + 3 : this.size_Ord + 3.5);

		if (this.model_Ord == 0 && this.rear_side_pleats == 1)
			this.waistStdDum = 37 + 4 * (this.size_Ord - 14);
		else if(this.model_Ord == 1 && this.rear_side_pleats == 1)
			this.waistStdDum = 40 + 4 * (this.size_Ord - 14);
		else if(this.model_Ord == 0 && this.rear_side_pleats == 0)
			this.waistStdDum = 36 + 4 * (this.size_Ord - 14);
		else
			this.waistStdDum = 39 + 4 * (this.size_Ord - 14);

		// adj variables
		if (calculateAdjValues)
		{
			this.adjShoulder = excelCeil( this.yokeStandard * 2 ) / 2;
			/*
			this.adjShoulder = excelCeil(2 * (this.shoulder_W <= this.yokeStandard - 1.5?this.yokeStandard - 1.5: 
				(this.shoulder_W <= this.yokeStandard - 1?this.yokeStandard - 1:
				(this.shoulder_W <= this.yokeStandard - 0.5?this.yokeStandard - 0.5:
				(this.shoulder_W <= this.yokeStandard?this.yokeStandard:
				(this.shoulder_W <= this.yokeStandard + 0.5?this.yokeStandard + 0.5:
				(this.shoulder_W <= this.yokeStandard + 1?this.yokeStandard + 1:this.yokeStandard + 1.5))))))) / 2;
			*/
			
			this.adjMiddle = ((this.waistDesDum < this.waistStdDum - 4? this.waistStdDum - 4 : (this.waistDesDum > this.waistStdDum + 4? this.waistStdDum + 4 : this.waistDesDum))) / 2;
//			this.adjSleeveWidth = (this.bicepDesDum < this.bicepStdDum - 2? this.bicepStdDum - 2 : (this.bicepDesDum > this.bicepStdDum + 1? this.bicepStdDum + 1 : this.bicepStdDum - (excelFloor((this.bicepStdDum - this.bicepDesDum) * 2) / 2))) / 2;
			this.adjSleeveWidth = this.bicepDesDum;
			if (this.adjSleeveWidth > this.bicepStdDum + 1) this.adjSleeveWidth = this.bicepStdDum + 1;
			if (this.adjSleeveWidth < this.bicepStdDum - 1) this.adjSleeveWidth = this.bicepStdDum - 1;
		}

		// ord variables
		this.waist_Ord  	= this.adjMiddle * 2 - this.waistStdDum;
		this.bicep_adj_Ord  = (this.adjSleeveWidth - this.bicepStdDum > 0? excelCeil((this.adjSleeveWidth - this.bicepStdDum) * 2) : excelFloor((this.adjSleeveWidth - this.bicepStdDum) * 2));
		this.yokeadj_Ord  	= this.adjShoulder - this.yokeStandard;
		//alert(' adjMiddle: ' + this.adjMiddle + ' adjSleeveWidth: ' + this.adjSleeveWidth);

		// adj variables
		if (calculateAdjValues)
		{
			this.adjCollar = (this.neck);
			this.adjBackLen = this.length;
		}

		// check limits
		this.min_collar		= this.size_Ord - 2;
		this.max_collar		= this.size_Ord + 2;
		this.min_length		= 29;
		this.max_length		= 44;
		if (this.adjCollar > this.max_collar) this.adjCollar = this.max_collar;
		if (this.adjCollar < this.min_collar) this.adjCollar = this.min_collar;
		if (this.adjBackLen > this.max_length) this.adjBackLen = this.max_length;
		if (this.adjBackLen < this.min_length) this.adjBackLen = this.min_length;

		// ord variables
		this.neck_Ord  		= this.adjCollar;
		this.length_Ord  	= excelRound(this.adjBackLen - (31.625 + 0.75 * (this.size_Ord - 14)));

		this.calculateLimits();
		this.correctByLimits();

		return;
	};
	
		//	---------	--------	---------	---------	---------	----------	----------	----------
	this.debug_limits 		= function()
	{
		var str = '';
		str += 'collar: ' + this.min_collar + ' | ' + this.max_collar + '\n';
		str += 'sleeve: ' + this.min_sleeve + ' | ' + this.max_sleeve + '\n';
		str += 'shoulder: ' + this.min_shoulder + ' | ' + this.max_shoulder + '\n';
		str += 'chest: ' + this.min_chest + ' | ' + this.max_chest + '\n';
		str += 'midle: ' + this.min_mid + ' | ' + this.max_mid + '\n';
		str += 'sleeve_width: ' + this.min_sleeveW + ' | ' + this.max_sleeveW + '\n';
		str += 'shirt len: ' + this.min_length + ' | ' + this.max_length + '\n';
		str += 'cuff: ' + this.min_cuff + ' | ' + this.max_cuff + '\n';
		alert(str);
	}

	this.debug_adj			= function()
	{
		var str = 'Collar: ' + this.adjCollar + '\n';
		str += 'Chest: ' + this.adjChest + '\n';
		str += 'Shoulder: ' + this.adjShoulder	 + '\n';
		str += 'Middle: ' + this.adjMiddle	 + '\n';
		str += 'Length: ' + this.adjBackLen	 + '\n';
		str += 'Sleeve width: ' + this.adjSleeveWidth	 + '\n';
		str += 'Sleeve Len: ' + this.adjSleeveLen	 + '\n';
		str += 'Cuff: ' + this.adjCuff		 + '\n';
		alert(str);
	}

	this.debug_tmp			= function()
	{
		var str = 'bicepStdDum: ' + this.bicepStdDum + '\n';
		str += 'yokeStandard: ' + this.yokeStandard + '\n';
		str += 'waistStdDum: ' + this.waistStdDum + '\n';
		str += 'waistDesDum: ' + this.waistDesDum + '\n';

		str += 'bicepDesDum: ' + this.bicepDesDum + '\n';
		str += 'chestDesDum: ' + this.chestDesDum + '\n';

		alert(str);
	}

	this.debug_ord			= function()
	{
		var str = '';
		str += 'getFitOrd: ' + this.getFitOrd() + '\n';
		str += 'getModelOrd: ' + this.getModelOrd() + '\n';
		str += 'getSizeOrd: ' + this.getSizeOrd() + '\n';
		str += 'getNeckOrd: ' + this.getNeckOrd() + '\n';
		str += 'getLengthOrd: ' + this.getLengthOrd() + '\n';
		str += 'getRSleeveOrd: ' + this.getRSleeveOrd() + '\n';
		str += 'getLSleeveOrd: ' + this.getLSleeveOrd() + '\n';
		str += 'getWaistOrd: ' + this.getWaistOrd() + '\n';
		str += 'getRCuffOrd: ' + this.getRCuffOrd() + '\n';
		str += 'getLCuffOrd: ' + this.getLCuffOrd() + '\n';
		str += 'getBicepAdjOrd: ' + this.getBicepAdjOrd() + '\n';
		str += 'getYokeAdjOrd: ' + this.getYokeAdjOrd() + '\n';
		str += 'getBackDetailOrd: ' + this.getBackDetailOrd() + '\n';
		str += '\n';
		str += 'explanations: \n';
		str += 'getBackDetailOrd: 1 or true = pleats ; 0 or false - no pleats\n';
		str += 'getFitOrd: 1 or true - regular ; 0 or false - slim\n';

		alert(str);
	}
}
/*
var bodyMeasurement = new BodyMeasurement();
bodyMeasurement.setNeck( 15.5 );
bodyMeasurement.setArmLen( 33.1 );
bodyMeasurement.setShoulderW( 18.5 );
bodyMeasurement.setChest( 42.25 );
bodyMeasurement.setWaist( 34.5 );
bodyMeasurement.setLength( 33 );
bodyMeasurement.setWrist( 7.25 );
bodyMeasurement.setBicep( 14 );
bodyMeasurement.setStyleBody( BODY_STYLE_CLASSIC );
bodyMeasurement.calculate();

bodyMeasurement.debug_adj();
bodyMeasurement.debug_limits();
*/

function AdjSizes(data) {

	this.data = data;
	
	// check all for numbers
	for (var i in data) {
		if (isNaN(parseFloat(data[i])) && "adddim" != i.substr(0,6)) {
			throw new Error("`" + i + "` param in AdjSizes is not a number");
		} else {
			this.data[i] = parseFloat(data[i]);
		}
	}

	// rounding
	this.rdata = {};
	this.rdata.collar = Math.ceil(this.data.collar * 4) / 4;
	this.rdata.sleeve = Math.ceil(this.data.sleeve * 4) / 4;
	this.rdata.yoke = Math.ceil(this.data.yoke * 4) / 4;
	this.rdata.chest = Math.ceil(this.data.chest * 2) / 2;
	this.rdata.midsection = Math.ceil(this.data.midsection * 2) / 2;
	this.rdata.shirt_length = Math.ceil(this.data.shirt_length * 2) / 2;
	this.rdata.sleeve_w = Math.ceil(this.data.sleeve_w * 4) / 4;
	this.rdata.cuff = Math.ceil(this.data.cuff * 4) / 4;
	this.rdata.adddim_bottom_width = Math.ceil(this.data.adddim_bottom_width * 2) / 2;
	for (var i in this.rdata) {
		this.rdata[i] = this.rdata[i].toFixed(2);
	}

	// XML Variables
	this.xml_vars = {};

	this.xml_vars.body_size = this.get_body_size_chest_width();
	this.xml_vars.default_collar = this.xml_vars.body_size;

	this.xml_vars.adj_collar = this.restrict_limit(
		this.rdata.collar-this.xml_vars.default_collar,
		this.get_adj_limit('collar', 'min'),
		this.get_adj_limit('collar', 'max')
	) + this.xml_vars.default_collar;

	this.xml_vars.default_chest = (this.xml_vars.body_size - 14.5) * 2 + 19;
	this.xml_vars.adj_chest = this.restrict_limit(
		(this.rdata.chest-this.xml_vars.default_chest) * 2,
		this.get_adj_limit('chest', 'min'),
		this.get_adj_limit('chest', 'max')
	);

	this.xml_vars.default_midsection = (this.xml_vars.body_size - 14.5) * 2 + 17.5;
	this.xml_vars.adj_midsection = this.restrict_limit(
		(this.rdata.midsection-this.xml_vars.default_midsection) * 2,
		this.get_adj_limit('midsection', 'min'),
		this.get_adj_limit('midsection', 'max')
	);

	this.xml_vars.default_bottom = (this.xml_vars.body_size - 14.5) * 2 + 18.5;
	this.xml_vars.adj_bottom = this.restrict_limit(
		(this.rdata.adddim_bottom_width-this.xml_vars.default_bottom) * 2,
		this.get_adj_limit('adddim_bottom_width', 'min'),
		this.get_adj_limit('adddim_bottom_width', 'max')
	);

	this.xml_vars.default_yoke = this.xml_vars.body_size + 2;
	this.xml_vars.adj_yoke = this.restrict_limit(
		this.rdata.yoke-this.xml_vars.default_yoke,
		this.get_adj_limit('yoke', 'min'),
		this.get_adj_limit('yoke', 'max')
	);

	this.xml_vars.default_length = 32;
	this.xml_vars.adj_length = this.restrict_limit(
		this.rdata.shirt_length-this.xml_vars.default_length,
		this.get_adj_limit('shirt_length', 'min'),
		this.get_adj_limit('shirt_length', 'max')
	);

	this.xml_vars.default_sleeve_w = ((this.xml_vars.body_size - 14.5) * 2 * 0.75 + 16) / 2
	this.xml_vars.adj_sleeve_w = this.restrict_limit(
		(this.rdata.sleeve_w-this.xml_vars.default_sleeve_w) * 2,
		this.get_adj_limit('sleeve_w', 'min'),
		this.get_adj_limit('sleeve_w', 'max')
	);

	this.xml_vars.default_cuff = 0;
	this.xml_vars.adj_cuff = this.rdata.cuff - this.xml_vars.default_cuff + 1;

	this.xml_vars.default_sleeve = 0;
	this.xml_vars.adj_sleeve = this.data.sleeve - this.xml_vars.default_sleeve;

	// Actual Shirt Dimensions
	this.actual_dimensions = {};
	this.actual_dimensions.collar				= this.xml_vars.adj_collar;
	this.actual_dimensions.sleeve				= this.xml_vars.default_sleeve + this.xml_vars.adj_sleeve;
	this.actual_dimensions.yoke					= this.xml_vars.default_yoke + this.xml_vars.adj_yoke;
	this.actual_dimensions.chest				= this.xml_vars.default_chest + this.xml_vars.adj_chest / 2;
	this.actual_dimensions.midsection			= this.xml_vars.default_midsection + this.xml_vars.adj_midsection / 2;
	this.actual_dimensions.shirt_length			= this.xml_vars.default_length + this.xml_vars.adj_length;
	this.actual_dimensions.sleeve_w				= this.xml_vars.default_sleeve_w + this.xml_vars.adj_sleeve_w / 2;
	this.actual_dimensions.cuff					= this.xml_vars.default_cuff + this.xml_vars.adj_cuff - 1;
	this.actual_dimensions.adddim_bottom_width	= this.xml_vars.default_bottom + this.xml_vars.adj_bottom / 2;
	for (var i in this.actual_dimensions) {
		this.actual_dimensions[i] = this.actual_dimensions[i].toFixed(2);
	}

	this.min_collar = this.get_limit('collar', 'min');
	this.max_collar = this.get_limit('collar', 'max');
		 
	this.min_sleeve = this.get_limit('sleeve', 'min');
	this.max_sleeve = this.get_limit('sleeve', 'max');
	
	this.min_shoulder = this.min_yoke = this.get_limit('yoke', 'min');
	this.max_shoulder = this.max_yoke = this.get_limit('yoke', 'max');
	
	this.min_chest = this.get_limit('chest', 'min');
	this.max_chest = this.get_limit('chest', 'max');
	
	this.min_mid = this.min_midsection = this.get_limit('midsection', 'min'); 
	this.max_mid = this.max_midsection = this.get_limit('midsection', 'max');
	
	this.min_length = this.get_limit('length', 'min'); 
	this.max_length = this.get_limit('length', 'max'); 
	
	this.min_sleeve_w = this.get_limit('sleeve_w', 'min'); 
	this.max_sleeve_w = this.get_limit('sleeve_w', 'max'); 
	
	this.min_cuff = this.get_limit('cuff', 'min');
	this.max_cuff = this.get_limit('cuff', 'max');
	
	this.min_bottom_width = this.get_limit('adddim_bottom_width', 'min');
	this.max_bottom_width = this.get_limit('adddim_bottom_width', 'max');

	/*
		var str  = "this.actual_dimensions.collar = " + this.actual_dimensions.collar + "\n";
		str += "this.actual_dimensions.sleeve = " + this.actual_dimensions.sleeve + "\n";
		str += "this.actual_dimensions.yoke = " + this.actual_dimensions.yoke + "\n";
		str += "this.actual_dimensions.chest = " + this.actual_dimensions.chest + "\n";
		str += "this.actual_dimensions.midsection = " + this.actual_dimensions.midsection + "\n";
		str += "this.actual_dimensions.shirt_length = " + this.actual_dimensions.shirt_length + "\n";
		str += "this.actual_dimensions.sleeve_w = " + this.actual_dimensions.sleeve_w + "\n";
		str += "this.actual_dimensions.cuff = " + this.actual_dimensions.cuff + "\n";
		str += "this.actual_dimensions.adddim_bottom_width = " + this.actual_dimensions.adddim_bottom_width + "\n";
		alert(str);
	*/
	/*
		var str1  = "collar - " + this.get_limit('collar', 'min') + " | " + this.get_limit('collar', 'max') + "\n";
		str1 += "chest - " + this.get_limit('chest', 'min') + " | " + this.get_limit('chest', 'max') + "\n";
		str1 += "midsection - " + this.get_limit('midsection', 'min') + " | " + this.get_limit('midsection', 'max') + "\n";
		str1 += "adddim_bottom_width - " + this.get_limit('adddim_bottom_width', 'min') + " | " + this.get_limit('adddim_bottom_width', 'max') + "\n";
		str1 += "yoke - " + this.get_limit('yoke', 'min') + " | " + this.get_limit('yoke', 'max') + "\n";
		str1 += "length - " + this.get_limit('length', 'min') + " | " + this.get_limit('length', 'max') + "\n";
		str1 += "sleeve_w - " + this.get_limit('sleeve_w', 'min') + " | " + this.get_limit('sleeve_w', 'max') + "\n";
		str1 += "cuff - " + this.get_limit('cuff', 'min') + " | " + this.get_limit('cuff', 'max') + "\n";
		str1 += "sleeve - " + this.get_limit('sleeve', 'min') + " | " + this.get_limit('sleeve', 'max') + "\n";
		alert(str1);
	*/
}
AdjSizes.prototype.restrict_limit = function(value, minimum, maximum) {
	if (value < minimum) {
		return minimum;
	} else if(value > maximum) {
		return maximum;
	} else {
		return value;
	}
}
AdjSizes.prototype.get_limit = function(size, type) {
	switch (size.toLowerCase()) {
		case "collar":
			if ("min" == type) {
				return this.xml_vars.body_size - 2;
			} else if("max" == type) {
				return this.xml_vars.body_size + 2;
			}
			break;
		case "chest":
			if ("min" == type) {
				return parseFloat(this.actual_dimensions.chest) + 
					Math.max(
						(this.xml_vars.adj_collar - this.xml_vars.body_size - this.get_adj_limit('collar', 'max')) * 2,
						this.xml_vars.adj_yoke - this.get_adj_limit('yoke', 'max'),
						(this.xml_vars.adj_sleeve_w - this.get_adj_limit('sleeve_w', 'max')) * 2 / 1.5,
						this.xml_vars.adj_midsection - this.get_adj_limit('midsection', 'max')
					);
			} else if("max" == type) {

				return parseFloat(this.actual_dimensions.chest) + 
					Math.min(
						(this.xml_vars.adj_collar - this.xml_vars.body_size - this.get_adj_limit('collar', 'min')) * 2,
						this.xml_vars.adj_yoke - this.get_adj_limit('yoke', 'min'),
						(this.xml_vars.adj_sleeve_w - this.get_adj_limit('sleeve_w', 'min')) * 2 / 1.5,
						this.xml_vars.adj_midsection - this.get_adj_limit('midsection', 'min')
					);
			}
			break;
		case "midsection":
			if ("min" == type) {
				return parseFloat(this.actual_dimensions.midsection) + (this.get_adj_limit('midsection', 'min') - this.xml_vars.adj_midsection) / 2;
			} else if("max" == type) {
				return Math.min(
					parseFloat(this.actual_dimensions.midsection) + (this.get_adj_limit('midsection', 'max') - this.xml_vars.adj_midsection) / 2,
					parseFloat(this.actual_dimensions.chest)
				);
			}
			break;
		case "adddim_bottom_width":
			if ("min" == type) {
				return Math.max(
					parseFloat(this.actual_dimensions.adddim_bottom_width) + (
						this.get_adj_limit('adddim_bottom_width', 'min') - this.xml_vars.adj_bottom
					) / 2,
					this.actual_dimensions.midsection
				);
			} else if("max" == type) {
				return Math.min(
					parseFloat(this.actual_dimensions.adddim_bottom_width) + (
						this.get_adj_limit('adddim_bottom_width', 'max') - this.xml_vars.adj_bottom
					) / 2,
					this.actual_dimensions.chest
				);
			}
			break;
		case "yoke":
			if ("min" == type) {
				return parseFloat(this.actual_dimensions.yoke) + this.get_adj_limit('yoke', 'min') - this.xml_vars.adj_yoke;
			} else if("max" == type) {
				return parseFloat(this.actual_dimensions.yoke) + this.get_adj_limit('yoke', 'max') - this.xml_vars.adj_yoke;
			}
			break;
		case "length":
			if ("min" == type) {
				return parseFloat(this.actual_dimensions.shirt_length) + this.get_adj_limit('shirt_length', 'min') - this.xml_vars.adj_length;
			} else if("max" == type) {
				return parseFloat(this.actual_dimensions.shirt_length) + this.get_adj_limit('shirt_length', 'max') - this.xml_vars.adj_length;
			}
			break;
		case "sleeve_w":
			if ("min" == type) {
				var t = parseFloat(this.actual_dimensions.sleeve_w) + (this.get_adj_limit('sleeve_w', 'min') - this.xml_vars.adj_sleeve_w) / 2;
				t = t.toFixed(2);
				return parseFloat(t);
			} else if("max" == type) {
				var t = parseFloat(this.actual_dimensions.sleeve_w) + (this.get_adj_limit('sleeve_w', 'max') - this.xml_vars.adj_sleeve_w) / 2;
				t = t.toFixed(2);
				return parseFloat(t);
			}
			break;
		case "cuff":
			if ("min" == type) {
				return 8;
				//return parseFloat(this.actual_dimensions.cuff) + this.get_adj_limit('cuff', 'min') - this.xml_vars.adj_cuff;
			} else if("max" == type) {
				return 13;
				//return parseFloat(this.actual_dimensions.cuff) + this.get_adj_limit('cuff', 'max') - this.xml_vars.adj_cuff;
			}
			break;
		case "sleeve":
			if ("min" == type) {
				return parseFloat(this.actual_dimensions.sleeve) + this.get_adj_limit('sleeve', 'min') - this.xml_vars.adj_sleeve;
			} else if("max" == type) {
				return parseFloat(this.actual_dimensions.sleeve) + this.get_adj_limit('sleeve', 'max') - this.xml_vars.adj_sleeve;
			}
			break;
	}
	throw new Error("`"+size+"` param in get_limit() doesn't exists");
}
AdjSizes.prototype.get_adj_limit = function(size, type) {
	var limits = {
		"collar":				{"min": -2, "max": 2},
		"sleeve":				{"min": 22, "max": 42},
		"yoke":					{"min": -2, "max": 2},
		"chest":				{"min": -2, "max": 2},
		"midsection":			{"min": -8, "max": 6},
		"shirt_length":			{"min": -6, "max": 6},
		"sleeve_w":				{"min": -2, "max": 2},
		"cuff":					{"min": 7.5, "max": 9.25},
		"adddim_bottom_width":	{"min": -6, "max": 6}
	}
	if ("min" != type && "max" != type) {
		throw new Error("type `"+type+"` doesn't exist");
	}
	if (undefined != limits[size]) {
		return limits[size][type];
	} else {
		throw new Error("size `"+size+"` doesn't exist");
	}
}
AdjSizes.prototype.get_body_size_chest_width = function() {
	var body_size_chest_widths = {
		odd: {
			"13.5": {"2": 11.5, "3": 12.0},
			"14.5": {"2": 12.0, "3": 12.5},
			"15.5": {"2": 12.5, "3": 13.0},
			"16.5": {"2": 13.0, "3": 13.5},
			"17.5": {"2": 13.5, "3": 14.0},
			"18.5": {"2": 14.0, "3": 14.5},
			"19.5": {"2": 14.5, "3": 15.0},
			"20.5": {"2": 15.0, "3": 15.5},
			"21.5": {"2": 15.5, "3": 16.0},
			"22.5": {"2": 16.0, "3": 16.5},
			"23.5": {"2": 16.5, "3": 17.0},
			"24.5": {"2": 17.0, "3": 17.5},
			"25.5": {"2": 17.5, "3": 18.0},
			"26.5": {"2": 18.0, "3": 18.5},
			"27.5": {"2": 18.5, "3": 19.0},
			"28.5": {"2": 19.0, "3": 19.5},
			"29.5": {"2": 19.5, "3": 20.0},
			"30.5": {"2": 20.0, "3": 20.5},
			"31.5": {"2": 20.5, "3": 21.0},
			"32.5": {"2": 21.0, "3": 21.5},
			"33.5": {"2": 21.5, "3": 22.0},
			"34.5": {"2": 22.0, "3": 22.5},
			"35.5": {"2": 22.5, "3": 23.0},
			"36.5": {"2": 23.0, "3": 23.5},
			"37.5": {"2": 23.5, "3": 24.0}
		},
		even: {
			"13": {"2": 11.0, "3": 11.5, "4": 12.0},
			"14": {"2": 11.5, "3": 12.0, "4": 12.5},
			"15": {"2": 12.0, "3": 12.5, "4": 13.0},
			"16": {"2": 12.5, "3": 13.0, "4": 13.5},
			"17": {"2": 13.0, "3": 13.5, "4": 14.0},
			"18": {"2": 13.5, "3": 14.0, "4": 14.5},
			"19": {"2": 14.0, "3": 14.5, "4": 15.0},
			"20": {"2": 14.5, "3": 15.0, "4": 15.5},
			"21": {"2": 15.0, "3": 15.5, "4": 16.0},
			"22": {"2": 15.5, "3": 16.0, "4": 16.5},
			"23": {"2": 16.0, "3": 16.5, "4": 17.0},
			"24": {"2": 16.5, "3": 17.0, "4": 17.5},
			"25": {"2": 17.0, "3": 17.5, "4": 18.0},
			"26": {"2": 17.5, "3": 18.0, "4": 18.5},
			"27": {"2": 18.0, "3": 18.5, "4": 19.0},
			"28": {"2": 18.5, "3": 19.0, "4": 19.5},
			"29": {"2": 19.0, "3": 19.5, "4": 20.0},
			"30": {"2": 19.5, "3": 20.0, "4": 20.5},
			"31": {"2": 20.0, "3": 20.5, "4": 21.0},
			"32": {"2": 20.5, "3": 21.0, "4": 21.5},
			"33": {"2": 21.0, "3": 21.5, "4": 22.0},
			"34": {"2": 21.5, "3": 22.0, "4": 22.5},
			"35": {"2": 22.0, "3": 22.5, "4": 23.0},
			"36": {"2": 22.5, "3": 23.0, "4": 23.5},
			"37": {"2": 23.0, "3": 23.5, "4": 24.0},
			"38": {"2": 23.5, "3": 24.0, "4": 24.5}
		}
	};
	var optimal_body = (this.data.chest - 19) / 2 + 14.5;
	var target_column_even	= this.data.collar >= optimal_body + 1 ? 4 : (this.data.collar <= optimal_body - 1 ? 2 : 3);
	var target_column_odd	= this.data.collar >= optimal_body ? 3 : 2;
	var double_chest = this.rdata.chest * 2;
	if (parseInt(double_chest / 2) == parseFloat(double_chest / 2)) {
		return body_size_chest_widths.even[parseInt(this.rdata.chest).toString()][target_column_even];
	} else {
		return body_size_chest_widths.odd[parseFloat(this.rdata.chest).toString()][target_column_odd];
	}
}
AdjSizes.prototype.get_default_bottom_width = function() {
	var default_bottom_widths = {
		"0":	{"1":0, "2":0.5 , "3":1,   "4":1.5, "5":2,   "6":2   ,"7":2   ,"8":2   ,"9":2   ,"10":2   ,"11":2.5 ,"12":2.5 ,"13":2.5 },
		"0.5":	{"1":0, "2":0.5 , "3":1,   "4":1.5, "5":2,   "6":2   ,"7":2   ,"8":2   ,"9":2   ,"10":2   ,"11":2   ,"12":2.5 ,"13":2.5 },
		"1":	{"1":0, "2":0.25, "3":1,   "4":1,   "5":1.5, "6":2   ,"7":2   ,"8":2   ,"9":2   ,"10":2   ,"11":2   ,"12":2   ,"13":2 },
		"1.5":	{"1":0, "2":0.25, "3":0.5, "4":1,   "5":1.5, "6":2   ,"7":2   ,"8":2   ,"9":2   ,"10":2   ,"11":2   ,"12":2   ,"13":2 },
		"2":	{"1":0, "2":0.25, "3":0.5, "4":1,   "5":1.5, "6":1.5 ,"7":2   ,"8":2   ,"9":2   ,"10":2   ,"11":2   ,"12":2   ,"13":2 },
		"2.5":	{"1":0, "2":0.25, "3":0.5, "4":1,   "5":1,   "6":1.5 ,"7":1.5 ,"8":1.5 ,"9":1.5 ,"10":2   ,"11":2   ,"12":2   ,"13":2 },
		"3":	{"1":0, "2":0.25, "3":0.5, "4":0.5, "5":1,   "6":1   ,"7":1.5 ,"8":1.5 ,"9":1.5 ,"10":1.5 ,"11":1.5 ,"12":1.5 ,"13":1.5 },
		"3.5":	{"1":0, "2":0.25, "3":0.5, "4":0.5, "5":1,   "6":1   ,"7":1   ,"8":1   ,"9":1.5 ,"10":1.5 ,"11":1.5 ,"12":1.5 ,"13":1.5 },
		"4":	{"1":0, "2":0.25, "3":0.5, "4":0.5, "5":1,   "6":1   ,"7":1   ,"8":1   ,"9":1   ,"10":1.5 ,"11":1.5 ,"12":1.5 ,"13":1.5 },
		"4.5":	{"1":0, "2":0.25, "3":0.5, "4":0.5, "5":1,   "6":1   ,"7":1   ,"8":1   ,"9":1   ,"10":1   ,"11":1   ,"12":1   ,"13":1 },
		"5":	{"1":0, "2":0.25, "3":0.5, "4":0.5, "5":0.5, "6":1   ,"7":1   ,"8":1   ,"9":1   ,"10":1   ,"11":1   ,"12":1   ,"13":1 },
		"5.5":	{"1":0, "2":0.25, "3":0.5, "4":0.5, "5":0.5, "6":0.5 ,"7":0.5 ,"8":0.5 ,"9":1   ,"10":1   ,"11":1   ,"12":1   ,"13":1 },
		"6":	{"1":0, "2":0.25, "3":0.5, "4":0.5, "5":0.5, "6":0.5 ,"7":0.5 ,"8":0.5 ,"9":0.5 ,"10":1   ,"11":1   ,"12":1   ,"13":1 },
		"6.5":	{"1":0, "2":0.25, "3":0.5, "4":0.5, "5":0.5, "6":0.5 ,"7":0.5 ,"8":0.5 ,"9":0.5 ,"10":0.5 ,"11":0.5 ,"12":0.5 ,"13":0.5 },
		"7":	{"1":0, "2":0.25, "3":0.5, "4":0.5, "5":0.5, "6":0.5 ,"7":0.5 ,"8":0.5 ,"9":0.5 ,"10":0.5 ,"11":0.5 ,"12":0.5 ,"13":0.5 },
		"7.5":	{"1":0, "2":0.25, "3":0.5, "4":0.5, "5":0.5, "6":0.5 ,"7":0.5 ,"8":0.5 ,"9":0.5 ,"10":0.5 ,"11":0.5 ,"12":0.5 ,"13":0.5 },
		"8":	{"1":0, "2":0.25, "3":0.5, "4":0.5, "5":0.5, "6":0.5 ,"7":0.5 ,"8":0.5 ,"9":0.5 ,"10":0.5 ,"11":0.5 ,"12":0.5 ,"13":0.5 }
	};
	var length_sleeve_sub = this.rdata.sleeve - this.rdata.shirt_length;
	length_sleeve_sub = Math.round(length_sleeve_sub * 2) / 2;
	var chest_midsection_sub = parseInt((this.rdata.chest - this.rdata.midsection) * 2 + 1);
	if (length_sleeve_sub < 0)
		length_sleeve_sub = 0;
	if (length_sleeve_sub > 8)
		length_sleeve_sub = 8;
	if (chest_midsection_sub < 1)
		chest_midsection_sub = 1;
	if (chest_midsection_sub > 13)
		chest_midsection_sub = 13;
	return parseFloat(this.rdata.midsection) + parseFloat(default_bottom_widths[length_sleeve_sub][chest_midsection_sub]);
}
